recordModel = new \app\admin\model\greenroom\Record; $this->adminModel = new \app\admin\model\Admin; $this->userlinkModel = new \app\admin\model\greenroom\Userlink; $this->moneyLogModel = new \app\common\model\MoneyLog; } /** * 首页 * */ public function index() { $this->success('请求成功'); } //跟新收益 public function upincome() { $maxId = $this->recordModel->max('id'); $recorddata = $this->recordModel ->field('sum(income) as income ,uid as id') ->where("id", "<=", $maxId) ->where(['status' => 0]) ->group('uid') ->select(); $temp = $userids = []; $returndata = '1'; Db::startTrans(); 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 =$moenylog= []; foreach ($admindata as $k => $vl) { if (isset($temp[$vl['id']])) { db("admin")->where('id', $vl['id'])->setInc("money",$temp[$vl['id']]); $moenylog[]=['user_id'=>$vl['id'],'money' =>$temp[$vl['id']],'before' => $vl['money'], 'after' => $vl['money'] + $temp[$vl['id']], 'memo' => 'upincome']; } } if ($upincome) { $returndata = '123'; // $this->adminModel->saveAll($upincome); $this->moneyLogModel->saveAll($moenylog); $this->recordModel->where("id", "<=", $maxId)->where(['status' => 0])->update(['status' => 1]); } } Db::commit(); 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(); Db::startTrans(); 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_userlink.id as userlinkid, fa_userlink.income as income, fa_link.minincome as minincome, fa_link.maxincome as maxincome ")->where(['uid' => ['in', $userids]])->select(); if (!$userlink) { $returndata = 'no data1'; } else { $savedata = $userlinkdata = []; foreach ($userlink as $key => $val) { $unit = bcpow(10, 10); // $income = mt_rand( * $unit, $val['maxincome'] * $unit) / $unit; $income = bcdiv(mt_rand(bcmul($val['minincome'], $unit, 10), bcmul($val['maxincome'], $unit, 10)), $unit, 10); $savedata[] = ['income' => $income, 'time' => $nowtime, 'link' => $val['link'], 'uid' => $val['uid'], 'status' => 0 ]; $userlinkdata[] = ['id' => $val['userlinkid'], 'income' => $val['income'] + $income]; } $this->userlinkModel->saveAll($userlinkdata); $this->recordModel->saveAll($savedata); $returndata = 'insert ' . count($savedata) . ' record'; } Db::commit(); } 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) ->where('status', 1) ->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); } }