123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- namespace app\api\controller;
- use think\Db;
- /**
- * @title 首页、详情
- * @controller Index
- * @package app\api\controller
- */
- class Index extends Base
- {
- public function initialize(){
- // parent::check_login();
- }
- /**
- * @title 获取轮播图
- * @desc 获取轮播图
- * @author Gavin
- * @url /api/Index/getBanner
- * @method POST
- * @header name:Authorization require:1 desc:Token
- *
- */
- public function getBanner()
- {
- $list = Db::table('store_banner')
- ->field('id,name,cover')
- ->where(['is_deleted'=>0])
- ->order('sort desc ,id desc')
- ->select();
- $this->success('ok',$list);
- }
- /**
- * @title 首页藏品列表
- * @desc 首页藏品列表
- * @author Gavin
- * @url /api/Index/indexCollectionList
- * @method POST
- * @header name:Authorization require:1 desc:Token
- *
- * @return name:name type:string default:-- desc:藏品名称
- * @return name:cover type:string default:-- desc:藏品图
- * @return name:label type:string default:-- desc:标签
- * @return name:price type:DECIMAL default:-- desc:价格
- * @return name:inventory type:int default:-- desc:库存
- * @return name:now_inventory type:int default:-- desc:剩余库存
- * @return name:state type:float default:-- desc:藏品状态(1:进行中2:即将开售3:已售罄)
- * @return name:sell_time type:string default:-- desc:发行时间
- * @return name:is_remind type:string default:-- desc:是否设置提醒true:已设置false:未设置
- */
- public function indexCollectionList(){
- checkCollectionState();
- $type = input('type',1);
- if ($this->uid=='1' || $this->uid=='3'){
- $list = Db::name('store_collection')
- ->where('is_deleted',0)
- ->whereIn('type',$type)
- ->field('id,cover,name,label,price,inventory,now_inventory,state,sell_time')
- ->order('state asc,sell_time asc')
- ->select();
- }else{
- $list = Db::name('store_collection')
- ->where('is_deleted',0)
- ->where('status',1)
- ->whereIn('type',$type)
- ->field('id,cover,name,label,price,inventory,now_inventory,state,sell_time')
- ->order('state asc,sell_time asc')
- ->select();
- }
- $memberVip = Db::name('store_member')->where('id',$this->uid)->value('vip');
- $advance_minutes = getAdvanceMinutes();
- foreach ($list as &$v){
- if ($memberVip==2 && $advance_minutes>0){
- if ($v['state']==2){
- $sell_time = strtotime($v['sell_time'])-($advance_minutes*60);
- if ($sell_time<=time()){
- $v['state'] = 1;
- }
- $v['sell_time'] = date('Y-m-d H:i:s',$sell_time);
- }
- }
- $now_inventory = getCollectionInventory($v['id']);
- $v['now_inventory'] = $now_inventory<=0 ? 0 : $now_inventory;
- }
- foreach ($list as &$v){
- $v['is_remind'] = getRemind($this->uid,$v['id']) ? true : false;
- }
- $this->success('成功',$list);
- }
- /**
- * @title 发售日历
- * @desc 发售日历
- * @author Gavin
- * @url /api/Index/CollectionCalendar
- * @method POST
- * @header name:Authorization require:1 desc:Token
- *
- * @return name:name type:string default:-- desc:藏品名称
- * @return name:cover type:string default:-- desc:藏品图
- * @return name:label type:string default:-- desc:标签
- * @return name:price type:DECIMAL default:-- desc:价格
- * @return name:inventory type:int default:-- desc:库存
- * @return name:now_inventory type:int default:-- desc:剩余库存
- * @return name:state type:float default:-- desc:藏品状态(1:进行中2:即将开售3:已售罄)
- * @return name:sell_time type:string default:-- desc:发行时间
- * @return name:date type:string default:-- desc:日期
- * @return name:time type:string default:-- desc:时间
- * @return name:is_remind type:string default:-- desc:是否设置提醒true:已设置false:未设置
- */
- public function CollectionCalendar(){
- checkCollectionState();
- $datelist = Db::name('store_collection')
- ->where('is_deleted',0)
- ->where('status',1)
- ->where('state',2)
- ->whereIn('type','1,3')
- ->where('date','>=',date('Y-m-d',time()))
- ->group('date')
- ->order('date asc')
- ->column('date');
- if ($datelist){
- foreach ($datelist as $k=>&$v){
- $array[$k]['date'] = $v;
- $list = Db::name('store_collection')
- ->where('is_deleted',0)
- ->where('status',1)
- ->where('state',2)
- ->where('date',$v)
- ->field('id,cover,name,label,price,inventory,now_inventory,state,sell_time,date')
- ->order('state asc,sell_time asc')
- ->select();
- foreach ($list as &$a){
- $a['time'] = date('H:i',strtotime($a['sell_time']));
- $a['is_remind'] = getRemind($this->uid,$a['id']) ? true : false;
- $now_inventory = getCollectionInventory($a['id']);
- $a['now_inventory'] = $now_inventory<=0 ? 0 : $now_inventory;
- }
- $array[$k]['list'] = $list;
- }
- }else $array=[];
- $this->success('成功',$array);
- }
- /**
- * @title 藏品详情
- * @desc 藏品详情
- * @author Gavin
- * @url /api/Index/CollectionDetail
- * @method POST
- * @header name:Authorization require:1 desc:Token
- *
- * @param name:id type:string require:1 default:-- desc:藏品ID
- *
- * @return name:name type:string default:-- desc:藏品名称
- * @return name:cover type:string default:-- desc:藏品图
- * @return name:label type:string default:-- desc:标签
- * @return name:price type:DECIMAL default:-- desc:价格
- * @return name:inventory type:int default:-- desc:库存
- * @return name:now_inventory type:int default:-- desc:剩余库存
- * @return name:state type:float default:-- desc:藏品状态(1:进行中2:即将开售3:已售罄)
- * @return name:sell_time type:string default:-- desc:发行时间
- * @return name:describe type:string default:-- desc:商品描述
- * @return name:buy_count type:int default:1 desc:限购数量
- * @return name:instructions type:int default:1 desc:权益说明
- * @return name:buy_notice type:int default:1 desc:购买须知
- * @return name:warm_prompt type:int default:1 desc:温馨提示
- * @return name:auth_img type:int default:1 desc:作者头像
- * @return name:auth_name type:int default:1 desc:作者姓名
- * @return name:is_remind type:string default:-- desc:是否设置提醒true:已设置false:未设置
- * @return name:share_img type:string default:-- desc:分享二维码
- */
- public function CollectionDetail(){
- $collect_id = input('id');
- if (!$collect_id) $this->error('参数错误');
- checkCollectionState($collect_id);
- if ($this->uid=='1' || $this->uid=='3'){
- $info = Db::name('store_collection')
- ->where('is_deleted',0)
- ->whereIn('type','1,3')
- ->where('id',$collect_id)
- ->field('id,cover,name,label,price,inventory,now_inventory,state,sell_time,describe,buy_count,instructions,buy_notice,warm_prompt,auth_img,auth_name,share_img,intro,detail_img,format')
- ->find();
- }else{
- $info = Db::name('store_collection')
- ->where('is_deleted',0)
- ->where('status',1)
- ->whereIn('type','1,3')
- ->where('id',$collect_id)
- ->field('id,cover,name,label,price,inventory,now_inventory,state,sell_time,describe,buy_count,instructions,buy_notice,warm_prompt,auth_img,auth_name,share_img,intro,detail_img,format')
- ->find();
- }
- if (!$info) $this->error('藏品不存在');
- $info['describe'] = explode('|',$info['describe']);
- $memberVip = Db::name('store_member')->where('id',$this->uid)->value('vip');
- $advance_minutes = getAdvanceMinutes();
- if ($memberVip==2 && $advance_minutes>0){
- if ($info['state']==2){
- $sell_time = strtotime($info['sell_time'])-($advance_minutes*60);
- if ($sell_time<=time()){
- $info['state'] = 1;
- }
- $info['sell_time'] = date('Y-m-d H:i:s',$sell_time);
- }
- }
- $info['is_remind'] = getRemind($this->uid,$info['id']) ? true : false;
- $now_inventory = getCollectionInventory($info['id']);
- $info['now_inventory'] = $now_inventory<=0 ? 0 : $now_inventory;
- $this->success('成功',$info);
- }
- /**
- * @title 设置提醒
- * @desc 设置提醒
- * @author Gavin
- * @url /api/Index/setRemind
- * @method POST
- * @header name:Authorization require:1 desc:Token
- *
- * @param name:id type:string require:1 default:-- desc:藏品ID
- */
- public function setRemind(){
- $id = input('id');
- if (!$id) $this->error('参数错误');
- $remind = Db::name('store_collection_remind')
- ->where('mid',$this->uid)
- ->where('c_id',$id)
- ->count();
- if ($remind) $this->error('已设置过');
- $data = [
- 'c_id'=>$id,
- 'mid'=>$this->uid
- ];
- if (Db::name('store_collection_remind')->insert($data)) $this->success('设置成功');
- $this->error('设置失败');
- }
- }
|