Express.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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\admin\store;
  12. use crmeb\jobs\ExpressSyncJob;
  13. use think\App;
  14. use crmeb\basic\BaseController;
  15. use app\common\repositories\store\shipping\ExpressRepository as repository;
  16. use think\facade\Queue;
  17. class Express extends BaseController
  18. {
  19. /**
  20. * @var repository
  21. */
  22. protected $repository;
  23. /**
  24. * City constructor.
  25. * @param App $app
  26. * @param repository $repository
  27. */
  28. public function __construct(App $app, repository $repository)
  29. {
  30. parent::__construct($app);
  31. $this->repository = $repository;
  32. }
  33. /**
  34. * @Author:Qinii
  35. * @Date: 2020/5/13
  36. * @return mixed
  37. */
  38. public function lst()
  39. {
  40. [$page , $limit] = $this->getPage();
  41. $where = $this->request->params(['keyword','code']);
  42. $mer_id = $this->request->merId();
  43. if($mer_id) $where['is_show'] = 1;
  44. return app('json')->success($this->repository->search($where, $page, $limit));
  45. }
  46. public function detail($id)
  47. {
  48. return app('json')->success($this->repository->get($id));
  49. }
  50. /**
  51. * @Author:Qinii
  52. * @Date: 2020/5/13
  53. * @return mixed
  54. */
  55. public function create()
  56. {
  57. $data = $this->request->params(['name','code','is_show','sort']);
  58. if(empty($data['name']))
  59. return app('json')->fail('名称不可为空');
  60. if($this->repository->codeExists($data['code'],null))
  61. return app('json')->fail('编码重复');
  62. if($this->repository->nameExists($data['name'],null))
  63. return app('json')->fail('名称重复');
  64. $this->repository->create($data);
  65. return app('json')->success('添加成功');
  66. }
  67. /**
  68. * @Author:Qinii
  69. * @Date: 2020/5/13
  70. * @param $id
  71. * @return mixed
  72. */
  73. public function update($id)
  74. {
  75. $data = $this->request->params(['name','code','is_show','sort']);
  76. if(!$this->repository->fieldExists($id))
  77. return app('json')->fail('数据不存在');
  78. if(empty($data['name']))
  79. return app('json')->fail('名称不可为空');
  80. if($this->repository->codeExists($data['code'],$id))
  81. return app('json')->fail('编码重复');
  82. if($this->repository->nameExists($data['name'],$id))
  83. return app('json')->fail('名称重复');
  84. $this->repository->update($id,$data);
  85. return app('json')->success('编辑成功');
  86. }
  87. /**
  88. * @Author:Qinii
  89. * @Date: 2020/5/13
  90. * @param $id
  91. * @return mixed
  92. */
  93. public function delete($id)
  94. {
  95. if(!$this->repository->fieldExists($id))
  96. return app('json')->fail('数据不存在');
  97. $this->repository->delete($id);
  98. return app('json')->success('删除成功');
  99. }
  100. /**
  101. * @Author:Qinii
  102. * @Date: 2020/5/22
  103. * @return mixed
  104. */
  105. public function createForm()
  106. {
  107. return app('json')->success(formToData($this->repository->form($this->request->merId())));
  108. }
  109. /**
  110. * @Author:Qinii
  111. * @Date: 2020/5/22
  112. * @param $id
  113. * @return mixed
  114. */
  115. public function updateForm($id)
  116. {
  117. if(!$this->repository->fieldExists($id))
  118. return app('json')->fail('数据不存在');
  119. return app('json')->success(formToData($this->repository->updateForm($this->request->merId(),$id)));
  120. }
  121. /**
  122. * @Author:Qinii
  123. * @Date: 2020/5/22
  124. * @param int $id
  125. * @return mixed
  126. */
  127. public function switchStatus($id)
  128. {
  129. $status = $this->request->param('is_show', 0) == 1 ? 1 : 0;
  130. if(!$this->repository->fieldExists($id))
  131. return app('json')->fail('数据不存在');
  132. $this->repository->switchStatus($id, ['is_show' =>$status]);
  133. return app('json')->success('修改成功');
  134. }
  135. /**
  136. * TODO 同步信息
  137. * @return \think\response\Json
  138. * @author Qinii
  139. * @day 7/23/21
  140. */
  141. public function syncAll()
  142. {
  143. Queue::push(ExpressSyncJob::class,[]);
  144. return app('json')->success('后台同步中,请稍后来查看~');
  145. }
  146. public function partnerForm($id)
  147. {
  148. $merId = $this->request->merId();
  149. return app('json')->success(formToData($this->repository->partnerForm($id,$merId)));
  150. }
  151. public function partner($id)
  152. {
  153. $data = $this->request->params(['account','key','net_name']);
  154. if (!$expressInfo = $this->repository->get($id))
  155. return app('json')->fail('编辑的记录不存在!');
  156. if ($expressInfo['partner_id'] == 1 && !$data['account'])
  157. return app('json')->fail('请输入月结账号');
  158. if ($expressInfo['partner_key'] == 1 && !$data['key'])
  159. return app('json')->fail('请输入月结密码');
  160. if ($expressInfo['net'] == 1 && !$data['net_name'])
  161. return app('json')->fail('请输入取件网点');
  162. if ($expressInfo['check_man'] == 1 && !$data['check_man'])
  163. return app('json')->fail('请输入承载快递员名称');
  164. if ($expressInfo['partner_name'] == 1 && !$data['partner_name'])
  165. return app('json')->fail('请输入客户账户名称');
  166. if ($expressInfo['is_code'] == 1 && !$data['code'])
  167. return app('json')->fail('请输入承载编号');
  168. $data['express_id'] = $id;
  169. $data['mer_id'] = $this->request->merId();
  170. $this->repository->updatePartne($data);
  171. return app('json')->success('修改成功');
  172. }
  173. public function options()
  174. {
  175. return app('json')->success($this->repository->options());
  176. }
  177. }