Protector.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Protector extends Model
  5. {
  6. // 表名
  7. protected $table = 'protector';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. // 追加属性
  14. protected $append = [
  15. ];
  16. /**
  17. * 判断单位是否存在,存在返回name
  18. * @param $unit_name
  19. * @return bool|mixed
  20. */
  21. public static function unitNameIsExist($unit_name)
  22. {
  23. $res = self::where('unit_name',$unit_name)
  24. ->value('unit_name');
  25. return $res;
  26. }
  27. /**
  28. * 判断用户是否超出保护个数上限
  29. * @param $usr_id
  30. * @param $count
  31. * @return bool|string
  32. */
  33. public static function proCountIsExceed($usr_id, $count)
  34. {
  35. $exist_count = self::where('usr_id',$usr_id)
  36. ->where('status',0)
  37. ->count();
  38. if($exist_count >= $count){
  39. return '保护客户个数已超出上限!';
  40. }
  41. return false;
  42. }
  43. }