Index.php 14 KB

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