Admin.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use think\Session;
  5. class Admin extends Model
  6. {
  7. // 开启自动写入时间戳字段
  8. protected $autoWriteTimestamp = 'int';
  9. // 定义时间戳字段名
  10. protected $createTime = 'createtime';
  11. protected $updateTime = 'updatetime';
  12. public static function PlatformKey()
  13. {
  14. return "platform:w:update:1";
  15. }
  16. public static function AgencyKey($id)
  17. {
  18. return "agency:w:update:{$id}";
  19. }
  20. /**
  21. * 重置用户密码
  22. * @author baiyouwen
  23. */
  24. public function resetPassword($uid, $NewPassword)
  25. {
  26. $passwd = $this->encryptPassword($NewPassword);
  27. $ret = $this->where(['id' => $uid])->update(['password' => $passwd]);
  28. return $ret;
  29. }
  30. // 密码加密
  31. protected function encryptPassword($password, $salt = '', $encrypt = 'md5')
  32. {
  33. return $encrypt($password . $salt);
  34. }
  35. public function checkByCityCodes($city_codes = [], $admin_id = null)
  36. {
  37. if (0 === $city_codes)
  38. return false;
  39. $query = $this->where("type", \E_ADMIN_TYPE::Agency);
  40. $orSql = join(" or ", array_map(function ($data) {
  41. return "FIND_IN_SET('$data', city_codes)";
  42. }, $city_codes));
  43. if ($admin_id > 0)
  44. $query->where("id", "<>", $admin_id);
  45. return $query->where("( $orSql )")
  46. ->select();
  47. }
  48. public function findAgency($city_code)
  49. {
  50. return $this->where("FIND_IN_SET('$city_code', city_codes)")
  51. ->where("type", \E_ADMIN_TYPE::Agency)
  52. ->order("createtime", "ASC")
  53. ->find();
  54. }
  55. public function findByUnionId($union_id)
  56. {
  57. return $this->where("union_id", $union_id)
  58. ->find();
  59. }
  60. public function findByMobile($mobile) {
  61. return $this->where("mobile", $mobile)->find();
  62. }
  63. }