|
@@ -0,0 +1,99 @@
|
|
|
|
+<?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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|