Commit fe11ff22 by haojie

1

parent 904a2075
...@@ -101,10 +101,14 @@ protected function grid() ...@@ -101,10 +101,14 @@ protected function grid()
}); });
# winner_list-中奖钱包 # winner_list-中奖钱包
$grid->column('winner_list', '中奖钱包')->display(function ($item) { $grid->column('winner_list', '中奖钱包')->display(function ($item) {
$list = ['12', '234']; $json = json_decode($item);
$json = json_encode($list); if (!$json) {
$json = json_decode($json); return '暂无';
if (count($json)) { }
return '点击展开';
})->expand(function () {
$json = json_decode($this->winner_list);
if ($json && count($json)) {
# 是数组 # 是数组
$div = ''; $div = '';
foreach ($json as $value) { foreach ($json as $value) {
......
...@@ -44,11 +44,10 @@ public function handle() ...@@ -44,11 +44,10 @@ public function handle()
BlindBoxList::query()->where('id', $value->id)->update(['status' => $status]); BlindBoxList::query()->where('id', $value->id)->update(['status' => $status]);
} }
} }
Log::error('结束运行了');
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error($e); Log::error($e);
} }
sleep(5);
return Command::SUCCESS; return Command::SUCCESS;
} }
} }
...@@ -4,10 +4,8 @@ ...@@ -4,10 +4,8 @@
namespace App\Http\Controllers\API\BlindBox; namespace App\Http\Controllers\API\BlindBox;
use App\Models\BlindBoxList; use App\Models\BlindBoxList;
use App\Models\UserWallet;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
class OpenPrizeController class OpenPrizeController
{ {
/** /**
...@@ -15,12 +13,11 @@ class OpenPrizeController ...@@ -15,12 +13,11 @@ class OpenPrizeController
*/ */
public function useOpenPrize($item) public function useOpenPrize($item)
{ {
Log::error('进入');
# 已购买人数 # 已购买人数
$purchased = json_decode($item->purchased); $purchased = json_decode($item->purchased);
# 可中奖人数 # 可中奖人数
$winner_num = $item->winner_num; $winner_num = $item->winner_num;
if ($purchased && count($purchased) && count($purchased) > $item->min_participants_num) { if ($purchased && count($purchased) && count($purchased) >= $item->min_participants_num) {
# 计算购买者应有的中奖几率 # 计算购买者应有的中奖几率
#平均值 #平均值
$average_value = 100 / count($purchased); $average_value = 100 / count($purchased);
...@@ -44,47 +41,48 @@ public function useOpenPrize($item) ...@@ -44,47 +41,48 @@ public function useOpenPrize($item)
$values->rate = $not_invite_rate; $values->rate = $not_invite_rate;
} }
} }
}
# 开奖 - address-invite_num-rate---$winner_num # 开奖 -
$while_status = true; $while_status = 1;
$winner_list = json_decode($item->winner_list); $winner_list = json_decode($item->winner_list);
while ($while_status) { while ($while_status) {
# 直到抽奖人数达标 # 直到抽奖人数达标
if ($winner_list && count($winner_list) >= $winner_num) { if ($winner_list && count($winner_list) >= $winner_num) {
$while_status = false; $while_status = 0;
continue; continue;
} }
$res = self::get_prize($purchased); $res = self::get_prize($purchased);
Log::error($res); if ($res) {
if ($res) { if ($winner_list && count($winner_list)) {
if ($winner_list && count($winner_list)) { foreach ($winner_list as $win_item) {
# 数组已存在 if ($win_item == $res) {
foreach ($winner_list as $win_item) { continue;
if ($win_item == $res) { } else {
continue; # 没有重复中奖--push
} else { $winner_list[] = $res;
# 没有重复中奖--push break;
$winner_list[] = $res; }
break;
} }
} else {
# 为空创建一个数组
$list = [];
$list[] = $res;
$winner_list = $list;
} }
} else { } else {
# 为空创建一个数组 $while_status = 0;
$list = []; Log::error('未取到中奖地址');
$list[] = $res; }
$winner_list = $list; $while_status += 1;
if ($while_status == 100) {
$while_status = 0;
Log::error('本次开奖已经循环一百次,请查看问题');
} }
} else {
Log::error('空地址');
$while_status = false;
} }
$while_status = false; # 更新数据
BlindBoxList::query()->where('id', $item->id)->update(['winner_list' => json_encode($winner_list),
'purchased' => json_encode($purchased)]);
} }
Log::error('结束');
# 更新数据
BlindBoxList::query()->where('id', $item->id)->update(['winner_list' => json_encode($winner_list),
'purchased' => json_encode($purchased)]);
} }
public function get_prize($list) public function get_prize($list)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment