Browse Source

活动抽奖

lizhen_gitee 2 months ago
parent
commit
2dd3124e2a
2 changed files with 130 additions and 0 deletions
  1. 126 0
      application/api/controller/Active.php
  2. 4 0
      application/extra/site.php

+ 126 - 0
application/api/controller/Active.php

@@ -0,0 +1,126 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use app\common\library\Tenim;
+use think\Db;
+/**
+ * 活动
+ */
+class Active extends Api
+{
+
+    // 无需登录的接口,*表示全部
+    protected $noNeedLogin = [''];
+    // 无需鉴权的接口,*表示全部
+    protected $noNeedRight = ['*'];
+
+    //首页
+    public function index(){
+        $result = [];
+        //开奖时间
+        $result['kaijiang_time'] = date('H:i',strtotime(config('site.active_kaijiang_time')));
+
+        //奖池金额
+        $result['jiangchi'] = $this->jiangchi();
+
+        //我今天已经领取的气泡,数字
+        $result['my_number'] = $this->get_my_number();
+
+        //我今天的应得气泡数量,扣除已经领掉的,最大4个
+        $qipao_count = $this->get_qipao_count() - count($result['my_number']);
+        $qipao_count = $qipao_count > 4 ? 4 : $qipao_count ;
+        $result['qipao_count'] = $qipao_count;
+
+        $this->success('success',$result);
+    }
+
+    //收集一个气泡
+    public function open_qipao(){
+        //我今天的应得气泡数量
+        $qipao_count = $this->get_qipao_count();
+
+        //我今天打开的气泡数量
+        $my_count = Db::name('active_user_number')->whereTime('createtime','today')->where('user_id',$this->auth->id)->count();
+
+        if($my_count + 1 > $qipao_count){
+            $this->error('可收集气泡不足');
+        }
+
+        $week = [
+            1 => 4,
+            2 => 4,
+            3 => 4,
+            4 => 4,
+            5 => 4,
+            6 => 4,
+            7 => 10,
+        ];
+
+        $today_max = $week[date('N')];
+        if($my_count + 1 > $today_max){
+            $this->error('今天最多能收集'.$today_max.'个气泡,已到上限');
+        }
+
+        $data = [
+            'user_id' => $this->auth->id,
+            'number'  => $this->get_rand_number(),
+            'createtime' => time(),
+        ];
+        Db::name('active_user_number')->insertGetId($data);
+
+        $this->success('已收集',$this->get_my_number());
+    }
+
+    //今日开奖结果
+    public function active_result(){}
+
+    //我今天已经领取的气泡,数字
+    private function get_my_number(){
+        $list = Db::name('active_user_number')->whereTime('createtime','today')->where('user_id',$this->auth->id)->order('id asc')->select();
+        return $list;
+    }
+
+    //我今天的应得气泡数量
+    private function get_qipao_count(){
+        $xiaofei_log_type = '11,12,13,53,59,71,81';//消费金币的log
+
+        $xiaofei_total = Db::name('user_gold_log')->whereTime('createtime','today')->where('user_id',$this->auth->id)->where('log_type','IN',$xiaofei_log_type)
+            ->sum('change_value');
+        $xiaofei_total = abs($xiaofei_total);
+
+        $qipao_value = config('site.active_qipao_value');   //气泡价格
+        if($qipao_value <= 0){
+            return 0; //0不能做除数
+        }
+        $qipao       = bcdiv($xiaofei_total,$qipao_value);  //金币没有小数点
+
+        return intval($qipao);  //退一法
+    }
+
+    //随机一个中奖号码
+    private function get_rand_number(){
+        $min = config('site.active_number_min');
+        $max = config('site.active_number_max');
+
+        return rand($min,$max);
+    }
+
+    //奖池金额
+    private function jiangchi(){
+        $xiaofei_log_type = '11,12,13,53,59,71,81';//消费金币的log
+
+        //奖池为昨日平台消费总金额百分比
+        $starttime = strtotime(date('Y-m-d')) - 86400;
+        $endtime   = $starttime + 86399;
+        $xiaofei_total = Db::name('user_gold_log')->where('createtime','BETWEEN',[$starttime,$endtime])->where('log_type','IN',$xiaofei_log_type)->sum('change_value');
+        $xiaofei_total = abs($xiaofei_total);
+        $jiangchi_bili = config('site.active_jiangchi_bili');
+        $jiangchi = bcdiv(bcmul($xiaofei_total,$jiangchi_bili,0),100,0);  //金币没有小数点
+
+        return $jiangchi;
+    }
+
+
+}

+ 4 - 0
application/extra/site.php

@@ -29,6 +29,7 @@ return array (
     'version' => '版本配置',
     'withdraw' => '提现配置',
     'showrules' => '显示规则配置',
+    'active' => '活动设置',
   ),
   'mail_type' => '1',
   'mail_smtp_host' => 'smtp.163.com',
@@ -105,4 +106,7 @@ return array (
 8、15天后自动注销,15天内再次登录账号即视为放弃注销;请谨慎使用账号注销功能,账号一旦注销将无法找回,因该账号注销带来的问题,平台不承担任何责任。',
   'exchange_rule' => '1、每个档位不限制兑换次数
 2、兑换金币即可到账,若出现兑换失败或延迟的情况,请联系在线客服处理',
+  'active_kaijiang_time' => '21:00:00',
+  'active_jiangchi_bili' => '50',
+  'active_qipao_value' => '100',
 );