MateGoodsLog.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. class MateGoodsLog extends Auth
  6. {
  7. public function __construct(App $app = null) {
  8. parent::__construct($app);
  9. $this->model = new \app\common\model\MateGoodsLog();
  10. $this->table = $this->model->table;
  11. }
  12. public function index(){
  13. if(request()->isAjax()){
  14. //分页参数
  15. $length = input('rows',10,'intval'); //每页条数
  16. $page = input('page',1,'intval'); //第几页
  17. $start = ($page - 1) * $length; //分页开始位置
  18. //排序
  19. $sortRow = input('sidx','sort','trim'); //排序列
  20. $sort = input('sord','asc','trim'); //排序方式
  21. $order = $sortRow.' '.$sort.' ,id desc';
  22. $title = input('title','','trim');
  23. if($title){
  24. $goods_id = db('mate_goods')
  25. ->where('title','like','%'.$title.'%')
  26. ->column('id');
  27. $map[] = ['goods_id','in',$goods_id];
  28. }
  29. $enable = input('enable','','trim');
  30. if($enable != ''){
  31. $map[] = ['enable','=',$enable];
  32. }
  33. $map[] = ['org_id','=',$this->orgId];
  34. $map= empty($map) ? true: $map;
  35. //数据查询
  36. $lists =db($this->table)
  37. ->where($map)->limit($start,$length)
  38. ->order($order)->select();
  39. foreach ($lists as $k=>$v){
  40. $lists[$k]['title'] = db('mate_goods')
  41. ->where('id',$v['goods_id'])
  42. ->value('title');
  43. $lists[$k]['userName'] = db('user')
  44. ->where('id',$v['user_id'])
  45. ->value('real_name');
  46. }
  47. //数据返回
  48. $totalCount = db($this->table)->where($map)->count();
  49. $totalPage = ceil($totalCount/$length);
  50. $result['page'] = $page;
  51. $result['total'] = $totalPage;
  52. $result['records'] = $totalCount;
  53. $result['rows'] = $lists;
  54. return json($result);
  55. }else{
  56. $this->assign('meta_title','处置记录');
  57. return $this->fetch();
  58. }
  59. }
  60. }