ShippingTemplate.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /**
  3. * @package merchant
  4. * @Author: Qinii
  5. * @Date: 2020/5/6
  6. * @Time: 14:37
  7. */
  8. namespace app\controller\merchant\store\shipping;
  9. use think\App;
  10. use crmeb\basic\BaseController;
  11. use app\validate\merchant\ShippingTemplateValidate as validate;
  12. use app\common\repositories\store\shipping\ShippingTemplateRepository as repository;
  13. class ShippingTemplate extends BaseController
  14. {
  15. protected $repository;
  16. /**
  17. * ShippingTemplate constructor.
  18. * @param App $app
  19. * @param repository $repository
  20. */
  21. public function __construct(App $app, repository $repository)
  22. {
  23. parent::__construct($app);
  24. $this->repository = $repository;
  25. }
  26. /**
  27. * @Author:Qinii
  28. * @Date: 2020/5/8
  29. * @Time: 14:39
  30. * @return mixed
  31. */
  32. public function lst()
  33. {
  34. [$page, $limit] = $this->getPage();
  35. $where = $this->request->params(['type','name']);
  36. return app('json')->success($this->repository->search($this->request->merId(),$where, $page, $limit));
  37. }
  38. /**
  39. * @Author:Qinii
  40. * @Date: 2020/5/18
  41. * @return mixed
  42. */
  43. public function getList()
  44. {
  45. return app('json')->success($this->repository->getList($this->request->merId()));
  46. // return app('json')->success($this->repository->getList(0)); 取消硬编码
  47. }
  48. /**
  49. * @Author:Qinii
  50. * @Date: 2020/5/8
  51. * @Time: 14:39
  52. * @param validate $validate
  53. * @return mixed
  54. */
  55. public function create(validate $validate)
  56. {
  57. $data = $this->checkParams($validate);
  58. $data['mer_id'] = $this->request->merId();
  59. $this->repository->create($data);
  60. return app('json')->success('添加成功');
  61. }
  62. /**
  63. * @Author:Qinii
  64. * @Date: 2020/5/8
  65. * @Time: 14:39
  66. * @param $id
  67. * @return mixed
  68. */
  69. public function detail($id)
  70. {
  71. if(!$this->repository->merExists($this->request->merId(),$id))
  72. return app('json')->fail('数据不存在');
  73. return app('json')->success($this->repository->getOne($id));
  74. }
  75. /**
  76. * @Author:Qinii
  77. * @Date: 2020/5/8
  78. * @Time: 14:39
  79. * @param $id
  80. * @param validate $validate
  81. * @return mixed
  82. */
  83. public function update($id,validate $validate)
  84. {
  85. $data = $this->checkParams($validate);
  86. if(!$this->repository->merExists($this->request->merId(),$id))
  87. return app('json')->fail('数据不存在');
  88. $this->repository->update($id,$data,$this->request->merId());
  89. return app('json')->success('编辑成功');
  90. }
  91. /**
  92. * @Author:Qinii
  93. * @Date: 2020/5/8
  94. * @Time: 14:39
  95. * @param $id
  96. * @return mixed
  97. */
  98. public function delete($id)
  99. {
  100. if(!$this->repository->merExists($this->request->merId(),$id))
  101. return app('json')->fail('数据不存在');
  102. if($this->repository->merDefaultExists($this->request->merId(),$id))
  103. return app('json')->fail('默认模板不能删除');
  104. if($this->repository->getProductUse($this->request->merId(),$id))
  105. return app('json')->fail('模板使用中,不能删除');
  106. $this->repository->delete($id);
  107. return app('json')->success('删除成功');
  108. }
  109. /**
  110. * @Author:Qinii
  111. * @Date: 2020/5/8
  112. * @Time: 14:39
  113. * @param validate $validate
  114. * @return array
  115. */
  116. public function checkParams(validate $validate)
  117. {
  118. $data = $this->request->params(['name','type','appoint','undelivery','region','free','undelives','sort']);
  119. $validate->check($data);
  120. return $data;
  121. }
  122. }