Index.php 9.2 KB

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