StoreNewcomerDao.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\newcomer;
  13. use app\dao\BaseDao;
  14. use app\model\activity\newcomer\StoreNewcomer;
  15. /**
  16. * 新人礼商品
  17. * Class StoreNewcomerDao
  18. * @package app\dao\activity\newcomer
  19. */
  20. class StoreNewcomerDao extends BaseDao
  21. {
  22. /**
  23. * 设置模型
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return StoreNewcomer::class;
  29. }
  30. /**
  31. * 搜索
  32. * @param array $where
  33. * @return \crmeb\basic\BaseModel|mixed|\think\Model
  34. */
  35. protected function search(array $where = [])
  36. {
  37. return parent::search($where)->when(isset($where['storeProductId']), function ($query) {
  38. $query->where('product_id', 'IN', function ($query) {
  39. $query->name('store_product')->where('is_show', 1)->where('is_del', 0)->field('id');
  40. });
  41. });
  42. }
  43. /**
  44. * 新人专享商品列表
  45. * @param array $where
  46. * @param string $field
  47. * @param int $page
  48. * @param int $limit
  49. * @param array $with
  50. * @return array
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. */
  55. public function getList(array $where, string $field = '*', int $page = 0, int $limit = 0, array $with = [])
  56. {
  57. return $this->search($where)->field($field)
  58. ->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
  59. $query->page($page, $limit);
  60. })->when($with, function ($query) use ($with) {
  61. $query->with($with);
  62. })->when(isset($where['priceOrder']) && $where['priceOrder'] != '', function ($query) use ($where) {
  63. if ($where['priceOrder'] === 'desc') {
  64. $query->order("price desc");
  65. } else {
  66. $query->order("price asc");
  67. }
  68. })->when(isset($where['salesOrder']) && $where['salesOrder'] != '', function ($query) use ($where) {
  69. if ($where['salesOrder'] === 'desc') {
  70. $query->order("sales desc");
  71. } else {
  72. $query->order("sales asc");
  73. }
  74. })->order('id desc')->select()->toArray();
  75. }
  76. }