ShippingTemplatesRegionCityDao.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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\ShippingTemplatesRegion;
  14. use app\model\shipping\SystemCity;
  15. /**
  16. *
  17. * Class ShippingTemplatesRegionCityDao
  18. * @package app\dao\shipping
  19. */
  20. class ShippingTemplatesRegionCityDao extends BaseDao
  21. {
  22. /**
  23. * 当前表别名
  24. * @var string
  25. */
  26. protected $alias = 'a';
  27. /**
  28. * 设置join连表别名
  29. * @var string
  30. */
  31. protected $joinAlis = 'c';
  32. /**
  33. * 设置当前模型
  34. * @return string
  35. */
  36. protected function setModel(): string
  37. {
  38. return ShippingTemplatesRegion::class;
  39. }
  40. /**
  41. * 设置连表模型
  42. * @return string
  43. */
  44. protected function setJoinModel(): string
  45. {
  46. return SystemCity::class;
  47. }
  48. /**
  49. * 关联模型
  50. * @param string $alias
  51. * @param string $join_alias
  52. * @return \crmeb\basic\BaseModel
  53. */
  54. protected function getModel(string $key = 'province_id', string $join = 'LEFT')
  55. {
  56. /** @var SystemCity $city */
  57. $city = app()->make($this->setJoinModel());
  58. $name = $city->getName();
  59. return parent::getModel()->join($name . ' ' . $this->joinAlis, $this->alias . '.' . $key . ' = ' . $this->joinAlis . '.city_id', $join)->alias($this->alias);
  60. }
  61. /**
  62. * 获取指定条件下的包邮列表
  63. * @param array $where
  64. * @return mixed
  65. */
  66. public function getUniqidList(array $where, bool $group = true)
  67. {
  68. return $this->getModel($group ? 'province_id' : 'city_id')->when(isset($where['uniqid']), function ($query) use ($where) {
  69. $query->where($this->alias . '.uniqid', $where['uniqid']);
  70. })->when(isset($where['province_id']), function ($query) use ($where) {
  71. $query->where($this->alias . '.province_id', $where['province_id']);
  72. })->when($group, function ($query) {
  73. $query->group($this->alias . '.province_id');
  74. })->field($this->alias . '.province_id,' . $this->joinAlis . '.name,' . $this->alias . '.city_id')->select()->toArray();
  75. }
  76. }