Commit 36e62741 by guanghui.cui

餐盒处理,折扣计算修正

parent fd681728
...@@ -19,6 +19,8 @@ serverip=192.168.0.102 ...@@ -19,6 +19,8 @@ serverip=192.168.0.102
#优惠类型 #优惠类型
discountTypeShop=600 discountTypeShop=600
discountTypePlantform=601 discountTypePlantform=601
#餐盒sku
boxSku=007104
#守护进程脚本 #守护进程脚本
[SH] [SH]
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
COrderInfo::COrderInfo() COrderInfo::COrderInfo()
:mysql(NULL) :mysql(NULL)
,_tempLatin1(NULL)
{ {
if(mysql==NULL){ if(mysql==NULL){
std::string strIniPath = GetProcDir(); std::string strIniPath = GetProcDir();
...@@ -39,6 +38,12 @@ COrderInfo::COrderInfo() ...@@ -39,6 +38,12 @@ COrderInfo::COrderInfo()
if(_plantformFeeId<=0){ if(_plantformFeeId<=0){
LOG(ERROR)<<"get discountTypePlantform failed,discountTypePlantform:"<<_plantformFeeId; LOG(ERROR)<<"get discountTypePlantform failed,discountTypePlantform:"<<_plantformFeeId;
} }
_boxSku = ZIni::readString("SYS","boxSku", "",strIniPath.c_str());
if(_boxSku==""){
LOG(ERROR)<<"get boxSku failed,boxSku:"<<_boxSku;
}
} }
pthread_mutex_init(&mutex, NULL); //初始化互斥锁 pthread_mutex_init(&mutex, NULL); //初始化互斥锁
} }
...@@ -46,10 +51,6 @@ COrderInfo::COrderInfo() ...@@ -46,10 +51,6 @@ COrderInfo::COrderInfo()
COrderInfo::~COrderInfo() COrderInfo::~COrderInfo()
{ {
pthread_mutex_destroy(&mutex); //销毁互斥锁 pthread_mutex_destroy(&mutex); //销毁互斥锁
if(_tempLatin1!=NULL){
delete[] _tempLatin1;
_tempLatin1=NULL;
}
} }
int COrderInfo::DBConnect() int COrderInfo::DBConnect()
...@@ -260,7 +261,7 @@ int COrderInfo::SetTakeawayOrder(TakeawayOrder &order) ...@@ -260,7 +261,7 @@ int COrderInfo::SetTakeawayOrder(TakeawayOrder &order)
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_Check(`Date`,`Check`,BarCode,Outlet,`Floor`,TableNo,Cover,OpenTime,OpenPeriod,OpenStation,\ snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_Check(`Date`,`Check`,BarCode,Outlet,`Floor`,TableNo,Cover,OpenTime,OpenPeriod,OpenStation,\
OpenStationRef,OpenEmp,CloseTime,ClosePeriod,CloseStation,CloseEmp,PrintCount,LastPrintTime,CheckTot,ItemTot,DiscBefore,PayTot,IsPaid,SCRate1,\ OpenStationRef,OpenEmp,CloseTime,ClosePeriod,CloseStation,CloseEmp,PrintCount,LastPrintTime,CheckTot,ItemTot,DiscBefore,PayTot,IsPaid,SCRate1,\
IsModified,LastModifiedTime)\ IsModified,LastModifiedTime)\
VALUES('%s',%d,'%s',%d,1,'1',4,'%s',3,99,99,4,'%s',4,99,4,1,'%s',%.2f,%.2f,%.2f,%.2f,'1',0.1,1,'%s')", \ VALUES('%s',%d,'%s',%d,1,'1',1,'%s',3,99,99,4,'%s',4,99,4,1,'%s',%.2f,%.2f,%.2f,%.2f,'1',0.1,1,'%s')", \
strDate.data(),orderId,orderIdStr,iOutlet,chTime,chTime,chTime,merchantTot,order.shop_fee/100.00,-discount,merchantTot,chTime); strDate.data(),orderId,orderIdStr,iOutlet,chTime,chTime,chTime,merchantTot,order.shop_fee/100.00,-discount,merchantTot,chTime);
nErrCode = mysql->insert(); nErrCode = mysql->insert();
if(nErrCode != EC_OK) if(nErrCode != EC_OK)
...@@ -320,30 +321,36 @@ int COrderInfo::SetTakeawayOrder(TakeawayOrder &order) ...@@ -320,30 +321,36 @@ int COrderInfo::SetTakeawayOrder(TakeawayOrder &order)
vecDish.push_back(info); vecDish.push_back(info);
} }
//把餐盒加入到商品列表中
DishInfo boxDish={0,0,"",0,0,1,"1"};
boxDish.pid=_boxSku;
boxDish.consume_num=1;
boxDish.original_price=order.package_fee;
vecDish.push_back(boxDish);
//订单商品写入“订单详情表” //订单商品写入“订单详情表”
float disRate=(order.service_fee*1.00)/(order.products_fee); //平台服务费率 float disRate=(order.service_fee*1.00)/(order.products_fee-order.dis_shop_fee); //平台服务费率
float fBoxRateFee=disRate*(order.package_fee/100.00); //餐盒需要承担的平台服务费,由于没有餐盒这个商品,所以把这个费用分摊到其它商品中
bool bDisShop=false; //是否已经计算商户优惠金额 bool bDisShop=false; //是否已经计算商户优惠金额
bool bBoxRateFee=false; //是否已经计算餐盒平台服务费
int iDisShopIndex=0; //写入商户优惠的商品索引 int iDisShopIndex=0; //写入商户优惠的商品索引
float fRateProShop=0.00; //使用商户优惠商品的折扣率; float fRateProShop=0.00; //使用商户优惠商品的折扣率;
int itemIndex=0; int itemIndex=0;
for(auto dish:vecDish){ for(auto dish:vecDish){
bool bDiscOnItem=false;
itemIndex++; itemIndex++;
float price_product=dish.original_price/100.00; //商品单价 float price_product=dish.original_price/100.00; //商品单价
float discount_product=price_product*disRate; //折扣金额
float tot_product=dish.original_price*dish.consume_num/100.00; //商品总额 float tot_product=dish.original_price*dish.consume_num/100.00; //商品总额
float discount_product=tot_product*disRate; //折扣金额
std::string dish_name=""; std::string dish_name="";
int print1=0,print2=0,print3=0,print4=0,print5=0,cat=0,dept=0; int print1=0,print2=0,print3=0,print4=0,print5=0,cat=0,dept=0;
if(!bDisShop&&price_product>(discount_product+order.dis_shop_fee/100.00)){ if(!bDisShop&&order.dis_shop_fee>0&&tot_product>((tot_product-order.dis_shop_fee/100.00)*disRate+order.dis_shop_fee/100.00)){
discount_product+=order.dis_shop_fee/100.00; discount_product=(tot_product-order.dis_shop_fee/100.00)*disRate+order.dis_shop_fee/100.00;
iDisShopIndex=itemIndex; iDisShopIndex=itemIndex;
fRateProShop=order.dis_shop_fee*1.00/dish.original_price; fRateProShop=order.dis_shop_fee*1.00/(dish.original_price*dish.consume_num);
bDisShop=true; bDisShop=true;
//写入商品折扣表 //写入商品折扣表
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_DiscOnItem(`Date`,`Check`,Outlet, DiscIdx,ItemIdx,DiscTot) \ snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_DiscOnItem(`Date`,`Check`,Outlet, DiscIdx,ItemIdx,DiscTot) \
VALUES('%s',%d,%d,2,%d,%.2f)", strDate.data(),orderId,iOutlet,itemIndex,-order.dis_shop_fee/100.00); VALUES('%s',%d,%d,1,%d,%.2f)", strDate.data(),orderId,iOutlet,itemIndex,-order.dis_shop_fee/100.00);
nErrCode = mysql->insert(); nErrCode = mysql->insert();
if(nErrCode != EC_OK) if(nErrCode != EC_OK)
{ {
...@@ -351,11 +358,19 @@ int COrderInfo::SetTakeawayOrder(TakeawayOrder &order) ...@@ -351,11 +358,19 @@ int COrderInfo::SetTakeawayOrder(TakeawayOrder &order)
pthread_mutex_unlock(&mutex); //解锁 pthread_mutex_unlock(&mutex); //解锁
return EC_EX_SQL_FAILED; return EC_EX_SQL_FAILED;
} }
}
if(!bBoxRateFee&&price_product>(discount_product+fBoxRateFee)){ snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_DiscOnItem(`Date`,`Check`,Outlet, DiscIdx,ItemIdx,DiscTot) \
discount_product+=fBoxRateFee; VALUES('%s',%d,%d,2,%d,%.2f)", \
bBoxRateFee=true; strDate.data(),orderId,iOutlet,itemIndex,-(tot_product-order.dis_shop_fee/100.00)*disRate);
nErrCode = mysql->insert();
if(nErrCode != EC_OK)
{
rollbackData(orderIdStr);
pthread_mutex_unlock(&mutex); //解锁
return EC_EX_SQL_FAILED;
}
LOG(INFO)<<"tot_product-order.dis_shop_fee/100.00:"<<tot_product-order.dis_shop_fee/100.00<<" disRate:"<<disRate<<" :"<<-(tot_product-order.dis_shop_fee/100.00)*disRate;
bDiscOnItem=true;
} }
//查询商品详细信息 //查询商品详细信息
...@@ -394,19 +409,27 @@ int COrderInfo::SetTakeawayOrder(TakeawayOrder &order) ...@@ -394,19 +409,27 @@ int COrderInfo::SetTakeawayOrder(TakeawayOrder &order)
return EC_EX_SQL_FAILED; return EC_EX_SQL_FAILED;
} }
//商品折扣列表 if(!bDiscOnItem){
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_DiscOnItem(`Date`,`Check`,Outlet, DiscIdx,ItemIdx,DiscTot) \ //商品折扣列表
VALUES('%s',%d,%d,1,%d,%.2f)", \ int discType=1;
strDate.data(),orderId,iOutlet,itemIndex,-price_product*disRate); if(order.dis_shop_fee>0)
nErrCode = mysql->insert(); discType=2;
if(nErrCode != EC_OK)
{ snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_DiscOnItem(`Date`,`Check`,Outlet, DiscIdx,ItemIdx,DiscTot) \
rollbackData(orderIdStr); VALUES('%s',%d,%d,%d,%d,%.2f)", \
pthread_mutex_unlock(&mutex); //解锁 strDate.data(),orderId,iOutlet,discType,itemIndex,-tot_product*disRate);
return EC_EX_SQL_FAILED; nErrCode = mysql->insert();
LOG(INFO)<<"tot_product:"<<tot_product<<" disRate:"<<disRate<<" -tot_product*disRate:"<<-tot_product*disRate;
if(nErrCode != EC_OK)
{
rollbackData(orderIdStr);
pthread_mutex_unlock(&mutex); //解锁
return EC_EX_SQL_FAILED;
}
} }
} }
//支付信息吸入“支付详情表” //支付信息吸入“支付详情表”
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_Payment(`Date`,`Check`,Outlet,PayIdx,PayNo,Name3,PayEmp,PayTime,PayStation,PayTot,PayClass,Member,\ snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_Payment(`Date`,`Check`,Outlet,PayIdx,PayNo,Name3,PayEmp,PayTime,PayStation,PayTot,PayClass,Member,\
IsModified,LastModifiedTime)\ IsModified,LastModifiedTime)\
...@@ -438,7 +461,7 @@ int COrderInfo::SetTakeawayOrder(TakeawayOrder &order) ...@@ -438,7 +461,7 @@ int COrderInfo::SetTakeawayOrder(TakeawayOrder &order)
} }
if(order.dis_shop_fee>0){ if(order.dis_shop_fee>0){
float dis_shop=(order.service_fee)/100.00; //折扣金额 float dis_shop=(order.dis_shop_fee)/100.00; //折扣金额
float shopRate=(order.dis_shop_fee*1.00)/order.products_fee; float shopRate=(order.dis_shop_fee*1.00)/order.products_fee;
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_Disc(`Date`,`Check`,Outlet,DiscIdx,DiscNo,Name1,Name2,Name3,ItemIdx,StartLevel,EndLevel,ApplyTime,\ snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_Disc(`Date`,`Check`,Outlet,DiscIdx,DiscNo,Name1,Name2,Name3,ItemIdx,StartLevel,EndLevel,ApplyTime,\
ApplyStation,ApplyEmp,IsDiscBefore,Rate,DiscTot)\ ApplyStation,ApplyEmp,IsDiscBefore,Rate,DiscTot)\
...@@ -492,6 +515,8 @@ int COrderInfo::CancleTakeaway(TakeawayOrder &order) ...@@ -492,6 +515,8 @@ int COrderInfo::CancleTakeaway(TakeawayOrder &order)
nErrCode = mysql->remove(); nErrCode = mysql->remove();
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE,"DELETE FROM tbl_Disc WHERE `Check`=%d;",iOrderId); snprintf(mysql->sqlStr,SQL_BUFFER_SIZE,"DELETE FROM tbl_Disc WHERE `Check`=%d;",iOrderId);
nErrCode = mysql->remove(); nErrCode = mysql->remove();
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE,"DELETE FROM tbl_DiscOnItem WHERE `Check`=%d;",iOrderId);
nErrCode = mysql->remove();
//更新外卖订单记录为已退单,同时修改订单orderid ,规则,orderid后加‘_1’ //更新外卖订单记录为已退单,同时修改订单orderid ,规则,orderid后加‘_1’
std::string newOrderId = strOrderId+"_1"; std::string newOrderId = strOrderId+"_1";
...@@ -747,6 +772,9 @@ void COrderInfo::rollbackData(std::string orderid) ...@@ -747,6 +772,9 @@ void COrderInfo::rollbackData(std::string orderid)
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE,"DELETE FROM tbl_Disc WHERE `Check`=%d;",iOrderId); snprintf(mysql->sqlStr,SQL_BUFFER_SIZE,"DELETE FROM tbl_Disc WHERE `Check`=%d;",iOrderId);
mysql->remove(); mysql->remove();
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE,"DELETE FROM tbl_DiscOnItem WHERE `Check`=%d;",iOrderId);
mysql->remove();
} }
int COrderInfo::PrintLable(LableObj &printObj) int COrderInfo::PrintLable(LableObj &printObj)
......
...@@ -111,12 +111,12 @@ private: ...@@ -111,12 +111,12 @@ private:
pthread_mutex_t mutex; //互斥锁 pthread_mutex_t mutex; //互斥锁
MySQLService *mysql; MySQLService *mysql;
DB db; DB db;
char* _tempLatin1; //utf8转换为Latin1后,存放在此变量中
std::string strMonitorDeamon; //monitor守护进程脚本文件路径 std::string strMonitorDeamon; //monitor守护进程脚本文件路径
std::string strTakeoutDeamon; //takeout守护进程脚本文件路径 std::string strTakeoutDeamon; //takeout守护进程脚本文件路径
int _merchantDisId; //优惠类型id(商户减免) int _merchantDisId; //优惠类型id(商户减免)
int _plantformFeeId; //优惠类型id(平台服务费) int _plantformFeeId; //优惠类型id(平台服务费)
std::string _boxSku; //餐盒SKU
}; };
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment