Index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <?php
  2. namespace app\api\controller;
  3. use think\Db;
  4. /**
  5. * @title 首页、详情
  6. * @controller Index
  7. * @package app\api\controller
  8. */
  9. class Index extends Base
  10. {
  11. public function initialize(){
  12. parent::initialize();
  13. $path = explode('/',$this->request->path());
  14. if(in_array(end($path),['CollectionDetail']) )parent::set_uid();
  15. if(!in_array(end($path),['CollectionDetail']) )parent::check_login();
  16. }
  17. /**
  18. * @title 获取轮播图列表
  19. * @desc 获取轮播图列表
  20. * @author Gavin
  21. * @url /api/Index/getBanner
  22. * @method POST
  23. * @header name:Authorization require:1 desc:Token
  24. * @return name:id type:int require:0 default:0 desc:轮播图id
  25. * @return name:name type:string require:0 default:0 desc:标题
  26. * @return name:cover type:string require:0 default:0 desc:图片
  27. * @return name:content type:string require:0 default:0 desc:内容【富文本】
  28. */
  29. public function getBanner()
  30. {
  31. $list = Db::table('store_banner')
  32. ->field('id,name,cover,content')
  33. ->where(['is_deleted'=>0])
  34. ->order('sort desc ,id desc')
  35. ->cache(300)
  36. ->select();
  37. $this->success('ok',$list);
  38. }
  39. /**
  40. * @title 获取轮播图详情
  41. * @desc 获取轮播图详情
  42. * @author Gavin
  43. * @url /api/Index/getBannerInfo
  44. * @method GET
  45. * @header name:Authorization require:1 desc:Token
  46. * @param name:id type:int require:0 default:0 desc:轮播图id
  47. * @return name:name type:string require:0 default:0 desc:标题
  48. * @return name:cover type:string require:0 default:0 desc:图片
  49. * @return name:content type:string require:0 default:0 desc:内容【富文本】
  50. */
  51. public function getBannerInfo()
  52. {
  53. $detail = Db::table('store_banner')->field('id,name,cover,content')->where(['id'=>input('id')])->find();
  54. $this->success('ok',['detail'=>$detail]);
  55. }
  56. /**
  57. * @title 首页藏品列表
  58. * @desc 首页藏品列表
  59. * @author Gavin
  60. * @url /api/Index/indexCollectionList
  61. * @method POST
  62. * @header name:Authorization require:1 desc:Token
  63. * @param name:page type:int : default:1 desc:页数
  64. * @param name:page_num type:int : default:20 desc:每页数
  65. * @param name:type type:int require:-- default:0 desc:0全部1普通藏品3盲盒
  66. * @param name:issue_mode type:int require:-- default:0 desc:发行方式(0全部1普通发行2抽签发行)
  67. *
  68. * @return name:name type:string default:-- desc:藏品名称
  69. * @return name:cover type:string default:-- desc:藏品图
  70. * @return name:label type:string default:-- desc:标签
  71. * @return name:price type:DECIMAL default:-- desc:价格
  72. * @return name:inventory type:int default:-- desc:库存
  73. * @return name:type type:int default:-- desc:1普通藏品3盲盒
  74. * @return name:now_inventory type:int default:-- desc:剩余库存
  75. * @return name:state type:float default:-- desc:藏品状态(1:进行中2:即将开售3:已售罄)
  76. * @return name:sell_time type:string default:-- desc:发行时间[抽签时间,报名结束时间]
  77. * @return name:issue_mode type:string default:-- desc:发行方式(1普通发行2抽签发行)
  78. * @return name:is_remind type:string default:-- desc:是否设置提醒true:已设置false:未设置
  79. * @return name:auth_name type:string default:-- desc:作者名称
  80. * @return name:auth_img type:string default:-- desc:作者头像
  81. * @return name:issue_mode type:string default:-- desc:发行方式(1普通发行2抽签发行)
  82. * @return name:apply_st type:string default:-- desc:抽签报名开始时间【普通发行忽略】
  83. */
  84. public function indexCollectionList(){
  85. checkCollectionState();
  86. $type = input('type',0);
  87. if(!in_array($type,[0,1,3])) $this->error('参数错误');
  88. $in_type = $type == 0 ? '1,3' : $type;
  89. $issue_mode = input('issue_mode',0);
  90. $list = Db::name('store_collection')
  91. ->where('is_deleted',0)
  92. ->where('status',1)
  93. ->whereIn('type',$in_type)
  94. ->where('sell_time','< time',date("Y-m-d 23:59:59"))
  95. ->when($issue_mode,function ($query)use($issue_mode){ if($issue_mode) $query->where('issue_mode',$issue_mode);})
  96. ->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')
  97. ->order('state asc,sell_time asc')
  98. ->limit($this->off_set,$this->page_num)
  99. ->select();
  100. foreach ($list as &$v){
  101. $advance_minutes = $v['before_time'];
  102. // 验证产品赋能优先购
  103. if($v['issue_mode'] == 1){
  104. $priority = checkMemberPriority($this->uid,$v['id']);
  105. if($priority){
  106. $sell_time = strtotime($v['sell_time'])-($advance_minutes * 60);
  107. if ($sell_time <= time()) $info['state'] = 1;
  108. $info['sell_time'] = date('Y-m-d H:i:s',$sell_time);
  109. }
  110. }
  111. $now_inventory = getCollectionInventory($v['id']);
  112. $v['now_inventory'] = $now_inventory<=0 ? 0 : $now_inventory;
  113. $v['is_remind'] = getRemind($this->uid,$v['id']) ? true : false;
  114. }
  115. $this->success('成功',$list);
  116. }
  117. /**
  118. * @title 发售日历
  119. * @desc 发售日历
  120. * @author Gavin
  121. * @url /api/Index/CollectionCalendar
  122. * @method POST
  123. * @header name:Authorization require:1 desc:Token
  124. * @param name:type type:int require:-- default:0 desc:0普通藏品&&盲盒1普通藏品3盲盒
  125. * @return name:name type:string default:-- desc:藏品名称
  126. * @return name:cover type:string default:-- desc:藏品图
  127. * @return name:label type:string default:-- desc:标签
  128. * @return name:price type:DECIMAL default:-- desc:价格
  129. * @return name:inventory type:int default:-- desc:库存
  130. * @return name:type type:int default:-- desc:1普通藏品3盲盒
  131. * @return name:now_inventory type:int default:-- desc:剩余库存
  132. * @return name:state type:float default:-- desc:藏品状态(1:进行中2:即将开售3:已售罄)
  133. * @return name:sell_time type:string default:-- desc:发行时间[抽签时间,报名结束时间]
  134. * @return name:date type:string default:-- desc:日期
  135. * @return name:time type:string default:-- desc:时间
  136. * @return name:is_remind type:string default:-- desc:是否设置提醒true:已设置false:未设置
  137. */
  138. public function CollectionCalendar(){
  139. checkCollectionState();
  140. $type = input('type',0);
  141. $in_type= $type ? $type :'1,3';
  142. $datelist = Db::name('store_collection')
  143. ->where('is_deleted',0)
  144. ->where('status',1)
  145. ->where('state',2)
  146. ->whereIn('type',$in_type)
  147. ->where('date','>=',date('Y-m-d',time()+86400))
  148. ->group('date')
  149. ->order('date asc')
  150. ->column('date');
  151. if ($datelist){
  152. foreach ($datelist as $k=>&$v){
  153. $array[$k]['date'] = $v;
  154. $list = Db::name('store_collection')
  155. ->where('is_deleted',0)
  156. ->where('status',1)
  157. ->where('state',2)
  158. ->where('date',$v)
  159. ->whereIn('type',$in_type)
  160. ->field('id,cover,name,label,price,inventory,now_inventory,state,sell_time,date,issue_mode,apply_st')
  161. ->order('state asc,sell_time asc')
  162. ->select();
  163. foreach ($list as &$a){
  164. $a['time'] = date('H:i',strtotime($a['sell_time']));
  165. $a['is_remind'] = getRemind($this->uid,$a['id']) ? true : false;
  166. $now_inventory = getCollectionInventory($a['id']);
  167. $a['now_inventory'] = $now_inventory<=0 ? 0 : $now_inventory;
  168. }
  169. $array[$k]['list'] = $list;
  170. }
  171. }else $array=[];
  172. $this->success('成功',$array);
  173. }
  174. /**
  175. * @title 藏品详情
  176. * @desc 藏品详情
  177. * @author Gavin
  178. * @url /api/Index/CollectionDetail
  179. * @method POST
  180. * @header name:Authorization require:1 desc:Token
  181. *
  182. * @param name:id type:string require:1 default:-- desc:藏品ID
  183. *
  184. * @return name:name type:string default:-- desc:藏品名称
  185. * @return name:cover type:string default:-- desc:藏品图
  186. * @return name:label type:string default:-- desc:标签
  187. * @return name:price type:DECIMAL default:-- desc:价格
  188. * @return name:inventory type:int default:-- desc:库存
  189. * @return name:type type:int default:-- desc:1普通藏品3盲盒
  190. * @return name:now_inventory type:int default:-- desc:剩余库存
  191. * @return name:state type:float default:-- desc:藏品状态(1:进行中2:即将开售3:已售罄)
  192. * @return name:sell_time type:string default:-- desc:发行时间[抽签时间,报名结束时间]
  193. * @return name:describe type:string default:-- desc:商品描述
  194. * @return name:buy_count type:int default:1 desc:限购数量
  195. * @return name:before_count type:int default:1 desc:提前购限购数量
  196. * @return name:instructions type:int default:1 desc:权益说明
  197. * @return name:buy_notice type:int default:1 desc:购买须知
  198. * @return name:warm_prompt type:int default:1 desc:温馨提示
  199. * @return name:auth_img type:int default:1 desc:作者头像
  200. * @return name:auth_name type:int default:1 desc:作者姓名
  201. * @return name:is_remind type:string default:-- desc:是否设置提醒true:已设置false:未设置
  202. * @return name:share_img type:string default:-- desc:分享二维码
  203. * @return name:issue_mode type:string default:-- desc:发行方式(1普通发行2抽签发行)
  204. * @return name:circulate_num type:int default:-- desc:流通量
  205. * @return name:is_task type:int default:-- desc:是否有抽签结果(0未出结果,1已出结果)【普通发行忽略】
  206. * @return name:all_apply type:int default:-- desc:参与抽签人数【普通发行忽略】
  207. * @return name:apply_st type:string default:-- desc:抽签报名开始时间【普通发行忽略】
  208. * @return name:apply_end type:string default:-- desc:抽签报名结束时间||抽奖发布时间【普通发行忽略】
  209. * @return name:has_apply type:int default:-- desc:是否报名(0否,1是)【普通发行忽略】
  210. * @return name:apply_code type:int default:-- desc:抽签码【普通发行忽略】
  211. * @return name:ballot_status type:int default:-- desc:是否中签(0待抽签1抽中2未中)【普通发行忽略】
  212. */
  213. public function CollectionDetail(){
  214. $collect_id = input('id');
  215. if (!$collect_id) $this->error('参数错误');
  216. checkCollectionState($collect_id);
  217. (new Timedtask())->collectionDraw($collect_id);
  218. $info = Db::name('store_collection')
  219. ->where('is_deleted',0)
  220. ->where('status',1)
  221. ->whereIn('type','1,3')
  222. ->where('id',$collect_id)
  223. ->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')
  224. ->find();
  225. if(!$info) $this->error('商品已下架');
  226. // 抽签发行
  227. $draw = Db::name('store_collection_draw')->where(['coll_id'=>$info['id'],'sell_time'=>$info['sell_time'],'user_id'=>$this->uid])->find();
  228. $info['has_apply'] = empty($draw) ? 0 : 1;
  229. $info['apply_code'] = empty($draw) ? '' : $draw['code'];
  230. $info['ballot_status'] = empty($draw) ? 0 : $draw['is_ballot'];
  231. $info['all_apply'] = Db::name('store_collection_draw')->where(['coll_id'=>$info['id'],'sell_time'=>$info['sell_time']])->count();
  232. if (!$info) $this->error('藏品不存在');
  233. $info['describe'] = explode('|',$info['describe']);
  234. $info['before_count'] = 0;
  235. // 验证产品赋能优先购
  236. $set_time = $info['sell_time'];
  237. if( $info['issue_mode'] == 1){
  238. $priority = checkMemberPriority($this->uid,$info['id']);
  239. if($priority){
  240. $sell_time = strtotime($info['sell_time'])-($info['before_time'] * 60);
  241. if ($sell_time <= time()) $info['state'] = 1;
  242. $info['sell_time'] = date('Y-m-d H:i:s',$sell_time);
  243. }
  244. }
  245. $info['is_remind'] = getRemind($this->uid,$info['id']) ? true : false;
  246. $now_inventory = getCollectionInventory($info['id']);
  247. $info['now_inventory'] = $now_inventory<=0 ? 0 : $now_inventory;
  248. // 用户持有量
  249. $info['circulate_num']= Db::name('store_order_info')
  250. ->where('c_id',$info['id'])
  251. ->where('is_destruction',1)
  252. ->whereIn('resale_status','1,2')
  253. ->count();
  254. $this->success('成功',$info);
  255. }
  256. /**
  257. * @title 设置提醒
  258. * @desc 设置提醒
  259. * @author Gavin
  260. * @url /api/Index/setRemind
  261. * @method POST
  262. * @header name:Authorization require:1 desc:Token
  263. *
  264. * @param name:id type:string require:1 default:-- desc:藏品ID
  265. */
  266. public function setRemind(){
  267. $id = input('id');
  268. if (!$id) $this->error('参数错误');
  269. $remind = Db::name('store_collection_remind')
  270. ->where('mid',$this->uid)
  271. ->where('c_id',$id)
  272. ->count();
  273. if ($remind) $this->error('已设置过');
  274. $data = [
  275. 'c_id'=>$id,
  276. 'mid'=>$this->uid
  277. ];
  278. if (Db::name('store_collection_remind')->insert($data)) $this->success('设置成功');
  279. $this->error('设置失败');
  280. }
  281. /**
  282. * @title 认证信息
  283. * @desc 认证信息
  284. * @author QC
  285. * @url /api/Index/certificate
  286. * @method POST
  287. * @header name:Authorization require:1 desc:Token
  288. * @param name:name type:string default:-- desc:名称
  289. * @param name:link type:string default:-- desc:合约地址
  290. */
  291. public function certificate()
  292. {
  293. $this->success('ok',['name' => '蚂蚁链HASH', 'link' => '0c214bcd4f1766fdd6d36f127234fc7e7ba883711e19938777f01523c28e74dc',]);
  294. }
  295. }