Express.php 4.2 KB

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