Index.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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::check_login();
  13. }
  14. /**
  15. * @title 获取轮播图
  16. * @desc 获取轮播图
  17. * @author Gavin
  18. * @url /api/Index/getBanner
  19. * @method POST
  20. * @header name:Authorization require:1 desc:Token
  21. *
  22. */
  23. public function getBanner()
  24. {
  25. $list = Db::table('store_banner')
  26. ->field('id,name,cover')
  27. ->where(['is_deleted'=>0])
  28. ->order('sort desc ,id desc')
  29. ->select();
  30. $this->success('ok',$list);
  31. }
  32. /**
  33. * @title 首页藏品列表
  34. * @desc 首页藏品列表
  35. * @author Gavin
  36. * @url /api/Index/indexCollectionList
  37. * @method POST
  38. * @header name:Authorization require:1 desc:Token
  39. *
  40. * @return name:name type:string default:-- desc:藏品名称
  41. * @return name:cover type:string default:-- desc:藏品图
  42. * @return name:label type:string default:-- desc:标签
  43. * @return name:price type:DECIMAL default:-- desc:价格
  44. * @return name:inventory type:int default:-- desc:库存
  45. * @return name:now_inventory type:int default:-- desc:剩余库存
  46. * @return name:state type:float default:-- desc:藏品状态(1:进行中2:即将开售3:已售罄)
  47. * @return name:sell_time type:string default:-- desc:发行时间
  48. * @return name:is_remind type:string default:-- desc:是否设置提醒true:已设置false:未设置
  49. */
  50. public function indexCollectionList(){
  51. checkCollectionState();
  52. $type = input('type',1);
  53. if ($this->uid=='1' || $this->uid=='3'){
  54. $list = Db::name('store_collection')
  55. ->where('is_deleted',0)
  56. ->whereIn('type',$type)
  57. ->field('id,cover,name,label,price,inventory,now_inventory,state,sell_time')
  58. ->order('state asc,sell_time asc')
  59. ->select();
  60. }else{
  61. $list = Db::name('store_collection')
  62. ->where('is_deleted',0)
  63. ->where('status',1)
  64. ->whereIn('type',$type)
  65. ->field('id,cover,name,label,price,inventory,now_inventory,state,sell_time')
  66. ->order('state asc,sell_time asc')
  67. ->select();
  68. }
  69. $memberVip = Db::name('store_member')->where('id',$this->uid)->value('vip');
  70. $advance_minutes = getAdvanceMinutes();
  71. foreach ($list as &$v){
  72. if ($memberVip==2 && $advance_minutes>0){
  73. if ($v['state']==2){
  74. $sell_time = strtotime($v['sell_time'])-($advance_minutes*60);
  75. if ($sell_time<=time()){
  76. $v['state'] = 1;
  77. }
  78. $v['sell_time'] = date('Y-m-d H:i:s',$sell_time);
  79. }
  80. }
  81. $now_inventory = getCollectionInventory($v['id']);
  82. $v['now_inventory'] = $now_inventory<=0 ? 0 : $now_inventory;
  83. }
  84. foreach ($list as &$v){
  85. $v['is_remind'] = getRemind($this->uid,$v['id']) ? true : false;
  86. }
  87. $this->success('成功',$list);
  88. }
  89. /**
  90. * @title 发售日历
  91. * @desc 发售日历
  92. * @author Gavin
  93. * @url /api/Index/CollectionCalendar
  94. * @method POST
  95. * @header name:Authorization require:1 desc:Token
  96. *
  97. * @return name:name type:string default:-- desc:藏品名称
  98. * @return name:cover type:string default:-- desc:藏品图
  99. * @return name:label type:string default:-- desc:标签
  100. * @return name:price type:DECIMAL default:-- desc:价格
  101. * @return name:inventory type:int default:-- desc:库存
  102. * @return name:now_inventory type:int default:-- desc:剩余库存
  103. * @return name:state type:float default:-- desc:藏品状态(1:进行中2:即将开售3:已售罄)
  104. * @return name:sell_time type:string default:-- desc:发行时间
  105. * @return name:date type:string default:-- desc:日期
  106. * @return name:time type:string default:-- desc:时间
  107. * @return name:is_remind type:string default:-- desc:是否设置提醒true:已设置false:未设置
  108. */
  109. public function CollectionCalendar(){
  110. checkCollectionState();
  111. $datelist = Db::name('store_collection')
  112. ->where('is_deleted',0)
  113. ->where('status',1)
  114. ->where('state',2)
  115. ->whereIn('type','1,3')
  116. ->where('date','>=',date('Y-m-d',time()))
  117. ->group('date')
  118. ->order('date asc')
  119. ->column('date');
  120. if ($datelist){
  121. foreach ($datelist as $k=>&$v){
  122. $array[$k]['date'] = $v;
  123. $list = Db::name('store_collection')
  124. ->where('is_deleted',0)
  125. ->where('status',1)
  126. ->where('state',2)
  127. ->where('date',$v)
  128. ->field('id,cover,name,label,price,inventory,now_inventory,state,sell_time,date')
  129. ->order('state asc,sell_time asc')
  130. ->select();
  131. foreach ($list as &$a){
  132. $a['time'] = date('H:i',strtotime($a['sell_time']));
  133. $a['is_remind'] = getRemind($this->uid,$a['id']) ? true : false;
  134. $now_inventory = getCollectionInventory($a['id']);
  135. $a['now_inventory'] = $now_inventory<=0 ? 0 : $now_inventory;
  136. }
  137. $array[$k]['list'] = $list;
  138. }
  139. }else $array=[];
  140. $this->success('成功',$array);
  141. }
  142. /**
  143. * @title 藏品详情
  144. * @desc 藏品详情
  145. * @author Gavin
  146. * @url /api/Index/CollectionDetail
  147. * @method POST
  148. * @header name:Authorization require:1 desc:Token
  149. *
  150. * @param name:id type:string require:1 default:-- desc:藏品ID
  151. *
  152. * @return name:name type:string default:-- desc:藏品名称
  153. * @return name:cover type:string default:-- desc:藏品图
  154. * @return name:label type:string default:-- desc:标签
  155. * @return name:price type:DECIMAL default:-- desc:价格
  156. * @return name:inventory type:int default:-- desc:库存
  157. * @return name:now_inventory type:int default:-- desc:剩余库存
  158. * @return name:state type:float default:-- desc:藏品状态(1:进行中2:即将开售3:已售罄)
  159. * @return name:sell_time type:string default:-- desc:发行时间
  160. * @return name:describe type:string default:-- desc:商品描述
  161. * @return name:buy_count type:int default:1 desc:限购数量
  162. * @return name:instructions type:int default:1 desc:权益说明
  163. * @return name:buy_notice type:int default:1 desc:购买须知
  164. * @return name:warm_prompt type:int default:1 desc:温馨提示
  165. * @return name:auth_img type:int default:1 desc:作者头像
  166. * @return name:auth_name type:int default:1 desc:作者姓名
  167. * @return name:is_remind type:string default:-- desc:是否设置提醒true:已设置false:未设置
  168. * @return name:share_img type:string default:-- desc:分享二维码
  169. */
  170. public function CollectionDetail(){
  171. $collect_id = input('id');
  172. if (!$collect_id) $this->error('参数错误');
  173. checkCollectionState($collect_id);
  174. if ($this->uid=='1' || $this->uid=='3'){
  175. $info = Db::name('store_collection')
  176. ->where('is_deleted',0)
  177. ->whereIn('type','1,3')
  178. ->where('id',$collect_id)
  179. ->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')
  180. ->find();
  181. }else{
  182. $info = Db::name('store_collection')
  183. ->where('is_deleted',0)
  184. ->where('status',1)
  185. ->whereIn('type','1,3')
  186. ->where('id',$collect_id)
  187. ->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')
  188. ->find();
  189. }
  190. if (!$info) $this->error('藏品不存在');
  191. $info['describe'] = explode('|',$info['describe']);
  192. $memberVip = Db::name('store_member')->where('id',$this->uid)->value('vip');
  193. $advance_minutes = getAdvanceMinutes();
  194. if ($memberVip==2 && $advance_minutes>0){
  195. if ($info['state']==2){
  196. $sell_time = strtotime($info['sell_time'])-($advance_minutes*60);
  197. if ($sell_time<=time()){
  198. $info['state'] = 1;
  199. }
  200. $info['sell_time'] = date('Y-m-d H:i:s',$sell_time);
  201. }
  202. }
  203. $info['is_remind'] = getRemind($this->uid,$info['id']) ? true : false;
  204. $now_inventory = getCollectionInventory($info['id']);
  205. $info['now_inventory'] = $now_inventory<=0 ? 0 : $now_inventory;
  206. $this->success('成功',$info);
  207. }
  208. /**
  209. * @title 设置提醒
  210. * @desc 设置提醒
  211. * @author Gavin
  212. * @url /api/Index/setRemind
  213. * @method POST
  214. * @header name:Authorization require:1 desc:Token
  215. *
  216. * @param name:id type:string require:1 default:-- desc:藏品ID
  217. */
  218. public function setRemind(){
  219. $id = input('id');
  220. if (!$id) $this->error('参数错误');
  221. $remind = Db::name('store_collection_remind')
  222. ->where('mid',$this->uid)
  223. ->where('c_id',$id)
  224. ->count();
  225. if ($remind) $this->error('已设置过');
  226. $data = [
  227. 'c_id'=>$id,
  228. 'mid'=>$this->uid
  229. ];
  230. if (Db::name('store_collection_remind')->insert($data)) $this->success('设置成功');
  231. $this->error('设置失败');
  232. }
  233. }