123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- 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;
-
- protected function getSingleCacheKey($id) {
- return $this->cache_key_prefix.$id;
- }
-
- public function addData($data) {
- $_data = $data;
- $_id = parent::parentAddData($_data);
- if (false === $_id) {
- return false;
- }
-
- return $_id;
- }
-
- 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;
- }
-
- 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);
-
- return true;
- }
-
- 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);
-
- return $_rs;
- }
-
- public function game() {
- return $this->belongsTo('huo\model\game\GameModel', 'app_id')->field('id,name game_name,pay_switch');
- }
- }
|