Purch.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. }
  25. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ? trim($this->post['cgdNo'])
  26. :"";
  27. if($cgdNo!=""){
  28. $where['cgdNo'] = Db::Raw("like '%{$cgdNo}%'");
  29. }
  30. $apply_name = isset($this->post['apply_name']) && $this->post['apply_name']!="" ? trim($this->post['apply_name']):"";
  31. if($apply_name!=""){
  32. $where['cgder'] =Db::Raw("like '%{$apply_name}%'");
  33. }
  34. $wsm_code = isset($this->post['wsm_code']) && $this->post['wsm_code']!="" ? trim($this->post['wsm_code']):"";
  35. if($wsm_code!=""){
  36. $where['wsm_code'] = $wsm_code;
  37. }
  38. $good_name = isset($this->post['good_name']) && $this->post['good_name']!="" ? trim($this->post['good_name']):"";
  39. if($good_name!=""){
  40. $where['good_name'] = Db::raw(" like %{$good_name}%");
  41. }
  42. $good_code = isset($this->post['good_code']) && $this->post['good_code']!="" ? trim($this->post['good_code'])
  43. :"";
  44. if($good_code!=""){
  45. $where['good_code'] = Db::raw(" like %{$good_code}%");
  46. }
  47. $start = isset($this->post['start']) && $this->post['start']!="" ?$this->post['start']:"";
  48. if($start!=""){
  49. $where['addtime'] = Db::raw(" >= '{$start}'");
  50. }
  51. $end = isset($this->post['end']) && $this->post['end']!="" ?$this->post['end']:"";
  52. if($end!=""){
  53. $where['addtime'] = Db::raw(" <= '{$end}'");
  54. }
  55. $last_start = isset($this->post['last_start']) && $this->post['last_start']!="" ?$this->post['last_start']:"";
  56. if($last_start!=""){
  57. $where['lasttime'] = Db::raw(" >= '{$last_start}'");
  58. }
  59. $last_end = isset($this->post['last_end']) && $this->post['last_end']!="" ?$this->post['last_end']:"";
  60. if($last_end!=""){
  61. $where['lasttime'] = Db::raw(" <= '{$last_end}'");
  62. }
  63. $count=Db::name("purchease_order")->where($where)->count();
  64. $total = ceil($count/$size);
  65. $page = $page >= $total ? $total : $page;
  66. $list = Db::name("purchease_order")->where($where)->page($page,$size)->order("addtime desc")->select();
  67. $data=[];
  68. foreach ($list as $value){
  69. $value['wsm_name']="";
  70. if($value['wsm_code']!=""){
  71. $ware = Db::name("warehouse_info")->where(["wsm_code"=>$value['wsm_code'],"is_del"=>0])->find();
  72. $value['wsm_name']=isset($ware['name'])? $ware['name']: "";
  73. }
  74. $data[]=$value;
  75. }
  76. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  77. }
  78. public function info(){
  79. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  80. if($cgdNo==""){
  81. return error_show(1004,"参数cgdNo 不能为空");
  82. }
  83. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  84. if(empty($data)){
  85. return error_show(1004,"未找到数据");
  86. }
  87. $data['wsm_name']="";
  88. if($data['wsm_code']!=""){
  89. $ware = Db::name("warehouse_info")->where(["wsm_code"=>$data['wsm_code'],"is_del"=>0])->find();
  90. $data['wsm_name']=isset($ware['name'])? $ware['name']: "";
  91. }
  92. return app_show(0,"获取成功",$data);
  93. }
  94. public function edit(){
  95. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  96. if($cgdNo==""){
  97. return error_show(1004,"参数cgdNo 不能为空");
  98. }
  99. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  100. if(empty($data)){
  101. return error_show(1004,"未找到数据");
  102. }
  103. $wsm_code = isset($this->post['wsm_code'])&&$this->post['wsm_code']!=""? trim($this->post['wsm_code']):"";
  104. if($wsm_code==""){
  105. return error_show(1004,"参数wsm_code 不能为空");
  106. }
  107. $ware = Db::name("warehouse_info")->where(["wsm_code"=>$wsm_code,"is_del"=>0])->find();
  108. if(empty($ware)){
  109. return error_show(1004,"未找到仓库信息");
  110. }
  111. $data['wsm_code'] = $wsm_code;
  112. $data['updatetime'] =date("Y-m-d H:i:s");
  113. $upd=Db::name("purchease_order")->save($data);
  114. return $upd?app_show(0,"更新成功"):error_show(1004,'更新失败');
  115. }
  116. public function status(){
  117. $cgdNo = isset($this->post['cgdNo']) && $this->post['cgdNo']!="" ?trim($this->post['cgdNo']):"";
  118. if($cgdNo==""){
  119. return error_show(1004,"参数cgdNo 不能为空");
  120. }
  121. $data = Db::name("purchease_order")->where(["cgdNo"=>$cgdNo,"is_del"=>0])->find();
  122. if(empty($data)){
  123. return error_show(1004,"未找到数据");
  124. }
  125. $remark= isset($this->post['remark']) && $this->post['remark']!="" ?trim($this->post['remark']):"";
  126. $status = isset($this->post['status'])&&$this->post['status']!=""? intval($this->post['status']):"";
  127. if($status==""){
  128. return error_show(1004,"参数status 不能为空");
  129. }
  130. $data['status'] = $status;
  131. $data['remark'] = $remark;
  132. $data['updatetime'] =date("Y-m-d H:i:s");
  133. $upd=Db::name("purchease_order")->save($data);
  134. return $upd?app_show(0,"更新成功"):error_show(1004,'更新失败');
  135. }
  136. }