Member.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\model\system;
  4. use Closure;
  5. use library\basic\BaseModel;
  6. use library\traits\JwtAuthModelTrait;
  7. use library\traits\ModelTrait;
  8. use think\Model;
  9. /**
  10. * @mixin \think\Model
  11. */
  12. class Member extends BaseModel
  13. {
  14. use ModelTrait;
  15. use JwtAuthModelTrait;
  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 > 0 and uid = m.uid ) as order_info_count,
  29. (select nickname from table_member where uid = m.i_uid) 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. ->when(!empty($where),function ($query) use($where){
  36. //keyword
  37. if(!empty($where['keyword'])) {
  38. $query->whereLike('m.nickname',"%{$where['keyword']}%");
  39. }
  40. if(!empty($where['timeVal'][0]) && !empty($where['timeVal'][1])) {
  41. $query->where('regtime','>',strtotime($where['timeVal'][0]));
  42. $query->where('regtime','<',strtotime($where['timeVal'][1]));
  43. }
  44. if(!empty($where['not_buy'])) {
  45. //今日消费
  46. if($where['not_buy'] == 'today') {
  47. $query->whereTime("last_con_time",'today');
  48. }
  49. //7天内消费
  50. if($where['not_buy'] == '1_7day') {
  51. $time = time() - 6*24*3600;
  52. $query->where("last_con_time",'>',$time);
  53. $query->order("last_con_time","desc");
  54. }
  55. //7-13天未消费
  56. if($where['not_buy'] == '7day') {
  57. $time = time() - 13*24*3600;
  58. $times = time() - 6*24*3600;
  59. $query->where("last_con_time",'>',$time);
  60. $query->where("last_con_time",'<',$times);
  61. $query->order("last_con_time","desc");
  62. }
  63. //14天未消费
  64. if($where['not_buy'] == '14day') {
  65. $time = time() - 13*24*3600;
  66. $query->where("last_con_time",'<',$time);
  67. $query->where("last_con_time",'<>',0);
  68. $query->order("last_con_time","desc");
  69. }
  70. //1个月未消费
  71. if($where['not_buy'] == 'month') {
  72. $time = strtotime('-1 month');
  73. $query->where("last_con_time",'<',$time);
  74. $query->where("last_con_time",'<>',0);
  75. $query->order("last_con_time","desc");
  76. }
  77. //从无消费
  78. if($where['not_buy'] == 'nothing') {
  79. $query->where("last_con_time",0);
  80. }
  81. }
  82. if(!empty($where['mobile'])) {
  83. $query->whereLike('m.mobile',"%{$where['mobile']}%");
  84. }
  85. if(!empty($where['level'])) {
  86. $query->where('m.levelid',$where['level']);
  87. }
  88. if(strlen($where['follow_type']) > 0) {
  89. $query->where('m.follow_type',$where['follow_type']);
  90. }
  91. if(!empty($where['sassid'])) {
  92. //判断是否多个
  93. $sassIds = explode(',',(string)$where['sassid']);
  94. if(count($sassIds) > 1)
  95. $query->whereIn('m.sassid',$sassIds);
  96. else
  97. $query->where('m.sassid',$where['sassid']);
  98. }
  99. if(!empty($where['i_uid'])) {
  100. $query->where('m.i_uid',$where['i_uid']);
  101. }
  102. if(!empty($where['uid'])) {
  103. $query->where('m.uid',$where['uid']);
  104. }
  105. if(!empty($where['label'])) {
  106. $query->where('m.label',$where['label']);
  107. }
  108. if(!empty($where['admin_id'])) {
  109. $query->where('m.admin_id',$where['admin_id']);
  110. }
  111. if(!empty($where['not_follow'])) {
  112. if($where['not_follow']=='3day'){
  113. $time = time() - 3*24*3600;
  114. $query->where("last_follow_time",'<',$time);
  115. }else{
  116. $time = time() - 7*24*3600;
  117. $query->where("last_follow_time",'<',$time);
  118. }
  119. }
  120. if(!empty($where['lately_login'])) {
  121. $time = time() - 3*24*3600;
  122. $query->where("lasttime",'>',$time);
  123. }
  124. if(!empty($where['type'])) {
  125. if($where['type']=='new'){
  126. $query->where("last_con_time",'=',0);
  127. }else{
  128. $query->where("last_con_time",'<>',0);
  129. }
  130. }
  131. })
  132. ->order($desc)
  133. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  134. ->toArray();
  135. // echo $this->getLastSql();
  136. return [$data['total'],$data['data']];
  137. }
  138. /**
  139. * 获取列表数据
  140. * @param $page
  141. * @param $where
  142. * @param $pageCount
  143. * @param $desc
  144. */
  145. public function getItem($uid){
  146. $data = $this
  147. ->field("*,(SELECT count(*) from table_order where uid = u.uid and status > 0) as order_count,
  148. (select name from table_member_level where id = u.levelid) as lavel_name,
  149. (select sum(v) from table_recharge where status = 1 and uid = u.uid ) as recharge_count,
  150. (select count(*) from table_order_info where status >= 1 and uid = u.uid ) as order_info_count
  151. ")
  152. ->alias("u")
  153. ->where('uid',$uid)
  154. ->find();
  155. return $data;
  156. }
  157. }