Bladeren bron

修改文件

柳建 9 maanden geleden
bovenliggende
commit
ba550f8b1f
3 gewijzigde bestanden met toevoegingen van 113 en 151 verwijderingen
  1. 52 0
      application/admin/command/Runrecord.php
  2. 0 99
      application/admin/command/runrecord.php
  3. 61 52
      application/api/controller/Index.php

+ 52 - 0
application/admin/command/Runrecord.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace app\admin\command;
+
+
+
+use think\console\Command;
+use think\console\Input;
+
+use think\console\Output;
+use think\Exception;
+use think\Loader;
+
+class Runrecord extends Command
+{
+    protected $model = null;
+
+    protected function configure()
+    {
+        $this
+            ->setName('Runrecord')
+            ->addArgument('action')
+            ->setDescription('命令行执行定时任务')//运行 "php think list" 时的简短描述
+            ->setHelp("执行接口 参数为api (api/index/index)");
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        $action= $input->getArgument('action');
+        switch ($action){
+            case "upincome"://更新用户收益
+
+                while (true) {
+                    $result= action("api/index/upincome");
+                    $output->writeln('131');
+                    sleep(600);
+                }
+                break;
+            case "runrecord"://记录广告收益
+                while (true) {
+                    $result= action("api/index/runrecord");
+                    $output->writeln($result);
+                    sleep(60);
+                }
+
+                break;
+        }
+
+    }
+
+
+}

+ 0 - 99
application/admin/command/runrecord.php

