예제 #1
0
	public function method()
	{
		if (!empty($this->_params['token']) && !empty($this->_params['type'])) {
			$printer = new orderPrint();
			return $printer->printit($this->_params['token'], $this->_params['companyid'], $this->_params['type'], $this->_params['content'], $this->_params['paid'], $this->_params['qr']);
		}
	}
예제 #2
0
 public function index($orderid, $paytype = '', $third_id = '')
 {
     $wecha_id = '';
     $token = '';
     if ($order = M('dish_order')->where(array('orderid' => $orderid))->find()) {
         //TODO 发货的短信提醒
         $token = $order['token'];
         $wecha_id = $order['wecha_id'];
         //$order['paid']=1;
         $Dishcompany = M('Dish_company')->where(array('cid' => $order['cid']))->find();
         $kconoff = $Dishcompany['kconoff'];
         if ($order['paid']) {
             $temp = unserialize($order['info']);
             $tmparr = array('token' => $token, 'cid' => $order['cid'], 'order_id' => $order['id'], 'paytype' => $order['paytype']);
             $log_db = M('Dishout_salelog');
             if (!empty($temp) && is_array($temp)) {
                 $DishDb = M('Dish');
                 $mDishSet = ThirdPayDishOut::getDishMainCompany($token);
                 foreach ($temp as $kk => $vv) {
                     $did = isset($vv['did']) ? $vv['did'] : $kk;
                     $dishofcid = $order['cid'];
                     if ($mDishSet['cid'] != $order['cid'] && $mDishSet['dishsame'] == 1) {
                         $dishofcid = $mDishSet['cid'];
                         $kconoff = $mDishSet['kconoff'];
                     }
                     $tmpdish = $DishDb->where(array('id' => $did, 'cid' => $dishofcid))->find();
                     if ($kconoff && !empty($tmpdish) && $tmpdish['instock'] > 0) {
                         $DishDb->where(array('id' => $did, 'cid' => $dishofcid))->setDec('instock', $vv['num']);
                     }
                     $logarr = array('did' => isset($vv['did']) ? $vv['did'] : $kk, 'nums' => $vv['num'], 'unitprice' => $vv['price'], 'money' => $vv['num'] * $vv['price'], 'dname' => $vv['name'], 'addtime' => $order['time'], 'addtimestr' => date('Y-m-d H:i:s', $order['time']), 'comefrom' => 0);
                     $savelogarr = array_merge($tmparr, $logarr);
                     $log_db->add($savelogarr);
                 }
             }
             $company = M('Company')->where(array('token' => $token, 'id' => $order['cid']))->find();
             if (empty($company) || !is_array($company)) {
                 header('Location:' . U('DishOut/index', array('token' => $token, 'wecha_id' => $wecha_id)));
             }
             Sms::sendSms($token, "顾客{$order['name']}刚刚对订单号:{$orderid}的订单进行了支付,请您注意查看并处理", $company['mp']);
             $model = new templateNews();
             $siteurl = $_SERVER['HTTP_HOST'];
             $siteurl = strtolower($siteurl);
             if (strpos($siteurl, "http:") === false && strpos($siteurl, "https:") === false) {
                 $siteurl = 'http://' . $siteurl;
             }
             $siteurl = rtrim($siteurl, '/');
             /*$model->sendTempMsg('OPENTM202521011', array('href' =>U('DishOut/myOrder', array('token' => $token, 'wecha_id' => $wecha_id, 'cid' => $order['cid']), true, false, true), 'wecha_id' => $wecha_id, 'first' => '外卖订餐交易提醒', 'keyword1' => $orderid, 'keyword2' => date("Y年m月d日H时i分s秒"), 'remark' => '支付成功,感谢您的光临,欢迎下次再次光临!'));*/
             $model->sendTempMsg('OPENTM202521011', array('href' => $siteurl . '/index.php?g=Wap&m=DishOut&a=myOrder&token=' . $token . '&wecha_id=' . $wecha_id . '&cid=' . $order['cid'], 'wecha_id' => $wecha_id, 'first' => '外卖订餐交易提醒', 'keyword1' => $orderid, 'keyword2' => date("Y年m月d日H时i分s秒"), 'remark' => '支付成功,感谢您的光临,欢迎下次再次光临!'));
             $op = new orderPrint();
             $msg = array('companyname' => $company['name'], 'des' => htmlspecialchars_decode($order['des'], ENT_QUOTES), 'companytel' => $company['tel'], 'truename' => htmlspecialchars_decode($order['name'], ENT_QUOTES), 'tel' => $order['tel'], 'address' => htmlspecialchars_decode($order['address'], ENT_QUOTES), 'buytime' => $order['time'], 'orderid' => $order['orderid'], 'sendtime' => $order['reservetime'] > 0 ? $order['reservetime'] : '尽快送达', 'price' => $order['price'], 'total' => $order['total'], 'typename' => '外卖', 'ptype' => $order['paytype'], 'list' => $temp);
             $msg = ArrayToStr::array_to_str($msg, $order['paid']);
             $op->printit($token, $order['cid'], 'DishOut', $msg, $order['paid']);
         }
         header('Location:' . U('DishOut/myOrder', array('token' => $token, 'wecha_id' => $wecha_id, 'cid' => $order['cid'])));
     } else {
         exit('抱歉,订单信息出错');
     }
 }
예제 #3
0
 public function index($orderid, $paytype = '', $third_id = '')
 {
     if ($order = M('Product_cart')->where(array('orderid' => $orderid))->find()) {
         //TODO 发货的短信提醒
         if ($order['paid']) {
             $userInfo = D('Userinfo')->where(array('token' => $order['token'], 'wecha_id' => $order['wecha_id']))->find();
             $carts = unserialize($order['info']);
             $tdata = self::getCat($carts, $order['token'], $order['cid'], $userInfo['getcardtime']);
             $list = array();
             $info = '';
             $pre = '';
             foreach ($tdata[0] as $va) {
                 $t = array();
                 $salecount = 0;
                 if (!empty($va['detail'])) {
                     foreach ($va['detail'] as $v) {
                         $t = array('num' => $v['count'], 'colorName' => $v['colorName'], 'formatName' => $v['formatName'], 'price' => $v['price'], 'name' => $va['name']);
                         $list[] = $t;
                         $salecount += $v['count'];
                     }
                 } else {
                     $t = array('num' => $va['count'], 'price' => $va['price'], 'name' => $va['name']);
                     $list[] = $t;
                     $salecount = $va['count'];
                 }
                 $info .= $pre . $va['name'];
                 $pre = ',';
                 D("Product")->where(array('id' => $va['id']))->setInc('salecount', $salecount);
             }
             if ($order['twid']) {
                 if ($set = M("Twitter_set")->where(array('token' => $order['token'], 'cid' => $order['cid']))->find()) {
                     $price = $set['percent'] * 0.01 * $order['totalprice'];
                     $info = $info ? '购买' . $info . '等产品,订单号:' . $orderid : '购买订单号:' . $orderid;
                     D("Twitter_log")->add(array('token' => $order['token'], 'cid' => $order['cid'], 'twid' => $order['twid'], 'type' => 3, 'dateline' => time(), 'param' => $order['totalprice'], 'price' => $price, 'wecha_id' => $order['wecha_id'], 'info' => $info));
                     if ($count = M("Twitter_count")->where(array('token' => $order['token'], 'cid' => $order['cid'], 'twid' => $order['twid']))->find()) {
                         D("Twitter_count")->where(array('id' => $count['id']))->setInc('total', $price);
                     } else {
                         D("Twitter_count")->add(array('token' => $order['token'], 'cid' => $order['cid'], 'twid' => $order['twid'], 'total' => $price, 'remove' => 0));
                     }
                 }
             }
             $company = D('Company')->where(array('token' => $order['token'], 'id' => $order['cid']))->find();
             $op = new orderPrint();
             $msg = array('companyname' => $company['name'], 'companytel' => $company['tel'], 'truename' => $order['truename'], 'tel' => $order['tel'], 'address' => $order['address'], 'buytime' => $order['time'], 'orderid' => $order['orderid'], 'sendtime' => '', 'price' => $order['price'], 'total' => $order['total'], 'list' => $list);
             $msg = ArrayToStr::array_to_str($msg, 1);
             $op->printit($order['token'], $order['cid'], 'Store', $msg, 1);
             $userInfo = D('Userinfo')->where(array('token' => $order['token'], 'wecha_id' => $order['wecha_id']))->find();
             Sms::sendSms($order['token'], "您的顾客{$userInfo['truename']}刚刚对订单号:{$orderid}的订单进行了支付,请您注意查看并处理");
             $model = new templateNews();
             $model->sendTempMsg('OPENTM202521011', array('href' => U('Store/my', array('token' => $order['token'], 'wecha_id' => $order['wecha_id'], 'twid' => $order['twid']), true, false, true), 'wecha_id' => $order['wecha_id'], 'first' => '购买商品提醒', 'keyword1' => $orderid, 'keyword2' => date("Y年m月d日H时i分s秒"), 'remark' => '购买成功,感谢您的光临,欢迎下次再次光临!'));
         }
         header('Location:/index.php?g=Wap&m=Store&a=my&token=' . $order['token'] . '&wecha_id=' . $order['wecha_id'] . '&twid=' . $order['twid']);
     } else {
         exit('订单不存在:' . $out_trade_no);
         exit('订单不存在');
     }
 }
예제 #4
0
	public function index($orderid, $paytype = '', $third_id = ''){
		
		if ($order = M('Hotels_order')->where(array('orderid' => $orderid))->find()) {
			//TODO 发货的短信提醒
			if ($order['paid']) {
				$userInfo = D('Userinfo')->where(array('token' => $order['token'], 'wecha_id' => $order['wecha_id']))->find();
				$sort = M('Hotels_house_sort')->where(array('id' => $order['sid'], 'token' => $order['token']))->find();
				$days = (strtotime($order['enddate']) - strtotime($order['startdate'])) / 86400;
				$price = $userInfo['getcardtime'] > 0 ? ($sort['vprice'] ? $sort['vprice'] : $sort['price']) : $sort['price'];
				$company = M('Company')->where(array('id' => $order['cid'], 'token' => $order['token']))->find();
				$op = new orderPrint();
				$msg = array('companyname' => $company['name'], 'companytel' => $company['tel'], 'truename' => $order['name'], 'tel' => $order['tel'], 'address' => '', 'buytime' => $order['time'], 'orderid' => $order['orderid'], 'sendtime' => '', 'price' => $order['price'], 'total' => $order['nums'], 'list' => array(array('name' => $sort['name'], 'day' => $days, 'price' => $price, 'num' => $order['nums'], 'startdate' => $order['startdate'], 'enddate' => $order['enddate'])));
				$msg = ArrayToStr::array_to_str($msg, 1);
				$op->printit($order['token'], $order['cid'], 'Hotel', $msg, 1);
		
				Sms::sendSms($order['token'] . "_" . $order['cid'], "顾客{$order['name']}刚刚对订单号:{$orderid}的订单进行了支付,请您注意查看并处理");
				$model = new templateNews();
				$href = C('site_url').'/index.php?g=Wap&m=Hotels&a=my&token=' . $order['token'] . '&wecha_id=' . $order['wecha_id'] . '&cid=' . $order['cid'];
				$model->sendTempMsg('OPENTM202521011', array('href' => $href, 'wecha_id' => $order['wecha_id'], 'first' => '预订房间提醒', 'keyword1' => $orderid, 'keyword2' => date("Y年m月d日H时i分s秒"), 'remark' => '预订房间成功,感谢您的光临,欢迎下次再次光临!'));
		
			}
			header('Location:/index.php?g=Wap&m=Hotels&a=my&token='.$order['token'].'&wecha_id='.$order['wecha_id'].'&cid='.$order['cid']);
// 			$this->redirect(U('Hotels/my', array('token'=>$this->token, 'wecha_id' => $this->wecha_id)));
		}else{
			exit('订单不存在');
		}
		
		
// 		$product_cart_model=M('product_cart');
// 		$out_trade_no=$orderid;
// 		$order=$product_cart_model->where(array('orderid'=>$out_trade_no))->find();
// 		if (!$this->wecha_id){
// 			$this->wecha_id=$order['wecha_id'];
// 		}
// 		$sepOrder=0;
// 		if (!$order){
// 			$order=$product_cart_model->where(array('id'=>$out_trade_no))->find();
// 			$sepOrder=1;
// 		}
// 		if($order){
// 			if($order['paid']!=1){exit('该订单还未支付');}
// 			/************************************************/
// 			Sms::sendSms($this->token,'您的微信里有团购订单已经付款');
// 			/************************************************/
// 			header('Location:/index.php?g=Wap&m=Groupon&a=myOrders&token='.$order['token'].'&wecha_id='.$order['wecha_id']);
			
// 		}else{
// 			exit('订单不存在:'.$out_trade_no);
// 		}
	}
예제 #5
0
 public function cart()
 {
     $this->wapIsLogin();
     if (IS_POST) {
         $phone = isset($_POST['phone']) ? htmlspecialchars($_POST['phone']) : '';
         $name = isset($_POST['name']) ? htmlspecialchars($_POST['name']) : '';
         $address = isset($_POST['address']) ? htmlspecialchars($_POST['address']) : '';
         $note = isset($_POST['note']) ? htmlspecialchars($_POST['note']) : '';
         if (empty($name)) {
             $this->error('联系人不能为空');
         }
         if (empty($phone)) {
             $this->error('联系电话不能为空');
         }
         $goodsData = isset($_POST['goodsData']) ? htmlspecialchars($_POST['goodsData']) : '';
         if (empty($goodsData)) {
             $this->error('您还没有点菜');
         }
         $products = explode(";", $goodsData);
         $dish = array();
         $meal = array();
         foreach ($products as $p) {
             $t = explode(",", $p);
             $dish[$t[0]] = $t[1];
             $meal[] = $t[0];
         }
         $total = $price = 0;
         if ($meal) {
             $meals = M("Meal")->where(array('meal_id' => array('in', $meal), 'store_id' => $this->store_id))->select();
             $info = array();
             foreach ($meals as $m) {
                 $info[] = array('id' => $m['meal_id'], 'name' => $m['name'], 'num' => $dish[$m['meal_id']], 'price' => $m['price']);
                 $total += $dish[$m['meal_id']];
                 $price += $dish[$m['meal_id']] * $m['price'];
             }
         }
         $data = array('mer_id' => $this->mer_id, 'store_id' => $this->store_id, 'name' => $name, 'phone' => $phone, 'address' => $address, 'note' => $note, 'info' => serialize($info), 'dateline' => time(), 'total' => $total, 'price' => $price);
         $data['orderid'] = $this->mer_id . $this->store_id . date("YmdHis") . rand(1000000, 9999999);
         // 			$data['wecha_id'] = $this->wecha_id;
         $data['uid'] = $this->user_session['uid'];
         $data['note'] = isset($_POST['note']) ? htmlspecialchars($_POST['note']) : '';
         $orderid = D("Meal_order")->add($data);
         if ($orderid) {
             if ($this->user_session['openid']) {
                 $keyword2 = '';
                 $pre = '';
                 foreach (unserialize($data['info']) as $menu) {
                     $keyword2 .= $pre . $menu['name'] . ':' . $menu['price'] . '*' . $menu['num'];
                     $pre = '\\n\\t\\t\\t';
                 }
                 $href = C('config.site_url') . '/wap.php?c=Meal&a=detail&orderid=' . $orderid . '&mer_id=' . $data['mer_id'] . '&store_id=' . $data['store_id'];
                 $model = new templateNews(C('config.wechat_appid'), C('config.wechat_appsecret'));
                 $model->sendTempMsg('OPENTM201682460', array('href' => $href, 'wecha_id' => $this->user_session['openid'], 'first' => '您好,您的订单已生成', 'keyword3' => $orderid, 'keyword1' => date('Y-m-d H:i:s'), 'keyword2' => $keyword2, 'remark' => '您的该次' . $this->config['meal_alias_name'] . '下单成功,感谢您的使用!'));
             }
             $msg = array();
             $msg['user_name'] = $data['name'];
             $msg['user_phone'] = $data['phone'];
             $msg['user_address'] = $data['address'];
             $msg['user_message'] = $data['note'];
             $msg['buy_time'] = date("Y-m-d H:i:s", $data['dateline']);
             $msg['goods_list'] = $info;
             $msg['goods_count'] = $data['total'];
             $msg['goods_price'] = $data['price'];
             $msg['orderid'] = $orderid;
             $msg['pay_status'] = '';
             $msg['pay_type'] = '';
             $msg['store_name'] = $this->_store['name'];
             $msg['store_phone'] = $this->_store['phone'];
             $msg['store_address'] = $this->_store['adress'];
             $msg = ArrayToStr::array_to_str($msg, 0, $this->config['print_format']);
             $op = new orderPrint($this->config['print_server_key'], $this->config['print_server_topdomain']);
             $op->printit($this->mer_id, $this->store_id, $msg, 0);
             /* 粉丝行为分析 */
             $this->behavior(array('mer_id' => $this->mer_id, 'biz_id' => $orderid));
             redirect(U('Pay/check', array('order_id' => $orderid, 'type' => 'meal')));
             //$this->success('订餐成功', U("Meal/detail", array('mer_id' => $this->mer_id, 'store_id' => $this->store_id, 'orderid' => $orderid)));
         }
     } else {
         $now_group['user_adress'] = D('User_adress')->get_one_adress($this->user_session['uid'], intval($_GET['adress_id']));
         $this->assign('now_group', $now_group);
         $sorts = M("Meal_sort")->where(array('store_id' => $this->store_id))->select();
         $temp = array();
         foreach ($sorts as $sort) {
             $temp[$sort['sort_id']] = $sort['sort_name'];
         }
         $this->assign("categories", json_encode($temp));
         $this->assign('class', 3);
         $this->assign('title', '购物车');
         $this->display();
     }
 }
예제 #6
0
    /**
     * 保存订餐人的信息到session
     */
    public function OrderPay() {
        $disharr = $_POST['dish']; /*         * 菜品id 数组*id 份数 */
        $shopid = intval($_POST['mycid']);
        $shopidd = $shopid; //下单时写回自己的分店ID
		/////自行
	$Mcompany = $this->getDishMainCompany();
	   
        if (($Mcompany['cid'] != $shopid) && ($Mcompany['dishsame'] == 1)) {
            $dishofcid = $Mcompany['cid']; /*             * *开启分店统一主店 菜品功能** */
			$shopid  = $dishofcid;
        }
		////
        $totalmoney = floatval(trim($_POST['totalmoney']));
        $totalnum = intval(trim($_POST['totalnum']));
        $ouserName = htmlspecialchars(trim($_POST['ouserName']), ENT_QUOTES);
        $ouserSex = intval(trim($_POST['ouserSex']));
        $ouserTel = htmlspecialchars(trim($_POST['ouserTel']), ENT_QUOTES);
        $ouserAddres = htmlspecialchars(trim($_POST['ouserAddres']), ENT_QUOTES);
        $oarrivalTime = htmlspecialchars(trim($_POST['oarrivalTime']), ENT_QUOTES);
        $omark = htmlspecialchars(trim($_POST['omark']), ENT_QUOTES);

        if ($shopid > 0) {
            $jumpurl = U('DishOut/dishMenu', array('token' => $this->token, 'cid' => $shopid, 'wecha_id' => $this->wecha_id));
            if (empty($disharr) || !($totalmoney > 0) || !($totalnum > 0)) {
                $this->exitdisplay('订单信息出错!', $jumpurl);
            }
            if (empty($ouserName) || empty($ouserTel) || empty($ouserAddres)) {
                $this->exitdisplay('订单中相关联系地址:姓名或联系电话或送货地址有没写的', $jumpurl);
            }
            if (preg_match('/\-\d{2}\s\d{2}\:/', $oarrivalTime)) {   /** **如果选择了明日的时间 是带上日期的** */
                $oarrivalTime = strtotime($oarrivalTime);
            } else {
                $oarrivalTime = $oarrivalTime ? strtotime(date('Y-m-d ') . $oarrivalTime) : 0;
            }
            $tmparr = array();
            $tmpsubnum = 0;
            $tmpsubmoney = 0;
            
			/**************************************************/
            $disharr && $idarr = array_keys($disharr);
            if ($idarr) {
            	$dishs = M('Dish')->where(array('id' => array('in', $idarr), 'cid' => $shopid, 'isopen' => 1))->select();
            	foreach ($dishs as $dh) {
            		if (isset($disharr[$dh['id']]['num']) && $disharr[$dh['id']]['num']) {
            			$tmpnum = $disharr[$dh['id']]['num'];
            			$discount = trim($disharr[$dh['id']]['discount']);
            			if ($discount > 0) {
            				$tmpprice = ($discount * $dh['price']) / 10;
            			} else {
            				$tmpprice = $dh['price'];
            			}
            			//$tmpprice = $discount > 0 ? $discount * floatval($dv['price']) / 10 : floatval($dv['price']);
            			$tmparr[$dh['id']] = array();
            			$tmparr[$dh['id']]['did'] = $dh['id'];
            			$tmparr[$dh['id']]['num'] = $tmpnum;
            			$tmparr[$dh['id']]['discount'] = $discount;
            			$tmparr[$dh['id']]['price'] = $tmpprice;
            			$tmparr[$dh['id']]['name'] = $dh['name'];
            			$tmparr[$dh['id']]['kitchen_id'] = $dh['kitchen_id'];
            			$tmparr[$dh['id']]['omark'] = htmlspecialchars(trim($disharr[$dh['id']]['omark']), ENT_QUOTES);
            			$tmpsubnum += $tmpnum;
            			$tmpsubmoney += ($tmpprice * $tmpnum);
            		}
            	}
            }
            /**************************************************/
            /*foreach ($disharr as $dk => $dv) {
                if (!empty($dv)) {
                    $tmpnum = intval($dv['num']);
                    if ($tmpnum > 0) {
                        $tmpprice = floatval($dv['price']);
                        $tmparr[$dk] = array();
                        $tmparr[$dk]['did'] = $dk;
                        $tmparr[$dk]['num'] = $tmpnum;
                        $tmparr[$dk]['price'] = $tmpprice;
                        $tmparr[$dk]['name'] = $dv['name'];
                        $tmpsubnum+=$tmpnum;
                        $tmpsubmoney+=($tmpprice * $tmpnum);
                    }
                }
            }*/
            
            if (empty($tmparr)) {
                $this->exitdisplay('没有订单信息', $jumpurl);
            }
			$tmpsubmoney=number_format($tmpsubmoney,2);
            $t_tmpsubmoney = (int) ($tmpsubmoney * 10000);

            $t_totalmoney = (int) ($totalmoney * 10000);

            if (($tmpsubnum != $totalnum) || ($t_tmpsubmoney != $t_totalmoney)) {
                $this->error('订单的金额或点的菜的份数不对', $jumpurl);
            }

            $outset = $this->outManage($shopid);
            if (($outset['stype'] == 2) && ($tmpsubmoney < $outset['pricing'])) {
                $tmpsubmoney = $outset['pricing']; /*                 * 处理起步价方式订单金额不足起步价按起步价收取* */
            }
            $wecha_id = $this->wecha_id ? $this->wecha_id : 'DishOutm_' . $ouserTel;
            $orderid = substr($wecha_id, -5) . date("YmdHis");
            $Orderarr = array('cid' => $shopidd, 'wecha_id' => $wecha_id, 'token' => $this->token, 'total' => $tmpsubnum,
                'price' => $tmpsubmoney, 'nums' => 1,
                'info' => serialize($tmparr), 'name' => $ouserName,
                'sex' => $ouserSex, 'tel' => $ouserTel,
                'address' => $ouserAddres, 'tableid' => 0,
                'time' => time(), 'reservetime' => $oarrivalTime,
                'stype' => $outset['stype'], 'paid' => 0, 'isuse' => 0,
                'orderid' => $orderid, 'printed' => 0,
                'des' => $omark, 'takeaway' => 1,
                'comefrom' => 'dishout'
            );//$cid => $shopidd
            $orid = D('Dish_order')->add($Orderarr);
            if ($orid) {
                $_SESSION[$this->session_dish_info] = '';
                //TODO 短信提示
                $company = $this->getCompany($shopid);
                Sms::sendSms($this->token, "顾客{$ouserName}刚刚叫了一份外卖,订单号:{$orderid},请您注意查看并处理", $company['mp']);
				//给商家发站内信
				$params = array();
				$params['site'] = array('token'=>$this->token, 'from'=>'微外卖消息','content'=>"顾客{$ouserName}刚刚叫了一份外卖,订单号:{$orderid},请您注意查看并处理");
				MessageFactory::method($params, 'SiteMessage');
//                 $printer_set = $this->getPrinter_set($shopid);
//                 if (!empty($printer_set) && ($printer_set['paid'] == 0)) {
                    $op = new orderPrint();
                    $msg = array('companyname' => $company['name'], 'des' => trim($_POST['omark']),
                        'companytel' => $company['tel'], 'truename' => trim($_POST['ouserName']),
                        'tel' => trim($_POST['ouserTel']), 'address' => trim($_POST['ouserAddres']),
                        'buytime' => $Orderarr['time'], 'orderid' => $Orderarr['orderid'],
                        'sendtime' => $oarrivalTime > 0 ? $oarrivalTime : '尽快送达', 'price' => $Orderarr['price'],
                        'total' => $Orderarr['total'], 'typename' => '外卖',
                        'list' => $tmparr);
                    $msg = ArrayToStr::array_to_str($msg, 0);
                    $op->printit($this->token, $shopid, 'DishOut', $msg, 0);
                    
                    /*厨房打印菜单*/
                    if ($kitchens_list = D('Dish_kitchen')->where(array('cid' => $this->_cid))->select()) {
	                    $t_list = array();
	                    foreach ($tmparr as $dish) $t_list[$dish['kitchen_id']][] = $dish;

	                    $kitchens = array();
	                    foreach ($kitchens_list as $kit_row) $kitchens[$kit_row['id']] = $kit_row;
	                    
	                    $print_msg = array('des' => trim($_POST['omark']), 'truename' => trim($_POST['ouserName']), 'tel' => trim($_POST['ouserTel']), 'address' => trim($_POST['ouserAddres']), 'buytime' => $Orderarr['time'], 'orderid' => $Orderarr['orderid'], 'sendtime' => $oarrivalTime > 0 ? $oarrivalTime : '尽快送达');
	                    foreach ($t_list as $k => $rowset) {
	                    	if ($k) {
	                    		if (isset($kitchens[$k]) && $kitchens[$k]['status']) {
	                    			for ($i = 0; $i < count($rowset); $i++) {
			                    		$msg = $print_msg;
			                    		$msg['list'][] = $rowset[$i];
					                    $msg = ArrayToStr::array_to_str($msg, 0);
					                    $op->printit($this->token, $this->_cid, 'DishOut', $msg, 0, '', $k);
	                    			}
	                    		} else {
		                    		$msg = $print_msg;
		                    		$msg['list'] = $rowset;
				                    $msg = ArrayToStr::array_to_str($msg, 0);
				                    $op->printit($this->token, $this->_cid, 'DishOut', $msg, 0, '', $k);
	                    		}
	                    	}
	                    }
                    }
                    /*厨房打印菜单*/
                    
                    
//                 }
                $alipayConfig = M('Alipay_config')->where(array('token' => $this->token))->find();

                if ($alipayConfig['open']) {
                    $this->success('正在提交中...', U('Alipay/pay', array('token' => $this->token, 'wecha_id' => $wecha_id, 'success' => 1, 'from' => 'DishOut', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $tmpsubmoney)));
                } /* elseif ($this->fans['balance']) {
                  $this->success('正在提交中...', U('CardPay/pay',array('token' => $this->token, 'wecha_id' => $wecha_id, 'success' => 1, 'from'=> 'DishOut', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $tmpsubmoney)));
                  } */ else {
                    $this->exitdisplay('商家尚未开启支付功能', $jumpurl);
                }
            } else {
                $this->exitdisplay('订单录入系统出错,抱歉给您的带来了不便。请重新下单吧', $jumpurl);
            }
            if (!empty($this->wecha_id)) {
                /* 保存个人信息 */
                $userinfo_model = M('Userinfo');
                $thisUser = $userinfo_model->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
                if (empty($thisUser)) {
                    $userRow = array('tel' => $ouserTel, 'truename' => $ouserName, 'address' => $ouserAddres);
                    $userRow['token'] = $this->token;
                    $userRow['wecha_id'] = $this->wecha_id;
                    $userRow['wechaname'] = '';
                    $userRow['qq'] = 0;
                    $userRow['sex'] = $ouserSex;
                    $userRow['age'] = 0;
                    $userRow['birthday'] = '';
                    $userRow['info'] = '';

                    $userRow['total_score'] = 0;
                    $userRow['sign_score'] = 0;
                    $userRow['expend_score'] = 0;
                    $userRow['continuous'] = 0;
                    $userRow['add_expend'] = 0;
                    $userRow['add_expend_time'] = 0;
                    $userRow['live_time'] = 0;
                    $userinfo_model->add($userRow);
                }
            }
        } else {
            $jumpurl = U('DishOut/index', array('token' => $this->token, 'wecha_id' => $this->wecha_id));
            $this->exitdisplay('订单信息中店面信息出错', $jumpurl);
        }
    }
