StoreIntegralDao.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. * @return int
  34. */
  35. public function count(array $where = []): int
  36. {
  37. return $this->search($where)->count();
  38. }
  39. /**
  40. * 积分商品列表
  41. * @param array $where
  42. * @param int $page
  43. * @param int $limit
  44. * @return array
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. */
  49. public function getList(array $where, int $page = 0, int $limit = 0, string $field = '*')
  50. {
  51. return $this->search($where)->where('is_del', 0)
  52. ->when(isset($where['integral_time']) && $where['integral_time'] !== '', function ($query) use ($where) {
  53. list($startTime, $endTime) = explode('-', $where['integral_time']);
  54. $query->where('add_time', '>', strtotime($startTime))
  55. ->where('add_time', '<', strtotime($endTime) + 24 * 3600);
  56. })->when(isset($where['priceOrder']) && $where['priceOrder'] != '', function ($query) use ($where) {
  57. if ($where['priceOrder'] === 'desc') {
  58. $query->order("price desc");
  59. } else {
  60. $query->order("price asc");
  61. }
  62. })->when(isset($where['salesOrder']) && $where['salesOrder'] != '', function ($query) use ($where) {
  63. if ($where['salesOrder'] === 'desc') {
  64. $query->order("sales desc");
  65. } else {
  66. $query->order("sales asc");
  67. }
  68. })->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
  69. $query->page($page, $limit);
  70. })->field($field)->order('sort desc,id desc')->select()->toArray();
  71. }
  72. /**
  73. * 获取一条积分商品数据
  74. * @param int $id
  75. * @param string $field
  76. * @return array|\think\Model|null
  77. * @throws \think\db\exception\DataNotFoundException
  78. * @throws \think\db\exception\DbException
  79. * @throws \think\db\exception\ModelNotFoundException
  80. */
  81. public function validProduct(int $id, string $field)
  82. {
  83. $where = ['is_show' => 1, 'is_del' => 0];
  84. return $this->search($where)->where('id', $id)->field($field)->order('add_time desc')->find();
  85. }
  86. }