ComplexChannel.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace app\common\model;
  3. use think\Cache;
  4. use think\Db;
  5. /**
  6. * 渠道表
  7. * @author Administrator
  8. */
  9. class ComplexChannel extends \think\Model
  10. {
  11. protected $pk = 'id';
  12. protected $table = 'nw_complex_channel';
  13. const CACHE_KEY_MARK_INFO = "complex_channel_mark_info:";
  14. protected static function init()
  15. {
  16. Channel::afterInsert(function () {
  17. Cache::clear('complex_channel_cache');
  18. });
  19. Channel::afterUpdate(function () {
  20. Cache::clear('complex_channel_cache');
  21. });
  22. Channel::afterWrite(function () {
  23. Cache::clear('complex_channel_cache');
  24. });
  25. }
  26. /**
  27. * 根据 渠道标识 获取聚合渠道数据
  28. *
  29. * @param $mark
  30. *
  31. * @return array|bool|\PDOStatement|string|\think\Model|null
  32. * @throws \think\db\exception\DataNotFoundException
  33. * @throws \think\db\exception\ModelNotFoundException
  34. * @throws \think\exception\DbException
  35. */
  36. public function getCacheInfoByMark($mark){
  37. return $this->where('mark', $mark)->cache(self::CACHE_KEY_MARK_INFO.$mark, 30)->field('id,name,mark,status')->find();
  38. }
  39. }