Express.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * @package merchant
  4. * @Author: Qinii
  5. * @Date: 2020/5/13
  6. */
  7. namespace app\controller\admin\store;
  8. use think\App;
  9. use crmeb\basic\BaseController;
  10. use app\common\repositories\store\shipping\ExpressRepository as repository;
  11. class Express extends BaseController
  12. {
  13. /**
  14. * @var repository
  15. */
  16. protected $repository;
  17. /**
  18. * City constructor.
  19. * @param App $app
  20. * @param repository $repository
  21. */
  22. public function __construct(App $app, repository $repository)
  23. {
  24. parent::__construct($app);
  25. $this->repository = $repository;
  26. }
  27. /**
  28. * @Author:Qinii
  29. * @Date: 2020/5/13
  30. * @return mixed
  31. */
  32. public function lst()
  33. {
  34. [$page , $limit] = $this->getPage();
  35. $where = $this->request->params(['name','code']);
  36. return app('json')->success($this->repository->search($where, $page, $limit));
  37. }
  38. public function detail($id)
  39. {
  40. return app('json')->success($this->repository->get($id));
  41. }
  42. /**
  43. * @Author:Qinii
  44. * @Date: 2020/5/13
  45. * @return mixed
  46. */
  47. public function create()
  48. {
  49. $data = $this->request->params(['name','code','is_show','sort']);
  50. if(empty($data['name']))
  51. return app('json')->fail('名称不可为空');
  52. if($this->repository->codeExists($data['code'],null))
  53. return app('json')->fail('编码重复');
  54. if($this->repository->nameExists($data['name'],null))
  55. return app('json')->fail('名称重复');
  56. $this->repository->create($data);
  57. return app('json')->success('添加成功');
  58. }
  59. /**
  60. * @Author:Qinii
  61. * @Date: 2020/5/13
  62. * @param $id
  63. * @return mixed
  64. */
  65. public function update($id)
  66. {
  67. $data = $this->request->params(['name','code','is_show','sort']);
  68. if(!$this->repository->fieldExists($id))
  69. return app('json')->fail('数据不存在');
  70. if(empty($data['name']))
  71. return app('json')->fail('名称不可为空');
  72. if($this->repository->codeExists($data['code'],$id))
  73. return app('json')->fail('编码重复');
  74. if($this->repository->nameExists($data['name'],$id))
  75. return app('json')->fail('名称重复');
  76. $this->repository->update($id,$data);
  77. return app('json')->success('编辑成功');
  78. }
  79. /**
  80. * @Author:Qinii
  81. * @Date: 2020/5/13
  82. * @param $id
  83. * @return mixed
  84. */
  85. public function delete($id)
  86. {
  87. if(!$this->repository->fieldExists($id))
  88. return app('json')->fail('数据不存在');
  89. $this->repository->delete($id);
  90. return app('json')->success('删除成功');
  91. }
  92. /**
  93. * @Author:Qinii
  94. * @Date: 2020/5/22
  95. * @return mixed
  96. */
  97. public function createForm()
  98. {
  99. return app('json')->success(formToData($this->repository->form($this->request->merId())));
  100. }
  101. /**
  102. * @Author:Qinii
  103. * @Date: 2020/5/22
  104. * @param $id
  105. * @return mixed
  106. */
  107. public function updateForm($id)
  108. {
  109. if(!$this->repository->fieldExists($id))
  110. return app('json')->fail('数据不存在');
  111. return app('json')->success(formToData($this->repository->updateForm($this->request->merId(),$id)));
  112. }
  113. /**
  114. * @Author:Qinii
  115. * @Date: 2020/5/22
  116. * @param int $id
  117. * @return mixed
  118. */
  119. public function switchStatus($id)
  120. {
  121. $status = $this->request->param('is_show', 0) == 1 ? 1 : 0;
  122. if(!$this->repository->fieldExists($id))
  123. return app('json')->fail('数据不存在');
  124. $this->repository->switchStatus($id, ['is_show' =>$status]);
  125. return app('json')->success('修改成功');
  126. }
  127. }