Express.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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\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. *
  36. * @return \think\Response
  37. */
  38. public function index()
  39. {
  40. $where = $this->request->getMore([
  41. ['keyword', '']
  42. ]);
  43. return app('json')->success($this->services->getExpressList($where));
  44. }
  45. /**
  46. * 显示创建资源表单页.
  47. *
  48. * @return \think\Response
  49. */
  50. public function create()
  51. {
  52. return app('json')->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 app('json')->fail('请输入公司名称');
  67. $this->services->save($data);
  68. return app('json')->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 app('json')->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. ['sort', 0],
  103. ['is_show', 0]]);
  104. if (!$expressInfo = $this->services->get($id)) return app('json')->fail('编辑的记录不存在!');
  105. if ($expressInfo['partner_id'] == 1 && !$data['account']) {
  106. return app('json')->fail('请输入月结账号');
  107. }
  108. if ($expressInfo['partner_key'] == 1 && !$data['key']) {
  109. return app('json')->fail('请输入月结密码');
  110. }
  111. if ($expressInfo['net'] == 1 && !$data['net_name']) {
  112. return app('json')->fail('请输入取件网点');
  113. }
  114. $expressInfo->account = $data['account'];
  115. $expressInfo->key = $data['key'];
  116. $expressInfo->net_name = $data['net_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('修改成功!');
  122. }
  123. /**
  124. * 删除指定资源
  125. *
  126. * @param int $id
  127. * @return \think\Response
  128. */
  129. public function delete($id)
  130. {
  131. if (!$id) return app('json')->fail('参数错误,请重新打开');
  132. $res = $this->services->delete($id);
  133. if (!$res)
  134. return app('json')->fail('删除失败,请稍候再试!');
  135. else
  136. return app('json')->success('删除成功!');
  137. }
  138. /**
  139. * 修改状态
  140. * @param int $id
  141. * @param string $status
  142. * @return mixed
  143. */
  144. public function set_status($id = 0, $status = '')
  145. {
  146. if ($status == '' || $id == 0) return app('json')->fail('参数错误');
  147. $this->services->update($id, ['is_show' => $status]);
  148. return app('json')->success($status == 0 ? '隐藏成功' : '显示成功');
  149. }
  150. /**
  151. * 同步平台快递公司
  152. * @return mixed
  153. */
  154. public function syncExpress()
  155. {
  156. $this->services->syncExpress();
  157. return app('json')->success('同步成功');
  158. }
  159. }