123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <?php
- namespace app\api\controller;
- use think\Db;
- class Index extends Base
- {
- public function initialize(){
-
- }
-
- 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);
- }
-
- public function indexCollectionList(){
- checkCollectionState();
- $type = '1,3';
- 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,auth_name,auth_img,type,first_cid,first_time')
- ->order('state asc,sell_time desc')
- ->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,auth_name,auth_img,type,first_cid,first_time')
- ->order('state asc,sell_time desc')
- ->select();
- }
- $uid = $this->get_uid();
- foreach ($list as &$v){
-
- if($v['first_time']>0 && $v['state'] == 2 && $uid)
- {
- $data = [
- 'uid' => $uid,
- 'first_time' => $v['first_time'],
- 'state' => $v['state'],
- 'sell_time' => $v['sell_time'],
- 'c_id' => $v['id'],
- ];
- $firstData = getUserBuyCollection($data);
- if(!empty($firstData))
- {
- $v['state'] = $firstData['state'];
- $v['sell_time'] = $firstData['sell_time'];
- }
- }
- $now_inventory = getCollectionInventory($v['id']);
- $v['now_inventory'] = $now_inventory<=0 ? 0 : $now_inventory;
- }
- $this->success('成功',$list);
- }
-
- 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);
- }
-
- 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,first_cid,first_time')
- ->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,first_cid,first_time')
- ->find();
- }
- if (!$info) $this->error('藏品不存在');
- $info['describe'] = explode('|',$info['describe']);
-
- $uid = $this->get_uid();
- if($info['first_time']>0 && $info['state'] == 2 && $uid)
- {
- $data = [
- 'uid' => $uid,
- 'first_time' => $info['first_time'],
- 'state' => $info['state'],
- 'sell_time' => $info['sell_time'],
- 'c_id' => $info['id'],
- ];
- $firstData = getUserBuyCollection($data);
- if(!empty($firstData))
- {
- $info['state'] = $firstData['state'];
- $info['sell_time'] = $firstData['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);
- }
-
- 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('设置失败');
- }
- }
|