123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- /**
- * GameOrderSwitchModel.php UTF-8
- * 支付切换规则
- *
- * @date : 2018/6/6 22:06
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\model\game;
- use huo\model\common\CommonModel;
- use huolib\constant\CacheConst;
- use think\Cache;
- class GameOrderSwitchModel extends CommonModel {
- protected $pk = 'app_id';
- protected $name = 'game_order_switch';
- /* 开启自动写入时间戳字段 */
- protected $autoWriteTimestamp = true;
- protected $cache_key_prefix = CacheConst::CACHE_GAME_ORDER_SWITCH_PREFIX;
- /**
- * 获取单条记录缓存key
- *
- * @param int $id ID
- *
- * @return string
- */
- protected function getSingleCacheKey($id) {
- return $this->cache_key_prefix.$id;
- }
- /**
- * 添加数据
- *
- * @param array $data 需要添加的数据
- *
- * @return false|int 添加失败返回 false 添加成功 返回添加的ID
- */
- public function addData($data) {
- $_data = $data;
- $_id = parent::parentAddData($_data);
- if (false === $_id) {
- return false;
- }
- /* TAG缓存操作 */
- return $_id;
- }
- /**
- * 通过ID获取信息
- *
- * @param int $id 主键ID
- *
- * @return array|false
- */
- public function getInfoById($id) {
- /* 缓存操作 */
- $_single_cache_key = $this->getSingleCacheKey($id);
- $_data = Cache::get($_single_cache_key);
- if (!empty($_data)) {
- return $_data;
- }
- $_data = parent::parentGetInfoById($id);
- if (empty($_data)) {
- return [];
- }
- Cache::set($_single_cache_key, $_data);
- return $_data;
- }
- /**
- * 更新单条数据
- *
- * @param array $data 数据
- * @param int $id ID
- *
- * @return bool
- */
- public function updateData($data, $id) {
- $_data = $data;
- $_rs = parent::parentUpdateData($_data, $id);
- if (false === $_rs) {
- return false;
- }
- /* 缓存操作 */
- $_single_cache_key = $this->getSingleCacheKey($id);
- Cache::rm($_single_cache_key);
- /* TAG缓存操作 */
- return true;
- }
- /**
- * 删除单条数据
- *
- * @param int $id ID
- * @param bool $is_complete 是否完成删除
- *
- * @return bool
- */
- public function deleteData($id, $is_complete = false) {
- $_rs = parent::parentDeleteData($id, $is_complete);
- if (false == $_rs) {
- return false;
- }
- /* 缓存操作 */
- $_single_cache_key = $this->getSingleCacheKey($id);
- Cache::rm($_single_cache_key);
- /* TAG缓存操作 */
- return $_rs;
- }
- /**
- * 关联game表
- *
- * @return mixed
- */
- public function game() {
- return $this->belongsTo('huo\model\game\GameModel', 'app_id')->field('id,name game_name,pay_switch');
- }
- }
|