123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- <?php
- /**
- * AgentGameRateModel.php UTF-8
- * http://doc.1tsdk.com/170?page_id=5613
- * 渠道游戏折扣返利表
- *
- *
- * @date : 2019/4/20 16:23
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.5
- */
- namespace huoRate\model;
- use huo\model\common\CommonModel;
- use huolib\constant\CacheConst;
- use huolib\constant\CommonConst;
- use huolib\constant\GameConst;
- use think\Cache;
- class AgentGameRateModel extends CommonModel {
- protected $name = 'agent_game_rate';
- protected $pk = 'ag_id';
- protected $type = ['benefit_type' => 'int'];
- /* 开启自动写入时间戳字段 */
- protected $autoWriteTimestamp = true;
- protected $cache_key_prefix = CacheConst::CACHE_AGENT_GAME_RATE_PREFIX;
- protected $agent_cache_tag = CacheConst::TAG_AGENT_GAME_LIST;
- /**
- * 获取单条记录缓存key
- *
- * @param int $id ID
- *
- * @return string
- */
- protected function getSingleCacheKey($id) {
- return $this->cache_key_prefix.$id;
- }
- /**
- * 获取单条记录缓存key
- *
- * @param int $app_id 应用ID
- * @param int $agent_id 渠道ID
- *
- * @return string
- */
- protected function getCacheKeyByGameAgent($app_id, $agent_id) {
- return $this->cache_key_prefix.$app_id.'_'.$agent_id;
- }
- /**
- * 添加数据
- *
- * @param array $data 需要添加的数据
- *
- * @return false|int 添加失败返回 false 添加成功 返回添加的ID
- */
- public function addData($data) {
- $_data = $data;
- $_id = parent::addData($_data);
- if (false === $_id) {
- return false;
- }
- {
- $_app_id = get_val($data, 'app_id', 0);
- $_agent_id = get_val($data, 'agent_id', 0);
- /* 添加数据 APP VIP 缓存 */
- $_cache_key = $this->getCacheKeyByGameAgent($_app_id, $_agent_id);
- Cache::set($_cache_key, $_id);
- }
- /* 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::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) {
- $_data = $data;
- $_rs = parent::updateData($_data, $id);
- if (false === $_rs) {
- return false;
- }
- /* 缓存操作 */
- $_single_cache_key = $this->getSingleCacheKey($id);
- Cache::rm($_single_cache_key);
- /* TAG缓存操作 */
- Cache::clear($this->agent_cache_tag);
- /* 更新轮播图列表缓存数据 */
- if (!empty($data['app_id'])) {
- //(new SlideItemModel())->clCacheByAppId($data['app_id']);
- }
- return true;
- }
- /**
- * 删除单条数据
- *
- * @param int $id ID
- * @param bool $is_complete 是否完成删除
- *
- * @return bool
- */
- public function deleteData($id, $is_complete = false) {
- $_rs = parent::deleteData($id, $is_complete);
- if (false == $_rs) {
- return false;
- }
- /* 缓存操作 */
- $_single_cache_key = $this->getSingleCacheKey($id);
- Cache::rm($_single_cache_key);
- /* TAG缓存操作 */
- Cache::clear($this->agent_cache_tag);
- return $_rs;
- }
- /**
- * 更新多条数据
- *
- * @param array $data 数据
- * @param array $ids 主集ID
- *
- * @return bool
- */
- public function updateDatas($data, $ids) {
- $_data = $data;
- foreach ($ids as $_id) {
- $_rs = $this->updateData($_data, $_id);
- if (false == $_rs) {
- return false;
- }
- }
- return true;
- }
- /**
- * 根据游戏删除所有数据
- *
- * @param int $app_id 应用ID
- *
- * @return bool
- */
- public function deleteDataByAppId($app_id) {
- $_map = [
- 'app_id' => $app_id,
- ];
- $_ids = $this->where($_map)->column('id');
- foreach ($_ids as $_id) {
- $this->deleteData($_id);
- }
- return true;
- }
- /**
- * 根据应用渠道获取ID
- *
- * @param int $app_id 应用ID
- * @param int $agent_id 渠道ID
- *
- * @return int
- */
- public function getIdByGameAgent($app_id, $agent_id) {
- if (empty($app_id) && empty($agent_id)) {
- return 0;
- }
- $_cache_key = $this->getCacheKeyByGameAgent($app_id, $agent_id);
- $_id = Cache::get($_cache_key);
- if (!empty($_id)) {
- if (CommonConst::CACHE_HAS_READ == $_id) {
- return 0;
- }
- return $_id;
- }
- $_map = [
- 'app_id' => $app_id,
- 'agent_id' => $agent_id,
- ];
- $_id = $this->where($_map)->value($this->pk);
- if (empty($_id)) {
- Cache::set($_cache_key, CommonConst::CACHE_HAS_READ);
- return 0;
- }
- Cache::set($_cache_key, $_id);
- return $_id;
- }
- /**
- * 根据应用渠道获取信息
- *
- * @param int $app_id 应用ID
- * @param int $agent_id 渠道ID
- *
- *
- * @return array|false
- */
- public function getInfoByGameAgent($app_id, $agent_id) {
- $_id = $this->getIdByGameAgent($app_id, $agent_id);
- if (empty($_id)) {
- return false;
- }
- return $this->getInfoById($_id);
- }
- /**
- * 根据ID获取应用ID
- *
- * @param int $id ID
- *
- *
- * @return int
- */
- public function getAppIdById($id) {
- $_data = $this->getInfoById($id);
- return get_val($_data, 'app_id', CommonConst::CONST_ZERO);
- }
- /**
- * 根据ID获取渠道ID
- *
- * @param int $id ID
- *
- *
- * @return int
- */
- public function getAgentIdById($id) {
- $_data = $this->getInfoById($id);
- return get_val($_data, 'agent_id', CommonConst::CONST_ZERO);
- }
- /**
- * 根据应用渠道获取信息
- *
- * @param int $app_id 应用ID
- * @param int $agent_id 渠道ID
- *
- *
- * @return array|false
- */
- public function getPromoteSwitchByGameAgent($app_id, $agent_id = 0) {
- $_data = $this->getInfoByGameAgent($app_id, $agent_id);
- return get_val($_data, 'promote_switch', 0);
- }
- /**
- * 根据应用渠道游戏折扣
- *
- * @param int $app_id 应用ID
- * @param int $agent_id 渠道ID
- *
- *
- * @return array|false
- */
- public function getGameRateByGameAgent($app_id, $agent_id = 0) {
- $_data = $this->getInfoByGameAgent($app_id, 0);
- return get_val($_data, 'game_rate', CommonConst::CONST_ZERO);
- }
- /**
- * 根据应用渠道获取 优惠类型
- *
- * @param int $app_id 应用ID
- * @param int $agent_id 渠道ID
- *
- *
- * @return int 优惠类型,0 无优惠 1 折扣 2 返利
- */
- public function getBenefitTypeByGameAgent($app_id, $agent_id = 0) {
- $_data = $this->getInfoByGameAgent($app_id, 0);
- return get_val($_data, 'benefit_type', GameConst::RATE_BENEFIT_NO);
- }
- /**
- * 关联game表
- */
- public function game() {
- return $this->belongsTo('huo\model\game\GameModel', 'app_id')->field('id,name,icon,classify');
- }
- /**
- * 关联user表
- */
- public function user() {
- return $this->belongsTo('huo\model\user\UserModel', 'agent_id')->field('id,user_login,user_nicename,role_id');
- }
- //
- // /**
- // * 根据应用渠道获取一级渠道返点比例
- // *
- // * @param int $app_id 应用ID
- // * @param int $agent_id 渠道ID
- // *
- // *
- // * @return FLOAT
- // */
- // public function getAgentRebateByGameAgent($app_id, $agent_id) {
- // $_data = $this->getInfoByGameAgent($app_id, $agent_id);
- //
- // return get_val($_data, 'agent_rebate', CommonConst::CONST_ZERO);
- // }
- //
- // /**
- // * 根据应用渠道获取 二级渠道返点比例
- // *
- // * @param int $app_id 应用ID
- // * @param int $agent_id 渠道ID
- // *
- // *
- // * @return FLOAT
- // */
- // public function getSubAgentRebateByGameAgent($app_id, $agent_id) {
- // $_data = $this->getInfoByGameAgent($app_id, $agent_id);
- //
- // return get_val($_data, 'sub_agent_rebate', CommonConst::CONST_ZERO);
- // }
- //
- // /**
- // * 根据应用渠道获取 一级渠道分成比例
- // *
- // * @param int $app_id 应用ID
- // * @param int $agent_id 渠道ID
- // *
- // *
- // * @return FLOAT
- // */
- // public function getAgentRateByGameAgent($app_id, $agent_id) {
- // $_data = $this->getInfoByGameAgent($app_id, $agent_id);
- //
- // return get_val($_data, 'agent_rate', CommonConst::CONST_ONE);
- // }
- //
- // /**
- // * 根据应用渠道获取下级渠道分成比例
- // *
- // * @param int $app_id 应用ID
- // * @param int $agent_id 渠道ID
- // *
- // *
- // * @return FLOAT
- // */
- // public function getSubAgentRateByGameAgent($app_id, $agent_id) {
- // $_data = $this->getInfoByGameAgent($app_id, $agent_id);
- //
- // return get_val($_data, 'sub_agent_rate', CommonConst::CONST_ONE);
- // }
- //
- //
- // /**
- // * 根据应用渠道获取 玩家折扣比例
- // *
- // * @param int $app_id 应用ID
- // * @param int $agent_id 渠道ID
- // *
- // *
- // * @return FLOAT
- // */
- // public function getMemRateByGameAgent($app_id, $agent_id) {
- // $_data = $this->getInfoByGameAgent($app_id, $agent_id);
- //
- // return get_val($_data, 'mem_rate', CommonConst::CONST_ZERO);
- // }
- //
- // /**
- // * 根据应用渠道获取 玩家首充折扣比例
- // *
- // * @param int $app_id 应用ID
- // * @param int $agent_id 渠道ID
- // *
- // *
- // * @return FLOAT
- // */
- // public function getFirstMemRateByGameAgent($app_id, $agent_id) {
- // $_data = $this->getInfoByGameAgent($app_id, $agent_id);
- //
- // return get_val($_data, 'first_mem_rate', CommonConst::CONST_ZERO);
- // }
- //
- // /**
- // * 根据应用渠道获取 玩家返利比例
- // *
- // * @param int $app_id 应用ID
- // * @param int $agent_id 渠道ID
- // *
- // *
- // * @return FLOAT
- // */
- // public function getMemRebateByGameAgent($app_id, $agent_id) {
- // $_data = $this->getInfoByGameAgent($app_id, $agent_id);
- //
- // return get_val($_data, 'mem_rebate', CommonConst::CONST_ZERO);
- // }
- //
- // /**
- // * 根据应用渠道获取 玩家首充返利比例
- // *
- // * @param int $app_id 应用ID
- // * @param int $agent_id 渠道ID
- // *
- // *
- // * @return FLOAT
- // */
- // public function getFirstMemRebateByGameAgent($app_id, $agent_id) {
- // $_data = $this->getInfoByGameAgent($app_id, $agent_id);
- //
- // return get_val($_data, 'first_mem_rebate', CommonConst::CONST_ZERO);
- // }
- //
- // /**
- // * 根据应用渠道获取渠道奖励
- // *
- // * @param int $app_id 应用ID
- // * @param int $agent_id 渠道ID
- // *
- // *
- // * @return int CPA计价
- // */
- // public function getAgentRewardByGameAgent($app_id, $agent_id) {
- // $_data = $this->getInfoByGameAgent($app_id, $agent_id);
- //
- // return get_val($_data, 'agent_reward', 0);
- // }
- //
- // /**
- // * 根据应用渠道获取玩家奖励
- // *
- // * @param int $app_id 应用ID
- // * @param int $agent_id 渠道ID
- // *
- // *
- // * @return int CPA计价
- // */
- // public function getMemRewardByGameAgent($app_id, $agent_id) {
- // $_data = $this->getInfoByGameAgent($app_id, $agent_id);
- //
- // return get_val($_data, 'mem_reward', 0);
- // }
- }
|