ShippingTemplate.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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\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. /**
  19. * Class ShippingTemplate
  20. * app\controller\api\server
  21. * 移动端客服运费模板管理
  22. */
  23. class ShippingTemplate extends BaseController
  24. {
  25. protected $merId;
  26. protected $repository;
  27. public function __construct(App $app, ShippingTemplateRepository $repository)
  28. {
  29. parent::__construct($app);
  30. $this->repository = $repository;
  31. $this->merId = $this->request->route('merId');
  32. }
  33. /**
  34. * 列表 - 下啦筛选
  35. * @return \think\response\Json
  36. * @author Qinii
  37. * @day 8/24/21
  38. */
  39. public function lst()
  40. {
  41. [$page, $limit] = $this->getPage();
  42. $where = $this->request->params(['type','name']);
  43. return app('json')->success($this->repository->search($this->merId, $where, $page, $limit));
  44. }
  45. /**
  46. * 列表
  47. * @return \think\response\Json
  48. * @author Qinii
  49. * @day 8/24/21
  50. */
  51. public function getList()
  52. {
  53. return app('json')->success($this->repository->getList($this->merId));
  54. }
  55. /**
  56. * 创建
  57. * @param ShippingTemplateValidate $validate
  58. * @return \think\response\Json
  59. * @author Qinii
  60. * @day 8/24/21
  61. */
  62. public function create(ShippingTemplateValidate $validate)
  63. {
  64. $data = $this->checkParams($validate);
  65. $data['mer_id'] = $this->merId;
  66. $this->repository->create($data);
  67. return app('json')->success('添加成功');
  68. }
  69. /**
  70. * 详情
  71. * @param $id
  72. * @return \think\response\Json
  73. * @author Qinii
  74. * @day 8/24/21
  75. */
  76. public function detail($id)
  77. {
  78. if(!$this->repository->merExists($this->merId,$id))
  79. return app('json')->fail('数据不存在');
  80. return app('json')->success($this->repository->getOne($id,1));
  81. }
  82. /**
  83. * 编辑
  84. * @param $id
  85. * @param ShippingTemplateValidate $validate
  86. * @return \think\response\Json
  87. * @author Qinii
  88. * @day 8/24/21
  89. */
  90. public function update($id, ShippingTemplateValidate $validate)
  91. {
  92. $data = $this->checkParams($validate);
  93. if(!$this->repository->merExists($this->merId,$id))
  94. return app('json')->fail('数据不存在');
  95. $this->repository->update($id,$data, $this->merId);
  96. return app('json')->success('编辑成功');
  97. }
  98. /**
  99. * 删除
  100. * @param $id
  101. * @return \think\response\Json
  102. * @author Qinii
  103. * @day 8/24/21
  104. */
  105. public function batchDelete()
  106. {
  107. $ids = $this->request->param('ids');
  108. foreach ($ids as $id) {
  109. $this->repository->check($this->merId, $id);
  110. }
  111. $this->repository->delete($ids);
  112. return app('json')->success('删除成功');
  113. }
  114. /**
  115. * 参数验证
  116. * @param ShippingTemplateValidate $validate
  117. * @return array
  118. * @author Qinii
  119. * @day 8/24/21
  120. */
  121. public function checkParams(ShippingTemplateValidate $validate)
  122. {
  123. $data = $this->request->params(['name','type','appoint','undelivery','region','free','undelives','sort','info']);
  124. $validate->check($data);
  125. return $data;
  126. }
  127. }