1.新增商城参数配置菜单-管理兑换比例
This commit is contained in:
91
app/admin/controller/mall/PlayxConfig.php
Normal file
91
app/admin/controller/mall/PlayxConfig.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\admin\controller\mall;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\MallPlayxRatios;
|
||||
use app\common\model\MallConfig;
|
||||
use support\Response;
|
||||
use Webman\Http\Request;
|
||||
|
||||
/**
|
||||
* 积分商城参数(PlayX 比例等)
|
||||
*/
|
||||
class PlayxConfig extends Backend
|
||||
{
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$row = MallConfig::order('id', 'asc')->find();
|
||||
if (!$row) {
|
||||
$now = time();
|
||||
MallConfig::create([
|
||||
'return_ratio' => floatval(env('PLAYX_RETURN_RATIO', '0.1')),
|
||||
'unlock_ratio' => floatval(env('PLAYX_UNLOCK_RATIO', '0.1')),
|
||||
'points_to_cash_ratio' => floatval(env('PLAYX_POINTS_TO_CASH_RATIO', '0.1')),
|
||||
'create_time' => $now,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
$row = MallConfig::order('id', 'asc')->find();
|
||||
}
|
||||
|
||||
return $this->success('', [
|
||||
'row' => $row ? $row->toArray() : [],
|
||||
'remark' => get_route_remark(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeBackend($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$data = $request->post();
|
||||
if (empty($data) || !is_array($data)) {
|
||||
return $this->error(__('Parameter %s can not be empty', ['']));
|
||||
}
|
||||
|
||||
$return = $data['return_ratio'] ?? null;
|
||||
$unlock = $data['unlock_ratio'] ?? null;
|
||||
$cash = $data['points_to_cash_ratio'] ?? null;
|
||||
if (!is_numeric($return) || !is_numeric($unlock) || !is_numeric($cash)) {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
|
||||
$returnF = floatval($return);
|
||||
$unlockF = floatval($unlock);
|
||||
$cashF = floatval($cash);
|
||||
if ($returnF < 0 || $unlockF < 0 || $cashF < 0) {
|
||||
return $this->error(__('Parameter error'));
|
||||
}
|
||||
|
||||
$row = MallConfig::order('id', 'asc')->find();
|
||||
if (!$row) {
|
||||
$now = time();
|
||||
MallConfig::create([
|
||||
'return_ratio' => $returnF,
|
||||
'unlock_ratio' => $unlockF,
|
||||
'points_to_cash_ratio' => $cashF,
|
||||
'create_time' => $now,
|
||||
'update_time' => $now,
|
||||
]);
|
||||
} else {
|
||||
$row->return_ratio = $returnF;
|
||||
$row->unlock_ratio = $unlockF;
|
||||
$row->points_to_cash_ratio = $cashF;
|
||||
$row->save();
|
||||
}
|
||||
|
||||
MallPlayxRatios::forget();
|
||||
|
||||
return $this->success(__('The current page configuration item was updated successfully'));
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ use app\common\model\MallDailyPush;
|
||||
use app\common\model\MallSession;
|
||||
use app\common\model\MallOrder;
|
||||
use app\common\model\MallUserAsset;
|
||||
use app\common\library\MallPlayxRatios;
|
||||
use app\common\model\MallAddress;
|
||||
use support\think\Db;
|
||||
use Webman\Http\Request;
|
||||
@@ -231,8 +232,9 @@ class Playx extends Api
|
||||
$requestId = 'report_' . $date;
|
||||
}
|
||||
|
||||
$returnRatio = config('playx.return_ratio', 0.1);
|
||||
$unlockRatio = config('playx.unlock_ratio', 0.1);
|
||||
$ratios = MallPlayxRatios::get();
|
||||
$returnRatio = $ratios['return_ratio'];
|
||||
$unlockRatio = $ratios['unlock_ratio'];
|
||||
|
||||
$results = [];
|
||||
$allDeduped = true;
|
||||
@@ -332,8 +334,9 @@ class Playx extends Api
|
||||
$exists = MallDailyPush::where('user_id', $playxUserId)->where('date', $date)->find();
|
||||
if ($exists) {
|
||||
$newLocked = 0;
|
||||
$returnRatio = config('playx.return_ratio', 0.1);
|
||||
$unlockRatio = config('playx.unlock_ratio', 0.1);
|
||||
$ratios = MallPlayxRatios::get();
|
||||
$returnRatio = $ratios['return_ratio'];
|
||||
$unlockRatio = $ratios['unlock_ratio'];
|
||||
if ($yesterdayWinLossNet < 0) {
|
||||
$newLocked = intval(round(abs(floatval($yesterdayWinLossNet)) * $returnRatio));
|
||||
}
|
||||
@@ -365,8 +368,9 @@ class Playx extends Api
|
||||
]);
|
||||
|
||||
$newLocked = 0;
|
||||
$returnRatio = config('playx.return_ratio', 0.1);
|
||||
$unlockRatio = config('playx.unlock_ratio', 0.1);
|
||||
$ratios = MallPlayxRatios::get();
|
||||
$returnRatio = $ratios['return_ratio'];
|
||||
$unlockRatio = $ratios['unlock_ratio'];
|
||||
if ($yesterdayWinLossNet < 0) {
|
||||
$newLocked = intval(round(abs(floatval($yesterdayWinLossNet)) * $returnRatio));
|
||||
}
|
||||
@@ -668,7 +672,7 @@ class Playx extends Api
|
||||
]);
|
||||
}
|
||||
|
||||
$ratio = config('playx.points_to_cash_ratio', 0.1);
|
||||
$ratio = MallPlayxRatios::get()['points_to_cash_ratio'];
|
||||
$withdrawableCash = round($asset->available_points * $ratio, 2);
|
||||
|
||||
return $this->success('', [
|
||||
@@ -1257,7 +1261,7 @@ SQL;
|
||||
'withdrawable_cash' => 0,
|
||||
];
|
||||
}
|
||||
$ratio = config('playx.points_to_cash_ratio', 0.1);
|
||||
$ratio = MallPlayxRatios::get()['points_to_cash_ratio'];
|
||||
return [
|
||||
'locked_points' => $asset->locked_points,
|
||||
'available_points' => $asset->available_points,
|
||||
|
||||
58
app/common/library/MallPlayxRatios.php
Normal file
58
app/common/library/MallPlayxRatios.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\library;
|
||||
|
||||
use app\common\model\MallConfig;
|
||||
|
||||
/**
|
||||
* PlayX 与积分商城相关的比例配置:优先读 mall_config,无表记录时回退 .env
|
||||
*/
|
||||
final class MallPlayxRatios
|
||||
{
|
||||
private static ?array $cache = null;
|
||||
|
||||
/**
|
||||
* @return array{return_ratio: float, unlock_ratio: float, points_to_cash_ratio: float}
|
||||
*/
|
||||
public static function get(): array
|
||||
{
|
||||
if (self::$cache !== null) {
|
||||
return self::$cache;
|
||||
}
|
||||
|
||||
$row = MallConfig::order('id', 'asc')->find();
|
||||
if ($row) {
|
||||
self::$cache = [
|
||||
'return_ratio' => self::toFloat($row->return_ratio),
|
||||
'unlock_ratio' => self::toFloat($row->unlock_ratio),
|
||||
'points_to_cash_ratio' => self::toFloat($row->points_to_cash_ratio),
|
||||
];
|
||||
|
||||
return self::$cache;
|
||||
}
|
||||
|
||||
self::$cache = [
|
||||
'return_ratio' => floatval(env('PLAYX_RETURN_RATIO', '0.1')),
|
||||
'unlock_ratio' => floatval(env('PLAYX_UNLOCK_RATIO', '0.1')),
|
||||
'points_to_cash_ratio' => floatval(env('PLAYX_POINTS_TO_CASH_RATIO', '0.1')),
|
||||
];
|
||||
|
||||
return self::$cache;
|
||||
}
|
||||
|
||||
public static function forget(): void
|
||||
{
|
||||
self::$cache = null;
|
||||
}
|
||||
|
||||
private static function toFloat(mixed $v): float
|
||||
{
|
||||
if (is_numeric($v)) {
|
||||
return floatval($v);
|
||||
}
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
25
app/common/model/MallConfig.php
Normal file
25
app/common/model/MallConfig.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\think\Model;
|
||||
|
||||
/**
|
||||
* 积分商城配置(比例等)
|
||||
*/
|
||||
class MallConfig extends Model
|
||||
{
|
||||
protected string $name = 'mall_config';
|
||||
|
||||
protected bool $autoWriteTimestamp = true;
|
||||
|
||||
protected array $type = [
|
||||
'create_time' => 'integer',
|
||||
'update_time' => 'integer',
|
||||
'return_ratio' => 'float',
|
||||
'unlock_ratio' => 'float',
|
||||
'points_to_cash_ratio' => 'float',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user