Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 public function show()
 {
     $shop = trim(IFilter::act(IReq::get("id")));
     $where = 0 < intval($shop) ? " where a.shopid = " . $shop : "where shortname='" . $shop . "'";
     $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 . "   ");
     if (empty($shopinfo)) {
         $link = IUrl::creaturl("site/index");
         $this->message("获取店铺信息失败", $link);
     }
     if ($shopinfo['endtime'] < time()) {
         $link = IUrl::creaturl("site/index");
         $this->message("店铺已关门", $link);
     }
     $nowhour = date("H:i:s", time());
     $nowhour = strtotime($nowhour);
     $data['shopinfo'] = $shopinfo;
     $data['shopopeninfo'] = $this->shopIsopen($shopinfo['is_open'], $shopinfo['starttime'], $shopinfo['is_orderbefore'], $nowhour);
     $data['com_goods'] = $this->mysql->getarr("select *  from " . Mysite::$app->config['tablepre'] . "goods where shopid = " . $shopinfo['id'] . " and is_com = 1 and is_goshop=1 ");
     $goodstype = $this->mysql->getarr("select * from " . Mysite::$app->config['tablepre'] . "goodstype where shopid = " . $shopinfo['id'] . " and cattype = " . $shopinfo['shoptype'] . " and is_goshop=1 order by orderid asc");
     $data['goodstype'] = array();
     $tempids = array();
     foreach ($goodstype as $key => $value) {
         $value['det'] = $this->mysql->getarr("select *  from " . Mysite::$app->config['tablepre'] . "goods where typeid = " . $value['id'] . " and shopid=" . $shopinfo['id'] . " and  is_goshop=1");
         $tempids[] = $value['id'];
         $data['goodstype'][] = $value;
     }
     $data['mainattr'] = array();
     $templist = $this->mysql->getarr("select * from " . Mysite::$app->config['tablepre'] . "shoptype where  cattype = " . $shopinfo['shoptype'] . " and parent_id = 0 and is_main =1  order by orderid asc limit 0,1000");
     foreach ($templist as $key => $value) {
         $value['det'] = $this->mysql->getarr("select * from " . Mysite::$app->config['tablepre'] . "shoptype where parent_id = " . $value['id'] . " order by orderid asc  limit 0,20");
         $data['mainattr'][] = $value;
     }
     $data['shopattr'] = $this->mysql->getarr("select * from " . Mysite::$app->config['tablepre'] . "shopattr  where  cattype = " . $shopinfo['shoptype'] . " and shopid = '" . $shopinfo['id'] . "'  order by firstattr asc limit 0,1000");
     $data['goodsattr'] = array();
     $goodsattr = $this->mysql->getarr("select * from " . Mysite::$app->config['tablepre'] . "goodssign  where  type = 'goods'  order by id asc limit 0,1000");
     foreach ($goodsattr as $key => $value) {
         $data['goodsattr'][$value['id']] = $value['imgurl'];
     }
     $data['psinfo'] = $this->pscost($shopinfo, 1);
     $sellrule = new sellrule();
     $sellrule->setdata($shopinfo['shopid'], 1000, $shopinfo['shoptype']);
     $ruleinfo = $sellrule->getdata();
     $data['ruledata'] = array();
     if (isset($ruleinfo['cxids']) && $ruleinfo['cxids']) {
         $data['ruledata'] = $this->mysql->getarr("select * from " . Mysite::$app->config['tablepre'] . "rule  where  id in(" . $ruleinfo['cxids'] . ")  order by id asc limit 0,1000");
     }
     $cximglist = $this->mysql->getarr("select * from " . Mysite::$app->config['tablepre'] . "goodssign  where  type = 'cx'  order by id asc limit 0,1000");
     $data['ruleimg'] = array();
     foreach ($cximglist as $key => $value) {
         $data['ruleimg'][$value['id']] = $value['imgurl'];
     }
     $data['cxlist'] = $ruleinfo;
     $data['scoretocost'] = Mysite::$app->config['scoretocost'];
     $data['collect'] = array();
     if (!empty($this->memberinfo)) {
         $data['collect'] = $this->mysql->select_one("select * from " . Mysite::$app->config['tablepre'] . "collect where collectid=" . $shopinfo['id'] . " and collecttype = 0 and uid=" . $this->member['uid'] . " ");
     }
     $bzinfo = Mysite::$app->config['orderbz'];
     $data['bzlist'] = array();
     if (!empty($bzinfo)) {
         $data['bzlist'] = unserialize($bzinfo);
     }
     $addresslist = array();
     if (0 < $this->member['uid']) {
         $addresslist = $this->mysql->getarr("select * from " . Mysite::$app->config['tablepre'] . "address where userid=" . $this->member['uid'] . "  ");
     }
     $data['addresslist'] = $addresslist;
     $data['paylist'] = $this->mysql->getarr("select * from " . Mysite::$app->config['tablepre'] . "paylist   order by id desc  ");
     $data['juanlist'] = array();
     if (!empty($this->member['uid'])) {
         $data['juanlist'] = $this->mysql->getarr("select * from " . Mysite::$app->config['tablepre'] . "juan  where uid ='" . $this->member['uid'] . "'  and status = 1 and endtime > " . time() . "  order by id desc limit 0,20");
     }
     Mysite::$app->setdata($data);
 }
