98 lines
3.1 KiB
PHP
98 lines
3.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年10月12日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
|
|
namespace app\models\common\integral\mall;
|
|
|
|
use app\models\common\CommonGoodsListForm;
|
|
use app\models\integral\mall\IntegralMallGoods;
|
|
use app\models\integral\mall\IntegralMallGoodsAttr;
|
|
use app\models\Goods;
|
|
use app\models\GoodsHub;
|
|
use app\models\GoodsAttr;
|
|
use app\models\Model;
|
|
use app\components\SiteHelper;
|
|
use app\components\SysConst;
|
|
use app\components\Serializer;
|
|
|
|
|
|
class CommonIntegralMallGoodsListForm extends CommonGoodsListForm
|
|
{
|
|
|
|
protected function getQuery($cat_query)
|
|
{
|
|
$query = Goods::find()->alias('g')
|
|
->leftJoin(['gh' => GoodsHub::tableName()], 'gh.id=g.goods_hub_id')
|
|
->leftJoin(['img' => IntegralMallGoods::tableName()], 'img.goods_id=g.id')
|
|
->leftJoin(['gc' => $cat_query], 'gc.goods_hub_id=gh.id');
|
|
return $query;
|
|
}
|
|
|
|
|
|
protected function handleList($list)
|
|
{
|
|
foreach ($list as $index => $item) {
|
|
if (isset($item['status'])) {
|
|
$item['status_cn'] = $item['status'] == Goods::STATUS_ONLINE ? '已上架' : '已下架';
|
|
}
|
|
$item['created_at_cn'] = date('Y-m-d H:i:s', $item['created_at']);
|
|
if (isset($item['goods_hub_id'])) {
|
|
$item['cat_list'] = $this->getCatList($item['goods_hub_id']);
|
|
}
|
|
$item['cover_pic'] = SiteHelper::getFullUrl($item['cover_pic']);
|
|
if ($this->scenario == 'detail') {
|
|
// $item['detail'] = SiteHelper::repairContent($item['detail']);
|
|
// $item['pic_urls'] = $this->fixPicUrls($item['pic_urls']);
|
|
// $item['video_url'] = SiteHelper::getFullUrl($item['video_url']);
|
|
// $item['goods_sales'] = $item['virtaul_sales'] + $item['sales'];
|
|
$item['attr_groups'] = empty($item['attr_groups']) ? [] : json_decode($item['attr_groups'], true);
|
|
$attr = $this->getAttr($item['id']);
|
|
|
|
$attr = array_column($attr, 'price', 'sign_id');
|
|
|
|
if (is_array($item['attr_groups'])) {
|
|
|
|
foreach ($item['attr_groups'] as $key => $value) {
|
|
|
|
// unset($value['attr_group_name']);
|
|
unset($value['attr_group_id']);
|
|
|
|
foreach ($value['attr_list'] as $key1 => $value1) {
|
|
$value['attr_list'][$key1]['price'] = $attr[$value1['attr_id']];
|
|
}
|
|
$item['attr_groups'][$key] = $value;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
$list[$index] = $item;
|
|
}
|
|
return $list;
|
|
}
|
|
|
|
//获取商品规格
|
|
private function getAttr($goods_id)
|
|
{
|
|
$attr = GoodsAttr::find()->alias('gr')
|
|
->where([
|
|
'gr.goods_id' => $goods_id,
|
|
'gr.is_delete' => 0,
|
|
])
|
|
->select('gr.id,gr.goods_id,gr.price,gr.sign_id')
|
|
->asArray()->all();
|
|
|
|
return $attr;
|
|
|
|
}
|
|
}
|
|
|