TeamLists.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\shopapi\lists;
  20. use app\common\enum\GoodsEnum;
  21. use app\common\enum\TeamEnum;
  22. use app\common\lists\ListsSearchInterface;
  23. use app\common\model\TeamActivity;
  24. use app\common\model\TeamGoods;
  25. use app\common\model\TeamGoodsItem;
  26. class TeamLists extends BaseShopDataLists implements ListsSearchInterface
  27. {
  28. /**
  29. * @notes 设置搜索
  30. * @return array
  31. * @author 张无忌
  32. * @date 2021/8/3 15:13
  33. */
  34. public function setSearch(): array
  35. {
  36. return [];
  37. }
  38. /**
  39. * @notes 拼团活动商品列表
  40. * @return array
  41. * @author 张无忌
  42. * @date 2021/8/3 15:11
  43. */
  44. public function lists(): array
  45. {
  46. // 查询出正在进行的活动ID
  47. $activityIds = (new TeamActivity())->where([
  48. ['start_time', '<=', time()],
  49. ['end_time', '>=', time()],
  50. ['status', '=', TeamEnum::TEAM_STATUS_CONDUCT]
  51. ])->column('id');
  52. // 查询出活动中的商品数据
  53. $lists = (new TeamGoods())->alias('TG')
  54. ->field('TG.*,TA.people_num,TA.partake_number')
  55. ->whereIn('TG.team_id', $activityIds)
  56. ->where('G.status', GoodsEnum::STATUS_SELL)
  57. ->join('team_activity TA', 'TA.id = TG.team_id')
  58. ->join('goods G', 'G.id = TG.goods_id')
  59. ->order('TG.min_team_price asc')
  60. ->limit($this->limitOffset, $this->limitLength)
  61. ->select()->toArray();
  62. $goodsIds = array_column($lists,'goods_id');
  63. $salesList = TeamGoodsItem::where(['team_id'=>$activityIds,'goods_id'=>$goodsIds])
  64. ->group('goods_id')
  65. ->column('sum(sales_volume)','goods_id');
  66. // 处理数据
  67. foreach ($lists as &$item) {
  68. $item['name'] = $item['goods_snap']['name'];
  69. $item['image'] = $item['goods_snap']['image'];
  70. $item['min_price'] = $item['goods_snap']['min_price'];
  71. $item['max_price'] = $item['goods_snap']['max_price'];
  72. unset($item['goods_snap']);
  73. $item['activity_sales'] = $salesList[$item['goods_id']] ?? 0;
  74. }
  75. return $lists;
  76. }
  77. /**
  78. * @notes 总数量
  79. * @return int
  80. * @author 张无忌
  81. * @date 2021/8/3 15:12
  82. */
  83. public function count(): int
  84. {
  85. $activityIds = (new TeamActivity())->where([
  86. ['start_time', '<=', time()],
  87. ['end_time', '>=', time()],
  88. ['status', '=', TeamEnum::TEAM_STATUS_CONDUCT]
  89. ])->column('id');
  90. return (new TeamGoods())->alias('TG')
  91. ->field('TG.*,TA.people_num')
  92. ->whereIn('TG.team_id', $activityIds)
  93. ->where('G.status', GoodsEnum::STATUS_SELL)
  94. ->join('goods G', 'G.id = TG.goods_id')
  95. ->join('team_activity TA', 'TA.id = TG.team_id')
  96. ->count();
  97. }
  98. }