예제 #7
0
 public function saveorder()
 {
     //判断登录
     if (empty($this->user_session)) {
         $this->assign('jumpUrl', U('Index/Login/index'));
         $this->error('请先登录!');
     }
     $store_id = intval($_POST['store_id']);
     $store = D('Merchant_store')->where(array('store_id' => $store_id))->find();
     if (empty($store)) {
         exit(json_encode(array('error_code' => 1, 'msg' => '您查看的餐厅不存在!')));
     }
     if (empty($this->user_session)) {
         exit(json_encode(array('error_code' => 1, 'msg' => '请先进行登录!', 'data' => U('Login/index'))));
     }
     // 		$phone = isset($_POST['phone']) ? htmlspecialchars($_POST['phone']) : '';
     // 		$name = isset($_POST['name']) ? htmlspecialchars($_POST['name']) : '';
     $address_id = isset($_POST['address_id']) ? intval($_POST['address_id']) : 0;
     $note = isset($_POST['note']) ? htmlspecialchars($_POST['note']) : '';
     if (empty($address_id)) {
         exit(json_encode(array('error_code' => 1, 'msg' => '联系信息不能为空')));
     }
     $now_adress = D('User_adress')->get_one_adress($this->user_session['uid'], $address_id);
     if (empty($now_adress)) {
         exit(json_encode(array('error_code' => 1, 'msg' => '请先添加联系信息!')));
     }
     $products = isset($_POST['products']) ? $_POST['products'] : '';
     if (empty($products)) {
         exit(json_encode(array('error_code' => 1, 'msg' => '您还没有点菜')));
     }
     $total = $price = 0;
     if ($products) {
         // 			$info = array();
         // 			foreach ($products as $m) {
         // 				$info[] = array('id' => $m['id'],'name' => $m['name'], 'num' => $m['number'], 'price' => $m['price']);
         // 				$total += $m['number'];
         // 				$price += $m['number'] * $m['price'];
         // 			}
         $temp = explode(":", $products);
         $store_id = $temp[0];
         $menus = explode("|", $temp[1]);
         $ids = $list = array();
         $food_count = 0;
         foreach ($menus as $m) {
             $t = explode(",", $m);
             $ids[] = $t[0];
             $list[$t[0]] = $t[1];
             $food_count += $t[1];
         }
         $meals = D("Meal")->field(true)->where(array('store_id' => $store_id, 'meal_id' => array('in', $ids)))->select();
         $info = array();
         foreach ($meals as $m) {
             $info[] = array('id' => $m['meal_id'], 'name' => $m['name'], 'num' => $list[$m['meal_id']], 'price' => $m['price']);
             $total += $list[$m['meal_id']];
             $price += $list[$m['meal_id']] * $m['price'];
         }
     }
     //用户等级 优惠
     $finaltotalprice = 0;
     $level_off = false;
     $store_meal = D('Merchant_store_meal')->where(array('store_id' => $store_id))->find();
     if (!empty($this->user_level) && !empty($store_meal) && !empty($store_meal['leveloff'])) {
         $leveloff = unserialize($store_meal['leveloff']);
         if (!empty($this->user_session) && isset($this->user_session['level'])) {
             /****type:0无优惠 1百分比 2立减*******/
             if (!empty($leveloff) && is_array($leveloff) && isset($this->user_level[$this->user_session['level']]) && isset($leveloff[$this->user_session['level']])) {
                 $level_off = $leveloff[$this->user_session['level']];
                 if ($level_off['type'] == 1) {
                     $finaltotalprice = $price * ($level_off['vv'] / 100);
                     $finaltotalprice = $finaltotalprice > 0 ? $finaltotalprice : 0;
                     $level_off['offstr'] = '按此次总价' . $level_off['vv'] . '%来结算';
                 } elseif ($level_off['type'] == 2) {
                     $finaltotalprice = $price - $level_off['vv'];
                     $finaltotalprice = $finaltotalprice > 0 ? $finaltotalprice : 0;
                     $level_off['offstr'] = '此次总价立减' . $level_off['vv'] . '元';
                 }
             }
         }
         unset($leveloff);
     }
     $price = $finaltotalprice > 0 ? round($finaltotalprice, 2) : $price;
     $total_price = $price;
     $minus_price = 0;
     if ($store_meal && !empty($store_meal['minus_money']) && $price > $store_meal['full_money']) {
         $price = $price - $store_meal['minus_money'];
         $minus_price = $store_meal['minus_money'];
     }
     is_array($level_off) && ($level_off['totalprice'] = $price);
     $data = array('mer_id' => $store['mer_id'], 'store_id' => $store_id, 'name' => $now_adress['name'], 'phone' => $now_adress['phone'], 'address' => $now_adress['province_txt'] . $now_adress['city_txt'] . $now_adress['area_txt'] . $now_adress['adress'], 'note' => $note, 'info' => serialize($info), 'dateline' => time(), 'total' => $total, 'price' => $price);
     $data['total_price'] = $total_price;
     $data['minus_price'] = $minus_price;
     $data['orderid'] = $store['mer_id'] . $store_id . date("YmdHis") . rand(1000000, 9999999);
     $data['uid'] = $this->user_session['uid'];
     $level_off && is_array($level_off) && ($data['leveloff'] = serialize($level_off));
     $orderid = D("Meal_order")->add($data);
     if ($orderid) {
         $msg = array();
         $msg['user_name'] = $data['name'];
         $msg['user_phone'] = $data['phone'];
         $msg['user_address'] = $data['address'];
         $msg['user_message'] = $data['note'];
         $msg['buy_time'] = date("Y-m-d H:i:s", $data['dateline']);
         $msg['goods_list'] = $info;
         $msg['goods_count'] = $data['total'];
         $msg['goods_price'] = $data['price'];
         $msg['orderid'] = $orderid;
         $msg['pay_status'] = '';
         $msg['pay_type'] = '';
         $msg['store_name'] = $store['name'];
         $msg['store_phone'] = $store['phone'];
         $msg['store_address'] = $store['adress'];
         $msg = ArrayToStr::array_to_str($msg, 0, $this->config['print_format']);
         $op = new orderPrint($this->config['print_server_key'], $this->config['print_server_topdomain']);
         $op->printit($store['mer_id'], $store['store_id'], $msg, 0);
         $sms_data = array('mer_id' => $store['mer_id'], 'store_id' => $store['store_id'], 'type' => 'food');
         if ($this->config['sms_place_order'] == 1 || $this->config['sms_place_order'] == 3) {
             $sms_data['uid'] = $this->user_session['uid'];
             $sms_data['mobile'] = $data['phone'];
             $sms_data['sendto'] = 'user';
             $sms_data['content'] = '您在' . $store['name'] . '中下单成功,订单号:' . $orderid;
             Sms::sendSms($sms_data);
         }
         if ($this->config['sms_place_order'] == 2 || $this->config['sms_place_order'] == 3) {
             $sms_data['uid'] = 0;
             $sms_data['mobile'] = $store['phone'];
             $sms_data['sendto'] = 'merchant';
             $sms_data['content'] = '客户' . $data['name'] . '刚刚下了一个订单,订单号:' . $orderid . ',请您注意查看并处理';
             Sms::sendSms($sms_data);
         }
         session('shop_cart', null);
         exit(json_encode(array('error_code' => 0, 'msg' => '', 'data' => U('Index/Pay/check', array('order_id' => $orderid, 'type' => 'meal')))));
     } else {
         exit(json_encode(array('error_code' => 1, 'msg' => D("Meal_order")->getError())));
     }
 }
예제 #8
0
 /**
  * 提交订单
  */
 public function saveorder()
 {
     $dataBase = D('Hotels_order');
     if (IS_POST) {
         $price = 0;
         if ($sort = M('Hotels_house_sort')->where(array('cid' => $this->_cid, 'token' => $this->token, 'id' => $_POST['sid']))->find()) {
             if ($this->fans['getcardtime'] > 0) {
                 $price = $sort['vprice'] ? $sort['vprice'] : $sort['price'];
             } else {
                 $price = $sort['price'];
             }
         }
         $days = (strtotime($_POST['enddate']) - strtotime($_POST['startdate'])) / 86400;
         $sday = date("Y年m月d日", strtotime($_POST['startdate']));
         $eday = date("Y年m月d日", strtotime($_POST['enddate']));
         if ($_POST['startdate'] < date("Ymd") || $days < 1) {
             $this->error('您预定的时间不正确');
         }
         //处理预定房间的数量
         $in = date("Ymd", strtotime($_POST['startdate']));
         $etime = strtotime($_POST['enddate']);
         $hotelSort = M("Hotels_house_sort")->where(array('id' => $_POST['sid'], 'token' => $this->token))->find();
         $time = strtotime($_POST['startdate']);
         for (; $time < $etime;) {
             $order = M('Hotels_order')->field('sum(nums) as num')->where(array('startdate' => array('ELT', date('Ymd', $time)), 'enddate' => array('GT', date('Ymd', $time)), 'token' => $this->token, 'cid' => $this->_cid, 'sid' => $_POST['sid'], 'status' => array('ELT', 1)))->find();
             $oldnum = isset($order['num']) ? $order['num'] : 0;
             $total = $_POST['nums'] + $oldnum;
             if ($total > $hotelSort['houses']) {
                 $this->error('您预定的房间数在' . date('Y年m月d日', strtotime($time)) . '超出总房间数了,请重新预定');
             } else {
                 $time += 86400;
             }
         }
         $_POST['orderid'] = $orderid = substr($this->wecha_id, -1, 4) . date("YmdHis");
         $_POST['price'] = $_POST['nums'] * $days * $price;
         $_POST['time'] = time();
         //保存个人信息
         $userinfo_model = M('Userinfo');
         $thisUser = $userinfo_model->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
         if (empty($thisUser)) {
             $userRow = array('tel' => $_POST['tel'], 'truename' => $_POST['name'], 'address' => '');
             $userRow['token'] = $this->token;
             $userRow['wecha_id'] = $this->wecha_id;
             $userRow['wechaname'] = '';
             $userRow['qq'] = 0;
             $userRow['sex'] = -1;
             $userRow['age'] = 0;
             $userRow['birthday'] = '';
             $userRow['info'] = '';
             $userRow['total_score'] = 0;
             $userRow['sign_score'] = 0;
             $userRow['expend_score'] = 0;
             $userRow['continuous'] = 0;
             $userRow['add_expend'] = 0;
             $userRow['add_expend_time'] = 0;
             $userRow['live_time'] = 0;
             $userinfo_model->add($userRow);
         }
         if ($dataBase->create() !== false) {
             $action = $dataBase->add();
             if ($action != false) {
                 $company = M('Company')->where(array('id' => $this->_cid, 'token' => $this->token))->find();
                 $op = new orderPrint();
                 $msg = array('companyname' => $company['name'], 'companytel' => $company['tel'], 'truename' => $_POST['name'], 'tel' => $_POST['tel'], 'address' => '', 'buytime' => time(), 'orderid' => $_POST['orderid'], 'sendtime' => '', 'price' => $_POST['price'], 'total' => $_POST['nums'], 'list' => array(array('name' => $sort['name'], 'day' => $days, 'price' => $price, 'num' => $_POST['nums'], 'startdate' => $_POST['startdate'], 'enddate' => $_POST['enddate'])));
                 $msg = ArrayToStr::array_to_str($msg);
                 $op->printit($this->token, $this->_cid, 'Hotel', $msg, 0);
                 Sms::sendSms($this->token . "_" . $this->_cid, "顾客{$_POST['name']}刚刚预定了{$sday}到{$eday},{$days}天的{$sort['name']},请您注意查看并处理");
                 // 					$alipayConfig = M('Alipay_config')->where(array('token' => $this->token))->find();
                 // 					if ($_POST['paymode'] == 1 && $alipayConfig['open']) {
                 // 						$this->success('正在提交中...', U('Alipay/pay',array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'from'=> 'Hotels', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $_POST['price'])));
                 // 					} elseif ($_POST['paymode'] == 4 && $this->fans['balance']) {
                 // 						$this->success('正在提交中...', U('CardPay/pay',array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'from'=> 'Hotels', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $_POST['price'])));
                 // 					} else {
                 // 						$model = new templateNews();
                 // 						$model->sendTempMsg('TM00820', array('href' => U('Hotels/my',array('token' => $this->token, 'wecha_id' => $this->wecha_id)), 'wecha_id' => $this->wecha_id, 'first' => '预订房间提醒', 'keynote1' => '订单未支付', 'keynote2' => date("Y年m月d日H时i分s秒"), 'remark' => '预订房间成功,感谢您的光临,欢迎下次再次光临!'));
                 // 						$this->success('预定成功,进入您的订单页', U('Hotels/my',array('token' => $this->token, 'wecha_id' => $this->wecha_id)));
                 // 					}
                 $config = M('Alipay_config')->where(array('token' => $this->token))->find();
                 $model = new templateNews();
                 $model->sendTempMsg('TM00184', array('href' => U('Hotels/my', array('token' => $this->token, 'wecha_id' => $this->wecha_id), true, false, true), 'wecha_id' => $this->wecha_id, 'first' => '预订房间提醒', 'ordertape' => date("Y年m月d日H时i分s秒"), 'ordeID' => $orderid, 'remark' => '预订房间成功,感谢您的光临,欢迎下次再次光临!'));
                 if ($_POST['paymode'] == 4 && $this->fans['balance']) {
                     $this->success('正在提交中...', U('CardPay/pay', array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'from' => 'Hotels', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $_POST['price'])));
                 } elseif ($config['open']) {
                     $this->success('正在提交中...', U('Alipay/pay', array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'from' => 'Hotels', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $_POST['price'])));
                 } else {
                     $this->success('预定成功,进入您的订单页', U('Hotels/my', array('token' => $this->token, 'wecha_id' => $this->wecha_id)));
                 }
             } else {
                 $this->error('操作失败');
             }
         } else {
             $this->error($dataBase->getError());
         }
     }
 }
예제 #9
0
 public function orderInfo()
 {
     $this->product_model = M('Product');
     $this->product_cat_model = M('Product_cat');
     $product_cart_model = M('product_cart');
     $thisOrder = $product_cart_model->where(array('id' => intval($_GET['id']), 'token' => $this->token))->find();
     //检查权限
     if (strtolower($thisOrder['token']) != strtolower($this->_session('token'))) {
         exit;
     }
     if (IS_POST) {
         if (intval($_POST['sent'])) {
             $_POST['handled'] = 1;
         }
         $company = M('Company')->where(array('token' => $this->token, 'isbranch' => 0))->find();
         $save = array('sent' => intval($_POST['sent']), 'logistics' => $_POST['logistics'], 'logisticsid' => $_POST['logisticsid'], 'handled' => 1);
         if ($company['id'] != $this->_cid) {
             empty($thisOrder['paid']) && ($save['paid'] = intval($_POST['paid']));
         } else {
             $save['paid'] = intval($_POST['paid']);
         }
         $product_cart_model->where(array('id' => $thisOrder['id']))->save($save);
         //TODO 发货的短信提醒
         $company = D('Company')->where(array('token' => $thisOrder['token'], 'id' => $thisOrder['cid']))->find();
         if ($_POST['sent']) {
             $userInfo = D('Userinfo')->where(array('token' => $thisOrder['token'], 'wecha_id' => $thisOrder['wecha_id']))->find();
             Sms::sendSms($this->token, "您在{$company['name']}商城购买的商品,商家已经给您发货了,请您注意查收", $userInfo['tel']);
         }
         $carts = unserialize($thisOrder['info']);
         $tdata = $this->getCat($carts);
         if (intval($_POST['paid']) && empty($thisOrder['paid'])) {
             $list = array();
             $info = '';
             $pre = '';
             foreach ($tdata[0] as $va) {
                 $t = array();
                 if (!empty($va['detail'])) {
                     foreach ($va['detail'] as $v) {
                         $t = array('num' => $v['count'], 'colorName' => $v['colorName'], 'formatName' => $v['formatName'], 'price' => $v['price'], 'name' => $va['name']);
                         $list[] = $t;
                     }
                 } else {
                     $t = array('num' => $va['count'], 'price' => $va['price'], 'name' => $va['name']);
                     $list[] = $t;
                 }
                 $info .= $pre . $va['name'];
                 $pre = ',';
             }
             if (intval($thisOrder['price'])) {
                 //支付订单打印
                 $op = new orderPrint();
                 $msg = array('companyname' => $company['name'], 'companytel' => $company['tel'], 'truename' => $thisOrder['truename'], 'tel' => $thisOrder['tel'], 'address' => $thisOrder['address'], 'buytime' => $thisOrder['time'], 'orderid' => $thisOrder['orderid'], 'sendtime' => '', 'price' => $thisOrder['price'], 'total' => $thisOrder['total'], 'list' => $list);
                 $msg = ArrayToStr::array_to_str($msg, 1);
                 $op->printit($this->token, $this->_cid, 'Store', $msg, 1);
             }
             if ($thisOrder['twid']) {
                 //给分佣者增加分佣记录
                 if ($set = M("Twitter_set")->where(array('token' => $this->token, 'cid' => $thisOrder['cid']))->find()) {
                     $price = $set['percent'] * 0.01 * $thisOrder['totalprice'];
                     $info = $info ? '购买' . $info . '等产品,订单号:' . $thisOrder['orderid'] : '购买订单号:' . $thisOrder['orderid'];
                     D("Twitter_log")->add(array('token' => $this->token, 'cid' => $thisOrder['cid'], 'twid' => $thisOrder['twid'], 'type' => 3, 'dateline' => time(), 'param' => $thisOrder['totalprice'], 'price' => $price, 'wecha_id' => $thisOrder['wecha_id'], 'info' => $info));
                     if ($count = M("Twitter_count")->where(array('token' => $this->token, 'cid' => $thisOrder['cid'], 'twid' => $thisOrder['twid']))->find()) {
                         D("Twitter_count")->where(array('id' => $count['id']))->setInc('total', $price);
                     } else {
                         D("Twitter_count")->add(array('token' => $this->token, 'cid' => $thisOrder['cid'], 'twid' => $thisOrder['twid'], 'total' => $price, 'remove' => 0));
                     }
                 }
             }
         }
         /*******************销量的增加******************************/
         if (intval($_POST['paid']) && empty($thisOrder['paid'])) {
             foreach ($carts as $k => $c) {
                 $this->product_model->where(array('id' => $k))->setInc('salecount', $tdata[1][$k]['total']);
             }
         }
         /*******************销量的增加******************************/
         $this->success('修改成功', U('Store/orderInfo', array('token' => session('token'), 'id' => $thisOrder['id'])));
     } else {
         //订餐信息
         $product_diningtable_model = M('product_diningtable');
         if ($thisOrder['tableid']) {
             $thisTable = $product_diningtable_model->where(array('id' => $thisOrder['tableid']))->find();
             $thisOrder['tableName'] = $thisTable['name'];
         }
         $this->assign('thisOrder', $thisOrder);
         $carts = unserialize($thisOrder['info']);
         $totalFee = 0;
         $totalCount = 0;
         $data = $this->getCat($carts);
         if (isset($data[1])) {
             foreach ($data[1] as $pid => $row) {
                 $totalCount += $row['total'];
                 $totalFee += $row['totalPrice'];
                 $listNum[$pid] = $row['total'];
             }
         }
         $list = $data[0];
         $this->assign('products', $list);
         $this->assign('totalFee', $totalFee);
         $this->assign('totalCount', $totalCount);
         $this->assign('mailprice', $data[2]);
         $this->display();
     }
 }
예제 #10
0
	public function orderInfo()
	{
		$this->product_model = M('Product');
		$this->product_cat_model = M('Product_cat');
		$product_cart_model = M('product_cart');
		$thisOrder = $product_cart_model->where(array('id' => intval($_GET['id']), 'token' => $this->token))->find();

		if (strtolower($thisOrder['token']) != strtolower($this->_session('token'))) {
			exit();
		}

		if (IS_POST) {
			if (intval($_POST['sent'])) {
				$_POST['handled'] = 1;
			}

			$company = M('Company')->where(array('token' => $this->token, 'isbranch' => 0))->find();
			$save = array('sent' => intval($_POST['sent']), 'logistics' => $_POST['logistics'], 'logisticsid' => $_POST['logisticsid'], 'handled' => 1);

			if ($company['id'] != $this->_cid) {
				empty($thisOrder['paid']) && $save['paid'] = intval($_POST['paid']);
			}
			else {
				$save['paid'] = intval($_POST['paid']);
			}

			$product_cart_model->where(array('id' => $thisOrder['id']))->save($save);
			$company = D('Company')->where(array('token' => $thisOrder['token'], 'id' => $thisOrder['cid']))->find();

			if ($_POST['sent']) {
				$userInfo = D('Userinfo')->where(array('token' => $thisOrder['token'], 'wecha_id' => $thisOrder['wecha_id']))->find();
				Sms::sendSms($this->token, '您在' . $company['name'] . '商城购买的商品,商家已经给您发货了,请您注意查收', $userInfo['tel']);
			}

			$carts = unserialize($thisOrder['info']);
			$tdata = $this->getCat($carts);
			if (intval($_POST['paid']) && empty($thisOrder['paid'])) {
				$list = array();
				$info = '';
				$pre = '';

				foreach ($tdata[0] as $va) {
					$t = array();

					if (!empty($va['detail'])) {
						foreach ($va['detail'] as $v) {
							$t = array('num' => $v['count'], 'colorName' => $v['colorName'], 'formatName' => $v['formatName'], 'price' => $v['price'], 'name' => $va['name']);
							$list[] = $t;
						}
					}
					else {
						$t = array('num' => $va['count'], 'price' => $va['price'], 'name' => $va['name']);
						$list[] = $t;
					}

					$info .= $pre . $va['name'];
					$pre = ',';
				}

				if (intval($thisOrder['price'])) {
					$op = new orderPrint();
					$msg = array('companyname' => $company['name'], 'companytel' => $company['tel'], 'truename' => $thisOrder['truename'], 'tel' => $thisOrder['tel'], 'address' => $thisOrder['address'], 'buytime' => $thisOrder['time'], 'orderid' => $thisOrder['orderid'], 'sendtime' => '', 'price' => $thisOrder['price'], 'total' => $thisOrder['total'], 'list' => $list);
					$msg = ArrayToStr::array_to_str($msg, 1);
					$op->printit($this->token, $this->_cid, 'Store', $msg, 1);
				}

				if ($thisOrder['twid']) {
					if ($set = M('Twitter_set')->where(array('token' => $this->token, 'cid' => $thisOrder['cid']))->find()) {
						$price = $set['percent'] * 0.01 * $thisOrder['totalprice'];
						$info = ($info ? '购买' . $info . '等产品,订单号:' . $thisOrder['orderid'] : '购买订单号:' . $thisOrder['orderid']);
						D('Twitter_log')->add(array('token' => $this->token, 'cid' => $thisOrder['cid'], 'twid' => $thisOrder['twid'], 'type' => 3, 'dateline' => time(), 'param' => $thisOrder['totalprice'], 'price' => $price, 'wecha_id' => $thisOrder['wecha_id'], 'info' => $info));

						if ($count = M('Twitter_count')->where(array('token' => $this->token, 'cid' => $thisOrder['cid'], 'twid' => $thisOrder['twid']))->find()) {
							D('Twitter_count')->where(array('id' => $count['id']))->setInc('total', $price);
						}
						else {
							D('Twitter_count')->add(array('token' => $this->token, 'cid' => $thisOrder['cid'], 'twid' => $thisOrder['twid'], 'total' => $price, 'remove' => 0));
						}

						$userinfo = D('Userinfo')->where(array('twid' => $thisOrder['twid']))->find();
						$messages = $params = array();

						if ($userinfo['tel']) {
							$messages[] = 'SmsMessage';
							$params['sms'] = array('token' => $this->token, 'content' => '您分享的商城被您的朋友点击查看,您将从商家哪儿获得' . $price . '元的佣金,请您查看', 'moblie' => $userinfo['tel']);
						}

						$messages[] = 'TemplateMessage';
						$params['template'] = array();
						$params['template']['template_id'] = 'OPENTM201812627';
						$params['template']['template_data']['href'] = C('site_url') . '/index.php?g=Wap&m=Store&a=detail&token=' . $this->token . '&wecha_id=' . $userinfo['wecha_id'] . '&twid=' . $userinfo['twid'];
						$params['template']['template_data']['wecha_id'] = $userinfo['wecha_id'];
						$params['template']['template_data']['first'] = '您获得了一笔新的佣金';
						$params['template']['template_data']['keyword1'] = $price;
						$params['template']['template_data']['keyword2'] = date('Y年m月d日 H:i');
						$params['template']['template_data']['remark'] = '请进入店铺查看详情';
						MessageFactory::method($params, $messages);
					}
				}
			}

			if (intval($_POST['paid']) && empty($thisOrder['paid'])) {
				foreach ($carts as $k => $c) {
					$this->product_model->where(array('id' => $k))->setInc('salecount', $tdata[1][$k]['total']);
				}
			}

			$this->success('修改成功', U('Store/orderInfo', array('token' => session('token'), 'id' => $thisOrder['id'])));
		}
		else {
			$product_diningtable_model = M('product_diningtable');

			if ($thisOrder['tableid']) {
				$thisTable = $product_diningtable_model->where(array('id' => $thisOrder['tableid']))->find();
				$thisOrder['tableName'] = $thisTable['name'];
			}

			$this->assign('thisOrder', $thisOrder);
			$carts = unserialize($thisOrder['info']);
			$totalFee = 0;
			$totalCount = 0;
			$data = $this->getCat($carts);

			if (isset($data[1])) {
				foreach ($data[1] as $pid => $row) {
					$totalCount += $row['total'];
					$totalFee += $row['totalPrice'];
					$listNum[$pid] = $row['total'];
				}
			}

			$list = $data[0];
			$this->assign('products', $list);
			$this->assign('totalFee', $totalFee);
			$this->assign('totalCount', $totalCount);
			$this->assign('mailprice', $data[2]);
			$this->display();
		}
	}
예제 #11
0
 public function meal_order_check_refund()
 {
     if (empty($this->user_session)) {
         $this->error_tips('请先进行登录!');
     }
     $orderid = intval($_GET['orderid']);
     $store_id = intval($_GET['store_id']);
     $now_order = M("Meal_order")->where(array('order_id' => $orderid, 'mer_id' => $this->mer_id, 'store_id' => $store_id))->find();
     if (empty($now_order)) {
         $this->error_tips('当前订单不存在');
     }
     if (empty($now_order['paid'])) {
         $this->error_tips('当前订单还未付款!');
     }
     if (!empty($now_order['status'])) {
         if ($now_order['meal_type']) {
             $this->error_tips('订单必须是未消费状态才能取消!', U('Takeout/order_detail', array('order_id' => $now_order['order_id'], 'store_id' => $store_id, 'mer_id' => $this->mer_id)));
         } else {
             $this->error_tips('订单必须是未消费状态才能取消!', U('Food/order_detail', array('order_id' => $now_order['order_id'], 'store_id' => $store_id, 'mer_id' => $this->mer_id)));
         }
     }
     $now_order['price'] = $now_order['pay_money'];
     $data_meal_order['pay_money'] = 0;
     $data_meal_order['paid'] = 0;
     //在线付款退款
     if ($now_order['pay_type'] == 'offline') {
         $data_meal_order['order_id'] = $now_order['order_id'];
         $data_meal_order['refund_detail'] = serialize(array('refund_time' => time()));
         $data_meal_order['status'] = 3;
         if (D('Meal_order')->data($data_meal_order)->save()) {
             if ($now_order['meal_type']) {
                 $this->success_tips('您使用的是线下支付!订单状态已修改为已退款。', U('Takeout/order_detail', array('order_id' => $now_order['order_id'], 'store_id' => $store_id, 'mer_id' => $this->mer_id)));
             } else {
                 $this->success_tips('您使用的是线下支付!订单状态已修改为已退款。', U('Food/order_detail', array('order_id' => $now_order['order_id'], 'store_id' => $store_id, 'mer_id' => $this->mer_id)));
             }
             exit;
         } else {
             $this->error_tips('取消订单失败!请重试。');
         }
     }
     if ($now_order['payment_money'] != '0.00') {
         $pay_method = D('Config')->get_pay_method();
         if (empty($pay_method)) {
             $this->error_tips('系统管理员没开启任一一种支付方式!');
         }
         if (empty($pay_method[$now_order['pay_type']])) {
             $this->error_tips('您选择的支付方式不存在,请更新支付方式!');
         }
         $pay_class_name = ucfirst($now_order['pay_type']);
         $import_result = import('@.ORG.pay.' . $pay_class_name);
         if (empty($import_result)) {
             $this->error_tips('系统管理员暂未开启该支付方式,请更换其他的支付方式');
         }
         $now_order['order_type'] = 'meal';
         $pay_class = new $pay_class_name($now_order, $now_order['payment_money'], $now_order['pay_type'], $pay_method[$now_order['pay_type']]['config'], $this->user_session, 1);
         $go_refund_param = $pay_class->refund();
         $data_meal_order['order_id'] = $now_order['order_id'];
         $data_meal_order['refund_detail'] = serialize($go_refund_param['refund_param']);
         if (empty($go_refund_param['error']) && $go_refund_param['type'] == 'ok') {
             $data_meal_order['status'] = 3;
         }
         D('Meal_order')->data($data_meal_order)->save();
         if ($data_meal_order['status'] != 3) {
             $this->error_tips($go_refund_param['msg']);
         }
     }
     //如果使用了优惠券
     if ($now_order['card_id']) {
         $result = D('Member_card_coupon')->add_card($now_order['card_id'], $now_order['mer_id'], $now_order['uid']);
         $param = array('refund_time' => time());
         if ($result['error_code']) {
             $param['err_msg'] = $result['msg'];
         } else {
             $param['refund_id'] = $now_order['order_id'];
         }
         $data_meal_order['order_id'] = $now_order['order_id'];
         $data_meal_order['refund_detail'] = serialize($param);
         $result['error_code'] || ($data_meal_order['status'] = 3);
         D('Meal_order')->data($data_meal_order)->save();
         if ($result['error_code']) {
             $this->error_tips($result['msg']);
         }
         $go_refund_param['msg'] = $result['msg'];
     }
     //平台余额退款
     if ($now_order['balance_pay'] != '0.00') {
         $add_result = D('User')->add_money($now_order['uid'], $now_order['balance_pay'], '退款 ' . $now_order['order_name'] . ' 增加余额');
         $param = array('refund_time' => time());
         if ($result['error_code']) {
             $param['err_msg'] = $result['msg'];
         } else {
             $param['refund_id'] = $now_order['order_id'];
         }
         $data_meal_order['order_id'] = $now_order['order_id'];
         $data_meal_order['refund_detail'] = serialize($param);
         $result['error_code'] || ($data_meal_order['status'] = 3);
         D('Meal_order')->data($data_meal_order)->save();
         if ($result['error_code']) {
             $this->error_tips($result['msg']);
         }
         $go_refund_param['msg'] = $result['msg'];
         // 			if($add_result['error_code']){
         // 				$this->error_tips($add_result['msg']);
         // 			}
         // 			$go_refund_param['msg'] = $add_result['msg'];
         // 			$data_meal_order['order_id'] = $now_order['order_id'];
         // 			$data_meal_order['refund_detail'] = serialize(array('refund_time'=>time()));
         // 			$data_meal_order['status'] = 3;
         // 			D('Meal_order')->data($data_meal_order)->save();
     }
     //商家会员卡余额退款
     if ($now_order['merchant_balance'] != '0.00') {
         $result = D('Member_card')->add_card($now_order['uid'], $now_order['mer_id'], $now_order['merchant_balance'], '退款 ' . $now_order['order_name'] . ' 增加余额');
         $param = array('refund_time' => time());
         if ($result['error_code']) {
             $param['err_msg'] = $result['msg'];
         } else {
             $param['refund_id'] = $now_order['order_id'];
         }
         $data_meal_order['order_id'] = $now_order['order_id'];
         $data_meal_order['refund_detail'] = serialize($param);
         $result['error_code'] || ($data_meal_order['status'] = 3);
         D('Meal_order')->data($data_meal_order)->save();
         if ($result['error_code']) {
             $this->error_tips($result['msg']);
         }
         $go_refund_param['msg'] = $result['msg'];
     }
     //退款打印
     $mer_store = D('Merchant_store')->where(array('mer_id' => $this->mer_id, 'store_id' => $store_id))->find();
     $msg = array();
     $msg['user_name'] = $now_order['name'];
     $msg['user_phone'] = $now_order['phone'];
     $msg['user_address'] = $now_order['address'];
     $msg['user_message'] = $now_order['note'];
     $msg['buy_time'] = date("Y-m-d H:i:s", $now_order['dateline']);
     $msg['goods_list'] = unserialize($now_order['info']);
     $msg['goods_count'] = $now_order['total'];
     $msg['goods_price'] = $now_order['price'];
     $msg['orderid'] = $now_order['order_id'];
     $msg['pay_status'] = '客户退款';
     $msg['pay_type'] = $now_order['pay_type'];
     $msg['store_name'] = $mer_store['name'];
     $msg['store_phone'] = $mer_store['phone'];
     $msg['store_address'] = $mer_store['adress'];
     $msg = ArrayToStr::array_to_str($msg, 0, $this->config['print_format']);
     $op = new orderPrint($this->config['print_server_key'], $this->config['print_server_topdomain']);
     $op->printit($this->mer_id, $store_id, $msg, 1);
     $sms_data = array('mer_id' => $mer_store['mer_id'], 'store_id' => $mer_store['store_id'], 'type' => 'food');
     if ($this->config['sms_cancel_order'] == 1 || $this->config['sms_cancel_order'] == 3) {
         $sms_data['uid'] = $now_order['uid'];
         $sms_data['mobile'] = $now_order['phone'];
         $sms_data['sendto'] = 'user';
         $sms_data['content'] = '您在 ' . $mer_store['name'] . '店中下的订单(订单号:' . $now_order['order_id'] . '),在' . date('Y-m-d H:i:s') . '时已被您取消并退款,欢迎再次光临!';
         Sms::sendSms($sms_data);
     }
     if ($this->config['sms_cancel_order'] == 2 || $this->config['sms_cancel_order'] == 3) {
         $sms_data['uid'] = 0;
         $sms_data['mobile'] = $merchant['phone'];
         $sms_data['sendto'] = 'merchant';
         $sms_data['content'] = '顾客' . $now_order['name'] . '的预定订单(订单号:' . $now_order['order_id'] . '),在' . date('Y-m-d H:i:s') . '时已客户取消并退款!';
         Sms::sendSms($sms_data);
     }
     if ($now_order['meal_type']) {
         $this->success_tips($go_refund_param['msg'], U('Takeout/order_detail', array('order_id' => $now_order['order_id'], 'store_id' => $store_id, 'mer_id' => $this->mer_id)));
     } else {
         $this->success_tips($go_refund_param['msg'], U('Food/order_detail', array('order_id' => $now_order['order_id'], 'store_id' => $store_id, 'mer_id' => $this->mer_id)));
     }
 }
예제 #12
0
 /**
  * 保存订餐人的信息到session
  */
 public function OrderPay()
 {
     $disharr = $_POST['dish'];
     /*         * 菜品id 数组*id 份数 */
     $shopid = intval($_POST['mycid']);
     $totalmoney = floatval(trim($_POST['totalmoney']));
     $totalnum = intval(trim($_POST['totalnum']));
     $ouserName = htmlspecialchars(trim($_POST['ouserName']), ENT_QUOTES);
     $ouserSex = intval(trim($_POST['ouserSex']));
     $ouserTel = htmlspecialchars(trim($_POST['ouserTel']), ENT_QUOTES);
     $ouserAddres = htmlspecialchars(trim($_POST['ouserAddres']), ENT_QUOTES);
     $oarrivalTime = htmlspecialchars(trim($_POST['oarrivalTime']), ENT_QUOTES);
     $omark = htmlspecialchars(trim($_POST['omark']), ENT_QUOTES);
     if ($shopid > 0) {
         $jumpurl = U('DishOut/dishMenu', array('token' => $this->token, 'cid' => $shopid, 'wecha_id' => $this->wecha_id));
         if (empty($disharr) || !($totalmoney > 0) || !($totalnum > 0)) {
             $this->exitdisplay('订单信息出错!', $jumpurl);
         }
         if (empty($ouserName) || empty($ouserTel) || empty($ouserAddres)) {
             $this->exitdisplay('订单中相关联系地址:姓名或联系电话或送货地址有没写的', $jumpurl);
         }
         $oarrivalTime = $oarrivalTime ? strtotime(date('Y-m-d ') . $oarrivalTime) : 0;
         $tmparr = array();
         $tmpsubnum = 0;
         $tmpsubmoney = 0;
         foreach ($disharr as $dk => $dv) {
             if (!empty($dv)) {
                 $tmpnum = intval($dv['num']);
                 if ($tmpnum > 0) {
                     $tmpprice = floatval($dv['price']);
                     $tmparr[$dk] = array();
                     $tmparr[$dk]['did'] = $dk;
                     $tmparr[$dk]['num'] = $tmpnum;
                     $tmparr[$dk]['price'] = $tmpprice;
                     $tmparr[$dk]['name'] = $dv['name'];
                     $tmpsubnum += $tmpnum;
                     $tmpsubmoney += $tmpprice * $tmpnum;
                 }
             }
         }
         if (empty($tmparr)) {
             $this->exitdisplay('没有订单信息', $jumpurl);
         }
         $t_tmpsubmoney = (int) $tmpsubmoney * 10000;
         $t_totalmoney = (int) $totalmoney * 10000;
         if ($tmpsubnum != $totalnum || $t_tmpsubmoney != $t_totalmoney) {
             $this->error('订单的金额或点的菜的份数不对', $jumpurl);
         }
         $outset = $this->outManage($shopid);
         if ($outset['stype'] == 2 && $tmpsubmoney < $outset['pricing']) {
             $tmpsubmoney = $outset['pricing'];
             /*                 * 处理起步价方式订单金额不足起步价按起步价收取* */
         }
         $wecha_id = $this->wecha_id ? $this->wecha_id : 'DishOutm_' . $ouserTel;
         $orderid = substr($wecha_id, -5) . date("YmdHis");
         $Orderarr = array('cid' => $shopid, 'wecha_id' => $wecha_id, 'token' => $this->token, 'total' => $tmpsubnum, 'price' => $tmpsubmoney, 'nums' => 1, 'info' => serialize($tmparr), 'name' => $ouserName, 'sex' => $ouserSex, 'tel' => $ouserTel, 'address' => $ouserAddres, 'tableid' => 0, 'time' => time(), 'reservetime' => $oarrivalTime, 'stype' => $outset['stype'], 'paid' => 0, 'isuse' => 0, 'orderid' => $orderid, 'printed' => 0, 'des' => $omark, 'takeaway' => 1, 'comefrom' => 'dishout');
         $orid = D('Dish_order')->add($Orderarr);
         if ($orid) {
             $_SESSION[$this->session_dish_info] = '';
             //TODO 短信提示
             $company = $this->getCompany($shopid);
             Sms::sendSms($this->token, "顾客{$ouserName}刚刚叫了一份外卖,订单号:{$orderid},请您注意查看并处理", $company['mp']);
             $printer_set = $this->getPrinter_set($shopid);
             if (!empty($printer_set) && $printer_set['paid'] == 0) {
                 $op = new orderPrint();
                 $msg = array('companyname' => $company['name'], 'des' => trim($_POST['omark']), 'companytel' => $company['tel'], 'truename' => trim($_POST['ouserName']), 'tel' => trim($_POST['ouserTel']), 'address' => trim($_POST['ouserAddres']), 'buytime' => $Orderarr['time'], 'orderid' => $Orderarr['orderid'], 'sendtime' => $oarrivalTime > 0 ? $oarrivalTime : '尽快送达', 'price' => $Orderarr['price'], 'total' => $Orderarr['total'], 'typename' => '外卖', 'list' => $tmparr);
                 $msg = ArrayToStr::array_to_str($msg, 0);
                 $op->printit($this->token, $shopid, 'DishOut', $msg, 0);
             }
             $alipayConfig = M('Alipay_config')->where(array('token' => $this->token))->find();
             if ($alipayConfig['open']) {
                 $this->success('正在提交中...', U('Alipay/pay', array('token' => $this->token, 'wecha_id' => $wecha_id, 'success' => 1, 'from' => 'DishOut', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $tmpsubmoney)));
             } else {
                 $this->exitdisplay('商家尚未开启支付功能', $jumpurl);
             }
         } else {
             $this->exitdisplay('订单录入系统出错,抱歉给您的带来了不便。请重新下单吧', $jumpurl);
         }
         if (!empty($this->wecha_id)) {
             /* 保存个人信息 */
             $userinfo_model = M('Userinfo');
             $thisUser = $userinfo_model->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
             if (empty($thisUser)) {
                 $userRow = array('tel' => $ouserTel, 'truename' => $ouserName, 'address' => $ouserAddres);
                 $userRow['token'] = $this->token;
                 $userRow['wecha_id'] = $this->wecha_id;
                 $userRow['wechaname'] = '';
                 $userRow['qq'] = 0;
                 $userRow['sex'] = $ouserSex;
                 $userRow['age'] = 0;
                 $userRow['birthday'] = '';
                 $userRow['info'] = '';
                 $userRow['total_score'] = 0;
                 $userRow['sign_score'] = 0;
                 $userRow['expend_score'] = 0;
                 $userRow['continuous'] = 0;
                 $userRow['add_expend'] = 0;
                 $userRow['add_expend_time'] = 0;
                 $userRow['live_time'] = 0;
                 $userinfo_model->add($userRow);
             }
         }
     } else {
         $jumpurl = U('DishOut/index', array('token' => $this->token, 'wecha_id' => $this->wecha_id));
         $this->exitdisplay('订单信息中店面信息出错', $jumpurl);
     }
 }
예제 #13
0
 public function ordersave()
 {
     $row = array();
     $wecha_id = $this->wecha_id ? $this->wecha_id : session('twid');
     $row['truename'] = $this->_post('truename');
     $row['tel'] = $this->_post('tel');
     $row['address'] = $this->_post('address');
     $row['token'] = $this->token;
     $row['wecha_id'] = $wecha_id;
     $row['paymode'] = isset($_POST['paymode']) ? intval($_POST['paymode']) : 0;
     $row['cid'] = $cid = $this->_isgroup ? $this->mainCompany['id'] : $this->_cid;
     //积分
     $score = isset($_POST['score']) ? intval($_POST['score']) : 0;
     $orid = isset($_POST['orid']) ? intval($_POST['orid']) : 0;
     $product_cart_model = D('Product_cart');
     if ($cartObj = $product_cart_model->where(array('token' => $this->token, 'wecha_id' => $wecha_id, 'id' => $orid))->find()) {
         $carts = unserialize($cartObj['info']);
     } else {
         $carts = $this->_getCart();
     }
     $normal_rt = 0;
     $info = array();
     if ($carts) {
         $calCartInfo = $this->calCartInfo($carts);
         foreach ($carts as $pid => $rowset) {
             $total = 0;
             $tmp = M('product')->where(array('id' => $pid))->find();
             //setDec('num', $total);
             if (is_array($rowset)) {
                 foreach ($rowset as $did => $ro) {
                     $temp = M('Product_detail')->where(array('id' => $did, 'pid' => $pid))->find();
                     //setDec('num', $ro['count']);
                     if ($temp['num'] < $ro['count'] && empty($cartObj)) {
                         $this->error('购买的量超过了库存');
                     }
                     $total += $ro['count'];
                     $price = $this->fans['getcardtime'] ? $temp['vprice'] ? $temp['vprice'] : $temp['price'] : $temp['price'];
                     $info[$pid][$did] = array('count' => $ro['count'], 'price' => $price);
                 }
             } else {
                 $total = $rowset;
                 $price = $this->fans['getcardtime'] ? $tmp['vprice'] ? $tmp['vprice'] : $tmp['price'] : $tmp['price'];
                 $info[$pid] = $rowset . "|" . $price;
             }
             if ($tmp['num'] < $total && empty($cartObj)) {
                 $this->error('购买的量超过了库存');
             }
         }
         $setting = M('Product_setting')->where(array('token' => $this->token, 'cid' => $cid))->find();
         $saveprice = $totalprice = $calCartInfo[1] + $calCartInfo[2];
         if ($score && $setting && $setting['score'] > 0 && $this->fans['total_score'] >= $score) {
             $s = isset($cartObj['score']) ? intval($cartObj['score']) : 0;
             $totalprice -= ($score + $s) / $setting['score'];
             if ($totalprice <= 0) {
                 $score = ($calCartInfo[1] + $calCartInfo[2]) * $setting['score'];
                 $totalprice = 0;
                 $row['paid'] = 1;
                 $row['paymode'] = 5;
                 $row['paytype'] = 'score';
             } else {
                 $score += $s;
             }
         }
         $row['total'] = $calCartInfo[0];
         $row['price'] = $totalprice;
         $row['diningtype'] = 0;
         $row['buytime'] = '';
         $row['tableid'] = 0;
         $row['info'] = serialize($info);
         $row['groupon'] = 0;
         $row['dining'] = 0;
         $row['score'] = $score;
         $row['twid'] = $this->_twid;
         $row['totalprice'] = $saveprice;
         if ($cartObj) {
             //$row['score'] = $cartObj['score'] + $score;
             $row['time'] = $time = time();
             $normal_rt = $product_cart_model->where(array('id' => $orid))->save($row);
             $orderid = $cartObj['orderid'];
         } else {
             //删除库存
             foreach ($carts as $pid => $rowset) {
                 $total = 0;
                 if (is_array($rowset)) {
                     foreach ($rowset as $did => $ro) {
                         M('Product_detail')->where(array('id' => $did, 'pid' => $pid))->setDec('num', $ro['count']);
                         $total += $ro['count'];
                     }
                 } else {
                     if (strstr($rowset, '|')) {
                         $a = explode("|", $rowset);
                         $total = $a[0];
                     } else {
                         $total = $rowset;
                     }
                 }
                 $product_model = M('product');
                 $product_model->where(array('id' => $pid))->setDec('num', $total);
             }
             $row['time'] = $time = time();
             $row['orderid'] = $orderid = date("YmdHis") . rand(100000, 999999);
             $normal_rt = $product_cart_model->add($row);
         }
         $_SESSION[$this->session_cart_name] = null;
         unset($_SESSION[$this->session_cart_name]);
         //TODO 发货的短信提醒
         if ($normal_rt && empty($orid)) {
             $tdata = $this->getCat($carts);
             $list = array();
             foreach ($tdata[0] as $va) {
                 $t = array();
                 if (!empty($va['detail'])) {
                     foreach ($va['detail'] as $v) {
                         $t = array('num' => $v['count'], 'colorName' => $v['colorName'], 'formatName' => $v['formatName'], 'price' => $v['price'], 'name' => $va['name']);
                         $list[] = $t;
                     }
                 } else {
                     $t = array('num' => $va['count'], 'price' => $va['price'], 'name' => $va['name']);
                     $list[] = $t;
                 }
             }
             $company = D('Company')->where(array('token' => $this->token, 'id' => $cid))->find();
             $op = new orderPrint();
             $msg = array('companyname' => $company['name'], 'companytel' => $company['tel'], 'truename' => $row['truename'], 'tel' => $row['tel'], 'address' => $row['address'], 'buytime' => $row['time'], 'orderid' => $row['orderid'], 'sendtime' => '', 'price' => $row['price'], 'total' => $row['total'], 'list' => $list);
             $msg = ArrayToStr::array_to_str($msg);
             $op->printit($this->token, $this->_cid, 'Store', $msg, 0);
             $userInfo = D('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $wecha_id))->find();
             Sms::sendSms($this->token, "您的顾客{$row['truename']}刚刚下了一个订单,订单号:{$orderid},手机号:{$row['tel']}请您注意查看并处理");
         }
     }
     if ($normal_rt) {
         $product_model = M('product');
         $product_cart_list_model = M('product_cart_list');
         $userinfo_model = M('Userinfo');
         $thisUser = $userinfo_model->where(array('token' => $this->token, 'wecha_id' => $wecha_id))->find();
         if (empty($cartObj)) {
             $crow = array();
             $tdata = $this->getCat($carts);
             foreach ($carts as $k => $c) {
                 $crow['cartid'] = $normal_rt;
                 $crow['productid'] = $k;
                 $crow['price'] = $tdata[1][$k]['totalPrice'];
                 //$c['price'];
                 $crow['total'] = $tdata[1][$k]['total'];
                 $crow['wecha_id'] = $row['wecha_id'];
                 $crow['token'] = $row['token'];
                 $crow['cid'] = $row['cid'];
                 $crow['time'] = $time;
                 $product_cart_list_model->add($crow);
                 //增加销量
                 $totalprice || $product_model->where(array('id' => $k))->setInc('salecount', $tdata[1][$k]['total']);
             }
             //保存个人信息
             if ($_POST['saveinfo']) {
                 $this->assign('thisUser', $thisUser);
                 $userRow = array('tel' => $row['tel'], 'truename' => $row['truename'], 'address' => $row['address']);
                 if ($thisUser) {
                     $userinfo_model->where(array('id' => $thisUser['id']))->save($userRow);
                     // 						$userinfo_model->where(array('id' => $thisUser['id'], 'total_score' => array('egt', $score)))->setDec('total_score', $score);
                     S('fans_' . $this->token . '_' . $this->wecha_id, null);
                 } else {
                     $userRow['token'] = $this->token;
                     $userRow['wecha_id'] = $wecha_id;
                     $userRow['wechaname'] = '';
                     $userRow['qq'] = 0;
                     $userRow['sex'] = -1;
                     $userRow['age'] = 0;
                     $userRow['birthday'] = '';
                     $userRow['info'] = '';
                     $userRow['total_score'] = 0;
                     $userRow['sign_score'] = 0;
                     $userRow['expend_score'] = 0;
                     $userRow['continuous'] = 0;
                     $userRow['add_expend'] = 0;
                     $userRow['add_expend_time'] = 0;
                     $userRow['live_time'] = 0;
                     $userinfo_model->add($userRow);
                 }
             }
             if ($thisUser) {
                 // 					$userinfo_model->where(array('id' => $thisUser['id']))->save($userRow);
                 $userinfo_model->where(array('id' => $thisUser['id'], 'total_score' => array('egt', $score)))->setDec('total_score', $score);
                 S('fans_' . $this->token . '_' . $this->wecha_id, null);
             }
         } else {
             $userinfo_model->where(array('id' => $thisUser['id'], 'total_score' => array('egt', $score - $cartObj['score'])))->setDec('total_score', $score - $cartObj['score']);
             S('fans_' . $this->token . '_' . $this->wecha_id, null);
         }
         //购买商品时的推广记录
         // 			if ($this->_twid) {
         // 				$this->savelog(3, $this->_twid, $this->token, $this->_cid, $saveprice);
         // 			}
         // 			$alipayConfig = M('Alipay_config')->where(array('token' => $this->token))->find();
         // 			if ($totalprice) {
         // 				if ($alipayConfig['open'] && $totalprice && $row['paymode'] == 1) {
         // 					$this->success('正在提交中...', U('Alipay/pay', array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'success' => 1, 'from'=> 'Store', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $totalprice)));
         // 					die;
         // 				} elseif ($this->fans['balance'] > 0 && $row['paymode'] == 4) {
         // 					$this->success('正在提交中...', U('CardPay/pay', array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'success' => 1, 'from'=> 'Store', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $totalprice)));
         // 					die;
         // 				}
         // 			}
         $model = new templateNews();
         $model->sendTempMsg('TM00184', array('href' => U('Store/my', array('token' => $this->token, 'wecha_id' => $wecha_id, 'success' => 1, 'twid' => $this->_twid), true, false, true), 'wecha_id' => $wecha_id, 'first' => '购买商品提醒', 'ordertape' => date("Y年m月d日H时i分s秒"), 'ordeID' => $orderid, 'remark' => '购买成功,感谢您的光临,欢迎下次再次光临!'));
         if ($totalprice) {
             if ($this->fans['balance'] > 0 && $row['paymode'] == 4) {
                 $this->success('正在提交中...', U('CardPay/pay', array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'success' => 1, 'from' => 'Store', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $totalprice)));
                 die;
             } else {
                 $notOffline = $setting['paymode'] == 1 ? 0 : 1;
                 $this->success('正在提交中...', U('Alipay/pay', array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'success' => 1, 'from' => 'Store', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $totalprice, 'notOffline' => $notOffline)));
                 die;
             }
         }
         $this->success('预定成功,进入您的订单页', U('Store/my', array('token' => $_GET['token'], 'wecha_id' => $wecha_id, 'success' => 1, 'twid' => $this->_twid)));
     } else {
         $this->error('订单生产失败');
     }
 }
예제 #14
0
    public function saveOrderAndToPay() {
        $sessionDK = "session_Ordishs{$this->_cid}_{$this->token}";
        $tmpOrderdata = $_SESSION[$sessionDK];
        $tmpOrderdata = !empty($tmpOrderdata) ? unserialize($tmpOrderdata) : false;
        $DishC = $this->getDishCompany($this->_cid);
        $isjiacai = false;
        if (is_array($tmpOrderdata)) {
            $orid = $this->_get('orid') ? intval($this->_get('orid', "trim")) : 0;
            $sessionoridK = "session_orid{$this->_cid}_{$this->token}";
            $sessionorid = $_SESSION[$sessionoridK];
            $allmark = $_SESSION["allmark" . $this->_cid . $this->token];
            if (($orid > 0) && ($orid == $sessionorid)) {
                $takeaway = 2;
                $Dish_order = D('Dish_order');
                $myorder = $Dish_order->where(array('id' => $orid, 'token' => $this->token, 'cid' => $this->_cid))->find();
                if ($myorder) {
                    $orderdish = array();
                    $takeaway = $myorder['takeaway'];
                    $myorderinfo = !empty($myorder['info']) ? unserialize($myorder['info']) : false;
                    if ((empty($myorderinfo) || ((count($myorderinfo) == 1) && isset($myorderinfo['table']))) && ($myorder['total'] == 0)) {

                        $orderdish = $tmpOrderdata['orderdish'];
                        $orderdish['table'] = array('tableid' => $myorder['tableid'], 'num' => 1, 'price' => $myorder['price']);
                    } else {
                        $myorderinfo = unserialize($myorder['info']);
                        $mc = count($myorderinfo);
                        $mc = $mc > 0 ? $mc : 1;
                        foreach ($tmpOrderdata['orderdish'] as $key => $val) {
                            $val['j_c'] = 1;
                            $val['flag'] = $mc;
                            $myorderinfo[$mc . 'jc' . $key] = $val;
                        }
                        $orderdish = $myorderinfo;
                    }
                    $orderid = $myorder['orderid'];
                    $tmporderid = 'order' . date("YmdHis");
                    $tmpOrderarr = array('total' => $tmpOrderdata['totalnum'] + $myorder['total'],
                        'price' => $tmpOrderdata['totalmoney'] + $myorder['price'],
                        'info' => serialize($orderdish), 'paid' => 0, 'allmark' => $allmark, 'tmporderid' => $tmporderid);
                    if ($myorder['paid'] == 1) {
                        //$tmpOrderarr['havepaid'] = $myorder['price'] + $myorder['havepaid']; 注销此处,
                        $tmpOrderarr['paid'] = 0;
                    }
                    $Dish_order->where(array('id' => $orid, 'token' => $this->token, 'cid' => $this->_cid))->save($tmpOrderarr);

                    $Orderarr = array('nums' => $myorder['nums'], 'time' => time(),
                        'allmark' => $allmark, 'orderid' => $myorder['orderid'],
                        'name' => $myorder['name'], 'tel' => $myorder['tel'],
                        'wecha_id' => $myorder['wecha_id'], 'tableid' => $myorder['tableid'],
                        'des' => '', 'sex' => $myorder['sex'], 'tmporderid' => $tmporderid);
                    unset($myorder, $orderdish);
                    $_SESSION[$sessionoridK] = '';
                    $isjiacai = true;
                } else {
                    $jumpurl = U('Repast/dishMenu', array('token' => $this->token, 'cid' => $this->_cid, 'wecha_id' => $this->wecha_id, 'orid' => $orid));
                    $this->error('订单信息出错了', $jumpurl);
                }
            } else {
                $data = $_POST;
                $takeaway = intval($data['takeaway']);
                $youtel = htmlspecialchars(trim($data['youtel']), ENT_QUOTES);
                $youname = htmlspecialchars(trim($data['youname']), ENT_QUOTES);
                $youremark = htmlspecialchars(trim($data['youremark']), ENT_QUOTES);
                $youtableid = isset($data['youtable']) ? intval(trim($data['youtable'])) : 0;
                $isallpay = isset($_POST['isallpay']) ? intval($_POST['isallpay']) : 1; /*                 * 是否要立刻全额支付0不是1是* */
                if (empty($youtel) || empty($youname)) {
                    $this->error('手机号码或顾客姓名没有填写!');
                }
                if (!($youtableid > 0) && ($DishC['offtable'] == 0)) {
                    $this->error('请选择一个餐桌!');
                }
                $wecha_id = $this->wecha_id ? $this->wecha_id : 'Repastm_' . $youtel;
                $orderid = substr($wecha_id, -5) . date("YmdHis");
                $Orderarr = array('cid' => $this->_cid, 'wecha_id' => $wecha_id, 'token' => $this->token, 'total' => $tmpOrderdata['totalnum'], 'price' => $tmpOrderdata['totalmoney'], 'tmporderid' => $orderid);
                if ($takeaway == 0) {
                    /* $date=trim($data['date']);
                      $time=trim($data['time']);
                      $number=intval(trim($data['number']));
                      if(empty($date) || empty($time)){
                      $this->error('就餐时间没有填写完整!');
                      }
                      if(!($number>0)){
                      $this->error('就餐人数填写有误!');
                      } */
                    $Orderarr['nums'] = $number;
                    $Orderarr['reservetime'] = strtotime($date . ' ' . $time);
                } else {
                    $Orderarr['nums'] = 1;
                    $Orderarr['reservetime'] = time();
                }
                $Orderarr['info'] = serialize($tmpOrderdata['orderdish']);
                $Orderarr['name'] = $youname;
                $Orderarr['sex'] = intval(trim($data['yousex']));
                $Orderarr['tel'] = $youtel;
                $Orderarr['address'] = '';
                $Orderarr['tableid'] = $youtableid;
                $Orderarr['time'] = time();
                $Orderarr['stype'] = 0;
                $Orderarr['paid'] = 0;
                $Orderarr['isuse'] = 0;
                $Orderarr['orderid'] = $orderid;
                $Orderarr['printed'] = 0;
                $Orderarr['des'] = $youremark;
                $Orderarr['allmark'] = $allmark;
                $Orderarr['takeaway'] = $takeaway;
                $Orderarr['advancepay'] = !($isallpay > 0) ? $DishC['advancepay'] : 0;
                $Orderarr['isover'] = !($isallpay > 0) ? 1 : 0; /*                 * 订单支付是否结束1进行2结束* */
                $orid = M('Dish_order')->add($Orderarr);
                $datas['wechaname'] = $this->_POST('youname');
                $datas['sex'] = $this->_POST('yousex');
                $datas['tel'] = $this->_POST('youtel');
                $wheres['token']=$this->token;
                $wheres['wecha_id']=$this->wecha_id;
                $dbs=M('Userinfo');
                $find=$dbs->where($where)->find();
                if($find == null){
                	$dbs->add($datas);
                }else{
                	$dbs->where($wheres)->save($datas);
                }
            }
            if ($orid) {
                $_SESSION[$sessionDK] = '';
                $sessionK = "session_dishs{$this->_cid}_{$this->token}";
                $_SESSION[$sessionK] = '';
                /*                 * 更新餐桌状态* */
                if ($takeaway == 2) {
                    M('Dining_table')->where(array('cid' => $this->_cid, 'id' => $Orderarr['tableid']))->save(array('status' => 1));
                }
                $t_table = M("Dining_table")->where(array('cid' => $this->_cid, 'id' => $Orderarr['tableid']))->find();
                //TODO 短信提示
                $company = $this->getCompany($this->_cid);
                $msgstr = "顾客{$youname}他刚刚点了一份餐,订单号:{$orderid},请您注意查看并处理";
                if ($isjiacai)
                    $msgstr = "顾客{$youname}他刚刚在订单号为 {$orderid} 里加了菜,请您注意查看并处理";
                Sms::sendSms($this->token, $msgstr, $company['mp']);
				
				//给商家发站内信
				$params = array();
				if($isjiacai){
					$siteMessage = "顾客{$youname}他刚刚在订单号为 {$orderid} 里加了菜,请您注意查看并处理";
				}else{
					$siteMessage = "顾客{$youname}他刚刚点了一份餐,订单号:{$orderid},请您注意查看并处理";
				}
				$params['site'] = array('token'=>$this->token, 'from'=>'微餐饮消息','content'=>$siteMessage);
				MessageFactory::method($params, 'SiteMessage');
//                 $printer_set = $this->getPrinter_set($this->_cid);
//                 if (!empty($printer_set) && ($printer_set['paid'] == 0)) {
                    $op = new orderPrint();
                    $msg = array('companyname' => $company['name'], 'des' => $Orderarr['allmark'] ? $Orderarr['allmark'] : $Orderarr['des'],
                        'companytel' => $company['tel'], 'truename' => $Orderarr['name'],
                        'tel' => $Orderarr['tel'], 'address' => '',
                        'buytime' => $Orderarr['time'], 'orderid' => $Orderarr['orderid'],
                        'price' => $tmpOrderdata['totalmoney'],
                        'total' => $tmpOrderdata['totalnum'], 'typename' => $takeaway == 2 ? '现场点餐' : '预约点餐',
                        'tablename' => $t_table['name'],
                        'list' => $tmpOrderdata['orderdish']);
                    if (isset($isallpay) && ($isallpay == 0)) {
                        $advancepay = $msg['advancepay'] = $DishC['advancepay'];
                    }
                    $msg = ArrayToStr::array_to_str($msg, 0);
                    $op->printit($this->token, $this->_cid, 'Repast', $msg, 0);
                    
                    /*厨房打印菜单*/
                    if ($kitchens_list = D('Dish_kitchen')->where(array('cid' => $this->_cid))->select()) {
	                    $t_list = array();
	                    foreach ($tmpOrderdata['orderdish'] as $dish) $t_list[$dish['kitchen_id']][] = $dish;
	                    
	                    $kitchens = array();
	                    foreach ($kitchens_list as $kit_row) $kitchens[$kit_row['id']] = $kit_row;
	                    
	                    $print_msg = array('des' => $Orderarr['allmark'] ? $Orderarr['allmark'] : $Orderarr['des'], 'truename' => $Orderarr['name'], 'buytime' => $Orderarr['time'], 'orderid' => $Orderarr['orderid'], 'typename' => $takeaway == 2 ? '现场点餐' : '预约点餐', 'tablename' => $t_table['name']);
	                    foreach ($t_list as $k => $rowset) {
	                    	if ($k) {
	                    		if (isset($kitchens[$k]) && $kitchens[$k]['status']) {
	                    			for ($i = 0; $i < count($rowset); $i++) {
			                    		$msg = $print_msg;
			                    		$msg['list'][] = $rowset[$i];
					                    $msg = ArrayToStr::array_to_str($msg, 0);
					                    $op->printit($this->token, $this->_cid, 'Repast', $msg, 0, '', $k);
	                    			}
	                    		} else {
		                    		$msg = $print_msg;
		                    		$msg['list'] = $rowset;
				                    $msg = ArrayToStr::array_to_str($msg, 0);
				                    $op->printit($this->token, $this->_cid, 'Repast', $msg, 0, '', $k);
	                    		}
	                    	}
	                    }
                    }
                    /*厨房打印菜单*/
//                 }
                $alipayConfig = M('Alipay_config')->where(array('token' => $this->token))->find();

                if ($alipayConfig['open']) {
                    $msgstr = isset($advancepay) ? '需要支付 ' . $advancepay . ' 元就餐预定金<br/>正在提交中...' : '正在提交中...';
                    $paydata = array('token' => $this->token, 'wecha_id' => $Orderarr['wecha_id'], 'success' => 1, 'from' => 'Repast', 'orderName' => $Orderarr['tmporderid'], 'single_orderid' => $Orderarr['tmporderid'], 'price' => $tmpOrderdata['totalmoney']);
                    if (isset($advancepay) && ($advancepay > 0)) {
                        $paydata['price'] = $advancepay;
                        $paydata['advancepay'] = 1;
                    }
                    $this->success($msgstr, U('Alipay/pay', $paydata));
                } /* elseif ($this->fans['balance']) {
                  $this->success('正在提交中...', U('CardPay/pay',array('token' => $this->token, 'wecha_id' => $wecha_id, 'success' => 1, 'from'=> 'Repast', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $tmpOrderdata['totalmoney'])));
                  } */ else {
                    $this->error('商家尚未开启支付功能', $jumpurl);
                }
            } else {
                $this->error('订单录入系统出错,抱歉给您的带来了不便。请重新下单吧', $jumpurl);
            }
            if (!empty($this->wecha_id)) {
                /* 保存个人信息 */
                $userinfo_model = M('Userinfo');
                $thisUser = $userinfo_model->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
                if (empty($thisUser)) {
                    $userRow = array('tel' => $Orderarr['tel'], 'truename' => $Orderarr['name'], 'address' => '');
                    $userRow['token'] = $this->token;
                    $userRow['wecha_id'] = $this->wecha_id;
                    $userRow['wechaname'] = '';
                    $userRow['qq'] = 0;
                    $userRow['sex'] = $Orderarr['sex'] == 1 ? 1 : 2;
                    $userRow['age'] = 0;
                    $userRow['birthday'] = '';
                    $userRow['info'] = '';

                    $userRow['total_score'] = 0;
                    $userRow['sign_score'] = 0;
                    $userRow['expend_score'] = 0;
                    $userRow['continuous'] = 0;
                    $userRow['add_expend'] = 0;
                    $userRow['add_expend_time'] = 0;
                    $userRow['live_time'] = 0;
                    $userinfo_model->add($userRow);
                }
            }
        } else {
            $jumpurl = U('Repast/index', array('token' => $this->token, 'wecha_id' => $this->wecha_id));
            $this->error('没有点菜', $jumpurl);
        }
    }
