select('id,storeId,outTradeNo,uniacid,appointment,deliveryMode,grantCouponId,userId,money,takeNo,outTradeNo') ->from('{{%ybwm_takeout_order}}') ->where('id=:id', [':id' => $orderId])->one(); $store = (new \yii\db\Query()) ->select('receiveStatus') ->from('{{%ybwm_store}}') ->where('id=:id', [':id' => $order['storeId']])->one(); $set=Config::getStoreSet('takeOutSet',$order['storeId']); $data['state']=2; $data['payMode']=$payMode; $data['payAt']=time(); if($order['deliveryMode']==10){ $data['selfCode'] = randomAESKey(5); } $startToday = strtotime(date('Y-m-d')." 00:00:00"); $endToday = strtotime(date('Y-m-d')." 23:59:59"); $total = (new \yii\db\Query()) ->from('{{%ybwm_takeout_order}}') ->where('takeNo>0 AND state not in (1,7) AND createdAt>=:startTime AND createdAt<:endTime AND storeId=:storeId',[':endTime'=>$endToday,'startTime'=>$startToday,'storeId'=>$order['storeId']])->count(); $data['takeNo'] = $total + 1; $res = Yii::$app->db->createCommand()->update('{{%ybwm_takeout_order}}', $data, 'id=:id', ['id' =>$orderId])->execute(); $transaction = Yii::$app->db->beginTransaction(); //开始事务 if($res){ $bill=Bill::bill($order['uniacid'],1,1,$order['outTradeNo'],1); if(!$bill){ $transaction->rollBack();//事务回滚 return false; } $transaction->commit();//提交事务 if($store['receiveStatus']==1){ //自动接单 self::voiceType($order['uniacid'],$order['storeId'],'receiving',$orderId); Order::receipt($orderId); // if($set['printType']==2){ // Printing::orderPrint($orderId,1); // } }else{ if($order['appointment']==2){ //普通订单提醒 self::voiceType($order['uniacid'],$order['storeId'],'newOrder',$orderId); } } if($order['grantCouponId']){ // 下单返红包 Member::grantCoupon($order['grantCouponId'],$order['userId']); // if(!$grantCoupon){ // $transaction->rollBack();//事务回滚 // return false; // } } Member::bonusPackage($orderId); //下单有礼 $politely=(new \yii\db\Query()) ->from('{{%ybwm_pay_politely}}') ->where('uniacid=:uniacid AND deleteAt=0 AND display=1 AND startTime<=:startTime AND endTime>:endTime AND orderMoney<=:orderMoney',[':orderMoney'=>$order['money'],':startTime'=>$now,':endTime'=>$now,':uniacid'=>$order['uniacid']]) ->andWhere([ 'or', ['and',['storeType'=>1,'storeId'=>$order['storeId']]], ['storeType'=>2], ['and',['storeType'=>3],['like','storeArr',$order['storeId']]] ])->one(); if($politely){ $isLabel=1; if($politely['people']==3){ $userBind=(new \yii\db\Query()) ->from('{{%ybwm_member_bind}}') ->where('userId=:userId AND storeId=:storeId',[':userId'=>$order['userId'],':storeId'=>$order['storeId']])->one(); $memberLabel=json_decode($politely['userLabel'],true); if(!in_array($userBind['vipLabel'],$memberLabel)){ $isLabel=2; } } $startTime=strtotime(date("Y-m-d")." 00:00:00"); $endTime=strtotime(date("Y-m-d")." 23:59:59"); $count=(new \yii\db\Query()) ->from('{{%ybwm_pay_politely_record}}') ->where('politelyId=:politelyId AND createdAt>=:startTime AND createdAt<=:endTime',[':startTime'=>$startTime,':endTime'=>$endTime,':politelyId'=>$politely['id']]) ->count(); $userCount=(new \yii\db\Query()) ->from('{{%ybwm_pay_politely_record}}') ->where('userId=:userId AND politelyId=:politelyId AND createdAt>=:startTime AND createdAt<=:endTime',[':startTime'=>$startTime,':endTime'=>$endTime,':userId'=>$order['userId'],':politelyId'=>$politely['id']]) ->count(); if($count<$politely['dayNum'] AND ($politely['limitType']==1 or $politely['maxNum']>$userCount) AND $isLabel==1){ $recordData['userId']=$order['userId']; $recordData['orderId']=$order['id']; $recordData['politelyId']=$politely['id']; $recordData['createdAt']=$now; if($politely['isBalance']==1){ $recordData['balance']=$politely['balance']; } if($politely['isIntegral']==1){ $recordData['integral']=$politely['integral']; } if($politely['isGrowth']==1){ $recordData['growth']=$politely['growth']; } if($politely['isCoupon']==1){ $recordData['coupon']=$politely['couponId']; } Yii::$app->db->createCommand()->insert('{{%ybwm_pay_politely_record}}', $recordData)->execute(); } } //$stock=Order::reduceStock($orderId); // if(!$stock){ // $transaction->rollBack();//事务回滚 // return false; // } if($set['printType']==1){ Printing::orderPrint($orderId,1); } WeChatPay::reporting($orderId,'PAY_SUCCESS'); Message::payOk($orderId); Message::storeSendSms($order['storeId'],1);//短信提醒 $openIdList=(new \yii\db\Query()) ->select(['openId']) ->from('{{%ybwm_openId}}') ->where('storeId=:storeId',[':storeId'=>$order['storeId']])->all(); if($openIdList){ for($i=0;$ifrom('{{%ybwm_user_balance_order}}') ->where('id=:id', [':id' => $orderId])->one(); $storeId = $order['storeId']; $data['state']=2; $data['payMode']=$payMode; $data['payAt']=time(); $transaction = Yii::$app->db->beginTransaction(); //开始事务 $res = Yii::$app->db->createCommand()->update('{{%ybwm_user_balance_order}}', $data, 'id=:id', ['id' =>$orderId])->execute(); if($res){ $bill=Bill::bill($order['uniacid'],2,2,$order['outTradeNo'],1);//添加账单 if(!$bill){ $transaction->rollBack();//事务回滚 return false; } $saveBalance=Member::saveBalance($order['userId'],2,$order['money'],1,'在线充值',$order['uniacid'],0,$storeId);//增加余额 if(!$saveBalance){ $transaction->rollBack();//事务回滚 return false; } if($order['giveMoney']>0){ $saveGiveBalance=Member::saveBalance($order['userId'],2,$order['giveMoney'],1,'充值赠送',$order['uniacid'],0,$storeId);//增加赠送余额 if(!$saveGiveBalance){ $transaction->rollBack();//事务回滚 return false; } } if($order['giveScore']>0){ $saveGiveIntegral=Member::saveIntegral($order['userId'],2,$order['giveScore'],1,'充值赠送',$order['uniacid'],'',0,$storeId);//增加赠送积分 if(!$saveGiveIntegral){ $transaction->rollBack();//事务回滚 return false; } } if($order['giveGrow']>0){ $saveGiveGrow=Member::saveGrowth($order['userId'],2,$order['giveGrow'],1,'充值赠送',$order['uniacid']);//增加赠送积分 if(!$saveGiveGrow){ $transaction->rollBack();//事务回滚 return false; } } if($order['couponId']){ //赠送优惠券 Member::receiveCoupon(json_decode($order['couponId'],true),$order['userId']); } $transaction->commit();//提交事务 return true; } return false; } //积分商城 public static function integralOrder($orderId,$payMode=1) { $order = (new \yii\db\Query()) ->from('{{%ybwm_integral_order}}') ->where('id=:id', [':id' => $orderId])->one(); if($order['goodsType']==2) { $data['state'] = 4; }else{ $data['state'] = 2; } $data['payMode']=$payMode; $data['payAt']=time(); $res = Yii::$app->db->createCommand()->update('{{%ybwm_integral_order}}', $data, 'id=:id', ['id' =>$orderId])->execute(); $transaction = Yii::$app->db->beginTransaction(); //开始事务 if($res){ if($order['money'] > 0){ $bill=Bill::bill($order['uniacid'],2,3,$order['outTradeNo'],1); if(!$bill){ $transaction->rollBack();//事务回滚 return false; } } if($order['goodsMoney'] > 0 and $order['goodsType']==2){ $saveGiveBalance=Member::saveBalance($order['userId'],2,$order['goodsMoney'],1,'积分兑换',$order['uniacid']);//增加赠送余额 if(!$saveGiveBalance){ $transaction->rollBack();//事务回滚 return false; } } if($order['score']>0){ $score=Member::saveIntegral($order['userId'], 2, $order['score'], 2, '兑换积分商品',$order['uniacid']);//扣除积分 if(!$score){ $transaction->rollBack();//事务回滚 return false; } } if($order['goodsType']==1){ $config=Config::getSystemSet('integralShop',$order['uniacid']); if($config['smsOpen']==1){ Message::sendSms($order['uniacid'],3,$config['tel']);//短信提醒 } if($config['printOpen']==1){ //打印订单 $storeId=Store::getMainStore($order['uniacid'])['id']; $result=Printing::integralOrderPrint($order['id'],$storeId); } } $transaction->commit();//提交事务 return true; } return false; } //券包 public static function rollBagOrder($orderId,$payMode=1) { $order = (new \yii\db\Query()) ->from('{{%ybwm_roll_bag_order}}') ->where('id=:id', [':id' => $orderId])->one(); $data['state'] = 2; $data['payMode']=$payMode; $data['payAt']=time(); $transaction = Yii::$app->db->beginTransaction(); //开始事务 $res = Yii::$app->db->createCommand()->update('{{%ybwm_roll_bag_order}}', $data, 'id=:id', ['id' =>$orderId])->execute(); if($res){ if($order['money'] > 0){ $bill=Bill::bill($order['uniacid'],2,4,$order['outTradeNo'],1); if(!$bill){ $transaction->rollBack();//事务回滚 return false; } } Member::rollBag($orderId); $num=$order['num']; Yii::$app->db->createCommand()->update('{{%ybwm_roll_bag}}', ['stock'=>new \yii\db\Expression('stock - '.$num),'salesNum'=>new \yii\db\Expression('salesNum + '.$num)], 'id=:id', ['id' =>$order['bagId']])->execute(); $transaction->commit();//提交事务 return true; } return false; } //收银订单 public static function cashierOrder($orderId,$payMode=1) { $order = (new \yii\db\Query()) ->from('{{%ybwm_cashier_order}}') ->where('id=:id', [':id' => $orderId])->one(); $data['state'] = 2; $data['payMode']=$payMode; $data['payAt']=time(); $transaction = Yii::$app->db->beginTransaction(); //开始事务 $res = Yii::$app->db->createCommand()->update('{{%ybwm_cashier_order}}', $data, 'id=:id', ['id' =>$orderId])->execute(); if($res){ if($order['money'] > 0){ $bill=Bill::bill($order['uniacid'],2,5,$order['outTradeNo'],1); if(!$bill){ $transaction->rollBack();//事务回滚 return false; } } $system=Config::getSystemSet('currency',$order['uniacid']); $orderIntegralType=$system['orderIntegralType']?:3; if($orderIntegralType==1){ Member::saveIntegral($order['userId'],2,$system['integral'],1,'订单积分奖励',$order['uniacid']);//增加积分 } if($orderIntegralType==2){ Member::saveIntegral($order['userId'],2,bcmul($order['money'],$system['integral']/100,0),1,'订单积分奖励',$order['uniacid']);//增加积分 } $orderGrowthType=$system['orderGrowthType']?:3; if($orderGrowthType==1){ Member::saveGrowth($order['userId'],2,$system['growth'],1,'订单成长值奖励',$order['uniacid']);//增加成长值 } if($orderGrowthType==2){ Member::saveGrowth($order['userId'],2,bcmul($order['money'],$system['growth']/100,0),1,'订单成长值奖励',$order['uniacid']);//增加成长值 } Printing::orderPrint($order['id'],4); Message::cashierPay($order['id']); Message::newCashierOrder($order['id']); $transaction->commit();//提交事务 Order::cashierVoice($order['id'], 'collection'); return true; } return false; } //快餐订单 public static function fastOrder($orderId,$payMode=1) { $order = (new \yii\db\Query()) ->from('{{%ybwm_instore_order}}') ->where('id=:id', [':id' => $orderId])->one(); $data['state'] = 2; $data['payMode']=$payMode; $data['payAt']=time(); $data['changeAt']=time(); $startToday = strtotime(date('Y-m-d', time())); $endToday = strtotime(date('Y-m-d', time())) + 3600 * 24; $day = date('Ymd'); $key = 'fastOrder'.$order['storeId'].$day; $res = Yii::$app->redis->setnx($key,1); if(empty($res)){ $rst = (new \yii\db\Query()) ->select('id,callNo') ->from('{{%ybwm_instore_order}}') ->where('createdAt>=:startTime AND createdAt<:endTime AND storeId=:storeId AND orderMode=2 AND state not in(1,5)',[':startTime'=>$startToday,':endTime'=>$endToday,':storeId'=>$order['storeId']])->orderBy('id desc')->count(); $num = empty($rst) ? 1 : $rst; Yii::$app->redis->setnx($key,$num); }else{ Yii::$app->redis->incrby($key,1); $code = Yii::$app->redis->get($key); } $code = substr("00" . $num, -3); $data['callNo'] = 'A' . $code; $total = (new \yii\db\Query()) ->from('{{%ybwm_instore_order}}') ->where('orderMode=2 AND takeNo>0 AND state not in (1,5) AND createdAt>=:startTime AND createdAt<:endTime AND storeId=:storeId',[':endTime'=>$endToday,'startTime'=>$startToday,'storeId'=>$order['storeId']])->count(); $data['takeNo'] = $total + 1; $transaction = Yii::$app->db->beginTransaction(); //开始事务 $res = Yii::$app->db->createCommand()->update('{{%ybwm_instore_order}}', $data, 'id=:id', ['id' =>$orderId])->execute(); if($res){ if($order['money'] > 0){ $bill=Bill::bill($order['uniacid'],1,6,$order['outTradeNo'],1); if(!$bill){ $transaction->rollBack();//事务回滚 return false; } } $transaction->commit();//提交事务 $set=Config::getStoreSet('fastSet',$order['storeId']); if($set['receiving']==1){ //自动接单 Order::fastReceipt($orderId); } Order::reduceStock($order['id'],1,3); Message::newFastOrder($order['id']); WeChatPay::reporting($orderId,'PAY_SUCCESS',3); Printing::orderPrint($order['id'],3); Order::instoreVoice($orderId, 'fastNewOrder'); return true; } return false; } //快餐订单 public static function cashierbalanceOrder($orderId,$payMode=1) { date_default_timezone_set('PRC'); $order = (new \yii\db\Query()) ->from('{{%ybwm_instore_order}}') ->where('id=:id', [':id' => $orderId])->one(); $data['state'] = 2; $data['payMode']=$payMode; $data['payAt']=time(); $data['changeAt']=time(); $startToday = strtotime(date('Y-m-d', time())); $endToday = strtotime(date('Y-m-d', time())) + 3600 * 24; $rst = (new \yii\db\Query()) ->select('id,callNo') ->from('{{%ybwm_instore_order}}') ->where('createdAt>=:startTime AND createdAt<:endTime AND storeId=:storeId AND orderMode=2 AND state not in(1,5)',[':startTime'=>$startToday,':endTime'=>$endToday,':storeId'=>$order['storeId']])->orderBy('id desc')->one(); if ($rst) { $str = substr($rst['callNo'], 1); $preg = '/[0]*/'; $result = preg_replace($preg, '', $str, 1); $num = $result + 1; $code = substr("00" . $num, -3); $data['callNo'] = 'A' . $code; } else { $data['callNo'] = "A001"; } $total = (new \yii\db\Query()) ->from('{{%ybwm_instore_order}}') ->where('orderMode=2 AND takeNo>0 AND state not in (1,5) AND createdAt>=:startTime AND createdAt<:endTime AND storeId=:storeId',[':endTime'=>$endToday,'startTime'=>$startToday,'storeId'=>$order['storeId']])->count(); $data['takeNo'] = $total + 1; $transaction = Yii::$app->db->beginTransaction(); //开始事务 $res = Yii::$app->db->createCommand()->update('{{%ybwm_instore_order}}', $data, 'id=:id', ['id' =>$orderId])->execute(); if($res){ if($order['money'] > 0){ $bill=Bill::bill($order['uniacid'],1,6,$order['outTradeNo'],1); if(!$bill){ $transaction->rollBack();//事务回滚 return false; } } $transaction->commit();//提交事务 // $set=Config::getStoreSet('fastSet',$order['storeId']); // if($set['receiving']==1){ // //自动接单 // Order::fastReceipt($orderId); // } Printing::orderPrint($order['id'],3); Message::newFastOrder($order['id']); return true; } return false; } //店内订单 public static function instoreOrder($orderId,$payMode=1) { $order = (new \yii\db\Query()) ->from('{{%ybwm_instore_order}}') ->where('id=:id', [':id' => $orderId])->one(); if($order['eatType']==1){ $data['state'] = 2;//餐前支付 变成就餐中 $data['receiptAt']=time(); $type=1; }else{ $data['completeAt']=time(); $data['state'] = 3; $type=2; } $data['payMode']=$payMode; $data['payAt']=time(); $data['changeAt']=time(); $startToday = strtotime(date('Y-m-d', time())); $endToday = strtotime(date('Y-m-d', time())) + 3600 * 24; $total = (new \yii\db\Query()) ->from('{{%ybwm_instore_order}}') ->where('orderMode=1 AND takeNo>0 AND createdAt>=:startTime AND createdAt<:endTime AND storeId=:storeId',[':endTime'=>$endToday,'startTime'=>$startToday,'storeId'=>$order['storeId']])->count(); $data['takeNo'] = $total + 1; $transaction = Yii::$app->db->beginTransaction(); //开始事务 $res = Yii::$app->db->createCommand()->update('{{%ybwm_instore_order}}', $data, 'id=:id', ['id' =>$orderId])->execute(); if($res){ if($order['money'] > 0){ $bill=Bill::bill($order['uniacid'],$type,7,$order['outTradeNo'],1); if(!$bill){ $transaction->rollBack();//事务回滚 return false; } } $transaction->commit();//提交事务 try{ if($order['eatType']==2){ Printing::orderPrint($order['id'],2,'',false); }else{ Printing::orderPrint($order['id'],2); } if($order['eatType']==1){ Message::inStoreOrder($orderId); Message::newInStoreOrder($orderId); //餐前 Yii::$app->db->createCommand()->update('{{%ybwm_table}}', ['state'=>3], 'id=:id', ['id' =>$order['tableId']])->execute(); }else{ $system=Config::getSystemSet('currency',$order['uniacid']); $orderIntegralType=$system['orderIntegralType']?:3; if($orderIntegralType==1){ Member::saveIntegral($order['userId'],2,$system['integral'],1,'订单积分奖励',$order['uniacid']);//增加积分 } if($orderIntegralType==2){ Member::saveIntegral($order['userId'],2,bcmul($order['money'],$system['integral']/100,0),1,'订单积分奖励',$order['uniacid']);//增加积分 } $orderGrowthType=$system['orderGrowthType']?:3; if($orderGrowthType==1){ Member::saveGrowth($order['userId'],2,$system['growth'],1,'订单成长值奖励',$order['uniacid']);//增加成长值 } if($orderGrowthType==2){ Member::saveGrowth($order['userId'],2,bcmul($order['money'],$system['growth']/100,0),1,'订单成长值奖励',$order['uniacid']);//增加成长值 } //餐后 Yii::$app->db->createCommand()->update('{{%ybwm_table}}', ['state'=>1,'userId'=>0], 'id=:id', ['id' =>$order['tableId']])->execute(); } WeChatPay::reporting($orderId,'PAY_SUCCESS',2); Order::reduceStock($orderId,1,2); //当餐前模式下,自动清台关闭后,支付完自动清台 if($order['eatType']==1){ $payModeData=Config::getStoreSet('instoreSet',$order['storeId']); if($payModeData&&$payModeData['autoClose']==2){ Order::inStoreCheckOut($order['id']); } Order::instoreVoice($orderId, 'inNewOrder'); } }catch (\Exception $e){ file_put_contents('堂食回调.log',json_encode($e)); } return true; } return false; } //收银台订单 public static function payOrder($orderId,$payMode=1,$userId='') { $order = (new \yii\db\Query()) ->from('{{%ybwm_instore_order}}') ->where('id=:id', [':id' => $orderId])->one(); if($order['payAt']){ echo json_encode(['code'=>2,'msg'=>'请勿重复支付']);die; } $payModeData=Config::getStoreSet('instoreSet',$order['storeId']); $eatType=$payModeData['payMode']?:2; $type=1; if($order['tableId']){ $orderType=2; if($eatType==1){ $data['state'] =2; $data['receiptAt']=time(); }else{ $data['completeAt']=time(); $data['state'] = 3; $type=2; } $origin=7; $startToday = strtotime(date('Y-m-d', time())); $endToday = strtotime(date('Y-m-d', time())) + 3600 * 24; $total = (new \yii\db\Query()) ->from('{{%ybwm_instore_order}}') ->where('orderMode=1 AND takeNo>0 AND state not in (1,4) AND createdAt>=:startTime AND createdAt<:endTime AND storeId=:storeId',[':endTime'=>$endToday,'startTime'=>$startToday,'storeId'=>$order['storeId']])->count(); $data['takeNo'] = $total + 1; }else{ $orderType=3; $origin=6; $data['state'] =2; $startToday = strtotime(date('Y-m-d', time())); $endToday = strtotime(date('Y-m-d', time())) + 3600 * 24; $rst = (new \yii\db\Query()) ->select('id,callNo') ->from('{{%ybwm_instore_order}}') ->where('createdAt>=:startTime AND createdAt<:endTime AND storeId=:storeId AND orderMode=2 AND state not in(1,5)',[':startTime'=>$startToday,':endTime'=>$endToday,':storeId'=>$order['storeId']])->orderBy('id desc')->one(); if ($rst) { $str = substr($rst['callNo'], 1); $preg = '/[0]*/'; $result = preg_replace($preg, '', $str, 1); $num = $result + 1; $code = substr("00" . $num, -3); $data['callNo'] = 'A' . $code; } else { $data['callNo'] = "A001"; } $total = (new \yii\db\Query()) ->from('{{%ybwm_instore_order}}') ->where('orderMode=2 AND takeNo>0 AND state not in (1,5) AND createdAt>=:startTime AND createdAt<:endTime AND storeId=:storeId',[':endTime'=>$endToday,'startTime'=>$startToday,'storeId'=>$order['storeId']])->count(); $data['takeNo'] = $total + 1; $data['receiptAt']=time(); } $data['payMode']=$payMode; $data['userId']=$userId; $data['payAt']=time(); $data['changeAt']=time(); $transaction = Yii::$app->db->beginTransaction(); //开始事务 $res = Yii::$app->db->createCommand()->update('{{%ybwm_instore_order}}', $data, 'id=:id', ['id' =>$orderId])->execute(); if(!$order['tableId']){ Order::fastReceipt($orderId); } //减库存 Order::reduceStock($orderId,1,$orderType); if($res!==false){ if($order['money'] > 0){ $bill=Bill::bill($order['uniacid'],$type,$origin,$order['outTradeNo'],1); if(!$bill){ $transaction->rollBack();//事务回滚 return false; } } if($order['tableId']){ if($eatType==1){ Yii::$app->db->createCommand()->update('{{%ybwm_table}}', ['state'=>3], 'id=:id', ['id' =>$order['tableId']])->execute(); } if($eatType==2){ Yii::$app->db->createCommand()->update('{{%ybwm_table}}', ['people'=>0,'state'=>1,'userId'=>0], 'id=:id', ['id' =>$order['tableId']])->execute(); } //当餐前模式下,自动清台关闭后,支付完自动清台 if($eatType==1){ if($payModeData&&$payModeData['autoClose']==2){ Order::inStoreCheckOut($orderId); } } if($order['eatType']==2){ Printing::orderPrint($order['id'],2,'',false); }else{ Printing::orderPrint($order['id'],2); } }else{ Printing::orderPrint($order['id'],3); } if($order['userId']){ Message::inStoreOrder($orderId); } $transaction->commit();//提交事务 return true; } return false; } //会员订单 public static function vipOrder($orderId,$payMode=1) { $order = (new \yii\db\Query()) ->from('{{%ybwm_user_vip_order}}') ->where('id=:id', [':id' => $orderId])->one(); $user=(new \yii\db\Query()) ->from('{{%ybwm_member}}') ->where('id=:id', [':id' => $order['userId']])->one(); if($user['vipEndTime']>time()){ $isEnd=2; }else{ $isEnd=1; } $set=Config::getSystemSet('payVipRebate',$order['uniacid']); $data['state'] = 2; $data['payMode']=$payMode; $data['payAt']=time(); $transaction = Yii::$app->db->beginTransaction(); //开始事务 $res = Yii::$app->db->createCommand()->update('{{%ybwm_user_vip_order}}', $data, 'id=:id', ['id' =>$orderId])->execute(); if($res){ if($isEnd==2){ $vipEndTime=$user['vipEndTime']+$order['day']*86400; }else{ $vipEndTime=time()+$order['day']*86400; } $userRes=Yii::$app->db->createCommand()->update('{{%ybwm_member}}', ['vipEndTime'=>$vipEndTime,'changeAt'=>time()], 'id=:id', ['id' =>$order['userId']])->execute(); Yii::$app->db->createCommand()->update('{{%ybwm_user_vip_order}}', ['endTime'=>$vipEndTime], 'id=:id', ['id' =>$orderId])->execute(); if(!$userRes){ $transaction->rollBack();//事务回滚 return false; } if($order['money'] > 0){ $bill=Bill::bill($order['uniacid'],2,8,$order['outTradeNo'],1); if(!$bill){ $transaction->rollBack();//事务回滚 return false; } } if($isEnd==1){ Yii::$app->db->createCommand()->update('{{%ybwm_user_vip_coupon}}',['state'=>1],['state'=>2,'userId'=>$order['userId']])->execute(); //不是会员购买 $couponArr=$set['couponArr']; $receiveCoupon=Member::receiveCoupon($couponArr,$order['userId'],13); if(!$receiveCoupon){ $transaction->rollBack();//事务回滚 return false; } $releaseAt=0; $rebateSet=Config::getSystemSet('payVipCycleRebate',$order['uniacid']); if($rebateSet['open']==1){ $releaseAt=strtotime(date("Y-m-d"))+($rebateSet['day']+1)*86400; } $couponData['userId']=$order['userId']; $couponData['couponId']=json_encode($couponArr); $couponData['releaseAt']=$releaseAt?:0; $couponData['state']=2; $couponData['uniacid']=$order['uniacid']; $couponData['createdAt']=time(); $coupon=Yii::$app->db->createCommand()->insert('{{%ybwm_user_vip_coupon}}',$couponData)->execute(); if(!$coupon){ // $transaction->rollBack();//事务回滚 return false; } } $transaction->commit();//提交事务 return true; } return false; } //预约订单 public static function appointmentOrder($orderId,$payMode=1) { $order = (new \yii\db\Query()) ->from('{{%ybwm_appointment}}') ->where('id=:id', [':id' => $orderId])->one(); $set=Config::getStoreSet('appointment',$order['storeId']); $data['state'] = 2; $data['payMode']=$payMode; $data['payAt']=time(); $transaction = Yii::$app->db->beginTransaction(); //开始事务 $res = Yii::$app->db->createCommand()->update('{{%ybwm_appointment}}', $data, 'id=:id', ['id' =>$orderId])->execute(); if($res){ if($order['money'] > 0){ $bill=Bill::bill($order['uniacid'],1,9,$order['outTradeNo'],1); if(!$bill){ $transaction->rollBack();//事务回滚 return false; } } if($set['auto']==1){ $adopt=Order::adoptAppointment($orderId); if(!$adopt){ $transaction->rollBack();//事务回滚 return false; } } $transaction->commit();//提交事务 return true; } return false; } public static function voiceType($uniacid,$storeId,$voiceName,$orderId=0){ //voiceName 新订单newOrder 自动接单receiving 预订单提醒advanceOrder 取消单cancelOrder // 退单chargebackOrder 催单reminderOrder 异常单errorOrder 打印机断开printerDisconnect 出餐慢slowOrder $re=(new \yii\db\Query()) ->from('{{%ybwm_store_set}}') ->where('uniacid=:uniacid and storeId=:storeId and ident=:ident',[':uniacid'=>$uniacid,':storeId'=>$storeId,':ident'=>'takeawayVoice']) ->one(); $typeData=json_decode($re['data'],true); $num=$typeData[$voiceName]; $redisArray=array( 'voiceName'=>$voiceName, 'uniacid'=>$uniacid, 'storeId'=>$storeId, 'num'=>$num?:1, 'orderId'=>$orderId, 'modelName'=>Yii::$app->params['channel_model_name'], 'type'=>1, ); if($voiceName){ try { Yii::$app->redis->rpush("myqueue",json_encode($redisArray)); }catch (\Exception $exception){ } } } function jPushSend($storeId=null,$note=null,$uniacid=null){ // require './vendor/jpush/jpush/autoload.php'; $config=[]; $app_key = $config['appKey']?:'18880bc1528d014a9ea834df'; $master_secret = $config['masterSecret']?:'70b7ff81cf42ae29fd44af6b'; $rider=(new \yii\db\Query()) ->from('{{%ybwm_registralist}}') ->where(['storeId'=>$storeId])->all(); $rider=array_column($rider,'registrationId'); if($rider){ if(count($rider)==1){ $rider=$rider[0]; } $client = new JPush($app_key, $master_secret); $pusher = $client->push(); $pusher->setPlatform('android'); //$pusher->addTag(array('dang')); //$pusher->addAlias('alias') //$pusher->addTag(array('tag1', 'tag2')) $pusher->addRegistrationId($rider); //$pusher->addAllAudience(); $pusher->setNotificationAlert($note); //var_dump($pusher);die; try{ $bool=$pusher->send(); // if($bool['http_code']==200){ // file_put_contents('push.logs',date('Y-m-d H:i:s',time()).PHP_EOL, FILE_APPEND); // } // file_put_contents('push.logs',json_encode($bool).PHP_EOL, FILE_APPEND); } catch (\JPush\Exceptions\JPushException $e) { // try something else here ///print $e; } } } }