Order.php 2.5 KB

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