'审核中', self::AUDIT_STATUS_PASSED => '审核通过', self::AUDIT_STATUS_REJECTED => '审核驳回' ]; } /** * 获取审核状态文本 */ public function getAuditStatusTextAttr($value, $data) { $status = $value ?: ($data['audit_status'] ?? self::AUDIT_STATUS_PENDING); $list = $this->getAuditStatusList(); return $list[$status] ?? '未知状态'; } /** * 获取申请时间文本 */ public function getApplyTimeTextAttr($value, $data) { $time = $value ?: ($data['apply_time'] ?? 0); return $time > 0 ? date('Y-m-d H:i:s', $time) : ''; } /** * 获取审核时间文本 */ public function getAuditTimeTextAttr($value, $data) { $time = $value ?: ($data['audit_time'] ?? 0); return $time > 0 ? date('Y-m-d H:i:s', $time) : ''; } /** * 获取供应商名称 */ public function getSupplierNameAttr($value, $data) { if (!empty($data['supplier_id'])) { $supplier = \app\common\model\supplier\Index::where('id', $data['supplier_id'])->find(); return $supplier ? $supplier['name'] : ''; } return ''; } /** * 获取身份证正面图片完整URL */ public function getIdCardFrontAttr($value) { return $value ? cdnurl($value, true) : ''; } /** * 获取身份证反面图片完整URL */ public function getIdCardBackAttr($value) { return $value ? cdnurl($value, true) : ''; } /** * 设置身份证正面图片 */ public function setIdCardFrontAttr($value) { return $value ? str_replace(request()->domain(), '', $value) : ''; } /** * 设置身份证反面图片 */ public function setIdCardBackAttr($value) { return $value ? str_replace(request()->domain(), '', $value) : ''; } /** * 关联用户表 */ public function user() { return $this->belongsTo('app\\common\\model\\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0); } /** * 关联供应商表 */ public function supplier() { return $this->belongsTo('app\\common\\model\\supplier\\Index', 'supplier_id', 'id', [], 'LEFT')->setEagerlyType(0); } /** * 关联地区表(省) */ public function province() { return $this->belongsTo('app\\common\\model\\Area', 'province_adcode', 'adcode', [], 'LEFT')->setEagerlyType(0); } /** * 关联地区表(市) */ public function city() { return $this->belongsTo('app\\common\\model\\Area', 'city_adcode', 'adcode', [], 'LEFT')->setEagerlyType(0); } /** * 关联地区表(区县) */ public function district() { return $this->belongsTo('app\\common\\model\\Area', 'district_adcode', 'adcode', [], 'LEFT')->setEagerlyType(0); } /** * 获取省级名称 */ public function getProvinceNameAttr($value, $data) { if (!empty($data['province_adcode'])) { $area = \app\common\model\Area::where('id', $data['province_adcode'])->find(); return $area ? $area['name'] : ''; } return ''; } /** * 获取市级名称 */ public function getCityNameAttr($value, $data) { if (!empty($data['city_adcode'])) { $area = \app\common\model\Area::where('id', $data['city_adcode'])->find(); return $area ? $area['name'] : ''; } return ''; } /** * 获取区域名称 */ public function getDistrictNameAttr($value, $data) { if (!empty($data['district_adcode'])) { $area = \app\common\model\Area::where('id', $data['district_adcode'])->find(); return $area ? $area['name'] : ''; } return ''; } /** * 检查用户是否可以申请 */ public static function canApply($userId) { // 检查是否已有审核中或已通过的申请 $existingApplication = self::where('user_id', $userId) ->where('audit_status', 'in', [self::AUDIT_STATUS_PENDING, self::AUDIT_STATUS_PASSED]) ->find(); return !$existingApplication; } /** * 检查手机号是否已申请 */ public static function isPhoneApplied($phone, $excludeId = null) { $where = ['phone' => $phone]; if ($excludeId) { $where['id'] = ['neq', $excludeId]; } return self::where($where)->find() ? true : false; } /** * 是否可以修改 */ public function canEdit() { return $this->audit_status == self::AUDIT_STATUS_PENDING; } }