DeliveryService.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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\DeliveryServiceRepository;
  13. use app\common\repositories\system\serve\ServeOrderRepository;
  14. use app\validate\merchant\DeliveryServiceValidate;
  15. use crmeb\services\DeliverySevices;
  16. use think\App;
  17. use crmeb\basic\BaseController;
  18. use app\validate\merchant\DeliveryStationValidate;
  19. use think\exception\ValidateException;
  20. class DeliveryService extends BaseController
  21. {
  22. protected $repository;
  23. public function __construct(App $app, DeliveryServiceRepository $repository)
  24. {
  25. parent::__construct($app);
  26. $this->repository = $repository;
  27. }
  28. /**
  29. * 列表
  30. * @return \think\response\Json
  31. * @author Qinii
  32. */
  33. public function lst()
  34. {
  35. [$page, $limit] = $this->getPage();
  36. $where = $this->request->params(['keyword','status','type','date']);
  37. $where['mer_id'] = $this->request->merId();
  38. $data = $this->repository->getList($where, $page, $limit);
  39. return app('json')->success($data);
  40. }
  41. /**
  42. * 详情
  43. * @param $id
  44. * @return \think\response\Json
  45. * @author Qinii
  46. */
  47. public function detail($id)
  48. {
  49. $data = $this->repository->detail($id,$this->request->merId());
  50. return app('json')->success($data);
  51. }
  52. /**
  53. * 添加表单
  54. * @return \think\response\Json
  55. * @author Qinii
  56. */
  57. public function createForm()
  58. {
  59. $form = $this->repository->form(null);
  60. return app('json')->success(formToData($form));
  61. }
  62. /**
  63. * 编辑表单
  64. * @param $id
  65. * @return \think\response\Json
  66. * @author Qinii
  67. */
  68. public function updateForm($id)
  69. {
  70. $form = $this->repository->form($id);
  71. return app('json')->success(formToData($form));
  72. }
  73. /**
  74. * 添加
  75. * @return \think\response\Json
  76. * @author Qinii
  77. */
  78. public function create()
  79. {
  80. $data = $this->checkParams();
  81. $data['mer_id'] = $this->request->merId();
  82. $this->repository->create($data);
  83. return app('json')->success('添加成功');
  84. }
  85. /**
  86. * 编辑
  87. * @param $id
  88. * @return \think\response\Json
  89. * @author Qinii
  90. */
  91. public function update($id)
  92. {
  93. $data = $this->checkParams();
  94. $this->repository->update($id, $data);
  95. return app('json')->success('编辑成功');
  96. }
  97. /**
  98. * 删除
  99. * @param $id
  100. * @return \think\response\Json
  101. * @author Qinii
  102. */
  103. public function delete($id)
  104. {
  105. $getOne = $this->repository->getWhere(['service_id' => $id, 'mer_id' => $this->request->merId()]);
  106. if (!$getOne){
  107. return app('json')->fail('该配送员不存在或不属于您的商户,无法删除');
  108. }
  109. $this->repository->delete($id);
  110. return app('json')->success('删除成功');
  111. }
  112. /**
  113. * 根据ID切换服务状态
  114. * @param int $id 服务ID
  115. * @return \think\response\Json
  116. */
  117. public function switchWithStatus($id)
  118. {
  119. // 获取请求参数中的状态值,如果没有则默认为0
  120. $status = $this->request->param('status') == 1 ? 1 : 0;
  121. // 根据条件查询服务信息
  122. $getOne = $this->repository->getWhere(['service_id' => $id, 'mer_id' => $this->request->merId()]);
  123. // 如果查询结果为空,则返回错误信息
  124. if (!$getOne) return app('json')->fail('数据不存在');
  125. // 更新服务状态
  126. $this->repository->update($id, ['status' => $status]);
  127. // 返回成功信息
  128. return app('json')->success('修改成功');
  129. }
  130. /**
  131. * 检查请求参数
  132. * @return array
  133. */
  134. public function checkParams()
  135. {
  136. // 从请求参数中获取头像、姓名、电话和状态信息
  137. $data = $this->request->params(['avatar', 'name', 'phone', 'status']);
  138. // 使用DeliveryServiceValidate类对数据进行校验
  139. app()->make(DeliveryServiceValidate::class)->check($data);
  140. // 返回校验后的数据
  141. return $data;
  142. }
  143. /**
  144. * 配送员所有下啦筛选
  145. * @return \think\response\Json
  146. * @author Qinii
  147. */
  148. public function options()
  149. {
  150. $where = [
  151. 'status' => 1,
  152. 'mer_id' => $this->request->merId(),
  153. ];
  154. return app('json')->success($this->repository->getOptions($where));
  155. }
  156. }