예제 #15
0
 public function add_recevice()
 {
     $queue_type = $this->_post('type', 'trim');
     $token = $this->_post('token', 'trim');
     $store_id = $this->_post('store_id', 'intval');
     if (empty($queue_type) || empty($token) || empty($store_id)) {
         echo json_encode(array('stat' => 'FAIL', 'data' => ''));
         exit;
     }
     $store_info = M('numqueue_store')->where(array('id' => $store_id))->find();
     $opentime = mktime((int) $store_info['opentime'], 0, 0, date('m'), date('d'), date('Y'));
     $closetime = mktime((int) $store_info['closetime'], 0, 0, date('m'), date('d'), date('Y'));
     if (time() < $opentime || $closetime < time()) {
         echo json_encode(array('stat' => 'FAIL', 'data' => '营业时间未到'));
         exit;
     }
     $where = array();
     $where['store_id'] = $store_id;
     $where['token'] = $token;
     $where['queue_type'] = $queue_type;
     $where['add_time'] = array('egt', strtotime(date('Y-m-d 00:00:00', time())));
     $total = M('numqueue_receive')->where($where)->count();
     $data = array();
     $data['store_id'] = $store_id;
     $data['queue_type'] = $queue_type;
     $data['queue_number'] = $queue_type . ($total + 1);
     $data['token'] = $token;
     $data['add_time'] = time();
     $data['status'] = 1;
     $add = M('numqueue_receive')->add($data);
     if ($add) {
         $wait_type = unserialize($store_info['type_name']);
         $msg = '';
         $msg .= chr(10) . '餐厅名称:' . $store_info['name'];
         $msg .= chr(10) . '排号类型:' . $wait_type[$queue_type];
         $msg .= chr(10) . '等待位数:' . $total;
         $msg .= chr(10) . '排队号码:' . $data['queue_number'];
         $msg .= chr(10) . '取号时间:' . date('YmdHis');
         $msg .= chr(10) . '联系电话:' . $store_info['tel'];
         $msg .= chr(10) . '*******************************';
         $msg .= chr(10) . '谢谢惠顾,欢迎下次光临!';
         $op = new orderPrint();
         $op->printit($token, 0, 'Numqueue', $msg, 0);
         $first_number = M('numqueue_receive')->where(array('store_id' => $store_id, 'queue_type' => $queue_type, 'status' => 1))->order('add_time asc')->limit(1)->getField('queue_number');
         echo json_encode(array('stat' => 'DONE', 'data' => $first_number));
         exit;
     } else {
         echo json_encode(array('stat' => 'FAIL', 'data' => '增加失败'));
         exit;
     }
 }
예제 #16
0
 public function meal_edit()
 {
     $order_id = isset($_GET['order_id']) ? intval($_GET['order_id']) : 0;
     $store_id = intval($this->store['store_id']);
     if (IS_POST) {
         if (isset($_POST['status'])) {
             $status = intval($_POST['status']);
             if ($order = D("Meal_order")->where(array('mer_id' => $this->store['mer_id'], 'order_id' => $order_id, 'store_id' => $store_id))->find()) {
                 $data = array('store_uid' => $this->staff_session['id'], 'status' => $status, 'use_time' => time(), 'last_staff' => $this->staff_session['name']);
                 if (empty($order['third_id']) && $order['pay_type'] == 'offline') {
                     $order['paid'] = 0;
                 }
                 if ($status && $order['paid'] == 0) {
                     //将未支付的订单,由店员改成已消费,其订单状态则修改成线下已支付!
                     $data['third_id'] = $order['order_id'];
                     $data['pay_type'] = 'offline';
                     $data['paid'] = 1;
                 }
                 if (D("Meal_order")->where(array('mer_id' => $this->store['mer_id'], 'order_id' => $order_id, 'store_id' => $store_id))->save($data)) {
                     if ($status && $order['status'] == 0) {
                         $mer_store = D('Merchant_store')->where(array('mer_id' => $this->store['mer_id'], 'store_id' => $store_id))->find();
                         $msg = array();
                         $msg['user_name'] = $order['name'];
                         $msg['user_phone'] = $order['phone'];
                         $msg['user_address'] = $order['address'];
                         $msg['user_message'] = $order['note'];
                         $msg['buy_time'] = date("Y-m-d H:i:s", $order['dateline']);
                         $msg['goods_list'] = unserialize($order['info']);
                         $msg['goods_count'] = $order['total'];
                         $msg['goods_price'] = $order['price'];
                         $msg['orderid'] = $order['order_id'];
                         $msg['pay_status'] = '客户已消费';
                         $msg['pay_type'] = $order['pay_type'];
                         $msg['store_name'] = $mer_store['name'];
                         $msg['store_phone'] = $mer_store['phone'];
                         $msg['store_address'] = $mer_store['adress'];
                         $msg = ArrayToStr::array_to_str($msg, 0, $this->config['print_format']);
                         $op = new orderPrint($this->config['print_server_key'], $this->config['print_server_topdomain']);
                         $op->printit($this->store['mer_id'], $store_id, $msg, 1);
                         D('User')->add_score($order['uid'], floor($order['price'] * C('config.user_score_get')), '在 ' . $mer_store['name'] . ' 中消费' . floatval($order['price']) . '元 获得积分');
                         if ($order['merchant_balance'] > 0) {
                             D('Userinfo')->add_score($order['uid'], $order['mer_id'], $order['merchant_balance'], '在 ' . $mer_store['name'] . ' 中消费' . floatval($order['merchant_balance']) . '元 获得积分');
                         }
                         $sms_data = array('mer_id' => $mer_store['mer_id'], 'store_id' => $mer_store['store_id'], 'type' => 'food');
                         if ($this->config['sms_finish_order'] == 1 || $this->config['sms_finish_order'] == 3) {
                             $sms_data['uid'] = $order['uid'];
                             $sms_data['mobile'] = $order['phone'];
                             $sms_data['sendto'] = 'user';
                             $sms_data['content'] = '您在 ' . $mer_store['name'] . '店中下的订单(订单号:' . $order['order_id'] . '),已经完成了消费,如有任何疑意,请您及时联系本店,欢迎再次光临!';
                             Sms::sendSms($sms_data);
                         }
                         if ($this->config['sms_finish_order'] == 2 || $this->config['sms_finish_order'] == 3) {
                             $sms_data['uid'] = 0;
                             $sms_data['mobile'] = $merchant['phone'];
                             $sms_data['sendto'] = 'merchant';
                             $sms_data['content'] = '顾客购买的' . $order['name'] . '的订单(订单号:' . $order['order_id'] . '),已经完成了消费!';
                             Sms::sendSms($sms_data);
                         }
                     }
                     $this->success_tips('更新成功', U('Storestaff/meal_edit', array('order_id' => $order['order_id'])));
                 } else {
                     $this->error_tips('更新失败,稍后再试');
                 }
             } else {
                 $this->error_tips('不合法的请求');
             }
         } else {
             $this->redirect(U('Storestaff/meal_list'));
         }
     } else {
         $order = D("Meal_order")->where(array('mer_id' => $this->store['mer_id'], 'order_id' => $order_id, 'store_id' => $store_id))->find();
         $order['info'] = unserialize($order['info']);
         if ($order['store_uid']) {
             $staff = D("Merchant_store_staff")->where(array('id' => $order['store_uid']))->find();
             $order['store_uname'] = $staff['name'];
         }
         if (empty($order['third_id']) && $order['pay_type'] == 'offline') {
             $order['paid'] = 0;
         }
         if (!empty($order['pay_type'])) {
             $order['paytypestr'] = D('Pay')->get_pay_name($order['pay_type']);
             if ($order['pay_type'] == 'offline' && !empty($order['third_id']) && $order['paid'] == 1) {
                 $order['paytypestr'] .= '<span style="color:green">&nbsp; 已支付</span>';
             } else {
                 if ($order['pay_type'] != 'offline' && $order['paid'] == 1) {
                     $order['paytypestr'] .= '<span style="color:green">&nbsp; 已支付</span>';
                 } else {
                     $order['paytypestr'] .= '<span style="color:red">&nbsp; 未支付</span>';
                 }
             }
         } else {
             $order['paytypestr'] = '未知';
         }
         $this->assign('order', $order);
         $this->display();
     }
 }
예제 #17
0
 public function ordersave()
 {
     $row = array();
     $wecha_id = $this->wecha_id;
     $row['truename'] = $this->_post('truename');
     $row['tel'] = $this->_post('tel');
     $row['address'] = $this->_post('address');
     $row['note'] = $this->_post('note');
     $row['token'] = $this->token;
     $row['wecha_id'] = $wecha_id;
     $row['paymode'] = isset($_POST['paymode']) ? intval($_POST['paymode']) : 0;
     $row['cid'] = $cid = $this->_isgroup ? $this->mainCompany['id'] : $this->_cid;
     if (empty($row['address'])) {
         $this->error('未填写收货地址');
     }
     if (empty($row['tel'])) {
         $this->error('未填写联系电话');
     }
     if (empty($row['truename'])) {
         $this->error('未填写收货人姓名');
     }
     //积分
     $score = isset($_POST['score']) ? intval($_POST['score']) : 0;
     $orid = isset($_POST['orid']) ? intval($_POST['orid']) : 0;
     $product_cart_model = D('New_product_cart');
     if ($cartObj = $product_cart_model->where(array('token' => $this->token, 'wecha_id' => $wecha_id, 'id' => $orid))->find()) {
         $carts = unserialize($cartObj['info']);
     } else {
         $carts = $this->_getCart();
     }
     $normal_rt = 0;
     $info = array();
     if ($carts) {
         $calCartInfo = $this->calCartInfo($carts);
         foreach ($carts as $pid => $rowset) {
             $total = 0;
             $tmp = M('New_product')->where(array('id' => $pid))->find();
             //setDec('num', $total);
             if (is_array($rowset)) {
                 foreach ($rowset as $did => $ro) {
                     $temp = M('New_product_detail')->where(array('id' => $did, 'pid' => $pid))->find();
                     //setDec('num', $ro['count']);
                     if ($temp['num'] < $ro['count'] && empty($cartObj)) {
                         $this->error('购买的量超过了库存');
                     }
                     $total += $ro['count'];
                     $price = $this->fans['getcardtime'] ? $temp['vprice'] ? $temp['vprice'] : $temp['price'] : $temp['price'];
                     $info[$pid][$did] = array('count' => $ro['count'], 'price' => $price);
                 }
             } else {
                 $total = $rowset;
                 $price = $this->fans['getcardtime'] ? $tmp['vprice'] ? $tmp['vprice'] : $tmp['price'] : $tmp['price'];
                 $info[$pid] = $rowset . "|" . $price;
             }
             if ($tmp['num'] < $total && empty($cartObj)) {
                 $this->error('购买的量超过了库存');
             }
         }
         $setting = M('New_product_setting')->where(array('token' => $this->token, 'cid' => $cid))->find();
         $saveprice = $totalprice = $calCartInfo[1] + $calCartInfo[2];
         if ($score && $setting && $setting['score'] > 0 && $this->fans['total_score'] >= $score) {
             $s = isset($cartObj['score']) ? intval($cartObj['score']) : 0;
             $totalprice -= ($score + $s) / $setting['score'];
             if ($totalprice <= 0) {
                 $score = ($calCartInfo[1] + $calCartInfo[2]) * $setting['score'];
                 $totalprice = 0;
                 $row['paid'] = 1;
                 $row['paymode'] = 5;
             } else {
                 $score += $s;
             }
         }
         $row['total'] = $calCartInfo[0];
         $row['price'] = $totalprice;
         $row['diningtype'] = 0;
         $row['buytime'] = '';
         $row['tableid'] = 0;
         $row['info'] = serialize($info);
         $row['groupon'] = 0;
         $row['dining'] = 0;
         $row['score'] = $score;
         $row['twid'] = $this->_twid;
         $row['totalprice'] = $saveprice;
         if ($cartObj) {
             //$row['score'] = $cartObj['score'] + $score;
             $row['time'] = $time = time();
             $normal_rt = $product_cart_model->where(array('id' => $orid))->save($row);
             $orderid = $cartObj['orderid'];
         } else {
             //删除库存
             foreach ($carts as $pid => $rowset) {
                 $total = 0;
                 if (is_array($rowset)) {
                     foreach ($rowset as $did => $ro) {
                         M('New_product_detail')->where(array('id' => $did, 'pid' => $pid))->setDec('num', $ro['count']);
                         $total += $ro['count'];
                     }
                 } else {
                     if (strstr($rowset, '|')) {
                         $a = explode("|", $rowset);
                         $total = $a[0];
                     } else {
                         $total = $rowset;
                     }
                 }
                 $product_model = M('New_product');
                 $product_model->where(array('id' => $pid))->setDec('num', $total);
             }
             $row['time'] = $time = time();
             $row['orderid'] = $orderid = date("YmdHis") . rand(100000, 999999);
             $normal_rt = $product_cart_model->add($row);
         }
         $_SESSION[$this->session_cart_name] = null;
         unset($_SESSION[$this->session_cart_name]);
         //TODO 发货的短信提醒
         if ($normal_rt && empty($orid)) {
             $tdata = $this->getCat($carts);
             $list = array();
             foreach ($tdata[0] as $va) {
                 $t = array();
                 if (!empty($va['detail'])) {
                     foreach ($va['detail'] as $v) {
                         $t = array('num' => $v['count'], 'colorName' => $v['colorName'], 'formatName' => $v['formatName'], 'price' => $v['price'], 'name' => $va['name']);
                         $list[] = $t;
                     }
                 } else {
                     $t = array('num' => $va['count'], 'price' => $va['price'], 'name' => $va['name']);
                     $list[] = $t;
                 }
             }
             $company = D('Company')->where(array('token' => $this->token, 'id' => $cid))->find();
             $op = new orderPrint();
             $msg = array('companyname' => $company['name'], 'companytel' => $company['tel'], 'truename' => $row['truename'], 'tel' => $row['tel'], 'address' => $row['address'], 'buytime' => $row['time'], 'orderid' => $row['orderid'], 'sendtime' => '', 'price' => $row['price'], 'total' => $row['total'], 'list' => $list);
             $msg = ArrayToStr::array_to_str($msg);
             $op->printit($this->token, $this->_cid, 'Store', $msg, 0);
             $userInfo = D('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $wecha_id))->find();
             Sms::sendSms($this->token, "您的顾客{$row['truename']}刚刚下了一个订单,订单号:{$orderid},手机号:{$row['tel']}请您注意查看并处理");
         }
     }
     if ($normal_rt) {
         $product_model = M('New_product');
         $product_cart_list_model = M('New_product_cart_list');
         $userinfo_model = M('Userinfo');
         $thisUser = $userinfo_model->where(array('token' => $this->token, 'wecha_id' => $wecha_id))->find();
         if (empty($cartObj)) {
             $crow = array();
             $tdata = $this->getCat($carts);
             foreach ($carts as $k => $c) {
                 $crow['cartid'] = $normal_rt;
                 $crow['productid'] = $k;
                 $crow['price'] = $tdata[1][$k]['totalPrice'];
                 //$c['price'];
                 $crow['total'] = $tdata[1][$k]['total'];
                 $crow['wecha_id'] = $row['wecha_id'];
                 $crow['token'] = $row['token'];
                 $crow['cid'] = $row['cid'];
                 $crow['time'] = $time;
                 $product_cart_list_model->add($crow);
                 //增加销量
                 $totalprice || $product_model->where(array('id' => $k))->setInc('salecount', $tdata[1][$k]['total']);
             }
             //保存个人信息
             if ($_POST['saveinfo']) {
                 $this->assign('thisUser', $thisUser);
                 $userRow = array('tel' => $row['tel'], 'truename' => $row['truename'], 'address' => $row['address']);
                 if ($thisUser) {
                     $userinfo_model->where(array('id' => $thisUser['id']))->save($userRow);
                     // 						$userinfo_model->where(array('id' => $thisUser['id'], 'total_score' => array('egt', $score)))->setDec('total_score', $score);
                     F('fans_token_wechaid', NULL);
                 } else {
                     $userRow['token'] = $this->token;
                     $userRow['wecha_id'] = $wecha_id;
                     $userRow['wechaname'] = '';
                     $userRow['qq'] = 0;
                     $userRow['sex'] = -1;
                     $userRow['age'] = 0;
                     $userRow['birthday'] = '';
                     $userRow['info'] = '';
                     $userRow['total_score'] = 0;
                     $userRow['sign_score'] = 0;
                     $userRow['expend_score'] = 0;
                     $userRow['continuous'] = 0;
                     $userRow['add_expend'] = 0;
                     $userRow['add_expend_time'] = 0;
                     $userRow['live_time'] = 0;
                     $userinfo_model->add($userRow);
                 }
             }
             if ($thisUser) {
                 // 					$userinfo_model->where(array('id' => $thisUser['id']))->save($userRow);
                 $userinfo_model->where(array('id' => $thisUser['id'], 'total_score' => array('egt', $score)))->setDec('total_score', $score);
                 F('fans_token_wechaid', NULL);
             }
         } else {
             $userinfo_model->where(array('id' => $thisUser['id'], 'total_score' => array('egt', $score - $cartObj['score'])))->setDec('total_score', $score - $cartObj['score']);
             F('fans_token_wechaid', NULL);
         }
         //购买商品时的推广记录
         // 			if ($this->_twid) {
         // 				$this->savelog(3, $this->_twid, $this->token, $this->_cid, $saveprice);
         // 			}
         // 			$alipayConfig = M('Alipay_config')->where(array('token' => $this->token))->find();
         // 			if ($totalprice) {
         // 				if ($alipayConfig['open'] && $totalprice && $row['paymode'] == 1) {
         // 					$this->success('正在提交中...', U('Alipay/pay', array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'success' => 1, 'from'=> 'Store', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $totalprice)));
         // 					die;
         // 				} elseif ($this->fans['balance'] > 0 && $row['paymode'] == 4) {
         // 					$this->success('正在提交中...', U('CardPay/pay', array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'success' => 1, 'from'=> 'Store', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $totalprice)));
         // 					die;
         // 				}
         // 			}
         $model = new templateNews();
         $model->sendTempMsg('TM00184', array('href' => U('Storenew/my', array('token' => $this->token, 'wecha_id' => $wecha_id), true, false, true), 'wecha_id' => $wecha_id, 'first' => '' . $row['truename'] . ',您好!您的订单未支付', 'ordertape' => date("Y年m月d日H时i分s秒"), 'ordeID' => $orderid, 'remark' => '本次订单金额:' . $row['price'] . '元,备注信息:' . $row['note'] . ',请及时付款,点击查看详情!'));
         //测试消息服务
         //$where=array('token'=>$this->token);
         //$this->thisWxUser=M('Wxuser')->where($where)->find();
         //$url_get='https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$this->thisWxUser['appid'].'&secret='.$this->thisWxUser['appsecret'];
         //$access_token=json_decode($this->curlGet($url_get));
         //$a = $access_token->access_token;
         //客服接口,24小时内发送过内容的用户才有
         //$url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token='.$a;
         //消息预览接口
         //$url = 'https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token='.$a;
         //$data = '{"touser":"******","msgtype":"text", "text":{"content":"'.$row['truename'].'你订购了商品,电话:'.$row['tel'].',收获地址:'.$row['address'].',订单号:'.$orderid.',订单金额:'.$row['price'].',请及时付款,谢谢!"}}';
         //$this->postCurl($url,$data);
         //
         if ($totalprice) {
             if ($this->fans['balance'] > 0 && $row['paymode'] == 4) {
                 $this->success('正在提交中...', U('CardPay/pay', array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'success' => 1, 'from' => 'Storenew', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $totalprice)));
                 die;
             } else {
                 $notOffline = $setting['paymode'] == 1 ? 0 : 1;
                 $this->success('正在提交中...', U('Alipay/pay', array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'success' => 1, 'from' => 'Storenew', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $totalprice, 'notOffline' => $notOffline)));
                 die;
             }
         }
         $this->success('预定成功,进入您的订单页', U('Storenew/my', array('token' => $_GET['token'], 'wecha_id' => $wecha_id, 'success' => 1, 'twid' => $this->_twid)));
     } else {
         $this->error('订单生产失败');
     }
 }
예제 #18
0
 public function printOrder($orderid)
 {
     $thisOrder = M('product_cart')->where(array('orderid' => $orderid))->find();
     $msg = '';
     $msg = $msg . chr(10) . '姓名:' . $thisOrder['truename'] . chr(10) . '电话:' . $thisOrder['tel'] . chr(10) . '地址:' . $thisOrder['address'] . chr(10) . '下单时间:' . date('Y-m-d H:i:s', $thisOrder['time']) . chr(10) . '配送时间:' . $thisOrder['buytime'] . chr(10) . '*******************************' . chr(10) . $product_list . chr(10) . '*******************************' . chr(10) . '品种数量:' . $thisOrder['total'] . chr(10) . '合计:' . $thisOrder['price'] . '元' . chr(10) . '※※※※※※※※※※※※※※' . chr(10) . '谢谢惠顾,欢迎下次光临' . chr(10) . '订单编号:' . $thisOrder['orderid'];
     $op = new orderPrint();
     $op->printit($this->token, 0, 'Store', $msg);
 }
예제 #19
0
 /**
  * 支付成功后的回调函数
  */
 public function payReturn()
 {
     $orderid = $_GET['orderid'];
     if ($order = M('Hotels_order')->where(array('orderid' => $orderid, 'token' => $this->token))->find()) {
         //TODO 发货的短信提醒
         if ($order['paid']) {
             $sort = M('Hotels_house_sort')->where(array('id' => $order['sid'], 'token' => $this->token))->find();
             $days = (strtotime($order['enddate']) - strtotime($order['startdate'])) / 86400;
             $price = $this->fans['getcardtime'] > 0 ? $sort['vprice'] ? $sort['vprice'] : $sort['price'] : $sort['price'];
             $company = M('Company')->where(array('id' => $order['cid'], 'token' => $this->token))->find();
             $op = new orderPrint();
             $msg = array('companyname' => $company['name'], 'companytel' => $company['tel'], 'truename' => $order['name'], 'tel' => $order['tel'], 'address' => '', 'buytime' => $order['time'], 'orderid' => $order['orderid'], 'sendtime' => '', 'price' => $order['price'], 'total' => $order['nums'], 'list' => array(array('name' => $sort['name'], 'day' => $days, 'price' => $price, 'num' => $order['nums'])));
             $msg = ArrayToStr::array_to_str($msg, 1);
             $op->printit($this->token, $this->_cid, 'Hotel', $msg, 1);
             Sms::sendSms($this->token . "_" . $order['cid'], "顾客{$order['name']}刚刚对订单号:{$orderid}的订单进行了支付,请您注意查看并处理");
             $model = new templateNews();
             $model->sendTempMsg('TM00820', array('href' => U('Hotels/my', array('token' => $this->token, 'wecha_id' => $this->wecha_id)), 'wecha_id' => $this->wecha_id, 'first' => '预订房间提醒', 'keynote1' => '订单已支付', 'keynote2' => date("Y年m月d日H时i分s秒"), 'remark' => '预订房间成功,感谢您的光临,欢迎下次再次光临!'));
         }
         $this->redirect(U('Hotels/my', array('token' => $this->token, 'wecha_id' => $this->wecha_id)));
     } else {
         exit('订单不存在');
     }
 }
