UserAddressDao.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-05-07
  7. *
  8. *
  9. */
  10. namespace app\common\dao\user;
  11. use app\common\dao\BaseDao;
  12. use app\common\enum\CommonEnum;
  13. use app\common\model\user\UserAddress as model;
  14. use app\entity\CommonEntity;
  15. use app\entity\data\user\UserAddressEntity;
  16. class UserAddressDao extends BaseDao
  17. {
  18. /**
  19. * @return string
  20. * @author Qinii
  21. */
  22. protected function getModel(): string
  23. {
  24. return model::class;
  25. }
  26. public function userFieldExists($field, $value,$uid): bool
  27. {
  28. return (($this->getModel()::getDB())->where('uid',$uid)->where($field,$value)->count()) > 0;
  29. }
  30. public function changeDefault(int $uid)
  31. {
  32. return ($this->getModel()::getDB())->where('uid',$uid)->update(['is_default' => 0]);
  33. }
  34. public function getAll(int $uid)
  35. {
  36. return (($this->getModel()::getDB())->where('uid',$uid));
  37. }
  38. /**
  39. * 根据 地址ID 获取地址实体
  40. * @param int $addressId
  41. * @return CommonEntity
  42. */
  43. public function getAddressEntityByAddressId(int $addressId): CommonEntity
  44. {
  45. $addressData = [];
  46. try {
  47. /** @var model $model */
  48. $model = $this->getModel();
  49. $addressDataRes = $model::getDB()
  50. ->where('address_id', '=', $addressId)
  51. ->where('is_del', '=', CommonEnum::IS_DEL['No']['code'])
  52. ->find();
  53. if (!empty($addressDataRes)) {
  54. $addressData = $addressDataRes->toArray();
  55. }
  56. } catch (\Exception $e) {
  57. }
  58. return UserAddressEntity::newInstance($addressData);
  59. }
  60. }