Selaa lähdekoodia

fix: 订单不够开奖也添加开奖记录
修改神抢手和幸运2021的赔付比例为0.3

joe 4 vuotta sitten
vanhempi
commit
d141eebb44

+ 20 - 3
crmeb/services/async/ActivityCalc.php

@@ -41,12 +41,18 @@ abstract class ActivityCalc {
             ->where('o.is_system_del', 0)
             ->where('p.cate_id', $cate_id)
             ->where('ci.activity', '')
-            ->field('o.id, o.pay_price, ci.product_id, ci.cart_info, u.uid, u.now_money, u.pay_count, p.store_name')
+            ->field('o.id, o.order_id, o.pay_price, ci.product_id, ci.cart_info, u.uid, u.now_money, u.pay_count, p.store_name')
             ->select();
         $products = $products ? $products->toArray() : [];
         return $products;
     }
 
+    protected function getPoolKey()
+    {
+        $KEY = 'activity:pool:';
+        return $KEY . $this->getName();
+    }
+    
     /**
      * 用统一的架构来计算输赢
      */
@@ -58,6 +64,17 @@ abstract class ActivityCalc {
         $minNum = $this->getMinimalProductNum();
         if ($pNum < $minNum) {
             Log::warning("not enough order. product num: $pNum, $minNum needed, stop activity:" . $this->getNameCN());
+             SystemAwardHistory::create([
+                'activity' => $this->getName(),
+                'result' => $this->getResult(mt_rand(0, 10) < 5 ? true : false),
+                'ts' => time(),
+                'order_num' => $pNum,
+                'winner_num' => 0,
+                'total_paid' => 0,
+                'diff_paid' => 0,
+                'profit' => 0,
+                'rate' => $this->repRate(),
+            ]);
             return;
         }
 
@@ -153,7 +170,7 @@ abstract class ActivityCalc {
                 $itWin = true;
             }
 
-            $remain = intval(Redis::hGet($KEY, $this->getName()));
+            $remain = intval(Redis::hGet($KEY, $this->getName()));  // pool 中金额
             if (!$itWin) {
                 // 如果为新用户,且池子有钱,让他胜
                 if ($remain > $profit && $products[0]['pay_count'] <= 1) {
@@ -163,7 +180,7 @@ abstract class ActivityCalc {
             
             if ($itWin) {
                 $profit = -$profit;
-                list($winners, $losers) = [$losers, $winners];
+                list($winners, $losers) = [$losers, $winners];  // swap
             }
             Redis::hSet($KEY, $this->getName(), $remain + $profit);
 

+ 2 - 2
crmeb/services/async/ClearanceCalc.php

@@ -35,12 +35,12 @@ class ClearanceCalc extends ActivityCalc{
 
     // 赔款比例, 为利润的比例
     protected function repRate() {
-        return 0.2;
+        return 0.3;
     }
 
     protected function getMinimalProductNum()
     {
-        return 2;
+        return 1;
     }
 
     protected function getResult($leftwin=true) {

+ 1 - 1
crmeb/services/async/LuckyCalc.php

@@ -21,7 +21,7 @@ class LuckyCalc extends ActivityCalc{
     }
 
     protected function repRate() {
-        return 0.2;
+        return 0.3;
     }
 
     protected function getMinimalProductNum()

+ 12 - 0
docs/TODO.md

@@ -55,3 +55,15 @@
 
 - ALTER TABLE twong.eb_system_admin ADD secret varchar(100) NULL COMMENT '2FA secret';
 - ALTER TABLE twong.eb_system_award_history MODIFY COLUMN profit decimal(8,2) DEFAULT 0 NOT NULL COMMENT '本次盈利';
+
+## 匹配算法
+
+v1
+
+所有活动 1 单即可开奖, 0单得有开奖结果
+
+2021 类按自然算法处理
+
+神枪手活动让新用户优先中奖
+
+1 单开奖有较大自由度,让新用户优先中奖