StoreIntegralDao.php 3.6 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. declare (strict_types=1);
  12. namespace app\dao\activity\integral;
  13. use app\dao\BaseDao;
  14. use app\model\activity\integral\StoreIntegral;
  15. /**
  16. *
  17. * Class StoreIntegralDao
  18. * @package app\dao\activity
  19. */
  20. class StoreIntegralDao extends BaseDao
  21. {
  22. /**
  23. * 设置模型
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return StoreIntegral::class;
  29. }
  30. /**
  31. * 获取指定条件下的条数
  32. * @param array $where
  33. * @param bool $search
  34. * @return int
  35. * @throws \ReflectionException
  36. */
  37. public function count(array $where = [], bool $search = true)
  38. {
  39. return $this->search($where, $search)->count();
  40. }
  41. /**
  42. * 积分商品列表
  43. * @param array $where
  44. * @param int $page
  45. * @param int $limit
  46. * @return array
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public function getList(array $where, int $page = 0, int $limit = 0, string $field = '*')
  52. {
  53. return $this->search($where, false)->where('is_del', 0)
  54. ->when(isset($where['integral_time']) && $where['integral_time'] !== '', function ($query) use ($where) {
  55. list($startTime, $endTime) = explode('-', $where['integral_time']);
  56. $query->where('add_time', '>', strtotime($startTime))
  57. ->where('add_time', '<', strtotime($endTime) + 24 * 3600);
  58. })->when(isset($where['goods_user_type']), function($query) use ($where) {
  59. $query->where('goods_user_type', $where['goods_user_type']);
  60. })->when(isset($where['priceOrder']) && $where['priceOrder'] != '', function ($query) use ($where) {
  61. if ($where['priceOrder'] === 'desc') {
  62. $query->order("price desc");
  63. } else {
  64. $query->order("price asc");
  65. }
  66. })->when(isset($where['salesOrder']) && $where['salesOrder'] != '', function ($query) use ($where) {
  67. if ($where['salesOrder'] === 'desc') {
  68. $query->order("sales desc");
  69. } else {
  70. $query->order("sales asc");
  71. }
  72. })->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
  73. $query->page($page, $limit);
  74. })->field($field)->order('sort desc,id desc')->select()->toArray();
  75. }
  76. /**
  77. * 获取一条积分商品数据
  78. * @param int $id
  79. * @param string $field
  80. * @return array|\think\Model|null
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\DbException
  83. * @throws \think\db\exception\ModelNotFoundException
  84. */
  85. public function validProduct(int $id, string $field)
  86. {
  87. $where = ['is_show' => 1, 'is_del' => 0];
  88. return $this->search($where)->where('id', $id)->field($field)->order('add_time desc')->find();
  89. }
  90. }