model = model('User'); $this->orderModel = model('Orders'); $this->consumeModel = model('consume'); $this->userRecentlyReadModel = model('user_recently_read'); $this->rechargeModel = model('recharge'); $this->adminConfigModel = model('admin_config'); $this->adminModel = model('admin'); $this->redis = Redis::instance(); $this->adminId = $this->auth->id; $group = model('AuthGroupAccess')->where('uid',$this->adminId)->find(); $this->groupId = $group->group_id; $this->view->assign("sexList", $this->model->getSexList()); $this->view->assign("isSubscribeList", $this->model->getIsSubscribeList()); $this->view->assign("isPayList", $this->model->getIsPayList()); $this->view->assign("stateList", $this->model->getStateList()); $this->view->assign("groupId",$this->groupId); $this->assignconfig("groupId",$this->groupId); } /** * 查看 */ public function index() { $search = []; if($this->groupId == 3){ //处理渠道商查询读者 $this->assign('groupId',$this->groupId); if(!empty($_GET['search'])){ $search['id'] = $_GET['search']; $this->assign('search',$_GET['search']); }else{ $this->assign('search',null); return $this->fetch(); } } //设置过滤方法 $this->request->filter(['strip_tags']); $channel = $this->request->get('channel',0); $agent = $this->request->get('agent',0); if($this->groupId == 3){ $path = 'auth/user/index?search='.$_GET['search']; }else{ $path = 'auth/user/index?channel='.$channel.'&agent='.$agent; } $this->assignconfig('urlPath',$path); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('pkey_name')) { return $this->selectpage(); } $condition = []; if($channel || $agent){ if($channel){ $condition['channel_id'] = $channel; } if($agent){ $condition['agent_id'] = $agent; } }else{ if($this->groupId==3){ //渠道商 $condition['channel_id'] = $this->adminId; }elseif($this->groupId==4){ //代理商 $condition['agent_id'] = $this->adminId; } } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->setConnect($_GET['search']) ->where($where) ->where($search) ->where($condition) ->order($sort, $order) ->limit($offset, $limit) ->select(); $result = array("total" => count($list), "rows" => $list); return json($result); } return $this->view->fetch(); } /** * 禁用用户 * @param $ids * @return string * @throws Exception */ public function disable($ids = ''){ if($this->request->isAjax()){ $redis = Redis::instance(); $where = $this->request->param("row/a"); if (ApiService::instance()->checkApiOn()) { $userUpdate = new UserUpdate(); $userUpdate->setId($ids)->setState($where['state']); $result = \app\source\service\UserService::instance()->updateUser($userUpdate)->id; } else{ $result = UserService::instance()->update(['state'=>$where['state']], ['id'=>$ids]); $redis->del('UN:' . $where['id']); } if($result){ $this->success(); }else{ $this->error('修改失败'); } }else{ if(!$ids){ $this->error('参数错误'); } $row = UserService::instance()->getUserModel()->getUserInfo($ids); // $row = $this->model->setConnect($ids)->where('id',$ids)->find(); $this->assign('row',$row); return $this->view->fetch(); } } /** * 批量禁用用户 * @return string * @throws Exception */ public function batchIsDisabled(){ if($this->request->isAjax()){ $redis = Redis::instance(); $err_ids = []; $where = $this->request->param("row/a"); if($ids = array_filter(explode(',',$where['id']))){ foreach($ids as $user_id){ // if(false === $this->model->setConnect($user_id)->where('id',$user_id)->update(['state'=>$where['state']])){ if (ApiService::instance()->checkApiOn()) { $userUpdate = new UserUpdate(); $userUpdate->setId($user_id)->setState($where['state']); $result = \app\source\service\UserService::instance()->updateUser($userUpdate)->id; } else{ $result = UserService::instance()->update(['state'=>$where['state']], ['id'=>$ids]); $redis->del('UN:' . $where['id']); } if(!$result){ array_push($err_ids,$user_id); } } }else{ $this->error('用户ID为空'); } if(count($err_ids)){ $this->error("用户ID: [".implode(',',$err_ids)."] 修改失败"); } $this->success(); }else{ return $this->view->fetch(); } } //渠道商查询用户 public function chsearch(){ $res = null; $id = ''; $search = ''; if(!empty($_POST['search'])){ $search = $_POST['search']; if(isMobile($search)){ $user_phone_data = UserService::instance()->getUserIdByPhone($search); if($user_phone_data){ $id = $user_phone_data['uid']; } }else{ $id = $search; } $admin_id = $this->adminId; if($id){ if (ApiService::instance()->checkApiOn()) { $res = \app\source\service\UserService::instance()->getUserInfo($id); } else { $res = UserService::instance()->getUserModel()->setConnect($id)->where('id', $id)->find(); } if($this->group != AdminConstants::ADMIN_GROUP_ID_CUSTOMER_SERVICE){ if ($res->is_black) { $res = false; } } if ($res && !$res->id) { $res = false; } if ($res) { if ($this->groupId == AdminConstants::ADMIN_GROUP_ID_CHANNEL || $this->groupId == AdminConstants::ADMIN_GROUP_ID_AGENT) { //渠道商 or 代理商 $count = OrderService::instance()->getOrderModel() ->where('user_id', $id) ->where('state', OrderContents::ORDER_STATE_PAID) ->where('deduct', OrderContents::ORDER_DEDUCT_YES) ->count(); if ($res->flush_state != UserConstants::USER_FLUSH_STATE_ADMIN) { UserDdFlushService::instance()->checkUserFlushState($id); UserDdFlushService::instance()->flushVip($id); if ($count) { UserDdFlushService::instance()->flushUserConsume($id); } UserService::instance()->update(['flush_state' => UserConstants::USER_FLUSH_STATE_ADMIN], ['id' => $id]); // UserService::instance()->getUserModel()->setConnect($id)->update(['flush_state' => UserConstants::USER_FLUSH_STATE_ADMIN], ['id' => $id]); $cacheUser = CacheConstants::getUserCacheKey($id); Redis::instance()->del($cacheUser); } else if ($count) { $total_consume = $this->consumeModel->setConnect($id) ->where(['user_id' => $id]) ->field('SUM(free_kandian-dd_free_kandian) as total_consume') ->find(); $total_remain = FinancialService::instance()->getRechargeModel() ->setConnect($id) ->where('user_id', $id) ->where('dd', OrderContents::ORDER_DEDUCT_NO) ->field([ 'sum(free_kandian-remain_free_kandian)' => 'total_remain', ])->find(); if ($total_consume['total_consume'] != $total_remain['total_remain']) { UserDdFlushService::instance()->flushUserConsume($id); } } $o_count = model('Orders')->where(['user_id'=>$id,'state'=>'1', 'deduct'=> 0])->count(); $res->is_pay = $o_count ? 1 : 0; $res->kandian = FinancialService::instance()->getTotalRemainKandian($id, 0)->data; } else { if ($this->groupId == AdminConstants::ADMIN_GROUP_ID_VIP || $this->groupId == AdminConstants::ADMIN_GROUP_ID_VIP_OPERATOR){ $res->kandian = FinancialService::instance()->getTotalRemainKandian($id, 0)->data; }else{ $res->kandian = FinancialService::instance()->getTotalKandian($id)->data; } $count = OrderService::instance()->getOrderModel() ->where('user_id', $id) ->where('state', OrderContents::ORDER_STATE_PAID) ->where('deduct', OrderContents::ORDER_DEDUCT_YES) ->count(); if ($res->flush_state != UserConstants::USER_FLUSH_STATE_ADMIN) { UserDdFlushService::instance()->checkUserFlushState($id); UserDdFlushService::instance()->flushVip($id); if ($count) { UserDdFlushService::instance()->flushUserConsume($id); } UserService::instance()->update(['flush_state' => UserConstants::USER_FLUSH_STATE_ADMIN], ['id' => $id]); } else if ($count) { $total_consume = $this->consumeModel->setConnect($id) ->where(['user_id' => $id]) ->field('SUM(free_kandian-dd_free_kandian) as total_consume') ->find(); $total_remain = FinancialService::instance()->getRechargeModel() ->setConnect($id) ->where('user_id', $id) ->where('dd', OrderContents::ORDER_DEDUCT_NO) ->field([ 'sum(free_kandian-remain_free_kandian)' => 'total_remain', ])->find(); if ($total_consume['total_consume'] != $total_remain['total_remain']) { UserDdFlushService::instance()->flushUserConsume($id); } } if ($this->groupId == AdminConstants::ADMIN_GROUP_ID_VIP || $this->groupId == AdminConstants::ADMIN_GROUP_ID_VIP_OPERATOR) { if (model("AuthGroupAccess")->getGroupId($res->channel_id) == 4) { $channelInfo = model("AdminExtend")->getInfo($res->channel_id); $channelId = $channelInfo['create_by']; } else { $channelId = $res->channel_id; } $vipids = model("VipAdminBind")->where("admin_id_master", $admin_id)->where("flag", 1)->column("admin_id_slave"); if (!in_array($channelId, $vipids)){ $res = []; } } } } else { $res = []; } } if($res){ if($this->group == AdminConstants::ADMIN_GROUP_ID_CUSTOMER_SERVICE){ if($res->vip_endtime>time()){ $res->isvip = 'VIP'; }else{ $res->isvip = '否'; } }else{ // $rechargeVipWhere = ['user_id' => $id ,'dd' => '0', 'type' => ['in', UserConstants::CHANNEL_VIP_TYPE]]; $ddRechargObj = $this->rechargeModel->setConnect($id)->where($rechargeVipWhere)->order('id', 'desc')->find(); if($ddRechargObj){ $ddVipEndTime = $ddRechargObj->channel_vip_starttime + $ddRechargObj->day * 86400 + $ddRechargObj->hour * 3600; if ($ddVipEndTime > time()) { $res->isvip = 'VIP'; } else { $res->isvip = '否'; } $res->vip_endtime = $ddVipEndTime; }else{ $res->isvip = '否'; $res->vip_endtime = '-'; } } $res = $res->toArray(); } } // dump($res); $this->assign('groupId',$this->groupId); $this->assign('time',time()); $this->assign('id',$id); $this->assign('searchkey',$search); $this->assign('user',$res); return $this->view->fetch(); } public function detail($ids=0,$type=1,$pay=0){ $this->hasAuth($ids); // $row = $this->model->join('admin','admin.id = user.channel_id','left')->where('user.id',$ids)->field('user.*,admin.nickname as channel')->find(); $row = $this->model->setConnect($ids)->where('id',$ids)->find(); $admin = model('admin')->where(['id'=>$row['channel_id']])->find(); $row['admin'] = $admin; $adminConfig = model('AdminConfig')->where(['admin_id'=>$row['channel_id']])->find(); $row['qrcode_image'] = !empty($adminConfig['qrcode_image']) ? $adminConfig['qrcode_image'] : ('https://open.weixin.qq.com/qr/code?username='.$adminConfig['json']['authorizer_info']['user_name']); //得到用户剩余免费书币 $free_kandian = model('Recharge')->setConnect($ids)->where('free_endtime','gt',time())->where('user_id',$ids)->sum('remain_free_kandian'); $old_free_kandian = model('Recharge')->setConnect($ids)->where('free_endtime','lt',time())->where('user_id',$ids)->sum('remain_free_kandian'); // $site_url = getCurrentDomain($row['channel_id']); $this->view->assign('site_url',$site_url); $this->view->assign('free_kandian',$free_kandian); $this->view->assign('old_free_kandian',$old_free_kandian); $this->view->assign('row',$row); $this->view->assign('id',$ids); $this->view->assign('type',$type); $this->view->assign('pay',$pay); $tj =0; $strName = ''; if($type==1){ //充值记录 $strName = '充值金额'; $tj = model('Orders')->where(['user_id'=>$ids,'state'=>'1'])->sum('money'); $tj = '¥'.$tj; //dump(model('Orders')->getLastSql()); //全部充值记录 if($pay == 1){ //待支付 $Czjl = model('Orders')->where(['user_id'=>$ids,'state'=>0])->order('id desc')->paginate(10); }elseif($pay == 2){ //已支付 $Czjl = model('Orders')->where(['user_id'=>$ids,'state'=>'1'])->order('id desc')->paginate(10); } else{ //全部 $Czjl = model('Orders')->where(['user_id'=>$ids])->order('id desc')->paginate(10); } if($Czjl){ foreach($Czjl as $key=>$val){ $Czjl[$key]['createtime'] = date('Y-m-d H:i:s',$val['createtime']); } } $this->assign('list',$Czjl); //dump($Czjl);die; }elseif($type==2){ //消费记录 $strName = '书币总消费'; $xfkd = model('consume')->setConnect($ids)->where(['user_id'=>$ids])->sum('kandian'); $xffreekd = model('consume')->setConnect($ids)->where(['user_id'=>$ids])->sum('free_kandian'); $tj = $xfkd + $xffreekd; //dump(Db::connect(get_db_connect($ids))->getLastSql()); $xfjl = model('consume')->setConnect($ids)->where(['user_id'=>$ids])->order('id desc')->paginate(10); $data = $xfjl->all(); foreach($data as $key=>$val){ $data[$key]['kandian'] = intval($val['free_kandian'])+intval($val['kandian']); $data[$key]['createtime'] = date('Y-m-d H:i:s',$val['createtime']); } $this->assign('data',$data); $this->view->assign('list',$xfjl); }elseif($type==3){ //阅读记录 $strName = '阅读书籍量'; $ydjl = model('user_recently_read')->setConnect($ids)->where(['user_id'=>$ids])->order('updatetime desc')->paginate(10); $tj = model('user_recently_read')->setConnect($ids)->where(['user_id'=>$ids])->count('id'); $data = $ydjl->all(); foreach ($data as $key => $item) { $bookName = model('Book')->where(['id'=>$item['book_id']])->find(); if($bookName){ $data[$key]['bookname'] = $bookName->name; }else{ $data[$key]['bookname'] = '未知'; } $data[$key]['createtime'] = date('Y-m-d H:i:s',$item['createtime']); $data[$key]['updatetime'] = date('Y-m-d H:i:s',$item['updatetime']); } $this->view->assign('data',$data); $this->view->assign('list',$ydjl); }elseif($type==4){ //充值记录 $strName='充值记录'; $rlist = model('recharge')->setConnect($ids)->where(['user_id'=>$ids])->order('id desc')->paginate(10); $data = $rlist->all(); foreach ($data as $key => $item) { if($item['type']=='1'){ if(empty($item['free_endtime'])){ $data[$key]['type'] = '看点充值'; }else{ $data[$key]['type'] = '赠送看点'; } }elseif($item['type']=='2'){ $data[$key]['type'] = 'VIP充值'; }elseif($item['type']=='3'){ $data[$key]['type'] = '系统操作看点'; }elseif($item['type']=='4'){ $data[$key]['type'] = '系统操作vip'; }else{ $data[$key]['type'] = '签到'; } $data[$key]['createtime'] = date('Y-m-d H:i:s',$item['createtime']); } $this->view->assign('data',$data); $this->assign('list',$rlist); } $this->assign('tj',$tj); $this->assign('strName',$strName); return $this->view->fetch(); } /** * 修改书币或vip时长 * @param int $ids * @return int|string * @throws \Exception */ public function kandian($ids=0){ if ($this->request->isAjax()) { $params = $this->request->post(); if ($params){ $err_list = []; $ids = strpos($params['userids'], '\r') ? explode("\r", $params['userids']) : explode("\n", $params['userids']); if (!trim($params['userids'])) { $err_list[] = "请填写要修改的用户id"; } foreach ($ids as $k => $v) { $v = trim($v); if (empty($v)) { unset($ids[$k]); } else { $ids[$k] = $v; } } $ids = array_unique($ids); //去重 $changeType = $params['changeType']; $kandianType = $params['kandianType']; $vipType = $params['vipType']; $kandian = intval($params['kandian']); $free_kandian = intval($params['free_kandian']); $czlx = $params['czlx']; //操作类型 1.活动奖励 2.系统操作 $operateAdmin = $this->auth->getUserInfo(); $bz = $params['bz'] . "--操作人ID:{$operateAdmin['id']}--操作人昵称:{$operateAdmin['nickname']}"; //备注 $day = intval($params['day']); $hour = intval($params['hour']); $errIds = ''; if($changeType == 1){ //修改书币 foreach($ids as $id){ if (FinancialService::instance()->modifyUserKandian($id, $kandianType, $czlx, $kandian, $free_kandian, $bz,0,20)->code != ErrorCodeConstants::SUCCESS) { $errIds .= $id . ','; //记录操作失败的id } } }elseif($changeType == 2){ //修改VIP foreach($ids as $id){ if (!$this->editVipTime($id, $vipType, $czlx, $day, $hour, $bz)) { $errIds .= $id . ','; //记录操作失败的id } } } if($errIds){ $errIds= substr($errIds,0,-1); $err_list[] = 'ID为('.$errIds.')的用户执行失败'; } if(count($err_list)>0){ $errMsg = implode('
',$err_list); $errArr = []; $errArr['error_code'] = 1; $errArr['msg'] = $errMsg; return json_encode($errArr,JSON_UNESCAPED_UNICODE); }else { $errArr = []; $errArr['error_code'] = 0; $errArr['msg'] = '执行成功'; return json_encode($errArr,JSON_UNESCAPED_UNICODE); } } } if($ids){ $this->view->assign('id',$ids); }else{ $this->view->assign('id',''); } return $this->view->fetch(); } //处理修改vip时长逻辑 public function editVipTime($id,$vipType,$czlx,$day=0,$hour=0,$bz=''){ $user = $this->model->getUserInfo($id); if($user){ $saveDate = []; //新增充值记录 $userDate = []; //修改用户数据 $userDate['id'] = $id; $saveDate['user_id'] = $id; $saveDate['type'] = 4; $saveDate['notes'] = $bz; $saveDate['edit_type'] = $czlx; $saveDate['createtime'] = time(); if($day){ if($vipType == 1){ $saveDate['day'] = $day; }else{ $saveDate['day'] = $day*-1; } } if($hour){ if($vipType == 1){ $saveDate['hour'] = $hour; }else{ $saveDate['hour'] = $hour*-1; } } if($vipType==1){ //增加VIP时长 if($day || $hour){ if(intval($user['vip_endtime'])>time()){ $userDate['vip_endtime'] = $day*86400 + $hour*3600 + intval($user['vip_endtime']); $saveDate['vip_starttime'] = intval($user['vip_endtime']); }else{ $userDate['vip_endtime'] = $day*86400 + $hour*3600 +time(); $saveDate['vip_starttime'] = time(); } $vipAddTime = $day * 86400 + $hour * 3600; $saveDate['vip_starttime'] = model('Recharge')->getVipStartTime($id); $saveDate['channel_vip_starttime'] = model('Recharge')->getChannelVipStartTime($id); } }elseif($vipType==2){ //减少VIP时长 if(intval($user['vip_endtime'])>time()) { $times = $day*86400 + $hour*3600; if($user['vip_endtime'] > $times){ $userDate['vip_endtime'] = intval($user['vip_endtime']) - $times; }else{ $userDate['vip_endtime'] = 0; } $vipAddTime = -$times; $saveDate['vip_starttime'] = model('Recharge')->getVipStartTime($id); $saveDate['channel_vip_starttime'] = model('Recharge')->getChannelVipStartTime($id); } } if (isset($vipAddTime)) { if (ApiService::instance()->checkApiOn()) { $userUpdate = new UserUpdate(); $userUpdate->setAddvipday($vipAddTime)->setId($id); $flagUser = \app\source\service\UserService::instance()->updateUser($userUpdate); } else { $flagUser = $this->model->setConnect($id)->update($userDate); //更改用户表数据 //user加入redis缓存 $userKey = 'UN:'.$id; if($this->redis->exists($userKey)){ $this->redis->hmset($userKey,$userDate); $this->redis->expire($userKey,86400); } } } $flagRecharge = model('Recharge')->setConnect($id)->insert($saveDate); //插入充值记录 if(!$flagRecharge || !$flagUser){ return false; } }else{ //没有此用户 return false; } return true; } /** * 从黑名单中踢出,加入白名单 * @param $ids 用户ID */ public function ridBlack(){ $ids = $this->request->param('userid'); if (ApiService::instance()->checkApiOn()) { $updateUser = new UserUpdate(); $updateUser->setId($ids)->setIsBlack(UserConstants::USER_BLACK_NO)->setIsWhite(UserConstants::USER_WHITE_YES); \app\source\service\UserService::instance()->updateUser($updateUser); } else { $this->model->setConnect($ids)->update(['is_black' => UserConstants::USER_BLACK_NO, 'is_white' => UserConstants::USER_WHITE_YES], ['id' => $ids]); Redis::instance()->del("UN:{$ids}"); } $this->success('操作成功'); } //判断权限 public function hasAuth($ids=0){ $condition = []; $condition['id'] = $ids; if($this->groupId==3 || $this->groupId==4){ //渠道商 or 代理商 $condition['channel_id'] = $this->adminId; } $isFather = $this->model->setConnect($ids)->where($condition)->find(); if(empty($isFather)){ $this->error('您没有此权限','/admin/auth/user?ref=addtabs'); } } }