123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- declare (strict_types=1);
- namespace app\api\model;
- use app\common\library\helper;
- use app\common\model\CustomBlockGoods;
- use app\common\model\CustomBlocks as CustomBlocksModel;
- use app\common\model\ms\MsActivity as MsActivityModel;
- use app\api\model\za\ZaActivity as ZaActivityModel;
- /**
- * 首页自定义模块
- * Class CustomBlocks
- * @package app\api\model
- * Author: zhangs
- * DateTime: 2021/9/24 16:45
- */
- class CustomBlocks extends CustomBlocksModel
- {
- public function getList($param = [])
- {
- // 实例化新查询对象
- /* $query = $this->getNewQuery();
- // 执行查询
- $list = $query->alias($this->name)
- ->order('sort', 'asc')
- ->select();
- if (!empty($list)) {
- foreach ($list as $item) {
- //①新品:即该版块按商品上架时间倒序排序
- //②销量:即该版块按商品销量倒序排序
- //③综合:即该版块按(购买数*1.5+加入购物车数+收藏数*0.8)之和排倒序
- $sortType = $item['sort_type'];
- if ($sortType == 2) { // 综合
- $sortArr = ['common_sort'=>'desc'];
- } elseif ($sortType == 1) { // 销量
- $sortArr = ['goods_sales'=>'desc'];
- } else { // 新品
- $sortArr = ['goods.create_time'=>'desc'];
- }
- $goodsList = CustomBlockGoods::alias('cbg')
- ->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')
- ->leftJoin('goods', 'goods.goods_id = cbg.goods_id')
- ->where('block_id', $item['id'])
- ->where('goods.status', 10)
- ->where('goods.stock_total', '>', 0)
- ->where('goods.is_delete', 0)
- ->order('cbg.sort','desc')
- ->order($sortArr)
- ->select();
- $goods = [];
- if (!empty($goodsList)) {
- foreach ($goodsList as $vv) {
- $goodsInfo = $vv;
- // 商品图片列表
- $goodsInfo['goods_images'] = helper::getArrayColumn($vv['goods']['images'], 'file');
- // 商品主图
- $goodsInfo['goods_image'] = current($goodsInfo['goods_images'])['preview_url'];
- $goods[] = [
- 'goods_id' => $goodsInfo['goods_id'],
- 'goods_name' => $goodsInfo['goods_name'],
- 'spec_type' => $goodsInfo['spec_type'],
- 'goods_price_min' => $goodsInfo['goods_price_min'],
- 'goods_price_max' => $goodsInfo['goods_price_max'],
- 'line_price_min' => $goodsInfo['line_price_min'],
- 'line_price_max' => $goodsInfo['line_price_max'],
- 'goods_images' => $goodsInfo['goods_images'],
- 'goods_image' => $goodsInfo['goods_image'],
- 'goods_sales' => $goodsInfo['goods_sales'],
- ];
- }
- }
- $item['goods'] = $goods;
- }
- }
- return $list;*/
- $allGoods = [];
- $goodsList = CustomBlockGoods::alias('cbg')
- ->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')
- ->leftJoin('goods', 'goods.goods_id = cbg.goods_id')
- ->where('goods.status', 10)
- //->where('goods.stock_total', '>', 0)
- ->where('goods.is_delete', 0)
- ->order('cbg.sort','desc')
- ->select();
- if (!empty($goodsList)) {
- foreach ($goodsList as $vv) {
- $goodsInfo = $vv;
- // 商品图片列表
- $goodsInfo['goods_images'] = helper::getArrayColumn($vv['goods']['images'], 'file');
- // 商品主图
- $goodsInfo['goods_image'] = current($goodsInfo['goods_images'])['preview_url'];
- $miaosha = (new MsActivityModel)->getMsPrice($goodsInfo['goods_id'],$goodsInfo['goods_price_min']);
- // $goodsInfo['miaosha'] = $miaosha;
- //买一赠一
- $za = (new ZaActivityModel())->getZaGood($goodsInfo['goods_id']);
-
- $allGoods[] = [
- 'goods_id' => $goodsInfo['goods_id'],
- 'goods_name' => $goodsInfo['goods_name'],
- 'spec_type' => $goodsInfo['spec_type'],
- 'goods_price_min' => $goodsInfo['goods_price_min'],
- 'goods_price_max' => $goodsInfo['goods_price_max'],
- 'line_price_min' => $goodsInfo['line_price_min'],
- 'line_price_max' => $goodsInfo['line_price_max'],
- 'goods_images' => $goodsInfo['goods_images'],
- 'goods_image' => $goodsInfo['goods_image'],
- 'goods_sales' => $goodsInfo['goods_sales'],
- 'stock_total' => $goodsInfo['stock_total'],
- 'miaosha' => $miaosha,
- 'za'=>$za
- ];
- }
- }
- return $allGoods;
- }
- }
|