Check.php 32 KB

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