where('order_addtimes', '<', $timeUnix) ->get(); foreach ($orders as $order) { // 订单主表 Order::where('order_id', $order->order_id)->update([ 'order_is_complete' => 'Y', 'order_status_system' => 'CONFIRM', 'order_status_storage'=> 'DONE' ]); // 订单详情表 OrderSheet::where('join_sheet_order_id', $order->order_id)->update(['order_sheet_status' => 'DONE']); // 7天后自动完成 order_is_complete=Y // $redis = Redis::connection(); // $key = Order::AUTOMATIC_COMPLETE_PREFIX . date('Ymd', strtotime("+7 days")); // $redis->sadd($key, $order->order_id); } Db::commit(); } catch (\Exception $e) { Db::rollBack(); } } /** * @Desc 自动完成订单 * @Author Gorden * @Date 2024/7/16 9:37 * * @return void */ public static function AutomaticComplete() { Db::beginTransaction(); try { $redis = Redis::connection(); $key = Order::AUTOMATIC_COMPLETE_PREFIX . date('Ymd'); $orderIds = $redis->smembers($key); foreach ($orderIds as $orderId){ $order = Order::where('order_id',$orderId) ->select('order_is_complete','order_category','order_status_system') ->first(); if ($order && $order->order_is_complete != 'Y' && $order->order_category != 'RETURN' && in_array($order->order_status_system,['RECVING','SIGNED','CONFIRM'])){ // 更新主表 Order::where('order_id',$orderId)->update(['order_is_complete'=>'Y','order_status_system'=>'CONFIRM','order_status_storage'=>'DONE']); // sheet表 OrderSheet::where('join_sheet_order_id',$orderId)->update(['order_sheet_status'=>'DONE']); } } $redis->del($key); Db::commit(); } catch (\Exception $e) { dump($e->getMessage()); Db::rollBack(); } } public static function checkPayingOrder() { try { Db::beginTransaction(); $timeUnix = strtotime("-30 minutes"); $orders = Order::where('order_status_system', 'PAYING') ->where('order_category','<>','DISHES') ->where('order_addtimes', '<', $timeUnix) ->get(); foreach ($orders as $order) { // 订单主表 Order::where('order_id', $order->order_id)->update([ 'order_is_complete' => 'Y', 'order_status_system' => 'CANCEL', 'order_status_payment' => 'CANCEL' ]); // 订单详情表 OrderSheet::where('join_sheet_order_id', $order->order_id)->update(['order_sheet_status' => 'CANCEL']); } Db::commit(); } catch (\Exception $e) { Db::rollBack(); } } public static function generateWriteOffData($params) { return [ 'charge' => [ 'charge_amount' => 1, 'charge_content' => $params['order_remark'] ?? '', 'charge_user_id' => $params['write_off_member_id'], 'charge_premises' => $params['dept_premises_id'], ], 'member_id' => $params['join_order_member_id'] ]; } /** * 微信支付宝扫码支付 */ public static function qrcodePay($params) { $qrcodeNbr = $params['qrcode_nbr']; $prefix = substr($qrcodeNbr,0,2); // 微信支付 if(in_array($prefix,[10,11,12,13,14,15])){ $payData = [ 'out_trade_no' => $params['orderGroupId'], 'body' => 'subject-测试', 'total_fee' => 1,//$params['order_sheet_pay']*100, 'auth_code' => $params['qrcode_nbr'], ]; try{ $result = Pay::wechat(config('payment.wxpay'))->pos($payData); }catch(\Exception $e){ Log::error("WXPAY",$e->getMessage()); throw new BusinessException("支付失败"); } Log::info("WXPAY_RETURN",$result); }else if(in_array($prefix,[25,26,27,28,29,30])){ $payData = [ 'out_trade_no' => $params['orderGroupId'], 'total_amount' => 0.01,//$params['order_sheet_pay'], 'subject' => '万悦康养订单', 'auth_code' => $params['qrcode_nbr'], ]; try{ $result = Pay::alipay(config('payment.alipay'))->pos($payData); }catch(\Exception $e){ Log::error("ALIPAY",$e->getMessage()); throw new BusinessException("支付失败"); } Log::info("ALIPAY_RETURN",$result); }else{ throw new BusinessException("二维码无效"); } return $result; } }