Check.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. }
  14. public function list()
  15. {
  16. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  17. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  18. $where = ['is_del' => 0];
  19. $addtime = isset($this->post['addtime']) && $this->post['addtime'] !== "" ? intval($this->post['addtime']) : "";
  20. if ($addtime !== "") {
  21. $where['check_code'] = $addtime;
  22. }
  23. $check_code = isset($this->post['check_code']) && $this->post['check_code'] !== "" ? intval($this->post['check_code']) : "";
  24. if ($check_code !== "") {
  25. $where['check_code'] = $check_code;
  26. }
  27. $wsm_code = isset($this->post['wsm_code ']) && $this->post['wsm_code '] !== "" ? intval($this->post['wsm_code ']) : "";
  28. if ($wsm_code !== "") {
  29. $where['wsm_code '] = $wsm_code;
  30. }
  31. $status= isset($this->post['status ']) && $this->post['status '] !== "" ? intval($this->post['status ']) : "";
  32. if ($status !== "") {
  33. $where['status '] = $status;
  34. }
  35. $count = Db::name('good_check')->count();
  36. $total = ceil($count / $size);
  37. $page = $page >= $total ? $page : $total;
  38. $list = Db::name('good_check')->field('apply_id,apply_name,type,addtime')->where($where)->page($page,$size)->select();
  39. return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
  40. }
  41. public function goodlist(){
  42. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']) :"1";
  43. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']) :"10";
  44. $where = ['is_del'=>0,'status'=>0];
  45. $count = Db::name('check_item')->count();
  46. $total = ceil($count / $size);
  47. $page = $page >= $total ? $page : $total;
  48. $list = Db::name('check_item')->where($where)->page($page,$size)->select();
  49. return app_show(0,"获取成功",['count'=>$count,'list'=>$list]);
  50. }
  51. // $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code'] !=="" ? $this->post['good_type_code']:"";
  52. // if($good_type_code==""){
  53. // return error_show(1002,"商品属性不能为空");
  54. // }
  55. // $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? $this->post['good_name'] : "";
  56. // if($good_name==""){
  57. // return error_show(1002,"商品名称不能为空");
  58. // }
  59. // $origin_price = isset($this->post['origin_price']) && $this->post['origin_price'] !=="" ? $this->post['origin_price'] :"";
  60. // $origin_num = isset($this->post['origin_num']) && $this->post['origin_num'] !=="" ? $this->post['origin_num'] :"";
  61. // $check_num = isset($this->post['check_num']) && $this->post['check_num'] !=="" ? $this->post['check_num'] :"";
  62. // $diff_num = isset($this->post['diff_num']) && $this->post['diff_num'] !=="" ? $this->post['diff_num'] :"";
  63. // $remark = isset($this->post['remark']) && $this->post['remark'] !=="" ? $this->post['remark'] :"";
  64. // $check_time = isset($this->post['check_time']) && $this->post['check_time'] !=="" ? $this->post['startTime']:date("Y-m-d H:i:s");
  65. public function create(){
  66. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !=="" ? trim($this->post['wsm_code']):"";
  67. if($wsm_code==""){
  68. return error_show(1002,"盘点仓库编号不能为空");
  69. }
  70. $type = isset($this->post['type']) && $this->post['type'] !=="" ? trim($this->post['type']) :"";
  71. if($type==""){
  72. return error_show(1002,"盘点类型不能为空");
  73. }
  74. $check_code = isset($this->post['check_code']) && $this->post['check_code'] !=="" ? trim($this->post['check_code']) : "";
  75. if($check_code==""){
  76. return error_show(1002,"盘点编号不能为空");
  77. }
  78. $apply_id = isset($this->post['apply_id']) && $this->post['apply_id'] !=="" ? trim($this->post['apply_id']):"";
  79. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name'] !=="" ? trim($this->post['apply_name']):"";
  80. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']) :"0";
  81. $dain=isset($this->post['good']) && $this->post['good'] !=="" ? trim($this->post['good']):"";
  82. if($type===2){
  83. if($dain==""||empty($dain)){
  84. return error_show(1002,"商品不能为空");
  85. }
  86. }else{
  87. if($type===1) {
  88. $do = Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  89. ->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")
  90. ->field("b.type_code,a.good_name")->select();
  91. }
  92. }
  93. Db::startTrans();
  94. try{
  95. $data=[
  96. "check_code"=>$check_code,
  97. "wsm_code"=>$wsm_code,
  98. "type"=>$type,
  99. "status"=>$status,
  100. "apply_id"=>$apply_id,
  101. "apply_name"=>$apply_name,
  102. "is_del"=>0,
  103. "addtime"=>date('Y-m-d H:i:s'),
  104. "updatetime"=>date("Y-m-d H:i:s")
  105. ];
  106. $da= Db::name('good_check')->insert($data,true);
  107. $dain=[];
  108. if($da>0){
  109. foreach ($do as $value){
  110. $st=Db::name("good_type")->alias("b")->join("good a","a.good_code = b.good_code","left")
  111. ->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")
  112. ->field("b.type_code,a.good_name,c.wsm_code,c.wait_in_")->select();
  113. $dain[] =$value;
  114. }
  115. $in= Db::name('check_item')->insertAll($dain);
  116. }
  117. if($in){
  118. Db::commit();
  119. return error_show(0,"盘点创建成功");
  120. }else{
  121. Db::rollback();
  122. return error_show(1002,"创建失败");
  123. }
  124. }catch (\Exception $e){
  125. Db::rollback();
  126. return error_show(1005,$e->getMessage());
  127. }
  128. }
  129. public function info(){
  130. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  131. if($id==""){
  132. return error_show(1002,"盘点单号不能为空");
  133. }
  134. $fo = Db::name('good_check')->where(['id'=>$id,'is_del'=>0])->find();
  135. if(empty($fo)){
  136. return error_show(1002,"未找到盘点编号");
  137. }else{
  138. return app_show(0,"获取成功",$fo);
  139. }
  140. }
  141. public function edit()
  142. {
  143. $id = isset($this->post['id']) && $this->post['id'] !== "" ? intval($this->post['id']) : "";
  144. $eid = Db::name('good_check')->where(['id' => $id, 'is_del' => 0])->find();
  145. if ($eid ==="") {
  146. return error_show(1002, "未找到盘点编号信息");
  147. }
  148. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code'] !== "" ? trim($this->post['wsm_code']) : "";
  149. if ($wsm_code == "") {
  150. return error_show(1002, "盘点仓库不能为空");
  151. }
  152. $type = isset($this->post['type']) && $this->post['type'] !== "" ? trim($this->post['type']) : "";
  153. if ($type == "") {
  154. return error_show(1002, "盘点类型不能为空");
  155. }
  156. $good_type_code = isset($this->post['good_type_code']) && $this->post['good_type_code'] !== "" ? trim($this->post['good_type_code']) : "";
  157. if ($good_type_code == "") {
  158. return error_show(1002, "商品属性不能为空");
  159. }
  160. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !== "" ? trim($this->post['good_name']) : "";
  161. if ($good_name == "") {
  162. return error_show(1002, "商品名称不能为空");
  163. }
  164. $check_code = isset($this->post['check_code']) && $this->post['check_code'] !== "" ? trim($this->post['check_code']) : "";
  165. if ($check_code == "") {
  166. return error_show(1002, "盘点编号不能为空");
  167. }
  168. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  169. Db::startTrans();
  170. try {
  171. $var = [
  172. "id" => $id,
  173. "check_code" => $check_code,
  174. "wsm_code" => $wsm_code,
  175. "type" => $type,
  176. "status" => $status,
  177. "is_del" => 0,
  178. "updatetime" => date("Y-m-d H:i:s")
  179. ];
  180. $up = Db::name('good_check')->where(['id'=>$id,'is_del' => 0])->save($var);
  181. if($up){
  182. $varn = [
  183. "good_type_code" => $good_type_code,
  184. "good_name" => $good_name,
  185. "status" => $status,
  186. // "check_time" => $check_time,
  187. "is_del" => 0,
  188. "updatetime" => date("Y-m-d H:i:s")
  189. ];
  190. $np = Db::name('check_item')->where(["id"=>$eid['id']])->save($varn);
  191. //var_dump(Db::name('check_item')->getLastSql());
  192. if ($np) {
  193. Db::commit();
  194. return error_show(0, "盘点更新成功");
  195. } else {
  196. Db::rollback();
  197. return error_show(1002, "盘点更新失败");
  198. }
  199. }
  200. } catch (\Exception $e) {
  201. Db::rollback();
  202. return error_show(1005, $e->getMessage());
  203. }
  204. }
  205. public function dell(){
  206. $id = $this->post['id'] && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  207. if($id===""){
  208. return error_show(1004,"参数id不能为空");
  209. }
  210. $deln= Db::name('good_check')->where(['id'=>$id,'is_del'=>0])->find();
  211. if(empty($deln)){
  212. return error_show(1002,"未找到数据");
  213. }
  214. $sv = Db::name('good_check')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  215. if($sv){
  216. return error_show(0,"删除成功");
  217. }else{
  218. return error_show(1002,"删除失败");
  219. }
  220. }
  221. }