|
|
@@ -18,7 +18,7 @@ class Order extends BaseController
|
|
|
public function adminRefund()
|
|
|
{
|
|
|
$errors = [];
|
|
|
- DB::beginTransaction();
|
|
|
+ Db::startTrans();
|
|
|
try {
|
|
|
$params = $this->request->param();
|
|
|
|
|
|
@@ -66,17 +66,17 @@ class Order extends BaseController
|
|
|
public function refund()
|
|
|
{
|
|
|
$errors = [];
|
|
|
- DB::beginTransaction();
|
|
|
+ Db::startTrans();
|
|
|
try {
|
|
|
$params = $this->request->param();
|
|
|
- $orderId = $params['order_id'];
|
|
|
+ $order_id = $params['order_id'];
|
|
|
$safeWord = $params['safe_word'];
|
|
|
$admin = Admin::where('id', $this->admin_id)->findOrFail();
|
|
|
if (!password_verify($safeWord, $admin->payment_password)) throw new Exception('资金密码错误');
|
|
|
- $order = OrderModel::where('id', $orderId)->findOrFail();
|
|
|
+ $order = OrderModel::where('id', $order_id)->findOrFail();
|
|
|
if (!$order) throw new Exception('订单不存在');
|
|
|
if ($order->return_status != 1 || $order->pay_status != 1) {
|
|
|
- $errors = ['id' => $orderId];
|
|
|
+ $errors = ['id' => $order_id];
|
|
|
throw new Exception("该订单状态无法操作");
|
|
|
}
|
|
|
|
|
|
@@ -97,9 +97,9 @@ class Order extends BaseController
|
|
|
$user->money = $balanceAfter;
|
|
|
$user->save();
|
|
|
|
|
|
- DB::commit();
|
|
|
+ Db::commit();
|
|
|
} catch (Exception $e) {
|
|
|
- DB::rollBack();
|
|
|
+ Db::rollBack();
|
|
|
return $this->error($e->getMessage(), $errors);
|
|
|
}
|
|
|
return $this->success();
|
|
|
@@ -113,12 +113,12 @@ class Order extends BaseController
|
|
|
public function rejection()
|
|
|
{
|
|
|
$errors = [];
|
|
|
- DB::beginTransaction();
|
|
|
+ Db::startTrans();
|
|
|
try {
|
|
|
$params = $this->request->param();
|
|
|
if (empty($params['failure_msg'])) $params['failure_msg'] = '';
|
|
|
|
|
|
- $order = OrderModel::where('id', $params['order_id'])->first();
|
|
|
+ $order = OrderModel::where('id', $params['order_id'])->findOrFail();
|
|
|
if (!$order) throw new Exception('订单不存在');
|
|
|
if ($order->status != 1 || $order->return_status != 1) {
|
|
|
$errors = ['id' => $params['order_id']];
|
|
|
@@ -127,155 +127,71 @@ class Order extends BaseController
|
|
|
$order->return_operation_time = time();
|
|
|
$order->failure_msg = $params['failure_msg'];
|
|
|
$order->save();
|
|
|
- DB::commit();
|
|
|
+ Db::commit();
|
|
|
} catch (Exception $e) {
|
|
|
- DB::rollBack();
|
|
|
+ Db::rollBack();
|
|
|
return $this->error($e->getMessage(), $errors);
|
|
|
}
|
|
|
return $this->success();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @api {get} /order/list 订单列表
|
|
|
- * @apiGroup 订单管理
|
|
|
- * @apiVersion 1.0.0
|
|
|
- * @apiUse header
|
|
|
- * @apiUse lang
|
|
|
- *
|
|
|
- * @apiParam {int} [page=1]
|
|
|
- * @apiParam {int} [limit=15]
|
|
|
- * @apiParam {String} [id] 订单编号
|
|
|
- * @apiParam {String} [user_id] 买家ID
|
|
|
- * @apiParam {String} [store_id] 卖家ID
|
|
|
- * @apiParam {String} [phone] 手机号
|
|
|
- * @apiParam {String} [contacts] 收货人
|
|
|
- * @apiParam {int=0,1} [pay_status] 支付状态 0待支付 1已支付
|
|
|
- * @apiParam {int=0,1} [profit_status] 利润发放 0未发放 1已发放
|
|
|
- * @apiParam {String} [start_time] 开始时间
|
|
|
- * - 格式:`yyyy-mm-dd`
|
|
|
- * @apiParam {String} [end_time] 开始时间
|
|
|
- * - 格式:`yyyy-mm-dd`
|
|
|
- * @apiParam {int=-1,0,1,2,3,4,5,6,7} [type=7] 订单类别
|
|
|
- * - `7 全部订单`,`0 待付款`,`1 已确认`,`2 待发货`,`3 待收货`,`4 已收货`,`5 已评价`,`6 已退款`,`-1 已取消`
|
|
|
- * @apiSuccess {String} id 订单编号
|
|
|
- * @apiSuccess {Object} store 店铺信息
|
|
|
- * @apiSuccess {String} store.user_id 店铺ID
|
|
|
- * @apiSuccess {String} store.seller_name 店铺名
|
|
|
- * @apiSuccess {String} store.seller_img 店铺logo
|
|
|
- * @apiSuccess {String} store.seller_address 店铺地址
|
|
|
- * @apiSuccess {String} contacts 收货人姓名
|
|
|
- * @apiSuccess {String} user_id 买家ID
|
|
|
- * @apiSuccess {String} store_id 卖家ID
|
|
|
- * @apiSuccess {String} total_cost 采购价格
|
|
|
- * @apiSuccess {String} price_count 订单金额
|
|
|
- * @apiSuccess {String} profit 利润
|
|
|
- * @apiSuccess {int} pay_status 支付状态 0待支付 1已支付
|
|
|
- * @apiSuccess {int} status 订单状态
|
|
|
- * - -1 已取消
|
|
|
- * - 0 待付款
|
|
|
- * - 1 待发货
|
|
|
- * - 2 待发货
|
|
|
- * - 3 待收货
|
|
|
- * - 4 已确认
|
|
|
- * - 5 已评价
|
|
|
- *
|
|
|
+ * 订单列表
|
|
|
*/
|
|
|
- public function getList(Request $request)
|
|
|
+ public function list()
|
|
|
{
|
|
|
try {
|
|
|
- $params = request()->validate([
|
|
|
- 'page' => ['nullable', 'integer', 'min:1'],
|
|
|
- 'limit' => ['nullable', 'integer', 'min:1'],
|
|
|
- 'id' => ['nullable', 'string'],
|
|
|
- 'user_id' => ['nullable', 'string'],
|
|
|
- 'store_id' => ['nullable', 'string'],
|
|
|
- 'phone' => ['nullable', 'string'],
|
|
|
- 'contacts' => ['nullable', 'string'],
|
|
|
- 'pay_status' => ['nullable', 'integer', 'in:0,1'],
|
|
|
- 'return_status' => ['nullable', 'integer', 'in:0,1,2,3'],
|
|
|
- 'purchase_status' => ['nullable', 'integer', 'in:0,1,2'],
|
|
|
- 'purchase_amount_status' => ['nullable', 'integer', 'in:0,1'],
|
|
|
- 'profit_status' => ['nullable', 'integer', 'in:0,1'],
|
|
|
- 'status' => ['nullable', 'integer', 'in:0,1,2,3,4,5,6,7,-1'],
|
|
|
- 'start_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:end_time'],
|
|
|
- 'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:start_time'],
|
|
|
- 'order_task_id' => ['nullable', 'string'],
|
|
|
- 'type' => ['nullable', 'integer', 'in:1,2'],
|
|
|
- ]);
|
|
|
- $page = request()->input('page', 1);
|
|
|
- $limit = request()->input('limit', 15);
|
|
|
+ $params = $this->request->param();
|
|
|
+ $page = $this->request->param('page', 1);
|
|
|
+ $limit = $this->request->param('limit', 15);
|
|
|
|
|
|
- $admin_id = $request->user->id;
|
|
|
- if ($admin_id != 1 && Config::adminOpenAllData($admin_id) === false) {
|
|
|
- $user_code = $request->user->user_code;
|
|
|
- $query = OrderModel::leftJoin('users', 'orders.user_id', '=', 'users.user_id')
|
|
|
- ->leftJoin('users as stores', 'orders.store_id', '=', 'stores.user_id')
|
|
|
- ->where(function ($query) use ($user_code){
|
|
|
- $query->where('users.user_code', $user_code)
|
|
|
- ->orWhere('stores.user_code', $user_code);
|
|
|
- });
|
|
|
- } else {
|
|
|
- $query = OrderModel::query();
|
|
|
- }
|
|
|
-
|
|
|
+ $query = new OrderModel();
|
|
|
if (!empty($params['start_time'])) {
|
|
|
- $query = $query->where('orders.created_at', '>=', $params['start_time'] . " 00:00:00")
|
|
|
- ->where('orders.created_at', '<=', $params['end_time'] . " 23:59:59");
|
|
|
+ $startTime = strtotime($params['start_time'] . " 00:00:00");
|
|
|
+ $query = $query->where('create_time', '>=', $startTime);
|
|
|
}
|
|
|
- if (!empty($params['id'])) {
|
|
|
- $query = $query->where('orders.id', $params['id']);
|
|
|
- }
|
|
|
- if (!empty($params['user_id'])) {
|
|
|
- $query = $query->where('orders.user_id', $params['user_id']);
|
|
|
+ if (!empty($params['end_time'])) {
|
|
|
+ $endTime = strtotime($params['end_time'] . " 23:59:59");
|
|
|
+ $query = $query->where('create_time', '<=', $endTime);
|
|
|
}
|
|
|
- if (!empty($params['store_id'])) {
|
|
|
- $query = $query->where('orders.store_id', $params['store_id']);
|
|
|
+ if (!empty($params['id'])) {
|
|
|
+ $query = $query->where('id', $params['id']);
|
|
|
}
|
|
|
- if (!empty($params['phone'])) {
|
|
|
- $query = $query->where('orders.phone', $params['phone']);
|
|
|
+ if (!empty($params['order_id'])) {
|
|
|
+ $query = $query->where('order_id', $params['order_id']);
|
|
|
}
|
|
|
- if (!empty($params['contacts'])) {
|
|
|
- $query = $query->where('orders.contacts', 'like', '%' . $params['contacts'] . '%');
|
|
|
+ if (!empty($params['user_id'])) {
|
|
|
+ $query = $query->where('user_id', $params['user_id']);
|
|
|
}
|
|
|
if (isset($params['status'])) {
|
|
|
- $query = $query->where('orders.status', $params['status']);
|
|
|
+ $query = $query->where('status', $params['status']);
|
|
|
}
|
|
|
if (isset($params['return_status'])) {
|
|
|
- $query = $query->where('orders.return_status', $params['return_status']);
|
|
|
+ $query = $query->where('return_status', $params['return_status']);
|
|
|
}
|
|
|
if (isset($params['pay_status'])) {
|
|
|
- $query = $query->where('orders.pay_status', $params['pay_status']);
|
|
|
- }
|
|
|
- if (isset($params['profit_status'])) {
|
|
|
- $query = $query->where('orders.profit_status', $params['profit_status']);
|
|
|
+ $query = $query->where('pay_status', $params['pay_status']);
|
|
|
}
|
|
|
- if (isset($params['purchase_status'])) {
|
|
|
- $query = $query->where('orders.purchase_status', $params['purchase_status']);
|
|
|
+ if (isset($params['is_win'])) {
|
|
|
+ $query = $query->where('is_win', $params['is_win']);
|
|
|
}
|
|
|
- if (isset($params['purchase_amount_status'])) {
|
|
|
- $query = $query->where('orders.purchase_amount_status', $params['purchase_amount_status']);
|
|
|
+ if (isset($params['settlement_status'])) {
|
|
|
+ $query = $query->where('settlement_status', $params['settlement_status']);
|
|
|
}
|
|
|
- if (!empty($params['order_task_id'])) {
|
|
|
- $query = $query->where('orders.order_task_id', $params['order_task_id']);
|
|
|
- }
|
|
|
- if (!empty($params['type'])) {
|
|
|
- $query = $query->where('orders.type', $params['type']);
|
|
|
+ if (isset($params['is_roll'])) {
|
|
|
+ $query = $query->where('is_roll', $params['is_roll']);
|
|
|
}
|
|
|
|
|
|
$count = $query->count();
|
|
|
- $list = $query->with(['store', 'orderLog'])
|
|
|
- ->select('orders.*')
|
|
|
- ->forPage($page, $limit)
|
|
|
- ->orderByDesc('orders.created_at')
|
|
|
- ->get();
|
|
|
-
|
|
|
-
|
|
|
- } catch (ValidationException $e) {
|
|
|
- return $this->error($e->validator->errors()->first());
|
|
|
+ $list = $query
|
|
|
+ ->limit($limit)
|
|
|
+ ->page($page)
|
|
|
+ ->order('create_time', 'desc')
|
|
|
+ ->select();
|
|
|
} catch (Exception $e) {
|
|
|
return $this->error($e->getMessage());
|
|
|
}
|
|
|
- return $this->success(['count' => $count, 'stateList' => OrderShip::getStateList(), 'list' => $list]);
|
|
|
+ return $this->success(['count' => $count, 'list' => $list]);
|
|
|
|
|
|
}
|
|
|
|
|
|
@@ -283,163 +199,17 @@ class Order extends BaseController
|
|
|
function info()
|
|
|
{
|
|
|
try {
|
|
|
- request()->validate([
|
|
|
- 'order_id' => ['required', 'string', 'min:19', 'max:19'],
|
|
|
- ]);
|
|
|
- $orderId = request()->input('order_id');
|
|
|
- $order = OrderModel::with(['store'])->where('id', $orderId)->first();
|
|
|
+ $order_id = $this->request->param('order_id');
|
|
|
+ $order = OrderModel::where('order_id', $order_id)->findOrFail();
|
|
|
if (!$order) throw new Exception('订单不存在');
|
|
|
$order = $order->toArray();
|
|
|
+ $order['detail'] = json_decode($order['detail'],true);
|
|
|
+ $order['game_result'] = $order['game_result'] ? json_decode($order['game_result'],true) : null;
|
|
|
ksort($order);
|
|
|
-
|
|
|
- //订单的商品列表
|
|
|
- $list = OrderItem::where('order_id', $orderId)
|
|
|
- ->get()->makeHidden(['total_cost', 'system_price', 'profit'])
|
|
|
- ->toArray();
|
|
|
-
|
|
|
- foreach ($list as &$item) {
|
|
|
- $goodsLanguages = GoodsLanguages::where('goods_id', $item['goods_id'])
|
|
|
- ->get()->toArray();
|
|
|
- $goodsLanguages = Util::getDataByLanguageCode($goodsLanguages, $this->lang);
|
|
|
- $item['goods_name'] = $goodsLanguages['name'];
|
|
|
- $sku = GoodsSku::where('sku_id', $item['sku_id'])->first();
|
|
|
- if (empty($sku)) {
|
|
|
- $item['cover_img'] = '';
|
|
|
- $item['attributes'] = [];
|
|
|
- } else {
|
|
|
- $sku = $sku->toArray();
|
|
|
- $item['cover_img'] = $sku['cover_img'];
|
|
|
- $item['attributes'] = AttrValue::getAttr($sku['attr_value_ids'], $this->lang);
|
|
|
- }
|
|
|
- }
|
|
|
- $order['goods'] = $list;
|
|
|
-
|
|
|
- //退款驳回的原因
|
|
|
- $order['failure_msg'] = '';
|
|
|
- if ($order['return_status'] == 3) {
|
|
|
- $order['failure_msg'] = OrderRefund::where('order_id', $orderId)->pluck('failure_msg')->first();
|
|
|
- }
|
|
|
- } catch (ValidationException $e) {
|
|
|
- return $this->error($e->validator->errors()->first());
|
|
|
} catch (Exception $e) {
|
|
|
return $this->error($e->getMessage());
|
|
|
}
|
|
|
- $order['stateList'] = OrderShip::getStateList();
|
|
|
- $order['ship_time'] = OrderShip::where(['order_id' => $orderId, 'state' => 3])->value('created_at');
|
|
|
return $this->success($order);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @api {post} /order/ship 发货
|
|
|
- * @apiGroup 订单管理
|
|
|
- * @apiVersion 1.0.0
|
|
|
- * @apiUse header
|
|
|
- * @apiUse lang
|
|
|
- *
|
|
|
- * @apiParam {String[]} order_id 订单id
|
|
|
- */
|
|
|
- public function ship()
|
|
|
- {
|
|
|
- $errors = [];
|
|
|
- DB::beginTransaction();
|
|
|
- try {
|
|
|
- $params = request()->validate([
|
|
|
- 'order_id' => ['required', 'array', 'min:1'],
|
|
|
- 'order_id.*' => ['string', 'min:19', 'max:19'],
|
|
|
- ]);
|
|
|
- $orderIds = $params['order_id'];
|
|
|
-
|
|
|
- foreach ($orderIds as $orderId) {
|
|
|
- $order = OrderModel::where('id', $orderId)->first();
|
|
|
- if (!$order) continue;
|
|
|
- if ($order->pay_status != 1 ) {
|
|
|
- continue;
|
|
|
- // $errors = ['id' => $orderId];
|
|
|
- // throw new Exception("当前订单未支付");
|
|
|
- }
|
|
|
- if ($order->purchase_status != 1 ) {
|
|
|
- continue;
|
|
|
- // $errors = ['id' => $orderId];
|
|
|
- // throw new Exception("当前订单未采购");
|
|
|
- }
|
|
|
- if ($order->status != 2 ) {
|
|
|
- continue;
|
|
|
- // $errors = ['id' => $orderId];
|
|
|
- // throw new Exception("当前订单未到待发货状态");
|
|
|
- }
|
|
|
- if ($order->return_status != 0 ) {
|
|
|
- continue;
|
|
|
- // $errors = ['id' => $orderId];
|
|
|
- // throw new Exception("当前订单已申请退款");
|
|
|
- }
|
|
|
- $order->status = 3;
|
|
|
- $order->ship_state = 3;
|
|
|
- $order->save();
|
|
|
- OrderLog::addData([
|
|
|
- 'order_id' => $order->id,
|
|
|
- 'state' => 7
|
|
|
- ]);
|
|
|
-
|
|
|
- //记录物流
|
|
|
- OrderShip::addData($order->id, 3);
|
|
|
- }
|
|
|
- DB::commit();
|
|
|
- } catch (ValidationException $e) {
|
|
|
- DB::rollBack();
|
|
|
- return $this->error($e->validator->errors()->first());
|
|
|
- } catch (Exception $e) {
|
|
|
- DB::rollBack();
|
|
|
- return $this->error($e->getMessage(), $errors);
|
|
|
- }
|
|
|
- return $this->success();
|
|
|
- }
|
|
|
-
|
|
|
- public function updateOrderShip()
|
|
|
- {
|
|
|
- try {
|
|
|
-
|
|
|
- $params = request()->validate([
|
|
|
- 'order_id' => ['required', 'string', 'min:19', 'max:19'],
|
|
|
- 'state' => ['required', 'integer', 'in:4,5,6,7,8,9'],
|
|
|
- ]);
|
|
|
- $orderId = $params['order_id'];
|
|
|
- $state = $params['state'];
|
|
|
- $order = OrderModel::where('id', $orderId)->first();
|
|
|
- if (!$order) throw new Exception('订单不存在');
|
|
|
- if ($order->status < 3 ) {
|
|
|
- throw new Exception("当前订单未到已发货状态");
|
|
|
- }
|
|
|
-
|
|
|
- Db::beginTransaction();
|
|
|
- $order->ship_state = $state;
|
|
|
- $order->save();
|
|
|
-
|
|
|
- OrderShip::addData($order->id, $state);
|
|
|
- Db::commit();
|
|
|
- } catch (ValidationException $e) {
|
|
|
- return $this->error($e->validator->errors()->first());
|
|
|
- } catch (Exception $e) {
|
|
|
- Db::rollBack();
|
|
|
- return $this->error($e->getMessage());
|
|
|
- }
|
|
|
- return $this->success();
|
|
|
- }
|
|
|
-
|
|
|
- //查看订单物流
|
|
|
- public function orderShip()
|
|
|
- {
|
|
|
- try {
|
|
|
- $params = request()->validate([
|
|
|
- 'order_id' => ['required', 'string', 'min:19', 'max:19'],
|
|
|
- ]);
|
|
|
- $orderId = $params['order_id'];
|
|
|
-
|
|
|
- $ship = OrderModel::getOrderShip($orderId);
|
|
|
- } catch (ValidationException $e) {
|
|
|
- return $this->error($e->validator->errors()->first());
|
|
|
- } catch (Exception $e) {
|
|
|
- return $this->error($e->getMessage());
|
|
|
- }
|
|
|
- return $this->success($ship);
|
|
|
- }
|
|
|
}
|