recordModel= new \app\admin\model\greenroom\Record; $this->adminModel= new \app\admin\model\Admin; $this->userlinkModel= new \app\admin\model\greenroom\Userlink; } /** * 首页 * */ public function index() { $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('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('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_userlink.uid as uid, 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'; } } return $returndata; } public function oldrecord() { $beginYesterday=mktime(0,0,0,date('m'),date('d') - 1,date('Y')); $endYesterday = mktime(0,0,0,date('m'),date('d'),date('Y')); // 统计前面的收益 $total = Record::where('time', ">=", $beginYesterday) ->where("time", '<', $endYesterday) ->field('sum(income) as income, count(id) as num,uid as id') ->group("uid") ->select(); $date = date("Y-m-d", $beginYesterday); Db::startTrans(); foreach ($total as $item) { DayRecord::create([ "uid" => $item->id, "addtime" => $date, "link_num" => $item->num, "income" => bcmul('1', $item->income, 4) ]); } Record::where('time', ">=", $beginYesterday) ->where("time", '<', $endYesterday)->delete(); Db::commit(); // $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y')); // $userlink = db('userlink')->select(); // $uplink=[]; // foreach ($userlink as $key=>$val){ // if($val['dayincome']>0){ // $uplinktemp=[ // 'id'=>$val['id'], // 'dayincome'=>0, // 'oldincome'=>$val['dayincome'], // ]; // if($val['endtime']<$beginYesterday){ // $uplinktemp['oldincome']=0; // } // $uplink[]= $uplinktemp; // } // } // $this->userlinkModel->saveAll($uplink); } }