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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user