123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\model\user;
- use app\model\agent\AgentLevel;
- use app\model\order\StoreOrder;
- use app\model\user\level\SystemUserLevel;
- use app\model\user\group\UserGroup;
- use app\model\user\label\UserLabel;
- use app\model\user\label\UserLabelRelation;
- use crmeb\basic\BaseModel;
- use crmeb\traits\ModelTrait;
- use think\Model;
- use think\model\concern\SoftDelete;
- /**
- * Class User
- * @package app\model\user
- */
- class User extends BaseModel
- {
- use ModelTrait;
- use SoftDelete;
- /**
- * @var string
- */
- protected $pk = 'uid';
- protected $name = 'user';
- protected $insert = ['add_time', 'add_ip', 'last_time', 'last_ip'];
- protected $hidden = [
- 'add_ip', 'account', 'clean_time', 'last_ip', 'pwd'
- ];
- protected $deleteTime = 'delete_time';
- /**
- * 自动转类型
- * @var string[]
- */
- protected $type = [
- 'birthday' => 'int'
- ];
- protected $updateTime = false;
- /**
- * 更新用户事件
- * @param Model $user
- */
- public static function onAfterUpdate($user)
- {
- event('user.update');
- }
- protected function setAddTimeAttr($value)
- {
- return time();
- }
- protected function setAddIpAttr($value)
- {
- return app('request')->ip();
- }
- protected function setLastTimeAttr($value)
- {
- return time();
- }
- protected function setLastIpAttr($value)
- {
- return app('request')->ip();
- }
- /**
- * 自定义信息
- * @param $value
- * @param $data
- * @return mixed
- */
- protected function setExtendInfoAttr($value)
- {
- if ($value) {
- return is_array($value) ? json_encode($value) : $value;
- }
- return '';
- }
- /**
- * 自定义信息
- * @param $value
- * @param $data
- * @return mixed
- */
- protected function getExtendInfoAttr($value)
- {
- if ($value) {
- return is_string($value) ? json_decode($value, true) : $value;
- }
- return [];
- }
- /**
- * 自定义会员卡信息
- * @param $value
- * @param $data
- * @return mixed
- */
- protected function setLevelExtendInfoAttr($value)
- {
- if ($value) {
- return is_array($value) ? json_encode($value) : $value;
- }
- return '';
- }
- /**
- * 自定义会员卡信息
- * @param $value
- * @param $data
- * @return mixed
- */
- protected function getLevelExtendInfoAttr($value)
- {
- if ($value) {
- return is_string($value) ? json_decode($value, true) : $value;
- }
- return [];
- }
- /**
- * 链接会员登陆设置表
- * @return \think\model\relation\HasOne
- */
- public function systemUserLevel()
- {
- return $this->hasOne(SystemUserLevel::class, 'id', 'level');
- }
- /**
- * 关联用户分组
- * @return \think\model\relation\HasOne
- */
- public function userGroup()
- {
- return $this->hasOne(UserGroup::class, 'id', 'group_id');
- }
- /**
- * 关联自己
- * @return \think\model\relation\HasOne
- */
- public function spreadUser()
- {
- return $this->hasOne(self::class, 'uid', 'spread_uid');
- }
- /**
- * 关联自己
- * @return \think\model\relation\HasMany
- */
- public function spreadCount()
- {
- return $this->hasMany(UserSpread::class, 'spread_uid', 'uid');
- }
- /**
- * 关联用户标签关系
- * @return \think\model\relation\HasMany
- */
- public function LabelRelation()
- {
- return $this->hasMany(UserLabelRelation::class, 'uid', 'uid');
- }
- /**
- * 关联用户标签
- * @return \think\model\relation\HasManyThrough
- */
- public function label()
- {
- return $this->hasManyThrough(UserLabel::class, UserLabelRelation::class, 'uid', 'id', 'uid', 'label_id');
- }
- /**
- * 关联用户地址
- * @return \think\model\relation\HasMany
- */
- public function address()
- {
- return $this->hasMany(UserAddress::class, 'uid', 'uid');
- }
- /**
- * 关联提现
- * @return \think\model\relation\HasMany
- */
- public function extract()
- {
- return $this->hasMany(UserExtract::class, 'uid', 'uid');
- }
- /**
- * 关联订单
- * @return User|\think\model\relation\HasMany
- */
- public function order()
- {
- return $this->hasMany(StoreOrder::class, 'uid', 'uid');
- }
- /**
- * 关联分销等级
- * @return \think\model\relation\HasOne
- */
- public function agentLevel()
- {
- return $this->hasOne(AgentLevel::class, 'id', 'agent_level')->where('is_del', 0)->where('status', 1);
- }
- /**
- * 关联积分数据
- * @return \think\model\relation\HasMany
- */
- public function bill()
- {
- return $this->hasMany(UserBill::class, 'uid', 'uid');
- }
- /**
- * 关联佣金数据
- * @return \think\model\relation\HasMany
- */
- public function brokerage()
- {
- return $this->hasMany(UserBrokerage::class, 'uid', 'uid');
- }
- /**
- * 关联余额数据
- * @return \think\model\relation\HasMany
- */
- public function money()
- {
- return $this->hasMany(UserMoney::class, 'uid', 'uid');
- }
- /**
- * 用户uid
- * @param Model $query
- * @param $value
- */
- public function searchUidAttr($query, $value)
- {
- if (is_array($value))
- $query->whereIn('uid', $value);
- else
- $query->where('uid', $value);
- }
- /**
- * 账号搜索器
- * @param Model $query
- * @param $value
- */
- public function searchAccountAttr($query, $value)
- {
- $query->where('account', $value);
- }
- /**
- * 密码搜索器
- * @param Model $query
- * @param $value
- */
- public function searchPwdAttr($query, $value)
- {
- $query->where('pwd', $value);
- }
- /**
- * uid范围查询搜索器
- * @param Model $query
- * @param $value
- */
- public function searchUidsAttr($query, $value)
- {
- $query->whereIn('uid', $value);
- }
- /**
- * 模糊条件搜索器
- * @param Model $query
- * @param $value
- */
- public function searchStoreLikeAttr($query, $value)
- {
- $query->where('uid|phone|bar_code', 'LIKE', "%$value%");
- }
- /**
- * 模糊条件搜索器
- * @param Model $query
- * @param $value
- */
- public function searchLikeAttr($query, $value)
- {
- $query->where('account|nickname|phone|real_name|uid', 'LIKE', "%$value%");
- }
- /**
- * 手机号搜索器
- * @param Model $query
- * @param $value
- */
- public function searchPhoneAttr($query, $value)
- {
- if (is_array($value)) {
- $query->whereIn('phone', $value);
- } else {
- $query->where('phone', $value);
- }
- }
- /**
- * 分组搜索器
- * @param Model $query
- * @param $value
- */
- public function searchGroupIdAttr($query, $value)
- {
- $query->where('group_id', $value);
- }
- /**
- * 是否推广人搜索器
- * @param Model $query
- * @param $value
- */
- public function searchIsPromoterAttr($query, $value)
- {
- $query->where('is_promoter', $value);
- }
- /**
- * 状态搜索器
- * @param Model $query
- * @param $value
- */
- public function searchStatusAttr($query, $value)
- {
- $query->where('status', $value);
- }
- /**
- * 会员等级搜索器
- * @param Model $query
- * @param $value
- */
- public function searchLevelAttr($query, $value)
- {
- $query->where('level', $value);
- }
- /**
- * 推广人uid搜索器
- * @param Model $query
- * @param $value
- */
- public function searchSpreadUidAttr($query, $value)
- {
- $query->where('spread_uid', $value);
- }
- /**
- * 推广人uid不等于搜索器
- * @param Model $query
- * @param $value
- */
- public function searchNotSpreadUidAttr($query, $value)
- {
- $query->where('spread_uid', '<>', $value);
- }
- /**
- * 推广人时间搜索器
- * @param Model $query
- * @param $value
- */
- public function searchSpreadTimeAttr($query, $value)
- {
- if ($value) {
- if (is_array($value)) {
- if (count($value) == 2) $query->where('spread_time', $value[0], $value[1]);
- } else {
- $query->where('spread_time', $value);
- }
- }
- }
- /**
- * 用户类型搜索器
- * @param Model $query
- * @param $value
- */
- public function searchUserTypeAttr($query, $value)
- {
- if ($value != '') $query->where('user_type', $value);
- }
- /**
- * 购买次数搜索器
- * @param Model $query
- * @param $value
- */
- public function searchPayCountAttr($query, $value)
- {
- if ($value !== '') {
- if ($value == -1) {
- $query->where('pay_count', '>', 0);
- } else {
- $query->where('pay_count', $value);
- }
- }
- }
- /**
- * 用户推广资格
- * @param Model $query
- * @param $value
- */
- public function searchSpreadOpenAttr($query, $value)
- {
- if ($value != '') $query->where('spread_open', $value);
- }
- public function searchNicknameAttr($query, $value)
- {
- $query->where('nickname', "like", "%" . $value . "%");
- }
- /**
- * bar_code搜索器
- * @param Model $query
- * @param $value
- */
- public function searchBarCodeAttr($query, $value)
- {
- if ($value != '') $query->where('bar_code', $value);
- }
- }
|