Check.php 13 KB

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