CustomBlocks.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. declare (strict_types=1);
  3. namespace app\api\model;
  4. use app\common\library\helper;
  5. use app\common\model\CustomBlockGoods;
  6. use app\common\model\CustomBlocks as CustomBlocksModel;
  7. use app\common\model\ms\MsActivity as MsActivityModel;
  8. use app\api\model\za\ZaActivity as ZaActivityModel;
  9. /**
  10. * 首页自定义模块
  11. * Class CustomBlocks
  12. * @package app\api\model
  13. * Author: zhangs
  14. * DateTime: 2021/9/24 16:45
  15. */
  16. class CustomBlocks extends CustomBlocksModel
  17. {
  18. public function getList($param = [])
  19. {
  20. // 实例化新查询对象
  21. /* $query = $this->getNewQuery();
  22. // 执行查询
  23. $list = $query->alias($this->name)
  24. ->order('sort', 'asc')
  25. ->select();
  26. if (!empty($list)) {
  27. foreach ($list as $item) {
  28. //①新品:即该版块按商品上架时间倒序排序
  29. //②销量:即该版块按商品销量倒序排序
  30. //③综合:即该版块按(购买数*1.5+加入购物车数+收藏数*0.8)之和排倒序
  31. $sortType = $item['sort_type'];
  32. if ($sortType == 2) { // 综合
  33. $sortArr = ['common_sort'=>'desc'];
  34. } elseif ($sortType == 1) { // 销量
  35. $sortArr = ['goods_sales'=>'desc'];
  36. } else { // 新品
  37. $sortArr = ['goods.create_time'=>'desc'];
  38. }
  39. $goodsList = CustomBlockGoods::alias('cbg')
  40. ->field('cbg.*,goods.*,(goods.sales_initial+goods.sales_actual) as goods_sales,(goods.collect_num*0.8+goods.cart_num+(goods.sales_initial+goods.sales_actual)*1.5) as common_sort')
  41. ->leftJoin('goods', 'goods.goods_id = cbg.goods_id')
  42. ->where('block_id', $item['id'])
  43. ->where('goods.status', 10)
  44. ->where('goods.stock_total', '>', 0)
  45. ->where('goods.is_delete', 0)
  46. ->order('cbg.sort','desc')
  47. ->order($sortArr)
  48. ->select();
  49. $goods = [];
  50. if (!empty($goodsList)) {
  51. foreach ($goodsList as $vv) {
  52. $goodsInfo = $vv;
  53. // 商品图片列表
  54. $goodsInfo['goods_images'] = helper::getArrayColumn($vv['goods']['images'], 'file');
  55. // 商品主图
  56. $goodsInfo['goods_image'] = current($goodsInfo['goods_images'])['preview_url'];
  57. $goods[] = [
  58. 'goods_id' => $goodsInfo['goods_id'],
  59. 'goods_name' => $goodsInfo['goods_name'],
  60. 'spec_type' => $goodsInfo['spec_type'],
  61. 'goods_price_min' => $goodsInfo['goods_price_min'],
  62. 'goods_price_max' => $goodsInfo['goods_price_max'],
  63. 'line_price_min' => $goodsInfo['line_price_min'],
  64. 'line_price_max' => $goodsInfo['line_price_max'],
  65. 'goods_images' => $goodsInfo['goods_images'],
  66. 'goods_image' => $goodsInfo['goods_image'],
  67. 'goods_sales' => $goodsInfo['goods_sales'],
  68. ];
  69. }
  70. }
  71. $item['goods'] = $goods;
  72. }
  73. }
  74. return $list;*/
  75. $allGoods = [];
  76. $goodsList = CustomBlockGoods::alias('cbg')
  77. ->field('cbg.*,goods.*,(goods.sales_initial+goods.sales_actual + goods.sales_shops) as goods_sales,(goods.collect_num*0.8+goods.cart_num+(goods.sales_initial+goods.sales_actual)*1.5) as common_sort')
  78. ->leftJoin('goods', 'goods.goods_id = cbg.goods_id')
  79. ->where('goods.status', 10)
  80. //->where('goods.stock_total', '>', 0)
  81. ->where('goods.is_delete', 0)
  82. ->order('cbg.sort','desc')
  83. ->select();
  84. if (!empty($goodsList)) {
  85. foreach ($goodsList as $vv) {
  86. $goodsInfo = $vv;
  87. // 商品图片列表
  88. $goodsInfo['goods_images'] = helper::getArrayColumn($vv['goods']['images'], 'file');
  89. // 商品主图
  90. $goodsInfo['goods_image'] = current($goodsInfo['goods_images'])['preview_url'];
  91. $miaosha = (new MsActivityModel)->getMsPrice($goodsInfo['goods_id'],$goodsInfo['goods_price_min']);
  92. // $goodsInfo['miaosha'] = $miaosha;
  93. //买一赠一
  94. $za = (new ZaActivityModel())->getZaGood($goodsInfo['goods_id']);
  95. $allGoods[] = [
  96. 'goods_id' => $goodsInfo['goods_id'],
  97. 'goods_name' => $goodsInfo['goods_name'],
  98. 'spec_type' => $goodsInfo['spec_type'],
  99. 'goods_price_min' => $goodsInfo['goods_price_min'],
  100. 'goods_price_max' => $goodsInfo['goods_price_max'],
  101. 'line_price_min' => $goodsInfo['line_price_min'],
  102. 'line_price_max' => $goodsInfo['line_price_max'],
  103. 'goods_images' => $goodsInfo['goods_images'],
  104. 'goods_image' => $goodsInfo['goods_image'],
  105. 'goods_sales' => $goodsInfo['goods_sales'],
  106. 'stock_total' => $goodsInfo['stock_total'],
  107. 'miaosha' => $miaosha,
  108. 'za'=>$za
  109. ];
  110. }
  111. }
  112. return $allGoods;
  113. }
  114. }