123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- namespace app\api\controller;
- use app\admin\model\DayRecord;
- use app\admin\model\Record;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 首页接口
- */
- 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;
- $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);
- }
- }
|