WareHouse.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. use app\admin\model\ActionLog;
  7. use think\facade\Validate;
  8. //仓库
  9. class WareHouse extends Base
  10. {
  11. public function add()
  12. {
  13. $post = $this->request->only([
  14. 'companyNo',
  15. 'supplierNo',
  16. 'name',
  17. 'addr_code' => '',
  18. 'addr',
  19. 'contactor_id',
  20. 'mobile',
  21. 'wsm_name' => '',
  22. 'wsm_mobile' => '',
  23. 'wsm_addr' => '',
  24. 'addrs_code' => '',
  25. 'position' => '',
  26. 'wsmtype',
  27. ], 'post', 'trim');
  28. $val = Validate::rule([
  29. 'companyNo|业务公司编码' => 'require',
  30. 'supplierNo|供应商编码' => 'require',
  31. 'name|仓库名称' => 'require',
  32. 'wsmtype|仓库类型' => 'require',
  33. 'addr|仓库地址' => 'require',
  34. 'contactor_id|仓库管理员' => 'require|number|gt:0',
  35. 'mobile|仓库联系方式' => 'require',
  36. ]);
  37. if ($val->check($post) == false) return json_show(1004, $val->getError());
  38. // $name = isset($post['name'])&& $post['name']!='' ?trim($post['name']) :'';
  39. // if($name==''){
  40. // return error_show(1004,'参数name 不能为空');
  41. // }
  42. // $supplier = isset($post['supplierNo'])&& $post['supplierNo']!='' ?trim($post['supplierNo']) :'';
  43. // if($supplier==''){
  44. // return error_show(1004,'参数supplierNo 不能为空');
  45. // }
  46. // $supplierinfo = Db::name("supplier")->where(["code"=>$supplier])->find();
  47. // if(empty($supplierinfo)){
  48. // return error_show(1004,'未找到供应商数据');
  49. // }
  50. // if($name==$supplierinfo['name']){
  51. // return error_show(1004,'仓库名不可以与供应商名称相同');
  52. // }
  53. // $wsmtype = isset($post['wsmtype'])&& $post['wsmtype']!='' ?intval($post['wsmtype']) :'';
  54. // if($wsmtype==''){
  55. // return error_show(1004,'参数wsmtype 不能为空');
  56. // }
  57. $isT = Db::name('warehouse_info')
  58. ->field('id')
  59. ->where([['name', "=", $post['name']], ["is_del", "=", 0],["companyNo","=",$post['companyNo']]])
  60. ->findOrEmpty();
  61. if (!empty($isT)) return error_show(1004, '仓库名称已存在');
  62. // $addr = isset($post['addr'])&& $post['addr']!='' ?trim($post['addr']) :'';
  63. // if($addr==''){
  64. // return error_show(1004,'参数addr 不能为空');
  65. // }
  66. // $contactor_id = isset($post['contactor_id'])&& $post['contactor_id']!='' ?trim($post['contactor_id']) :'';
  67. // if($contactor_id==''){
  68. // return error_show(1004,'参数 contactor_id 不能为空');
  69. // }
  70. // $contactorinfo = GetInfoById($post['token'],['id'=>$contactor_id]);
  71. // if(!empty($contactorinfo) && $contactorinfo['code']!=0){
  72. // return error_show($contactorinfo['code'],$contactorinfo['message']);
  73. // }
  74. // $nickname = $this->uname;
  75. // $mobile = isset($post['mobile'])&& $post['mobile']!='' ?trim($post['mobile']) :'';
  76. // if($mobile==''){
  77. // return error_show(1004,'参数mobile 不能为空');
  78. // }
  79. // $position = isset($post['position'])&& $post['position']!='' ?trim($post['position']) :'';
  80. // $companyNo = isset($post['companyNo'])&& $post['companyNo']!='' ?trim($post['companyNo']) :'';
  81. // if($companyNo==""){
  82. // return error_show(1004,"参数companyNo不能为空");
  83. // }
  84. // $company = Db::name("business")->where(["companyNo"=>$companyNo,"is_del"=>0])->find();
  85. // if($company==false){
  86. // return error_show(1004,"业务企业未找到");
  87. // }
  88. $userCommon = \app\admin\common\User::getIns();
  89. $tmp = $userCommon->handle('getCodeAndName', ['code' => [$post['companyNo'], $post['supplierNo']]]);
  90. if (!isset($tmp['data'][$post['companyNo']])) return json_show(1004, '业务企业未找到');
  91. if (!isset($tmp['data'][$post['supplierNo']])) return json_show(1004, '供应商未找到');
  92. if ($tmp['data'][$post['supplierNo']] == $post['name']) return json_show(1004, '仓库名不可以与供应商名称相同');
  93. $user = $userCommon->handle('userinfo', ['id' => $post['contactor_id']]);
  94. // $wsm_type = isset($post['wsm_type']) && $post['wsm_type']!=="" ? intval($post['wsm_type']):"1";
  95. // $wsm_name = isset($post['wsm_name']) && $post['wsm_name']!=="" ? trim($post['wsm_name']):"";
  96. // $wsm_mobile = isset($post['wsm_mobile']) && $post['wsm_mobile']!=="" ? trim($post['wsm_mobile']):"";
  97. // $addr_code = isset($post['addr_code']) && $post['addr_code']!=="" ? $post['addr_code']:"";
  98. // $wsm_addr = isset($post['wsm_addr']) && $post['wsm_addr']!=="" ? trim($post['wsm_addr']):"";
  99. // $addrs_code = isset($post['addrs_code']) && $post['addrs_code']!=="" ? $post['addrs_code']:"";
  100. Db::startTrans();
  101. try {
  102. $date = date('Y-m-d H:i:s');
  103. $wsm_code = makeNo("WSM");
  104. $data = [
  105. 'wsm_code' => $wsm_code,
  106. 'name' => $post['name'],
  107. 'wsm_type' => $post['wsmtype'],
  108. 'supplierNo' => $post['supplierNo'],
  109. 'supplierName' => $tmp['data'][$post['supplierNo']],
  110. 'addr' => $post['addr'],
  111. 'companyNo' => $post['companyNo'],
  112. 'companyName' => $tmp['data'][$post['companyNo']]??'',
  113. 'contactor' => $post['contactor_id'],
  114. 'contactor_name' => $user['data']['nickname'],
  115. 'mobile' => $post['mobile'],
  116. 'position' => $post['position'],
  117. "addrs_code" => json_encode($post['addrs_code']),
  118. 'status' => 1,
  119. 'is_del' => 0,
  120. 'createrid' => $this->uid,
  121. 'creater' => $this->uname,
  122. 'addtime' => $date,
  123. 'updaterid' => $this->uid,
  124. 'updater' => $this->uname,
  125. 'updatetime' => $date
  126. ];
  127. $add = Db::name('warehouse_info')->insert($data, true);
  128. if ($add > 0) {
  129. $st = ["order_code" => $wsm_code, "status" => 1, "action_remark" => '', "action_type" => "create"];
  130. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $st, "warehouse", 1, $data);
  131. $addrinfo = [
  132. "wsm_code" => $wsm_code,
  133. "wsm_type" => $post['wsmtype'],
  134. "wsm_name" => $post['wsm_name'],
  135. "wsm_mobile" => $post['wsm_mobile'],
  136. "wsm_addr" => $post['wsm_addr'],
  137. "addr_code" => json_encode($post['addr_code']),
  138. "status" => 1,
  139. "addtime" => $date,
  140. "updatetime" => $date,
  141. ];
  142. $addri = DB::name("warehouse_addr")->insert($addrinfo);
  143. if ($addri) {
  144. $sf = ["order_code" => $wsm_code, "status" => 1, "action_remark" => '', "action_type" => "create"];
  145. ActionLog::logAdd(['id' => $this->uid, 'nickname' => $this->uname], $sf, "warehouse", 1, $addrinfo);
  146. Db::commit();
  147. return app_show(0, '仓库创建成功', ["wsm_code" => $wsm_code]);
  148. }
  149. }
  150. Db::rollback();
  151. return error_show(1005, '仓库创建失败');
  152. } catch (\Exception $e) {
  153. Db::rollback();
  154. return error_show(1005, $e->getMessage());
  155. }
  156. }
  157. public function list(){
  158. $post =$this->request->post();
  159. $condition= [['a.is_del',"=",0],["b.is_del","=",0]];
  160. $supplier = isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :"";
  161. if($supplier!=""){
  162. $condition[]=["supplierNo","=",$supplier];
  163. }
  164. // $companyNo = isset($post['companyNo'])&&$post['companyNo']!="" ? trim($post['companyNo']) :"";
  165. // if($companyNo!=""){
  166. // $condition[]=["companyNo","=",$companyNo];
  167. // }
  168. $wsm_code = isset($post['wsm_code'])&&$post['wsm_code']!="" ? trim($post['wsm_code']) :"";
  169. if($wsm_code!=""){
  170. $condition[]=["a.wsm_code","like","%{$wsm_code}%"];
  171. }
  172. $start = isset($post['start'])&&$post['start']!="" ? $post['start'] :"";
  173. if($start!=""){
  174. $condition[]=["a.addtime",">=",$start];
  175. }
  176. $end = isset($post['end'])&&$post['end']!="" ? $post['end'] :"";
  177. if($end!=""){
  178. $condition[]=["a.addtime","<=",$end];
  179. }
  180. $mobile = isset($post['mobile'])&&$post['mobile']!="" ? trim($post['mobile']) :"";
  181. if($mobile!=""){
  182. $condition[]=["a.mobile","like","%{$mobile}%"];
  183. }
  184. $contactor = isset($post['contactor_id'])&&$post['contactor_id']!="" ? trim($post['contactor_id']) :"";
  185. if($contactor!=""){
  186. $condition[]=["a.contactor","=",$contactor];
  187. }
  188. $wsm_type = isset($post['wsm_type'])&&$post['wsm_type']!="" ? intval($post['wsm_type']) :"";
  189. if($wsm_type!=""){
  190. $condition[]=["a.wsm_type","=",$wsm_type];
  191. }
  192. $contactor_name = isset($post['contactor_name'])&&$post['contactor_name']!="" ? trim($post['contactor_name']) :"";
  193. if($contactor_name!=""){
  194. $condition[]=["a.contactor_name","like","%{$contactor_name}%"];
  195. }
  196. $wsm_name = isset($post['wsm_name'])&&$post['wsm_name']!="" ? trim($post['wsm_name']) :"";
  197. if($wsm_name!=""){
  198. $condition[]=["a.name","like","%{$wsm_name}%"];
  199. }
  200. $companyNo = isset($post['companyNo'])&&$post['companyNo']!="" ? trim($post['companyNo']) :"";
  201. if($companyNo!=""){
  202. $condition[]=["a.companyNo","like","%{$companyNo}%"];
  203. }
  204. $relaComNo = isset($this->post['relaComNo']) && $this->post['relaComNo']!="" ? trim($this->post['relaComNo']):"";
  205. if($relaComNo!="") $condition[]=['a.companyNo','=', $relaComNo];
  206. $wsm_type = isset($post['wsm_type'])&&$post['wsm_type']!="" ? (int)($post['wsm_type']) :0;
  207. if($wsm_type){
  208. $condition[]=["a.wsm_type",'=',$wsm_type];
  209. }
  210. $page = isset($post['page']) &&$post['page']!=='' ?intval($post['page']) :1;
  211. $size = isset($post['size']) &&$post['size']!=='' ?intval($post['size']) :10;
  212. $company_new_name = isset($post['company_new_name']) && $post['company_new_name'] !== "" ? trim($post['company_new_name']) : "";
  213. if ($company_new_name !== "") $condition[] = ["a.contactor", 'in', get_company_item_user_by_name($company_new_name)];
  214. $count = Db::name("warehouse_info")
  215. ->alias("a")
  216. ->join("warehouse_addr b ","a.wsm_code=b.wsm_code","left")
  217. ->where($condition)
  218. ->count();
  219. $page>=ceil($count/$size) ? $page = ceil($count/$size): '';
  220. $list = Db::name("warehouse_info")
  221. ->alias("a")
  222. ->join("warehouse_addr b ","a.wsm_code=b.wsm_code","left")
  223. ->where($condition)
  224. ->field("a.id,a.wsm_code,a.name,a.wsm_type,a.supplierNo,a.supplierName,a.addr,a.contactor,a.contactor_name,a.mobile,a.position,a.status,a.addtime,a.companyNo,a.companyName,a.updatetime,a.wsm_type,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code,a.addrs_code,a.creater")
  225. ->page($page,$size)
  226. ->order("a.addtime desc")
  227. ->select()
  228. ->toArray();
  229. $all_createrid = array_column($list,'contactor');
  230. $item = get_company_name_by_uid($all_createrid);
  231. // $all_companyNo = array_column($list,'companyNo');
  232. // $userCommon = \app\admin\common\User::getIns();
  233. // $tmp = $userCommon->handle('getCodeAndName',['code'=>$all_companyNo]);
  234. foreach ($list as $key=>$value){
  235. $value['company_name'] = $value['companyName'];//$tmp['data'][$value['companyNo']]??'';
  236. if($value['wsm_type']!=""){
  237. $type = Db::name("warehouse_type")->where(["id"=>$value['wsm_type']])->find();
  238. $value['type_name'] = isset($type['name']) ? $type['name'] :"";
  239. }else{
  240. $value['type_name']="";
  241. }
  242. $value['addrs_cn'] =isset($value['addrs_code']) ?GetAddr($value['addrs_code']):"";
  243. $value['addr_cn'] =isset($value['addr_code']) ? GetAddr($value['addr_code']):"";
  244. $value['addr_code'] = json_decode($value['addr_code'], true);
  245. $value['addrs_code'] = json_decode($value['addrs_code'], true);
  246. $value['company_new_name'] = $item[$value['contactor']]??'';
  247. $list[$key]=$value;
  248. }
  249. return app_show(0,"获取成功",['list'=>$list,"count"=>$count]);
  250. }
  251. public function info(){
  252. $post =$this->request->post();
  253. $id = isset($post['id']) && $post['id']!==''?intval($post['id']): "";
  254. if($id===""){
  255. return error_show(1004,"参数id不能为空");
  256. }
  257. $warse = Db::name("warehouse_info")
  258. ->alias("a")
  259. ->join("warehouse_addr b ","a.wsm_code=b.wsm_code","left")
  260. ->where(["a.id"=>$id,"a.is_del"=>0,"a.status"=>1])
  261. ->field("a.*,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code")
  262. ->withAttr('addr_code', function ($val) {
  263. return json_decode($val, true); //单独处理省市区编码
  264. })
  265. ->findOrEmpty();
  266. if(empty($warse)) return error_show(1004,"未找到数据");
  267. // $userCommon = \app\admin\common\User::getIns();
  268. // $tmp = $userCommon->handle('getCodeAndName',['code'=>[$warse['supplierNo'],$warse['companyNo']]]);
  269. // if($warse['supplierNo']!=""){
  270. // $supplierinfo = Db::name("supplier")->where(["code"=>$warse['supplierNo']])->find();
  271. // $warse['supplier_name'] = isset($supplierinfo['name']) ? $supplierinfo['name'] :"";
  272. // }else{
  273. // $warse['supplier_name']="";
  274. // }
  275. $warse['supplier_name'] = $warse['supplierName'];//$tmp['data'][$warse['supplierNo']]??'';
  276. // if($warse['companyNo']!=""){
  277. // $company = Db::name("business")->where(["companyNo"=>$warse['companyNo']])->find();
  278. // $warse['company_name'] = isset($company['company']) ? $company['company'] :"";
  279. // }else{
  280. // $warse['company_name']="";
  281. // }
  282. $warse['company_name'] = $warse['companyName'];//$tmp['data'][$warse['companyNo']]??'';
  283. $warse['addrs_code'] = isset($warse['addrs_code'])&&$warse['addrs_code']!="" ? json_decode($warse['addrs_code'],true):"";
  284. if($warse['wsm_type']!=""){
  285. $type = Db::name("warehouse_type")->field('name')->where(["id"=>$warse['wsm_type']])->findOrEmpty();
  286. $warse['type_name'] = isset($type['name']) ? $type['name'] :"";
  287. }else{
  288. $warse['type_name']="";
  289. }
  290. return app_show(0,"获取成功",$warse);
  291. }
  292. public function save(){
  293. $post =$this->request->post();
  294. $id = isset($post['id']) && $post['id']!==''?intval($post['id']): "";
  295. if($id===""){
  296. return error_show(1004,"参数id不能为空");
  297. };
  298. $warse = Db::name("warehouse_info")->where(["id"=>$id,"is_del"=>0,"status"=>1])->find();
  299. if(empty($warse)){
  300. return error_show(1004,"未找到数据");
  301. }
  302. $companyNo = isset($post['companyNo'])&& $post['companyNo']!='' ?trim($post['companyNo']) :'';
  303. if($companyNo==""){
  304. return error_show(1004,"参数companyNo不能为空");
  305. }
  306. $name = isset($post['name'])&& $post['name']!='' ?trim($post['name']) :'';
  307. if($name==''){
  308. return error_show(1004,'参数name 不能为空');
  309. }
  310. $isT = Db::name('warehouse_info')->where([['name',"=",$name],["is_del","=",0],["companyNo","=", $companyNo],["id","<>", $id]])->find();
  311. if(!empty($isT)){
  312. return error_show(1004,'仓库名称已存在');
  313. }
  314. $addr = isset($post['addr'])&& $post['addr']!='' ?trim($post['addr']) :'';
  315. if($addr==''){
  316. return error_show(1004,'参数addr 不能为空');
  317. }
  318. // $contactor = isset($post['contactor'])&& $post['contactor']!='' ?trim($post['contactor']) :'';
  319. // if($contactor==''){
  320. // return error_show(1004,'参数contactor_id 不能为空');
  321. // }
  322. $contactor = isset($post['contactor_id'])&& $post['contactor_id']!='' ?intval($post['contactor_id']) :'';
  323. if($contactor==''){
  324. return error_show(1004,'参数contactor 不能为空');
  325. }
  326. // $company = Db::name("business")->where(["companyNo"=>$companyNo,"is_del"=>0])->find();
  327. // if($company==false){
  328. // return error_show(1004,"业务企业未找到");
  329. // }
  330. $userCommon = \app\admin\common\User::getIns();
  331. $tmp = $userCommon->handle('getCodeAndName',['code'=>$companyNo]);
  332. if(empty($tmp['data'])) return json_show(1004,'业务企业未找到');
  333. $user = $userCommon->handle('userinfo',['id'=>$contactor]);
  334. // $contactorinfo = GetInfoById($post['token'],['id'=>$contactor]);
  335. // if(!empty($contactorinfo) && $contactorinfo['code']!=0){
  336. // return error_show($contactorinfo['code'],$contactorinfo['message']);
  337. // }
  338. $mobile = isset($post['mobile'])&& $post['mobile']!='' ?trim($post['mobile']) :'';
  339. if($mobile==''){
  340. return error_show(1004,'参数mobile 不能为空');
  341. }
  342. $position = isset($post['position'])&& $post['position']!='' ?trim($post['position']) :'';
  343. $wsm_type = isset($post['wsm_type']) && $post['wsm_type']!=="" ? intval($post['wsm_type']):"1";
  344. $wsm_name = isset($post['wsm_name']) && $post['wsm_name']!=="" ? trim($post['wsm_name']):"";
  345. $wsm_mobile = isset($post['wsm_mobile']) && $post['wsm_mobile']!=="" ? trim($post['wsm_mobile']):"";
  346. $addr_code = isset($post['addr_code']) && $post['addr_code']!=="" ? $post['addr_code']:"";
  347. $addrs_code = isset($post['addrs_code']) && $post['addrs_code']!=="" ? $post['addrs_code']:"";
  348. $wsm_addr = isset($post['wsm_addr']) && $post['wsm_addr']!=="" ? trim($post['wsm_addr']):"";
  349. Db::startTrans();
  350. try{
  351. $data =[
  352. 'name'=>$name,
  353. 'addr'=>$addr,
  354. 'contactor'=>$contactor,
  355. 'contactor_name'=>$user['data']['nickname']??'',
  356. 'mobile'=>$mobile,
  357. 'position'=>$position,
  358. 'companyNo' => $companyNo,
  359. 'companyName' => $tmp['data'][$companyNo],
  360. 'updaterid'=>$this->uid,
  361. 'updater'=>$this->uname,
  362. "addrs_code"=>json_encode($addrs_code),
  363. 'updatetime'=>date("Y-m-d H:i:s")
  364. ];
  365. $add = Db::name('warehouse_info')->where($warse)->update($data);
  366. if($add){
  367. $st = ["order_code"=>$id,"status"=>0,"action_remark"=>'',"action_type"=>"edit"];
  368. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$st,"warehouse_info",0,$data);
  369. $addrinfo = [
  370. "wsm_type"=> $wsm_type,
  371. "wsm_name"=>$wsm_name,
  372. "wsm_mobile"=>$wsm_mobile,
  373. "wsm_addr"=>$wsm_addr,
  374. "addr_code"=>json_encode($addr_code),
  375. "updatetime"=>date("Y-m-d H:i:s"),
  376. ];
  377. $addri = Db::name("warehouse_addr")->where(["wsm_code"=>$warse['wsm_code'],"is_del"=>0])->update
  378. ($addrinfo);
  379. if($addri){
  380. $sf = ["order_code"=>$warse['wsm_code'],"status"=>$warse['status'],"action_remark"=>'',"action_type"=>"edit"];
  381. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$sf,"warehouse",1,$data);
  382. Db::commit();
  383. return app_show(0,'仓库更新成功');
  384. }
  385. }
  386. Db::rollback();
  387. return error_show(1005,'仓库更新失败');
  388. }catch (\Exception $e){
  389. Db::rollback();
  390. return error_show(1005,$e->getMessage());
  391. }
  392. }
  393. public function delete(){
  394. $post =$this->request->post();
  395. $id = isset($post['id']) && $post['id']!==''?intval($post['id']): "";
  396. if($id===""){
  397. return error_show(1004,"参数id不能为空");
  398. };
  399. $warse = Db::name("warehouse_info")->where(["id"=>$id,"is_del"=>0])->find();
  400. if(empty($warse)){
  401. return error_show(1004,"未找到数据");
  402. }
  403. $warse['is_del'] = 1;
  404. $warse['updatetime'] = date("Y-m-d H:i:s");
  405. $Del= Db::name("warehouse_info")->save($warse);
  406. if($Del){
  407. $sf = ["order_code"=>$warse['wsm_code'],"status"=>$warse['status'],"action_remark"=>'',"action_type"=>"delete"];
  408. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$sf,"warehouse",1,$warse);
  409. }
  410. return $Del? app_show(0,'仓库删除成功'): error_show(1005,'仓库删除失败');
  411. }
  412. public function status(){
  413. $post =$this->request->post();
  414. $id = isset($post['id']) && $post['id']!==''?intval($post['id']): "";
  415. if($id===""){
  416. return error_show(1004,"参数id不能为空");
  417. };
  418. $warse = Db::name("warehouse_info")->where(["id"=>$id,"is_del"=>0])->find();
  419. if(empty($warse)){
  420. return error_show(1004,"未找到数据");
  421. }
  422. $status = isset($post['status']) && $post['status']!=="" ? intval($post['status']) : "";
  423. if($status===""){
  424. return error_show(1005,"参数status 不能为空");
  425. }
  426. $vmp=$warse['status'];
  427. $warse['status'] = $status;
  428. $warse['updatetime'] = date("Y-m-d H:i:s");
  429. $Del= Db::name("warehouse_info")->save($warse);
  430. if($Del){
  431. $sf = ["order_code"=>$warse['wsm_code'],"status"=>$vmp,"action_remark"=>'',"action_type"=>"status"];
  432. ActionLog::logAdd(['id'=>$this->uid,'nickname'=>$this->uname],$sf,"warehouse",$status,$warse);
  433. }
  434. return $Del? app_show(0,'仓库状态修改成功'): error_show(1005,'仓库状态修改失败');
  435. }
  436. public function select(){
  437. $post =$this->request->post();
  438. $condition= [['a.is_del',"=",0],['a.status',"=",1],["b.is_del","=",0]];
  439. // $supplier = isset($post['supplierNo'])&&$post['supplierNo']!="" ? trim($post['supplierNo']) :"";
  440. // if($supplier!=""){
  441. // $condition[]=["supplierNo","=",$supplier];
  442. // }
  443. $company = isset($post['companyNo'])&&$post['companyNo']!="" ? trim($post['companyNo']) :"";
  444. if($company!=""){
  445. $condition[]=["companyNo","=",$company];
  446. }
  447. $wsm_type = isset($post['wsm_type'])&&$post['wsm_type']!="" ? intval($post['wsm_type']) :"1";
  448. $condition[]=["a.wsm_type","=",$wsm_type];
  449. $list = Db::name("warehouse_info")
  450. ->alias("a")
  451. ->join("warehouse_addr b ","a.wsm_code=b.wsm_code","left")
  452. ->where($condition)
  453. ->field("a.id,a.wsm_code,a.name,a.wsm_type,a.supplierNo,a.supplierName,a.addr,a.contactor,a.contactor_name,a.mobile,a.position,a.status,a.addtime,a.updatetime,a.wsm_type,a.companyNo,a.companyName,b.wsm_name,b.wsm_mobile,b.wsm_addr,b.addr_code,a.addrs_code")
  454. ->order("a.addtime desc")
  455. ->select()
  456. ->toArray();
  457. // $all_companyNo = array_column($list, 'companyNo');
  458. // $userCommon = \app\admin\common\User::getIns();
  459. // $tmp = $userCommon->handle('getCodeAndName', ['code' => $all_companyNo]);
  460. $data=[];
  461. foreach ($list as $value){
  462. $temp=[];
  463. $temp['wsm_code'] =$value['wsm_code'];
  464. $temp['wsm_type'] =$value['wsm_type'];
  465. $temp['name'] =$value['name'];
  466. $temp['supplierNo'] =$value['supplierNo'];
  467. $temp['contactor_name'] =$value['contactor_name'];
  468. $temp['contactor_id'] =$value['contactor'];
  469. $temp['mobile'] =$value['mobile'];
  470. $temp['wsm_name'] =$value['wsm_name'];
  471. $temp['wsm_mobile'] =$value['wsm_mobile'];
  472. $temp['wsm_addr'] =$value['wsm_addr'];
  473. $temp['addrs_cn'] =GetAddr($value['addrs_code']);
  474. $temp['addr'] =$value['addr'];
  475. $temp['wsm_addr_cn'] =GetAddr($value['addr_code']);
  476. // $supplierinfo = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  477. // $temp['supplier_name'] = isset($supplierinfo['name']) ? $supplierinfo['name'] :"";
  478. $temp['companyNo'] = $value['companyNo'];
  479. $value['company_name'] = $value['companyName'];//$tmp[$value['companyNo']] ?? '';
  480. // if($value['companyNo']!=""){
  481. // $company = Db::name("business")->where(["companyNo"=>$value['companyNo']])->find();
  482. // $temp['company_name'] = isset($company['company']) ? $company['company'] :"";
  483. // }else{
  484. // $temp['company_name']="";
  485. // }
  486. $type = Db::name("warehouse_type")->where(["id"=>$value['wsm_type']])->find();
  487. $temp['type_name'] = isset($type['name']) ? $type['name'] :"";
  488. $data[]=$temp;
  489. }
  490. return app_show(0,'获取成功',$data);
  491. }
  492. }