123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- <?php
- namespace app\admin\model;
- use app\admin\model\UserAuth;
- use support\Model;
- use support\Db;
- /**
- * 悦享家用户信息模型
- * Class Users
- * @package app\admin\model
- */
- class User extends Model
- {
- const UPDATED_AT = 'user_update_time';
- const REAL_NO = '0';
- const REAL_YES = '1';
- const REAL_STATUS = [
- self::REAL_NO => '未认证',
- self::REAL_YES => '已认证'
- ];
- const PACKAGE_NO = '0';
- const PACKAGE_YES = '1';
- const PACKAGE_STATUS = [
- self::PACKAGE_NO => '未购买',
- self::PACKAGE_YES => '已购买'
- ];
- const TOURIST = '0';
- const ORDINARY = '1';
- const FORMAL = '2';
- const INSIDE = '3';
- const USER_CATEGORY = [
- self::TOURIST => '游客会员',
- self::ORDINARY => '普通会员',
- self::FORMAL => '正式会员',
- self::INSIDE => '内部会员'
- ];
- const NO_OWNER = '0';
- const PROSPECTIVE_OWNER = '1';
- const YES_OWNER = '2';
- const USER_OWNER = [
- self::NO_OWNER => '非业主',
- self::PROSPECTIVE_OWNER => '准业主',
- self::YES_OWNER => '业主'
- ];
- protected $dateFormat = 'U';
- /**
- * The table associated with the model.
- *
- * @var string
- */
- protected $table = 'user';
- /**
- * The primary key associated with the table.
- *
- * @var string
- */
- protected $primaryKey = 'user_id';
- /**
- * Notes:MembersAuth关联模型
- * @return \Illuminate\Database\Eloquent\Relations\HasMany
- * User: yym
- * Date: 2022/8/4
- */
- public function member_auth_list()
- {
- return $this->hasMany(UserAuth::class, 'auth_user_id', 'user_id');
- }
- /**
- * Notes:关联未审核信息
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- * User: yym
- * Date: 2022/8/4
- */
- public function member_auth()
- {
- return $this->hasOne(UserAuth::class, 'auth_user_id', 'user_id')->whereIn('auth_status', [UserAuth::WAIT, UserAuth::RETURN, UserAuth::CANCEL]);
- }
- /**
- * Notes:一对多关联会员权益包
- * @return \Illuminate\Database\Eloquent\Relations\HasMany
- * User: yym
- * Date: 2022/8/5
- */
- public function members_package()
- {
- return $this->hasMany(UserPackageLog::class, 'log_user_id', 'user_id')->whereIn('log_package_status', [UserPackageLog::NORMAL]);
- }
- /**
- * Notes:Users插入会员
- * @param int $mobile
- * @return int
- * User: yym
- * Date: 2022/7/25
- */
- public static function insertUsers(int $mobile): int
- {
- $insert = array(
- 'user_name' => $mobile,
- 'user_category' => 'MEMBER',
- 'user_addtimes' => time()
- );
- return static::insertGetId($insert);
- }
- /**
- * Notes:获取会员信息
- * @param int $user_id
- * @return object|null
- * User: yym
- * Date: 2022/7/26
- */
- public static function getUserInfo(int $user_id)
- {
- return static::where(['user.user_id' => $user_id])
- ->select('user.*')
- ->with(['member_auth_list', 'member_auth', 'members_package' => function($query){
- $query->join('package', 'package_id', '=', 'user_package_log.log_package_id');
- }])
- ->first();
- }
- /**
- * Notes:获取会员列表
- * @param string $keywords
- * @param int $category
- * @param int $status
- * @param int $page
- * @param int $limit
- * @return array
- * User: yym
- * Date: 2022/8/4
- */
- public static function getUserList(string $keywords, int $category, int $status, int $pid, string $user_create_time, int $page, int $limit)
- {
- $list = static::where('user.user_id', '>', 0)
- ->select('user.*')
- ->with(['member_auth_list', 'member_auth', 'members_package' => function($query){
- $query->select('user_package_log.*', 'package.*', 'package_price as package_money')->join('package', 'package_id', '=', 'user_package_log.log_package_id');
- }])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where(function ($query1) use ($keywords){
- $query1->where('user.user_account', 'like', '%' . $keywords . '%')
- ->orWhere('user.user_phone', 'like', '%' . $keywords . '%')
- ->orWhere('user.user_real_name', 'like', '%' . $keywords . '%');
- });
- })
- ->when($category !== '', function ($query) use ($category){
- $query->where('user.user_type', $category);
- })
- ->when($status != '', function ($query) use ($status){
- $ids = UserAuth::getListIds($status);
- $member_ids = array(0);
- if(!empty($ids))
- {
- $member_ids = array_unique(array_column($ids, 'auth_user_id'));
- }
- $query->whereIn('user.user_id', $member_ids);
- })
- ->when($pid > '0', function ($query) use ($pid){
- $query->where('user.user_spread_uid', $pid);
- })
- ->when($user_create_time != '', function ($query) use ($user_create_time){
- $start = strtotime($user_create_time);
- $end = $start+24*60*60;
- $query->whereBetween('user_create_time',[$start,$end]);
- })
- ->orderBy('user.user_create_time', 'desc')
- ->forPage($page, $limit)
- ->get()
- ->toArray();
- $count = static::where('user.user_id', '>', 0)
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where(function ($query1) use ($keywords){
- $query1->where('user.user_account', 'like', '%' . $keywords . '%')
- ->orWhere('user.user_phone', 'like', '%' . $keywords . '%')
- ->orWhere('user.user_real_name', 'like', '%' . $keywords . '%');
- });
- })
- ->when($category !== '', function ($query) use ($category){
- $query->where('user.user_type', $category);
- })
- ->when($pid > '0', function ($query) use ($pid){
- $query->where('user.user_spread_uid', $pid);
- })
- ->when($user_create_time != '', function ($query) use ($user_create_time){
- $start = strtotime($user_create_time);
- $end = $start+24*60*60;
- $query->whereBetween('user_create_time',[$start,$end]);
- })
- ->when($status != '', function ($query) use ($status){
- $ids = UserAuth::getListIds($status);
- $member_ids = array(0);
- if(!empty($ids))
- {
- $member_ids = array_unique(array_column($ids, 'auth_user_id'));
- }
- $query->whereIn('user.user_id', $member_ids);
- })
- ->count();
- return [$list, $count];
- }
- /**
- * Notes:获取营销排行
- * @param string $keywords
- * @param int $category
- * @param int $status
- * @param int $page
- * @param int $limit
- * @return array
- * User: ycp
- * Date: 2023/3/1
- */
- public static function getRankList($act,$s_time,$e_time)
- {
- $list = static::select(DB::raw('count(*) as num, user_spread_uid'))
- ->with('User')
- ->groupBy('user_spread_uid')
- ->having('user_spread_uid','>',0)
- ->when($act > '0', function ($query) use ($act){
- $query->where('user_act_source', $act);
- })
- ->when($s_time != '', function ($query) use ($s_time){
- $s_time = strtotime($s_time);
- $query->where('user_create_time','>',$s_time);
- })
- ->when($e_time != '', function ($query) use ($e_time){
- $e_time = strtotime($e_time);
- $query->where('user_create_time','<',$e_time);
- })
- ->orderBy('num','desc')
- ->get();
-
- return $list;
- }
- /**
- * Notes:获取活动拉新明细
- * @param string $keywords
- * @param int $category
- * @param int $status
- * @param int $page
- * @param int $limit
- * @return array
- * User: ycp
- * Date: 2023/3/1
- */
- public static function getActLog($act,$page,$limit)
- {
- $list = static::select('user_id','user_account','user_act_source','user_spread_uid','user_create_time')
- ->with('User','Activity')
- ->where('user_act_source','>',0)
- ->when($act > '0', function ($query) use ($act){
- $query->where('user_act_source', $act);
- })
- ->orderBy('user_create_time','desc')
- ->forPage($page, $limit)
- ->get();
- $count = static::where('user_act_source','>',0)
- ->when($act > '0', function ($query) use ($act){
- $query->where('user_act_source', $act);
- })
- ->count();
-
- return [$list,$count];
- }
- //关联用户
- public function User(){
- return $this->belongsTo(User::class,'user_spread_uid','user_id');
- }
- //关联活动
- public function Activity(){
- return $this->belongsTo(Activity::class,'user_act_source','config_id');
- }
- /**
- * Notes:根据条件搜索会员列表
- * @param string $keywords
- * @param string $field
- * @return array
- * User: yym
- * Date: 2022/8/12
- */
- public static function getUserListKeywords(string $keywords, string $field)
- {
- return static::select($field)
- ->leftJoin('members', 'member_id', '=', 'users.user_id')
- ->where('members.member_name', 'like', '%' . $keywords . '%')
- ->orWhere('members.member_mobile', 'like', '%' . $keywords . '%')
- ->orWhere('users.user_name', 'like', '%' . $keywords . '%')
- ->get()
- ->toArray();
- }
- /**
- * Notes:根据主键更新会员信息
- * @param int $member_id
- * @param array $update
- * @return false|int
- * User: yym
- * Date: 2022/7/28
- */
- public static function updateMember(int $member_id, array $update)
- {
- if(empty($update) || $member_id <= 0)
- {
- return false;
- }
- return static::where(['user_id' => $member_id])->update($update);
- }
- /**
- * Notes:获取用户信息
- * @param int $member_id
- * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
- * User: yym
- * Date: 2022/9/14
- */
- public static function getMemberInfo(int $member_id)
- {
- return static::where(['user_id' => $member_id])->first();
- }
- /**
- * Notes:用户账号唯一判断
- * @param int $user_account
- * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
- * User: ZQ
- * Date: 2022/11/21
- */
- public static function getUserAccount($user_account)
- {
- return static::where(['user_account' => $user_account])->first();
- }
- /**
- * Notes:用户身份证号唯一判断
- * @param int $user_account
- * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
- * User: ZQ
- * Date: 2022/11/21
- */
- public static function getUserCard($user_card_id)
- {
- return static::where(['user_card_id' => $user_card_id])->first();
- }
- }
|