Member.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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(
  26. "m.*,l.name as level_name,
  27. (select count(*) from table_order where uid = m.uid and status > 0) as order_count,
  28. (select sum(v) from table_recharge where status = 1 and uid = m.uid ) as recharge_count,
  29. (select count(*) from table_order_info where status > 0 and uid = m.uid ) as order_info_count,
  30. (select nickname from table_member where uid = m.i_uid) as i_nickname"
  31. )
  32. ->alias("m")
  33. ->leftJoin("member_level l","l.id=m.levelid")
  34. ->when(!empty($where),function ($query) use($where){
  35. //keyword
  36. if(!empty($where['keyword'])) {
  37. $query->whereLike('m.nickname',"%{$where['keyword']}%");
  38. }
  39. if(!empty($where['timeVal'][0]) && !empty($where['timeVal'][1])) {
  40. $query->where('regtime','>',strtotime($where['timeVal'][0]));
  41. $query->where('regtime','<',strtotime($where['timeVal'][1]));
  42. }
  43. if(!empty($where['not_buy'])) {
  44. //今日消费
  45. if($where['not_buy'] == 'today') {
  46. $query->whereTime("last_con_time",'today');
  47. }
  48. //7天内消费
  49. if($where['not_buy'] == '1_7day') {
  50. $time = time() - 6*24*3600;
  51. $query->where("last_con_time",'>',$time);
  52. $query->order("last_con_time","desc");
  53. }
  54. //7-13天未消费
  55. if($where['not_buy'] == '7day') {
  56. $time = time() - 13*24*3600;
  57. $times = time() - 6*24*3600;
  58. $query->where("last_con_time",'>',$time);
  59. $query->where("last_con_time",'<',$times);
  60. $query->order("last_con_time","desc");
  61. }
  62. //14天未消费
  63. if($where['not_buy'] == '14day') {
  64. $time = time() - 13*24*3600;
  65. $query->where("last_con_time",'<',$time);
  66. $query->where("last_con_time",'<>',0);
  67. $query->order("last_con_time","desc");
  68. }
  69. //1个月未消费
  70. if($where['not_buy'] == 'month') {
  71. $time = strtotime('-1 month');
  72. $query->where("last_con_time",'<',$time);
  73. $query->where("last_con_time",'<>',0);
  74. $query->order("last_con_time","desc");
  75. }
  76. //从无消费
  77. if($where['not_buy'] == 'nothing') {
  78. $query->where("last_con_time",0);
  79. }
  80. }
  81. if(!empty($where['mobile'])) {
  82. $query->whereLike('m.mobile',"%{$where['mobile']}%");
  83. }
  84. if(!empty($where['level'])) {
  85. $query->where('m.levelid',$where['level']);
  86. }
  87. if(strlen($where['follow_type']) > 0) {
  88. $query->where('m.follow_type',$where['follow_type']);
  89. }
  90. if(!empty($where['i_uid'])) {
  91. $query->where('m.i_uid',$where['i_uid']);
  92. }
  93. if(!empty($where['uid'])) {
  94. $query->where('m.uid',$where['uid']);
  95. }
  96. if(!empty($where['label'])) {
  97. $query->where('m.label',$where['label']);
  98. }
  99. if(!empty($where['admin_id'])) {
  100. $query->where('m.admin_id',$where['admin_id']);
  101. }
  102. if(!empty($where['not_follow'])) {
  103. if($where['not_follow']=='3day'){
  104. $time = time() - 3*24*3600;
  105. $query->where("last_follow_time",'<',$time);
  106. }else{
  107. $time = time() - 7*24*3600;
  108. $query->where("last_follow_time",'<',$time);
  109. }
  110. }
  111. if(!empty($where['lately_login'])) {
  112. $time = time() - 3*24*3600;
  113. $query->where("lasttime",'>',$time);
  114. }
  115. if(!empty($where['type'])) {
  116. if($where['type']=='new'){
  117. $query->where("last_con_time",'=',0);
  118. }else{
  119. $query->where("last_con_time",'<>',0);
  120. }
  121. }
  122. })
  123. ->order($desc)
  124. ->paginate(['list_rows'=>$pageCount,'page'=>$page])
  125. ->toArray();
  126. //echo $this->getLastSql();
  127. return [$data['total'],$data['data']];
  128. }
  129. /**
  130. * 获取列表数据
  131. * @param $page
  132. * @param $where
  133. * @param $pageCount
  134. * @param $desc
  135. */
  136. public function getItem($uid){
  137. $data = $this
  138. ->field("*,(SELECT count(*) from table_order where uid = u.uid and status > 0) as order_count,
  139. (select name from table_member_level where id = u.levelid) as lavel_name,
  140. (select sum(v) from table_recharge where status = 1 and uid = u.uid ) as recharge_count,
  141. (select count(*) from table_order_info where status >= 1 and uid = u.uid ) as order_info_count
  142. ")
  143. ->alias("u")
  144. ->where('uid',$uid)
  145. ->find();
  146. return $data;
  147. }
  148. }