Express.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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\v1\other;
  12. use app\controller\admin\AuthController;
  13. use app\services\other\ExpressServices;
  14. use think\facade\App;
  15. /**
  16. * 物流
  17. * Class Express
  18. * @package app\controller\admin\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. *
  36. * @return \think\Response
  37. */
  38. public function index()
  39. {
  40. $where = $this->request->getMore([
  41. ['keyword', '']
  42. ]);
  43. return $this->success($this->services->getExpressList($where));
  44. }
  45. /**
  46. * 显示创建资源表单页.
  47. *
  48. * @return \think\Response
  49. */
  50. public function create()
  51. {
  52. return $this->success($this->services->createForm());
  53. }
  54. /**
  55. * 保存新建的资源
  56. *
  57. * @return \think\Response
  58. */
  59. public function save()
  60. {
  61. $data = $this->request->postMore([
  62. 'name',
  63. 'code',
  64. ['sort', 0],
  65. ['is_show', 0]]);
  66. if (!$data['name']) return $this->fail('请输入公司名称');
  67. $this->services->save($data);
  68. return $this->success('添加公司成功!');
  69. }
  70. /**
  71. * 显示指定的资源
  72. *
  73. * @param int $id
  74. * @return \think\Response
  75. */
  76. public function read($id)
  77. {
  78. //
  79. }
  80. /**
  81. * 显示编辑资源表单页.
  82. *
  83. * @param int $id
  84. * @return \think\Response
  85. */
  86. public function edit($id)
  87. {
  88. return $this->success($this->services->updateForm((int)$id));
  89. }
  90. /**
  91. * 保存更新的资源
  92. *
  93. * @param int $id
  94. * @return \think\Response
  95. */
  96. public function update($id)
  97. {
  98. $data = $this->request->postMore([
  99. ['account', ''],
  100. ['key', ''],
  101. ['net_name', ''],
  102. ['courier_name', ''],
  103. ['customer_name', ''],
  104. ['code_name', ''],
  105. ['sort', 0],
  106. ['is_show', 0]]);
  107. if (!$expressInfo = $this->services->get($id)) return $this->fail('编辑的记录不存在!');
  108. if ($expressInfo['partner_id'] == 1 && !$data['account']) {
  109. return $this->fail('请输入月结账号');
  110. }
  111. if ($expressInfo['partner_key'] == 1 && !$data['key']) {
  112. return $this->fail('请输入月结密码');
  113. }
  114. if ($expressInfo['net'] == 1 && !$data['net_name']) {
  115. return $this->fail('请输入取件网点');
  116. }
  117. if ($expressInfo['check_man'] == 1 && !$data['courier_name']) {
  118. return app('json')->fail('请输入承载快递员名');
  119. }
  120. if ($expressInfo['partner_name'] == 1 && !$data['customer_name']) {
  121. return app('json')->fail('请输入客户账户名称');
  122. }
  123. if ($expressInfo['is_code'] == 1 && !$data['code_name']) {
  124. return app('json')->fail('请输入电子面单承载编号');
  125. }
  126. $expressInfo->account = $data['account'];
  127. $expressInfo->key = $data['key'];
  128. $expressInfo->net_name = $data['net_name'];
  129. $expressInfo->courier_name = $data['courier_name'];
  130. $expressInfo->customer_name = $data['customer_name'];
  131. $expressInfo->code_name = $data['code_name'];
  132. $expressInfo->sort = $data['sort'];
  133. $expressInfo->is_show = $data['is_show'];
  134. $expressInfo->status = 1;
  135. $expressInfo->save();
  136. return $this->success('修改成功!');
  137. }
  138. /**
  139. * 删除指定资源
  140. *
  141. * @param int $id
  142. * @return \think\Response
  143. */
  144. public function delete($id)
  145. {
  146. if (!$id) return $this->fail('参数错误,请重新打开');
  147. $res = $this->services->delete($id);
  148. if (!$res)
  149. return $this->fail('删除失败,请稍候再试!');
  150. else
  151. return $this->success('删除成功!');
  152. }
  153. /**
  154. * 修改状态
  155. * @param int $id
  156. * @param string $status
  157. * @return mixed
  158. */
  159. public function set_status($id = 0, $status = '')
  160. {
  161. if ($status == '' || $id == 0) return $this->fail('参数错误');
  162. $this->services->update($id, ['is_show' => $status]);
  163. return $this->success($status == 0 ? '隐藏成功' : '显示成功');
  164. }
  165. /**
  166. * 同步平台快递公司
  167. * @return mixed
  168. */
  169. public function syncExpress()
  170. {
  171. $this->services->syncExpress();
  172. return $this->success('同步成功');
  173. }
  174. }