123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- <?php
- namespace app\api\controller;
- use think\Db;
- class Index extends Base
- {
- public function initialize(){
- parent::initialize();
- parent::check_login();
- }
-
- public function getBanner()
- {
- $list = Db::table('store_banner')
- ->field('id,name,cover,content')
- ->where(['is_deleted'=>0])
- ->order('sort desc ,id desc')
- ->cache(300)
- ->select();
- $this->success('ok',$list);
- }
-
- public function getBannerInfo()
- {
- $detail = Db::table('store_banner')->field('id,name,cover,content')->where(['id'=>input('id')])->find();
- $this->success('ok',['detail'=>$detail]);
- }
-
- public function indexCollectionList(){
- checkCollectionState();
- $type = input('type',0);
- if(!in_array($type,[0,1,3])) $this->error('参数错误');
- $in_type = $type == 0 ? '1,3' : $type;
- $issue_mode = input('issue_mode',0);
- $list = Db::name('store_collection')
- ->where('is_deleted',0)
- ->where('status',1)
- ->whereIn('type',$in_type)
- ->when($issue_mode,function ($query)use($issue_mode){ if($issue_mode) $query->where('issue_mode',$issue_mode);})
- ->field('id,cover,name,type,label,price,inventory,now_inventory,state,sell_time,advance_info,auth_name,auth_img,issue_mode,apply_st,before_time')
- ->order('state asc,sell_time asc')
- ->limit($this->off_set,$this->page_num)
- ->select();
- foreach ($list as &$v){
- $advance_minutes = $v['before_time'];
-
- if($v['issue_mode'] == 1){
- $priority = checkMemberPriority($this->uid,$v['id']);
- if($priority){
- $sell_time = strtotime($v['sell_time'])-($advance_minutes * 60);
- if ($sell_time <= time()) $info['state'] = 1;
- $info['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;
- $v['is_remind'] = getRemind($this->uid,$v['id']) ? true : false;
- }
- $this->success('成功',$list);
- }
-
- public function CollectionCalendar(){
- checkCollectionState();
- $type = input('type',0);
- $in_type= $type ? $type :'1,3';
- $datelist = Db::name('store_collection')
- ->where('is_deleted',0)
- ->where('status',1)
- ->where('state',2)
- ->whereIn('type',$in_type)
- ->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)
- ->whereIn('type',$in_type)
- ->field('id,cover,name,label,price,inventory,now_inventory,state,sell_time,date,issue_mode,apply_st')
- ->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);
- }
-
- public function CollectionDetail(){
- $collect_id = input('id');
- if (!$collect_id) $this->error('参数错误');
- checkCollectionState($collect_id);
- (new Timedtask())->collectionDraw($collect_id);
- $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,type,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,advance_info,issue_mode,apply_st,apply_end,is_task,before_time')
- ->find();
- if(!$info) $this->error('商品已下架');
-
- $draw = Db::name('store_collection_draw')->where(['coll_id'=>$info['id'],'sell_time'=>$info['sell_time'],'user_id'=>$this->uid])->find();
- $info['has_apply'] = empty($draw) ? 0 : 1;
- $info['apply_code'] = empty($draw) ? '' : $draw['code'];
- $info['ballot_status'] = empty($draw) ? 0 : $draw['is_ballot'];
- $info['all_apply'] = Db::name('store_collection_draw')->where(['coll_id'=>$info['id'],'sell_time'=>$info['sell_time']])->count();
- if (!$info) $this->error('藏品不存在');
- $info['describe'] = explode('|',$info['describe']);
- $info['before_count'] = 0;
-
- $set_time = $info['sell_time'];
- if( $info['issue_mode'] == 1){
- $priority = checkMemberPriority($this->uid,$info['id']);
- if($priority){
- $sell_time = strtotime($info['sell_time'])-($info['before_time'] * 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;
-
- $info['circulate_num']= Db::name('store_order_info')
- ->where('c_id',$info['id'])
- ->where('is_destruction',1)
- ->whereIn('resale_status','1,2')
- ->count();
- $this->success('成功',$info);
- }
-
- 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('设置失败');
- }
-
- public function certificate()
- {
- $this->success('ok',['name' => '蚂蚁链HASH', 'link' => '0c214bcd4f1766fdd6d36f127234fc7e7ba883711e19938777f01523c28e74dc',]);
- }
- }
|