DeliveryOrder.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\merchant\store\delivery;
  12. use app\common\repositories\delivery\DeliveryOrderRepository;
  13. use app\common\repositories\system\serve\ServeOrderRepository;
  14. use think\App;
  15. use crmeb\basic\BaseController;
  16. use think\exception\ValidateException;
  17. class DeliveryOrder extends BaseController
  18. {
  19. protected $repository;
  20. /**
  21. * 构造函数
  22. *
  23. * @param App $app 应用实例
  24. * @param DeliveryOrderRepository $repository 配送订单仓库实例
  25. */
  26. public function __construct(App $app, DeliveryOrderRepository $repository)
  27. {
  28. // 调用父类构造函数
  29. parent::__construct($app);
  30. // 初始化配送订单仓库实例
  31. $this->repository = $repository;
  32. // 判断同城配送是否开启
  33. if (systemConfig('delivery_status') != 1) throw new ValidateException('未开启同城配送');
  34. }
  35. /**
  36. * 获取配送订单列表
  37. *
  38. * @return \think\response\Json
  39. */
  40. public function lst()
  41. {
  42. // 获取分页参数
  43. [$page, $limit] = $this->getPage();
  44. $where = $this->request->params(['keyword', 'station_id', 'status', 'date', 'order_sn', 'station_type']);
  45. // 添加商家ID条件
  46. $where['mer_id'] = $this->request->merId();
  47. // 获取配送订单列表
  48. $data = $this->repository->merList($where, $page, $limit);
  49. // 返回成功响应
  50. return app('json')->success($data);
  51. }
  52. /**
  53. * 获取配送订单详情
  54. *
  55. * @param int $id 配送订单ID
  56. * @return \think\response\Json
  57. */
  58. public function detail($id)
  59. {
  60. $data = $this->repository->detail($id, $this->request->merId());
  61. // 返回成功响应
  62. return app('json')->success($data);
  63. }
  64. /**
  65. * 取消配送订单
  66. *
  67. * @param int $id 配送订单ID
  68. * @return \think\response\Json
  69. */
  70. public function cancelForm($id)
  71. {
  72. // 转换表单数据为数组并取消配送订单
  73. return app('json')->success(formToData($this->repository->cancelForm($id)));
  74. }
  75. /**
  76. * 取消操作
  77. * @param int $id 订单ID
  78. * @return \think\response\Json 返回JSON格式的结果
  79. */
  80. public function cancel($id)
  81. {
  82. $reason = $this->request->params(['reason', 'cancel_reason']);
  83. // 判断取消理由是否为空
  84. if (empty($reason['reason']))
  85. return app('json')->fail('取消理由不能为空');
  86. // 调用仓库的取消方法
  87. $this->repository->cancel($id, $this->request->merId(), $reason);
  88. // 返回成功结果
  89. return app('json')->success('取消成功');
  90. }
  91. /**
  92. * 删除操作
  93. * @param int $id 订单ID
  94. * @return \think\response\Json 返回JSON格式的结果
  95. */
  96. public function delete($id)
  97. {
  98. // 调用仓库的删除方法
  99. $this->repository->destory($id, $this->request->merId());
  100. return app('json')->success('删除成功');
  101. }
  102. /**
  103. * 切换状态操作
  104. * @param int $id 订单ID
  105. * @return \think\response\Json 返回JSON格式的结果
  106. */
  107. public function switchWithStatus($id)
  108. {
  109. // 获取状态值
  110. $status = $this->request->param('status') == 1 ? 1 : 0;
  111. $this->repository->update($id, ['status' => $status]);
  112. return app('json')->success('修改成功');
  113. }
  114. }