ShippingTemplatesNoDeliveryDao.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\product\shipping;
  12. use app\dao\BaseDao;
  13. use app\model\product\shipping\ShippingTemplatesNoDelivery;
  14. /**
  15. * 不送达
  16. * Class ShippingTemplatesNoDeliveryDao
  17. * @package app\dao\shipping
  18. */
  19. class ShippingTemplatesNoDeliveryDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return ShippingTemplatesNoDelivery::class;
  28. }
  29. /**
  30. * 获取运费模板列表并按照指定字段进行分组
  31. * @param array $where
  32. * @param string $group
  33. * @param string $field
  34. * @param string $key
  35. * @return mixed
  36. */
  37. public function getShippingGroupArray(array $where, string $group, string $field, string $key)
  38. {
  39. return $this->search($where)->group($group)->column($field, $key);
  40. }
  41. /**
  42. * 获取列表
  43. * @param array $where
  44. * @param array|string[] $field
  45. * @return array
  46. * @throws \think\db\exception\DataNotFoundException
  47. * @throws \think\db\exception\DbException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. */
  50. public function getShippingList(array $where, array $field = ['*'])
  51. {
  52. return $this->search($where)->field($field)->select()->toArray();
  53. }
  54. /**
  55. * 获取运费模板列表
  56. * @param array $where
  57. * @param string $field
  58. * @param string $key
  59. * @return array
  60. */
  61. public function getShippingArray(array $where, string $field, string $key)
  62. {
  63. return $this->search($where)->column($field, $key);
  64. }
  65. /**
  66. * 是否不送达
  67. * @param $tempId
  68. * @param $cityid
  69. * @param string $field
  70. * @param string $key
  71. * @return array
  72. */
  73. public function isNoDelivery($tempId, $cityid, string $field = 'temp_id', string $key = '')
  74. {
  75. return $this->getModel()
  76. ->when($cityid, function ($query) use ($cityid) {
  77. if (is_array($cityid)) {
  78. $query->whereIn('city_id', $cityid);
  79. } else {
  80. $query->where('city_id', $cityid);
  81. }
  82. })->when($tempId, function ($query) use ($tempId) {
  83. if (is_array($tempId)) {
  84. $query->whereIn('temp_id', $tempId);
  85. } else {
  86. $query->where('temp_id', $tempId);
  87. }
  88. })->column($field, $key);
  89. }
  90. }