Commit c345f981 by guanghui.cui

订单入库:如果菜品中含有套餐,先查询出套餐中菜品,然后把所有菜品一块写入销售单

parent 61a4d940
......@@ -33,8 +33,8 @@ struct FM_ORDER_INFO
struct TakeawayProduct
{
int consume_num; //数量
int original_price; //商品编码
std::string pid; //外卖平台上的单价
int original_price; //外卖平台上的单价
std::string pid; //商品编码
};
//外卖销售单
......
......@@ -234,24 +234,64 @@ int COrderInfo::SetTakeawayOrder(TakeawayOrder &order)
mysql_free_result(mysql->_result);
//订单写入“订单表”
float discount=0.00; //折扣金额
float discount=(order.service_fee+order.dis_shop_fee)/100.00; //折扣金额
float merchantTot=(order.products_fee-order.service_fee-order.dis_shop_fee)/100.00; //商户实际应到账金额
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,\
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')", \
strDate.data(),orderId,orderIdStr,iOutlet,chTime,chTime,chTime,order.shop_fee/100.00,order.shop_fee/100.00,discount,order.shop_fee/100.00,chTime);
strDate.data(),orderId,orderIdStr,iOutlet,chTime,chTime,chTime,merchantTot,order.shop_fee/100.00,discount,merchantTot,chTime);
nErrCode = mysql->insert();
//获取商品详细信息,如果是套餐,把套餐菜品加入vector
std::vector<DishInfo> vecDish;
for(auto product:order.vecProducts){
DishInfo info={0,0,"",0,0,1,"1"};
info.pid=product.pid;
info.consume_num=product.consume_num;
info.original_price=product.original_price;
//查询是否套餐
int suit=0;
int childCount=0;
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE,"SELECT IsSetMenu FROM tbl_Menu WHERE Item='%s';",product.pid.data());
nErrCode = mysql->query();
if (NULL != (mysql->_row = mysql_fetch_row(mysql->_result))){
suit=atoi(mysql->_row[0]);
mysql_free_result(mysql->_result);
if(1==suit){//是套餐
int pIndex=vecDish.size()+1;
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE,"SELECT ChildItem,UnitQty FROM tbl_SetMenu WHERE ParentItem='%s';",product.pid.data());
nErrCode = mysql->query();
while ((mysql->_row = mysql_fetch_row(mysql->_result)) != NULL){
DishInfo childInfo={0,0,"",0,0,2,"0"};
childInfo.pid=mysql->_row[0];
childInfo.consume_num=atoi(mysql->_row[1]);
childInfo.index=pIndex;
vecDish.push_back(childInfo);
childCount++;
}
mysql_free_result(mysql->_result);
}
}
else
mysql_free_result(mysql->_result);
info.childCount=childCount;
vecDish.push_back(info);
}
//订单商品写入“订单详情表”
for(std::vector<TakeawayProduct>::size_type i=0;i<order.vecProducts.size();i++){
int itemIndex=0;
for(auto dish:vecDish){
itemIndex++;
float discount_product=0.00; //折扣金额
float price_product=order.vecProducts[i].original_price/100.00; //商品单价
float tot_product=order.vecProducts[i].original_price*order.vecProducts[i].consume_num/100.00; //商品总额
float price_product=dish.original_price/100.00; //商品单价
float tot_product=dish.original_price*dish.consume_num/100.00; //商品总额
std::string dish_name="";
int print1=0,print2=0,print3=0,print4=0,print5=0,cat=0;
int print1=0,print2=0,print3=0,print4=0,print5=0,cat=0,dept=0;
//查询商品详细信息
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE,"SELECT Name3,PrintQ1,PrintQ2,PrintQ3,PrintQ4,PrintQ5,Category FROM tbl_Menu WHERE Item='%s';",order.vecProducts[i].pid.data());
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE,"SELECT Name3,PrintQ1,PrintQ2,PrintQ3,PrintQ4,PrintQ5,Category,Dept FROM tbl_Menu WHERE Item='%s';",dish.pid.data());
nErrCode = mysql->query();
if (NULL != (mysql->_row = mysql_fetch_row(mysql->_result))){
dish_name=mysql->_row[0];
......@@ -261,24 +301,58 @@ int COrderInfo::SetTakeawayOrder(TakeawayOrder &order)
print4=atoi(mysql->_row[4]);
print5=atoi(mysql->_row[5]);
cat=atoi(mysql->_row[6]);
dept=atoi(mysql->_row[7]);
}
mysql_free_result(mysql->_result);
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_Item(`Date`,`Check`,Outlet,ItemIdx,Item,Name3,NameS3,`Type`,OrderTime,OrderStation,OrderEmp,\
PrintQ1,PrintQ2,PrintQ3,PrintQ4,PrintQ5,IsPrintOnCheck,PrintStatus,PrintCheckStatus,PrintedOnCheck,OgnPrice,Price,PriceLevel,ModiMethod,\
DiscBefore,UnitQty,Qty,ItemTot,RvDiscBefore,RvItemTot,Dept,Category,IsItemModified,LastModifiedTime)\
VALUES('%s',%d,%d,%d,'%s','%s','%s',1,'%s',99,4,%d,%d,%d,%d,%d,'1',4,'1',1,%.2f,%.2f,1,-1,%.2f,1,%d,%.2f,%.2f,%.2f,3,%d,1,'%s')", \
strDate.data(),orderId,iOutlet,i+1,order.vecProducts[i].pid.data(),dish_name.data(),dish_name.data(),chTime,print1,print2,print3,print4,\
print5,price_product,price_product,discount_product,\
order.vecProducts[i].consume_num,tot_product,discount_product,tot_product,cat,chTime);
DiscBefore,UnitQty,Qty,ItemTot,RvDiscBefore,RvItemTot,Dept,Category,IsItemModified,LastModifiedTime,ParentItemIdx,ChildCount)\
VALUES('%s',%d,%d,%d,'%s','%s','%s',%d,'%s',99,4,%d,%d,%d,%d,%d,'%s',4,'1',1,%.2f,%.2f,1,-1,%.2f,1,%d,%.2f,%.2f,%.2f,%d,%d,1,'%s',%d,%d)", \
strDate.data(),orderId,iOutlet,itemIndex,dish.pid.data(),dish_name.data(),dish_name.data(),dish.type,chTime,print1,print2,print3,print4,\
print5,dish.isPrintCheck.data(),price_product,price_product,discount_product,\
dish.consume_num,tot_product,discount_product,tot_product,dept,cat,chTime,dish.index,dish.childCount);
nErrCode = mysql->insert();
}
// //订单商品写入“订单详情表”
// for(std::vector<TakeawayProduct>::size_type i=0;i<order.vecProducts.size();i++){
// float discount_product=0.00; //折扣金额
// float price_product=order.vecProducts[i].original_price/100.00; //商品单价
// float tot_product=order.vecProducts[i].original_price*order.vecProducts[i].consume_num/100.00; //商品总额
// std::string dish_name="";
// int print1=0,print2=0,print3=0,print4=0,print5=0,cat=0,dept=0;
// //查询商品详细信息
// snprintf(mysql->sqlStr,SQL_BUFFER_SIZE,"SELECT Name3,PrintQ1,PrintQ2,PrintQ3,PrintQ4,PrintQ5,Category,Dept FROM tbl_Menu WHERE Item='%s';",order.vecProducts[i].pid.data());
// nErrCode = mysql->query();
// if (NULL != (mysql->_row = mysql_fetch_row(mysql->_result))){
// dish_name=mysql->_row[0];
// print1=atoi(mysql->_row[1]);
// print2=atoi(mysql->_row[2]);
// print3=atoi(mysql->_row[3]);
// print4=atoi(mysql->_row[4]);
// print5=atoi(mysql->_row[5]);
// cat=atoi(mysql->_row[6]);
// dept=atoi(mysql->_row[7]);
// }
// mysql_free_result(mysql->_result);
// snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_Item(`Date`,`Check`,Outlet,ItemIdx,Item,Name3,NameS3,`Type`,OrderTime,OrderStation,OrderEmp,\
// PrintQ1,PrintQ2,PrintQ3,PrintQ4,PrintQ5,IsPrintOnCheck,PrintStatus,PrintCheckStatus,PrintedOnCheck,OgnPrice,Price,PriceLevel,ModiMethod,\
// DiscBefore,UnitQty,Qty,ItemTot,RvDiscBefore,RvItemTot,Dept,Category,IsItemModified,LastModifiedTime)\
// VALUES('%s',%d,%d,%d,'%s','%s','%s',1,'%s',99,4,%d,%d,%d,%d,%d,'1',4,'1',1,%.2f,%.2f,1,-1,%.2f,1,%d,%.2f,%.2f,%.2f,%d,%d,1,'%s')", \
// strDate.data(),orderId,iOutlet,i+1,order.vecProducts[i].pid.data(),dish_name.data(),dish_name.data(),chTime,print1,print2,print3,print4,\
// print5,price_product,price_product,discount_product,\
// order.vecProducts[i].consume_num,tot_product,discount_product,tot_product,dept,cat,chTime);
// nErrCode = mysql->insert();
// }
//支付信息吸入“支付详情表”
snprintf(mysql->sqlStr,SQL_BUFFER_SIZE, "INSERT INTO tbl_Payment(`Date`,`Check`,Outlet,PayIdx,PayNo,Name3,PayEmp,PayTime,PayStation,PayTot,PayClass,Member,\
IsModified,LastModifiedTime)\
VALUES('%s',%d,%d,1,%d,'%s',4,'%s',99,%.2f,1,'',1,'%s')", \
strDate.data(),orderId,iOutlet,atoi(posTakeway.merchantTypeId.data()),posTakeway.strName.data(),chTime,order.shop_fee/100.00,chTime);
strDate.data(),orderId,iOutlet,atoi(posTakeway.merchantTypeId.data()),posTakeway.strName.data(),chTime,merchantTot,chTime);
nErrCode = mysql->insert();
pthread_mutex_unlock(&mutex); //解锁
return 0;
......
......@@ -11,6 +11,18 @@
#define IN
#define OUT
//菜品信息(兼容套餐)
struct DishInfo
{
int consume_num; //数量
int original_price; //价格
std::string pid; //商品编码
int index; //父商品索引
int childCount; //子类数量
int type;
std::string isPrintCheck;
};
class COrderInfo:public IOperation
{
public:
......
......@@ -153,6 +153,64 @@ DWORD WINAPI FunPayRecv(LPVOID lpParamter)
}
*/
//外卖线程
#define CHINA_CHAR_START 0x80
#define LATIN_CTRL_START 0x80
#define LATIN_CTRL_END 0x9F
#define C_MASK 0x7F
//转换前后长度不变
void utf8_to_latin1(char * pcSrcStr, char *pcDstStr)
{
int strLen = strlen(pcSrcStr);
for(int idx = 0; idx < strLen; idx++)
{
unsigned char cc = (unsigned char)pcSrcStr[idx];
if (LATIN_CTRL_START <= cc && LATIN_CTRL_END >= cc)
{
cc &= C_MASK;
cc += 1;
}
pcDstStr[idx] = cc;
}
pcDstStr[strLen] = 0;
}
//转换前后长度不变,pcSrcStr从数据库里读出来后,要在最后一字符后面一个字节置0,即字符结束符
void latin1_to_utf8(char * pcSrcStr, char *pcDstStr)
{
int strLen = strlen(pcSrcStr);
int cFlag = 0;
for(int idx = 0; idx < strLen; idx++)
{
unsigned char cc = (unsigned char)pcSrcStr[idx];
if (cFlag)
{
if (CHINA_CHAR_START > cc)
{
cc--;
cc |= (~C_MASK);
}
cFlag = 0;
}
else
{
if (CHINA_CHAR_START <= cc)
{
cFlag = 1;
}
}
pcDstStr[idx] = cc;
}
pcDstStr[strLen] = 0;
}
void *FunTakeaway(void* lpParamter)
{
int socket_fd, connect_fd;
......@@ -208,6 +266,19 @@ void *FunTakeaway(void* lpParamter)
//int lenGBK = CCodeConv::UTF8ToGBK(takeWayRecvBuf,NULL,NULL);
//char* strGBK = new char[lenGBK];
//CCodeConv::UTF8ToGBK(takeWayRecvBuf,strGBK,lenGBK);
//--------------------test
// char* latinbuf = new char[rlt+1];
// utf8_to_latin1(takeWayRecvBuf,latinbuf);
// LOG(INFO)<<"++++++++utf8转latin:"<<latinbuf;
// char* utf8buf = new char[rlt+1];
// latin1_to_utf8(latinbuf,utf8buf);
// LOG(INFO)<<"++++++++latin转utf8:"<<utf8buf;
// delete[] utf8buf;
// delete[] latinbuf;
//---------------test end
//
LOG(INFO)<<"外卖请求:"<<takeWayRecvBuf;
order.vecProducts.clear();
GetTakeawayOrder(takeWayRecvBuf,order);
......@@ -346,6 +417,7 @@ int socketRecvData(char * recvBuf, int bufSize, int socket_fd)
//socket error
rlt = -1;
LOG(ERROR)<<"socket recv 返回值:"<<length;
break;
}
}
return rlt;
......
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