|
@@ -0,0 +1,69 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller;
|
|
|
+
|
|
|
+use app\common\controller\Api;
|
|
|
+use think\Db;
|
|
|
+use Redis;
|
|
|
+/**
|
|
|
+ * 示例接口
|
|
|
+ */
|
|
|
+class Grabgift extends Api
|
|
|
+{
|
|
|
+
|
|
|
+ protected $noNeedLogin = [];
|
|
|
+ // 无需鉴权的接口,*表示全部
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
+
|
|
|
+ protected $redis;
|
|
|
+
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ parent::__construct();
|
|
|
+
|
|
|
+ //redis
|
|
|
+ $redis = new Redis();
|
|
|
+ $redisconfig = config("redis");
|
|
|
+ $redis->connect($redisconfig["host"], $redisconfig["port"]);
|
|
|
+ if ($redisconfig['redis_pwd']) {
|
|
|
+ $redis->auth($redisconfig['redis_pwd']);
|
|
|
+ }
|
|
|
+ if($redisconfig['redis_selectdb'] > 0){
|
|
|
+ $redis->select($redisconfig['redis_selectdb']);
|
|
|
+ }
|
|
|
+ $this->redis = $redis;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //首页
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ $info = Db::name('grabgift')->where('status',0)->order('id desc')->find();
|
|
|
+
|
|
|
+ if(empty($info)){
|
|
|
+ $grabgift_data = [
|
|
|
+ 'price' => config('site.grabgift_price'),
|
|
|
+ 'gift_id' => config('site.grabgift_giftid'),
|
|
|
+ 'status' => 0,
|
|
|
+ 'grabtime' => time(),
|
|
|
+ 'createtime' => time(),
|
|
|
+ ];
|
|
|
+ $grabgift_data['id'] = Db::name('grabgift')->insertGetId($grabgift_data);
|
|
|
+ $info = $grabgift_data;
|
|
|
+ }
|
|
|
+
|
|
|
+ $userlist = Db::name('grabgift_log')->alias('log')
|
|
|
+ ->field('log.user_id,user.nickname,user.avatar')
|
|
|
+ ->join('user','log.user_id = user.id','LEFT')
|
|
|
+ ->where('log.grab_id',$info['id'])->order('log.id asc')->select();
|
|
|
+ $userlist = list_domain_image($userlist,['avatar']);
|
|
|
+
|
|
|
+ $result = [
|
|
|
+ 'info' => $info,
|
|
|
+ 'userlist' => $userlist,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $this->success(1,$result);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|