Check.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Check extends BaseController
  7. {
  8. public $post = "";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post=$this->request->post();
  13. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  14. if($token==""){
  15. return error_show(101,'token不能为空');
  16. }
  17. $effetc = VerifyTokens($token);
  18. if(!empty($effetc) && $effetc['code']!=0){
  19. return error_show($effetc['code'],$effetc['message']);
  20. }
  21. }
  22. public function flist(){
  23. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  24. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  25. $condtion=['a.is_del'=>0,'b.is_del'=>0];
  26. $wsmcode =isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  27. if($wsmcode==""){
  28. return error_show(1002,"仓库code不能为空");
  29. // $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
  30. }
  31. $condtion['c.wsm_code']=$wsmcode;
  32. $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  33. if($good_code!=""){
  34. $condtion['b.type_code'] = $good_code;
  35. }
  36. $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
  37. :"";
  38. if($goodcode!=""){
  39. $condtion['a.good_code'] = Db::raw("like '%{$goodcode}%'");
  40. }
  41. $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
  42. :"";
  43. if($good_name!=""){
  44. $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
  45. }
  46. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  47. if($supplierNo!=""){
  48. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  49. if(empty($supplier)){
  50. return error_show(1004,"未找到供应商信息");
  51. }
  52. // $typecode = Db::name("good_stock")->alias("a")->join("warehouse_info b","a.wsm_code=b.wsm_code","left")->where(["a.is_del"=>0,
  53. // "b.is_del"=>0,"b.supplierNo"=>$supplierNo])->column("a.good_type_code");
  54. // if(empty($typecode)){
  55. // return error_show(1004,"未找到供应商有关的商品信息");
  56. // }
  57. $condtion["a.gys_code"] = $supplierNo;
  58. }
  59. $count = Db::name("good_type")->alias("b")
  60. ->join("good a","a.good_code = b.good_code","left")
  61. ->join("good_stock c","c.good_type_code=b.type_code","left")
  62. ->where($condtion)->count();
  63. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  64. $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  65. ->join("good_stock c","c.good_type_code=b.type_code","left")
  66. ->where($condtion)->field("b.id,a.good_code,a.good_name,a.good_desc,a.brand,a.original_price,a.cg_saler,a.good_type,a.market_fee,a.gys_code,a.unit,
  67. a.sort_f,a.sort_s,a.sort_t,b.color,b.material,b.specs,b.is_main,b.type_code,b.attribute,b.status as bstatus,a.addtime,c.usable_stock,a.updatetime")
  68. ->page($page,$size)->select();
  69. $data=[];
  70. foreach ($list as $key=>$value){
  71. //$stock = Db::name("good_stock")->where(["good_type_code"=>$value['type_code'],"is_del"=>0])->sum("usable_stock");
  72. //$value['usable_stock']=$stock;
  73. $supplier = Db::name("supplier")->where(["code"=>$value['gys_code']])->find();
  74. $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
  75. $data[]=$value;
  76. }
  77. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  78. }
  79. public function list()
  80. {
  81. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  82. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  83. $where = ['a.is_del' => 0,'b.is_del'=>0];
  84. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  85. if ($start !="") {
  86. $where["a.addtime"]=Db::raw(">= '{$start}'");
  87. }
  88. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  89. if($end !=""){
  90. $where["a.addtime"] = Db::raw("<= '{$end}'");
  91. }
  92. $check_code = isset($this->post['check_code']) && $this->post['check_code'] !== "" ? trim($this->post['check_code']) : "";
  93. if ($check_code !== "") {
  94. $where['a.check_code'] = Db::raw("like '%$check_code%'");
  95. }
  96. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  97. if ($wsm_code !== "") {
  98. $where['a.wsm_code'] = Db::raw("like '%$wsm_code%'");
  99. }
  100. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name']) : "";
  101. if ($apply_name !== "") {
  102. $where['a.apply_name'] = $apply_name;
  103. }
  104. $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
  105. if ($type !== "") {
  106. $where['a.type'] = $type;
  107. }
  108. $apply_id = isset($this->post['apply_id']) && $this->post['apply_id'] !== "" ? intval($this->post['apply_id']) : "";
  109. if ($apply_id!== "") {
  110. $where['a.apply_id'] = $apply_id;
  111. }
  112. $status= isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  113. if ($status !== "") {
  114. $where['a.status '] = $status;
  115. }
  116. $count = Db::name('good_check')->alias('a')->join("warehouse_info b","a.wsm_code = b.wsm_code","left")
  117. ->join("supplier v","v.code=b.supplierNo","left")
  118. ->where($where)->count();
  119. $total = ceil($count / $size);
  120. $page = $page <= $total ? $page : $total;
  121. $list = Db::name('good_check')->alias('a')->join("warehouse_info b","a.wsm_code = b.wsm_code","left")
  122. ->join("supplier v","v.code=b.supplierNo","left")
  123. ->field("a.status,a.apply_id,a.apply_name,a.type,a.addtime,a.wsm_code,a.check_code,b.name,a.id,v.name as 'caname',v.code")->where($where)->page($page,$size)->order("a.id desc")->select();
  124. $data=[];
  125. foreach ($list as $key=>$value){
  126. $value['rename'] ='';
  127. if($value['apply_id']!=0){
  128. $depart = Db::name("depart_user")->alias("a")->leftJoin("company_item b","a.itemid = b.id")->where(['a.uid'=>$value['apply_id'],'a.is_del'=>0])
  129. ->column('b.name');
  130. // var_dump(Db::name("depart_user")->getLastSql());
  131. $value['rename'] =implode(",",$depart);
  132. }
  133. $data[] = $value;
  134. }
  135. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  136. }
  137. public function goodlist(){
  138. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  139. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  140. $where = ['is_del'=>0];
  141. $check_code = isset($this->post['check_code']) && $this->post['check_code'] !== "" ? trim($this->post['check_code']) : "";
  142. if ($check_code !== "") {
  143. $where['check_code'] = $check_code;
  144. }
  145. $count = Db::name('check_item')->where($where)->count();
  146. $total = ceil($count / $size);
  147. $page = $page >= $total ? $total: $page;
  148. $list = Db::name('check_item')->where($where)->page($page,$size)->select();
  149. return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
  150. }
  151. public function create(){
  152. $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  153. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  154. if($wsm_code==""){
  155. return error_show(1002,"盘点仓库编号不能为空");
  156. }
  157. $type = isset($this->post['type']) && $this->post['type'] !=="" ? intval($this->post['type']) :"";
  158. if($type==""){
  159. return error_show(1002,"盘点类型不能为空");
  160. }
  161. $check_code = makeNo("CK");
  162. $apply_id=GetUserInfo($token);
  163. if(empty($apply_id)||$apply_id['code']!=0){
  164. return error_show(1002,"申请人数据不存在");
  165. }
  166. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  167. $ri= isset($apply_name["data"]['nickname']) ? $apply_name["data"]['nickname'] : "";
  168. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"0";
  169. // $dain=isset($this->post['good']) && $this->post['good'] !=="" ? trim($this->post['good']):"";
  170. // if($type==2){
  171. // if($dain==""||empty($dain)){
  172. // return error_show(1002,"商品不能为空");
  173. // }
  174. // }else{
  175. // if($type==1) {
  176. //
  177. // $dain= Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  178. // ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
  179. // ->field("b.type_code,a.good_name")->select();
  180. // //var_dump($dain);
  181. // }
  182. // if($dain==""){
  183. // return error_show(1003,"商品不能为空");
  184. // }
  185. // }
  186. Db::startTrans();
  187. try{
  188. $data=[
  189. "check_code"=>$check_code,
  190. "wsm_code"=>$wsm_code,
  191. "type"=>$type,
  192. "status"=>$status,
  193. "apply_id"=>$rm,
  194. "apply_name"=>$ri,
  195. "is_del"=>0,
  196. "addtime"=>date('Y-m-d H:i:s'),
  197. "updatetime"=>date("Y-m-d H:i:s")
  198. ];
  199. $da= Db::name('good_check')->insert($data,true);
  200. // $dio=[];
  201. // if($da>0){
  202. // foreach ($dain as $value){
  203. // $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  204. // ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'good_type_code'=>$value['type_code'],'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
  205. // ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_stock,c.wait_out_stock,c.usable_stock,c.good_type_code,a.original_price")->find();
  206. //
  207. // $temp=[];
  208. // $temp['good_name']=$st['good_name'];
  209. // $temp['origin_price']=$st['original_price'];
  210. // $temp['good_type_code']=$st['good_type_code'];
  211. // $temp['origin_num']=$st['usable_stock'];
  212. // $temp['check_num']=0;
  213. // $temp['diff_num']=0;
  214. // $temp['status']=0;
  215. // $temp['remark']="";
  216. // $temp['is_del']=0;
  217. // $temp['check_time']=date('Y-m-d H:i:s');
  218. // $temp['check_code']=$check_code;
  219. // $temp['addtime']=date("Y-m-d H:i:s");
  220. // $temp['updatetime']=date("Y-m-d H:i:s");
  221. // $dio[] =$temp;
  222. // }
  223. // $in= Db::name('check_item')->insertAll($dio);
  224. // }
  225. if($da){
  226. Db::commit();
  227. return error_show(0,"盘点创建成功");
  228. }else{
  229. Db::rollback();
  230. return error_show(1002,"创建失败");
  231. }
  232. }catch (\Exception $e){
  233. Db::rollback();
  234. return error_show(1005,$e->getMessage());
  235. }
  236. }
  237. public function info(){
  238. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  239. if($id==""){
  240. return error_show(1002,"盘点单号不能为空");
  241. }
  242. $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left")
  243. ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,a.*")
  244. ->where(['a.id'=>$id,'a.is_del'=>0])->find();
  245. if(empty($fo)){
  246. return error_show(1003,"未找到盘点信息");
  247. }
  248. $fi = Db::name('check_item')->where(['check_code'=>$fo['check_code'],'is_del'=>0])->select();
  249. $fo['item']=$fi;
  250. if(empty($fo)){
  251. return error_show(1002,"未找到盘点编号");
  252. }else{
  253. return app_show(0,"获取成功",$fo);
  254. }
  255. }
  256. public function edit()
  257. {
  258. $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  259. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  260. $eid = Db::name('good_check')->where(['id' => $id, 'is_del' => 0])->find();
  261. if ($eid ==="") {
  262. return error_show(1002, "未找到盘点编号信息");
  263. }
  264. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  265. if ($wsm_code == "") {
  266. return error_show(1002, "盘点仓库不能为空");
  267. }
  268. $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
  269. if ($type == "") {
  270. return error_show(1002, "盘点类型不能为空");
  271. }
  272. $apply_id=GetUserInfo($token);
  273. if(empty($apply_id)||$apply_id['code']!=0){
  274. return error_show(1002,"申请人数据不存在");
  275. }
  276. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  277. $ri= isset($apply_name["data"]['nickname']) ? $apply_name["data"]['nickname'] : "";
  278. // $dain=isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
  279. // if($type==2){
  280. // // var_dump($dain);
  281. // if($dain==""||empty($dain)){
  282. // return error_show(1002,"商品不能为空");
  283. // }
  284. // }else{
  285. // if($type==1) {
  286. //
  287. // $dain= Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  288. // ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
  289. // ->field("b.type_code,a.good_name")->select();
  290. // //var_dump($dain);
  291. // }
  292. // if($dain==""){
  293. // return error_show(1003,"商品不能为空");
  294. // }
  295. // }
  296. Db::startTrans();
  297. try {
  298. $var = [
  299. "wsm_code" => $wsm_code,
  300. "type" => $type,
  301. "apply_id" => $rm,
  302. "apply_name" => $ri,
  303. "updatetime" => date("Y-m-d H:i:s")
  304. ];
  305. $up = Db::name('good_check')->where(['id'=>$id,'is_del' => 0])->save($var);
  306. // $dn =[];
  307. // if($up>0){
  308. // foreach ($dain as $value){
  309. // $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  310. // ->join("good_stock c","c.good_type_code = b.type_code","left")->where(['c.wsm_code'=>$wsm_code,'good_type_code'=>$value['type_code'],'b.is_del'=>0,'a.is_del'=>0])->where("c.is_del=0 or c.is_del is null")
  311. // ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_stock,c.wait_out_stock,c.usable_stock,c.good_type_code,a.original_price")->find();
  312. // $temp=[];
  313. // $temp['good_name']=$st['good_name'];
  314. // $temp['origin_price']=$st['original_price'];
  315. // $temp['good_type_code']=$st['good_type_code'];
  316. // $temp['origin_num']=$st['usable_stock'];
  317. // $temp['check_num']=0;
  318. // $temp['diff_num']=0;
  319. // $temp['status']=0;
  320. // $temp['remark']="";
  321. // $temp['is_del']=0;
  322. // $temp['check_time']=date('Y-m-d H:i:s');
  323. // $temp['check_code']=$eid['check_code'];
  324. // $temp['addtime']=date("Y-m-d H:i:s");
  325. // $temp['updatetime']=date("Y-m-d H:i:s");
  326. // $dn[] =$temp;
  327. // }
  328. // $np = Db::name('check_item')->where(['check_code'=>$eid['check_code'],'is_del'=>0])->update(['is_del'=>1,'updatetime'=>date('Y-m-d H:i:s')]);
  329. // $io = db::name('check_item')->insertAll($up);
  330. // var_dump(Db::name('check_item')->getLastSql());
  331. if ($up) {
  332. Db::commit();
  333. return error_show(0, "盘点更新成功");
  334. }
  335. Db::rollback();
  336. return error_show(1003,"盘点更新失败");
  337. } catch (\Exception $e) {
  338. Db::rollback();
  339. return error_show(1005, $e->getMessage());
  340. }
  341. }
  342. public function dell(){
  343. $id = $this->post['id'] && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  344. if($id===""){
  345. return error_show(1004,"参数id不能为空");
  346. }
  347. $deln= Db::name('good_check')->where(['id'=>$id,'is_del'=>0])->find();
  348. if(empty($deln)){
  349. return error_show(1002,"未找到数据");
  350. }
  351. $sv = Db::name('good_check')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  352. if($sv){
  353. return error_show(0,"删除成功");
  354. }else{
  355. return error_show(1002,"删除失败");
  356. }
  357. }
  358. public function statu()
  359. {
  360. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  361. if($id==""){
  362. return error_show(1002,"盘点id不能为空");
  363. }
  364. $stauts = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  365. if($stauts===""){
  366. return error_show(1002,"状态不能为空");
  367. }
  368. $st = Db::name('good_check')->where(['id'=>$id,"is_del"=>0])->find();
  369. if(empty($st)){
  370. return error_show(1002,"盘点信息未找到");
  371. }
  372. $st['status']=$stauts;
  373. $st['updatetime']= date('Y-m-d H:i:s');
  374. $sv = Db::name('good_check')->save($st);
  375. if($sv){
  376. return error_show(0,"状态更新成功");
  377. }else{
  378. return error_show(1002,"状态更新失败");
  379. }
  380. }
  381. public function exportGood(){
  382. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  383. if($id==""){
  384. return error_show(1002,"盘点单号不能为空");
  385. }
  386. $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left")
  387. ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,a.*")
  388. ->where(['a.id'=>$id,'a.is_del'=>0])->find();
  389. if(empty($fo)){
  390. return error_show(1003,"未找到盘点信息");
  391. }
  392. $fi = Db::name('check_item')->where(['check_code'=>$fo['check_code'],'is_del'=>0])->select();
  393. $fo['item']=$fi;
  394. if(empty($fo)){
  395. return error_show(1002,"未找到盘点编号");
  396. }else{
  397. return app_show(0,"获取成功",$fo);
  398. }
  399. }
  400. }