Express.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\v1\freight;
  12. use app\adminapi\controller\AuthController;
  13. use app\services\shipping\ExpressServices;
  14. use think\facade\App;
  15. /**
  16. * 物流
  17. * Class Express
  18. * @package app\adminapi\controller\v1\freight
  19. */
  20. class Express extends AuthController
  21. {
  22. /**
  23. * 构造方法
  24. * Express constructor.
  25. * @param App $app
  26. * @param ExpressServices $services
  27. */
  28. public function __construct(App $app, ExpressServices $services)
  29. {
  30. parent::__construct($app);
  31. $this->services = $services;
  32. }
  33. /**
  34. * 获取物流列表
  35. * @return mixed
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public function index()
  41. {
  42. $where = $this->request->getMore([
  43. ['keyword', ''],
  44. ['is_show', '']
  45. ]);
  46. return app('json')->success($this->services->getExpressList($where));
  47. }
  48. /**
  49. * 显示创建资源表单页
  50. * @return mixed
  51. * @throws \FormBuilder\Exception\FormBuilderException
  52. */
  53. public function create()
  54. {
  55. return app('json')->success($this->services->createForm());
  56. }
  57. /**
  58. * 保存新建的资源
  59. * @return \think\Response
  60. */
  61. public function save()
  62. {
  63. $data = $this->request->postMore([
  64. 'name',
  65. 'code',
  66. ['sort', 0],
  67. ['is_show', 0]]);
  68. if (!$data['name']) return app('json')->fail(400400);
  69. $this->services->save($data);
  70. return app('json')->success(400401);
  71. }
  72. /**
  73. * 显示编辑资源表单页
  74. * @param $id
  75. * @return mixed
  76. * @throws \FormBuilder\Exception\FormBuilderException
  77. */
  78. public function edit($id)
  79. {
  80. return app('json')->success($this->services->updateForm((int)$id));
  81. }
  82. /**
  83. * 保存更新的资源
  84. * @param $id
  85. * @return mixed
  86. */
  87. public function update($id)
  88. {
  89. $data = $this->request->postMore([
  90. ['account', ''],
  91. ['key', ''],
  92. ['net_name', ''],
  93. ['courier_name', ''],
  94. ['customer_name', ''],
  95. ['code_name', ''],
  96. ['sort', 0],
  97. ['is_show', 0]]);
  98. if (!$expressInfo = $this->services->get($id)) return app('json')->fail(100026);
  99. if ($expressInfo['net'] == 1 && !$data['net_name']) {
  100. return app('json')->fail(400404);
  101. }
  102. if ($expressInfo['check_man'] == 1 && !$data['courier_name']) {
  103. return app('json')->fail(500001);
  104. }
  105. if ($expressInfo['partner_name'] == 1 && !$data['customer_name']) {
  106. return app('json')->fail(500002);
  107. }
  108. if ($expressInfo['is_code'] == 1 && !$data['code_name']) {
  109. return app('json')->fail(500003);
  110. }
  111. $expressInfo->account = $data['account'];
  112. $expressInfo->key = $data['key'];
  113. $expressInfo->net_name = $data['net_name'];
  114. $expressInfo->courier_name = $data['courier_name'];
  115. $expressInfo->customer_name = $data['customer_name'];
  116. $expressInfo->code_name = $data['code_name'];
  117. $expressInfo->sort = $data['sort'];
  118. $expressInfo->is_show = $data['is_show'];
  119. $expressInfo->status = 1;
  120. $expressInfo->save();
  121. return app('json')->success(100001);
  122. }
  123. /**
  124. * 删除指定资源
  125. * @param $id
  126. * @return mixed
  127. */
  128. public function delete($id)
  129. {
  130. if (!$id) return app('json')->fail(100100);
  131. $res = $this->services->delete($id);
  132. if (!$res)
  133. return app('json')->fail(100008);
  134. else
  135. return app('json')->success(100002);
  136. }
  137. /**
  138. * 修改状态
  139. * @param int $id
  140. * @param string $status
  141. * @return mixed
  142. */
  143. public function set_status($id = 0, $status = '')
  144. {
  145. if ($status == '' || $id == 0) return app('json')->fail(100100);
  146. $this->services->update($id, ['is_show' => $status]);
  147. return app('json')->success(100014);
  148. }
  149. /**
  150. * 同步平台快递公司
  151. * @return mixed
  152. */
  153. public function syncExpress()
  154. {
  155. $this->services->syncExpress();
  156. return app('json')->success(100038);
  157. }
  158. }