user_coupon_id !==0){ $r = UserCoupon::where("id",$order['user_coupon_id'])->update(['status'=>0]); } $refund_pricet = $order->order_amount; if($order->order_status >=30){ $refund_pricet = $order->order_amount - $order->mileage_server_price; $refund_pricet = $refund_pricet-($order->server_all_price*0.3); } $recordSn = generate_sn(RefundRecord::class, 'order_sn'); $record = RefundRecord::create([ 'order_sn' => $recordSn, 'user_id' => $order->user_id, 'store_id'=>0, 'order_id' => $order->id, 'content_id'=>0,//关联相关id 'source_sn' => $order['order_sn'], 'order_type' => 10, 'order_amount' =>$refund_pricet, 'refund_amount' => $refund_pricet, 'refund_type' => 1, 'refund_way' => 1 ]); switch ($order->pay_way) { case '1': self::teamasterOrderRefund($order,$type); break; case '2': $refundData = [ 'transaction_id'=>$order->transaction_id, 'refund_sn'=>$recordSn, 'total_amount'=>$refund_pricet, 'notify_url'=>'https://76458.com/'.('api/pay/notifyMnp'), ]; $payService = (new WeChatPayService(1, $user_id ?? null)); $result = $payService->refund($refundData); if($result['status'] !=='PROCESSING'){ throw new \Exception('押金退款失败请联系客服'); } return true; default: } return []; } public static function teamasterOrderRefund($order,$type){ $data = [ 'uptime'=>time(), 'pay_status'=>3 ]; if($order->order_status ==28||$order->order_status ==29){ $data['order_status'] = $type; $data['refund_time'] = time(); $data['refund_price'] = $order->order_amount; }elseif($order->order_status ==30){ $data['order_status'] = 42; $data['refund_time'] = time(); $refund_pricet = $order->order_amount - $order->mileage_server_price; $refund_pricet = $refund_pricet-($order->server_all_price*0.3); $data['refund_price'] = $refund_pricet; $data['team_income_price'] = (($order->server_all_price*0.3)*0.65)+$order->mileage_server_price; $user_team =TeamasterUser::where('id',$order->team_user_id)->find(); $user_money = $user_team['user_money']+$data['team_income_price']; $user_team->user_money = $user_money; $user_team->save(); $account_log = [ 'team_user_id'=>$order->team_user_id, 'user_id'=>$order->user_id, 'change_object'=>1, 'change_type'=>1, 'action'=>1, 'amount'=>$data['team_income_price'], 'before_amount'=>$user_team->user_money, 'after_amount'=>$user_team->user_money+$data['team_income_price'], 'source_sn'=>$order->order_sn, 'sub_sn'=>$order->order_sn, 'remark'=>'出发后用户退款——收取30%服务费和全额车马费', 'create_time'=>time() ]; self::getTeamasterAccountLog($account_log); } $user = User::where('id',$order->user_id)->find(); $money = $user->user_money+$data['refund_price']; $user->user_money =$money; $user->save(); OrderTeamaster::where('id',$order->id)->update($data); return []; } public static function getTeamasterAccountLog($account_log){ TeamasterAccountLog::create($account_log); return []; } }