hasOne(UserAuth::class, 'user_id'); } /** * @notes 搜索器-用户信息 * @param $query * @param $value * @param $data * @author 段誉 * @date 2022/9/22 16:12 */ public function searchKeywordAttr($query, $value, $data) { if ($value) { $query->where('sn|account|mobile', 'like', '%' . $value . '%'); } } /** * @notes 搜索器-注册来源 * @param $query * @param $value * @param $data * @author 段誉 * @date 2022/9/22 16:13 */ public function searchChannelAttr($query, $value, $data) { if ($value) { $query->where('channel', '=', $value); } } /** * @notes 搜索器-注册时间 * @param $query * @param $value * @param $data * @author 段誉 * @date 2022/9/22 16:13 */ public function searchCreateTimeStartAttr($query, $value, $data) { if ($value) { $query->where('create_time', '>=', strtotime($value)); } } /** * @notes 搜索器-注册时间 * @param $query * @param $value * @param $data * @author 段誉 * @date 2022/9/22 16:13 */ public function searchCreateTimeEndAttr($query, $value, $data) { if ($value) { $query->where('create_time', '<=', strtotime($value)); } } /** * @notes 头像获取器 - 用于头像地址拼接域名 * @param $value * @return string * @author Tab * @date 2021/7/17 14:28 */ public function getAvatarAttr($value) { return trim($value) ? FileService::getFileUrl($value) : ''; } /** * @notes 获取器-性别描述 * @param $value * @param $data * @return string|string[] * @author 段誉 * @date 2022/9/7 15:15 */ public function getSexAttr($value, $data) { return UserEnum::getSexDesc($value); } /** * @notes 登录时间 * @param $value * @return string * @author 段誉 * @date 2022/9/23 18:15 */ public function getLoginTimeAttr($value) { return $value ? date('Y-m-d H:i:s', $value) : ''; } /** * @notes 生成用户编码 * @param string $prefix * @param int $length * @return string * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 段誉 * @date 2022/9/16 10:33 */ public static function createUserSn($prefix = '', $length = 8) { $rand_str = ''; for ($i = 0; $i < $length; $i++) { $rand_str .= mt_rand(0, 9); } $sn = $prefix . $rand_str; if (User::where(['sn' => $sn])->find()) { return self::createUserSn($prefix, $length); } return $sn; } /** * @notes 获取团队人数 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getTeamNumAttr($value, $data) { $config = ConfigService::get('website', 'distribute'); $level = count($config); return UserRelation::where(['parent_id' => $data['id']])->where("level <= $level")->count(); } /** * @notes 获取量化次数 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getLhNumAttr($value, $data) { return LhRecord::where(['user_id' => $data['id']])->count(); } /** * @notes 获取今日量化次数 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getTodayLhNumAttr($value, $data) { // 获取今天0点的时间戳 $todayStart = strtotime(date('Y-m-d 00:00:00')); return LhRecord::where(['user_id' => $data['id']])->where("create_time > $todayStart")->count(); } /** * @notes 获取投资次数 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getItemNumAttr($value, $data) { return ItemRecord::where(['user_id' => $data['id']])->count(); } /** * @notes 获取挖矿情况 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getMineAttr($value, $data) { $start_time = strtotime(date('Y-m-d 00:00:00', time()));//0点 $end_time = time(); $today_income = UserMineRecord::where(['user_id' => $data['id']])->where(" create_time >= $start_time AND create_time <= $end_time ")->sum('amount'); $start_time = 0; $total_income = UserMineRecord::where(['user_id' => $data['id']])->where(" create_time >= $start_time AND create_time <= $end_time ")->sum('amount'); return [ 'total_income' => $total_income, 'today_income' => $today_income, ]; } /** * @notes 获取今日投资次数 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getTodayItemNumAttr($value, $data) { // 获取今天0点的时间戳 $todayStart = strtotime(date('Y-m-d 00:00:00')); return ItemRecord::where(['user_id' => $data['id']])->where("create_time > $todayStart")->count(); } /** * @notes 获取团队总充值 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getTeamRechargeAttr($value, $data) { $config = ConfigService::get('website', 'distribute'); $level = count($config); $sum = UserRelation::alias('ur') ->join('user u', 'u.id = ur.user_id') ->where(['ur.parent_id' => $data['id']]) ->where("ur.level <= $level AND u.total_recharge > 0") ->sum('u.total_recharge'); return $sum; } /** * @notes 获取量化次数 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getUnusedMoneyAttr($value, $data) { return UserFinance::where(['user_id' => $data['id'],'frozen' => 1])->sum('change_amount'); } /** * @notes 获取团队总提现 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getTeamWithdrawAttr($value, $data) { $config = ConfigService::get('website', 'distribute'); $level = count($config); $sum = UserRelation::alias('ur') ->join('user u', 'u.id = ur.user_id') ->where(['ur.parent_id' => $data['id']]) ->where("ur.level <= $level AND u.total_withdraw > 0") ->sum('u.total_withdraw'); return $sum; } /** * @notes 获取推广情况 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getTeamReportAttr($value, $data) { $items = ConfigService::get('website', 'distribute'); foreach ($items as &$item) { $level = $item['level']; $item['num'] = UserRelation::where(['parent_id' => $data['id'],'level' => $level])->count(); $item['num_valid'] = UserRelation::alias('ur') ->join('user_member_record umr', 'ur.user_id = umr.user_id') ->where(['ur.parent_id' => $data['id'],'level' => $level]) ->where("umr.member_id > 1") ->count(); } return $items; } /** * @notes 获取用户层级 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getTeamTopAttr($value, $data) { $top_relation = UserRelationAgent::where(['user_id' => $data['id']])->order('level desc')->findOrEmpty(); $prev_relation = UserRelationAgent::where(['user_id' => $data['id'],'level' => 1])->findOrEmpty(); $level = ''; if (!$top_relation->isEmpty()) { $level = $top_relation['level']; } $top_user = User::where('id', $top_relation['parent_id'])->findOrEmpty(); return [ 'top_account' => $top_user['account'], 'top_name' => $top_user['is_agent'] == 1 ? $top_user['agent_name']:'', 'prev_account' => User::where('id', $prev_relation['parent_id'])->value('account'), 'level' => $level ]; } /** * @notes 获取用户层级 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getAgentTeamTopAttr($value, $data) { $top_relations = UserRelationAgent::where(['user_id' => $data['id']])->order('level desc')->select(); //只有一条数据的话即为代理直接下级,超过一条数据,则替换一代ID为代理二代ID $top_relation = $top_relations[0]; if(count($top_relations) > 1){ $top_relation = $top_relations[1]; } $prev_relation = UserRelationAgent::where(['user_id' => $data['id'],'level' => 1])->findOrEmpty(); $level = ''; if (!$top_relation->isEmpty()) { $level = $top_relation['level']; } return [ 'top_account' => User::where('id', $top_relation['parent_id'])->value('account'), 'prev_account' => User::where('id', $prev_relation['parent_id'])->value('account'), 'level' => $level ]; } /** * @notes 获取注册IP数量 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getRegisterIpNumAttr($value, $data) { return User::where(['register_ip' => $data['register_ip']])->count(); } /** * @notes 获取注册国家 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getRegisterCountryAttr($value, $data) { $country = ""; // if($data['register_isp'] == ''){ // if($data['register_ip'] != ''){ // $country = UtilsService::get_country_by_ip($data['register_ip'],1); // if($country == ''){ // $country = UtilsService::get_country_by_ip($data['register_ip'],2); // } // if($country != ''){ // User::where(['id' => $data['id']])->update(['register_isp' => $country]); // } // } // }else{ // $country = $data['register_isp']; // } return $country; } /** * @notes 获取登录IP数量 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getLoginIpNumAttr($value, $data) { return User::where(['login_ip' => $data['login_ip']])->count(); } /** * @notes 订单数 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getOrderNumAttr($value, $data) { return GoodsRecord::where(['user_id' => $data['id']])->count(); } /** * @notes 24小时订单数 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getOrderNum24Attr($value, $data) { $time24Hours = time() - 24 * 60 * 60;//24小时前 return GoodsRecord::where(['user_id' => $data['id']])->where("create_time > $time24Hours")->count(); } /** * @notes 会员等级 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getVipNameAttr($value, $data) { //查询会员等级 $vip_name = ''; $member_id = UtilsService::get_user_member_id($data['id']); $userMember = UserMember::where(['id' => $member_id])->findOrEmpty(); if (!$userMember->isEmpty()) { $vip_name = $userMember['name']; } return $vip_name; } /** * @notes 用户详情 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getUserInfoAttr($value, $data) { return UserInfo::where(['user_id' => $data['id']])->findOrEmpty(); } /** * @notes 用户分组 * @param $value * @param $data * @return string * @author BD * @date 2024/02/22 10:54 */ public function getGroupNameAttr($value, $data) { $group_name = '未分组'; $record = UserGroupRecord::where(['user_id' => ($data['id'])])->findOrEmpty(); if (!$record->isEmpty()) { $group_name = UserGroup::where('id', $record['group_id'])->value('name'); } return $group_name; } }