123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- 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;
-
- 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;
- }
-
- 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;
- }
-
- 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;
- }
-
- 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;
- }
-
- public function getCacheKeyByAgentId($agent_id) {
- return $this->cache_key_prefix.$agent_id;
- }
- }
|