diff --git a/app/common/repositories/store/order/StoreOrderRepository.php b/app/common/repositories/store/order/StoreOrderRepository.php index cecfe251..b3203fac 100644 --- a/app/common/repositories/store/order/StoreOrderRepository.php +++ b/app/common/repositories/store/order/StoreOrderRepository.php @@ -785,6 +785,44 @@ class StoreOrderRepository extends BaseRepository event('order.take', compact('order')); } + /** + * @param $id + * @param User $user + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author xaboy + * @day 2020/6/17 + */ + public function takeGoods($id, $orderSn) + { + $order = $this->dao->search([], null)->where('order_sn', $orderSn)->where('order_id', $id)->where('StoreOrder.is_del', 0)->find(); + if (!$order) + throw new ValidateException('订单不存在'); + if ($order['status'] != 1 || $order['order_type']) + throw new ValidateException('订单状态有误'); + $func = 'createUserLog'; + $user = $order->user; + $order->status = 2; + $order->verify_time = date('Y-m-d H:i:s'); + event('order.take.before', compact('order')); + //订单记录 + $storeOrderStatusRepository = app()->make(StoreOrderStatusRepository::class); + $orderStatus = [ + 'order_id' => $order->order_id, + 'order_sn' => $order->order_sn, + 'type' => $storeOrderStatusRepository::TYPE_ORDER, + 'change_message' => '已收货', + 'change_type' => $storeOrderStatusRepository::ORDER_STATUS_TAKE, + ]; + Db::transaction(function () use ($order, $user,$storeOrderStatusRepository,$orderStatus,$func) { + $this->takeAfter($order, $user); + $order->save(); + $storeOrderStatusRepository->{$func}($orderStatus); + }); + event('order.take', compact('order')); + } + /** * 获取订单列表头部统计数据 diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index a4adc669..a58ee5ad 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -72,6 +72,16 @@ class Auth extends BaseController return app('json')->success($logisticsInfo); } + public function takeGoods($id) + { + $orderSn = $this->request->param('order_sn'); + if (empty($orderSn)) { + return app('json')->fail('参数order_sn不能为空'); + } + app()->make(StoreOrderRepository::class)->takeGoods($id, $orderSn); + return app('json')->success('确认收货成功'); + } + public function test() { $type = $this->request->param('type'); diff --git a/route/api.php b/route/api.php index 2b799c24..095c57dc 100644 --- a/route/api.php +++ b/route/api.php @@ -22,6 +22,7 @@ use think\facade\Route; Route::group('api/', function () { Route::any('test', 'api.Auth/test'); Route::any('dotest', 'api.Auth/dotest'); + Route::post('goods/take/:id', 'api.Auth/takeGoods'); Route::resource('upload', 'api.Upload'); Route::post('articleCatch', 'api.Upload/article'); //强制登录