Protector.php 2.8 KB

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