예제 #1
0
 public function makeorder()
 {
     $subtype = intval(IReq::get("subtype"));
     $info['shopid'] = intval(IReq::get("shopid"));
     $info['remark'] = IFilter::act(IReq::get("content"));
     $info['paytype'] = IFilter::act(IReq::get("paytype"));
     $info['username'] = IFilter::act(IReq::get("contactname"));
     $info['mobile'] = IFilter::act(IReq::get("phone"));
     $info['addressdet'] = IFilter::act(IReq::get("addressdet"));
     $info['senddate'] = IFilter::act(IReq::get("senddate"));
     $info['minit'] = IFilter::act(IReq::get("orderTime"));
     $info['juanid'] = intval(IReq::get("juanid"));
     $info['ordertype'] = 1;
     $peopleNum = IFilter::act(IReq::get("personcount"));
     $info['othercontent'] = empty($peopleNum) ? "" : serialize(array("人数" => $peopleNum));
     $info['userid'] = !isset($this->member['score']) ? "0" : $this->member['uid'];
     if (Mysite::$app->config['allowedguestbuy'] != 1 && $info['userid'] == 0) {
         $this->message("member_nologin");
     }
     $shopinfo = $this->mysql->select_one("select * from " . Mysite::$app->config['tablepre'] . "shopfast as a left join " . Mysite::$app->config['tablepre'] . "shop as b  on a.shopid = b.id where a.shopid = '" . $info['shopid'] . "'    ");
     if (empty($shopinfo)) {
         $this->message("店铺不存在");
     }
     $checksend = Mysite::$app->config['ordercheckphone'];
     if ($checksend == 1 && empty($this->member['uid'])) {
         $checkphone = $this->mysql->select_one("select * from " . Mysite::$app->config['tablepre'] . "mobile where phone ='" . $info['mobile'] . "'   order by addtime desc limit 0,50");
         if (empty($checkphone)) {
             $this->message("member_emailyan");
         }
         if (empty($checkphone['is_send'])) {
             $mycode = IFilter::act(IReq::get("phonecode"));
             if ($mycode == $checkphone['code']) {
                 $this->mysql->update(Mysite::$app->config['tablepre'] . "mobile", array("is_send" => 1), "phone='" . $info['mobile'] . "'");
             } else {
                 $this->message("member_emailyan");
             }
         }
     }
     if (empty($info['username'])) {
         $this->message("emptycontact");
     }
     if (!IValidate::suremobi($info['mobile'])) {
         $this->message("errphone");
     }
     $info['ipaddress'] = "";
     $ip_l = new iplocation();
     $ipaddress = $ip_l->getaddress($ip_l->getIP());
     if (isset($ipaddress['area1'])) {
         $info['ipaddress'] = $ipaddress['ip'] . mb_convert_encoding($ipaddress['area1'], "UTF-8", "GB2312");
     }
     $info['cattype'] = 0;
     $senddate = $info['senddate'];
     $minit = $info['minit'];
     $nowpost = strtotime($senddate . " " . $minit . ":00");
     $settime = time() - 600;
     if ($nowpost < $settime) {
         $this->message("提交配送时间和服务器时间相差超过10分钟下单失败");
     }
     $temp = strtotime($minit . ":00");
     $is_orderbefore = $shopinfo['is_orderbefore'] == 0 ? 0 : $shopinfo['befortime'];
     $tempinfo = $this->checkshopopentime($is_orderbefore, $nowpost, $shopinfo['starttime']);
     if (!$tempinfo) {
         $this->message("配送时间不在有效配送时间范围");
     }
     if ($shopinfo['is_open'] != 1) {
         $this->message("店铺暂停营业");
     }
     $info['paytype'] = $info['paytype'] == 1 ? 1 : 0;
     $info['areaids'] = "";
     $info['shopinfo'] = $shopinfo;
     if ($subtype == 1) {
         $info['allcost'] = 0;
         $info['bagcost'] = 0;
         $info['allcount'] = 0;
         $info['goodslist'] = array();
     } else {
         if (empty($info['shopid'])) {
             $this->message("shop_noexit");
         }
         $Cart = new smCart();
         $Cart->cartName = 'platesmcart';
         $carinfo = $Cart->getMyCart();
         if (!isset($carinfo['list'][$info['shopid']]['data'])) {
             $this->message("shop_emptycart");
         }
         $info['allcost'] = $carinfo['list'][$info['shopid']]['sum'];
         $info['goodslist'] = $carinfo['list'][$info['shopid']]['data'];
         $info['bagcost'] = 0;
         $info['allcount'] = 0;
     }
     $info['shopps'] = 0;
     $info['pstype'] = 0;
     $info['cattype'] = 1;
     $info['is_goshop'] = 1;
     $info['subtype'] = $subtype;
     $info['sendtime'] = $nowpost;
     $orderclass = new orderclass($this->mysql);
     $orderclass->orderyuding($info);
     $orderid = $orderclass->getorder();
     if ($info['userid'] == 0) {
         ICookie::set("orderid", $orderid, 86400);
     }
     if ($subtype == 2) {
         $Cart->delshop($info['shopid']);
     }
     $this->success($orderid);
     exit;
 }
