123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app\admin\model;
- use think\db\Query;
- use think\Model;
- use think\Session;
- /**
- *@method static Query|static proxy()
- *@method static Query|static sub()
- * @property bool is_seller
- */
- class Admin extends Model
- {
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $readonly=['user_type'];
- protected $append=[];
- protected $hidden=['salt','password','token'];
- const UT_ADMIN=0;
- const UT_SELLER=1;
- /**
- * 重置用户密码
- * @author baiyouwen
- */
- public function resetPassword($uid, $NewPassword)
- {
- $passwd = $this->encryptPassword($NewPassword);
- $ret = $this->where(['id' => $uid])->update(['password' => $passwd]);
- return $ret;
- }
- // 密码加密
- protected static function encryptPassword($password, $salt = '', $encrypt = 'md5')
- {
- return $encrypt($password . $salt);
- }
- protected static function init()
- {
- self::beforeUpdate(function (self $admin){
- $data=$admin->getChangedData();
- if(isset($data['status']) && $data['status']=='normal'){
- $admin['logintime']=strtotime('-20days');
- }
- });
- self::beforeWrite(function (self $admin){
- });
- self::beforeInsert(function (self $admin){
- });
- self::beforeUpdate(function (self $admin){
- });
- }
- public function getIsManagerAttr($_,$admin){
- return !$admin['user_type']==self::UT_ADMIN;
- }
- public function getIsSellerAttr($_,$admin){
- return $admin['user_type']==self::UT_SELLER;
- }
- public function moneyLog(){
- return $this->hasMany(AdminMoneyLog::class);
- }
- public function getShareLinkAttr($_m,$model){
- return str_replace('{frommanager}',$model['id'],config('site.sell_share_url')?:'');
- return sprintf('%s/register',request()->domain(),);
- }
- }
|