ShippingTemplate.php 4.0 KB

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