StoreIntegralDao.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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['priceOrder']) && $where['priceOrder'] != '', function ($query) use ($where) {
  59. if ($where['priceOrder'] === 'desc') {
  60. $query->order("price desc");
  61. } else {
  62. $query->order("price asc");
  63. }
  64. })->when(isset($where['salesOrder']) && $where['salesOrder'] != '', function ($query) use ($where) {
  65. if ($where['salesOrder'] === 'desc') {
  66. $query->order("sales desc");
  67. } else {
  68. $query->order("sales asc");
  69. }
  70. })->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
  71. $query->page($page, $limit);
  72. })->field($field)->order('sort desc,id desc')->select()->toArray();
  73. }
  74. /**
  75. * 获取一条积分商品数据
  76. * @param int $id
  77. * @param string $field
  78. * @return array|\think\Model|null
  79. * @throws \think\db\exception\DataNotFoundException
  80. * @throws \think\db\exception\DbException
  81. * @throws \think\db\exception\ModelNotFoundException
  82. */
  83. public function validProduct(int $id, string $field)
  84. {
  85. $where = ['is_show' => 1, 'is_del' => 0];
  86. return $this->search($where)->where('id', $id)->field($field)->order('add_time desc')->find();
  87. }
  88. }