| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 | 
							- <?php
 
- /**
 
-  * GameModel.php  UTF-8
 
-  * 游戏表
 
-  *
 
-  * @date    : 2020/9/14 15:23
 
-  *
 
-  * @license 这不是一个自由软件,未经授权不许任何使用和传播。
 
-  * @author  : chenbingling <cbl@huosdk.com>
 
-  * @version : H5IOS 1.0
 
-  */
 
- namespace huosdk\h5ios\core\model;
 
- use huosdk\h5ios\core\constant\CacheConst;
 
- use huosdk\h5ios\core\constant\CommonConst;
 
- use huosdk\h5ios\core\constant\GameConst;
 
- use Pin;
 
- use think\Cache;
 
- use think\Loader;
 
- class GameModel extends \huo\model\game\GameModel {
 
-     protected $name = 'game';
 
-     protected $pk   = 'id';
 
-     /* 开启自动写入时间戳字段 */
 
-     protected $autoWriteTimestamp = true;
 
-     protected $cache_key_prefix   = CacheConst::CACHE_GAME_PREFIX;
 
-     use ModelTrait;
 
-     protected $type
 
-         = [
 
-             'id'             => 'integer',
 
-             'name'           => 'string',
 
-             'en_name'        => 'string',
 
-             'en_abbr'        => 'string',
 
-             'app_key'        => 'string',
 
-             'tags'           => 'string',
 
-             'category'       => 'string',
 
-             'classify'       => 'integer',
 
-             'icon'           => 'string',
 
-             'cp_payback_url' => 'string',
 
-             'cp_id'          => 'integer',
 
-             'parent_id'      => 'integer',
 
-             'package_name'   => 'string',
 
-             'pay_switch'     => 'integer',
 
-             'pay_show'       => 'integer',
 
-             'float_is_show'  => 'integer',
 
-             'status'         => 'integer',
 
-             'is_auth'        => 'integer',
 
-             'is_online'      => 'integer',
 
-             'is_sdk'         => 'integer',
 
-             'is_bt'          => 'integer',
 
-             'list_order'     => 'integer',
 
-             'rise_order'     => 'integer',
 
-             'hot_order'      => 'integer',
 
-             'like_order'     => 'integer',
 
-             'fine_order'     => 'integer',
 
-             'publicity'      => 'string',
 
-             'language'       => 'string',
 
-             'description'    => 'string',
 
-             'image'          => 'json',
 
-             'apple_id'       => 'string',
 
-             'single_tag'     => 'string',
 
-             'ext_info'       => 'json',
 
-             'is_delete'      => 'integer',
 
-             'delete_time'    => 'timestamp',
 
-             'add_cp_time'    => 'timestamp',
 
-             'run_time'       => 'timestamp',
 
-             'create_time'    => 'timestamp',
 
-             'update_time'    => 'timestamp',
 
-             'promote_switch' => 'integer',
 
-         ];
 
-     /**
 
-      * 添加游戏
 
-      *
 
-      * @param $data
 
-      *
 
-      * @return bool|mixed
 
-      */
 
-     public function addData($data) {
 
-         $_data = $data;
 
-         Loader::import('pinyin.Pin', '', '.class.php');
 
-         $_pin_class = new Pin();
 
-         $_data['en_name'] = $_pin_class->pinyin($_data['name']);
 
-         return parent::addGames($_data);
 
-     }
 
-     /**
 
-      * 通过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::getInfoById($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) {
 
-         if (isset($data['status']) && GameConst::GAME_STATUS_ON == $data['status']) {
 
-             $data['run_time'] = time();
 
-         }
 
-         $_rs = parent::updateGame($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) {
 
-         $data = [
 
-             $_data['is_delete'] = CommonConst::CONST_DELETED,
 
-             $_data['delete_time'] = time()
 
-         ];
 
-         $_rs = parent::updateGame($data, $id);
 
-         if (false == $_rs) {
 
-             return false;
 
-         }
 
-         /* 缓存操作 */
 
-         $_single_cache_key = $this->getSingleCacheKey($id);
 
-         Cache::rm($_single_cache_key);
 
-         /* TAG缓存操作 */
 
-         return $_rs;
 
-     }
 
-     /**
 
-      *  游戏名称同名数量
 
-      *
 
-      * @param array $where 查询条件
 
-      *
 
-      * @return int
 
-      */
 
-     public function getNameCnt($where) {
 
-         $_map = $where;
 
-         $_cnt = $this->getCnt($_map);
 
-         return $_cnt;
 
-     }
 
-     /**
 
-      * 通过条件获取数量
 
-      *
 
-      * @param array $where 条件
 
-      *
 
-      * @return int
 
-      */
 
-     public function getCnt($where = []) {
 
-         $_map = $where;
 
-         $_cnt = $this->useGlobalScope(false)->where($_map)->count();
 
-         if (empty($_cnt)) {
 
-             return 0;
 
-         }
 
-         return $_cnt;
 
-     }
 
-     /**
 
-      * 关联H5游戏
 
-      */
 
-     public function pg() {
 
-         return $this->belongsTo(GameModel::class, 'parent_id', 'id')->field('id,name,icon');
 
-     }
 
- }
 
 
  |