예제 #20
0
 /**
  * 提交订单
  */
 public function saveorder()
 {
     $dataBase = D('Hotels_order');
     if (IS_POST) {
         $price = 0;
         if ($sort = M('Hotels_house_sort')->where(array('cid' => $this->_cid, 'token' => $this->token, 'id' => $_POST['sid']))->find()) {
             if ($this->fans['getcardtime'] > 0) {
                 $price = $sort['vprice'] ? $sort['vprice'] : $sort['price'];
             } else {
                 $price = $sort['price'];
             }
         }
         $days = (strtotime($_POST['enddate']) - strtotime($_POST['startdate'])) / 86400;
         $sday = date("Y年m月d日", strtotime($_POST['startdate']));
         $eday = date("Y年m月d日", strtotime($_POST['enddate']));
         if ($_POST['startdate'] < date("Ymd") || $days < 1) {
             $this->error('您预定的时间不正确');
         }
         //处理预定房间的数量
         $in = date("Ymd", strtotime($_POST['startdate']));
         $etime = strtotime($_POST['enddate']);
         $hotelSort = M("Hotels_house_sort")->where(array('id' => $_POST['sid'], 'token' => $this->token))->find();
         $time = strtotime($_POST['startdate']);
         for (; $time < $etime;) {
             $order = M('Hotels_order')->field('sum(nums) as num')->where(array('startdate' => array('ELT', date('Ymd', $time)), 'enddate' => array('GT', date('Ymd', $time)), 'token' => $this->token, 'cid' => $this->_cid, 'sid' => $_POST['sid'], 'status' => array('ELT', 1)))->find();
             $oldnum = isset($order['num']) ? $order['num'] : 0;
             $total = $_POST['nums'] + $oldnum;
             if ($total > $hotelSort['houses']) {
                 $this->error('您预定的房间数在' . date('Y年m月d日', strtotime($time)) . '超出总房间数了,请重新预定');
             } else {
                 $time += 86400;
             }
         }
         $_POST['orderid'] = $orderid = substr($this->wecha_id, -1, 4) . date("YmdHis");
         $_POST['price'] = $_POST['nums'] * $days * $price;
         $_POST['time'] = time();
         //保存个人信息
         $userinfo_model = M('Userinfo');
         $thisUser = $userinfo_model->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
         if (empty($thisUser)) {
             $userRow = array('tel' => $_POST['tel'], 'truename' => $_POST['name'], 'address' => '');
             $userRow['token'] = $this->token;
             $userRow['wecha_id'] = $this->wecha_id;
             $userRow['wechaname'] = '';
             $userRow['qq'] = 0;
             $userRow['sex'] = -1;
             $userRow['age'] = 0;
             $userRow['birthday'] = '';
             $userRow['info'] = '';
             $userRow['total_score'] = 0;
             $userRow['sign_score'] = 0;
             $userRow['expend_score'] = 0;
             $userRow['continuous'] = 0;
             $userRow['add_expend'] = 0;
             $userRow['add_expend_time'] = 0;
             $userRow['live_time'] = 0;
             $userinfo_model->add($userRow);
         }
         if ($dataBase->create() !== false) {
             $action = $dataBase->add();
             if ($action != false) {
                 $info = M('deliemail')->where(array('token' => $_POST['token']))->find();
                 $mail->CharSet = 'UTF-8';
                 //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
                 $emailstatus = $info['jdbg'];
                 $emailreceive = $info['receive'];
                 $content = $this->sms();
                 if ($info['type'] == 1) {
                     $emailsmtpserver = $info['smtpserver'];
                     $emailport = $info['port'];
                     $emailsend = $info['name'];
                     $emailpassword = $info['password'];
                 } else {
                     $emailsmtpserver = C('email_server');
                     $emailport = C('email_port');
                     $emailsend = C('email_user');
                     $emailpassword = C('email_pwd');
                 }
                 $emailuser = explode('@', $emailsend);
                 $emailuser = $emailuser[0];
                 if ($emailstatus == 1) {
                     if ($content) {
                         date_default_timezone_set('PRC');
                         require "class.phpmailer.php";
                         $mail = new PHPMailer();
                         $mail->IsSMTP();
                         // set mailer to use SMTP
                         $mail->Host = "{$emailsmtpserver}";
                         // specify main and backup server
                         $mail->SMTPAuth = true;
                         // turn on SMTP authentication
                         $mail->Username = "******";
                         // SMTP username
                         $mail->Password = "******";
                         // SMTP password
                         $mail->From = $emailsend;
                         $mail->FromName = C('site_name');
                         $mail->AddAddress("{$emailreceive}", "商户");
                         //$mail->AddAddress("*****@*****.**");                  // name is optional
                         $mail->AddReplyTo($emailsend, "Information");
                         $mail->WordWrap = 50;
                         // set word wrap to 50 characters
                         //$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
                         //$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
                         $mail->IsHTML(false);
                         // set email format to HTML
                         $mail->Subject = '您有新的房间订单产生';
                         $mail->Body = $content;
                         $mail->AltBody = "";
                         if (!$mail->Send()) {
                             echo "Message could not be sent. <p>";
                             echo "Mailer Error: " . $mail->ErrorInfo;
                             exit;
                         }
                         //echo "Message has been sent";
                     }
                 }
                 $company = M('Company')->where(array('id' => $this->_cid, 'token' => $this->token))->find();
                 $op = new orderPrint();
                 $msg = array('companyname' => $company['name'], 'companytel' => $company['tel'], 'truename' => $_POST['name'], 'tel' => $_POST['tel'], 'address' => '', 'buytime' => time(), 'orderid' => $_POST['orderid'], 'sendtime' => '', 'price' => $_POST['price'], 'total' => $_POST['nums'], 'list' => array(array('name' => $sort['name'], 'day' => $days, 'price' => $price, 'num' => $_POST['nums'], 'startdate' => $_POST['startdate'], 'enddate' => $_POST['enddate'])));
                 $msg = ArrayToStr::array_to_str($msg);
                 $op->printit($this->token, $this->_cid, 'Hotel', $msg, 0);
                 Sms::sendSms($this->token . "_" . $this->_cid, "顾客{$_POST['name']}刚刚预定了{$sday}到{$eday},{$days}天的{$sort['name']},请您注意查看并处理");
                 // 					$alipayConfig = M('Alipay_config')->where(array('token' => $this->token))->find();
                 // 					if ($_POST['paymode'] == 1 && $alipayConfig['open']) {
                 // 						$this->success('正在提交中...', U('Alipay/pay',array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'from'=> 'Hotels', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $_POST['price'])));
                 // 					} elseif ($_POST['paymode'] == 4 && $this->fans['balance']) {
                 // 						$this->success('正在提交中...', U('CardPay/pay',array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'from'=> 'Hotels', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $_POST['price'])));
                 // 					} else {
                 // 						$model = new templateNews();
                 // 						$model->sendTempMsg('TM00820', array('href' => U('Hotels/my',array('token' => $this->token, 'wecha_id' => $this->wecha_id)), 'wecha_id' => $this->wecha_id, 'first' => '预订房间提醒', 'keynote1' => '订单未支付', 'keynote2' => date("Y年m月d日H时i分s秒"), 'remark' => '预订房间成功,感谢您的光临,欢迎下次再次光临!'));
                 // 						$this->success('预定成功,进入您的订单页', U('Hotels/my',array('token' => $this->token, 'wecha_id' => $this->wecha_id)));
                 // 					}
                 $config = M('Alipay_config')->where(array('token' => $this->token))->find();
                 $model = new templateNews();
                 $model->sendTempMsg('TM00184', array('href' => U('Hotels/my', array('token' => $this->token, 'wecha_id' => $this->wecha_id), true, false, true), 'wecha_id' => $this->wecha_id, 'first' => '预订房间提醒', 'ordertape' => date("Y年m月d日H时i分s秒"), 'ordeID' => $orderid, 'remark' => '预订房间成功,感谢您的光临,欢迎下次再次光临!'));
                 if ($_POST['paymode'] == 4 && $this->fans['balance']) {
                     $this->success('正在提交中...', U('CardPay/pay', array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'from' => 'Hotels', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $_POST['price'])));
                 } elseif ($config['open']) {
                     $this->success('正在提交中...', U('Alipay/pay', array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'from' => 'Hotels', 'orderName' => $orderid, 'single_orderid' => $orderid, 'price' => $_POST['price'])));
                 } else {
                     $this->success('预定成功,进入您的订单页', U('Hotels/my', array('token' => $this->token, 'wecha_id' => $this->wecha_id)));
                 }
             } else {
                 $this->error('操作失败');
             }
         } else {
             $this->error($dataBase->getError());
         }
     }
 }
예제 #21
0
 public function saveOrderAndToPay()
 {
     $sessionDK = 'session_Ordishs' . $this->_cid . '_' . $this->token;
     $tmpOrderdata = $_SESSION[$sessionDK];
     $tmpOrderdata = !empty($tmpOrderdata) ? unserialize($tmpOrderdata) : false;
     $DishC = $this->getDishCompany($this->_cid);
     $isjiacai = false;
     if (is_array($tmpOrderdata)) {
         $orid = $this->_get('orid') ? intval($this->_get('orid', 'trim')) : 0;
         $sessionoridK = 'session_orid' . $this->_cid . '_' . $this->token;
         $sessionorid = $_SESSION[$sessionoridK];
         $allmark = $_SESSION['allmark' . $this->_cid . $this->token];
         if (0 < $orid && $orid == $sessionorid) {
             $takeaway = 2;
             $Dish_order = D('Dish_order');
             $myorder = $Dish_order->where(array('id' => $orid, 'token' => $this->token, 'cid' => $this->_cid))->find();
             if ($myorder) {
                 $orderdish = array();
                 $takeaway = $myorder['takeaway'];
                 $myorderinfo = !empty($myorder['info']) ? unserialize($myorder['info']) : false;
                 if ((empty($myorderinfo) || count($myorderinfo) == 1 && isset($myorderinfo['table'])) && $myorder['total'] == 0) {
                     $orderdish = $tmpOrderdata['orderdish'];
                     $orderdish['table'] = array('tableid' => $myorder['tableid'], 'num' => 1, 'price' => $myorder['price']);
                 } else {
                     $myorderinfo = unserialize($myorder['info']);
                     $mc = count($myorderinfo);
                     $mc = 0 < $mc ? $mc : 1;
                     foreach ($tmpOrderdata['orderdish'] as $key => $val) {
                         $val['j_c'] = 1;
                         $val['flag'] = $mc;
                         $myorderinfo[$mc . 'jc' . $key] = $val;
                     }
                     $orderdish = $myorderinfo;
                 }
                 $orderid = $myorder['orderid'];
                 $tmporderid = 'order' . date('YmdHis');
                 $tmpOrderarr = array('total' => $tmpOrderdata['totalnum'] + $myorder['total'], 'price' => $tmpOrderdata['totalmoney'] + $myorder['price'], 'info' => serialize($orderdish), 'paid' => 0, 'allmark' => $allmark, 'tmporderid' => $tmporderid);
                 if ($myorder['paid'] == 1) {
                     //$tmpOrderarr['havepaid'] = $myorder['price'] + $myorder['havepaid']; //自行修改 导致加菜出错不正常
                     $tmpOrderarr['paid'] = 0;
                 }
                 $Dish_order->where(array('id' => $orid, 'token' => $this->token, 'cid' => $this->_cid))->save($tmpOrderarr);
                 $Orderarr = array('nums' => $myorder['nums'], 'time' => time(), 'allmark' => $allmark, 'orderid' => $myorder['orderid'], 'name' => $myorder['name'], 'tel' => $myorder['tel'], 'wecha_id' => $myorder['wecha_id'], 'tableid' => $myorder['tableid'], 'des' => '', 'sex' => $myorder['sex'], 'tmporderid' => $tmporderid);
                 unset($myorder);
                 unset($orderdish);
                 $_SESSION[$sessionoridK] = '';
                 $isjiacai = true;
             } else {
                 $jumpurl = U('Repast/dishMenu', array('token' => $this->token, 'cid' => $this->_cid, 'wecha_id' => $this->wecha_id, 'orid' => $orid));
                 $this->error('订单信息出错了', $jumpurl);
             }
         } else {
             $data = $_POST;
             $takeaway = intval($data['takeaway']);
             $youtel = htmlspecialchars(trim($data['youtel']), ENT_QUOTES);
             $youname = htmlspecialchars(trim($data['youname']), ENT_QUOTES);
             $youremark = htmlspecialchars(trim($data['youremark']), ENT_QUOTES);
             $youtableid = isset($data['youtable']) ? intval(trim($data['youtable'])) : 0;
             $isallpay = isset($_POST['isallpay']) ? intval($_POST['isallpay']) : 1;
             if (empty($youtel) || empty($youname)) {
                 $this->error('手机号码或顾客姓名没有填写!');
             }
             if (!(0 < $youtableid) && $DishC['offtable'] == 0) {
                 $this->error('请选择一个餐桌!');
             }
             $wecha_id = $this->wecha_id ? $this->wecha_id : 'Repastm_' . $youtel;
             $orderid = substr($wecha_id, -5) . date('YmdHis');
             $Orderarr = array('cid' => $this->_cid, 'wecha_id' => $wecha_id, 'token' => $this->token, 'total' => $tmpOrderdata['totalnum'], 'price' => $tmpOrderdata['totalmoney'], 'tmporderid' => $orderid);
             if ($takeaway == 0) {
                 $Orderarr['nums'] = $number;
                 $Orderarr['reservetime'] = strtotime($date . ' ' . $time);
             } else {
                 $Orderarr['nums'] = 1;
                 $Orderarr['reservetime'] = time();
             }
             $Orderarr['info'] = serialize($tmpOrderdata['orderdish']);
             $Orderarr['name'] = $youname;
             $Orderarr['sex'] = intval(trim($data['yousex']));
             $Orderarr['tel'] = $youtel;
             $Orderarr['address'] = '';
             $Orderarr['tableid'] = $youtableid;
             $Orderarr['time'] = time();
             $Orderarr['stype'] = 0;
             $Orderarr['paid'] = 0;
             $Orderarr['isuse'] = 0;
             $Orderarr['orderid'] = $orderid;
             $Orderarr['printed'] = 0;
             $Orderarr['des'] = $youremark;
             $Orderarr['allmark'] = $allmark;
             $Orderarr['takeaway'] = $takeaway;
             $Orderarr['advancepay'] = !(0 < $isallpay) ? $DishC['advancepay'] : 0;
             $Orderarr['isover'] = !(0 < $isallpay) ? 1 : 0;
             $orid = M('Dish_order')->add($Orderarr);
         }
         if ($orid) {
             $_SESSION[$sessionDK] = '';
             $sessionK = 'session_dishs' . $this->_cid . '_' . $this->token;
             $_SESSION[$sessionK] = '';
             if ($takeaway == 2) {
                 M('Dining_table')->where(array('cid' => $this->_cid, 'id' => $Orderarr['tableid']))->save(array('status' => 1));
             }
             $t_table = M('Dining_table')->where(array('cid' => $this->_cid, 'id' => $Orderarr['tableid']))->find();
             $company = $this->getCompany($this->_cid);
             $msgstr = '顾客' . $youname . '他刚刚点了一份餐,订单号:' . $orderid . ',请您注意查看并处理';
             if ($isjiacai) {
                 $msgstr = '顾客' . $youname . '他刚刚在订单号为 ' . $orderid . ' 里加了菜,请您注意查看并处理';
             }
             Sms::sendSms($this->token, $msgstr, $company['mp']);
             $printer_set = $this->getPrinter_set($this->_cid);
             if (!empty($printer_set) && $printer_set['paid'] == 0) {
                 $op = new orderPrint();
                 $msg = array('companyname' => $company['name'], 'des' => $Orderarr['allmark'] ? $Orderarr['allmark'] : $Orderarr['des'], 'companytel' => $company['tel'], 'truename' => $Orderarr['name'], 'tel' => $Orderarr['tel'], 'address' => '', 'buytime' => $Orderarr['time'], 'orderid' => $Orderarr['orderid'], 'price' => $tmpOrderdata['totalmoney'], 'total' => $tmpOrderdata['totalnum'], 'typename' => $takeaway == 2 ? '现场点餐' : '预约点餐', 'tablename' => $t_table['name'], 'list' => $tmpOrderdata['orderdish']);
                 if (isset($isallpay) && $isallpay == 0) {
                     $advancepay = $msg['advancepay'] = $DishC['advancepay'];
                 }
                 $msg = ArrayToStr::array_to_str($msg, 0);
                 $op->printit($this->token, $this->_cid, 'Repast', $msg, 0);
             }
             $alipayConfig = M('Alipay_config')->where(array('token' => $this->token))->find();
             if ($alipayConfig['open']) {
                 $msgstr = isset($advancepay) ? '需要支付 ' . $advancepay . ' 元就餐预定金<br/>正在提交中...' : '正在提交中...';
                 $paydata = array('token' => $this->token, 'wecha_id' => $Orderarr['wecha_id'], 'success' => 1, 'from' => 'Repast', 'orderName' => $Orderarr['tmporderid'], 'single_orderid' => $Orderarr['tmporderid'], 'price' => $tmpOrderdata['totalmoney']);
                 if (isset($advancepay) && 0 < $advancepay) {
                     $paydata['price'] = $advancepay;
                     $paydata['advancepay'] = 1;
                 }
                 $this->success($msgstr, U('Alipay/pay', $paydata));
             } else {
                 $this->error('商家尚未开启支付功能', $jumpurl);
             }
         } else {
             $this->error('订单录入系统出错,抱歉给您的带来了不便。请重新下单吧', $jumpurl);
         }
         if (!empty($this->wecha_id)) {
             $userinfo_model = M('Userinfo');
             $thisUser = $userinfo_model->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
             if (empty($thisUser)) {
                 $userRow = array('tel' => $Orderarr['tel'], 'truename' => $Orderarr['name'], 'address' => '');
                 $userRow['token'] = $this->token;
                 $userRow['wecha_id'] = $this->wecha_id;
                 $userRow['wechaname'] = '';
                 $userRow['qq'] = 0;
                 $userRow['sex'] = $Orderarr['sex'] == 1 ? 1 : 2;
                 $userRow['age'] = 0;
                 $userRow['birthday'] = '';
                 $userRow['info'] = '';
                 $userRow['total_score'] = 0;
                 $userRow['sign_score'] = 0;
                 $userRow['expend_score'] = 0;
                 $userRow['continuous'] = 0;
                 $userRow['add_expend'] = 0;
                 $userRow['add_expend_time'] = 0;
                 $userRow['live_time'] = 0;
                 $userinfo_model->add($userRow);
             }
         }
     } else {
         $jumpurl = U('Repast/index', array('token' => $this->token, 'wecha_id' => $this->wecha_id));
         $this->error('没有点菜', $jumpurl);
     }
 }
예제 #22
0
 public function OrderPay()
 {
     $this->isLogin();
     if (IS_POST) {
         $phone = isset($_POST['ouserTel']) ? htmlspecialchars($_POST['ouserTel']) : '';
         $name = isset($_POST['ouserName']) ? htmlspecialchars($_POST['ouserName']) : '';
         $address = isset($_POST['ouserAddres']) ? htmlspecialchars($_POST['ouserAddres']) : '';
         $arrive_time = isset($_POST['oarrivalTime']) ? htmlspecialchars($_POST['oarrivalTime']) : 0;
         $note = isset($_POST['omark']) ? htmlspecialchars($_POST['omark']) : '';
         if (empty($name)) {
             $this->error('联系人不能为空');
         }
         if (empty($phone)) {
             $this->error('联系电话不能为空');
         }
         $goodsData = isset($_POST['dish']) ? $_POST['dish'] : null;
         if (empty($goodsData)) {
             $this->error('您还没有点菜');
         }
         $meal = array_keys($goodsData);
         $total = $price = 0;
         if ($meal) {
             $meals = M("Meal")->where(array('meal_id' => array('in', $meal), 'store_id' => $this->store_id))->select();
             $info = array();
             foreach ($meals as $m) {
                 $info[] = array('id' => $m['meal_id'], 'name' => $m['name'], 'num' => $goodsData[$m['meal_id']]['num'], 'price' => $m['price']);
                 $total += $goodsData[$m['meal_id']]['num'];
                 $price += $goodsData[$m['meal_id']]['num'] * $m['price'];
             }
         }
         if (empty($this->_store['delivery_fee_valid']) && $price < $this->_store['basic_price']) {
             $this->error('您的外卖总金额没有达到起步价');
         }
         $delivery_fee = 0;
         if ($this->_store['delivery_fee'] > 0) {
             //外卖费
             if ($this->_store['reach_delivery_fee_type'] == 1) {
                 $delivery_fee = $this->_store['delivery_fee'];
             } else {
                 if ($price < $this->_store['basic_price']) {
                     //不足起送价
                     if ($this->_store['delivery_fee_valid']) {
                         $delivery_fee = $this->_store['delivery_fee'];
                     }
                 } else {
                     if ($this->_store['reach_delivery_fee_type'] == 2 && $price < $this->_store['no_delivery_fee_value']) {
                         $delivery_fee = $this->_store['delivery_fee'];
                     }
                 }
             }
         }
         $price += $delivery_fee;
         $total_price = $price;
         $minus_price = 0;
         if ($store_meal = D('Merchant_store_meal')->where(array('store_id' => $this->store_id))->find()) {
             if (!empty($store_meal['minus_money']) && $price > $store_meal['full_money']) {
                 $price = $price - $store_meal['minus_money'];
                 $minus_price = $store_meal['minus_money'];
             }
         }
         $arrive_time && ($arrive_time = strtotime(date("Y-m-d " . $arrive_time . ":00")));
         $data = array('arrive_time' => $arrive_time, 'mer_id' => $this->mer_id, 'store_id' => $this->store_id, 'name' => $name, 'phone' => $phone, 'address' => $address, 'note' => $note, 'info' => serialize($info), 'dateline' => time(), 'total' => $total, 'price' => $price, 'meal_type' => 1);
         $data['orderid'] = $this->mer_id . $this->store_id . date("YmdHis") . rand(1000000, 9999999);
         $data['uid'] = $this->user_session['uid'];
         $data['meal_type'] = 1;
         $data['delivery_fee'] = $delivery_fee;
         $data['total_price'] = $total_price;
         $data['minus_price'] = $minus_price;
         $orderid = D("Meal_order")->add($data);
         if ($orderid) {
             if ($this->user_session['openid']) {
                 $keyword2 = '';
                 $pre = '';
                 foreach (unserialize($data['info']) as $menu) {
                     $keyword2 .= $pre . $menu['name'] . ':' . $menu['price'] . '*' . $menu['num'];
                     $pre = '\\n\\t\\t\\t';
                 }
                 $href = C('config.site_url') . '/wap.php?c=Takeout&a=order_detail&order_id=' . $orderid . '&mer_id=' . $data['mer_id'] . '&store_id=' . $data['store_id'];
                 $model = new templateNews(C('config.wechat_appid'), C('config.wechat_appsecret'));
                 $model->sendTempMsg('OPENTM201682460', array('href' => $href, 'wecha_id' => $this->user_session['openid'], 'first' => '您好,您的订单已生成', 'keyword3' => $orderid, 'keyword1' => date('Y-m-d H:i:s'), 'keyword2' => $keyword2, 'remark' => '您的该次' . $this->config['meal_alias_name'] . '下单成功,感谢您的使用!'));
             }
             $msg = array();
             $msg['user_name'] = $data['name'];
             $msg['user_phone'] = $data['phone'];
             $msg['user_address'] = $data['address'];
             $msg['user_message'] = $data['note'];
             $msg['buy_time'] = date("Y-m-d H:i:s", $data['dateline']);
             $msg['goods_list'] = $info;
             $msg['goods_count'] = $data['total'];
             $msg['goods_price'] = $data['price'];
             $msg['orderid'] = $orderid;
             $msg['pay_status'] = '';
             $msg['pay_type'] = '';
             $msg['store_name'] = $this->_store['name'];
             $msg['store_phone'] = $this->_store['phone'];
             $msg['store_address'] = $this->_store['adress'];
             $msg = ArrayToStr::array_to_str($msg, 0, $this->config['print_format']);
             $op = new orderPrint($this->config['print_server_key'], $this->config['print_server_topdomain']);
             $op->printit($this->mer_id, $this->store_id, $msg, 0);
             $sms_data = array('mer_id' => $this->mer_id, 'store_id' => $this->store_id, 'type' => 'food');
             if ($this->config['sms_place_order'] == 1 || $this->config['sms_place_order'] == 3) {
                 $sms_data['uid'] = $this->user_session['uid'];
                 $sms_data['mobile'] = $data['phone'];
                 $sms_data['sendto'] = 'user';
                 $sms_data['content'] = '您' . date("Y-m-d H:i:s", $data['dateline']) . '在【' . $this->_store['name'] . '】中预定了一份外卖,订单号:' . $orderid;
                 Sms::sendSms($sms_data);
             }
             if ($this->config['sms_place_order'] == 2 || $this->config['sms_place_order'] == 3) {
                 $sms_data['uid'] = 0;
                 $sms_data['mobile'] = $this->_store['phone'];
                 $sms_data['sendto'] = 'merchant';
                 $sms_data['content'] = '顾客【' . $data['name'] . '】在' . date("Y-m-d H:i:s", $data['dateline']) . '时预定了一份外卖,订单号:' . $orderid . '请您注意查看并处理!';
                 Sms::sendSms($sms_data);
             }
             /* 粉丝行为分析 */
             $this->behavior(array('mer_id' => $this->mer_id, 'biz_id' => $orderid));
             $_SESSION[$this->session_index] = null;
             redirect(U('Pay/check', array('order_id' => $orderid, 'type' => 'takeout')));
         }
     } else {
         $this->error();
     }
 }
