ShippingTemplate.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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\api\server;
  12. use think\App;
  13. use crmeb\basic\BaseController;
  14. use think\exception\HttpResponseException;
  15. use app\validate\merchant\ShippingTemplateValidate;
  16. use app\common\repositories\store\service\StoreServiceRepository;
  17. use app\common\repositories\store\shipping\ShippingTemplateRepository;
  18. class ShippingTemplate extends BaseController
  19. {
  20. protected $merId;
  21. protected $repository;
  22. public function __construct(App $app, ShippingTemplateRepository $repository)
  23. {
  24. parent::__construct($app);
  25. $this->repository = $repository;
  26. $this->merId = $this->request->route('merId');
  27. }
  28. /**
  29. * TODO
  30. * @return \think\response\Json
  31. * @author Qinii
  32. * @day 8/24/21
  33. */
  34. public function lst()
  35. {
  36. [$page, $limit] = $this->getPage();
  37. $where = $this->request->params(['type','name']);
  38. return app('json')->success($this->repository->search($this->merId, $where, $page, $limit));
  39. }
  40. /**
  41. * TODO
  42. * @return \think\response\Json
  43. * @author Qinii
  44. * @day 8/24/21
  45. */
  46. public function getList()
  47. {
  48. return app('json')->success($this->repository->getList($this->merId));
  49. }
  50. /**
  51. * TODO
  52. * @param ShippingTemplateValidate $validate
  53. * @return \think\response\Json
  54. * @author Qinii
  55. * @day 8/24/21
  56. */
  57. public function create(ShippingTemplateValidate $validate)
  58. {
  59. $data = $this->checkParams($validate);
  60. $data['mer_id'] = $this->merId;
  61. $this->repository->create($data);
  62. return app('json')->success('添加成功');
  63. }
  64. /**
  65. * TODO
  66. * @param $id
  67. * @return \think\response\Json
  68. * @author Qinii
  69. * @day 8/24/21
  70. */
  71. public function detail($id)
  72. {
  73. if(!$this->repository->merExists($this->merId,$id))
  74. return app('json')->fail('数据不存在');
  75. return app('json')->success($this->repository->getOne($id,1));
  76. }
  77. /**
  78. * TODO
  79. * @param $id
  80. * @param ShippingTemplateValidate $validate
  81. * @return \think\response\Json
  82. * @author Qinii
  83. * @day 8/24/21
  84. */
  85. public function update($id, ShippingTemplateValidate $validate)
  86. {
  87. $data = $this->checkParams($validate);
  88. if(!$this->repository->merExists($this->merId,$id))
  89. return app('json')->fail('数据不存在');
  90. $this->repository->update($id,$data, $this->merId);
  91. return app('json')->success('编辑成功');
  92. }
  93. /**
  94. * TODO
  95. * @param $id
  96. * @return \think\response\Json
  97. * @author Qinii
  98. * @day 8/24/21
  99. */
  100. public function batchDelete()
  101. {
  102. $ids = $this->request->param('ids');
  103. foreach ($ids as $id) {
  104. $this->repository->check($this->merId, $id);
  105. }
  106. $this->repository->delete($ids);
  107. return app('json')->success('删除成功');
  108. }
  109. /**
  110. * TODO
  111. * @param ShippingTemplateValidate $validate
  112. * @return array
  113. * @author Qinii
  114. * @day 8/24/21
  115. */
  116. public function checkParams(ShippingTemplateValidate $validate)
  117. {
  118. $data = $this->request->params(['name','type','appoint','undelivery','region','free','undelives','sort','info']);
  119. $validate->check($data);
  120. return $data;
  121. }
  122. }