UserAddress.php
1.2 KB
<?php
namespace app\api\model;
use think\Model;
class UserAddress extends Model
{
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
public function getDefaultData($where)
{
$areaModel = new Area();
$areaExtendModel = new AreaExtend();
$where['is_default'] = 1;
$data = $this->where($where)->field('createtime,updatetime,is_default,id,user_id',true)->find();
if (!$data) return false;
$ids = $data['province_id'] . ',' . $data['city_id'] . ',' . $data['county_id'];
$area = $areaModel->where(['id' => ['in', $ids]])->column('name');
$data['address'] = implode('', $area) . $data['address'];
$where = ['province_id'=>$data['province_id'],'city_id'=>$data['city_id'],'county_id'=>$data['county_id']];
$is_special = $areaExtendModel->where($where)->value('is_special');
if (!$is_special) $is_special = $areaExtendModel->where(['province_id'=>$data['province_id']])->value('is_special');
$data['postage_type'] = $is_special;
return $data;
}
}