优惠券小程序

TopicGoods.php 795B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. class TopicGoods extends Model
  6. {
  7. use HasFactory;
  8. protected $table = 'topic_goods';
  9. public $timestamps = false;
  10. protected static $unguarded = true;
  11. /**
  12. * 专题商品列表
  13. * */
  14. public static function topicGoodsList($topicId, $page, $pageSize)
  15. {
  16. $goodsModel = self::where('enable', 1)->where('topic_id', $topicId);
  17. $count = $goodsModel->count();
  18. $itemIds = $goodsModel->select('item_id')
  19. ->orderBy('sort_num', 'desc')
  20. ->offset(($page-1) * $pageSize)
  21. ->limit($pageSize)
  22. ->pluck('item_id')
  23. ->toArray();
  24. return [$itemIds, $count];
  25. }
  26. }