예제 #23
0
 /**
  * 订单详情
  */
 public function orderInfo()
 {
     $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
     $fd = $this->_get('fd') ? $this->_get('fd', 'trim') : '';
     $cidd = $this->_get('cidd') ? intval($this->_get('cidd', 'trim')) : 0;
     $cid = $this->_cid;
     if ($fd == 'on' && $cidd > 0) {
         $cid = $cidd;
         $this->assign('isfd', true);
     }
     $dishOrder = M('Dish_order');
     if ($thisOrder = $dishOrder->where(array('id' => $id, 'cid' => $cid, 'token' => $this->token, 'comefrom' => 'dish'))->find()) {
         if (IS_POST) {
             $isuse = isset($_POST['isuse']) ? intval($_POST['isuse']) : 0;
             $paid = isset($_POST['paid']) ? intval($_POST['paid']) : 0;
             $dishOrder->where(array('id' => $thisOrder['id']))->save(array('isuse' => $isuse, 'paid' => $paid));
             if ($thisOrder['tableid'] && $isuse) {
                 D('Dish_table')->where(array('orderid' => $thisOrder['id']))->save(array('isuse' => 1));
             }
             $company = M('Company')->where(array('token' => $this->token, 'id' => $thisOrder['cid']))->find();
             if ($paid && empty($thisOrder['paid'])) {
                 $temp = unserialize($thisOrder['info']);
                 $temp = isset($temp['list']) ? $temp['list'] : $temp;
                 $this->saleLog(array('cid' => $cid, 'oid' => $thisOrder['id'], 'paytype' => $thisOrder['paytype'], 'dish' => $temp, 'time' => $thisOrder['time'], 'paycount' => $thisOrder['paycount']));
                 $takeAwayPrice = isset($temp['takeAwayPrice']) ? $temp['takeAwayPrice'] : '';
                 $bookTable = false;
                 if (isset($temp['table']) && !empty($temp['table'])) {
                     $bookTable = $temp['table']['price'];
                     unset($temp['table']);
                 }
                 $op = new orderPrint();
                 $msg = array('companyname' => $company['name'], 'des' => $thisOrder['des'], 'companytel' => $company['tel'], 'truename' => $thisOrder['name'], 'tel' => $thisOrder['tel'], 'takeAwayPrice' => $takeAwayPrice, 'address' => $thisOrder['address'], 'buytime' => $thisOrder['time'], 'orderid' => $thisOrder['orderid'], 'price' => $thisOrder['price'], 'total' => $thisOrder['nums'], 'ptype' => $thisOrder['paytype'], 'list' => $temp, 'bookTable' => $bookTable);
                 $msg['typename'] = $thisOrder['takeaway'] == 1 ? '外卖' : ($thisOrder['takeaway'] == 2 ? '现在点餐' : '预约点餐');
                 if ($thisOrder['takeaway'] == 0) {
                     $tmpstr = $this->GetCanTimeByoid($cid, $thisOrder['id'], $thisOrder['tableid']);
                     $msg['reservestr'] = $tmpstr ? date('Y-m-d', $order['reservetime']) . ' ' . $tmpstr : date('Y-m-d H:i', $thisOrder['reservetime']);
                 }
                 if ($thisOrder['tableid']) {
                     $t_table = M("Dining_table")->where(array('id' => $thisOrder['tableid']))->find();
                     $msg['tablename'] = isset($t_table['name']) ? $t_table['name'] : '';
                 }
                 $msg = ArrayToStr::array_to_str($msg, 1);
                 $op->printit($this->token, $this->_cid, 'Repast', $msg, 1);
             }
             Sms::sendSms($this->token, "{$company['name']}欢迎您,本店对您的订单号为:{$thisOrder['orderid']}的订单状态进行了修改,如有任何疑意,请您及时联系本店!", $thisOrder['tel']);
             $this->success('修改成功', U('Repast/orderInfo', array('token' => session('token'), 'id' => $thisOrder['id'])));
         } else {
             $payarr = array('alipay' => '支付宝', 'weixin' => '微信支付', 'tenpay' => '财付通[wap手机]', 'tenpaycomputer' => '财付通[即时到帐]', 'yeepay' => '易宝支付', 'allinpay' => '通联支付', 'daofu' => '货到付款', 'dianfu' => '到店付款', 'chinabank' => '网银在线');
             $paystr = strtolower($thisOrder['paytype']);
             $thisOrder['paystr'] = !empty($paystr) && array_key_exists($paystr, $payarr) ? $payarr[$paystr] : '其他';
             $dishList = unserialize($thisOrder['info']);
             $dishList = isset($dishList['list']) ? $dishList['list'] : $dishList;
             $this->assign('thisOrder', $thisOrder);
             $this->assign('dishList', $dishList);
             $this->display();
         }
     }
 }
예제 #24
0
 public function orderInfo()
 {
     $this->product_model = M('Product');
     $this->product_cat_model = M('Product_cat');
     $product_cart_model = M('product_cart');
     $thisOrder = $product_cart_model->where(array('id' => intval($_GET['id']), 'token' => $this->token))->find();
     //检查权限
     if (strtolower($thisOrder['token']) != strtolower($this->_session('token'))) {
         exit;
     }
     if (IS_POST) {
         if (intval($_POST['sent'])) {
             $_POST['handled'] = 1;
         }
         $product_cart_model->where(array('id' => $thisOrder['id']))->save(array('sent' => intval($_POST['sent']), 'paid' => intval($_POST['paid']), 'logistics' => $_POST['logistics'], 'logisticsid' => $_POST['logisticsid'], 'handled' => 1));
         //TODO 发货的短信提醒
         $company = D('Company')->where(array('token' => $thisOrder['token'], 'id' => $thisOrder['cid']))->find();
         if ($_POST['sent']) {
             $userInfo = D('Userinfo')->where(array('token' => $thisOrder['token'], 'wecha_id' => $thisOrder['wecha_id']))->find();
             Sms::sendSms($this->token, "您在{$company['name']}商城购买的商品,商家已经给您发货了,请您注意查收", $userInfo['tel']);
         }
         /*******************支付订单打印*****************************/
         if (intval($_POST['paid']) && intval($thisOrder['price'])) {
             $carts = unserialize($thisOrder['info']);
             $tdata = $this->getCat($carts);
             $list = array();
             foreach ($tdata[0] as $va) {
                 $t = array();
                 if (!empty($va['detail'])) {
                     foreach ($va['detail'] as $v) {
                         $t = array('num' => $v['count'], 'colorName' => $v['colorName'], 'formatName' => $v['formatName'], 'price' => $v['price'], 'name' => $va['name']);
                         $list[] = $t;
                     }
                 } else {
                     $t = array('num' => $va['count'], 'price' => $va['price'], 'name' => $va['name']);
                     $list[] = $t;
                 }
             }
             $op = new orderPrint();
             $msg = array('companyname' => $company['name'], 'companytel' => $company['tel'], 'truename' => $thisOrder['truename'], 'tel' => $thisOrder['tel'], 'address' => $thisOrder['address'], 'buytime' => $thisOrder['time'], 'orderid' => $thisOrder['orderid'], 'sendtime' => '', 'price' => $thisOrder['price'], 'total' => $thisOrder['total'], 'list' => $list);
             $msg = ArrayToStr::array_to_str($msg, 1);
             $op->printit($this->token, $this->_cid, 'Store', $msg, 1);
         }
         /*******************支付订单打印*****************************/
         $this->success('修改成功', U('Store/orderInfo', array('token' => session('token'), 'id' => $thisOrder['id'])));
     } else {
         //订餐信息
         $product_diningtable_model = M('product_diningtable');
         if ($thisOrder['tableid']) {
             $thisTable = $product_diningtable_model->where(array('id' => $thisOrder['tableid']))->find();
             $thisOrder['tableName'] = $thisTable['name'];
         }
         $this->assign('thisOrder', $thisOrder);
         $carts = unserialize($thisOrder['info']);
         $totalFee = 0;
         $totalCount = 0;
         $data = $this->getCat($carts);
         if (isset($data[1])) {
             foreach ($data[1] as $pid => $row) {
                 $totalCount += $row['total'];
                 $totalFee += $row['totalPrice'];
                 $listNum[$pid] = $row['total'];
             }
         }
         $list = $data[0];
         $this->assign('products', $list);
         $this->assign('totalFee', $totalFee);
         $this->assign('totalCount', $totalCount);
         $this->assign('mailprice', $data[2]);
         $this->display();
     }
 }
예제 #25
0
 public function index($orderid, $paytype = '', $third_id = '')
 {
     $wecha_id = '';
     $token = '';
     $cid = 0;
     $dish_order_db = M('dish_order');
     if ($order = $dish_order_db->where(array('tmporderid' => $orderid))->find()) {
         //TODO 发货的短信提醒
         $token = $order['token'];
         $wecha_id = $order['wecha_id'];
         $cid = $order['cid'];
         $company = M('Company')->where(array('token' => $token, 'id' => $cid))->find();
         $Dishcompany = M('Dish_company')->where(array('cid' => $cid))->find();
         $kconoff = $Dishcompany['kconoff'];
         $orderid = $order['orderid'];
         if (empty($company) || !is_array($company)) {
             header('Location:' . U('Repast/myOrders', array('token' => $token, 'wecha_id' => $wecha_id)));
         }
         $temp = !empty($order['info']) ? unserialize($order['info']) : array();
         $temp = isset($temp['list']) ? $temp['list'] : $temp;
         //$order['paid'] = 1;
         if ($order['paid']) {
             if (!empty($temp) && is_array($temp)) {
                 $log_db = M('Dishout_salelog');
                 $tmparr = array('token' => $token, 'cid' => $order['cid'], 'order_id' => $order['id'], 'paytype' => $order['paytype']);
                 $DishDb = M('Dish');
                 $mDishSet = ThirdPayRepast::getDishMainCompany($token);
                 foreach ($temp as $kk => $vv) {
                     $did = isset($vv['did']) ? $vv['did'] : $kk;
                     if ($did > 0) {
                         $flag = isset($vv['flag']) ? $vv['flag'] : '';
                         $newk = $flag . 'jc' . $did;
                         if (!($order['paycount'] > 0) || $kk == $newk) {
                             $dishofcid = $cid;
                             if ($mDishSet['cid'] != $cid && $mDishSet['dishsame'] == 1) {
                                 $dishofcid = $mDishSet['cid'];
                                 $kconoff = $mDishSet['kconoff'];
                             }
                             $tmpdish = $DishDb->where(array('id' => $did, 'cid' => $dishofcid))->find();
                             if ($kconoff && !empty($tmpdish) && $tmpdish['instock'] > 0) {
                                 $DishDb->where(array('id' => $did, 'cid' => $dishofcid))->setDec('instock', $vv['num']);
                             }
                             $logarr = array('did' => $did, 'nums' => $vv['num'], 'unitprice' => $vv['price'], 'money' => $vv['num'] * $vv['price'], 'dname' => $vv['name'], 'addtime' => $order['time'], 'addtimestr' => date('Y-m-d H:i:s', $order['time']), 'comefrom' => 1);
                             $savelogarr = array_merge($tmparr, $logarr);
                             $log_db->add($savelogarr);
                         }
                     }
                 }
                 $dish_order_db->where(array('id' => $order['id'], 'cid' => $order['cid']))->setInc('paycount', 1);
             }
             if ($order['takeaway'] == 2 && $order['isover'] == 2) {
                 M('Dining_table')->where(array('id' => $order['tableid'], 'cid' => $order['cid']))->save(array('status' => 0));
             } elseif ($order['takeaway'] == 2 && $order['isover'] == 1) {
                 $dish_order_db->where(array('id' => $order['id'], 'cid' => $order['cid']))->save(array('paid' => 0));
             }
             if ((empty($temp) || count($temp) == 1 && isset($temp['table'])) && $temp['total'] == 0) {
                 $temp = false;
                 $order['total'] = 1;
                 $bookTable = $order['price'];
             } elseif ($order['takeaway'] == 2 && $order['advancepay'] > 0) {
                 $bookTable = false;
                 if ($order['paycount'] == 1) {
                     $realpay = $myorder['price'] - $myorder['havepaid'];
                 } elseif ($order['paycount'] == 0) {
                     $advancepay = $order['advancepay'];
                 }
                 $dish_order_db->where(array('id' => $order['id'], 'cid' => $order['cid']))->save(array('havepaid' => $order['advancepay'], 'advancepay' => 0));
             } else {
                 $bookTable = false;
                 if (isset($temp['table']) && !empty($temp['table'])) {
                     $bookTable = $temp['table']['price'];
                     unset($temp['table']);
                 }
                 $realpay = $myorder['price'] - $myorder['havepaid'];
             }
             $op = new orderPrint();
             $msg = array('companyname' => $company['name'], 'des' => $order['des'], 'companytel' => $company['tel'], 'truename' => $order['name'], 'tel' => $order['tel'], 'address' => $order['address'], 'buytime' => $order['time'], 'orderid' => $order['orderid'], 'bookTable' => $bookTable, 'price' => $order['price'], 'total' => $order['total'], 'ptype' => $order['paytype'], 'list' => $temp, 'advancepay' => isset($advancepay) ? $advancepay : false, 'realpay' => isset($realpay) ? $realpay : false);
             $msg['typename'] = $order['takeaway'] == 2 ? '现场点餐' : '预约点餐';
             if ($order['takeaway'] == 1) {
                 $msg['sendtime'] = $order['reservetime'];
                 $msg['typename'] = '外卖';
             } elseif ($order['takeaway'] == 0) {
                 $tmpstr = ThirdPayRepast::GetCanTimeByoid($cid, $order['id'], $order['tableid']);
                 $msg['reservestr'] = $tmpstr ? date('Y-m-d', $order['reservetime']) . ' ' . $tmpstr : date('Y-m-d H:i', $order['reservetime']);
             }
             if ($order['tableid']) {
                 $t_table = M("Dining_table")->where(array('id' => $order['tableid']))->find();
                 $msg['tablename'] = isset($t_table['name']) ? $t_table['name'] : '';
             }
             $msg = ArrayToStr::array_to_str($msg, 1);
             $op->printit($token, $cid, 'Repast', $msg, 1);
             Sms::sendSms($token . "_" . $cid, "顾客{$order['name']}刚刚对订单号:{$orderid}的订单进行了支付,请您注意查看并处理");
             $siteurl = $_SERVER['HTTP_HOST'];
             $siteurl = strtolower($siteurl);
             if (strpos($siteurl, "http:") === false && strpos($siteurl, "https:") === false) {
                 $siteurl = 'http://' . $siteurl;
             }
             $siteurl = rtrim($siteurl, '/');
             $model = new templateNews();
             /*$model->sendTempMsg('OPENTM202521011', array('href' =>U('Repast/myOrders', array('token' => $token, 'wecha_id' => $wecha_id, 'cid' => $cid), true, false, true), 'wecha_id' => $wecha_id, 'first' => '餐饮订餐交易提醒', 'keyword1' => $orderid, 'keyword2' => date("Y年m月d日H时i分s秒"), 'remark' => '支付成功,感谢您的光临,欢迎下次再次光临!'));*/
             $model->sendTempMsg('OPENTM202521011', array('href' => $siteurl . '/index.php?g=Wap&m=Repast&a=myOrders&token=' . $token . '&wecha_id=' . $wecha_id . '&cid=' . $cid, 'wecha_id' => $wecha_id, 'first' => '餐饮订餐交易提醒', 'keyword1' => $orderid, 'keyword2' => date("Y年m月d日H时i分s秒"), 'remark' => '支付成功,感谢您的光临,欢迎下次再次光临!'));
         }
         header('Location:' . U('Repast/myOrders', array('token' => $token, 'wecha_id' => $wecha_id, 'cid' => $cid)));
     } else {
         exit('订单不存在');
     }
 }
예제 #26
0
 public function index($orderid, $paytype = '', $third_id = '')
 {
     if ($order = M('New_product_cart')->where(array('orderid' => $orderid))->find()) {
         //TODO 发货的短信提醒
         if ($order['paid']) {
             $userInfo = D('Userinfo')->where(array('token' => $order['token'], 'wecha_id' => $order['wecha_id']))->find();
             if ($order['jingpai'] == 0) {
                 $carts = unserialize($order['info']);
                 $tdata = $this->getCat($carts, $order['token'], $order['cid'], $userInfo['getcardtime']);
                 $list = array();
                 foreach ($tdata[0] as $va) {
                     $t = array();
                     $salecount = 0;
                     if (!empty($va['detail'])) {
                         foreach ($va['detail'] as $v) {
                             $t = array('num' => $v['count'], 'colorName' => $v['colorName'], 'formatName' => $v['formatName'], 'price' => $v['price'], 'name' => $va['name']);
                             $list[] = $t;
                             $salecount += $v['count'];
                         }
                     } else {
                         $t = array('num' => $va['count'], 'price' => $va['price'], 'name' => $va['name']);
                         $list[] = $t;
                         $salecount = $va['count'];
                     }
                     D("New_product")->where(array('id' => $va['id']))->setInc('salecount', $salecount);
                 }
             } else {
                 //竞拍内容
                 $order = M('New_product_cart')->where(array('token' => $order['token'], 'cid' => $order['cid'], 'id' => $order['id']))->find();
                 $orderlist = M('New_product_cart_list')->where(array('token' => $order['token'], 'cid' => $order['cid'], 'cartid' => $order['id']))->find();
                 if ($order['jingpai'] == 1) {
                     $produtcdb = M("New_product_jingpai");
                 } else {
                     if ($order['groupon'] == 1) {
                         $produtcdb = M("New_product");
                     }
                 }
                 $jingpai = $produtcdb->where(array('token' => $order['token'], 'cid' => $order['cid'], 'id' => $orderlist['productid']))->find();
                 $list = array($orderlist['productid'] => array('num' => '1', 'price' => $jingpai['price'], 'name' => $jingpai['name']));
                 if ($order['jingpai'] == 1) {
                     $order['note'] = '' . $order['note'] . '(竞拍订单)';
                 } else {
                     if ($order['groupon'] == 1) {
                         $order['note'] = '' . $order['note'] . '(团购订单)';
                         //修改团购记录已付款
                         M('New_product_groupon')->where(array('orderid' => $order['orderid']))->setField('paid', 1);
                     }
                 }
             }
             if ($order['twid']) {
                 $userInfo = D('Userinfo')->where(array('token' => $order['token'], 'wecha_id' => $order['wecha_id']))->find();
                 $twid = $order['twid'];
                 if ($twid == $userInfo['fromtwid']) {
                     $addtwid = $userInfo['addtwid'];
                 } else {
                     $addtwid = $userInfo['fromtwid'];
                 }
             } else {
                 $userInfo = D('Userinfo')->where(array('token' => $order['token'], 'wecha_id' => $order['wecha_id']))->find();
                 $twid = $userInfo['fromtwid'];
                 $addtwid = $userInfo['addtwid'];
             }
             //dump($twid);
             //die;
             if ($twid && $twid != $userInfo['twid']) {
                 $token = $order['token'];
                 $cid = $order['cid'];
                 $orderid = $order['orderid'];
                 $totalprice = $order['totalprice'];
                 $type = 3;
                 $param = 1;
                 $set = M("New_twitter_set")->where(array('token' => $token, 'cid' => $cid))->find();
                 if (empty($set)) {
                     return false;
                 }
                 //获取单一产品的1、2级佣金
                 $yongjinlist = M('New_product_cart_list')->where(array('token' => $token, 'cid' => $cid, 'cartid' => $order['id']))->select();
                 foreach ($yongjinlist as $key => $row) {
                     $products = M('New_product')->where(array('token' => $this->token, 'cid' => $this->_cid, 'id' => $row['productid']))->find();
                     if ($products['allow_distribution'] == '1') {
                         //一级佣金
                         switch ($products['commission_type']) {
                             default:
                                 $yongjinlist[$key]['commission'] = $set['percent'] * 0.01 * $products['price'] * $row['total'];
                                 break;
                             case 'fixed':
                                 $yongjinlist[$key]['commission'] = $products['commission'] * $row['total'];
                                 break;
                             case 'float':
                                 $products['commission'] = $products['price'] * ($products['commission'] * 0.01) * $row['total'];
                                 $yongjinlist[$key]['commission'] = $products['commission'];
                                 break;
                         }
                         //二级佣金
                         switch ($products['addcommission_type']) {
                             default:
                                 $yongjinlist[$key]['addcommission'] = $set['addpercent'] * 0.01 * $products['price'] * $row['total'];
                                 break;
                             case 'fixed':
                                 $yongjinlist[$key]['addcommission'] = $products['addcommission'] * $row['total'];
                                 break;
                             case 'float':
                                 $products['addcommission'] = $products['price'] * ($products['addcommission'] * 0.01) * $row['total'];
                                 $yongjinlist[$key]['addcommission'] = $products['addcommission'];
                                 break;
                         }
                         //产品总佣金
                         $commission += $yongjinlist[$key]['commission'];
                         $addcommission += $yongjinlist[$key]['addcommission'];
                     } else {
                         $yongjinlist[$key]['addcommission'] = '0';
                         $yongjinlist[$key]['commission'] = '0';
                         $commission += $yongjinlist[$key]['commission'];
                         $addcommission += $yongjinlist[$key]['addcommission'];
                     }
                 }
                 //佣金判断结束
                 if ($twid && $token && $cid && $commission != '0' && $addcommission != '0') {
                     $db = D("New_twitter_log");
                     // 1.点击, 2.注册会员, 3.购买商品
                     //判断佣金分成
                     $price = $commission;
                     $addprice = $addcommission;
                     //上级分成记录
                     if ($type == 3) {
                         //购买商品,上级分成
                         $db->add(array('token' => $token, 'cid' => $cid, 'twid' => $twid, 'addtwid' => $addtwid, 'orderid' => $orderid, 'type' => 3, 'dateline' => time(), 'param' => $param, 'price' => $price, 'wecha_id' => $order['wecha_id'], 'orderprice' => $order['price']));
                         //上级的上级参与分成记录
                         if (!empty($addtwid) && $addtwid != $twid) {
                             $db->add(array('token' => $token, 'cid' => $cid, 'twid' => $addtwid, 'type' => 4, 'orderid' => $orderid, 'dateline' => time(), 'param' => $param, 'price' => $addprice, 'wecha_id' => $order['wecha_id'], 'orderprice' => $order['price']));
                         }
                     }
                     //统计总收入
                     if ($count = M("New_twitter_count")->where(array('token' => $token, 'cid' => $cid, 'twid' => $twid))->find()) {
                         D("New_twitter_count")->where(array('id' => $count['id']))->setInc('total', $price);
                     } else {
                         D("New_twitter_count")->add(array('twid' => $twid, 'fromtwid' => $fromtwid, 'token' => $token, 'cid' => $cid, 'total' => $price, 'remove' => 0));
                     }
                     //上级的上级参与分成记录,统计总收入
                     if (!empty($addtwid) && $addtwid != $twid) {
                         if ($count = M("New_twitter_count")->where(array('token' => $token, 'cid' => $cid, 'twid' => $addtwid))->find()) {
                             D("New_twitter_count")->where(array('id' => $count['id']))->setInc('total', $addprice);
                         } else {
                             D("New_twitter_count")->add(array('twid' => $addtwid, 'token' => $token, 'cid' => $cid, 'total' => $addprice, 'remove' => 0));
                         }
                     }
                     //分佣写入结束
                     //查询分销人的信息,如果没有直接写入
                     $twiduserinfo = D('Userinfo')->where(array('token' => $order['token'], 'twid' => $twid))->find();
                     $twiduser = D('New_twitter_userinfo')->where(array('token' => $order['token'], 'twid' => $twid))->find();
                     if (empty($twiduser)) {
                         $userdata = array('token' => $order['token'], 'cid' => $order['cid'], 'wecha_id' => $twiduserinfo['wecha_id'], 'twid' => $twiduserinfo['twid'], 'truename' => $twiduserinfo['truename'], 'status' => '0', 'dateline' => time());
                         D("New_twitter_userinfo")->add($userdata);
                     }
                     //查询分销人的上家的上家信息,如果没有直接写入
                     $addtwiduserinfo = D('Userinfo')->where(array('token' => $order['token'], 'twid' => $addtwid))->find();
                     $addtwiduser = D('New_twitter_userinfo')->where(array('token' => $order['token'], 'twid' => $addtwid))->find();
                     if (empty($addtwiduser)) {
                         $adduserdata = array('token' => $order['token'], 'cid' => $order['cid'], 'wecha_id' => $addtwiduserinfo['wecha_id'], 'twid' => $addtwiduserinfo['twid'], 'truename' => $addtwiduserinfo['truename'], 'status' => '0', 'dateline' => time());
                         D("New_twitter_userinfo")->add($adduserdata);
                     }
                 }
                 //$this->savelog(3, $order['twid'], $order['token'], $order['cid'], $order['totalprice']);
             }
             //分佣判断END
             $userInfo = D('Userinfo')->where(array('token' => $order['token'], 'wecha_id' => $order['wecha_id']))->find();
             //获取配置信息
             $where = array('token' => $order['token']);
             $this->thisWxUser = M('Wxuser')->where($where)->find();
             $url_get = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $this->thisWxUser['appid'] . '&secret=' . $this->thisWxUser['appsecret'];
             $access_token = json_decode($this->curlGet($url_get));
             $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token->access_token;
             //获取用户openID
             $where = array('token' => $order['token'], 'cid' => $order['cid']);
             $sendwecha_id = M('New_product_set_reply')->where($where)->field('wecha_id')->find();
             //准备发送请求的数据
             $data = '{"touser":"******","msgtype":"text", "text":{"content":"您的用户:' . $userInfo['truename'] . '订购了商品,电话:' . $order['tel'] . ',收货地址:' . $order['address'] . ',备注信息:' . $order['note'] . ',订单号:' . $orderid . ',订单金额:' . $order['price'] . '元,已经付款成功!"}}';
             $this->postCurl($url, $data);
             //打印请求
             $company = D('Company')->where(array('token' => $order['token'], 'id' => $order['cid']))->find();
             $op = new orderPrint();
             $msg = array('companyname' => $company['name'], 'companytel' => $company['tel'], 'truename' => $order['truename'], 'tel' => $order['tel'], 'address' => $order['address'], 'buytime' => $order['time'], 'orderid' => $order['orderid'], 'sendtime' => '', 'price' => $order['price'], 'total' => $order['total'], 'des' => $order['note'], 'ptype' => $order['paytype'], 'list' => $list);
             $msg = ArrayToStr::array_to_str($msg, 1);
             $op->printit($order['token'], $order['cid'], 'Store', $msg, 1);
             Sms::sendSms($order['token'], "您的顾客{$userInfo['truename']}刚刚对订单号:{$orderid}的订单进行了支付,请您注意查看并处理", $company['mp']);
             $model = new templateNews();
             $model->sendTempMsg('OPENTM202521011', array('href' => U('Storenew/myinfo', array('token' => $order['token'], 'wecha_id' => $order['wecha_id'], 'twid' => $order['twid']), true, false, true), 'wecha_id' => $order['wecha_id'], 'first' => '购买商品提醒', 'keyword1' => $orderid, 'keyword2' => date("Y年m月d日H时i分s秒"), 'remark' => '购买成功,感谢您的光临,欢迎下次再次光临!'));
         }
         header('Location:/index.php?g=Wap&m=Storenew&a=myinfo&token=' . $order['token'] . '&wecha_id=' . $order['wecha_id'] . '&twid=' . $order['twid']);
     } else {
         exit('订单不存在:' . $out_trade_no);
         exit('订单不存在');
     }
 }
