柳建 9 сар өмнө
parent
commit
15b6d0b2b8

+ 11 - 2
application/api/controller/Index.php

@@ -77,15 +77,19 @@ class Index extends Api
         ->where(['livetime'=>['gt', $nowtime - $spacetime]])
         ->where(['incomeendtime'=>['gt', $nowtime]])
         ->select();
+        Db::startTrans();
         if (!$userdata) {
         $returndata= 'no data';
         } else {
+            Db::startTrans();
             $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();
@@ -93,18 +97,23 @@ class Index extends Api
                 $returndata='no data1';
 
             } else {
-                $savedata = [];
+                $savedata =$userlinkdata= [];
                 foreach ($userlink as $key => $val) {
-                    $savedata[] = ['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['userlinkid']+$income];
+
                 }
+                $this->userlinkModel->saveAll($userlinkdata);
                 $this->recordModel->saveAll($savedata);
                 $returndata= 'insert ' . count($savedata) . ' record';
             }
+            Db::commit();
         }
         return $returndata;
     }