ShippingTemplatesFreeDao.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. /**
  15. * 包邮
  16. * Class ShippingTemplatesFreeDao
  17. * @package app\dao\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 string $field
  45. * @param string $key
  46. * @return array
  47. */
  48. public function getShippingArray(array $where, string $field, string $key)
  49. {
  50. return $this->search($where)->column($field, $key);
  51. }
  52. /**
  53. * 是否可以满足包邮
  54. * @param $tempId
  55. * @param $cityid
  56. * @param $number
  57. * @param $price
  58. * @return int
  59. */
  60. public function isFree($tempId, $cityid, $number, $price)
  61. {
  62. return $this->getModel()->where('temp_id', $tempId)
  63. ->where('city_id', $cityid)
  64. ->where('number', '<=', $number)
  65. ->where('price', '<=', $price)->count();
  66. }
  67. /**
  68. * 是否包邮模版数据列表
  69. * @param $tempId
  70. * @param $cityid
  71. * @param int $price
  72. * @param string $field
  73. * @param string $key
  74. * @return array
  75. */
  76. public function isFreeList($tempId, $cityid, $price = 0, string $field = '*', string $key = '')
  77. {
  78. return $this->getModel()->where('city_id', $cityid)
  79. ->when($tempId, function ($query) use ($tempId) {
  80. if (is_array($tempId)) {
  81. $query->whereIn('temp_id', $tempId);
  82. } else {
  83. $query->where('temp_id', $tempId);
  84. }
  85. })->when($price, function ($query) use ($price) {
  86. $query->where('price', '<=', $price);
  87. })->column($field, $key);
  88. }
  89. }