Exemplo n.º 3
0
 function makeorder()
 {
     $info['shopid'] = intval(IReq::get('shopid'));
     //店铺ID
     $info['remark'] = IFilter::act(IReq::get('remark'));
     //备注
     $info['paytype'] = 'outpay';
     //默认调用货到支付
     $info['dikou'] = 0;
     //不计算抵扣
     $info['username'] = IFilter::act(IReq::get('contactname'));
     //
     $info['mobile'] = IFilter::act(IReq::get('phone'));
     $info['addressdet'] = IFilter::act(IReq::get('address'));
     //
     $info['senddate'] = IFilter::act(IReq::get('senddate'));
     //
     $info['minit'] = IFilter::act(IReq::get('minit'));
     //
     $info['juanid'] = 0;
     //优惠劵ID 不计算优惠券
     $info['ordertype'] = 2;
     //订单类型
     //http://localhost/index.php?controller=order&action=makeorder&ids=349,351,352,230&nums=1,1,1,1&shopid=9&contactname=fdsa&phone=13540907240&address=%E6%A0%AA%E6%B4%B2%E6%96%B0%E7%8E%9B%E7%89%B9%E8%B4%AD%E7%89%A9%E5%B9%BF%E5%9C%BAfdsafdsa&areaid=9&senddate=2014-8-7%2018:15
     $ids = IFilter::act(IReq::get('ids'));
     if (empty($ids)) {
         $this->message('商品ID错误');
     }
     $num = IFilter::act(IReq::get('nums'));
     if (empty($num)) {
         $this->message('商品数量错误');
     }
     $tempids = explode(',', $ids);
     $tempnum = explode(',', $num);
     if (count($tempids) != count($tempnum)) {
         $this->message('商品数量和商品ID不一致');
     }
     $newid = array();
     $idtonum = array();
     foreach ($tempids as $key => $value) {
         if (!empty($value)) {
             $check1 = intval($value);
             $check2 = intval($tempnum[$key]);
             if ($check1 > 0 && $check2 > 0) {
                 $newid[] = $value;
                 $idtonum[$value] = $check2;
             }
         }
     }
     $whereid = join(',', $newid);
     if (empty($whereid)) {
         $this->message('数据错误');
     }
     $goodslist = $this->mysql->getarr("select * from " . Mysite::$app->config['tablepre'] . "goods where shopid =" . $info['shopid'] . " and id in(" . $whereid . ") ");
     //判断库存
     $senddate = $info['senddate'];
     $nowpost = strtotime($senddate);
     $day = strtotime(date('Y-m-d', $nowpost));
     $stock_info_list = $this->mysql->getarr("SELECT goods_id,stock FROM " . Mysite::$app->config['tablepre'] . "daystock WHERE goods_id in ({$whereid}) AND day={$day}");
     $stock_list = [];
     foreach ($stock_info_list as $key => $value) {
         $stock_list[$value['goods_id']] = $value['stock'];
     }
     foreach ($goodslist as $key => $value) {
         if ($value['daycount'] - $stock_list[$value['id']] - $idtonum[$value['id']] < 0) {
             $this->message($valeu['name'] . '库存不足');
             exit;
         }
     }
     $goodsdata = array();
     $bagsum = 0;
     $goodssum = 0;
     $goodsnum = 0;
     foreach ($goodslist as $key => $value) {
         $value['shuliang'] = $idtonum[$value['id']];
         $goodssum += $value['cost'] * intval($idtonum[$value['id']]);
         $value['xiaoij'] = $value['cost'] * intval($idtonum[$value['id']]);
         $bagsum += $value['bagcost'] * intval($idtonum[$value['id']]);
         $goodsnum += $value['shuliang'];
         $goodsdata[] = $value;
     }
     $shop = $this->mysql->select_one("select * from " . Mysite::$app->config['tablepre'] . "shop where id = " . $info['shopid'] . "   ");
     if (empty($info['shopid'])) {
         $this->message('店铺ID错误');
     }
     if ($shop['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'] . "'    ");
     }
     $nowID = intval(IFilter::act(IReq::get('areaid')));
     //$areaid intval(ICookie::get('myaddress'));
     if (empty($nowID)) {
         $this->message('未选择配送区域');
     }
     if (empty($shopinfo)) {
         $this->message('店铺获取失败');
     }
     $checkps = $this->pscost($shopinfo, $goodsnum, $nowID);
     if ($checkps['canps'] != 1) {
         $this->message('该店铺不在配送范围内');
     }
     $info['cattype'] = 0;
     //
     if (empty($info['username'])) {
         $this->message('联系人不能为空');
     }
     if (empty($info['addressdet'])) {
         $this->message('详细地址为空');
     }
     $info['userid'] = 0;
     $info['ipaddress'] = '管理员快捷下单';
     //area1 二级地址名称	area2 三级地址名称	area3
     $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);
     $data['shopcost'] = 0;
     //:店铺商品总价
     $data['shopps'] = 0;
     //店铺配送费
     $data['shoptype'] = 0;
     //: 0:普通订单,1订台订单
     $data['bagcost'] = 0;
     //:打包费
     //获取店铺商品总价  获取超市商品总价
     $data['shopcost'] = $goodssum;
     $data['shopps'] = $checkps['pscost'];
     $data['bagcost'] = $bagsum;
     //支付方式检测
     $userid = $info['userid'];
     $data['paytype'] = $info['paytype'];
     //判断促销
     $data['cxids'] = '';
     $data['cxcost'] = 0;
     $zpin = array();
     $cattype = $info['cattype'];
     if ($data['shopcost'] > 0) {
         $sellrule = new sellrule();
         $sellrule->setdata($info['shopid'], $data['shopcost'], $shop['shoptype'], $day);
         $ruleinfo = $sellrule->getdata();
         $data['cxcost'] = $ruleinfo['downcost'];
         $data['cxids'] = $ruleinfo['cxids'];
         $data['shopps'] = $ruleinfo['nops'] == true ? 0 : $data['shopps'];
         $zpin = $ruleinfo['zid'];
         //赠品
     }
     //判断优惠劵
     $allcost = $data['shopcost'];
     $data['yhjcost'] = 0;
     $data['yhjids'] = '';
     //积分抵扣
     $allcost = $allcost - $data['cxcost'] - $data['yhjcost'];
     $data['scoredown'] = 0;
     $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() - 10 * 60;
     if ($settime > $nowpost) {
         $this->message('提交配送时间和服务器时间相差超过10分钟下单失败');
     }
     $is_orderbefore = $shopinfo['is_orderbefore'] == 0 ? 0 : $shopinfo['befortime'];
     $tempinfo = $this->checkshopopentime($is_orderbefore, $nowpost, $shop['starttime']);
     if (!$tempinfo) {
         $this->message('配送时间不在有效配送时间范围');
     }
     if ($shop['is_open'] != 1) {
         $this->message('店铺暂停营业');
     }
     if ($allcost < $shopinfo['limitcost']) {
         $this->message('商品总价低于最小起送价' . $shopinfo['limitcost']);
     }
     $data['shopuid'] = $shop['uid'];
     // 店铺UID
     $data['shopid'] = $shop['id'];
     //店铺ID
     $data['shopname'] = $shop['shopname'];
     //店铺名称
     $data['shopphone'] = $shop['phone'];
     //店铺电话
     $data['shopaddress'] = $shop['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'];
     // 订单备注
     $data['is_make'] = Mysite::$app->config['allowed_is_make'] == 1 ? 0 : 1;
     //  daycode 当天订单序号
     $data['ipaddress'] = $info['ipaddress'];
     $data['is_ping'] = 0;
     // 是否评价字段 1已评完 0未评
     $data['addtime'] = time();
     $data['posttime'] = $nowpost;
     //: 配送时间
     $data['othertext'] = '';
     //其他说明
     //  :审核时间
     $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 ($goodsdata as $key => $value) {
         $cmd['order_id'] = $orderid;
         $cmd['goodsid'] = $value['id'];
         $cmd['goodsname'] = $value['name'];
         $cmd['goodscost'] = $value['cost'];
         $cmd['goodscount'] = $value['shuliang'];
         $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'] = $info['shopid'];
             $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);
     }
     //http://localhost///orderid/865
     $link = IUrl::creatUrl('site/waitpay/orderid/' . $orderid);
     $this->message('', $link);
 }
