Browse Source

概率设置接口

master
wanghongjun 2 years ago
parent
commit
a6c5c252ac
  1. 39
      app/controller/Setting.php
  2. 9
      app/logic/InitData.php
  3. 4
      app/logic/ZoneLogic.php

39
app/controller/Setting.php

@ -63,7 +63,44 @@ class Setting extends BaseController
return $this->renderSuccess('设置成功');
} catch (ValidateException $validateException) {
return $this->renderError($validateException['msg']);
return $this->renderError($validateException->getMessage());
}
}
/**
* 获取概率
* @return array
*/
public function getProbability()
{
try {
$probability = SettingModel::settingLoad('amount_probability') ?: 0;
return $this->renderSuccess('数据返回成功',['rate' => $probability]);
} catch (\Exception $e) {
return $this->renderError('操作失败');
}
}
/**
* 设置概率
* @return array
*/
public function settingProbability()
{
$param = Request::param();
try {
validate()->rule([
'rate' => 'require|float|between:0.01,500',
])->check($param);
SettingModel::settingSave('amount_probability',round($param['rate'] / 100,4));
return $this->renderSuccess('设置成功');
} catch (ValidateException $validateException) {
return $this->renderError($validateException->getMessage());
} catch (\Exception $e) {
return $this->renderError('操作失败');
}
}
}

9
app/logic/InitData.php

@ -3,6 +3,7 @@
namespace app\logic;
use app\model\AdminUser;
use app\model\Setting as SettingModel;
use app\model\ZoneAmountParam;
use app\model\ZoneGoodsPlay;
@ -18,6 +19,7 @@ class InitData
$this->createZoneAmountParam();
$this->createZone();
$this->createZoneGoodsPlay();
$this->createSetting();
}
@ -89,6 +91,13 @@ class InitData
}
public function createSetting()
{
$query = SettingModel::settingLoad('amount_probability') ?: 0;
if (!$query) {
SettingModel::settingSave('amount_probability','0.5');
}
}

4
app/logic/ZoneLogic.php

@ -6,6 +6,7 @@ use app\model\AwardsLog;
use app\model\AwardsRecords;
use app\model\ConsumptionRecords;
use app\model\RechargeRecords;
use app\model\Setting as SettingModel;
use app\model\User;
use app\model\ZoneAmountParam;
use app\model\ZoneGoods;
@ -611,8 +612,7 @@ class ZoneLogic
protected static function judgeUserRate():array
{
try {
$userData = self::$userData;
$rate = $userData['rate'];
$rate = SettingModel::settingLoad('amount_probability') ?: '0.5';
$residue_amount = 0;
# 最近一次充值金额

Loading…
Cancel
Save