|
@@ -73,9 +73,81 @@ class Active extends Api
|
|
$this->success('已收集',$this->get_my_number());
|
|
$this->success('已收集',$this->get_my_number());
|
|
}
|
|
}
|
|
|
|
|
|
- //今日开奖结果
|
|
|
|
|
|
+ //开奖
|
|
|
|
+ public function active_finish(){
|
|
|
|
+ $check = Db::name('active_log')->where('opendate',date('Ymd'))->find();
|
|
|
|
+ if(!empty($check)){
|
|
|
|
+ $this->error('今天已开奖');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //中奖号码。所有号码中随机拿个一,就一定会中奖
|
|
|
|
+ $box = Db::name('active_user_number')->whereTime('createtime','today')->column('number');
|
|
|
|
+ $gift_number = $box[rand(0,count($box)-1)];
|
|
|
|
+
|
|
|
|
+ //中奖列表
|
|
|
|
+ $list = Db::name('active_user_number')->whereTime('createtime','today')->where('number',$gift_number)->select();
|
|
|
|
+ $log_ids = array_column($list,'id');//id更新快一点
|
|
|
|
+
|
|
|
|
+ //每股中奖额度
|
|
|
|
+ $jiangchi = $this->jiangchi();
|
|
|
|
+ $price = bcdiv($jiangchi,count($list),0);
|
|
|
|
+
|
|
|
|
+ //发奖结果集
|
|
|
|
+ $fajiang = [];
|
|
|
|
+ foreach($list as $key => $val){
|
|
|
|
+ if(isset($fajiang[$val['user_id']])){
|
|
|
|
+ $fajiang[$val['user_id']] += 1;
|
|
|
|
+ }else{
|
|
|
|
+ $fajiang[$val['user_id']] = 1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Db::startTrans();
|
|
|
|
+ //发奖
|
|
|
|
+ foreach($fajiang as $key => $val){
|
|
|
|
+ $gold = bcmul($val,$price,0);
|
|
|
|
+
|
|
|
|
+ $rs = model('wallet')->lockChangeAccountRemain($key,0,'gold',$gold,91,'第'.date('Ymd').'期');
|
|
|
|
+ if($rs['status'] === false){
|
|
|
|
+ Db::rollback();
|
|
|
|
+ $this->error('开奖失败');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //修改状态
|
|
|
|
+ $rs = Db::name('active_user_number')->where('id','IN',$log_ids)->update(['gold'=>$price,'status'=>1,'updatetime'=>time()]);
|
|
|
|
+ if($rs === false){
|
|
|
|
+ Db::rollback();
|
|
|
|
+ $this->error('开奖失败');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //开奖记录
|
|
|
|
+ $log = [
|
|
|
|
+ 'gift_number' => $gift_number,
|
|
|
|
+ 'jiangchi' => $jiangchi,
|
|
|
|
+ 'giftcount' => count($list),
|
|
|
|
+ 'price' => $price,
|
|
|
|
+ 'usercount' => count($fajiang),
|
|
|
|
+ 'opendate' => date('Ymd'),
|
|
|
|
+ 'createtime' => time(),
|
|
|
|
+ ];
|
|
|
|
+ $log_id = Db::name('active_log')->insertGetId($log);
|
|
|
|
+ if(!$log_id){
|
|
|
|
+ Db::rollback();
|
|
|
|
+ $this->error('开奖失败');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Db::commit();
|
|
|
|
+ $this->success('开奖完成');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //开奖结果
|
|
public function active_result(){}
|
|
public function active_result(){}
|
|
|
|
|
|
|
|
+ //参与统计
|
|
|
|
+ //参与日志
|
|
|
|
+ //历史中奖
|
|
|
|
+
|
|
//我今天已经领取的气泡,数字
|
|
//我今天已经领取的气泡,数字
|
|
private function get_my_number(){
|
|
private function get_my_number(){
|
|
$list = Db::name('active_user_number')->whereTime('createtime','today')->where('user_id',$this->auth->id)->order('id asc')->select();
|
|
$list = Db::name('active_user_number')->whereTime('createtime','today')->where('user_id',$this->auth->id)->order('id asc')->select();
|