Browse Source

修改 链接小数比例

程旭源 9 months ago
parent
commit
c5a6d44105

+ 29 - 0
application/admin/controller/greenroom/Link.php

@@ -33,5 +33,34 @@ class Link extends Backend
      * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
      */
 
+    public function edit($ids = null)
+    {
+        if ($this->request->isPost()) {
+            echo "-----------";
+            $params = $this->request->post('row/a');
+            if (empty($params)) {
+                $this->error(__('Parameter %s can not be empty', ''));
+            }
+            $params = $this->preExcludeFields($params);
+            if (bccomp($params['minincome'], $params['maxincome'], 7) === 1) {
+                return $this->error("最小值不允许超过最大值");
+            }
+        }
+        return parent::edit($ids);
+    }
 
+    public function add()
+    {
+        if ($this->request->isPost()) {
+            $params = $this->request->post('row/a');
+            if (empty($params)) {
+                $this->error(__('Parameter %s can not be empty', ''));
+            }
+            $params = $this->preExcludeFields($params);
+            if (bccomp($params['minincome'], $params['maxincome'], 7) === 1) {
+                return $this->error("最小值不允许超过最大值");
+            }
+        }
+        return parent::add();
+    }
 }

+ 12 - 1
application/api/controller/Index.php

@@ -103,7 +103,18 @@ class Index extends Api
             } else {
                 $savedata = $userlinkdata = [];
                 foreach ($userlink as $key => $val) {
-                    $income = mt_rand($val['minincome'] * 10000, $val['maxincome'] * 10000) / 10000;
+
+                    $unit = 1;
+                    for($i=1;; $i++) {
+                        $unit = bcpow(10, $i, 10);
+                        if (bccomp("1", bcmul($val['minincome'].'', $unit, 10), 10) !== 1) {
+                            break;
+                        }
+                    }
+
+
+//                    $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'],