dao = $dao; } /** * @param int $id * @param int $uid * @return bool * @author Qinii */ public function fieldExists(int $id,int $uid) { return $this->dao->userFieldExists($this->dao->getPk(),$id,$uid); } /** * @param int $uid * @return bool * @author Qinii */ public function defaultExists(int $uid) { return $this->dao->userFieldExists('is_default',1,$uid); } /** * @param int $id * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author Qinii */ public function checkDefault(int $id) { $res = $this->dao->getWhere([$this->dao->getPk() => $id]); return $res['is_default']; } /** * @param $province * @param $city * @return mixed * @author Qinii */ public function getCityId($province,$city) { $make = app()->make(CityRepository::class); $provinceData = $make->getWhere(['name' => $province]); $cityData = $make->getWhere(['name' => $city,'parent_id' => $provinceData['city_id']]); if(!$cityData)$cityData = $make->getWhere([['name','like','直辖'.'%'],['parent_id' ,'=', $provinceData['city_id']]]); return $cityData['city_id']; } /** * @param $uid * @param $page * @param $limit * @return array * @author Qinii */ public function getList($uid) { $list = $this->dao->getAll($uid)->order('is_default desc')->select(); foreach ($list as &$address){ $code_list = explode(',',$address['code_list']); if (isset($code_list[3])) { $address['town'] = \think\facade\Db::name('regions')->where('id', $code_list[3])->value('name'); } } return compact('list'); } /** * @param $id * @param $uid * @return array|\think\Model|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author Qinii */ public function get($id,$uid) { $address = $this->dao->getWhere(['address_id' => $id,'uid' => $uid]) ?? [] ; $code_list = explode(',',$address['code_list']); if (isset($code_list[3])) { $address['town'] = \think\facade\Db::name('regions')->where('id', $code_list[3])->value('name'); } return $address; } /** * 根据 地址ID 获取地址实体 * * @param $addressId * @return UserAddressEntity */ public function getAddressEntityByAddressId($addressId): UserAddressEntity { /** @var UserAddressEntity $addressEntity */ $addressEntity = $this->dao->getAddressEntityByAddressId($addressId); return $addressEntity; } }