Express.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use think\App;
  5. use think\Exception;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //物流信息
  9. class Express extends Base
  10. {
  11. //获取快递公司列表
  12. public function list()
  13. {
  14. $param = $this->request->only(['page' => 1, 'size' => 10, 'type' => 0, 'name' => '', 'plat_type' => ''], 'post', 'trim');
  15. $where = [['type', '=', $param['type']]];
  16. if ($param['name'] != '') $where[] = ['name|shortName', 'like', '%' . $param['name'] . '%'];
  17. if ($param['plat_type'] != '') $where[] = ['plat_type', '=', $param['plat_type']];
  18. $count = Db::name('express')
  19. ->where($where)
  20. ->count('id');
  21. $list = Db::name("express")
  22. ->field('id,type,comTypeName,name,plat_type,shortName,shortNameEn,shortNumber,canOrder')
  23. ->where($where)
  24. ->page($param['page'], $param['size'])
  25. ->select()
  26. ->toArray();
  27. return app_show(0, '获取成功', ['list' => $list, 'count' => $count]);
  28. }
  29. //快递公司启禁用
  30. public function SetUse()
  31. {
  32. $param = $this->request->only(['id' => 0], 'post', 'trim');
  33. $express = Db::name('express')
  34. ->field('id,canOrder')
  35. ->where(['id' => $param['id']])
  36. ->findOrEmpty();
  37. if (empty($express)) return error_show(1004, '未找到数据');
  38. Db::startTrans();
  39. try {
  40. $express['canOrder'] = $express['canOrder'] == 0 ? 1 : 0;
  41. $up = Db::name('express')
  42. ->save($express);
  43. $orde = ['order_code' => $param['id'], 'status' => 0, 'action_remark' => '', 'action_type' => 'edit'];
  44. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $orde, 'express', 0, $orde);
  45. Db::commit();
  46. return $up ? app_show(0, '更新成功') : error_show(1005, '更新失败');
  47. } catch (Exception $exception) {
  48. Db::rollback();
  49. return json_show(1004, '更新失败,' . $exception->getMessage());
  50. }
  51. }
  52. //获取可用的快递公司列表
  53. public function GetExpress()
  54. {
  55. $type = isset($this->post['type']) && $this->post['type'] !== "" ? intval($this->post['type']) : '';
  56. $where[] = ['canOrder', "=", 1];
  57. if ($type === 0) {
  58. $where[] = ["type", "=", $type];
  59. }
  60. $order_source = isset($this->post['order_source']) && $this->post['order_source'] !== "" ? intval($this->post['order_source']) : '1';
  61. $plat_type = 1;
  62. if ($order_source == 5) {
  63. $plat_type = 2;
  64. }
  65. $where[] = ["plat_type", "=", $plat_type];
  66. $name = isset($this->post['name']) && $this->post['name'] != "" ? trim($this->post['name']) : '';
  67. if ($name != '') {
  68. $where[] = ["name|shortName", "like", "%{$name}%"];
  69. }
  70. $list = Db::name("express")->where($where)->field('id,type,comTypeName,name,shortName,shortNameEn,shortNumber,canOrder')
  71. ->select();
  72. return app_show(0, '获取成功', $list);
  73. }
  74. //SupplierExpress 相关数据表不存在,以下5个接口貌似无用
  75. //获取公司关联的快递公司
  76. public function getSupplierExpress()
  77. {
  78. $param = $this->request->only(['page'=>1,'size'=>10, 'key_supplierNo'=>''], 'post', 'trim');
  79. $where=[['a.is_del','=',0]];
  80. if($param['key_supplierNo']!='') $where[]=['a.supplierNo','like','%'.$param['key_supplierNo'].'%'];
  81. $count = Db::name('express_supplier')
  82. ->alias('a')
  83. ->leftJoin('supplier b','b.code=a.supplierNo')
  84. ->where($where)
  85. ->count('a.id');
  86. $rs = Db::name('express_supplier')
  87. ->field('a.id,a.supplierNo,a.addtime,a.status,a.express_ids,b.name supplierName')
  88. ->alias('a')
  89. ->where($where)
  90. ->leftJoin('supplier b','b.code=a.supplierNo')
  91. ->order('a.id','desc')
  92. ->page($param['page'],$param['size'])
  93. ->append(['express_list'])
  94. ->withAttr('express_list',function($val,$da){
  95. return Db::name('express')
  96. ->field('id,name')
  97. ->whereIn('id',$da['express_ids'])
  98. ->order('id','desc')
  99. ->select()
  100. ->toArray();
  101. })
  102. ->select()
  103. ->toArray();
  104. return json_show(0, '操作成功',['count'=>$count,'list'=>$rs]);
  105. }
  106. //详情公司关联的快递公司
  107. public function infoSupplierExpress()
  108. {
  109. $id = $this->request->param('id/d', 0, 'trim');
  110. $rs = Db::name('express_supplier')
  111. ->field('a.*,b.name supplierName')
  112. ->alias('a')
  113. ->where(['a.id'=>$id,'a.is_del'=>0])
  114. ->leftJoin('supplier b','b.code=a.supplierNo')
  115. ->withAttr('express_ids',function($val,$da){
  116. return explode(',',$val);
  117. })
  118. ->findOrEmpty();
  119. return $rs ? json_show(0, '获取详情成功',$rs) : json_show(1004, '当前记录不存在');
  120. }
  121. //编辑公司关联的快递公司
  122. public function setSupplierExpress()
  123. {
  124. $param = $this->request->only(['express_ids', 'supplierNo'], 'post', 'trim');
  125. $val = Validate::rule([
  126. 'express_ids|快递公司id集合' => 'require|array|max:100',
  127. 'supplierNo|公司编码' => 'require|length:18'
  128. ]);
  129. if (!$val->check($param)) return json_show(1004, $val->getError());
  130. $tmp = Db::name('express_supplier')
  131. ->field('id')
  132. ->where('supplierNo', $param['supplierNo'])
  133. ->findOrEmpty();
  134. $date = date('Y-m-d H:i:s');
  135. if ($tmp) {
  136. $rs = Db::name('express_supplier')
  137. ->where('supplierNo', $param['supplierNo'])
  138. ->update([
  139. 'express_ids' => implode(',',$param['express_ids']),
  140. 'updatetime' => $date
  141. ]);
  142. } else {
  143. $rs = Db::name('express_supplier')
  144. ->where('supplierNo', $param['supplierNo'])
  145. ->insert([
  146. 'supplierNo' => $param['supplierNo'],
  147. 'express_ids' => implode(',',$param['express_ids']),
  148. 'addtime' => $date,
  149. 'updatetime' => $date
  150. ]);
  151. }
  152. return $rs ? json_show(0, '操作成功') : json_show(1004, '操作失败');
  153. }
  154. //启禁用公司关联的快递公司
  155. public function statusSupplierExpress()
  156. {
  157. $param = $this->request->only(['id', 'status'], 'post', 'trim');
  158. $val = Validate::rule([
  159. 'id' => 'require|number|gt:0',
  160. 'status|状态' => 'require|number|in:0,1'
  161. ]);
  162. if (!$val->check($param)) return json_show(1004, $val->getError());
  163. $tmp = Db::name('express_supplier')
  164. ->field('id,status')
  165. ->where('id', $param['id'])
  166. ->findOrEmpty();
  167. if (empty($tmp)) return json_show(1004, '该记录不存在');
  168. if ($tmp['status'] == $param['status']) return json_show(1005, '重复操作');
  169. $rs = Db::name('express_supplier')
  170. ->where('id', $param['id'])
  171. ->where('status', '<>', $param['status'])
  172. ->update([
  173. 'status' => $param['status'],
  174. 'updatetime' => date('Y-m-d H:i:s')
  175. ]);
  176. return $rs ? json_show(0, '操作成功') : json_show(1004, '操作失败');
  177. }
  178. //删除公司关联的快递公司
  179. public function deleteSupplierExpress()
  180. {
  181. $id = $this->request->param('id/d', 0, 'trim');
  182. $rs = Db::name('express_supplier')
  183. ->where(['id' => $id, 'is_del' => 0])
  184. ->update([
  185. 'is_del' => 1,
  186. 'updatetime' => date('Y-m-d H:i:s')
  187. ]);
  188. return $rs ? json_show(0, '删除成功') : json_show(1004, '删除失败,当前记录不存在');
  189. }
  190. }