Check.php 14 KB

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