فهرست منبع

修改默认模块

程旭源 1 سال پیش
والد
کامیت
427ad2c350
2فایلهای تغییر یافته به همراه45 افزوده شده و 42 حذف شده
  1. 44 41
      application/api/controller/Index.php
  2. 1 1
      application/config.php

+ 44 - 41
application/api/controller/Index.php

@@ -14,12 +14,14 @@ 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->recordModel = new \app\admin\model\greenroom\Record;
+        $this->adminModel = new \app\admin\model\Admin;
+        $this->userlinkModel = new \app\admin\model\greenroom\Userlink;
     }
+
     /**
      * 首页
      *
@@ -28,42 +30,45 @@ class Index extends Api
     {
         $this->success('请求成功');
     }
+
     //跟新收益
-    public function upincome(){
+    public function upincome()
+    {
 
         $maxId = $this->recordModel->max('id');
 
-        $recorddata=  $this->recordModel
+        $recorddata = $this->recordModel
             ->field('sum(income) as income ,uid as id')
             ->where("id", "<=", $maxId)
-            ->where(['status'=>0])
+            ->where(['status' => 0])
             ->group('uid')
             ->select();
-        $temp=$userids=[];
-        $returndata='1';
+        $temp = $userids = [];
+        $returndata = '1';
         Db::startTrans();
-        if($recorddata){
-            $returndata='12';
-            foreach ($recorddata as $key=>$val){
-            $temp[$val['id']]=$val['income'];
-            $userids[]=$val['id'];
+        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']]];
+            $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';
+            if ($upincome) {
+                $returndata = '123';
                 $this->adminModel->saveAll($upincome);
-                $this->recordModel->where("id", "<=", $maxId)->where(['status'=>0])->update(['status'=>1]);
+                $this->recordModel->where("id", "<=", $maxId)->where(['status' => 0])->update(['status' => 1]);
             }
         }
         Db::commit();
         return $returndata;
     }
+
     /**
      * 跑链接收益
      *
@@ -72,16 +77,15 @@ class Index extends Api
     {
         $nowtime = time();
         $spacetime = 10 * 60;
-        $returndata='';
+        $returndata = '';
         $userdata = db('admin')->field("id")
-        ->where(['livetime'=>['gt', $nowtime - $spacetime]])
-        ->where(['incomeendtime'=>['gt', $nowtime]])
-        ->select();
+            ->where(['livetime' => ['gt', $nowtime - $spacetime]])
+            ->where(['incomeendtime' => ['gt', $nowtime]])
+            ->select();
         Db::startTrans();
         if (!$userdata) {
-        $returndata= 'no data';
+            $returndata = 'no data';
         } else {
-            Db::startTrans();
             $userids = array_column($userdata, 'id');
             $userlink = db('userlink')
                 ->join(['fa_link'], 'fa_userlink.link_id = fa_link.id')
@@ -92,27 +96,27 @@ class Index extends Api
                               fa_userlink.income as income,
                             fa_link.minincome as minincome,
                             fa_link.maxincome as maxincome
-                    ")->where(['uid'=>['in', $userids]])->select();
+                    ")->where(['uid' => ['in', $userids]])->select();
             if (!$userlink) {
-                $returndata='no data1';
+                $returndata = 'no data1';
 
             } else {
-                $savedata =$userlinkdata= [];
+                $savedata = $userlinkdata = [];
                 foreach ($userlink as $key => $val) {
-                    $income=mt_rand($val['minincome'] * 10000, $val['maxincome'] * 10000) / 10000;
+                    $income = mt_rand($val['minincome'] * 10000, $val['maxincome'] * 10000) / 10000;
                     $savedata[] = ['income' => $income,
                         'time' => $nowtime,
                         'link' => $val['link'],
                         'uid' => $val['uid'],
                         'status' => 0
                     ];
-                    $userlinkdata[]=['id'=>$val['userlinkid'],'income'=>$val['income']+$income];
+                    $userlinkdata[] = ['id' => $val['userlinkid'], 'income' => $val['income'] + $income];
 
                 }
 
                 $this->userlinkModel->saveAll($userlinkdata);
                 $this->recordModel->saveAll($savedata);
-                $returndata= 'insert ' . count($savedata) . ' record';
+                $returndata = 'insert ' . count($savedata) . ' record';
             }
             Db::commit();
         }
@@ -122,8 +126,8 @@ class Index extends Api
 
     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'));
+        $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)
@@ -134,13 +138,12 @@ class Index extends Api
 
         $date = date("Y-m-d", $beginYesterday);
         Db::startTrans();
-        foreach ($total as $item)
-        {
+        foreach ($total as $item) {
             DayRecord::create([
-                "uid"   =>  $item->id,
-                "addtime"   =>  $date,
-                "link_num"  =>  $item->num,
-                "income"    =>  bcmul('1', $item->income, 4)
+                "uid" => $item->id,
+                "addtime" => $date,
+                "link_num" => $item->num,
+                "income" => bcmul('1', $item->income, 4)
             ]);
         }
 

+ 1 - 1
application/config.php

@@ -59,7 +59,7 @@ return [
     // | 模块设置
     // +----------------------------------------------------------------------
     // 默认模块名
-    'default_module'         => 'index',
+    'default_module'         => 'admin',
     // 禁止访问模块
     'deny_module_list'       => ['common', 'admin'],
     // 默认控制器名