Check.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ProcessOrder;
  4. use app\BaseController;
  5. use think\App;
  6. use think\facade\Db;
  7. use app\admin\model\ActionLog;
  8. class Check extends BaseController
  9. {
  10. public $post = "";
  11. public function __construct(App $app)
  12. {
  13. parent::__construct($app);
  14. $this->post=$this->request->post();
  15. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  16. if($token==""){
  17. return error_show(101,'token不能为空');
  18. }
  19. $effetc = VerifyTokens($token);
  20. if(!empty($effetc) && $effetc['code']!=0){
  21. return error_show($effetc['code'],$effetc['message']);
  22. }
  23. }
  24. public function flist(){
  25. $page = isset($this->post['page']) &&$this->post['page'] !=="" ? intval($this->post['page']):1;
  26. $size = isset($this->post['size']) &&$this->post['size'] !=="" ? intval($this->post['size']):10;
  27. $condtion=[['b.is_del',"=",0],['c.is_del',"=",0]];
  28. $wsmcode =isset($this->post['wsm_code']) &&$this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  29. if($wsmcode!==""){
  30. //return error_show(1002,"仓库code不能为空");
  31. $condtion[]=['c.wsm_code',"=",$wsmcode];
  32. // $typecode= Db::name("good_stock")->where(["wsm_code"=>$wsmcode,'is_del'=>0])->column("good_type_code");
  33. }
  34. // $good_code =isset($this->post['type_code']) &&$this->post['type_code'] !=="" ? trim($this->post['type_code']):"";
  35. // if($good_code!=""){
  36. // $condtion[]=['b.type_code',"=",$good_code];
  37. // }
  38. $goodcode =isset($this->post['good_code']) &&$this->post['good_code'] !=="" ? trim($this->post['good_code'])
  39. :"";
  40. if($goodcode!=""){
  41. // $condtion['a.good_code'] = Db::raw("like '%{$goodcode}%'");
  42. $condtion[]=['b.spuCode',"like","%{$goodcode}%"];
  43. }
  44. $good_name =isset($this->post['good_name']) &&$this->post['good_name'] !=="" ? trim($this->post['good_name'])
  45. :"";
  46. if($good_name!=""){
  47. // $condtion['a.good_name'] = Db::raw("like '%{$good_name}%'");
  48. $condtion[]=['b.good_name',"like","%{$good_name}%"];
  49. }
  50. $supplierNo =isset($this->post['supplierNo']) &&$this->post['supplierNo'] !=="" ? trim($this->post['supplierNo']):"";
  51. if($supplierNo!=""){
  52. $supplier = Db::name("supplier")->where(["code"=>$supplierNo])->find();
  53. if(empty($supplier)){
  54. return error_show(1004,"未找到供应商信息");
  55. }
  56. $wsmcode = Db::name("warehouse_info")->where(["is_del"=>0,"supplierNo"=>$supplierNo])->column("wsm_code");
  57. $condtion[]=['c.wsm_code',"in",$wsmcode];
  58. }
  59. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  60. if ($companyNo !== "") {
  61. $wsmcode = Db::name("warehouse_info")->where(['companyNo'=>$companyNo,"is_del"=>0])->column("wsm_code");
  62. $condition[]=["c.wsm_code","in",$wsmcode];
  63. }
  64. $stock_low =isset($this->post['stock_low']) &&$this->post['stock_low'] !=="" ? intval($this->post['stock_low'])
  65. :"";
  66. if($stock_low!=""){
  67. $condtion[]=['c.usable_stock',">=",$stock_low];
  68. }
  69. $stock_max =isset($this->post['stock_max']) &&$this->post['stock_max'] !=="" ? intval($this->post['stock_max'])
  70. :"";
  71. if($stock_max!=""){
  72. $condtion[]=['c.usable_stock',">=",$stock_max];
  73. }
  74. $stock_up =isset($this->post['stock_up']) &&$this->post['stock_up'] !=="" ? trim($this->post['stock_up'])
  75. :"";
  76. if($stock_up!=""){
  77. $condtion[]=['c.usable_stock',"<=",$stock_up];
  78. }
  79. $warn_low =isset($this->post['warn_low']) &&$this->post['warn_low'] !=="" ? intval($this->post['warn_low'])
  80. :"";
  81. if($warn_low!==""){
  82. $condtion[]=['c.warn_stock',">=",$warn_low];
  83. }
  84. $warn_up =isset($this->post['warn_up']) &&$this->post['warn_up'] !=="" ? intval($this->post['warn_up'])
  85. :"";
  86. if($warn_up!=""){
  87. $condtion[]=['c.warn_stock',"<=",$warn_up];
  88. }
  89. $cat_id =isset($this->post['cat_id']) &&$this->post['cat_id'] !=="" ? intval($this->post['cat_id']) :"";
  90. if($cat_id!=""){
  91. $at = Db::name('cat')->where(['id'=>$cat_id])->find();
  92. if(empty($at)){
  93. return error_show(1004,"未找到分类信息");
  94. }
  95. $cat=manger([$at['id']],$at['level']);
  96. $condtion[]=['b.cat_id',"in",$cat];
  97. }
  98. $count = Db::name("good")->alias("b")
  99. ->join("good_stock c","c.spuCode=b.spuCode","left")
  100. ->where($condtion)->count();
  101. $page>=ceil($count/$size) ? $page=ceil($count/$size) :"";
  102. $list = Db::name("good")->alias("b")
  103. ->join("good_stock c","c.spuCode=b.spuCode","left")
  104. ->where($condtion)->page($page,$size)->select();
  105. $data=[];
  106. foreach ($list as $key=>$value){
  107. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  108. $value['supplier_name'] =isset($supplier['name']) ?$supplier['name'] :"";
  109. $wsmcode = Db::name("warehouse_info")->alias("a")->leftJoin("supplier b","a.supplierNo=b.code")->where(["a.wsm_code"=>$value['wsm_code']])->field("a.name as wsm_name,b.name,b.code")->find();
  110. $value['wsm_name'] =isset($wsmcode['wsm_name']) ? $wsmcode['wsm_name']:"";
  111. $value['wsm_supplier'] =isset($wsmcode['name']) ? $wsmcode['name']:"";
  112. $value['wsm_supplierNo'] =isset($wsmcode['code']) ? $wsmcode['code']:"";
  113. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  114. $data[]=$value;
  115. }
  116. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  117. }
  118. public function list()
  119. {
  120. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  121. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  122. $where = [['a.is_del',"=",0],['b.is_del',"=",0]];
  123. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  124. if ($start !="") {
  125. // $where["a.addtime"]=Db::raw(">= '{$start}'");
  126. $where[]=['a.addtime',">=",$start];
  127. }
  128. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  129. if($end !=""){
  130. // $where["a.addtime"] = Db::raw("<= '{$end}'");
  131. $where[]=['a.addtime',"<=",$end];
  132. }
  133. $check_code = isset($this->post['check_code']) && $this->post['check_code'] !== "" ? trim($this->post['check_code']) : "";
  134. if ($check_code !== "") {
  135. // $where['a.check_code'] = Db::raw("like '%$check_code%'");
  136. $where[]=['a.check_code',"like","%$check_code%"];
  137. }
  138. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  139. if ($wsm_code !== "") {
  140. // $where['a.wsm_code'] = Db::raw("like '%$wsm_code%'");
  141. $where[]=['a.wsm_code',"like","%$wsm_code%"];
  142. }
  143. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !== "" ? trim($this->post['apply_name']) : "";
  144. if ($apply_name !== "") {
  145. // $where['a.apply_name'] = $apply_name;
  146. $where[]=['a.apply_name',"like","%$apply_name%"];
  147. }
  148. $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
  149. if ($type !== "") {
  150. // $where['a.type'] = $type;
  151. $where[]=['a.type',"=",$type];
  152. }
  153. $apply_id = isset($this->post['apply_id']) && $this->post['apply_id'] !== "" ? intval($this->post['apply_id']) : "";
  154. if ($apply_id!== "") {
  155. // $where['a.apply_id'] = $apply_id;
  156. $where[]=['a.apply_id',"=",$apply_id];
  157. }
  158. $status= isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  159. if ($status !== "") {
  160. // $where['a.status '] = $status;
  161. $where[]=['a.status',"=",$status];
  162. }
  163. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  164. if ($companyNo !== "") {
  165. $condition[]=["a.companyNo ","=",$companyNo ];
  166. }
  167. $count = Db::name('good_check')->alias('a')->join("warehouse_info b","a.wsm_code = b.wsm_code","left")
  168. ->join("supplier v","v.code=b.supplierNo","left")
  169. ->where($where)->count();
  170. $total = ceil($count / $size);
  171. $page = $page <= $total ? $page : $total;
  172. $list = Db::name('good_check')->alias('a')->join("warehouse_info b","a.wsm_code = b.wsm_code","left")
  173. ->join("supplier v","v.code=b.supplierNo","left")
  174. ->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();
  175. $data=[];
  176. foreach ($list as $key=>$value){
  177. $value['rename'] ='';
  178. if($value['apply_id']!=0){
  179. $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])
  180. ->column('b.name');
  181. // var_dump(Db::name("depart_user")->getLastSql());
  182. $value['rename'] =implode(",",$depart);
  183. }
  184. $data[] = $value;
  185. }
  186. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  187. }
  188. public function goodlist(){
  189. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  190. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  191. $where = ['is_del'=>0];
  192. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  193. if($id==""){
  194. return error_show(1002,"参数id不能为空");
  195. }
  196. $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left")
  197. ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,a.*")
  198. ->where(['a.id'=>$id,'a.is_del'=>0])->find();
  199. if(empty($fo)){
  200. return error_show(1003,"未找到盘点信息");
  201. }
  202. if ($fo['check_code'] !== "") {
  203. $where['check_code'] = $fo['check_code'];
  204. }
  205. $count = Db::name('check_item')->where($where)->count();
  206. $total = ceil($count / $size);
  207. $page = $page >= $total ? $total: $page;
  208. $list = Db::name('check_item')->where($where)->page($page,$size)->select();
  209. return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
  210. }
  211. public function create(){
  212. $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  213. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  214. if($wsm_code==""){
  215. return error_show(1002,"盘点仓库编号不能为空");
  216. }
  217. $type = isset($this->post['type']) && $this->post['type'] !=="" ? intval($this->post['type']) :"";
  218. if($type==""){
  219. return error_show(1002,"盘点类型不能为空");
  220. }
  221. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) :"";
  222. if($companyNo==""){
  223. return error_show(1002,"参数companyNo不能为空");
  224. }
  225. $company =Db::name("business")->where(['companyNo'=>$companyNo,"is_del"=>0])->find();
  226. if($company==false){
  227. return error_show(1002,"未找到业务公司");
  228. }
  229. $check_code = makeNo("CK");
  230. $apply_id=GetUserInfo($token);
  231. if(empty($apply_id)||$apply_id['code']!=0){
  232. return error_show(1002,"申请人数据不存在");
  233. }
  234. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  235. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  236. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"0";
  237. $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? intval($this->post['remark']) :"";
  238. // $dain=isset($this->post['good']) && $this->post['good'] !=="" ? trim($this->post['good']):"";
  239. // if($type==2){
  240. // if($dain==""||empty($dain)){
  241. // return error_show(1002,"商品不能为空");
  242. // }
  243. // }else{
  244. // if($type==1) {
  245. //
  246. // $dain= Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  247. // ->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")
  248. // ->field("b.type_code,a.good_name")->select();
  249. // //var_dump($dain);
  250. // }
  251. // if($dain==""){
  252. // return error_show(1003,"商品不能为空");
  253. // }
  254. // }
  255. Db::startTrans();
  256. try{
  257. $data=[
  258. "check_code"=>$check_code,
  259. "wsm_code"=>$wsm_code,
  260. "type"=>$type,
  261. "status"=>$status,
  262. "companyNo"=>$companyNo,
  263. "remark"=>$remark,
  264. "apply_id"=>$rm,
  265. "apply_name"=>$ri,
  266. "is_del"=>0,
  267. "addtime"=>date('Y-m-d H:i:s'),
  268. "updatetime"=>date("Y-m-d H:i:s")
  269. ];
  270. $da= Db::name('good_check')->insert($data,true);
  271. // $dio=[];
  272. // if($da>0){
  273. // foreach ($dain as $value){
  274. // $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  275. // ->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")
  276. // ->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();
  277. //
  278. // $temp=[];
  279. // $temp['good_name']=$st['good_name'];
  280. // $temp['origin_price']=$st['original_price'];
  281. // $temp['good_type_code']=$st['good_type_code'];
  282. // $temp['origin_num']=$st['usable_stock'];
  283. // $temp['check_num']=0;
  284. // $temp['diff_num']=0;
  285. // $temp['status']=0;
  286. // $temp['remark']="";
  287. // $temp['is_del']=0;
  288. // $temp['check_time']=date('Y-m-d H:i:s');
  289. // $temp['check_code']=$check_code;
  290. // $temp['addtime']=date("Y-m-d H:i:s");
  291. // $temp['updatetime']=date("Y-m-d H:i:s");
  292. // $dio[] =$temp;
  293. // }
  294. // $in= Db::name('check_item')->insertAll($dio);
  295. // }
  296. if($da){
  297. $orde = ["order_code"=>$check_code,"status"=>$data['status'],"action_remark"=>'',"action_type"=>"create"];
  298. ActionLog::logAdd($this->post['token'],$orde,'qrd',$data['status'],$orde);
  299. $process=["order_code"=>$check_code,"order_id"=>$da,"order_status"=>$data['status'],"order_type"=>'PDD'];
  300. ProcessOrder::AddProcess($this->post['token'],$process);
  301. Db::commit();
  302. return error_show(0,"盘点创建成功");
  303. }else{
  304. Db::rollback();
  305. return error_show(1002,"创建失败");
  306. }
  307. }catch (\Exception $e){
  308. Db::rollback();
  309. return error_show(1005,$e->getMessage());
  310. }
  311. }
  312. public function info(){
  313. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  314. if($id==""){
  315. return error_show(1002,"参数id不能为空");
  316. }
  317. $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left")
  318. ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,a.*")
  319. ->where(['a.id'=>$id,'a.is_del'=>0])->find();
  320. if(empty($fo)){
  321. return error_show(1003,"未找到盘点信息");
  322. }
  323. $fi = Db::name('check_item')->where(['check_code'=>$fo['check_code'],'is_del'=>0])->select();
  324. $fo['item']=$fi;
  325. if(empty($fo)){
  326. return error_show(1002,"未找到盘点编号");
  327. }else{
  328. return app_show(0,"获取成功",$fo);
  329. }
  330. }
  331. public function edit()
  332. {
  333. $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  334. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  335. $eid = Db::name('good_check')->where(['id' => $id, 'is_del' => 0])->find();
  336. if ($eid ==="") {
  337. return error_show(1002, "未找到盘点编号信息");
  338. }
  339. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  340. if ($wsm_code == "") {
  341. return error_show(1002, "盘点仓库不能为空");
  342. }
  343. $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
  344. $remark = isset($this->post['remark']) && $this->post['remark'] !== "" ? trim($this->post['remark']) : "";
  345. if ($type == "") {
  346. return error_show(1002, "盘点类型不能为空");
  347. }
  348. $apply_id=GetUserInfo($token);
  349. if(empty($apply_id)||$apply_id['code']!=0){
  350. return error_show(1002,"申请人数据不存在");
  351. }
  352. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  353. $ri= isset($apply_id["data"]['nickname']) ? $apply_id["data"]['nickname'] : "";
  354. // $dain=isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
  355. // if($type==2){
  356. // // var_dump($dain);
  357. // if($dain==""||empty($dain)){
  358. // return error_show(1002,"商品不能为空");
  359. // }
  360. // }else{
  361. // if($type==1) {
  362. //
  363. // $dain= Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  364. // ->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")
  365. // ->field("b.type_code,a.good_name")->select();
  366. // //var_dump($dain);
  367. // }
  368. // if($dain==""){
  369. // return error_show(1003,"商品不能为空");
  370. // }
  371. // }
  372. Db::startTrans();
  373. try {
  374. $var = [
  375. "wsm_code" => $wsm_code,
  376. "type" => $type,
  377. "apply_id" => $rm,
  378. "apply_name" => $ri,
  379. "remark" => $remark,
  380. "updatetime" => date("Y-m-d H:i:s")
  381. ];
  382. $up = Db::name('good_check')->where(['id'=>$id,'is_del' => 0])->save($var);
  383. // $dn =[];
  384. // if($up>0){
  385. // foreach ($dain as $value){
  386. // $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  387. // ->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")
  388. // ->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();
  389. // $temp=[];
  390. // $temp['good_name']=$st['good_name'];
  391. // $temp['origin_price']=$st['original_price'];
  392. // $temp['good_type_code']=$st['good_type_code'];
  393. // $temp['origin_num']=$st['usable_stock'];
  394. // $temp['check_num']=0;
  395. // $temp['diff_num']=0;
  396. // $temp['status']=0;
  397. // $temp['remark']="";
  398. // $temp['is_del']=0;
  399. // $temp['check_time']=date('Y-m-d H:i:s');
  400. // $temp['check_code']=$eid['check_code'];
  401. // $temp['addtime']=date("Y-m-d H:i:s");
  402. // $temp['updatetime']=date("Y-m-d H:i:s");
  403. // $dn[] =$temp;
  404. // }
  405. // $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')]);
  406. // $io = db::name('check_item')->insertAll($up);
  407. // var_dump(Db::name('check_item')->getLastSql());
  408. if ($up) {
  409. $orde = ["order_code"=>$eid['check_code'],"status"=>$eid['status'],"action_remark"=>'',"action_type"=>"edit"];
  410. ActionLog::logAdd($this->post['token'],$orde,'qrd',$eid['status'],$orde);
  411. Db::commit();
  412. return error_show(0, "盘点更新成功");
  413. }
  414. Db::rollback();
  415. return error_show(1003,"盘点更新失败");
  416. } catch (\Exception $e) {
  417. Db::rollback();
  418. return error_show(1005, $e->getMessage());
  419. }
  420. }
  421. /**
  422. * @return \think\response\Json|void
  423. * @throws \think\db\exception\DataNotFoundException
  424. * @throws \think\db\exception\DbException
  425. * @throws \think\db\exception\ModelNotFoundException
  426. */
  427. public function dell(){
  428. $id = $this->post['id'] && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  429. if($id===""){
  430. return error_show(1004,"参数id不能为空");
  431. }
  432. $deln= Db::name('good_check')->where(['id'=>$id,'is_del'=>0])->find();
  433. if(empty($deln)){
  434. return error_show(1002,"未找到数据");
  435. }
  436. $sv = Db::name('good_check')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  437. if($sv){
  438. $orde = ["order_code"=>$deln['check_code'],"status"=>$deln['status'],"action_remark"=>'',"action_type"=>"delete"];
  439. ActionLog::logAdd($this->post['token'],$orde,'qrd',$deln['status'],['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  440. $process=["order_code"=>$deln['check_code'],"order_status"=>$deln['status'],"order_type"=>'PDD'];
  441. ProcessOrder::workdel($process);
  442. return error_show(0,"删除成功");
  443. }else{
  444. return error_show(1002,"删除失败");
  445. }
  446. }
  447. /**
  448. * @return \think\response\Json|void
  449. * @throws \think\db\exception\DataNotFoundException
  450. * @throws \think\db\exception\DbException
  451. * @throws \think\db\exception\ModelNotFoundException
  452. */
  453. public function statu()
  454. {
  455. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  456. if($id==""){
  457. return error_show(1002,"盘点id不能为空");
  458. }
  459. $stauts = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"";
  460. $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? trim($this->post['remark']) :"";
  461. if($stauts===""){
  462. return error_show(1002,"状态不能为空");
  463. }
  464. $st = Db::name('good_check')->where(['id'=>$id,"is_del"=>0])->find();
  465. if(empty($st)){
  466. return error_show(1002,"盘点信息未找到");
  467. }
  468. Db::startTrans();
  469. try{
  470. $temp = $st['status'];
  471. $st['status']=$stauts;
  472. $st['remark']=$remark;
  473. $st['updatetime']= date('Y-m-d H:i:s');
  474. $sv = Db::name('good_check')->save($st);
  475. if($sv){
  476. $orde = ["order_code"=>$st['check_code'],$temp,"action_remark"=>'',"action_type"=>"status"];
  477. ActionLog::logAdd($this->post['token'],$orde,'PDD',$st['status'],$orde);
  478. if($stauts==1&&$temp==2){
  479. $up = Db::name('check_item')->where(['check_code'=>$st['check_code'],"is_del"=>0])->save(['is_del'=>1,
  480. "updatetime"=>date("Y-m-d H:i:s")]);
  481. if($up==false){
  482. Db::rollback();
  483. return error_show(1003,"盘点结果删除失败");
  484. }
  485. }
  486. if($stauts==2){
  487. $nu = Db::name('check_item')->where(['check_code'=>$st['check_code'],"is_del"=>0])->select()->toArray();
  488. if(empty($nu)){
  489. Db::rollback();
  490. return error_show(1003,"未上传盘点结果");
  491. }
  492. }
  493. $process=["order_code"=>$st['check_code'],"order_id"=>$st['id'],"order_status"=>$stauts,"order_type"=>'PDD'];
  494. ProcessOrder::AddProcess($this->post['token'],$process);
  495. Db::commit();
  496. return error_show(0,"状态更新成功");
  497. }
  498. Db::rollback();
  499. return error_show(1002,"状态更新失败");
  500. }catch (\Exception $e){
  501. Db::rollback();
  502. return error_show(1002,$e->getMessage());
  503. }
  504. }
  505. public function exportGood(){
  506. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  507. if($id==""){
  508. return error_show(1002,"参数id不能为空");
  509. }
  510. $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left")
  511. ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,b.name,a.*")
  512. ->where(['a.id'=>$id,'a.is_del'=>0])->find();
  513. if(empty($fo)){
  514. return error_show(1003,"未找到盘点信息");
  515. }
  516. $list = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  517. ->join("good_stock c","c.good_type_code=b.type_code","left")
  518. ->where(['c.wsm_code'=>$fo['wsm_code'],"a.is_del"=>0,"b.is_del"=>0,"c.is_del"=>0])->field("a.good_code '商品编码',b.type_code '商品属性编码',
  519. a.good_name '商品名称',a.good_desc '商品描述',a.brand '品牌',a.unit '单位',a.gys_code '供应商编码','' as '供应商名称',a.sort_f '一级分类',a.sort_s '二级分类',a.sort_t '三级分类',
  520. a.addtime '新建时间',c.wsm_code '仓库编码','' as '仓库名称',c.usable_stock '可用库存','' as '盘点库存'")
  521. ->select();
  522. $data=[];
  523. foreach ($list as $key=>$value){
  524. $wsm = Db::name("warehouse_info")->where(['wsm_code'=>$value['仓库编码']])->find();
  525. $supplier = Db::name("supplier")->where(["code"=>$value['供应商编码']])->find();
  526. $value['供应商名称'] =isset($supplier['name']) ?$supplier['name'] :"";
  527. $value['仓库名称'] =isset($wsm['name']) ?$wsm['name'] :"";
  528. $data[]=$value;
  529. }
  530. if(empty($data)){
  531. $data[]=["暂无商品信息"=>''];
  532. }
  533. $headerArr= array_keys($data[0]);
  534. excelSave('盘点商品',$headerArr,$data);
  535. // return app_show(0,"获取成功",$data);
  536. }
  537. public function importGood(){
  538. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  539. if($id==""){
  540. return error_show(1002,"参数id不能为空");
  541. }
  542. $fo = Db::name('good_check')->alias('a')->join('warehouse_info b',"b.wsm_code=a.wsm_code","left")
  543. ->join('supplier c',"c.code=b.supplierNo","left")->field("c.name,c.code,b.name,a.*")
  544. ->where(['a.id'=>$id,'a.is_del'=>0])->find();
  545. if(empty($fo)){
  546. return error_show(1003,"未找到盘点信息");
  547. }
  548. if($fo['status']>=2){
  549. return error_show(1003,"盘点已提交审核,不可提交盘点数据");
  550. }
  551. $data = isset($this->post['data']) && $this->post['data'] !=="" ?$this->post['data'] :"";
  552. if($data=="" || empty($data)){
  553. return error_show(1003,"盘点数据不能为空");
  554. }
  555. $insert=[];
  556. foreach ($data as $value){
  557. if($value["value1"]==""){
  558. return error_show(1003,"商品属性code 不能为空");
  559. }
  560. if($value["value15"]===""){
  561. continue;
  562. }
  563. $stock = Db::name("good_stock")->where(["good_type_code"=>$value["value1"],"wsm_code"=>$fo['wsm_code'],
  564. "is_del"=>0])->find();
  565. $stock_num = isset($stock) ? $stock['usable_stock']:0;
  566. $insert[]=[
  567. "good_type_code"=>$value["value1"],
  568. "good_name"=>$value["value2"],
  569. "origin_price"=>0,
  570. "origin_num"=>isset($stock) ? $stock['usable_stock']:0,
  571. "check_num"=>$value["value15"],
  572. "is_profit"=>intval($value["value15"])>=$stock_num ?0:1,
  573. "diff_num"=>intval($value["value15"])>=$stock_num ?intval($value["value15"])-$stock_num:$stock_num-intval($value["value15"]),
  574. 'addtime'=>date("Y-m-d H:i:s"),
  575. 'updatetime'=>date("Y-m-d H:i:s"),
  576. "check_code"=>$fo['check_code']
  577. ];
  578. }
  579. if(empty($insert)){
  580. return error_show(1003,"盘点数据不可用");
  581. }
  582. Db::startTrans();
  583. try{
  584. $inst = Db::name("check_item")->insertAll($insert);
  585. if($inst){
  586. $check_up = Db::name("good_check")->where(["check_code"=>$fo['check_code'],"is_del"=>0])->save(["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  587. if($check_up){
  588. $orde = ["order_code"=>$fo['check_code'],$fo['status'],"action_remark"=>'',"action_type"=>"edit"];
  589. ActionLog::logAdd($this->post['token'],$orde,'PDD',2,["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  590. $process=["order_code"=>$fo['check_code'],"order_id"=>$fo['id'],"order_status"=>2,"order_type"=>'PDD'];
  591. ProcessOrder::AddProcess($this->post['token'],$process);
  592. Db::commit();
  593. return app_show(0,"盘点数据导入成功");
  594. }
  595. }
  596. Db::rollback();
  597. return error_show(1002,"盘点数据导入失败");
  598. }catch (\Exception $e){
  599. Db::rollback();
  600. return error_show(1002,"盘点数据导入失败");
  601. }
  602. }
  603. }