OrderAddress.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. 'code' => RegionModel::getCodeById($data['region_id'])
  48. ];
  49. }
  50. /**
  51. * 获取完整地址
  52. * @return string
  53. */
  54. public function getFullAddress()
  55. {
  56. return $this['region']['province'] . $this['region']['city'] . $this['region']['region'] . $this['detail'];
  57. }
  58. /**
  59. * 获取完整地址
  60. * @param $detail
  61. * @return string
  62. */
  63. public static function fullAddress($detail)
  64. {
  65. return $detail['region']['province'] . $detail['region']['city'] . $detail['region']['region'] . $detail['detail'];
  66. }
  67. }