|  | @@ -440,28 +440,17 @@ class WholeController extends Curd
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          $order->sheet_amount = number_format($sheetAmount,2);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        $payDetail = PayDetail::where('join_pay_order_id', $order->order_groupby)
 | 
	
		
			
				|  |  | +        $payDetails = PayDetail::where('join_pay_order_id', $order->order_groupby)
 | 
	
		
			
				|  |  |              ->select('pay_id', 'pay_category', 'pay_prepayid', 'pay_paytimes', 'pay_status', 'pay_amount','pay_extend_json')
 | 
	
		
			
				|  |  | -            ->first();
 | 
	
		
			
				|  |  | +            ->get();
 | 
	
		
			
				|  |  | +        if (count($payDetails) > 1){
 | 
	
		
			
				|  |  | +            $order->pay_category = 'CONSTITUTE';
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        $payDetail = !empty($payDetails) ? $payDetails[0] : [];
 | 
	
		
			
				|  |  |          if(!empty($payDetail) && !empty($payDetail->pay_extend_json)){
 | 
	
		
			
				|  |  |              $payExtendJson = json_decode($payDetail->pay_extend_json,true);
 | 
	
		
			
				|  |  |              $payDetail->cancel_times = $payExtendJson['cancel_times'] ?? '';
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        $refund = OrderReturn::where('join_return_order_id',$orderId)
 | 
	
		
			
				|  |  | -            ->select('order_return_status','order_return_apply_datetime','order_return_apply_json','order_return_accept_datetime','order_return_refund_json','order_return_extend_json')
 | 
	
		
			
				|  |  | -            ->first();
 | 
	
		
			
				|  |  | -        if (!empty($refund->order_return_refund_json)){
 | 
	
		
			
				|  |  | -            $returnRefundJson = json_decode($refund->order_return_refund_json,true);
 | 
	
		
			
				|  |  | -            if (isset($returnRefundJson['user_id'])){
 | 
	
		
			
				|  |  | -                $userName = SysUser::where('user_id',$returnRefundJson['user_id'])->value('user_name');
 | 
	
		
			
				|  |  | -                $returnRefundJson['person'] = $userName;
 | 
	
		
			
				|  |  | -                unset($returnRefundJson['user_id']);
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            $refund->order_return_refund_json = json_encode($returnRefundJson);
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          if (!empty($payDetail) && !empty($payDetail->pay_prepayid)) {
 | 
	
		
			
				|  |  |              $categoryArray = explode('-', $payDetail->pay_prepayid);
 | 
	
		
			
				|  |  |              if (isset($categoryArray[1])) {
 | 
	
	
		
			
				|  | @@ -480,7 +469,19 @@ class WholeController extends Curd
 | 
	
		
			
				|  |  |          } else if (!empty($payDetail)) {
 | 
	
		
			
				|  |  |              $payDetail->pay_category = 'CASH';
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        $refund = OrderReturn::where('join_return_order_id',$orderId)
 | 
	
		
			
				|  |  | +            ->select('order_return_status','order_return_apply_datetime','order_return_apply_json','order_return_accept_datetime','order_return_refund_json','order_return_extend_json')
 | 
	
		
			
				|  |  | +            ->first();
 | 
	
		
			
				|  |  | +        if (!empty($refund->order_return_refund_json)){
 | 
	
		
			
				|  |  | +            $returnRefundJson = json_decode($refund->order_return_refund_json,true);
 | 
	
		
			
				|  |  | +            if (isset($returnRefundJson['user_id'])){
 | 
	
		
			
				|  |  | +                $userName = SysUser::where('user_id',$returnRefundJson['user_id'])->value('user_name');
 | 
	
		
			
				|  |  | +                $returnRefundJson['person'] = $userName;
 | 
	
		
			
				|  |  | +                unset($returnRefundJson['user_id']);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +            $refund->order_return_refund_json = json_encode($returnRefundJson);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          if (!empty($order->order_config_json)) {
 | 
	
		
			
				|  |  |              $orderConfigJson = json_decode($order->order_config_json, true);
 | 
	
		
			
				|  |  |              if (isset($orderConfigJson['reach'])) {
 | 
	
	
		
			
				|  | @@ -513,7 +514,8 @@ class WholeController extends Curd
 | 
	
		
			
				|  |  |              'refund' => $refund,
 | 
	
		
			
				|  |  |              'sheet' => $orderSheet,
 | 
	
		
			
				|  |  |              'express' => $express,
 | 
	
		
			
				|  |  | -            'payDetail' => $payDetail
 | 
	
		
			
				|  |  | +            'payDetail' => $payDetail,
 | 
	
		
			
				|  |  | +            'payDetails'=>$payDetails
 | 
	
		
			
				|  |  |          ];
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          return json_success('', $data);
 | 
	
	
		
			
				|  | @@ -1151,6 +1153,294 @@ class WholeController extends Curd
 | 
	
		
			
				|  |  |              return json_fail('支付失败');
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +    
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 组合支付
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public function payConstitute(Request $request)
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $params = $request->post();
 | 
	
		
			
				|  |  | +        // 余额、福利、储值卡 验证短信
 | 
	
		
			
				|  |  | +        if (!empty($params['pay_category_constitute']) && !in_array('OFFLINE',$params['pay_category_constitute']) && !in_array('QRCODE',$params['pay_category_constitute']) && (in_array('CASH',$params['pay_category_constitute']) || in_array('CARD',$params['pay_category_constitute']) || in_array('WELFARE',$params['pay_category_constitute']))){
 | 
	
		
			
				|  |  | +            $code = $params['sms_code'];
 | 
	
		
			
				|  |  | +            if (!$code){
 | 
	
		
			
				|  |  | +                return json_fail("验证码错误,请重新输入");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $member = Member::find($params['join_order_member_id']);
 | 
	
		
			
				|  |  | +            $mobile = $member->member_mobile;
 | 
	
		
			
				|  |  | +            $key = "SMS:CODE:ORDER_PAY:" . $mobile;
 | 
	
		
			
				|  |  | +            $redisCode = Redis::get($key);
 | 
	
		
			
				|  |  | +            if ($redisCode != $code && $code != '123456') {
 | 
	
		
			
				|  |  | +                return json_fail("验证码错误,请重新输入");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            Redis::del($key);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        // 验证线下付款密码
 | 
	
		
			
				|  |  | +        if (!empty($params['pay_category_constitute']) && in_array('OFFLINE',$params['pay_category_constitute'])){
 | 
	
		
			
				|  |  | +            $password = $params['offline_password'];
 | 
	
		
			
				|  |  | +            if ($password != '123456') {
 | 
	
		
			
				|  |  | +                return json_fail("密码错误,请重新输入");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $order = Order::where('order_id',$params['order_id'])->first();
 | 
	
		
			
				|  |  | +        if (!$order){
 | 
	
		
			
				|  |  | +            return json_fail('订单异常');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if ($order->order_status_system != 'PAYING'){
 | 
	
		
			
				|  |  | +            return json_fail('订单不是可支付状态');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (!empty($order->order_config_json)){
 | 
	
		
			
				|  |  | +            $orderConfigJson = json_decode($order->order_config_json,true);
 | 
	
		
			
				|  |  | +            if (isset($orderConfigJson['premises'])){
 | 
	
		
			
				|  |  | +                $premises = SysDept::where('dept_name',$orderConfigJson['premises'])->where('dept_category','营业场所')->first();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        $params['orderId'] = $params['order_id'];
 | 
	
		
			
				|  |  | +        $params['orderGroupId'] = $order->order_groupby;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $goods = Goods::where('goods_id', $params['join_sheet_goods_id'])
 | 
	
		
			
				|  |  | +        ->select('goods_id', 'goods_name', 'goods_classify')
 | 
	
		
			
				|  |  | +        ->first();
 | 
	
		
			
				|  |  | +        if (!$goods) {
 | 
	
		
			
				|  |  | +            Db::rollBack();
 | 
	
		
			
				|  |  | +            return json_fail('产品数据异常');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        $goods = $goods->toArray();
 | 
	
		
			
				|  |  | +        $params['goods_classify'] = $goods['goods_classify'];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $systemStatus = 'SENDING';  // 待发货
 | 
	
		
			
				|  |  | +        // 立即结算
 | 
	
		
			
				|  |  | +        if(in_array($params['goods_classify'],['SERVICE','CHNMED','CHNNCD','MEALS','VIP'])){
 | 
	
		
			
				|  |  | +            $order->order_is_complete = 'Y';
 | 
	
		
			
				|  |  | +            $systemStatus = 'DONE';
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        $payDetail = PayDetail::where('join_pay_order_id',$order->order_groupby)->first();
 | 
	
		
			
				|  |  | +        Db::beginTransaction();
 | 
	
		
			
				|  |  | +        try{
 | 
	
		
			
				|  |  | +            $orderAmountPay = $params['order_amount_pay'];
 | 
	
		
			
				|  |  | +            $constituteList = array_column($params['pay_category_constitute_list'],'amount','category');// 验证金额
 | 
	
		
			
				|  |  | +            $constituteAmount = 0;
 | 
	
		
			
				|  |  | +            foreach($params['pay_category_constitute_list'] as $item){
 | 
	
		
			
				|  |  | +                $constituteAmount = $constituteAmount + $item['amount'];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($params['order_amount_pay'] != $constituteAmount){
 | 
	
		
			
				|  |  | +                return json_fail('组合支付金额与应付金额不一致');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (!empty($params['pay_category_constitute']) && in_array('OFFLINE',$params['pay_category_constitute'])){  //线下付款
 | 
	
		
			
				|  |  | +                $order->order_status_system = $systemStatus;
 | 
	
		
			
				|  |  | +                $order->order_status_payment = 'SUCCESS';
 | 
	
		
			
				|  |  | +                $params['pay_category'] = 'OFFLINE';
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                // 线下支付金额
 | 
	
		
			
				|  |  | +                if (isset($constituteList['OFFLINE'])){
 | 
	
		
			
				|  |  | +                    $params['order_amount_pay'] = $constituteList['OFFLINE'];
 | 
	
		
			
				|  |  | +                    // 生成支付记录
 | 
	
		
			
				|  |  | +                    OrderService::createPayConstituteDetail($params, $payDetail);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                $params['order_amount_pay'] = $orderAmountPay;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (!empty($params['pay_category_constitute']) && in_array('CASH',$params['pay_category_constitute'])) {    // 余额支付
 | 
	
		
			
				|  |  | +                $account = MemberAccount::where('join_account_member_id', $params['join_order_member_id'])
 | 
	
		
			
				|  |  | +                    ->where('member_account_classify', 'CASH')
 | 
	
		
			
				|  |  | +                    ->where('member_account_status', 'ACTIVED')
 | 
	
		
			
				|  |  | +                    ->first();
 | 
	
		
			
				|  |  | +                if (!$account) {
 | 
	
		
			
				|  |  | +                    Db::rollBack();
 | 
	
		
			
				|  |  | +                    return json_fail('账户异常');
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (isset($constituteList['CASH'])){
 | 
	
		
			
				|  |  | +                    $params['order_amount_pay'] = $constituteList['CASH'];
 | 
	
		
			
				|  |  | +                    $params['pay_category'] = $params['join_order_member_id'].'-CASH';
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                $amount = $account->member_account_surplus + $account->member_account_added;
 | 
	
		
			
				|  |  | +                if ($params['pay_constitute'] == 'N' && (!$account || $params['order_amount_pay'] > $amount)) {
 | 
	
		
			
				|  |  | +                    Db::rollBack();
 | 
	
		
			
				|  |  | +                    return json_fail('账户余额不足');
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if($params['pay_constitute'] == 'Y' && (!$account || $params['order_amount_pay'] > $amount)){
 | 
	
		
			
				|  |  | +                    $qrcodePayAmount = $params['order_amount_pay'] - $amount;
 | 
	
		
			
				|  |  | +                    $params['order_amount_pay'] = $amount;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if ($params['order_amount_pay'] > $account->member_account_surplus) {
 | 
	
		
			
				|  |  | +                    $cut = $account->member_account_added - ($params['order_amount_pay'] - $account->member_account_surplus);
 | 
	
		
			
				|  |  | +                    $account->member_account_surplus = 0;
 | 
	
		
			
				|  |  | +                    $account->member_account_added = $cut;
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    $account->member_account_surplus = $account->member_account_surplus - $params['order_amount_pay'];
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
 | 
	
		
			
				|  |  | +                $account->save();
 | 
	
		
			
				|  |  | +                // 生成支付记录
 | 
	
		
			
				|  |  | +                OrderService::createPayConstituteDetail($params, $payDetail);
 | 
	
		
			
				|  |  | +                $params['order_amount_pay'] = $orderAmountPay;
 | 
	
		
			
				|  |  | +                $order->order_status_system = $systemStatus;
 | 
	
		
			
				|  |  | +                $order->order_status_payment = 'SUCCESS';
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (!empty($params['pay_category_constitute']) && in_array('CARD',$params['pay_category_constitute'])) {    // 储值卡账户
 | 
	
		
			
				|  |  | +                $cardNbr = $params['card_nbr'];
 | 
	
		
			
				|  |  | +                if (!$cardNbr){
 | 
	
		
			
				|  |  | +                    Db::rollBack();
 | 
	
		
			
				|  |  | +                    return json_fail('账户异常'); 
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                $account = MemberAccount::where('join_account_member_id', $params['join_order_member_id'])
 | 
	
		
			
				|  |  | +                    ->where('member_account_nbr', $cardNbr)
 | 
	
		
			
				|  |  | +                    ->where('member_account_status', 'ACTIVED')
 | 
	
		
			
				|  |  | +                    ->first();
 | 
	
		
			
				|  |  | +                if (!$account) {
 | 
	
		
			
				|  |  | +                    Db::rollBack();
 | 
	
		
			
				|  |  | +                    return json_fail('账户异常');
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                // 储值卡账户支付金额
 | 
	
		
			
				|  |  | +                if (isset($constituteList['CARD'])){
 | 
	
		
			
				|  |  | +                    $params['order_amount_pay'] = $constituteList['CARD'];
 | 
	
		
			
				|  |  | +                    $params['pay_category'] = $cardNbr;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                $amount = $account->member_account_surplus + $account->member_account_added;
 | 
	
		
			
				|  |  | +                if ($params['pay_constitute'] == 'N' && (!$account || $params['order_amount_pay'] > $amount)) {
 | 
	
		
			
				|  |  | +                    Db::rollBack();
 | 
	
		
			
				|  |  | +                    return json_fail('账户余额不足');
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if($params['pay_constitute'] == 'Y' && (!$account || $params['order_amount_pay'] > $amount)){
 | 
	
		
			
				|  |  | +                    $qrcodePayAmount = $params['order_amount_pay'] - $amount;
 | 
	
		
			
				|  |  | +                    $params['order_amount_pay'] = $amount;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if ($params['order_amount_pay'] > $account->member_account_surplus) {
 | 
	
		
			
				|  |  | +                    $cut = $account->member_account_added - ($params['order_amount_pay'] - $account->member_account_surplus);
 | 
	
		
			
				|  |  | +                    $account->member_account_surplus = 0;
 | 
	
		
			
				|  |  | +                    $account->member_account_added = $cut;
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    $account->member_account_surplus = $account->member_account_surplus - $params['order_amount_pay'];
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                $account->member_account_expend = $account->member_account_expend + $params['order_amount_pay'];
 | 
	
		
			
				|  |  | +                $account->save();
 | 
	
		
			
				|  |  | +                // 生成支付记录
 | 
	
		
			
				|  |  | +                OrderService::createPayConstituteDetail($params,$payDetail);
 | 
	
		
			
				|  |  | +                $params['order_amount_pay'] = $orderAmountPay;
 | 
	
		
			
				|  |  | +                $order->order_status_system = $systemStatus;
 | 
	
		
			
				|  |  | +                $order->order_status_payment = 'SUCCESS';
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if(!empty($params['pay_category_constitute']) && in_array('QRCODE',$params['pay_category_constitute']) && !empty($params['qrcode_nbr'])){     // 付款码
 | 
	
		
			
				|  |  | +                if(isset($constituteList['QRCODE']) && $constituteList['QRCODE'] > 0){
 | 
	
		
			
				|  |  | +                    // 付款码支付金额
 | 
	
		
			
				|  |  | +                    $params['order_amount_pay'] = $constituteList['QRCODE'];
 | 
	
		
			
				|  |  | +                    // 调支付
 | 
	
		
			
				|  |  | +                    $result = OrderService::qrcodePay($params);
 | 
	
		
			
				|  |  | +                    $result = json_encode($result);
 | 
	
		
			
				|  |  | +                    $params['pay_json_response'] = $result;
 | 
	
		
			
				|  |  | +                    $result = json_decode($result,true);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    $prefix = substr($params['qrcode_nbr'],0,2);
 | 
	
		
			
				|  |  | +                    if(in_array($prefix,[10,11,12,13,14,15])){
 | 
	
		
			
				|  |  | +                        $params['pay_category'] = 'WXPAY';
 | 
	
		
			
				|  |  | +                        if($result['return_code'] != 'SUCCESS' || $result['result_code'] != 'SUCCESS'){
 | 
	
		
			
				|  |  | +                            Db::rollBack();
 | 
	
		
			
				|  |  | +                            return json_fail('支付失败');
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }else if(in_array($prefix,[25,26,27,28,29,30])){
 | 
	
		
			
				|  |  | +                        $params['pay_category'] = 'ALIPAY';
 | 
	
		
			
				|  |  | +                        if($result['code'] != '10000' || $result['msg'] != 'Success'){
 | 
	
		
			
				|  |  | +                            Db::rollBack();
 | 
	
		
			
				|  |  | +                            return json_fail('支付失败');
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }else{
 | 
	
		
			
				|  |  | +                        Db::rollBack();
 | 
	
		
			
				|  |  | +                        return json_fail('二维码错误');
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                // 生成支付记录
 | 
	
		
			
				|  |  | +                OrderService::createPayConstituteDetail($params, $payDetail);
 | 
	
		
			
				|  |  | +                // 账户支付的金额
 | 
	
		
			
				|  |  | +                $params['order_amount_pay'] = $orderAmountPay;
 | 
	
		
			
				|  |  | +                $order->order_status_system = $systemStatus;
 | 
	
		
			
				|  |  | +                $order->order_status_payment = 'SUCCESS';
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $orderConfigJson = [];
 | 
	
		
			
				|  |  | +            if (!empty($order->order_config_json)){
 | 
	
		
			
				|  |  | +                $orderConfigJson = json_decode($order->order_config_json,true);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $orderConfigJson['preferential'] = $params['preferential'] ?? '';
 | 
	
		
			
				|  |  | +            if (isset($orderConfigJson['tableid']) && !empty($orderConfigJson['tableid'])){
 | 
	
		
			
				|  |  | +                SysDept::where('dept_id',$orderConfigJson['tableid'])->where('dept_category','桌台')->update(['dept_status'=>'ACTIVED']);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $order->order_config_json = json_encode($orderConfigJson);
 | 
	
		
			
				|  |  | +            $order->order_amount_pay = $params['order_amount_pay'];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            // 主订单
 | 
	
		
			
				|  |  | +            $order->save();
 | 
	
		
			
				|  |  | +            // sheet
 | 
	
		
			
				|  |  | +            if ($order->order_status_payment == 'SUCCESS'){
 | 
	
		
			
				|  |  | +                OrderSheet::where('join_sheet_order_id',$params['order_id'])->update([
 | 
	
		
			
				|  |  | +                    'order_sheet_status'=>$systemStatus,
 | 
	
		
			
				|  |  | +                ]);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            // 清除paydetail 中的未支付记录
 | 
	
		
			
				|  |  | +            PayDetail::where('join_pay_order_id',$params['orderGroupId'])->where('pay_status','<>','SUCCESS')->delete();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $writeOffDate = [];
 | 
	
		
			
				|  |  | +            $applyData = [];
 | 
	
		
			
				|  |  | +            // 有预约单,状态已完成
 | 
	
		
			
				|  |  | +            $appointment = Appointment::where('join_appointment_order_id',$params['order_id'])->first();
 | 
	
		
			
				|  |  | +            if($order->order_status_payment == 'SUCCESS' && $appointment){
 | 
	
		
			
				|  |  | +                $writeOffDate = OrderService::generateWriteOffData($params);
 | 
	
		
			
				|  |  | +                $applyData = OrderService::generateAppointmentApplyData($params);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                $appointment->appointment_status = 'DONE';
 | 
	
		
			
				|  |  | +                $appointment->appointment_done_datetime = date('Y-m-d H:i:s');
 | 
	
		
			
				|  |  | +                $appointment->appointment_done_json = json_encode($writeOffDate);
 | 
	
		
			
				|  |  | +                if (empty($appointment->appointment_apply_datetime)){
 | 
	
		
			
				|  |  | +                    $appointment->appointment_apply_datetime = date('Y-m-d H:i:s');
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (empty($appointment->appointment_apply_json)){
 | 
	
		
			
				|  |  | +                    $appointment->appointment_apply_json = json_encode($applyData);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (empty($appointment->appointment_datetime)){
 | 
	
		
			
				|  |  | +                    $appointment->appointment_datetime = date('Y-m-d');
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  | +                $appointment->save();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            Db::commit();
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            // 打小票
 | 
	
		
			
				|  |  | +            if (!empty($premises)){
 | 
	
		
			
				|  |  | +                $restaurant = SysDept::where('dept_super_id',$premises->dept_id)->where('dept_category','餐厅')->first();
 | 
	
		
			
				|  |  | +                if (!empty($restaurant->dept_extend_json)){
 | 
	
		
			
				|  |  | +                    $deptExtendJson = json_decode($restaurant->dept_extend_json,true);
 | 
	
		
			
				|  |  | +                    if (isset($deptExtendJson['printer'])){
 | 
	
		
			
				|  |  | +                        foreach($deptExtendJson['printer'] as $key => $item){
 | 
	
		
			
				|  |  | +                            if (strpos($key,'结算') !== false && $order->order_status_payment == 'SUCCESS'){
 | 
	
		
			
				|  |  | +                                $voteData = [
 | 
	
		
			
				|  |  | +                                    'func'=>'procActionToPrinter',
 | 
	
		
			
				|  |  | +                                    'sign'=>'',
 | 
	
		
			
				|  |  | +                                    'data'=>[
 | 
	
		
			
				|  |  | +                                        'printer_premises'=>$restaurant->dept_id,
 | 
	
		
			
				|  |  | +                                        'printer_device'=>[
 | 
	
		
			
				|  |  | +                                            $key
 | 
	
		
			
				|  |  | +                                        ],
 | 
	
		
			
				|  |  | +                                        'printer_action'=>'ExecPrintOrder',
 | 
	
		
			
				|  |  | +                                        'printer_data'=>[
 | 
	
		
			
				|  |  | +                                            'order_id'=>$params['order_id']
 | 
	
		
			
				|  |  | +                                        ]
 | 
	
		
			
				|  |  | +                                    ]
 | 
	
		
			
				|  |  | +                                ];
 | 
	
		
			
				|  |  | +                                http_post_json(getenv('VOTE_MENU_URL'),$voteData);
 | 
	
		
			
				|  |  | +                            }
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            _syslog("订单","订单支付成功");
 | 
	
		
			
				|  |  | +            return json_success('支付成功');
 | 
	
		
			
				|  |  | +        }catch(\Exception $e){
 | 
	
		
			
				|  |  | +            dump($e->getMessage());
 | 
	
		
			
				|  |  | +            Db::rollBack();
 | 
	
		
			
				|  |  | +            _syslog("订单","订单支付失败");
 | 
	
		
			
				|  |  | +            return json_fail('支付失败');
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 删除订单
 | 
	
	
		
			
				|  | @@ -1280,6 +1570,7 @@ class WholeController extends Curd
 | 
	
		
			
				|  |  |              $premises = SysDept::where('dept_name', $params['dept_premises_id'])->first();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        $params['goods_classify'] = $goodsClassifys[0];
 | 
	
		
			
				|  |  |          Db::beginTransaction();
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  |              // 验证库存
 | 
	
	
		
			
				|  | @@ -1343,16 +1634,6 @@ class WholeController extends Curd
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              
 | 
	
		
			
				|  |  |              $qrcodePayAmount = 0;
 | 
	
		
			
				|  |  | -            $goods = Goods::where('goods_id', $params['join_sheet_goods_id'])
 | 
	
		
			
				|  |  | -                ->select('goods_id', 'goods_name', 'goods_classify')
 | 
	
		
			
				|  |  | -                ->first();
 | 
	
		
			
				|  |  | -            if (!$goods) {
 | 
	
		
			
				|  |  | -                Db::rollBack();
 | 
	
		
			
				|  |  | -                return json_fail('产品数据异常');
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            $goods = $goods->toArray();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            $params['goods_classify'] = $goods['goods_classify'];
 | 
	
		
			
				|  |  |              $params['orderId'] = 'OD' . date('YmdHis') . random_string(6, 'up');
 | 
	
		
			
				|  |  |              $params['orderGroupId'] = 'OD' . date('YmdHis') . random_string(6, 'up');
 | 
	
		
			
				|  |  |              $params['benefitId'] = 'BF' . date('YmdHis') . random_string(6, 'up');
 | 
	
	
		
			
				|  | @@ -1635,7 +1916,6 @@ class WholeController extends Curd
 | 
	
		
			
				|  |  |                      $orderConfigJson['eat'] = $params['eat'] ?? null;
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |                  if ($params['settlement_now'] == 'N' && !empty($params['dept_table_id'])){
 | 
	
		
			
				|  |  |                      // 桌台设为使用中
 | 
	
		
			
				|  |  |                      SysDept::where('dept_id',$params['dept_table_id'])->where('dept_category','桌台')->update(['dept_status'=>'USING']);
 | 
	
	
		
			
				|  | @@ -1843,6 +2123,7 @@ class WholeController extends Curd
 | 
	
		
			
				|  |  |              if ($params['order_amount_pay'] != $constituteAmount){
 | 
	
		
			
				|  |  |                  return json_fail('组合支付金额与应付金额不一致');
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +            $params['goods_classify'] = $goodsClassifys[0];
 | 
	
		
			
				|  |  |              // 验证库存
 | 
	
		
			
				|  |  |              OrderService::checkGoodsStorage($params);
 | 
	
		
			
				|  |  |              // 余额、福利、储值卡 验证短信
 | 
	
	
		
			
				|  | @@ -1885,16 +2166,6 @@ class WholeController extends Curd
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              
 | 
	
		
			
				|  |  |              $qrcodePayAmount = 0;
 | 
	
		
			
				|  |  | -            $goods = Goods::where('goods_id', $params['join_sheet_goods_id'])
 | 
	
		
			
				|  |  | -                ->select('goods_id', 'goods_name', 'goods_classify')
 | 
	
		
			
				|  |  | -                ->first();
 | 
	
		
			
				|  |  | -            if (!$goods) {
 | 
	
		
			
				|  |  | -                Db::rollBack();
 | 
	
		
			
				|  |  | -                return json_fail('产品数据异常');
 | 
	
		
			
				|  |  | -            }
 | 
	
		
			
				|  |  | -            $goods = $goods->toArray();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -            $params['goods_classify'] = $goods['goods_classify'];
 | 
	
		
			
				|  |  |              $params['orderId'] = 'OD' . date('YmdHis') . random_string(6, 'up');
 | 
	
		
			
				|  |  |              $params['orderGroupId'] = 'OD' . date('YmdHis') . random_string(6, 'up');
 | 
	
		
			
				|  |  |              $params['benefitId'] = 'BF' . date('YmdHis') . random_string(6, 'up');
 |