예제 #2
0
 function makeorder()
 {
     $info['shopid'] = intval(IReq::get('shopid'));
     //店铺ID
     $info['remark'] = IFilter::act(IReq::get('remark'));
     //备注
     $info['paytype'] = IFilter::act(IReq::get('paytype'));
     //支付方式
     $info['dikou'] = intval(IReq::get('dikou'));
     //抵扣金额
     $info['username'] = IFilter::act(IReq::get('username'));
     $info['mobile'] = IFilter::act(IReq::get('mobile'));
     $info['addressdet'] = IFilter::act(IReq::get('addressdet'));
     $info['senddate'] = IFilter::act(IReq::get('senddate'));
     $info['minit'] = IFilter::act(IReq::get('minit'));
     $info['juanid'] = intval(IReq::get('juanid'));
     //优惠劵ID
     $info['ordertype'] = 1;
     //订单类型
     $peopleNum = IFilter::act(IReq::get('peopleNum'));
     $info['othercontent'] = '';
     //empty($peopleNum)?'':serialize(array('人数'=>$peopleNum));
     if (empty($info['shopid'])) {
         $this->message('店铺ID错误');
     }
     $Cart = new smCart();
     $carinfo = $Cart->getMyCart();
     //print_r($carinfo);exit;
     if (!isset($carinfo['list'][$info['shopid']]['data'])) {
         $this->message('对应店铺购物车商品为空');
     }
     if ($carinfo['list'][$info['shopid']]['shopinfo']['shoptype'] == 1) {
         $shopinfo = $this->mysql->select_one("select * from " . Mysite::$app->config['tablepre'] . "shopmarket as a left join " . Mysite::$app->config['tablepre'] . "shop as b  on a.shopid = b.id where a.shopid = '" . $info['shopid'] . "'    ");
     } else {
         $shopinfo = $this->mysql->select_one("select * from " . Mysite::$app->config['tablepre'] . "shopfast as a left join " . Mysite::$app->config['tablepre'] . "shop as b  on a.shopid = b.id where a.shopid = '" . $info['shopid'] . "'    ");
     }
     if (empty($shopinfo)) {
         $this->message('店铺获取失败');
     }
     $checkps = $this->pscost($shopinfo, $carinfo['list'][$info['shopid']]['count']);
     if ($checkps['canps'] != 1) {
         $this->message('该店铺不在配送范围内');
     }
     $info['cattype'] = 0;
     //
     if (empty($info['username'])) {
         $this->message('联系人不能为空');
     }
     if (!IValidate::suremobi($info['mobile'])) {
         $this->message('请输入正确的手机号');
     }
     if (empty($info['addressdet'])) {
         $this->message('详细地址为空');
     }
     $info['userid'] = !isset($this->member['score']) ? '0' : $this->member['uid'];
     if (Mysite::$app->config['allowedguestbuy'] != 1) {
         if ($info['userid'] == 0) {
             $this->message('禁止游客下单');
         }
     }
     //判断库存
     $senddate = $info['senddate'];
     $minit = $info['minit'];
     $nowpost = strtotime($senddate . ' ' . $minit);
     $day = strtotime(date('Y-m-d', $nowpost));
     $goods_id_list = [];
     foreach ($carinfo['list'][$info['shopid']]['data'] as $key => $value) {
         $goods_id_list[] = $value['id'];
     }
     $goods_ids = implode(',', $goods_id_list);
     $stock_info_list = $this->mysql->getarr("SELECT goods_id,stock FROM " . Mysite::$app->config['tablepre'] . "daystock WHERE goods_id in ({$goods_ids}) AND day={$day}");
     $stock_list = [];
     foreach ($stock_info_list as $key => $value) {
         $stock_list[$value['goods_id']] = $value['stock'];
     }
     foreach ($carinfo['list'][$info['shopid']]['data'] as $key => $value) {
         if (!array_key_exists($value['id'], $stock_list)) {
             $stock_list[$value['id']] = 0;
         }
         if ($value['daycount'] - $stock_list[$value['id']] - $value['count'] < 0) {
             $this->message($valeu['name'] . '库存不足');
             exit;
         }
     }
     $ip_l = new iplocation();
     $ipaddress = $ip_l->getaddress($ip_l->getIP());
     if (isset($ipaddress["area1"])) {
         $info['ipaddress'] = $ipaddress['ip'] . mb_convert_encoding($ipaddress["area1"], 'UTF-8', 'GB2312');
         //('GB2312','ansi',);
     }
     //area1 二级地址名称	area2 三级地址名称	area3
     $nowID = intval(ICookie::get('myaddress'));
     if (!empty($nowid)) {
         if (empty($nowID)) {
             $this->message('未选择配送区域');
         }
         $checkareaid = $nowID;
         $dataareaids = array();
         while ($checkareaid > 0) {
             $temp_check = $this->mysql->select_one("select * from " . Mysite::$app->config['tablepre'] . "area where id ='" . $checkareaid . "'   order by id desc limit 0,50");
             if (empty($temp_check)) {
                 break;
             }
             if (in_array($checkareaid, $dataareaids)) {
                 break;
             }
             $dataareaids[] = $checkareaid;
             $checkareaid = $temp_check['parent_id'];
         }
         $data['areaids'] = join(',', $dataareaids);
     } else {
         $data['areaids'] = '';
     }
     $checksend = Mysite::$app->config['ordercheckphone'];
     if ($checksend == 1) {
         if (empty($this->member['uid'])) {
             $checkphone = $this->mysql->select_one("select * from " . Mysite::$app->config['tablepre'] . "mobile where phone ='" . $info['mobile'] . "'   order by addtime desc limit 0,50");
             if (empty($checkphone)) {
                 $this->message('短信验证码不能为空');
             }
             if (empty($checkphone['is_send'])) {
                 $mycode = IFilter::act(IReq::get('phonecode'));
                 if ($mycode == $checkphone['code']) {
                     $this->mysql->update(Mysite::$app->config['tablepre'] . 'mobile', array('is_send' => 1), "phone='" . $info['mobile'] . "'");
                 } else {
                     $this->message('验证码不一致');
                 }
             }
         }
     }
     $data['shopcost'] = 0;
     //:店铺商品总价
     $data['shopps'] = 0;
     //店铺配送费
     $data['shoptype'] = 0;
     //: 0:普通订单,1订台订单
     $data['bagcost'] = 0;
     //:打包费
     //获取店铺商品总价  获取超市商品总价
     $data['shopcost'] = $carinfo['list'][$info['shopid']]['sum'];
     $data['shopps'] = $checkps['pscost'];
     $data['bagcost'] = $carinfo['list'][$info['shopid']]['bagcost'];
     //支付方式检测
     $userid = $info['userid'];
     $data['paytype'] = $info['paytype'];
     $paytype = $info['paytype'];
     if ($paytype != 'outpay') {
         if ($paytype == 'open_acout') {
             if (Mysite::$app->config['open_acout'] != 1 || $userid == 0) {
                 $data['paytype'] = 'outpay';
             }
         } else {
             $paylist = $this->mysql->counts("select * from " . Mysite::$app->config['tablepre'] . "paylist where loginname='" . $paytype . "'  order by id desc  ");
             if ($paylist < 1) {
                 $data['paytype'] = 'outpay';
             }
         }
     }
     //判断促销
     $data['cxids'] = '';
     $data['cxcost'] = 0;
     $zpin = array();
     $cattype = $info['cattype'];
     if ($data['shopcost'] > 0) {
         $sellrule = new sellrule();
         $sellrule->setdata($info['shopid'], $data['shopcost'], $shopinfo['shoptype'], $day);
         $ruleinfo = $sellrule->getdata();
         $data['cxcost'] = $ruleinfo['downcost'];
         $data['cxids'] = $ruleinfo['cxids'];
         $zpin = $ruleinfo['zid'];
         //赠品
         $data['shopps'] = $ruleinfo['nops'] == true ? 0 : $data['shopps'];
     }
     //判断优惠劵
     $allcost = $data['shopcost'];
     $data['yhjcost'] = 0;
     $data['yhjids'] = '';
     $juanid = $info['juanid'];
     if ($juanid > 0 && $userid > 0) {
         $juaninfo = $this->mysql->select_one("select *  from " . Mysite::$app->config['tablepre'] . "juan  where id= '" . $juanid . "' and uid='" . $userid . "'  and status = 1 and endtime > " . time() . " ");
         if (!empty($juaninfo)) {
             if ($allcost >= $juaninfo['limitcost']) {
                 $data['yhjcost'] = $juaninfo['cost'];
                 $juandata['status'] = 2;
                 $juandata['usetime'] = time();
                 $this->mysql->update(Mysite::$app->config['tablepre'] . 'juan', $juandata, "id='" . $juanid . "'");
                 $data['yhjids'] = $juanid;
             }
         }
     }
     //积分抵扣
     $allcost = $allcost - $data['cxcost'] - $data['yhjcost'];
     $data['scoredown'] = 0;
     $dikou = $info['dikou'];
     if (!empty($userid) && $dikou > 0 && Mysite::$app->config['scoretocost'] > 0 && $allcost > $dikou) {
         $checkuser = $this->mysql->select_one("select * from " . Mysite::$app->config['tablepre'] . "member where uid='" . $userid . "'  ");
         if (is_array($checkuser)) {
             $checkscore = $dikou * intval(Mysite::$app->config['scoretocost']);
             if ($checkuser['score'] >= $checkscore) {
                 $data['scoredown'] = $checkscore;
                 $this->mysql->update(Mysite::$app->config['tablepre'] . 'member', '`score`=`score`-' . $checkscore, "uid ='" . $userid . "' ");
             }
         }
     }
     $dikou = $data['scoredown'] > 0 ? $dikou : 0;
     $allcost = $allcost - $dikou;
     $data['allcost'] = $allcost + $data['shopps'] + $data['bagcost'];
     //订单应收费用
     $data['shopuid'] = 0;
     // 店铺UID
     $data['shopid'] = 0;
     //店铺ID
     $data['shopname'] = '商城';
     //店铺名称
     $data['shopphone'] = Mysite::$app->config['marketphone'];
     //店铺电话
     $data['shopaddress'] = '';
     // 店铺地址
     $data['pstype'] = $checkps['pstype'];
     $data['shoptype'] = $shopinfo['shoptype'];
     //检测店铺
     $settime = time() - 600;
     if ($settime > $nowpost) {
         $this->message('提交配送时间和服务器时间相差超过10分钟下单失败');
     }
     $temp = strtotime($minit . ':00');
     $is_orderbefore = $shopinfo['is_orderbefore'] == 0 ? 0 : $shopinfo['befortime'];
     $tempinfo = $this->checkshopopentime($is_orderbefore, $nowpost, $shopinfo['starttime']);
     if (!$tempinfo) {
         $this->message('配送时间不在有效配送时间范围');
     }
     if ($shopinfo['is_open'] != 1) {
         $this->message('店铺暂停营业');
     }
     if ($shopinfo['limitcost'] > $allcost) {
         $this->message('商品总价低于最小起送价' . $shopinfo['limitcost']);
     }
     $data['shopuid'] = $shopinfo['uid'];
     // 店铺UID
     $data['shopid'] = $shopinfo['id'];
     //店铺ID
     $data['shopname'] = $shopinfo['shopname'];
     //店铺名称
     $data['shopphone'] = $shopinfo['phone'];
     //店铺电话
     $data['shopaddress'] = $shopinfo['address'];
     // 店铺地址
     $data['buyeraddress'] = $info['addressdet'];
     $data['ordertype'] = $info['ordertype'];
     //来源方式;
     $data['buyeruid'] = $userid;
     // 购买用户ID,0未注册用户
     $data['buyername'] = $info['username'];
     //购买热名称
     $data['buyerphone'] = $info['mobile'];
     // 联系电话
     $panduan = Mysite::$app->config['man_ispass'];
     $data['status'] = $panduan == 1 ? '0' : 1;
     $data['paystatus'] = 0;
     // 支付状态1已支付
     $data['content'] = $info['remark'];
     // 订单备注
     //  daycode 当天订单序号
     $data['ipaddress'] = $info['ipaddress'];
     $data['is_ping'] = 0;
     // 是否评价字段 1已评完 0未评
     $data['addtime'] = time();
     $data['posttime'] = $nowpost;
     //: 配送时间
     $data['othertext'] = $info['othercontent'];
     //其他说明
     $data['is_make'] = Mysite::$app->config['allowed_is_make'] == 1 ? 0 : 1;
     //  :审核时间
     $data['passtime'] = time();
     if ($data['status'] == 1) {
         $data['passtime'] == 0;
     }
     $data['buycode'] = substr(md5(time()), 9, 6);
     $data['dno'] = time() . rand(1000, 9999);
     $minitime = strtotime(date('Y-m-d', time()));
     $tj = $this->mysql->select_one("select count(id) as shuliang from " . Mysite::$app->config['tablepre'] . "order where shopid='" . $info['shopid'] . "' and addtime > " . $minitime . "  limit 0,1000");
     $data['daycode'] = $tj['shuliang'] + 1;
     $this->mysql->insert(Mysite::$app->config['tablepre'] . 'order', $data);
     //写主订单
     $orderid = $this->mysql->insertid();
     $this->orderid = $orderid;
     foreach ($carinfo['list'][$info['shopid']]['data'] as $key => $value) {
         $cmd['order_id'] = $orderid;
         $cmd['goodsid'] = $value['id'];
         $cmd['goodsname'] = $value['name'];
         $cmd['goodscost'] = $value['cost'];
         $cmd['goodscount'] = $value['count'];
         $cmd['shopid'] = $value['shopid'];
         $cmd['status'] = 0;
         $cmd['is_send'] = 0;
         $this->mysql->insert(Mysite::$app->config['tablepre'] . 'orderdet', $cmd);
         //减少库存pinkky
         $daystock = $this->mysql->select_one("SELECT * FROM " . Mysite::$app->config['tablepre'] . "daystock WHERE goods_id=" . $value['id'] . " and day=" . $day);
         if ($daystock) {
             $this->mysql->update(Mysite::$app->config['tablepre'] . 'daystock', '`stock`=`stock`+1', "id=" . $daystock['id']);
         } else {
             $stockdata['goods_id'] = $value['id'];
             $stockdata['day'] = $day;
             $stockdata['stock'] = 1;
             $this->mysql->insert(Mysite::$app->config['tablepre'] . 'daystock', $stockdata);
         }
         //$this->mysql->update(Mysite::$app->config['tablepre'].'goods','`count`=`count`-'.$cmd['goodscount'].' ,`sellcount`=`sellcount`+'.$cmd['goodscount'],"id='".$cmd['goodsid']."'");
         $this->mysql->update(Mysite::$app->config['tablepre'] . 'goods', '`sellcount`=`sellcount`+' . $cmd['goodscount'], "id='" . $cmd['goodsid'] . "'");
     }
     if (is_array($zpin) && count($zpin) > 0) {
         foreach ($zpin as $key => $value) {
             $datadet['order_id'] = $orderid;
             $datadet['goodsid'] = $key;
             $datadet['goodsname'] = $value['presenttitle'];
             $datadet['goodscost'] = 0;
             $datadet['goodscount'] = 1;
             $datadet['shopid'] = $shopinfo['id'];
             $datadet['status'] = 0;
             $datadet['is_send'] = 1;
             //更新促销规则中 此赠品的数量
             $this->mysql->insert(Mysite::$app->config['tablepre'] . 'orderdet', $datadet);
             $this->mysql->update(Mysite::$app->config['tablepre'] . 'rule', '`controlcontent`=`controlcontent`-1', "id='" . $key . "'");
         }
     }
     $checkbuyer = Mysite::$app->config['allowedsendbuyer'];
     $checksend = Mysite::$app->config['man_ispass'];
     if ($checksend != 1) {
         $orderCLs = new orderclass($this->mysql);
         $orderCLs->sendmess($orderid);
     }
     if ($userid == 0) {
         ICookie::set('orderid', $orderid, 86400);
     } else {
         //保持地址数据
         $checkinfo = $this->mysql->select_one("select * from " . Mysite::$app->config['tablepre'] . "address where userid='" . $userid . "'  ");
         if (empty($checkinfo)) {
             $addata['userid'] = $this->member['uid'];
             $addata['username'] = $this->member['username'];
             $addata['address'] = $data['buyeraddress'];
             $addata['phone'] = $data['buyerphone'];
             $addata['contactname'] = $data['buyername'];
             $addata['default'] = 1;
             $this->mysql->insert(Mysite::$app->config['tablepre'] . 'address', $addata);
         }
     }
     $Cart->delshop($info['shopid']);
     $this->success($orderid);
 }
예제 #3
0
 function delshopcart()
 {
     $shopid = intval(IReq::get('shopid'));
     if ($shopid < 0) {
         $this->message('店铺获取失败');
     }
     $Cart = new smCart();
     $plate = intval(IReq::get('plate'));
     if (!empty($plate)) {
         $Cart->cartName = 'platesmcart';
     }
     $Cart->delshop($shopid);
     $this->success('操作成功');
 }