Exemplo n.º 4
0
 public function smallcatding()
 {
     $shopid = intval(IReq::get("shopid"));
     $Cart = new smCart();
     $plate = intval(IReq::get('plate'));
     if (!empty($plate)) {
         $Cart->cartName = 'platesmcart';
     }
     $carinfo = $Cart->getMyCart();
     $data['cartinfo'] = $carinfo;
     $cxclass = new sellrule();
     $showtype = trim(IReq::get("showtype"));
     $cxtemp = array();
     foreach ($carinfo['list'] as $key => $value) {
         if ($value['shopinfo']['shoptype'] == 1) {
             $shopcheckinfo = $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 = '" . $key . "'    ");
         } else {
             $shopcheckinfo = $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 = '" . $key . "'    ");
         }
         if ($key == $shopid) {
             $cxclass->setdata($key, $value['sum'], $value['shopinfo']['shoptype']);
             $cxinfo = $cxclass->getdata();
             $cxtemp = $cxinfo;
         }
     }
     $data['cxdata'] = $cxtemp;
     $data['shopid'] = $shopid;
     Mysite::$app->setdata($data);
 }
Exemplo n.º 5
0
 function orderyuding($info)
 {
     //$data['subtype'] = $info['subtype'];
     $data['is_goshop'] = $info['is_goshop'];
     $data['areaids'] = $info['areaids'];
     //$data['admin_id'] = $info['shopinfo']['admin_id'];
     $data['shopcost'] = $info['allcost'];
     //:店铺商品总价
     $data['shopps'] = 0;
     //店铺配送费
     $data['shoptype'] = 0;
     //: 0:普通订单,1订台订单
     $data['bagcost'] = 0;
     //:打包费
     //获取店铺商品总价  获取超市商品总价
     $data['paytype'] = $info['paytype'];
     $data['cxids'] = '';
     $data['cxcost'] = 0;
     $data['yhjcost'] = 0;
     $data['yhjids'] = '';
     $data['scoredown'] = 0;
     $data['allcost'] = $info['allcost'];
     //订单应收费用
     $data['shopuid'] = $info['shopinfo']['uid'];
     // 店铺UID
     $data['shopid'] = $info['shopinfo']['id'];
     //店铺ID
     $data['shopname'] = $info['shopinfo']['shopname'];
     //店铺名称
     $data['shopphone'] = $info['shopinfo']['phone'];
     //店铺电话
     $data['shopaddress'] = $info['shopinfo']['address'];
     // 店铺地址
     $data['pstype'] = $info['pstype'];
     $data['shoptype'] = 0;
     $data['buyeraddress'] = '';
     $data['ordertype'] = $info['ordertype'];
     //来源方式;
     $data['buyeruid'] = $info['userid'];
     // 购买用户ID,0未注册用户
     $data['buyername'] = $info['username'];
     //购买热名称
     $data['buyerphone'] = $info['mobile'];
     // 联系电话
     $data['paystatus'] = 0;
     // 支付状态1已支付
     $data['content'] = $info['remark'];
     // 订单备注
     //  daycode 当天订单序号
     $data['ipaddress'] = $info['ipaddress'];
     $data['is_ping'] = 0;
     // 是否评价字段 1已评完 0未评
     $data['addtime'] = time();
     $data['posttime'] = $info['sendtime'];
     //: 配送时间
     $data['othertext'] = $info['othercontent'];
     //其他说明
     //  :审核时间
     $data['passtime'] = time();
     $data['buycode'] = substr(md5(time()), 9, 6);
     $data['dno'] = time() . rand(1000, 9999);
     $minitime = strtotime(date('Y-m-d', time()));
     $zpin = array();
     $day = strtotime(date('Y-m-d', $data['posttime']));
     if ($info['subtype'] == 1) {
         // $this->message('订桌位');
         //
     } elseif ($info['subtype'] == 2) {
         $data['shopcost'] = $data['shopcost'];
         $data['cxids'] = '';
         $data['cxcost'] = 0;
         $cattype = $info['cattype'];
         if ($data['shopcost'] > 0) {
             $sellrule = new sellrule();
             $sellrule->setdata($info['shopid'], $data['shopcost'], $info['shopinfo']['shoptype'], $data['posttime'], 'platesmcart');
             $ruleinfo = $sellrule->getdata();
             $data['cxcost'] = $ruleinfo['downcost'];
             $data['cxids'] = $ruleinfo['cxids'];
             $zpin = $ruleinfo['zid'];
             //赠品
         }
         $data['allcost'] = $data['shopcost'] - $data['cxcost'];
     }
     $panduan = Mysite::$app->config['man_ispass'];
     $data['status'] = 0;
     if ($panduan != 1 && $data['paytype'] == 0) {
         $data['status'] = 1;
     }
     $data['is_make'] = Mysite::$app->config['allowed_is_make'] == 1 ? 0 : 1;
     $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;
     if ($info['subtype'] == 2) {
         foreach ($info['goodslist'] 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', '`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'] = $info['shopid'];
                 $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) {
         if ($data['status'] == 1) {
             $this->sendmess($orderid);
         }
     }
 }