gamebackend/application/common/model/GameConfiguration.php

40 lines
1.6 KiB
PHP
Raw Permalink Normal View History

<?php
// +----------------------------------------------------------------------
// | 作者:修缘 联系QQ278896498 QQ群1054861244
// | 声明:未经作者许可,禁止倒卖等商业运营,违者必究
// | 另接php业务网站制作、代理后台、gm后台、支付对接等
// +----------------------------------------------------------------------
// | 创建时间: 2022/1/13 0:53
// +----------------------------------------------------------------------
namespace app\common\model;
class GameConfiguration extends Model
{
protected $table = 'game_configuration';
public static function configuration(int $state, int $server_id, int $quota=0, int $maxQuota=0)
{
$server_string = "currency_{$server_id}";
$query = self::whereIn('key_data', $server_string)->find();
if ($state) {
if (!$query) {
$result = self::create(['key_data' => $server_string, 'value_data' => json_encode(['quota' => $quota, 'maxQuota' => $maxQuota, 'state' => 1])]);
}else {
$result = self::whereIn('key_data',$server_string)->update([
'value_data' => json_encode(['quota' => $quota, 'maxQuota' => $maxQuota, 'state' => 1])
]);
}
} else {
if (!$query) {
exception(lang('no_open_gold', [$server_id]));
}
$result = self::whereIn('key_data',$server_string)->update(['value_data' => json_encode(['state' => 0])]);
}
return $result ? ['code'=>0, 'msg' => lang('success')] : exception(lang('error'));
}
}