@@ -1,99 +0,0 @@
-<?php
-
-namespace app\admin\command;
-use think\console\Command;
-use think\console\Input;
-use think\console\Output;
-
-class runrecord extends Command
-{
-    protected $model = null;
-
-    protected function configure()
-    {
-        $this
-            ->setName('runrecord')
-            ->addArgument('action',Argument::OPTIONAL,'run action')
-            ->setDescription('命令行执行定时任务'); //运行 "php think list" 时的简短描述
-    }
-
-    protected function execute(Input $input, Output $output)
-    {
-        $this->recordModel= new \app\admin\model\greenroom\Record;
-        $nowtime = time();
-        $spacetime = 10 * 60;
-        $action= $input->getArgument('action');
-        switch ($action){
-            case "upincome"://更新用户收益
-                while (true) {
-                    $recorddata=  $this->recordModel->field('sum(income) as income ,uid as id')->where(['status'=>0])->group('uid')->select();
-                    $temp=$userids=[];
-                    $returndata='1';
-                    if($recorddata){
-                        $returndata='12';
-                        foreach ($recorddata as $key=>$val){
-                            $temp[$val['id']]=$val['income'];
-                            $userids[]=$val['id'];
-                        }
-                        $admindata=db('fa_admin')->where(['id'=>['in',$userids]])->select();
-                        $upincome=[];
-                        foreach ($admindata as $k=>$vl){
-                            if(isset($temp[$vl['id']])){
-                                $upincome[]=['id'=>$vl['id'],'money'=>$vl['money']+$temp[$vl['id']]];
-                            }
-                        }
-                        if($upincome){
-                            $returndata='123';
-                            $this->adminModel->saveAll($upincome);
-                        }
-                    }
-                    $output->writeln($returndata);
-                    sleep(600);
-                }
-                break;
-            case "runrecord"://记录广告收益
-                while (true) {
-                    $returndata='';
-                    $userdata = db('fa_admin')->field("id")
-                        ->where(['livetime', 'gt', $nowtime - $spacetime])
-                        ->where(['incomeendtime', 'gt', $nowtime])
-                        ->select();
-                    if (!$userdata) {
-                        $returndata= 'no data';
-                    } else {
-                        $userids = array_column($userdata, 'id');
-                        $userlink = db('userlink')
-                            ->join(['fa_link'], 'fa_userlink.link_id = fa_link.id')
-                            ->field("fa_link.link as link,
-                    fa_link.id as link_id,
-                    fa_link.minincome as minincome,
-                    fa_link.maxincome as maxincome
-            ")->where(['uid'=>['in', $userids]])->select();
-                        if (!$userlink) {
-                            $returndata='no data1';
-
-                        } else {
-                            $savedata = [];
-                            foreach ($userlink as $key => $val) {
-                                $savedata[] = ['income' => mt_rand($val['minincome'] * 10000, $val['maxincome'] * 10000) / 10000,
-                                    'time' => $nowtime,
-                                    'link' => $val['link'],
-                                    'uid' => $val['uid'],
-                                    'status' => 0
-                                ];
-                            }
-                            $this->recordModel->saveAll($savedata);
-                            $returndata= 'insert ' . count($savedata) . ' record';
-                        }
-                    }
-                    $output->writeln($returndata);
-                    sleep(60);
-                }
-
-                break;
-        }
-
-    }
-
-
-}

+ 61 - 52
application/api/controller/Index.php

@@ -25,71 +25,80 @@ class Index extends Api
     {
         $this->success('请求成功');
     }
+    //跟新收益
+    public function upincome(){
 
+        $recorddata=  $this->recordModel->field('sum(income) as income ,uid as id')->where(['status'=>0])->group('uid')->select();
+        $temp=$userids=[];
+        $returndata='1';
+        if($recorddata){
+            $returndata='12';
+            foreach ($recorddata as $key=>$val){
+            $temp[$val['id']]=$val['income'];
+            $userids[]=$val['id'];
+            }
+            $admindata=db('fa_admin')->where(['id'=>['in',$userids]])->select();
+            $upincome=[];
+            foreach ($admindata as $k=>$vl){
+                if(isset($temp[$vl['id']])){
+                    $upincome[]=['id'=>$vl['id'],'money'=>$vl['money']+$temp[$vl['id']]];
+                }
+            }
+            if($upincome){
+                $returndata='123';
+                $this->adminModel->saveAll($upincome);
+            }
+        }
+        return $returndata;
+    }
     /**
      * 跑链接收益
      *
      */
     public function runrecord()
     {
+        $nowtime = time();
+        $spacetime = 10 * 60;
+        $returndata='';
+        $userdata = db('fa_admin')->field("id")
+        ->where(['livetime', 'gt', $nowtime - $spacetime])
+        ->where(['incomeendtime', 'gt', $nowtime])
+        ->select();
+        if (!$userdata) {
+        $returndata= 'no data';
+        } else {
+            $userids = array_column($userdata, 'id');
+            $userlink = db('userlink')
+                ->join(['fa_link'], 'fa_userlink.link_id = fa_link.id')
+                ->field("fa_link.link as link,
+                            fa_link.id as link_id,
+                            fa_link.minincome as minincome,
+                            fa_link.maxincome as maxincome
+                    ")->where(['uid'=>['in', $userids]])->select();
+            if (!$userlink) {
+                $returndata='no data1';
 
-        $userlink = db('userlink')
-            ->join(['fa_link'], 'fa_userlink.link_id = fa_link.id')
-            ->field(
-                "fa_link.link as link,
-                    fa_link.id as link_id,
-                    fa_link.minincome as minincome,
-                    fa_link.maxincome as maxincome
-            ")->group("link_id")->select();
-
-        $record=[];
-        $nowtime =date("Y-m-d h:i:s");
-        $unixtime=time();
-        foreach ($userlink as $key=>$val){
-            $income = mt_rand ($val['minincome']*10000,$val['maxincome']*10000)/10000;
-            $record[$val['link_id']]=[
-                'link'=>$val['link'],
-                'time'=>$nowtime,
-                'income'=>$income
-            ];
-        }
-        if($record){
-            $this->recordModel->saveAll($record,true);
+            } else {
+                $savedata = [];
+                foreach ($userlink as $key => $val) {
+                    $savedata[] = ['income' => mt_rand($val['minincome'] * 10000, $val['maxincome'] * 10000) / 10000,
+                        'time' => $nowtime,
+                        'link' => $val['link'],
+                        'uid' => $val['uid'],
+                        'status' => 0
+                    ];
+                }
+                $this->recordModel->saveAll($savedata);
+                $returndata= 'insert ' . count($savedata) . ' record';
+            }
         }
-        $where=['incomeendtime'=>['gt',$unixtime]];
-        $usedata = db('admin')->field("money,id")->where($where)->select();
-        $buylink = db('userlink')->field("id,uid,link_id,income,dayincome,oldincome")->select();
-        $addincome=$linkincome=[];
-        foreach ($buylink as $key=>$val){
-            $addincome[$val['uid']]=isset($addincome[$val['uid']])?$addincome[$val['uid']]+$record[$val['link_id']]['income']:$record[$val['link_id']]['income'];
+        return $returndata;
+    }
+
 
-            $linkincome[$val['uid']][$val['id']]['income']=$val['income']+$record[$val['link_id']]['income'];
-            $linkincome[$val['uid']][$val['id']]['dayincome']=$val['dayincome']+$record[$val['link_id']]['income'];
 
-        }
-        $upincome=[];
-        $upuserlink=[];
-        foreach ($usedata as $k=>$vl){
-            if(isset($addincome[$vl['id']])){
-                $upincome[]=['id'=>$vl['id'],
-                    'money'=>$vl['money']+$addincome[$val['uid']]
-                ];
-            }
-            if(isset($linkincome[$vl['id']])){
-                foreach ($linkincome[$vl['id']] as $key=>$val){
-                    $upuserlink[$key]=$val;
-                    $upuserlink[$key]['id']=$key;
-                    $upuserlink[$key]['endtime']=$unixtime;
 
-                }
-            }
-            if($upincome){
-                $this->adminModel->saveAll($upincome);
-                $this->userlinkModel->saveAll($upuserlink);
-            }
 
-        }
-    }
 
 
     public function oldrecord()