|
@@ -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()
|