Check.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 list()
  23. {
  24. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  25. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  26. $where = ['a.is_del' => 0,'b.is_del'=>0];
  27. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  28. if ($start !="") {
  29. $where = ["a.addtime"=>Db::raw(">= '{$start}'")];
  30. }
  31. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  32. if($end !=""){
  33. $where = ["a.addtime"=>Db::raw("<= '{$end}'")];
  34. }
  35. $check_code = isset($this->post['check_code']) && $this->post['check_code'] !== "" ? trim($this->post['check_code']) : "";
  36. if ($check_code !== "") {
  37. $where['a.check_code'] = $check_code;
  38. }
  39. $wsm_code = isset($this->post['wsm_code ']) && $this->post['wsm_code '] !== "" ? trim($this->post['wsm_code ']) : "";
  40. if ($wsm_code !== "") {
  41. $where['a.wsm_code'] = $wsm_code;
  42. }
  43. $apply_name = isset($this->post['apply_name ']) && $this->post['apply_name '] !== "" ? trim($this->post['apply_name ']) : "";
  44. if ($apply_name !== "") {
  45. $where['a.apply_name'] = $apply_name;
  46. }
  47. $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
  48. if ($type !== "") {
  49. $where['a.type'] = $apply_name;
  50. }
  51. $apply_id = isset($this->post['apply_id ']) && $this->post['apply_id '] !== "" ? intval($this->post['apply_id ']) : "";
  52. if ($apply_id!== "") {
  53. $where['a.apply_id'] = $apply_id;
  54. }
  55. $status= isset($this->post['status ']) && $this->post['status '] !== "" ? intval($this->post['status ']) : "";
  56. if ($status !== "") {
  57. $where['a.status '] = $status;
  58. }
  59. $count = Db::name('good_check')->count();
  60. $total = ceil($count / $size);
  61. $page = $page >= $total ? $page : $total;
  62. $list = Db::name('good_check')->alias('a')->join("warehouse_info b","a.wsm_code = b.wsm_code","left")
  63. ->join("depart_user c","c.uid=a.apply_id","left")
  64. ->join("company_item d","d.id=c.itemid","left")
  65. ->join("supplier v","v.code=b.supplierNo","left")
  66. ->field("a.status,a.apply_id,a.apply_name,a.type,a.addtime,a.wsm_code,a.check_code,b.name,c.itemid,d.name as 'rename',a.id,v.name as 'caname',v.code")->where($where)->page($page,$size)->select();
  67. return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
  68. }
  69. public function goodlist(){
  70. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  71. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  72. $where = ['is_del'=>0];
  73. $check_code = isset($this->post['check_code']) && $this->post['check_code'] !== "" ? intval($this->post['check_code']) : "";
  74. if ($check_code !== "") {
  75. $where['check_code'] = $check_code;
  76. }
  77. $count = Db::name('check_item')->where($where)->count();
  78. $total = ceil($count / $size);
  79. $page = $page >= $total ? $page : $total;
  80. $list = Db::name('check_item')->where($where)->page($page,$size)->select();
  81. return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
  82. }
  83. public function create(){
  84. $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  85. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  86. if($wsm_code==""){
  87. return error_show(1002,"盘点仓库编号不能为空");
  88. }
  89. $type = isset($this->post['type']) && $this->post['type'] !=="" ? intval($this->post['type']) :"";
  90. if($type==""){
  91. return error_show(1002,"盘点类型不能为空");
  92. }
  93. $check_code = makeNo("CK");
  94. $apply_id=GetUserInfo($token);
  95. if(empty($apply_id)||$apply_id['code']!=0){
  96. return error_show(1002,"申请人数据不存在");
  97. }
  98. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  99. $ri= isset($apply_name["data"]['nickname']) ? $apply_name["data"]['nickname'] : "";
  100. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"0";
  101. // $dain=isset($this->post['good']) && $this->post['good'] !=="" ? trim($this->post['good']):"";
  102. // if($type==2){
  103. // if($dain==""||empty($dain)){
  104. // return error_show(1002,"商品不能为空");
  105. // }
  106. // }else{
  107. // if($type==1) {
  108. //
  109. // $dain= Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  110. // ->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")
  111. // ->field("b.type_code,a.good_name")->select();
  112. // //var_dump($dain);
  113. // }
  114. // if($dain==""){
  115. // return error_show(1003,"商品不能为空");
  116. // }
  117. // }
  118. Db::startTrans();
  119. try{
  120. $data=[
  121. "check_code"=>$check_code,
  122. "wsm_code"=>$wsm_code,
  123. "type"=>$type,
  124. "status"=>$status,
  125. "apply_id"=>$rm,
  126. "apply_name"=>$ri,
  127. "is_del"=>0,
  128. "addtime"=>date('Y-m-d H:i:s'),
  129. "updatetime"=>date("Y-m-d H:i:s")
  130. ];
  131. $da= Db::name('good_check')->insert($data,true);
  132. // $dio=[];
  133. // if($da>0){
  134. // foreach ($dain as $value){
  135. // $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  136. // ->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")
  137. // ->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();
  138. //
  139. // $temp=[];
  140. // $temp['good_name']=$st['good_name'];
  141. // $temp['origin_price']=$st['original_price'];
  142. // $temp['good_type_code']=$st['good_type_code'];
  143. // $temp['origin_num']=$st['usable_stock'];
  144. // $temp['check_num']=0;
  145. // $temp['diff_num']=0;
  146. // $temp['status']=0;
  147. // $temp['remark']="";
  148. // $temp['is_del']=0;
  149. // $temp['check_time']=date('Y-m-d H:i:s');
  150. // $temp['check_code']=$check_code;
  151. // $temp['addtime']=date("Y-m-d H:i:s");
  152. // $temp['updatetime']=date("Y-m-d H:i:s");
  153. // $dio[] =$temp;
  154. // }
  155. // $in= Db::name('check_item')->insertAll($dio);
  156. // }
  157. if($da){
  158. Db::commit();
  159. return error_show(0,"盘点创建成功");
  160. }else{
  161. Db::rollback();
  162. return error_show(1002,"创建失败");
  163. }
  164. }catch (\Exception $e){
  165. Db::rollback();
  166. return error_show(1005,$e->getMessage());
  167. }
  168. }
  169. public function info(){
  170. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  171. if($id==""){
  172. return error_show(1002,"盘点单号不能为空");
  173. }
  174. $temp=[];
  175. $temp['good_name']="";
  176. $temp['origin_price']="";
  177. $temp['good_type_code']="";
  178. $temp['origin_num']=0;
  179. $temp['check_num']=0;
  180. $temp['diff_num']=0;
  181. $temp['status']=0;
  182. $temp['remark']="";
  183. $temp['is_del']=0;
  184. $temp['check_time']=date('Y-m-d H:i:s');
  185. $temp['addtime']=date("Y-m-d H:i:s");
  186. $temp['updatetime']=date("Y-m-d H:i:s");
  187. $fo = Db::name('good_check')->where(['id'=>$id,'is_del'=>0])->find();
  188. $fi = Db::name('check_item')->where(['check_code'=>$fo['check_code'],'is_del'=>0])->select();
  189. $fo['item']=$fi;
  190. if(empty($fo)){
  191. return error_show(1002,"未找到盘点编号");
  192. }else{
  193. return app_show(0,"获取成功",$fo);
  194. }
  195. }
  196. public function edit()
  197. {
  198. $token =isset($this->post['token']) && $this->post['token'] !=="" ? trim($this->post['token']) :"";
  199. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  200. $eid = Db::name('good_check')->where(['id' => $id, 'is_del' => 0])->find();
  201. if ($eid ==="") {
  202. return error_show(1002, "未找到盘点编号信息");
  203. }
  204. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  205. if ($wsm_code == "") {
  206. return error_show(1002, "盘点仓库不能为空");
  207. }
  208. $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
  209. if ($type == "") {
  210. return error_show(1002, "盘点类型不能为空");
  211. }
  212. $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code'] !== "" ? trim($this->post['good_type_code']) : "";
  213. if ($good_type_code == "") {
  214. return error_show(1002, "商品属性不能为空");
  215. }
  216. $apply_id=GetUserInfo($token);
  217. if(empty($apply_id)||$apply_id['code']!=0){
  218. return error_show(1002,"申请人数据不存在");
  219. }
  220. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  221. $ri= isset($apply_name["data"]['nickname']) ? $apply_name["data"]['nickname'] : "";
  222. // $dain=isset($this->post['good']) && $this->post['good'] !=="" ? $this->post['good']:"";
  223. // if($type==2){
  224. // // var_dump($dain);
  225. // if($dain==""||empty($dain)){
  226. // return error_show(1002,"商品不能为空");
  227. // }
  228. // }else{
  229. // if($type==1) {
  230. //
  231. // $dain= Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  232. // ->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")
  233. // ->field("b.type_code,a.good_name")->select();
  234. // //var_dump($dain);
  235. // }
  236. // if($dain==""){
  237. // return error_show(1003,"商品不能为空");
  238. // }
  239. // }
  240. Db::startTrans();
  241. try {
  242. $var = [
  243. "wsm_code" => $wsm_code,
  244. "type" => $type,
  245. "apply_id" => $rm,
  246. "apply_name" => $ri,
  247. "updatetime" => date("Y-m-d H:i:s")
  248. ];
  249. $up = Db::name('good_check')->where(['id'=>$id,'is_del' => 0])->save($var);
  250. // $dn =[];
  251. // if($up>0){
  252. // foreach ($dain as $value){
  253. // $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  254. // ->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")
  255. // ->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();
  256. // $temp=[];
  257. // $temp['good_name']=$st['good_name'];
  258. // $temp['origin_price']=$st['original_price'];
  259. // $temp['good_type_code']=$st['good_type_code'];
  260. // $temp['origin_num']=$st['usable_stock'];
  261. // $temp['check_num']=0;
  262. // $temp['diff_num']=0;
  263. // $temp['status']=0;
  264. // $temp['remark']="";
  265. // $temp['is_del']=0;
  266. // $temp['check_time']=date('Y-m-d H:i:s');
  267. // $temp['check_code']=$eid['check_code'];
  268. // $temp['addtime']=date("Y-m-d H:i:s");
  269. // $temp['updatetime']=date("Y-m-d H:i:s");
  270. // $dn[] =$temp;
  271. // }
  272. // $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')]);
  273. // $io = db::name('check_item')->insertAll($up);
  274. // var_dump(Db::name('check_item')->getLastSql());
  275. if ($up) {
  276. Db::commit();
  277. return error_show(0, "盘点更新成功");
  278. }
  279. Db::rollback();
  280. return error_show(1003,"盘点更新失败");
  281. } catch (\Exception $e) {
  282. Db::rollback();
  283. return error_show(1005, $e->getMessage());
  284. }
  285. }
  286. public function dell(){
  287. $id = $this->post['id'] && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  288. if($id===""){
  289. return error_show(1004,"参数id不能为空");
  290. }
  291. $deln= Db::name('good_check')->where(['id'=>$id,'is_del'=>0])->find();
  292. if(empty($deln)){
  293. return error_show(1002,"未找到数据");
  294. }
  295. $sv = Db::name('good_check')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  296. if($sv){
  297. return error_show(0,"删除成功");
  298. }else{
  299. return error_show(1002,"删除失败");
  300. }
  301. }
  302. }