Protector.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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')
  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. $msg = $unit_name.'已经签单,无法保护!';
  39. break;
  40. case 4:
  41. $msg = $unit_name.'已经放弃,请到已放弃列表再次保护!';
  42. break;
  43. }
  44. return $msg;
  45. }
  46. return false;
  47. }
  48. /**
  49. * 判断用户是否超出保护个数上限
  50. * @param $usr_id
  51. * @param $count
  52. * @return bool|string
  53. */
  54. public static function proCountIsExceed($usr_id, $count)
  55. {
  56. $exist_count = self::where('usr_id',$usr_id)
  57. ->where('status',0)
  58. ->count();
  59. if($exist_count >= $count){
  60. return true;
  61. }
  62. return false;
  63. }
  64. /**
  65. * 更新过期的保护客户
  66. */
  67. public static function updateOverdue()
  68. {
  69. $now = date('Y-m-d');
  70. $ids = self::where('status',0)
  71. ->where('ex_date','<=',$now)
  72. ->column('id');
  73. if(!empty($ids)){
  74. self::whereIn('id',$ids)
  75. ->update(['status'=>1]);
  76. }
  77. }
  78. /**
  79. * 根据usr_id获取已经保护的个数
  80. * @param $usr_id
  81. * @return int|string
  82. */
  83. public static function getProtectCount($usr_id)
  84. {
  85. $count = self::where('usr_id',$usr_id)
  86. ->where('status',0)
  87. ->count();
  88. return $count;
  89. }
  90. }