123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- /**
- * 首页接口
- */
- class Index extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- public function _initialize()
- {
- $this->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 runrecord()
- {
- $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);
- }
- $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'];
- $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()
- {
- $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);
- }
- }
|