OrderAddress.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 app\common\model\chef\ChefAreas as RegionModel;
  14. /**
  15. * 订单收货地址模型
  16. * Class OrderAddress
  17. * @package app\common\model
  18. */
  19. class OrderAddress extends BaseModel
  20. {
  21. // 定义表名
  22. protected $name = 'order_address';
  23. // 定义主键
  24. protected $pk = 'order_address_id';
  25. protected $updateTime = false;
  26. /**
  27. * 追加字段
  28. * @var array
  29. */
  30. protected $append = ['region'];
  31. /**
  32. * 获取器:地区名称
  33. * @param $value
  34. * @param $data
  35. * @return array
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. */
  40. public function getRegionAttr($value, $data)
  41. {
  42. return [
  43. 'province' => RegionModel::getNameById($data['province_id']),
  44. 'city' => RegionModel::getNameById($data['city_id']),
  45. 'region' => RegionModel::getNameById($data['region_id'])
  46. ];
  47. }
  48. /**
  49. * 获取完整地址
  50. * @return string
  51. */
  52. public function getFullAddress()
  53. {
  54. return $this['region']['province'] . $this['region']['city'] . $this['region']['region'] . $this['detail'];
  55. }
  56. public function findByOrderId($orderId)
  57. {
  58. if (empty($orderId))return null;
  59. return $this->where('order_id', $orderId)->find();
  60. }
  61. public function batchByOrderIds($orderIds)
  62. {
  63. if (empty($orderIds))return null;
  64. return $this->whereIn('order_id', $orderIds)->select()->toArray();
  65. }
  66. }