| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace app\admin\model;
- use think\Model;
- use think\Session;
- class Admin extends Model
- {
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- public static function PlatformKey()
- {
- return "platform:w:update:1";
- }
- public static function AgencyKey($id)
- {
- return "agency:w:update:{$id}";
- }
- /**
- * 重置用户密码
- * @author baiyouwen
- */
- public function resetPassword($uid, $NewPassword)
- {
- $passwd = $this->encryptPassword($NewPassword);
- $ret = $this->where(['id' => $uid])->update(['password' => $passwd]);
- return $ret;
- }
- // 密码加密
- protected function encryptPassword($password, $salt = '', $encrypt = 'md5')
- {
- return $encrypt($password . $salt);
- }
- public function checkByCityCodes($city_codes = [], $admin_id = null)
- {
- if (0 === $city_codes)
- return false;
- $query = $this->where("type", \E_ADMIN_TYPE::Agency);
- $orSql = join(" or ", array_map(function ($data) {
- return "FIND_IN_SET('$data', city_codes)";
- }, $city_codes));
- if ($admin_id > 0)
- $query->where("id", "<>", $admin_id);
- return $query->where("( $orSql )")
- ->select();
- }
- public function findAgency($city_code)
- {
- return $this->where("FIND_IN_SET('$city_code', city_codes)")
- ->where("type", \E_ADMIN_TYPE::Agency)
- ->order("createtime", "ASC")
- ->find();
- }
- public function findByUnionId($union_id)
- {
- return $this->where("union_id", $union_id)
- ->find();
- }
- public function findByMobile($mobile) {
- return $this->where("mobile", $mobile)->find();
- }
- }
|