123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- /**
- * AgentAdsCfgModel.php UTF-8
- * 渠道二维码倒量配置
- *
- * @date : 2019/3/21 21:20
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : chenbingling <cbl@huosdk.com>
- * @version : HuoMp 1.0
- */
- namespace huomp\model\agent;
- use huolib\constant\CacheConst;
- use huomp\model\common\CommonModel;
- use think\Cache;
- class AgentAdsCfgModel extends CommonModel {
- protected $name = 'agent_ads_cfg';
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- protected $cache_key_prefix = CacheConst::CACHE_AGENT_ADS_CFG_PREFIX;
- /**
- * 添加数据
- *
- * @param $data
- *
- * @return bool
- */
- public function addData($data) {
- if (empty($data) || empty($data['agent_id'])) {
- return false;
- }
- $_data = $data;
- $_obj = self::create($_data, true);
- if ($_obj) {
- return true;
- }
- return false;
- }
- /**
- * 更新数据
- *
- * @param array $data 数据
- * @param int $id 应用ID
- *
- * @return bool
- */
- public function updateData($data, $id) {
- $_old_data = $this->getInfoById($id);
- $_map['id'] = $id;
- $_data = $data;
- $_rs = $this->allowField(true)->isUpdate(true)->save($_data, $_map);
- if (false === $_rs) {
- return false;
- }
- $_cache_key = $this->getCacheKeyByAgentId($_old_data['agent_id']);
- Cache::rm($_cache_key);
- return true;
- }
- /***
- * 获取数据
- *
- * @param $agent_id
- *
- * @return mixed
- */
- public function getInfoByAgentId($agent_id) {
- $_cache_key = $this->getCacheKeyByAgentId($agent_id);
- $_data = Cache::get($_cache_key);
- if (!empty($_data)) {
- return $_data;
- }
- $_map = ['agent_id' => $agent_id];
- $_data = $this->where($_map)->find();
- if (is_object($_data)) {
- $_data = $_data->toArray();
- }
- if (!empty($_data)) {
- Cache::set($_cache_key, $_data);
- }
- return $_data;
- }
- /**
- * 删除数据
- *
- * @param $id
- *
- * @return bool
- */
- public function deleteData($id) {
- $_old_data = $this->getInfoById($id);
- $_map['id'] = $id;
- $_rs = $this->where($_map)->delete();
- if (false == $_rs) {
- return false;
- }
- $_cache_key = $this->getCacheKeyByAgentId($_old_data['agent_id']);
- Cache::rm($_cache_key);
- return true;
- }
- /**
- * 获取缓存key
- *
- * @param $agent_id
- *
- * @return string
- */
- public function getCacheKeyByAgentId($agent_id) {
- return $this->cache_key_prefix.$agent_id;
- }
- }
|