114 lines
4.1 KiB
PHP
Executable File
114 lines
4.1 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* @author yupoxiong<i@yufuping.com>
|
|
* @title 首页
|
|
*/
|
|
|
|
namespace app\api\controller;
|
|
use app\common\model\Goodsindex;
|
|
use app\common\model\Goods;
|
|
use app\common\model\GoodsBrand;
|
|
use app\common\model\GoodsItem;
|
|
use app\common\model\GoodsCategory;
|
|
use app\common\model\MallImage;
|
|
use app\common\model\ShopConfig;
|
|
use app\common\model\PhaseConfig;
|
|
use tools\Crypt;
|
|
use think\Request;
|
|
class IndexController extends Controller
|
|
{
|
|
|
|
protected $authExcept = [
|
|
'home','pattern_goods'
|
|
];
|
|
|
|
public function home(Request $request,Goods $gmodel,Goodsindex $gimodel)
|
|
{
|
|
echo Crypt::encrypt(1).'|';
|
|
echo $this->getToken(1);
|
|
$param = $request->param();
|
|
//首页轮播
|
|
$carousel = get_ad('carousel',6);
|
|
$goodsindex_list=$gimodel->where(array('status'=>1))->order('sort_number ASC')->select();
|
|
$goodsindex=array();
|
|
foreach ($goodsindex_list as $key => $value) {
|
|
$goodsindex[$key]['id'] = Crypt::encrypt($value['id']);
|
|
$goodsindex[$key]['name']=$value['name'];
|
|
$goodsindex[$key]['type']=$value['type'];
|
|
$goods_ids=json_decode($value['goods_ids']);
|
|
$where[]=array('g.id','in',$goods_ids);
|
|
$goods_list=$gmodel
|
|
->alias('g')
|
|
->field("mi.thumb_image as img, g.name,g.price,g.id as goods_id,gb.name as brand_name")
|
|
->join('goods_brand gb', 'gb.id= g.brand_id')
|
|
->join('mall_image mi', 'mi.union_id= g.id and is_cover=1 and mi.type=1', 'LEFT')
|
|
->where($where)->select();
|
|
foreach ($goods_list as $k1 => $v1) {
|
|
$goods_list[$k1]['img'] =$this->img_url.$v1['img'];
|
|
$goods_list[$k1]['goods_id'] = Crypt::encrypt($v1['goods_id']);
|
|
}
|
|
$goodsindex[$key]['goods_list']=$goods_list;
|
|
}
|
|
$data = [
|
|
'carousel' =>$carousel,//首页轮播
|
|
'goodsindex' => $goodsindex,//模式板块
|
|
];
|
|
return success($data);
|
|
}
|
|
|
|
//模式商品
|
|
public function pattern_goods(Request $request,Goods $model,Goodsindex $gimodel)
|
|
{
|
|
$param = $request->param();
|
|
$id = $param['id']?Crypt::decrypt($param['id']):'';
|
|
if(!$id){
|
|
return success(array('list'=>[]));
|
|
}
|
|
$goodsindex_info=$gimodel->where(array('status'=>1,'id'=>$id))->find();
|
|
if(!$goodsindex_info){
|
|
return success(array('list'=>[]));
|
|
}
|
|
|
|
$id = $param['id']?Crypt::decrypt($param['id']):'';
|
|
|
|
$goods_ids=json_decode($goodsindex_info['goods_ids']);
|
|
$where[]=array('g.id','in',$goods_ids);
|
|
|
|
$sort=$param['sort']??'asc';
|
|
$order=$param['order']??'g.sort_number';
|
|
|
|
$size=$param['size']>0?$param['size']:12;
|
|
$page_l=$param['page']>1?$param['page']:1;
|
|
$page=$size * ($page_l - 1);
|
|
$goods_count = $model
|
|
->alias('g')
|
|
->where($where)
|
|
->join('goods_brand gb', 'gb.id= g.brand_id')
|
|
->join('mall_image mi', 'mi.union_id= g.id and is_cover=1 and mi.type=1', 'LEFT')
|
|
->count();
|
|
$totalPages = ceil($goods_count / $size);
|
|
$goods_list = $model
|
|
->alias('g')
|
|
->field("mi.thumb_image as img, g.name,g.price,g.id as goods_id,gb.name as brand_name")
|
|
->join('goods_brand gb', 'gb.id= g.brand_id')
|
|
->join('mall_image mi', 'mi.union_id= g.id and is_cover=1 and mi.type=1', 'LEFT')
|
|
->where($where)
|
|
->limit($page, $size)
|
|
->order($order.' '.$sort)
|
|
->select();
|
|
if (!$goods_list) {
|
|
return success(array('list'=>[]));
|
|
}
|
|
foreach ($goods_list as $k1 => $v1) {
|
|
$goods_list[$k1]['img'] =$this->img_url.$v1['img'];
|
|
$goods_list[$k1]['goods_id'] = Crypt::encrypt($v1['goods_id']);
|
|
}
|
|
$page=array(
|
|
'count'=>$goods_count,
|
|
'num'=>$page_l,
|
|
'size'=>$size,
|
|
'page'=>$totalPages
|
|
);
|
|
return success(array('list'=>$goods_list,'page'=>$page));
|
|
}
|
|
} |