123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace App\Models;
- use App\Traits\ModelHelpers;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Model;
- class User extends Model
- {
- //
- use ModelHelpers;
- protected $table = "users";
- // protected $fillable = ['status', 'mobile', 'is_bind_mobile', 'is_card_certified', 'is_match_ride_age', 'card_id', 'remark'];
- protected $guarded = [];
- // 注册来源
- const REGISTER_SOURCE_WEAPP = 'weapp';
- public static $registerSourceMaps = [
- self::REGISTER_SOURCE_WEAPP => '微信小程序'
- ];
- //账号状态
- const STATUS_OK = 1;
- const STATUS_PAUSE = 0;
- public static $statusMaps = [
- self::STATUS_PAUSE => '暂停使用',
- self::STATUS_OK => '正常'
- ];
- // 认证状态
- const CARD_OK = 1;
- const CARD_NO = 0;
- public static $cardMaps = [
- self::CARD_OK => '已实名认证',
- self::CARD_NO => '未实名认证'
- ];
- // 押金状态
- const DEPOSIT_OK = 1;
- const DEPOSIT_NO = 0;
- public static $depositMaps = [
- self::DEPOSIT_OK => '已缴纳押金',
- self::DEPOSIT_NO => '未缴纳押金'
- ];
- const DEPOSIT_MONEY = 1;
- const DEPOSIT_CARD = 2;
- const DEPOSIT_STUDENT = 3;
- const DEPOSIT_TYPE_NO = 0;
- public static $depositTypeMaps = [
- self::DEPOSIT_TYPE_NO => '没有缴纳押金',
- self::DEPOSIT_MONEY => '缴纳押金',
- self::DEPOSIT_CARD => '免押金卡',
- self::DEPOSIT_STUDENT => '师生认证',
- ];
- // 是否到了骑车年龄的状态
- const RIDE_BIKE_AGE_OK = 1;
- const RIDE_BIKE_AGE_NO = 0;
- public static $rideBikeAgeMaps = [
- self::RIDE_BIKE_AGE_OK => '已到骑车的年龄',
- self::RIDE_BIKE_AGE_NO => '未到骑车的年龄'
- ];
- // 手机号绑定状态
- const BIND_MOBILE_OK = 1;
- const BIND_MOBILE_NO = 0;
- public static $bingMobileMaps = [
- self::BIND_MOBILE_OK => '已绑定收手机号',
- self::BIND_MOBILE_NO => '未绑定手机号'
- ];
- // 用户授权状态
- const REGISTER_OK = 1;
- const REGISTER_NO = 0;
- public static $registerMaps = [
- self::REGISTER_OK => '已授权',
- self::REGISTER_NO => '未授权'
- ];
- // 用户授权状态
- const IS_STUDENT_OK = 1;
- const IS_STUDENT_NO = 0;
- public static $isStudentMaps = [
- self::IS_STUDENT_OK => '学生',
- self::IS_STUDENT_NO => '不是'
- ];
- public function areas()
- {
- return $this->belongsTo(Area::class, 'register_area_id', 'id');
- }
- public function auth()
- {
- return $this->hasOne(Auth::class)->where('type', Auth::TYPE_WEAPP);
- }
- public function userPhone()
- {
- return $this->hasOne(UserPhoneDetail::class);
- }
- public function getIsDepositAttribute($value)
- {
- if ((int)$this->deposit_type === self::DEPOSIT_CARD && (int)$value === self::DEPOSIT_OK) {
- $deposit_expire_time = Carbon::parse($this->deposit_expire_time);
- if (Carbon::now()->gt($deposit_expire_time)) {
- //判断第一个日期是否比第二个日期大
- $this->updateDeposit($this->id);
- $this->save();
- return self::DEPOSIT_NO;
- }
- }
- return $value;
- }
- public function updateDeposit($user_id)
- {
- self::query()->where('id', $user_id)->update(['is_deposit' => User::DEPOSIT_NO, 'is_student' => self::IS_STUDENT_NO, 'deposit_type' => User::DEPOSIT_TYPE_NO]);
- }
- }
|