123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace app\admin\model;
- use think\Model;
- class Protector extends Model
- {
- // 表名
- protected $table = 'protector';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = false;
- // 定义时间戳字段名
- protected $createTime = false;
- protected $updateTime = false;
-
- // 追加属性
- protected $append = [
- ];
- /**
- * 判断单位名称是否存在,存在返回错误信息,不存在返回false
- * @param $unit_name
- * @return bool|string
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public static function unitNameIsExist($unit_name)
- {
- $res = self::where('unit_name',$unit_name)
- ->field('status,unit_name,usr_nickname,again_date')
- ->find();
- if($res){
- switch ($res['status']){
- case 0:
- $msg = $unit_name.'已被"'.$res['usr_nickname'].'"保护,无法保护!';
- break;
- case 1:
- $msg = $unit_name.'已经过期,请到已过期列表再次保护!';
- break;
- case 2:
- if((time() - strtotime($res['again_date'])) >= 0){
- return false;
- }
- $msg = $unit_name.'已经进入签单冷却期,无法保护!';
- break;
- case 4:
- $msg = $unit_name.'已经放弃,请到已放弃列表再次保护!';
- break;
- }
- return $msg;
- }
- return false;
- }
- /**
- * 判断用户是否超出保护个数上限
- * @param $usr_id
- * @param $count
- * @return bool|string
- */
- public static function proCountIsExceed($usr_id, $count)
- {
- $exist_count = self::where('usr_id',$usr_id)
- ->where('status',0)
- ->count();
- if($exist_count >= $count){
- return true;
- }
- return false;
- }
- /**
- * 更新过期的保护客户
- */
- public static function updateOverdue()
- {
- $now = date('Y-m-d');
- $ids = self::where('status',0)
- ->where('ex_date','<=',$now)
- ->column('id');
- if(!empty($ids)){
- self::whereIn('id',$ids)
- ->update(['status'=>1]);
- }
- }
- /**
- * 根据usr_id获取已经保护的个数
- * @param $usr_id
- * @return int|string
- */
- public static function getProtectCount($usr_id)
- {
- $count = self::where('usr_id',$usr_id)
- ->where('status',0)
- ->count();
- return $count;
- }
- }
|