Express.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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\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. /**
  18. * 快递公司
  19. */
  20. class Express extends BaseController
  21. {
  22. /**
  23. * @var repository
  24. */
  25. protected $repository;
  26. /**
  27. * City constructor.
  28. * @param App $app
  29. * @param repository $repository
  30. */
  31. public function __construct(App $app, repository $repository)
  32. {
  33. parent::__construct($app);
  34. $this->repository = $repository;
  35. }
  36. /**
  37. * 列表
  38. * @Author:Qinii
  39. * @Date: 2020/5/13
  40. * @return mixed
  41. */
  42. public function lst()
  43. {
  44. [$page, $limit] = $this->getPage();
  45. $where = $this->request->params(['keyword', 'code']);
  46. $mer_id = $this->request->merId();
  47. if ($mer_id) $where['is_show'] = 1;
  48. return app('json')->success($this->repository->search($where, $page, $limit, $mer_id));
  49. }
  50. /**
  51. * 商户修改状态
  52. *
  53. * @param [type] $id
  54. * @return void
  55. */
  56. public function merStatus($id)
  57. {
  58. $merStatus = $this->request->param('mer_status');
  59. if(!in_array($merStatus,['0', '1'])) {
  60. return app('json')->fail('参数错误');
  61. }
  62. $merId = $this->request->merId();
  63. if(!$merId) {
  64. return app('json')->fail('商户不存在');
  65. }
  66. return app('json')->success('修改成功', $this->repository->changeMerStatus($id, $merStatus, $merId));
  67. }
  68. /**
  69. * 详情
  70. * @param $id
  71. * @return \think\response\Json
  72. * @author Qinii
  73. */
  74. public function detail($id)
  75. {
  76. return app('json')->success($this->repository->get($id));
  77. }
  78. /**
  79. * 添加
  80. * @Author:Qinii
  81. * @Date: 2020/5/13
  82. * @return mixed
  83. */
  84. public function create()
  85. {
  86. $data = $this->request->params(['name', 'code', 'is_show', 'sort']);
  87. if (empty($data['name']))
  88. return app('json')->fail('名称不可为空');
  89. if ($this->repository->codeExists($data['code'], null))
  90. return app('json')->fail('编码重复');
  91. if ($this->repository->nameExists($data['name'], null))
  92. return app('json')->fail('名称重复');
  93. $this->repository->create($data);
  94. return app('json')->success('添加成功');
  95. }
  96. /**
  97. * 编辑
  98. * @Author:Qinii
  99. * @Date: 2020/5/13
  100. * @param $id
  101. * @return mixed
  102. */
  103. public function update($id)
  104. {
  105. $data = $this->request->params(['name', 'code', 'is_show', 'sort']);
  106. if (!$this->repository->fieldExists($id))
  107. return app('json')->fail('数据不存在');
  108. if (empty($data['name']))
  109. return app('json')->fail('名称不可为空');
  110. if ($this->repository->codeExists($data['code'], $id))
  111. return app('json')->fail('编码重复');
  112. if ($this->repository->nameExists($data['name'], $id))
  113. return app('json')->fail('名称重复');
  114. $this->repository->update($id, $data);
  115. return app('json')->success('编辑成功');
  116. }
  117. /**
  118. * 删除
  119. * @Author:Qinii
  120. * @Date: 2020/5/13
  121. * @param $id
  122. * @return mixed
  123. */
  124. public function delete($id)
  125. {
  126. if (!$this->repository->fieldExists($id))
  127. return app('json')->fail('数据不存在');
  128. $this->repository->delete($id);
  129. return app('json')->success('删除成功');
  130. }
  131. /**
  132. * 添加表单
  133. * @Author:Qinii
  134. * @Date: 2020/5/22
  135. * @return mixed
  136. */
  137. public function createForm()
  138. {
  139. return app('json')->success(formToData($this->repository->form($this->request->merId())));
  140. }
  141. /**
  142. * 编辑表单
  143. * @Author:Qinii
  144. * @Date: 2020/5/22
  145. * @param $id
  146. * @return mixed
  147. */
  148. public function updateForm($id)
  149. {
  150. if (!$this->repository->fieldExists($id))
  151. return app('json')->fail('数据不存在');
  152. return app('json')->success(formToData($this->repository->updateForm($this->request->merId(), $id)));
  153. }
  154. /**
  155. * 状态修改
  156. * @Author:Qinii
  157. * @Date: 2020/5/22
  158. * @param int $id
  159. * @return mixed
  160. */
  161. public function switchStatus($id)
  162. {
  163. $status = $this->request->param('is_show', 0) == 1 ? 1 : 0;
  164. if (!$this->repository->fieldExists($id))
  165. return app('json')->fail('数据不存在');
  166. $this->repository->switchStatus($id, ['is_show' => $status]);
  167. return app('json')->success('修改成功');
  168. }
  169. /**
  170. * 同步信息
  171. * @return \think\response\Json
  172. * @author Qinii
  173. * @day 7/23/21
  174. */
  175. public function syncAll()
  176. {
  177. $config = systemConfig(['serve_account','serve_token']);
  178. if (!$config || !$config['serve_account'] || !$config['serve_token']) return app('json')->fail('请先配置一号通账号,再进行物流同步');
  179. Queue::push(ExpressSyncJob::class, []);
  180. return app('json')->success('后台同步中,请稍后来查看~');
  181. }
  182. /**
  183. * 快递公司月结账号等添加表单
  184. * @param $id
  185. * @return \think\response\Json
  186. * @author Qinii
  187. */
  188. public function partnerForm($id)
  189. {
  190. $merId = $this->request->merId();
  191. return app('json')->success(formToData($this->repository->partnerForm($id, $merId)));
  192. }
  193. /**
  194. * 快递公司月结账号等添加
  195. * @param $id
  196. * @return \think\response\Json
  197. * @author Qinii
  198. */
  199. public function partner($id)
  200. {
  201. $data = $this->request->params(['account', 'key', 'net_name']);
  202. if (!$expressInfo = $this->repository->get($id))
  203. return app('json')->fail('编辑的记录不存在!');
  204. if ($expressInfo['partner_id'] == 1 && !$data['account'])
  205. return app('json')->fail('请输入月结账号');
  206. if ($expressInfo['partner_key'] == 1 && !$data['key'])
  207. return app('json')->fail('请输入月结密码');
  208. if ($expressInfo['net'] == 1 && !$data['net_name'])
  209. return app('json')->fail('请输入取件网点');
  210. if ($expressInfo['check_man'] == 1 && !$data['check_man'])
  211. return app('json')->fail('请输入承载快递员名称');
  212. if ($expressInfo['partner_name'] == 1 && !$data['partner_name'])
  213. return app('json')->fail('请输入客户账户名称');
  214. if ($expressInfo['is_code'] == 1 && !$data['code'])
  215. return app('json')->fail('请输入承载编号');
  216. $data['express_id'] = $id;
  217. $data['mer_id'] = $this->request->merId();
  218. $this->repository->updatePartne($data);
  219. return app('json')->success('修改成功');
  220. }
  221. /**
  222. * 获取所有
  223. * @return \think\response\Json
  224. * @author Qinii
  225. */
  226. public function options()
  227. {
  228. $merId = $this->request->merId();
  229. return app('json')->success($this->repository->options($merId));
  230. }
  231. }