ShippingTemplatesFreeDao.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\ShippingTemplatesFree;
  14. /**
  15. * 包邮
  16. * Class ShippingTemplatesFreeDao
  17. * @package app\dao\product\shipping
  18. */
  19. class ShippingTemplatesFreeDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return ShippingTemplatesFree::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 $number
  70. * @param $price
  71. * @param $type
  72. * @return int
  73. */
  74. public function isFree($tempId, $cityid, $number, $price, $type = 0)
  75. {
  76. return $this->getModel()->where('temp_id', $tempId)
  77. ->where('city_id', $cityid)
  78. ->when($type, function ($query) use ($type, $number) {
  79. if ($type == 1) {//数量
  80. $query->where('number', '<=', $number);
  81. } else {//重量、体积
  82. $query->where('number', '>=', $number);
  83. }
  84. })->where('price', '<=', $price)->count();
  85. }
  86. /**
  87. * 是否包邮模版数据列表
  88. * @param $tempId
  89. * @param $cityid
  90. * @param int $price
  91. * @param string $field
  92. * @param string $key
  93. * @return array
  94. */
  95. public function isFreeList($tempId, $cityid, $price = 0, string $field = '*', string $key = '')
  96. {
  97. return $this->getModel()
  98. ->when($cityid, function ($query) use ($cityid) {
  99. if (is_array($cityid)) {
  100. $query->whereIn('city_id', $cityid);
  101. } else {
  102. $query->where('city_id', $cityid);
  103. }
  104. })->when($tempId, function ($query) use ($tempId) {
  105. if (is_array($tempId)) {
  106. $query->whereIn('temp_id', $tempId);
  107. } else {
  108. $query->where('temp_id', $tempId);
  109. }
  110. })->when($price, function ($query) use ($price) {
  111. $query->where('price', '<=', $price);
  112. })->column($field, $key);
  113. }
  114. }