StoreIntegralDao.php 3.2 KB

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