Order.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace app\api\controller\shop;
  3. use app\api\controller\Controller;
  4. use app\api\model\Setting as SettingModel;
  5. use app\common\service\Order as OrderService;
  6. use app\common\enum\OrderType as OrderTypeEnum;
  7. use app\api\model\store\shop\Clerk as ClerkModel;
  8. /**
  9. * 自提订单管理
  10. * Class Order
  11. * @package app\api\controller\shop
  12. */
  13. class Order extends Controller
  14. {
  15. /* @var \app\api\model\User $user */
  16. private $user;
  17. /**
  18. * 构造方法
  19. * @throws \app\common\exception\BaseException
  20. * @throws \think\exception\DbException
  21. */
  22. public function _initialize()
  23. {
  24. parent::_initialize();
  25. $this->user = $this->getUser(); // 用户信息
  26. }
  27. /**
  28. * 核销订单详情
  29. * @param $order_id
  30. * @param int $order_type
  31. * @return array
  32. * @throws \app\common\exception\BaseException
  33. * @throws \think\exception\DbException
  34. */
  35. public function detail($order_id, $order_type = OrderTypeEnum::MASTER)
  36. {
  37. // 订单详情
  38. $model = OrderService::getOrderDetail($order_id, $order_type);
  39. // 验证是否为该门店的核销员
  40. $clerkModel = ClerkModel::detail(['user_id' => $this->user['user_id']]);
  41. return $this->renderSuccess([
  42. 'order' => $model, // 订单详情
  43. 'clerkModel' => $clerkModel,
  44. 'setting' => [
  45. // 积分名称
  46. 'points_name' => SettingModel::getPointsName(),
  47. ],
  48. ]);
  49. }
  50. /**
  51. * 确认核销
  52. * @param $order_id
  53. * @param int $order_type
  54. * @return array
  55. * @throws \app\common\exception\BaseException
  56. * @throws \think\exception\DbException
  57. */
  58. public function extract($order_id, $order_type = OrderTypeEnum::MASTER)
  59. {
  60. // 订单详情
  61. $order = OrderService::getOrderDetail($order_id, $order_type);
  62. // 验证是否为该门店的核销员
  63. $ClerkModel = ClerkModel::detail(['user_id' => $this->user['user_id']]);
  64. if (!$ClerkModel->checkUser($order['extract_shop_id'])) {
  65. return $this->renderError($ClerkModel->getError());
  66. }
  67. // 确认核销
  68. if ($order->verificationOrder($ClerkModel['clerk_id'])) {
  69. return $this->renderSuccess([], '订单核销成功');
  70. }
  71. return $this->renderError($order->getError() ?: '核销失败');
  72. }
  73. }