OrderAddress.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace app\common\model;
  13. use cores\BaseModel;
  14. use app\common\model\Region as RegionModel;
  15. /**
  16. * 订单收货地址模型
  17. * Class OrderAddress
  18. * @package app\common\model
  19. */
  20. class OrderAddress extends BaseModel
  21. {
  22. // 定义表名
  23. protected $name = 'order_address';
  24. // 定义主键
  25. protected $pk = 'order_address_id';
  26. protected $updateTime = false;
  27. /**
  28. * 追加字段
  29. * @var array
  30. */
  31. protected $append = ['region'];
  32. /**
  33. * 获取器:地区名称
  34. * @param $value
  35. * @param $data
  36. * @return array
  37. * @throws \think\db\exception\DataNotFoundException
  38. * @throws \think\db\exception\DbException
  39. * @throws \think\db\exception\ModelNotFoundException
  40. */
  41. public function getRegionAttr($value, $data)
  42. {
  43. return [
  44. 'province' => RegionModel::getNameById($data['province_id']),
  45. 'city' => RegionModel::getNameById($data['city_id']),
  46. 'region' => RegionModel::getNameById($data['region_id'])
  47. ];
  48. }
  49. /**
  50. * 获取完整地址
  51. * @return string
  52. */
  53. public function getFullAddress()
  54. {
  55. return $this['region']['province'] . $this['region']['city'] . $this['region']['region'] . $this['detail'];
  56. }
  57. /**
  58. * 获取完整地址
  59. * @param $detail
  60. * @return string
  61. */
  62. public static function fullAddress($detail)
  63. {
  64. return $detail['region']['province'] . $detail['region']['city'] . $detail['region']['region'] . $detail['detail'];
  65. }
  66. }