Goodup.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Goodup 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. $page = isset($this->post['page']) && $this->post['page'] !==""? intval($this->post['page']):"1";
  16. $size = isset($this->post['size']) && $this->post['size'] !==""? intval($this->post['size']):"10";
  17. $where =[["is_del","=",0]];
  18. $cat_id = isset($this->post['cat_id']) && $this->post['cat_id'] !=="" ? trim($this->post['cat_id']):"";
  19. if($cat_id!==""){
  20. $where[]=['cat_id',"=",$cat_id];
  21. }
  22. $good_name = isset($this->post['good_name']) && $this->post['good_name'] !=="" ? trim($this->post['good_name']):"";
  23. if($good_name!==""){
  24. $where[]=['good_name',"like","$good_name"];
  25. }
  26. $good_code = isset($this->post['good_code']) && $this->post['good_code'] !=="" ? trim($this->post['good_code']):"";
  27. if($good_code!==""){
  28. $where [] = ['good_code',"like",$good_code];
  29. }
  30. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  31. if($start!==""){
  32. $where[]=['addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  33. }
  34. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  35. if($end!==""){
  36. $where[]=['addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  37. }
  38. $count = Db::name('good')->where($where)->count();
  39. $total = ceil($count / $size);
  40. $page = $page >= $total ? $total : $page;
  41. $list = Db::name('good')->where($where)->page($page,$size)->order("addtime desc")->select();
  42. return app_show(0,"获取成功",['list'=>$list,'count'=>$count]);
  43. }
  44. }