123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- /**
- * GameServerSwitchModel.php UTF-8
- * 区服支付切换
- *
- * @date : 2018/12/22 11:37
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\model\game;
- use huo\model\common\CommonModel;
- use huolib\constant\CacheConst;
- use huolib\constant\CommonConst;
- use huolib\constant\OrderConst;
- use think\Cache;
- class GameServerSwitchModel extends CommonModel {
- protected $name = 'game_server_switch';
- protected $autoWriteTimestamp = true;
- protected $key = CacheConst::CACHE_GAME_SERVER_PAY_SWITCH_PREFIX;
- /**
- * 获取缓存key
- *
- * @param $app_id
- * @param $server_id
- *
- * @return string
- */
- protected function getKey($app_id, $server_id) {
- $_key = $this->key.$app_id.'_'.$server_id;
- return $_key;
- }
- public function addData($data) {
- $_data = [];
- $_data['app_id'] = get_val($data, 'app_id', '');
- $_data['server_id'] = get_val($data, 'server_id', 0);
- $_data['server_name'] = get_val($data, 'server_name', '');
- $_data['is_switch'] = get_val($data, 'is_switch', OrderConst::PAY_SWITCH_YES);
- if ($_obj = self::create($_data, true)) {
- $_data['id'] = $_obj->id;
- $_key = $this->getKey($_data['app_id'], $_data['server_id']);
- Cache::set($_key, json_encode($_data), CommonConst::CONST_DAY_SECONDS);
- return $_data;
- } else {
- return false;
- }
- }
- /**
- * 获取详情
- *
- * @param $app_id
- * @param $server_id
- *
- * @return mixed
- */
- public function getInfo($app_id, $server_id) {
- $_key = $this->getKey($app_id, $server_id);
- $_data = Cache::get($_key);
- if (!empty($_data)) {
- return json_decode($_data, true);
- }
- $_map = [
- 'app_id' => $app_id,
- 'server_id' => $server_id,
- ];
- $_data = $this->where($_map)->find();
- if (is_object($_data)) {
- $_data = $_data->toArray();
- }
- if (empty($_data)) {
- return [];
- }
- Cache::set($_key, json_encode($_data), CommonConst::CONST_DAY_SECONDS);
- return $_data;
- }
- /**
- * 修改信息
- *
- * @param $app_id
- * @param $server_id
- * @param $data
- *
- * @return bool
- */
- public function updateDataGss($app_id, $server_id, $data) {
- $_key = $this->getKey($app_id, $server_id);
- $_data = $this->getInfo($app_id, $server_id);
- $_data = array_merge($_data, $data);
- $_map = [
- 'app_id' => $app_id,
- 'server_id' => $server_id,
- ];
- $_rs = $this->where($_map)->update($_data);
- if (false == $_rs) {
- return false;
- }
- Cache::set($_key, json_encode($_data), CommonConst::CONST_DAY_SECONDS);
- return true;
- }
- /**
- * 根据ID更新数据
- *
- * @param $id
- * @param $data
- *
- * @return bool
- */
- public function updateById($id, $data) {
- $_data = parent::getInfoById($id);
- $_data = array_merge($_data, $data);
- $_map = ['id' => $id];
- $_rs = $this->where($_map)->update($_data);
- if (false == $_rs) {
- return false;
- }
- $_key = $this->getKey($_data['app_id'], $_data['server_id']);
- Cache::set($_key, json_encode($_data), CommonConst::CONST_DAY_SECONDS);
- return true;
- }
- /**
- * 获取所有区服id_name
- *
- * @param $app_id
- *
- * @return array
- */
- public function getIdName($app_id) {
- $_map = [
- 'app_id' => $app_id,
- ];
- $_array = $this->where($_map)->column('server_name', 'id');
- return $_array;
- }
- /**
- * 获取标记为不切换的id
- *
- * @param $app_id
- *
- * @return array
- */
- public function getSwitchNo($app_id) {
- $_map = [
- 'app_id' => $app_id,
- 'is_switch' => OrderConst::PAY_SWITCH_NO
- ];
- $_array = $this->where($_map)->column('id');
- return $_array;
- }
- }
|