123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- <?php
- namespace app\api\controller;
- use app\common\model\DiscountGoods;
- use app\common\model\GiftGoods;
- use app\common\model\GoodsColumn;
- use app\common\model\GoodsOrder;
- use app\common\model\GoodsOrderItem;
- use app\common\model\InformationArticle;
- use app\common\model\InformationGoods;
- use app\common\model\MallMenu;
- use app\common\model\MenuGoods;
- use app\common\model\RegionMenu;
- use app\common\model\RegionGoods;
- use app\common\model\SeckillActivity;
- use app\common\model\SeckillGoods;
- use app\common\model\StoreGoods;
- use app\common\model\StoreGoodsItem;
- use app\common\model\SystemConfig;
- /**
- * @title 商城首页
- * @controller MallIndex
- * @package app\api\controller
- */
- class MallIndex extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::setUid();
- }
- /**
- * @title 获取首页公告
- * @desc 获取首页公告
- * @author qc
- * @url /api/Mall_index/getIndexNotice
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:detail type:srting default:-- desc:公告内容
- */
- public function getIndexNotice()
- {
- $detail = SystemConfig::where(['name'=>'index_notice'])->value('value');
- $this->success('ok',['detail'=>$detail]);
- }
- /**
- * @title 获取首页菜单(一级)
- * @desc 获取首页菜单(一级)
- * @author qc
- * @url /api/Mall_index/getIndexMenu
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:num type:int default:10 desc:查询数量
- * @return name:title type:srting default:-- desc:标题
- * @return name:logo type:srting default:-- desc:图片路径
- */
- public function getIndexMenu()
- {
- $num = input('get.num', 10);
- $list = MallMenu::field('id,title,logo')->where('is_deleted', 0)
- ->where('pid', 0)
- ->order('sort desc ,id desc')
- ->limit(0, $num)->select()->toArray();
- $this->success('ok', $list);
- }
- /**
- * @title 获取首页菜单(二级)
- * @desc 获取首页菜单(二级)
- * @author qc
- * @url /api/Mall_index/getSecondIndexMenu
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:-- desc:菜单id
- * @return name:title type:srting default:-- desc:标题
- * @return name:logo type:srting default:-- desc:图片路径
- */
- public function getSecondIndexMenu()
- {
- $pid = input('get.id');
- $list = MallMenu::field('id,title,logo')->where('is_deleted', 0)
- ->where('pid', $pid)
- ->order('sort desc ,id asc')
- ->select()->toArray();
- $this->success('ok', $list);
- }
- /**
- *
- * @title 获取首页菜单关联商品
- * @desc 获取首页菜单关联商品
- * @author qc
- * @url /api/Mall_index/getMallMenuGoods
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @param name:second_id type:int default:-- desc:菜单id(二级菜单id)
- * @return name:goods_id type:int default:-- desc:商品id
- * @return name:name type:srting default:-- desc:商品名称
- * @return name:cover type:srting default:-- desc:图片路径
- * @return name:low_price type:float default:-- desc:最低价
- * @return name:max_price type:float default:-- desc:下划线价格
- */
- public function getMallMenuGoods()
- {
- $second_id = input('get.second_id');
- $where = [];
- $where[] = ['m.second_menu', '=', $second_id];
- $where[] = ['g.is_deleted', '=', 0];
- $where[] = ['g.status', '=', 1];
- $list = MenuGoods::field('m.id as mid,m.goods_id,g.id,g.name,g.cover,g.desc,g.low_price')->alias('m')
- ->where($where)
- ->leftJoin('StoreGoods g', 'g.id = m.goods_id')
- ->order('m.sort desc ,m.id desc')
- ->limit($this->off_set, $this->page_num)
- ->select()->toArray();
- array_walk($list, function (&$v, $k) {
- $v['max_price'] = GoodsOrderItem::where('goods_id', $v['id'])->max('original_price');
- });
- $this->success('ok', ['list' => $list]);
- }
- /**
- *
- * @title 获取首页菜单搭配商品
- * @desc 获取首页菜单搭配商品
- * @author qc
- * @url /api/Mall_index/getRecommendGoods
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @param name:first_id type:int default:-- desc:菜单id(1级菜单id)
- * @return name:goods_id type:int default:-- desc:商品id
- * @return name:name type:srting default:-- desc:商品名称
- * @return name:cover type:srting default:-- desc:图片路径
- * @return name:content type:srting default:-- desc:图片(多张用|隔开)
- * @return name:low_price type:float default:-- desc:最低价
- * @return name:max_price type:float default:-- desc:下划线价格
- */
- public function getRecommendGoods()
- {
- $first_id = input('get.first_id');
- $where = [];
- $where[] = ['m.first_menu', '<>', $first_id];
- $where[] = ['g.is_deleted', '=', 0];
- $where[] = ['g.status', '=', 1];
- $list = MenuGoods::field('m.id as mid,m.goods_id,g.id,g.name,g.cover,g.desc,g.low_price,content')->alias('m')
- ->where($where)
- ->leftJoin('StoreGoods g', 'g.id = m.goods_id')
- ->order('m.sort desc ,m.id desc')
- ->limit($this->off_set, $this->page_num)
- ->select()->toArray();
- array_walk($list, function (&$v, $k) {
- $v['max_price'] = GoodsOrderItem::where('goods_id', $v['id'])->max('original_price');
- });
- $this->success('ok', ['list' => $list]);
- }
- /**
- * @title 获取首页推荐商品区(一级)
- * @desc 获取首页推荐商品区(一级)
- * @author qc
- * @url /api/Mall_index/getIndexRegion
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:num type:int default:10 desc:查询数量
- * @return name:title type:srting default:-- desc:标题
- * @return name:desc type:srting default:-- desc:简介
- * @return name:logo type:srting default:-- desc:图片路径
- */
- public function getIndexRegion()
- {
- $num = input('get.num', 10);
- $list = RegionMenu::field('id,title,desc,logo')->where('is_deleted', 0)
- ->where('pid', 0)
- ->order('sort desc ,id desc')
- ->limit(0, $num)->select()->toArray();
- $this->success('ok', $list);
- }
- /**
- * @title 获取首页专区详情(最多三级)
- * @desc 获取首页专区详情
- * @author qc
- * @url /api/Mall_index/getRegionMenu
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:-- desc:专区id
- * @return name:title type:srting default:-- desc:标题
- * @return name:logo type:srting default:-- desc:图片路径
- */
- public function getRegionMenu()
- {
- $id = input('get.id');
- $region = RegionMenu::field('id,title,logo,pid')->where('id', $id)->find()->toArray();
- $region['children'] = RegionMenu::field('id,title,logo,pid')->where('pid', $region['id'])->where('is_deleted', 0)->select()->toArray();
- if (!empty($region['children'])) {
- foreach ($region['children'] as $k => $v) {
- $region['children'][$k]['children'] = RegionMenu::field('id,title,logo,pid')->where('pid', $v['id'])->where('is_deleted', 0)->select()->toArray();
- }
- }
- $this->success('ok', ['detail' => $region]);
- }
- /**
- * @title 获取首页专区关联商品
- * @desc 获取首页专区关联商品
- * @author qc
- * @url /api/Mall_index/getRegionMenuGoods
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @param name:first_region type:int default:-- desc:第一等级id
- * @param name:second_region type:int default:-- desc:第二等级id
- * @param name:third_region type:int default:-- desc:第三等级id
- * @return name:goods_id type:int default:-- desc:商品id
- * @return name:name type:srting default:-- desc:商品名称
- * @return name:cover type:srting default:-- desc:图片路径
- * @return name:low_price type:float default:-- desc:最低价
- * @return name:max_price type:float default:-- desc:下划线价格
- */
- public function getRegionMenuGoods()
- {
- $first_region = input('get.first_region');
- $second_region = input('get.second_region');
- $third_region = input('get.third_region');
- $where = [];
- if ($first_region) $where[] = ['m.first_region', '=', $first_region];
- if ($second_region) $where[] = ['m.second_region', '=', $second_region];
- if ($third_region) $where[] = ['m.third_region', '=', $third_region];
- $where[] = ['g.is_deleted', '=', 0];
- $where[] = ['g.status', '=', 1];
- $list = RegionGoods::field('m.id as mid,m.goods_id,g.id,g.name,g.cover,g.desc,g.low_price')->alias('m')
- ->where($where)
- ->leftJoin('StoreGoods g', 'g.id = m.goods_id')
- ->order('m.sort desc ,m.id desc')
- ->limit($this->off_set, $this->page_num)
- ->select()->toArray();
- array_walk($list, function (&$v, $k) {
- $v['max_price'] = GoodsOrderItem::where('goods_id', $v['id'])->max('original_price');
- });
- $this->success('ok', ['list' => $list]);
- }
- /**
- * @title 获取首页商品推荐专栏
- * @desc 获取首页商品推荐专栏
- * @author qc
- * @url /api/Mall_index/getGoodsColumn
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:title type:srting default:-- desc:标题
- * @return name:desc type:srting default:-- desc:描述
- */
- public function getGoodsColumn()
- {
- $list = GoodsColumn::field('id,desc,title')->where(['status' => 1, 'is_deleted' => 0])->order('sort desc ,id asc')->select()->toArray();
- $this->success('ok', ['list' => $list]);
- }
- /**
- * @title 获取专区模块推荐商品
- * @desc 第一个亚健康,第二个礼品心选,第三个秒杀(促销)第四个预售
- * @author qc
- * @url /api/Mall_index/getRegionRecommend
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:num type:int default:2 desc:查询数量
- * @return name:goods_id type:int default:-- desc:商品id
- * @return name:name type:string default:-- desc:商品名
- * @return name:low_price type:string default:-- desc:价格
- * @return name:cover type:string default:-- desc:封面
- */
- public function getRegionRecommend()
- {
- $num = input('get.num',2);
- $list = [];
- $list[0] = InformationGoods::field('i.id,i.goods_id,g.name,g.low_price,g.cover')
- ->alias('i')
- ->leftJoin('StoreGoods g','i.goods_id = g.id')
- ->order('i.id desc')
- ->limit(0,$num)
- ->select()->toArray();
- $list[1] = GiftGoods::field('i.id,i.goods_id,g.name,g.low_price,g.cover')
- ->alias('i')
- ->leftJoin('StoreGoods g','i.goods_id = g.id')
- ->order('i.is_hot desc,id desc')
- ->limit(0,$num)
- ->select()->toArray();
- $seckill_act = SeckillActivity::where([['status','=',1],['end_time','> time',date('Y-m-d H:i:s')],['is_deleted','=',0]])
- ->order('sort desc,id asc')->limit(0,1)->select()->toArray();
- if(empty($seckill_act)){
- $list[2] = [];
- }else{
- $list[2] = SeckillGoods::field('i.id,i.goods_id,g.name,g.low_price,g.cover')
- ->alias('i')
- ->leftJoin('StoreGoods g','i.goods_id = g.id')
- ->where('i.act_id',$seckill_act[0]['id'])
- ->order('id desc')
- ->limit(0,$num)
- ->select()->toArray();
- }
- $list[3] = StoreGoods::field('id goods_id,name,low_price,cover')->where(['is_deleted'=>0,'status'=>1,'is_presell'=>1])->order('sort desc ,id desc')
- ->limit(0,$num)->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取首页我的康养食品(pc)
- * @desc 获取首页我的康养食品(pc)
- * @author qc
- * @url /api/Mall_index/getBuyInformationGoods
- * @method GET
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @return name:id type:int default:-- desc:记录id
- * @return name:goods_id type:int default:-- desc:商品id
- * @return name:spec_id type:int default:-- desc:规格id
- * @return name:goods_name type:srting default:-- desc:商品名称
- * @return name:cover type:srting default:-- desc:商品图片
- * @return name:original_price type:float default:-- desc:交易时原价(下划线)
- * @return name:sell_price type:float default:-- desc:交易价格
- */
- public function getBuyInformationGoods()
- {
- parent::checkLogin();
- $order_ids = GoodsOrder::where(['user_id'=>$this->user_id,'pay_state'=>1])->column('id');
- $list = GoodsOrderItem::field('id,goods_id,goods_name,cover,original_price,sell_price')
- ->where([['user_id','=',$this->user_id],['belong','=',1],['order_id','in',$order_ids]])
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取首页资讯
- * @desc 获取首页资讯
- * @author qc
- * @url /api/Mall_index/getIndexInformation
- * @method GET
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @return name:new_article type:array default:-- desc:最新资讯
- * @return name:new_article.id type:int default:-- desc:资讯id
- * @return name:new_article.title type:string default:-- desc:标题
- * @return name:new_article.type type:int default:-- desc:1文章2视频
- * @return name:top_article type:array default:-- desc:推荐资讯(数据同new_article)
- * @return name:hot_article type:array default:-- desc:热门资讯(数据同new_article)
- */
- public function getIndexInformation()
- {
- $list = [];
- $article_field = 'id,title,cover,type';
- // 最新
- $new_article = InformationArticle::field($article_field)->where(['status'=>1,'is_deleted'=>0])->order('id desc')->find();
- $list['new_article'] = $new_article ? $new_article->toArray():'';
- // 推荐
- $top_article = InformationArticle::field($article_field)->where(['status'=>1,'is_deleted'=>0,'is_top'=>1])->order('id desc')->find();
- $list['top_article'] = $top_article ? $top_article->toArray():'';
- // 热门
- $hot_article = InformationArticle::field($article_field)->where(['status'=>1,'is_deleted'=>0])->order('read_num desc')->find();
- $list['hot_article'] = $hot_article ? $hot_article->toArray():'';
- $this->success('ok',['list'=>$list]);
- }
- }
|