Member.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\admin;
  4. use library\basic\BaseModel;
  5. use library\traits\JwtAuthModelTrait;
  6. use library\traits\ModelTrait;
  7. use think\Model;
  8. /**
  9. * @mixin \think\Model
  10. */
  11. class Member extends BaseModel
  12. {
  13. use ModelTrait;
  14. use JwtAuthModelTrait;
  15. //
  16. /**
  17. * 获取列表数据
  18. * @param $page
  19. * @param $where
  20. * @param $pageCount
  21. * @param $desc
  22. */
  23. public function getList($page,$where = [],$pageCount = 20,$filed = '*',$desc = ''){
  24. $data = $this
  25. ->field("m.*,s.name as site_name,l.name as level_name,
  26. (select count(*) from table_order where uid = m.uid and status > 0) as order_count,
  27. (select sum(v) from table_recharge where status = 1 and uid = m.uid ) as recharge_count,
  28. (select count(*) from table_order_info where status = 1 and uid = m.uid ) as order_info_count,
  29. m2.mobile as i_mobile,m2.nickname as i_nickname
  30. "
  31. )
  32. ->alias("m")
  33. ->join('site s','s.sassid=m.sassid')
  34. ->leftJoin("member_level l","l.id=m.levelid")
  35. ->leftJoin('member m2',"m2.uid=m.i_uid")
  36. ->where('m.sassid',$where['sassid'])
  37. ->when(!empty($where),function ($query) use($where){
  38. //keyword
  39. if(!empty($where['keyword'])) {
  40. $query->whereLike('m.nickname',"%{$where['keyword']}%");
  41. }
  42. if(!empty($where['mobile'])) {
  43. $query->whereLike('m.mobile',"%{$where['mobile']}%");
  44. }
  45. if(!empty($where['level'])) {
  46. $query->where('m.levelid',$where['level']);
  47. }
  48. if(!empty($where['i_uid'])) {
  49. $query->where('m.i_uid',$where['i_uid']);
  50. }
  51. if(!empty($where['uid'])) {
  52. $query->where('m.uid',$where['uid']);
  53. }
  54. })
  55. ->order($desc)
  56. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  57. ->toArray();
  58. // echo $this->getLastSql();
  59. return [$data['total'],$data['data']];
  60. }
  61. /**
  62. * 获取列表数据
  63. * @param $page
  64. * @param $where
  65. * @param $pageCount
  66. * @param $desc
  67. */
  68. public function getItem($uid,$sassid){
  69. $data = $this
  70. ->field("*,(SELECT count(*) from table_order where uid = u.uid and status > 0) as order_count,
  71. (select name from table_member_level where id = u.levelid) as lavel_name,
  72. (select sum(v) from table_recharge where status = 1 and uid = u.uid ) as recharge_count,
  73. (select count(*) from table_order_info where status = 1 and uid = u.uid ) as order_info_count
  74. ")
  75. ->alias("u")
  76. ->where('uid',$uid)
  77. ->where('sassid',$sassid)
  78. ->find();
  79. return $data;
  80. }
  81. }