外卖订单生成分析

http://192.168.1.126/store.php?ctl=tview&act=menuorder
module:app/Lib/store/tviewModule.class.php
action:menuorder
提交参数
sid(商户id):9
contacter(联系人):王五
sex(性别):1
tel(联系电话):13012345678
address(地址):测试地址
msg(留言):留言


public function menuorder()
{
convert_req($_REQUEST);
$return = array("status"=>0,"message"=>"");

if($GLOBALS['user_info']) {
$return['status']=1;
$sid = intval($_REQUEST['sid']);

//判断餐厅id
if($sid==0){
$return['status']=0;
$return['message']="请选择餐厅!";
ajax_return($return);
}

//获取餐厅实体
$store_info = $GLOBALS['db']->getRowCached("select takeaway_price,takeaway_nums,takeaway_tel from ".DB_PREFIX."supplier_location where id = ".$sid." and is_effect = 1");

//不存在则退出
if(!$store_info)
exit();

$data['supplier_location_id'] = $sid;
$data['user_id'] = $GLOBALS['user_info']['id'];

//获取该餐厅所有菜单
$templist = $GLOBALS['db']->getAllCached("SELECT id,name,price FROM ".DB_PREFIX."supplier_location_menu WHERE supplier_location_id=".$sid." ORDER BY id DESC");
$list = array();
$all_nums = 0;
$all_price = 0;

//从session中获取用户的点菜信息
foreach($templist as $k=>$v){
$nums = es_session::get("cho_nums_".$v['id']);
if(intval($nums) > 0){
$templist[$k]['nums'] = $nums;
$list[]=$templist[$k];
$all_nums += $nums;
$all_price += $v['price'];
}
}

//判断起送金额
if(floatval($all_price) < floatval($store_info['takeaway_price'])){
$return['status']=0;
$return['message']="起送价格不够哦!";
ajax_return($return);
}

//判断起送份数
if(intval($all_nums) < intval($store_info['takeaway_nums'])){
$return['status']=0;
$return['message']="起送份数不够哦!";
ajax_return($return);
}

//开始表单验证
$data['contacter'] = htmlspecialchars(addslashes(trim($_REQUEST['contacter'])));
if($data['contacter']==""){
$return['status']=0;
$return['message']="请填写您的称呼!";
ajax_return($return);
}
$data['sex'] = intval($_REQUEST['sex']);

$data['tel'] = htmlspecialchars(addslashes(trim($_REQUEST['tel'])));
if($data['tel']==""){
$return['status']=0;
$return['message']="请填写您的联系电话!";
ajax_return($return);
}
$data['address'] = htmlspecialchars(addslashes(trim($_REQUEST['address'])));
if($data['address']==""){
$return['status']=0;
$return['message']="请填写您的送餐地址!";
ajax_return($return);
}
$data['msg'] = htmlspecialchars(addslashes(trim($_REQUEST['msg'])));
$data['create_time'] = get_gmtime();

//提交间隔判断
if(!check_ipop_limit(get_client_ip(),"store_torder",intval(app_conf("SUBMIT_DELAY")))){
ajax_return(array("status"=>false,"message"=>$GLOBALS['lang']['SUBMIT_TOO_FAST']));
}

//用户点菜信息序列化
if($list){
$data['cache_data'] = addslashes(serialize($list));
//生成外卖订单
do
{
$data['order_sn'] = to_date(get_gmtime(),"Ymdhis").rand(10,99);
$GLOBALS['db']->autoExecute(DB_PREFIX."takeaway_order",$data,'INSERT','','SILENT');
$order_id = intval($GLOBALS['db']->insert_id());
}while($order_id==0);

if($order_id > 0) {
//删除session中的菜单
foreach($list as $k=>$v) {
$nums = es_session::get("cho_nums_".$v['id']);
if(intval($nums) > 0){
$GLOBALS['db']->query("UPDATE ".DB_PREFIX."supplier_location_menu SET collect_nums = collect_nums + 1 WHERE id=".$v['id']);
}
es_session::delete("cho_nums_".$v['id']);
}


//发短信
if(app_conf("SMS_SEND_TAKEAWAY_STORE")==1 && $store_info['takeaway_tel']!=''){
$msg= "菜单:";
foreach($list as $kk=>$vv){
if($kk!=0)
$msg .=",";
$msg .= $vv['name']."×".$vv['nums'];
}

$msg .="。联系人:".$data['contacter'];
$msg .=",联系电话:".$data['tel'];
$msg .=",送餐地址:".$data['address'];
if($data['msg'])
$msg .=",备注:".$data['msg'];
$msg .= "。";

$msg_data['send_type'] = 0;
$msg_data['content'] = addslashes($msg);
$msg_data['send_time'] = 0;
$msg_data['is_send'] = 0;
$msg_data['create_time'] = get_gmtime();
$msg_data['user_id'] = intval($GLOBALS['user_info']['id']);
$msg_data['is_html'] = 0;
$msg_data['is_youhui'] = 4;
$msg_data['dest'] = $store_info['takeaway_tel'];
$GLOBALS['db']->autoExecute(DB_PREFIX."deal_msg_list",$msg_data,"INSERT"); //插入
}

$return['status']=1;
ajax_return($return);
}
else{
$return['status']=0;
$return['message']="处理数据失败!";
ajax_return($return);
}
}
else{
$return['status']=1;
ajax_return($return);
}
}
else{
//提示登录
$return['status']=2;
ajax_return($return);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值