|
|
@@ -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);
|
|
|
|