From 9e34d24fc0a72fe162e1eb7b00da04a6064b5a98 Mon Sep 17 00:00:00 2001 From: lanzu_qinsheng <334039090@qq.com> Date: Sat, 12 Sep 2020 14:43:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8D=95=E5=90=8E=E8=B0=83=E7=94=A8RP?= =?UTF-8?q?C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Common/Rpc.php | 16 ++++++++++++++++ app/Admin/Extensions/OrderStateHandle.php | 23 +++++++++++++---------- app/Admin/Forms/RefundNote.php | 15 +++++++++------ 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/app/Admin/Common/Rpc.php b/app/Admin/Common/Rpc.php index 7a9d558..235a302 100644 --- a/app/Admin/Common/Rpc.php +++ b/app/Admin/Common/Rpc.php @@ -13,9 +13,25 @@ class Rpc const ORDER_REFUND = "/order/onlineRefund"; const ORDER_SINGLE_REFUND = "/order/onlineSingleRefund"; const GET_DISTANCE = "/location/getDistanceByTencent"; + const DO_BY_ORDER = "/badge/doByOrder"; + /** + * 订单完成时分账流水 + * @param $oid + * @param $uid + * @return string + */ + public static function doByOrder($userId, $storeIds, $globalOrderId, $orderState){ + $client = Client::factory(env('RPC_SITE_HOST')); + $request = $client->request( + uniqid(), + self::DO_BY_ORDER, + ['userId' => $userId,'storeIds'=>$storeIds,'globalOrderId'=>$globalOrderId,'orderState'=>$orderState]); + $response = $client->send($request); + return $response->getBody()->getContents(); + } /** * 订单完成时分账流水 * @param $oid diff --git a/app/Admin/Extensions/OrderStateHandle.php b/app/Admin/Extensions/OrderStateHandle.php index 687832c..05c1bb5 100644 --- a/app/Admin/Extensions/OrderStateHandle.php +++ b/app/Admin/Extensions/OrderStateHandle.php @@ -3,6 +3,7 @@ namespace App\Admin\Extensions; use App\Admin\Common\Rpc; use App\Admin\Forms\RefundNote; +use App\Models\ImsCjdcOrder; use App\Models\ImsCjdcOrderMain; use Dcat\Admin\Grid\Displayers\Modal; use Dcat\Admin\Grid\RowAction; @@ -35,9 +36,9 @@ class OrderStateHandle extends RowAction // 获取当前行ID $id = $this->getKey(); $orderMain = new ImsCjdcOrderMain(); + $order = $orderMain::where('id',$id)->first(); $state = $request->get('state'); if ($state==4){ - $order = $orderMain::where('id',$id)->first(); //记录分账流水 $result = json_decode(Rpc::separateAccounts($order->global_order_id,$order->user_id),true)['result']; if ($result['code']!=0){ @@ -46,22 +47,24 @@ class OrderStateHandle extends RowAction } return $this->response()->success('操作成功')->refresh(); }elseif ($state==9){//同意退款 - $order = $orderMain::where('id',$id)->first(); $result = json_decode(Rpc::orderRefund($order->global_order_id,$order->user_id),true)['result']; if (isset($result['code'])&&$result['code']!=0){ Log::error('订单退款接口调用失败',$result); return $this->response()->error($result['message'])->refresh(); - }else{ - //$orderMain->modifyState($id,$state); } + //$orderMain->modifyState($id,$state); return $this->response()->success($result['message'])->refresh(); + }elseif ($state==3){//接单 + $res = $orderMain->modifyState($id,$state); + if ($res==true){ + $storeIds = ImsCjdcOrder::where('order_main_id',$order->global_order_id)->pluck('store_id')->toArray(); + Rpc::doByOrder($order->user_id,$storeIds,$order->global_order_id,$state); + return $this->response()->success('操作成功')->refresh(); + }else{ + return $this->response()->error('操作失败'); + } } - $res = $orderMain->modifyState($id,$state); - if ($res==true){ - return $this->response()->success('操作成功')->refresh(); - }else{ - return $this->response()->error('操作失败'); - } + } /** diff --git a/app/Admin/Forms/RefundNote.php b/app/Admin/Forms/RefundNote.php index 32ae947..4335ba0 100644 --- a/app/Admin/Forms/RefundNote.php +++ b/app/Admin/Forms/RefundNote.php @@ -2,6 +2,8 @@ namespace App\Admin\Forms; +use App\Admin\Common\Rpc; +use App\Models\ImsCjdcOrder; use App\Models\ImsCjdcOrderMain; use Dcat\Admin\Widgets\Form; use Symfony\Component\HttpFoundation\Response; @@ -20,12 +22,13 @@ class RefundNote extends Form $note = request()->get('refuse_refund_note'); $oid = request()->get('order_id'); $current_page = request()->get('current_page'); - $result = ImsCjdcOrderMain::where('id', $oid)->update([ - 'refuse_refund_note' => $note, - 'state'=>10, - 'updated_at' => time() - ]); - if ($result) { + $order = ImsCjdcOrderMain::where('id', $oid)->first(); + $order->refuse_refund_note = $note; + $order->state = 10; + $order->updated_at = time(); + if ($order->save()) { + $storeIds = ImsCjdcOrder::where('order_main_id',$order->global_order_id)->pluck('store_id')->toArray(); + Rpc::doByOrder($order->user_id,$storeIds,$order->global_order_id,10); return $this->success('操作成功', "order?page={$current_page}"); } else { return $this->error('操作失败');