55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
|
|
namespace app\common\model\user;
|
|
|
|
|
|
use app\common\model\BaseModel;
|
|
use app\common\model\geo\GeoArea;
|
|
use app\common\model\geo\GeoBrigade;
|
|
use app\common\model\geo\GeoStreet;
|
|
use app\common\model\geo\GeoVillage;
|
|
use think\model\concern\SoftDelete;
|
|
|
|
/**
|
|
* 用户地址表
|
|
* Class UserAddress
|
|
* @package app\common\model
|
|
*/
|
|
class UserAddress extends BaseModel
|
|
{
|
|
use SoftDelete;
|
|
protected $pk = 'id';
|
|
|
|
protected $deleteTime = 'delete_time';
|
|
|
|
public static function getDefaultAddress($uid)
|
|
{
|
|
$address = self::with(['area', 'street', 'village', 'brigade'])->where(['uid' => $uid, 'is_default' => 1])->find();
|
|
if (empty($address)) {
|
|
$address = self::with(['area', 'street', 'village', 'brigade'])->where(['uid' => $uid])->find();
|
|
}
|
|
return empty($address) ? [] : $address->toArray();
|
|
}
|
|
|
|
public function area()
|
|
{
|
|
return $this->hasOne(GeoArea::class, 'area_code', 'area')->field('area_code,area_name');
|
|
}
|
|
|
|
public function street()
|
|
{
|
|
return $this->hasOne(GeoStreet::class, 'street_code', 'street')->field('street_code,street_name');
|
|
}
|
|
|
|
public function village()
|
|
{
|
|
return $this->hasOne(GeoVillage::class, 'village_code', 'village')->field('village_code,village_name');
|
|
}
|
|
|
|
public function brigade()
|
|
{
|
|
return $this->hasOne(GeoBrigade::class, 'id', 'brigade')->field('id,brigade_name');
|
|
}
|
|
|
|
} |