Protector.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. public static function unitNameIsExist($unit_name)
  17. {
  18. $res = self::where('unit_name',$unit_name)
  19. ->field('status,unit_name,usr_nickname')
  20. ->find();
  21. if($res){
  22. switch ($res['status']){
  23. case 0:
  24. $msg = $unit_name.'已被"'.$res['usr_nickname'].'"保护,无法保护!';
  25. break;
  26. case 1:
  27. $msg = $unit_name.'已经过期,请到已过期列表再次保护!';
  28. break;
  29. case 2:
  30. $msg = $unit_name.'已经签单,无法保护!';
  31. break;
  32. case 4:
  33. $msg = $unit_name.'已经放弃,请到已放弃列表再次保护!';
  34. break;
  35. }
  36. return $msg;
  37. }
  38. return false;
  39. }
  40. /**
  41. * 判断用户是否超出保护个数上限
  42. * @param $usr_id
  43. * @param $count
  44. * @return bool|string
  45. */
  46. public static function proCountIsExceed($usr_id, $count)
  47. {
  48. $exist_count = self::where('usr_id',$usr_id)
  49. ->where('status',0)
  50. ->count();
  51. if($exist_count >= $count){
  52. return true;
  53. }
  54. return false;
  55. }
  56. /**
  57. * 更新过期的保护客户
  58. */
  59. public static function updateOverdue()
  60. {
  61. $now = date('Y-m-d');
  62. $ids = self::where('status',0)
  63. ->where('ex_date','<=',$now)
  64. ->column('id');
  65. if(!empty($ids)){
  66. self::whereIn('id',$ids)
  67. ->update(['status'=>1]);
  68. }
  69. }
  70. /**
  71. * 根据usr_id获取已经保护的个数
  72. * @param $usr_id
  73. * @return int|string
  74. */
  75. public static function getProtectCount($usr_id)
  76. {
  77. $count = self::where('usr_id',$usr_id)
  78. ->where('status',0)
  79. ->count();
  80. return $count;
  81. }
  82. }