ShippingTemplatesFreeCityDao.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\dao\shipping;
  12. use app\dao\BaseDao;
  13. use app\model\shipping\ShippingTemplatesFree;
  14. use app\model\shipping\SystemCity;
  15. /**
  16. * Class ShippingTemplatesFreeCityDao
  17. * @package app\dao\shipping
  18. */
  19. class ShippingTemplatesFreeCityDao extends BaseDao
  20. {
  21. /**
  22. * 主表别名
  23. * @var string
  24. */
  25. protected $alias = 'a';
  26. /**
  27. * 附表别名
  28. * @var string
  29. */
  30. protected $joinAlis = 'c';
  31. /**
  32. * 设置模型
  33. * @return string
  34. */
  35. protected function setModel(): string
  36. {
  37. return ShippingTemplatesFree::class;
  38. }
  39. /**
  40. * 设置join连表模型
  41. * @return string
  42. */
  43. protected function setJoinModel(): string
  44. {
  45. return SystemCity::class;
  46. }
  47. /**
  48. * 关联模型
  49. * @param string $alias
  50. * @param string $join_alias
  51. * @return \crmeb\basic\BaseModel
  52. */
  53. protected function getModel(string $key = 'province_id', string $join = 'LEFT')
  54. {
  55. /** @var SystemCity $city */
  56. $city = app()->make($this->setJoinModel());
  57. $name = $city->getName();
  58. return parent::getModel()->join($name . ' ' . $this->joinAlis, $this->alias . '.' . $key . ' = ' . $this->joinAlis . '.city_id', $join)->alias($this->alias);
  59. }
  60. /**
  61. * 获取指定条件下的包邮列表
  62. * @param array $where
  63. * @return mixed
  64. */
  65. public function getUniqidList(array $where, bool $group = true)
  66. {
  67. return $this->getModel($group ? 'province_id' : 'city_id')->when(isset($where['uniqid']), function ($query) use ($where) {
  68. $query->where($this->alias . '.uniqid', $where['uniqid']);
  69. })->when(isset($where['province_id']), function ($query) use ($where) {
  70. $query->where($this->alias . '.province_id', $where['province_id']);
  71. })->when($group, function ($query) {
  72. $query->group($this->alias . '.province_id');
  73. })->field($this->alias . '.province_id,' . $this->joinAlis . '.name,' . $this->alias . '.city_id')->select()->toArray();
  74. }
  75. }