ShippingTemplate.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. // 目前只包邮
  47. return app('json')->success($this->repository->getList(0));
  48. }
  49. /**
  50. * @Author:Qinii
  51. * @Date: 2020/5/8
  52. * @Time: 14:39
  53. * @param validate $validate
  54. * @return mixed
  55. */
  56. public function create(validate $validate)
  57. {
  58. $data = $this->checkParams($validate);
  59. $data['mer_id'] = $this->request->merId();
  60. $this->repository->create($data);
  61. return app('json')->success('添加成功');
  62. }
  63. /**
  64. * @Author:Qinii
  65. * @Date: 2020/5/8
  66. * @Time: 14:39
  67. * @param $id
  68. * @return mixed
  69. */
  70. public function detail($id)
  71. {
  72. if(!$this->repository->merExists($this->request->merId(),$id))
  73. return app('json')->fail('数据不存在');
  74. return app('json')->success($this->repository->getOne($id));
  75. }
  76. /**
  77. * @Author:Qinii
  78. * @Date: 2020/5/8
  79. * @Time: 14:39
  80. * @param $id
  81. * @param validate $validate
  82. * @return mixed
  83. */
  84. public function update($id,validate $validate)
  85. {
  86. $data = $this->checkParams($validate);
  87. if(!$this->repository->merExists($this->request->merId(),$id))
  88. return app('json')->fail('数据不存在');
  89. $this->repository->update($id,$data,$this->request->merId());
  90. return app('json')->success('编辑成功');
  91. }
  92. /**
  93. * @Author:Qinii
  94. * @Date: 2020/5/8
  95. * @Time: 14:39
  96. * @param $id
  97. * @return mixed
  98. */
  99. public function delete($id)
  100. {
  101. if(!$this->repository->merExists($this->request->merId(),$id))
  102. return app('json')->fail('数据不存在');
  103. if($this->repository->merDefaultExists($this->request->merId(),$id))
  104. return app('json')->fail('默认模板不能删除');
  105. if($this->repository->getProductUse($this->request->merId(),$id))
  106. return app('json')->fail('模板使用中,不能删除');
  107. $this->repository->delete($id);
  108. return app('json')->success('删除成功');
  109. }
  110. /**
  111. * @Author:Qinii
  112. * @Date: 2020/5/8
  113. * @Time: 14:39
  114. * @param validate $validate
  115. * @return array
  116. */
  117. public function checkParams(validate $validate)
  118. {
  119. $data = $this->request->params(['name','type','appoint','undelivery','region','free','undelives','sort']);
  120. $validate->check($data);
  121. return $data;
  122. }
  123. }