예제 #27
0
 public function toPrint()
 {
     $id = $this->_post('oid') ? intval($this->_post('oid', 'trim')) : 0;
     $dishOrder = M('Dish_order');
     if ($thisOrder = $dishOrder->where(array('id' => $id, 'cid' => $this->_cid, 'token' => $this->token, 'comefrom' => 'dishout'))->find()) {
         $company = M('Company')->where(array('token' => $this->token, 'id' => $thisOrder['cid']))->find();
         $temp = unserialize($thisOrder['info']);
         $op = new orderPrint();
         $msg = array('companyname' => $company['name'], 'des' => htmlspecialchars_decode($thisOrder['des'], ENT_QUOTES), 'companytel' => $company['tel'], 'truename' => htmlspecialchars_decode($thisOrder['name'], ENT_QUOTES), 'tel' => $thisOrder['tel'], 'address' => htmlspecialchars_decode($thisOrder['address'], ENT_QUOTES), 'buytime' => $thisOrder['time'], 'orderid' => $thisOrder['orderid'], 'sendtime' => $thisOrder['reservetime'], 'price' => $thisOrder['price'], 'total' => $thisOrder['total'], 'typename' => '外卖', 'list' => $temp);
         $msg = ArrayToStr::array_to_str($msg, $thisOrder['paid']);
         $op->printit($this->token, $this->_cid, 'DishOut', $msg, 1);
         echo json_encode(array('error' => 0));
     }
 }
예제 #28
0
	public function payReturn()
	{
		$tb_resbook = D('Medical_user');
		$orderid = filter_var($this->_get('orderid'), FILTER_SANITIZE_STRING);
		$token = filter_var($this->_get('token'), FILTER_SANITIZE_STRING);
		$checkOrder = $tb_resbook->where(array('orderid' => $orderid, 'token' => $token))->find();

		if ($checkOrder) {
			if ($checkOrder['paid'] == '1') {
				$this->assign('token', $checkOrder['token']);
				$this->assign('wecha_id', $checkOrder['wecha_id']);
				Sms::sendSms($checkOrder['token'], '您的会员 ' . $checkOrder['truename'] . ',已经预约了' . $checkOrder['orderName'] . ' 并付款成功,金额为' . $checkOrder['price'] . ',订单号为' . $checkOrder['orderid'] . '. ' . date('Y-m-d H:i:s', time()));
				Sms::sendSms($checkOrder['token'], ' ' . $checkOrder['truename'] . ',您购买的' . $checkOrder['orderName'] . ' 已经付款成功,金额为' . $checkOrder['price'] . ',订单号为' . $checkOrder['orderid'] . '! ' . date('Y-m-d H:i:s', time()), $checkOrder['utel']);
				$op = new orderPrint();
				$msg = $this->content_layout($checkOrder);
				$op->printit($token, 0, 'Medical', $msg, 1);
				$this->redirect('Medical/ReserveBooking', array('token' => $token, 'wecha_id' => $wecha_id), 1, '恭喜预约成功,请不要重复刷新页面...');
				exit();
			}
			else {
				$this->redirect('Medical/registered', array('token' => $token, 'wecha_id' => $checkOrder['wecha_id']), 3, '您好,支付失败,请重新下单,请不要重复刷新页面,请耐心等待...');
			}
		}
		else {
			exit('订单不存在!');
		}
	}
예제 #29
0
	/**
	 * 订单详情
	 */
	public function orderInfo() {
		$id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
		$hotelOrder = M('Hotels_order');
		if ($thisOrder = $hotelOrder->where(array('id' => $id, 'token' => $this->token, 'cid' => $this->_cid))->find()) {
			if (IS_POST) {
				$status = isset($_POST['status']) ? intval($_POST['status']) : 0;
				$paid = isset($_POST['paid']) ? intval($_POST['paid']) : 0;
				$hotelOrder->where(array('id' => $thisOrder['id']))->save(array('status' => $status, 'paid' => $paid));
				$company = M('Company')->where(array('token' => $this->token, 'id' => $thisOrder['cid']))->find();
				if ($paid && empty($thisOrder['paid'])) {
					$sort = M('Hotels_house_sort')->where(array('id' => $thisOrder['sid'], 'token' => $this->token))->find();
					$days = (strtotime($thisOrder['enddate']) - strtotime($thisOrder['startdate'])) / 86400;
					$price = $this->fans['getcardtime'] > 0 ? ($sort['vprice'] ? $sort['vprice'] : $sort['price']) : $sort['price'];
					$op = new orderPrint();
					$msg = array('companyname' => $company['name'], 'companytel' => $company['tel'], 'truename' => $thisOrder['name'], 'tel' => $thisOrder['tel'], 'address' => '', 'buytime' => $thisOrder['time'], 'orderid' => $thisOrder['orderid'], 'sendtime' => '', 'price' => $thisOrder['price'], 'total' => $thisOrder['nums'], 'list' => array(array('name' => $sort['name'], 'day' => $days, 'price' => $price, 'num' => $thisOrder['nums'], 'startdate' => $thisOrder['startdate'], 'enddate' => $thisOrder['enddate'])));
					$msg = ArrayToStr::array_to_str($msg, 1);
					$op->printit($this->token, $this->_cid, 'Hotel', $msg, 1);
				}
				
				Sms::sendSms($this->token, "{$company['name']}欢迎您,本店对您的订单号为:{$thisOrder['orderid']}的订单状态进行了修改,如有任何疑意,请您及时联系本店!", $thisOrder['tel']);
				$this->success('修改成功',U('Hotels/orderInfo',array('token'=>session('token'),'id'=>$thisOrder['id'])));
			} else {
				$sort = M('Hotels_house_sort')->where(array('cid' => $this->_cid, 'token' => $this->token, 'id' => $thisOrder['sid']))->find();
				$thisOrder['housename'] = isset($sort['name']) ? $sort['name'] : '';
				$this->assign('thisOrder', $thisOrder);
				$this->display();
			}
		}
	}
예제 #30
0
 /**
  * 保存订单
  */
 public function saveorder()
 {
     if (empty($this->user_session)) {
         exit(json_encode(array('status' => 1, 'message' => '请先进行登录!', 'url' => U('Login/index'))));
     }
     $orid = isset($_REQUEST['orid']) ? intval($_REQUEST['orid']) : 0;
     $total = $price = $tmpprice = 0;
     $disharr = unserialize($_SESSION[$this->session_index]);
     $idarr = array_keys($disharr);
     $store_meal = D('Merchant_store_meal')->where(array('store_id' => $this->store_id))->find();
     if ($old_order = $this->check_order($orid)) {
         //加菜
         $info = $old_order['info'] ? unserialize($old_order['info']) : array();
         $isadd = empty($info) ? 0 : 1;
         if ($idarr) {
             $dish = M("Meal")->where(array('store_id' => $this->store_id, 'meal_id' => array('in', $idarr), 'status' => 1))->select();
             foreach ($dish as $val) {
                 $num = isset($disharr[$val['meal_id']]['num']) ? intval($disharr[$val['meal_id']]['num']) : 0;
                 $omark = isset($disharr[$val['meal_id']]['omark']) ? htmlspecialchars($disharr[$val['meal_id']]['omark']) : '';
                 $info[] = array('id' => $val['meal_id'], 'name' => $val['name'], 'price' => $val['price'], 'num' => $num, 'omark' => $omark, 'isadd' => $isadd);
                 $total += $num;
                 $tmpprice += $val['price'] * $num;
                 // 					$price += $val['price'] * $num;
             }
             //会员等级优惠
             $level_off = false;
             $finaltotalprice = 0;
             if (!empty($this->user_level) && !empty($this->leveloff) && !empty($this->user_session) && isset($this->user_session['level'])) {
                 /****type:0无优惠 1百分比 2立减*******/
                 if (isset($this->leveloff[$this->user_session['level']]) && isset($this->user_level[$this->user_session['level']])) {
                     $level_off = $this->leveloff[$this->user_session['level']];
                     if ($level_off['type'] == 1) {
                         $finaltotalprice = $tmpprice * ($level_off['vv'] / 100);
                         $finaltotalprice = $finaltotalprice > 0 ? $finaltotalprice : 0;
                         $level_off['offstr'] = '按此次总价' . $level_off['vv'] . '%来结算';
                     } elseif ($level_off['type'] == 2) {
                         $finaltotalprice = $tmpprice - $level_off['vv'];
                         $finaltotalprice = $finaltotalprice > 0 ? $finaltotalprice : 0;
                         $level_off['offstr'] = '此次总价立减' . $level_off['vv'] . '元';
                     }
                 }
             }
             if (!empty($old_order['leveloff'])) {
                 $leveloff = unserialize($old_order['leveloff']);
                 $price = $finaltotalprice > 0 ? $leveloff['totalprice'] + $finaltotalprice : $leveloff['totalprice'] + $tmpprice;
                 $price = round($price, 2);
                 is_array($level_off) && ($level_off['totalprice'] = $price);
             } else {
                 foreach ($info as $v) {
                     $price += $v['price'] * $v['num'];
                 }
                 $price = max($price, $old_order['price']);
             }
             $total_price = $price;
             $minus_price = 0;
             if ($store_meal && !empty($store_meal['minus_money']) && $price > $store_meal['full_money']) {
                 $price = $price - $store_meal['minus_money'];
                 $minus_price = $store_meal['minus_money'];
             }
             $data = array('total' => $total + $old_order['total'], 'price' => $price, 'dateline' => time());
             $data['orderid'] = date("YmdHis") . sprintf("%08d", $this->user_session['uid']);
             $data['info'] = $info ? serialize($info) : '';
             $data['total_price'] = $total_price;
             $data['minus_price'] = $minus_price;
             $data['paid'] = $old_order['paid'] == 1 ? 2 : 0;
             !empty($level_off) && ($data['leveloff'] = serialize($level_off));
             if ($return = D("Meal_order")->where(array('order_id' => $orid, 'uid' => $this->user_session['uid']))->save($data)) {
                 $_SESSION[$this->session_index] = null;
                 $_SESSION["allmark" . $this->store_id . $this->mer_id] = null;
                 redirect(U('Pay/check', array('order_id' => $orid, 'type' => 'food')));
             } else {
                 $this->error('服务器繁忙,稍后重试');
             }
         } else {
             $jumpurl = U('Food/menu', array('mer_id' => $this->mer_id, 'store_id' => $this->store_id, 'orid' => $orid));
             $this->error('还没有加菜呢', $jumpurl);
         }
     } else {
         //点菜的新单信息
         $phone = isset($_POST['tel']) ? htmlspecialchars($_POST['tel']) : '';
         $name = isset($_POST['name']) ? htmlspecialchars($_POST['name']) : '';
         $address = isset($_POST['address']) ? htmlspecialchars($_POST['address']) : '';
         $note = isset($_POST['mark']) ? htmlspecialchars($_POST['mark']) : '';
         $date = isset($_POST['date']) ? htmlspecialchars($_POST['date']) : '';
         $time = isset($_POST['time']) ? htmlspecialchars($_POST['time']) : '';
         $sex = isset($_POST['sex']) ? intval($_POST['sex']) : 1;
         $num = isset($_POST['num']) ? intval($_POST['num']) : 2;
         $tableid = isset($_POST['seattype']) ? intval($_POST['seattype']) : 0;
         if (empty($date)) {
             exit(json_encode(array('status' => 1, 'message' => '就餐日期不能为空')));
         }
         if (empty($time)) {
             exit(json_encode(array('status' => 1, 'message' => '就餐时间不能为空')));
         }
         if (empty($name)) {
             exit(json_encode(array('status' => 1, 'message' => '您的姓名不能为空')));
         }
         if (empty($phone)) {
             exit(json_encode(array('status' => 1, 'message' => '您的电话不能为空')));
         }
         $arrive_time = strtotime($date . ' ' . $time . ":00");
         $info = array();
         if ($idarr) {
             //点餐
             $dish = M("Meal")->where(array('store_id' => $this->store_id, 'meal_id' => array('in', $idarr), 'status' => 1))->select();
             foreach ($dish as $val) {
                 $num = isset($disharr[$val['meal_id']]['num']) ? intval($disharr[$val['meal_id']]['num']) : 0;
                 $omark = isset($disharr[$val['meal_id']]['omark']) ? htmlspecialchars($disharr[$val['meal_id']]['omark']) : '';
                 $info[] = array('id' => $val['meal_id'], 'name' => $val['name'], 'price' => $val['price'], 'num' => $num, 'omark' => $omark, 'isadd' => 0);
                 $total += $num;
                 $price += $val['price'] * $num;
             }
             //会员等级优惠
             $level_off = false;
             $finaltotalprice = 0;
             if (!empty($this->user_level) && !empty($this->leveloff) && !empty($this->user_session) && isset($this->user_session['level'])) {
                 /****type:0无优惠 1百分比 2立减*******/
                 if (isset($this->leveloff[$this->user_session['level']]) && isset($this->user_level[$this->user_session['level']])) {
                     $level_off = $this->leveloff[$this->user_session['level']];
                     if ($level_off['type'] == 1) {
                         $finaltotalprice = $price * ($level_off['vv'] / 100);
                         $finaltotalprice = $finaltotalprice > 0 ? $finaltotalprice : 0;
                         $level_off['offstr'] = '按此次总价' . $level_off['vv'] . '%来结算';
                     } elseif ($level_off['type'] == 2) {
                         $finaltotalprice = $price - $level_off['vv'];
                         $finaltotalprice = $finaltotalprice > 0 ? $finaltotalprice : 0;
                         $level_off['offstr'] = '此次总价立减' . $level_off['vv'] . '元';
                     }
                 }
             }
             $price = $finaltotalprice > 0 ? round($finaltotalprice, 2) : $price;
             $level_off && is_array($level_off) && ($level_off['totalprice'] = $price);
         } else {
             //预定
             $price = $this->_store['deposit'];
         }
         $total_price = $price;
         $minus_price = 0;
         if ($store_meal && !empty($store_meal['minus_money']) && $price > $store_meal['full_money']) {
             $price = $price - $store_meal['minus_money'];
             $minus_price = $store_meal['minus_money'];
         }
         $isdeposit = isset($_POST['isdeposit']) ? intval($_POST['isdeposit']) : 0;
         /***isdeposit 1 支付预定经***/
         $price = $isdeposit ? $this->_store['deposit'] : $price;
         if (isset($level_off) && $isdeposit && $level_off['totalprice'] < $price) {
             $level_off['totalprice'] = $price;
         }
         $data = array('mer_id' => $this->mer_id, 'tableid' => $tableid, 'store_id' => $this->store_id, 'name' => $name, 'phone' => $phone, 'address' => $address, 'note' => $note, 'dateline' => time(), 'total' => $total, 'price' => $price, 'arrive_time' => $arrive_time);
         $data['orderid'] = date("YmdHis") . sprintf("%08d", $this->user_session['uid']);
         $data['uid'] = $this->user_session['uid'];
         $data['sex'] = $sex;
         $data['num'] = $num;
         $data['info'] = $info ? serialize($info) : '';
         $data['total_price'] = $total_price;
         $data['minus_price'] = $minus_price;
         isset($level_off) && !empty($level_off) && ($data['leveloff'] = serialize($level_off));
         $orderid = D("Meal_order")->add($data);
         if ($orderid) {
             $_SESSION[$this->session_index] = null;
             $_SESSION["allmark" . $this->store_id . $this->mer_id] = null;
             if ($this->user_session['openid']) {
                 $keyword2 = '';
                 $pre = '';
                 foreach (unserialize($data['info']) as $menu) {
                     $keyword2 .= $pre . $menu['name'] . ':' . $menu['price'] . '*' . $menu['num'];
                     $pre = '\\n\\t\\t\\t';
                 }
                 $href = C('config.site_url') . '/wap.php?c=Food&a=order_detail&order_id=' . $orderid . '&mer_id=' . $data['mer_id'] . '&store_id=' . $data['store_id'];
                 $model = new templateNews(C('config.wechat_appid'), C('config.wechat_appsecret'));
                 $model->sendTempMsg('OPENTM201682460', array('href' => $href, 'wecha_id' => $this->user_session['openid'], 'first' => '您好,您的订单已生成', 'keyword3' => $orderid, 'keyword1' => date('Y-m-d H:i:s'), 'keyword2' => $keyword2, 'remark' => '您的该次' . $this->config['meal_alias_name'] . '下单成功,感谢您的使用!'));
             }
             $msg = array();
             $msg['user_name'] = $data['name'];
             $msg['user_phone'] = $data['phone'];
             $msg['user_address'] = $data['address'];
             $msg['user_message'] = $data['note'];
             $msg['buy_time'] = date("Y-m-d H:i:s", $data['dateline']);
             $msg['goods_list'] = $info;
             $msg['goods_count'] = $data['total'];
             $msg['goods_price'] = $data['price'];
             $msg['orderid'] = $orderid;
             $msg['pay_status'] = '';
             $msg['pay_type'] = '';
             $msg['store_name'] = $this->_store['name'];
             $msg['store_phone'] = $this->_store['phone'];
             $msg['store_address'] = $this->_store['adress'];
             $msg = ArrayToStr::array_to_str($msg, 0, $this->config['print_format']);
             $op = new orderPrint($this->config['print_server_key'], $this->config['print_server_topdomain']);
             $op->printit($this->mer_id, $this->store_id, $msg, 0);
             $sms_data = array('mer_id' => $this->mer_id, 'store_id' => $this->store_id, 'type' => 'food');
             if ($this->config['sms_place_order'] == 1 || $this->config['sms_place_order'] == 3) {
                 $sms_data['uid'] = $this->user_session['uid'];
                 $sms_data['mobile'] = $data['phone'];
                 $sms_data['sendto'] = 'user';
                 $sms_data['content'] = '您在' . $this->_store['name'] . '中预定的用餐的订单生产成功,订单号:' . $orderid;
                 Sms::sendSms($sms_data);
             }
             if ($this->config['sms_place_order'] == 2 || $this->config['sms_place_order'] == 3) {
                 $sms_data['uid'] = 0;
                 $sms_data['mobile'] = $this->_store['phone'];
                 $sms_data['sendto'] = 'merchant';
                 $sms_data['content'] = '顾客' . $data['name'] . '刚刚下了一个订单,订单号:' . $orderid . '请您注意查看并处理';
                 Sms::sendSms($sms_data);
             }
             /* 粉丝行为分析 */
             $this->behavior(array('mer_id' => $this->mer_id, 'biz_id' => $orderid));
             exit(json_encode(array('status' => 0, 'url' => U('Pay/check', array('order_id' => $orderid, 'type' => 'food')))));
         } else {
             exit(json_encode(array('status' => 1, 'message' => '服务器繁忙,稍后重试')));
         }
     }
     // 		(
     // 		[date] => 2015-05-23
     // 		[time] => 10:11
     // 		[num] => 2
     // 		[seattype] => 1
     // 		[tel] => 15209838315
     // 		[name] => hf
     // 		[sex] => 1
     // 		[mark] => 55
     // 		[table_fee] => 0
     // 		[dishes_status] => 1
     // 		[order_sn] =>
     // 		[utype] => 1
     // 		)
 }