You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/common/model/wholesaler/Apply.php

104 lines
2.5 KiB

8 months ago
<?php
namespace app\common\model\wholesaler;
8 months ago
use app\common\enum\WholesalerEnum;
use app\common\model\Region as RegionModel;
use app\common\model\UploadFile;
8 months ago
use app\common\model\User;
8 months ago
use cores\BaseModel;
8 months ago
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\model\relation\HasOne;
8 months ago
class Apply extends BaseModel
{
// 定义表名
protected $name = 'wholesaler_apply';
// 定义主键
protected $pk = 'id';
8 months ago
protected $append = ['region', 'status_text'];
public static function detail($where, $with = [])
{
return static::get($where, $with);
}
8 months ago
public function user(): HasOne
{
return $this->hasOne(User::class, 'user_id', 'user_id');
}
8 months ago
/**
* 身份证正面图片
* @return HasOne
*/
public function cardFrontImg(): HasOne
{
return $this->hasOne(UploadFile::class, 'file_id', 'card_front_img_id')
->bind(['card_front_img' => 'preview_url']);
}
/**
* 身份证反面图片
* @return HasOne
*/
public function cardBackImg(): HasOne
{
return $this->hasOne(UploadFile::class, 'file_id', 'card_back_img_id')
->bind(['card_back_img' => 'preview_url']);
}
/**
* 营业执照
* @return HasOne
*/
public function licenseImg(): HasOne
8 months ago
{
8 months ago
return $this->hasOne(UploadFile::class, 'file_id', 'license_img_id')
->bind(['license_img' => 'preview_url']);
8 months ago
}
8 months ago
/**
* 门头照片
* @return HasOne
*/
public function doorImg(): HasOne
{
return $this->hasOne(UploadFile::class, 'file_id', 'door_img_id')
->bind(['door_img' => 'preview_url']);
}
/**
* @notes:地区名称
* @param $value
* @param $data
* @return array
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @author: wanghousheng
*/
public function getRegionAttr($value, $data): array
{
return [
'province' => RegionModel::getNameById($data['province_id']),
'city' => RegionModel::getNameById($data['city_id']),
];
}
public function getStatusTextAttr($value, $data)
{
// 状态
$result = WholesalerEnum::data();
if (!empty($result[$data['status']]['name'])) {
return $result[$data['status']]['name'];
}
return '未知';
}
8 months ago
}