1], [['limit'], 'default', 'value' => 20], ]; } public function search() { if(!$this->validate()){ return $this->getModelError(); } $admin_user_ids = SysAdmin::find() ->where(['is_delete' => 0]) ->select('user_id')->column(); $mobile_hash = !empty($this->keywords) ? EncryptHelper::encryptMobilePhone($this->keywords) : null; $query = User::find()->alias('u') ->leftJoin(['b' => Balance::tableName()],'u.id=b.user_id and b.is_delete=0') ->leftJoin(['i' => Integral::tableName()],'u.id=i.user_id and i.is_delete=0') ->andWhere([ 'u.is_delete' => 0, ]) ->andWhere(['!=','u.id',1]) // ->andWhere([ // 'not in','u.type',[User::TYPE_STORE,User::TYPE_COACH] // ]) ->andFilterWhere([ 'OR', ['LIKE', 'u.nickname', $this->keywords], ['LIKE', 'u.username', $this->keywords], ['LIKE', 'u.real_name', $this->keywords], ['LIKE', 'u.mobile_phone', $mobile_hash], ]) ->andFilterWhere([ 'u.status' => $this->status, 'u.level_id' => $this->level_id, ]) // $cond = $this->is_admin == 0 ? "NOT IN" : "IN"; // $query = $query->andWhere([ // $cond, // 'u.id', // $admin_user_ids // ]) ->select('u.id,u.username,u.nickname,u.avatar_url,u.mobile_phone,u.mobile_prefix,u.email,u.real_name,u.gender,u.birthday,u.status,u.created_at,u.updated_at,u.is_view,u.level_id,u.parent_id,b.account_balance,b.account_balance_with,i.account_integral'); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['u.created_at' => SORT_DESC])->asArray()->all(); foreach ($list as $index => $item){ $item['gender_cn'] = User::getGender($item['gender']); $item['status_cn'] = User::getStatus($item['status']); $item['created_at_cn'] = date("Y-m-d",$item['created_at']); $item['updated_at_cn'] = date("Y-m-d",$item['updated_at']); $item['mobile_phone'] = empty($item['mobile_phone']) ? '' : EncryptHelper::decryptMobilePhone($item['mobile_phone']); if(empty($item['mobile_phone'])){ $item['mobile_phone'] = ' -- '; } //脱敏 // $item['mobile_phone'] = $item['mobile_phone'] == null ? '--' : Utils::stringDesensitization($item['mobile_phone'], 3,4); $item['real_name'] = $item['real_name'] == null ? '--' : $item['real_name']; $item['parent_name'] = ""; $item['parent_mobile'] = ""; if(!empty($item['parent_id'])){ $find = User::findOne([ 'id' => $item['parent_id'], ]); $item['parent_name'] = empty($find->nickname) ? '' : $find->nickname; $item['parent_mobile'] = empty($find->mobile_phone) ? '' : $find->mobile_phone; } $item['account_balance'] = empty($item['account_balance']) ? 0 : $item['account_balance']; $item['account_balance_with'] = empty($item['account_balance_with']) ? 0 : $item['account_balance_with']; $item['account_integral'] = empty($item['account_integral']) ? 0 : $item['account_integral']; $list[$index] = $item; } $data = []; $data['code'] = 0; $data['msg'] = 'ok'; $data['data'] = $list; $data['count'] = $count; return $data; } //查询除admin账号外的所有用户 public function search_user() { if(!$this->validate()){ return $this->getModelError(); } $mobile_hash = !empty($this->keywords) ? EncryptHelper::encryptMobilePhone($this->keywords) : null; $query = User::find()->alias('u') ->where(['!=','u.id',1]) ->andWhere([ 'u.is_delete' => 0 ]) ->andFilterWhere([ 'OR', ['LIKE', 'u.nickname', $this->keywords], ['LIKE', 'u.username', $this->keywords], ['LIKE', 'u.real_name', $this->keywords], ['LIKE', 'u.mobile_phone', $mobile_hash], ]) ->andFilterWhere([ 'u.status' => $this->status, ]) ->select('u.id,u.username,u.nickname,u.avatar_url,u.mobile_phone,u.mobile_prefix,u.email,u.real_name,u.gender,u.birthday,u.status,u.created_at,u.updated_at'); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['u.created_at' => SORT_DESC])->asArray()->all(); foreach ($list as $index => $item){ $item['gender_cn'] = User::getGender($item['gender']); $item['status_cn'] = User::getStatus($item['status']); $item['created_at_cn'] = date("Y-m-d",$item['created_at']); $item['updated_at_cn'] = date("Y-m-d",$item['updated_at']); $item['mobile_phone'] = empty($item['mobile_phone']) ? '' : EncryptHelper::decryptMobilePhone($item['mobile_phone']); if(empty($item['mobile_phone'])){ $item['mobile_phone'] = ' -- '; } //脱敏 // $item['mobile_phone'] = $item['mobile_phone'] == null ? '--' : Utils::stringDesensitization($item['mobile_phone'], 3,4); $item['real_name'] = $item['real_name'] == null ? '--' : $item['real_name']; $list[$index] = $item; } $data = []; $data['code'] = 0; $data['msg'] = 'ok'; $data['data'] = $list; $data['count'] = $count; return $data; } public function logout_review() { $mobile_hash = !empty($this->keywords) ? EncryptHelper::encryptMobilePhone($this->keywords) : null; $query = UserLogoutReview::find()->alias('ulr') ->select('ulr.*,u.nickname,u.real_name,u.avatar_url,u.mobile_prefix,u.mobile_phone,u.id as user_id') ->leftJoin(['u' => User::tableName()],'ulr.user_id=u.id') ->where([ 'ulr.is_delete' => 0, ]) ->andFilterWhere([ 'OR', ['LIKE', 'u.nickname', $this->keywords], ['LIKE', 'u.username', $this->keywords], ['LIKE', 'u.real_name', $this->keywords], ['LIKE', 'u.mobile_phone', $mobile_hash], ]) ->andFilterWhere([ 'ulr.status' => $this->status, ]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['ulr.created_at' => SORT_DESC])->asArray()->all(); foreach ($list as $index => $item){ $item['status_cn'] = UserLogoutReview::getStatus($item['status']); $item['created_at_cn'] = date("Y/m/d H:i",$item['created_at']); $item['mobile_phone'] = empty($item['mobile_phone']) ? '' : EncryptHelper::decryptMobilePhone($item['mobile_phone']); if(empty($item['mobile_phone'])){ $item['mobile_phone'] = ' -- '; } $item['nickname'] = "[{$item['user_id']}]".$item['nickname']; //脱敏 if(!empty($item['real_name']) && $item['nickname'] != $item['real_name']){ $item['nickname'] .= '--'.$item['real_name']; } $list[$index] = $item; } $data = []; $data['code'] = 0; $data['msg'] = 'ok'; $data['data'] = $list; $data['count'] = $count; return $data; } public function distribution_list() { if(!$this->validate()){ return $this->getModelError(); } $mobile_hash = !empty($this->keywords) ? EncryptHelper::encryptMobilePhone($this->keywords) : null; $query = User::find()->alias('u') ->select('u.id,u.nickname,u.mobile_phone,u.avatar_url,u.parent_id,pu.nickname as nickname_p,pu.avatar_url as avatar_url_p,pu.mobile_phone as mobile_phone_p') ->leftJoin(['pu' => User::tableName()],'u.parent_id=pu.id') ->where(['u.is_delete' => 0]) ->andWhere(['!=','u.parent_id','0']) ->andFilterWhere([ 'OR', ['LIKE', 'u.nickname', $this->keywords], ['LIKE', 'u.mobile_phone', $mobile_hash], ]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['u.created_at' => SORT_DESC])->asArray()->all(); return [ 'code' => 0, 'msg' => 'ok', 'data' => $list, 'count' => $count ]; } /** * 绑定会员 */ public function actionBindParent() { if(empty($this->id)){ return $this->apiReturnError('暂无用户'); } if(empty($this->phone)){ return $this->apiReturnError('暂无用户'); } $find = User::findOne([ 'mobile_phone' => $this->phone ]); if(empty($find)){ return $this->apiReturnError('暂无用户'); } if($find->parent_id == $this->id){ return $this->apiReturnError('不能绑定此用户,此用户已跟搜索用户绑定'); } $obj = User::findOne([ 'id' => $this->id, ]); if(empty($obj)){ return $this->apiReturnError('暂无用户'); } $obj->parent_id = $find->id; if(!$obj->save()){ return $this->apiReturnError('error',$this->getModelError($obj)); } return $this->apiReturnSuccess('成功'); } public function user_export() { if(!$this->validate()){ return $this->getModelError(); } $mobile_hash = !empty($this->keywords) ? EncryptHelper::encryptMobilePhone($this->keywords) : null; $query = User::find()->alias('u') ->leftJoin(['b' => Balance::tableName()],'u.id=b.user_id and b.is_delete=0') ->leftJoin(['i' => Integral::tableName()],'u.id=i.user_id and i.is_delete=0') ->andWhere([ 'u.is_delete' => 0, ]) ->andWhere(['!=','u.id',1]) ->andFilterWhere([ 'OR', ['LIKE', 'u.nickname', $this->keywords], ['LIKE', 'u.username', $this->keywords], ['LIKE', 'u.real_name', $this->keywords], ['LIKE', 'u.mobile_phone', $mobile_hash], ]) ->andFilterWhere([ 'u.status' => $this->status, 'u.level_id' => $this->level_id, ]) ->select('u.id,u.username,u.nickname,u.avatar_url,u.mobile_phone,u.mobile_prefix,u.email,u.real_name,u.gender,u.birthday,u.status,u.created_at,u.updated_at,u.is_view,u.level_id,u.parent_id,b.account_balance,b.account_balance_with,i.account_integral'); $list = $query->orderBy(['u.id' => SORT_DESC])->asArray()->all(); foreach ($list as $index => $item){ $item['gender_cn'] = User::getGender($item['gender']); $item['status_cn'] = User::getStatus($item['status']); $item['created_at_cn'] = date("Y-m-d",$item['created_at']); $item['updated_at_cn'] = date("Y-m-d",$item['updated_at']); $item['mobile_phone'] = empty($item['mobile_phone']) ? '' : EncryptHelper::decryptMobilePhone($item['mobile_phone']); if(empty($item['mobile_phone'])){ $item['mobile_phone'] = ' -- '; } //脱敏 // $item['mobile_phone'] = $item['mobile_phone'] == null ? '--' : Utils::stringDesensitization($item['mobile_phone'], 3,4); $item['real_name'] = $item['real_name'] == null ? '--' : $item['real_name']; $item['parent_name'] = ""; $item['parent_mobile'] = ""; if(!empty($item['parent_id'])){ $find = User::findOne([ 'id' => $item['parent_id'], ]); $item['parent_name'] = empty($find->nickname) ? '' : $find->nickname; $item['parent_mobile'] = empty($find->mobile_phone) ? '' : $find->mobile_phone; } $item['level_name'] = ''; if($item['level_id'] == '0'){ $item['level_name'] = '普通用户'; }elseif ($item['level_id'] == '1'){ $item['level_name'] = '见习会员'; }elseif ($item['level_id'] == '1'){ $item['level_name'] = '进阶会员'; }elseif ($item['level_id'] == '1'){ $item['level_name'] = '高阶会员'; } $item['account_balance'] = empty($item['account_balance']) ? 0 : $item['account_balance']; $item['account_balance_with'] = empty($item['account_balance_with']) ? 0 : $item['account_balance_with']; $item['account_integral'] = empty($item['account_integral']) ? 0 : $item['account_integral']; $list[$index] = $item; } $fileName = '用户'.date('Y年m月d日H时i分').'导出'; ExportFile::export_user($list,$fileName,false); } }