Purch.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\facade\Db;
  5. class Purch extends \app\BaseController
  6. {
  7. public $post="";
  8. public function __construct(App $app)
  9. {
  10. parent::__construct($app);
  11. $this->post=$this->request->post();
  12. }
  13. public function list(){
  14. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  15. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  16. $where =[['is_del',"=",0]];
  17. $bkcode = isset($this->post['bk_code']) && $this->post['bk_code']!="" ? trim($this->post['bk_code']):"";
  18. if($bkcode!=""){
  19. $where[]=['bkcode',"=", $bkcode];
  20. }
  21. $status = isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  22. if($status!==""){
  23. // $where['status'] = $status;
  24. $where[]=['status',"=", $status];
  25. }
  26. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo'])
  27. :"";
  28. if($cgdNo!=""){
  29. //$where['cgdNo'] = Db::Raw("like '%{$cgdNo}%'");
  30. $where[]=['cgdNo',"like", "%{$cgdNo}%"];
  31. }
  32. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']):"";
  33. if($apply_name!=""){
  34. // $where['cgder'] =Db::Raw("like '%{$apply_name}%'");
  35. $where[]=['cgder',"like", "%{$apply_name}%"];
  36. }
  37. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  38. if($wsm_code!=""){
  39. // $where['wsm_code'] = $wsm_code;
  40. $where[]=['wsm_code',"=", $wsm_code];
  41. }
  42. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name']):"";
  43. if($good_name!=""){
  44. //$where['good_name'] = Db::raw(" like %{$good_name}%");
  45. $where[]=['good_name',"like", "%{$good_name}%"];
  46. }
  47. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code'])
  48. :"";
  49. if($good_code!=""){
  50. // $where['good_code'] = Db::raw(" like %{$good_code}%");
  51. $where[]=['good_code',"like", "%{$good_code}%"];
  52. }
  53. $start = isset($this->post['start']) && $this->post['start']!="" ?$this->post['start']:"";
  54. if($start!=""){
  55. // $where['addtime'] = Db::raw(" >= '{$start}'");
  56. $where[]=['addtime',">=", $start];
  57. }
  58. $end = isset($this->post['end']) && $this->post['end']!="" ?$this->post['end']:"";
  59. if($end!=""){
  60. $where[]=['addtime',"<=", $end];
  61. }
  62. $last_start = isset($this->post['last_start']) && $this->post['last_start']!="" ?$this->post['last_start']:"";
  63. if($last_start!=""){
  64. //$where['lasttime'] = Db::raw(" >= '{$last_start}'");
  65. $where[]=['lasttime',">=", $last_start];
  66. }
  67. $last_end = isset($this->post['last_end']) && $this->post['last_end']!="" ?$this->post['last_end']:"";
  68. if($last_end!=""){
  69. //$where['lasttime'] = Db::raw(" <= '{$last_end}'");
  70. $where[]=['lasttime',"<=", $last_end];
  71. }
  72. $count=Db::name("purchease_order")->where($where)->count();
  73. $total = ceil($count/$size);
  74. $page = $page >= $total ? $total : $page;
  75. $list = Db::name("purchease_order")->where($where)->page($page,$size)->order("addtime desc")->select();
  76. $data=[];
  77. foreach ($list as $value){
  78. $value['wsm_name']="";
  79. if($value['wsm_code']!=""){
  80. $ware = Db::name("warehouse_info")->where(["wsm_code"=>$value['wsm_code'],"is_del"=>0])->find();
  81. $value['wsm_name']=isset($ware['name'])? $ware['name']: "";
  82. }
  83. $data[]=$value;
  84. }
  85. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  86. }
  87. public function info(){
  88. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  89. if($cgdNo==""){
  90. return error_show(1004,"参数cgdNo 不能为空");
  91. }
  92. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  93. if(empty($data)){
  94. return error_show(1004,"未找到数据");
  95. }
  96. $data['wsm_name']="";
  97. if($data['wsm_code']!=""){
  98. $ware = Db::name("warehouse_info")->where(["wsm_code"=>$data['wsm_code'],"is_del"=>0])->find();
  99. $data['wsm_name']=isset($ware['name'])? $ware['name']: "";
  100. }
  101. return app_show(0,"获取成功",$data);
  102. }
  103. public function edit(){
  104. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  105. if($cgdNo==""){
  106. return error_show(1004,"参数cgdNo 不能为空");
  107. }
  108. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  109. if(empty($data)){
  110. return error_show(1004,"未找到数据");
  111. }
  112. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!=""? trim($this->post['wsm_code']):"";
  113. if($wsm_code==""){
  114. return error_show(1004,"参数wsm_code 不能为空");
  115. }
  116. $ware = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code,"is_del"=>0])->find();
  117. if(empty($ware)){
  118. return error_show(1004,"未找到仓库信息");
  119. }
  120. $data['wsm_code'] = $wsm_code;
  121. $data['updatetime'] =date("Y-m-d H:i:s");
  122. $upd=Db::name("purchease_order")->save($data);
  123. return $upd?app_show(0,"更新成功"):error_show(1004,'更新失败');
  124. }
  125. public function status(){
  126. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  127. if($cgdNo==""){
  128. return error_show(1004,"参数cgdNo 不能为空");
  129. }
  130. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  131. if(empty($data)){
  132. return error_show(1004,"未找到数据");
  133. }
  134. $remark= isset($this->post['remark']) && $this->post['remark']!="" ?trim($this->post['remark']):"";
  135. $status = isset($this->post['status'])&&$this->post['status']!=""? intval($this->post['status']):"";
  136. if($status==""){
  137. return error_show(1004,"参数status 不能为空");
  138. }
  139. $data['status'] = $status;
  140. $data['remark'] = $remark;
  141. $data['updatetime'] =date("Y-m-d H:i:s");
  142. $upd=Db::name("purchease_order")->save($data);
  143. return $upd?app_show(0,"更新成功"):error_show(1004,'更新失败');
  144. }
  145. }