User.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 创客管理
  7. */
  8. namespace app\ais\controller\vip;
  9. use app\common\model\SystemUser;
  10. use app\common\facade\Inform;
  11. use think\facade\Request;
  12. use think\facade\Validate;
  13. use think\helper\Time;
  14. use app\ais\controller\Common;
  15. use app\ais\model\AisVip;
  16. use app\ais\model\AisVipUser;
  17. class User extends Common{
  18. public function initialize() {
  19. parent::initialize();
  20. $this->assign('pathMaps',[['name'=>'会员设置','url'=>url("vip.user/index")]]);
  21. }
  22. /**
  23. *
  24. * @param int $types
  25. * @param int $vip_id
  26. * @return type
  27. */
  28. public function index(int $types = 0,int $vip_id = 0){
  29. $time = Request::param('time/d',0);
  30. $starttime = Request::param('starttime/s');
  31. $endtime = Request::param('endtime/s');
  32. $condition[] = ['is_lock','=',$types ? 1 : 0];
  33. if($time){
  34. switch ($time) {
  35. case 2:
  36. list($start, $end) = Time::yesterday();
  37. break;
  38. case 30:
  39. list($start, $end) = Time::month();
  40. break;
  41. case 60:
  42. list($start, $end) = Time::lastMonth();
  43. break;
  44. default:
  45. list($start, $end) = Time::today();
  46. break;
  47. }
  48. $condition[] = ['update_time','>=',$start];
  49. $condition[] = ['update_time','<=',$end];
  50. }else{
  51. if($starttime){
  52. $condition[] = ['update_time','>=',strtotime($starttime)];
  53. }
  54. if($endtime){
  55. $condition[] = ['update_time','<=',strtotime($endtime)];
  56. }
  57. }
  58. //查询内容
  59. $view['vip'] = AisVip::where($this->mini_program)->order('sort desc,id desc')->select();
  60. $view['info'] = [];
  61. $view['pathMaps'][] = ['name'=>' 会员列表','url'=>url('ais/vip.user/index')];
  62. if($vip_id){
  63. $condition[] = ['vip_id','=',$vip_id];
  64. $view['info'] = AisVip::where(['id' => $vip_id])->field('name,id')->find();
  65. $view['pathMaps'][] = ['name' => $view['info']->name,'url'=>url('ais/vip.user/index',['vip_id' => $view['info']->id])];
  66. }
  67. //用户精准查询
  68. $uid = Request::param('uid/d','');
  69. if($uid){
  70. $condition[] = ['uid','=',$uid];
  71. }
  72. $view['lists'] = AisVipUser::where($this->mini_program)->where($condition)->order('id desc')->paginate(20,false,['query'=> ['types' => $types,'vip_id' => $vip_id,'time' => $time]]);
  73. //模板赋值
  74. $view['pathMaps'][] = ['name' => $types ? '<span class="red fn-fb">锁定<span>' : '<span class="blue fn-fb">正常<span>','url'=>'javascript:;'];
  75. $view['types'] = $types;
  76. $view['vip_id'] = $vip_id;
  77. $view['time'] = $time;
  78. $view['starttime'] = $starttime;
  79. $view['endtime'] = $endtime;
  80. $view['uid'] = $uid;
  81. return view()->assign($view);
  82. }
  83. /**
  84. * 添加创客会员
  85. * @return type
  86. */
  87. public function winUser(){
  88. if(request()->isAjax()){
  89. $uids = ids($this->request->param('ids/s'),true);
  90. if(empty($uids)){
  91. return json(['code'=>0,'msg'=>'请选择要关联的用户']);
  92. }
  93. $vip_id = $this->request->param('vip_id/d');
  94. $vipcard = AisVip::where($this->mini_program)->where(['id' => $vip_id])->find();
  95. if(empty($vipcard)){
  96. return json(['code'=>0,'msg'=>'未找到对应会员组']);
  97. }
  98. //读取并判断是否VIP
  99. $vipdata = [];
  100. foreach ($uids as $key => $uid) {
  101. $vipdata[$key]['update_time'] = time();
  102. $vipdata[$key]['is_lock'] = 0;
  103. $vipdata[$key]['vip_id'] = $vipcard->id;
  104. $vipdata[$key]['uid'] = $uid;
  105. $vipdata[$key]['member_miniapp_id'] = $this->member_miniapp_id;
  106. //通知到申请者微信
  107. Inform::sms($uid,$this->member_miniapp_id,['title' =>'业务进展通知','type' => '身份变更','state' => '成功','content' =>'您的身份已变更为'.$vipcard['name']]);
  108. }
  109. //锁定以前的会员
  110. AisVipUser::where(['uid' => $uids])->update(['is_lock' => 1]);
  111. AisVipUser::insertAll($vipdata);
  112. return json(['code'=>200,'msg'=>'会员用户新增成功','data' => ['url'=>'']]);
  113. }else{
  114. $vip_id = $this->request->param('vip_id/d');
  115. $view['vip'] = AisVip::where($this->mini_program)->where(['id' => $vip_id])->find();
  116. if(empty($view['vip'])){
  117. $this->error('未找到会员类型');
  118. }
  119. $condition = [] ;
  120. $keyword = $this->request->param('keyword');
  121. if(!empty($keyword)){
  122. if(Validate::isMobile($keyword)){
  123. $condition[] = ['phone_uid','=',$keyword] ;
  124. }else{
  125. $condition[] = ['nickname','like','%'.$keyword.'%'];
  126. }
  127. }
  128. $view['list'] = SystemUser::where($this->mini_program)->where($condition)->where('id', 'NOT IN', function ($query) use($vip_id){
  129. $query->table('ai_ais_vip_user')->where(['vip_id' => $vip_id,'is_lock' => 0])->field('uid');
  130. })->order('id desc')->paginate(20,false,['query' => ['keyword'=>$keyword,'vip_id' => $vip_id]]);
  131. $view['keyword'] = $keyword;
  132. $view['vip_id'] = $vip_id;
  133. return view()->assign($view);
  134. }
  135. }
  136. /**
  137. * 删除用户的优惠券
  138. * @return void
  139. */
  140. public function delete(){
  141. $result = AisVipUser::where($this->mini_program)->where(['uid' => $this->request->param('uid/d')])->delete();
  142. if($result){
  143. return enjson(200);
  144. }
  145. return enjson(0);
  146. }
  147. }