12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\admin\model;
- use app\common\service\Qiyu;
- use think\db\Query;
- /**
- *@method static Query|static filterAdmin()
- * @property bool is_seller
- * @property bool is_manager
- */
- class Admin extends \app\common\model\Admin
- {
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $readonly=['user_type'];
- protected $append=[];
- protected $hidden=['salt','password','token'];
- /**
- * 重置用户密码
- * @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::afterInsert(function (self $admin){
- if(empty($admin['user_type'])){
- $admin['user_type']=0;
- }
- Qiyu::instance()->create($admin,$_SERVER['admin_pass']??null);
- });
- self::beforeUpdate(function (self $admin){
- Qiyu::instance()->update($admin,$_SERVER['admin_pass']??null);
- });
- self::afterDelete(function (self $admin){
- Qiyu::instance()->delete($admin);
- User::where('admin_id',$admin['id'])->update(['admin_id'=>null]);
- });
- }
- 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(),);
- }
- public function scopeFilterAdmin(Query $query){
- $query->where('user_type',self::UT_ADMIN);
- }
- }
|