Kefu.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/10/31
  6. * Time: 16:56
  7. */
  8. namespace app\common\model;
  9. use think\Cache;
  10. use think\Model;
  11. use think\Config;
  12. class Kefu extends Model
  13. {
  14. protected $pk = 'id';
  15. protected $table = 'cy_kefu';
  16. const CACHE_KEY = "kefu:getKefuList";
  17. protected static function init()
  18. {
  19. Kefu::afterInsert(function () {
  20. Cache::rm(self::CACHE_KEY);
  21. });
  22. Kefu::afterUpdate(function () {
  23. Cache::rm(self::CACHE_KEY);
  24. });
  25. Kefu::afterWrite(function () {
  26. Cache::rm(self::CACHE_KEY);
  27. });
  28. }
  29. /*
  30. *获取列表内容
  31. */
  32. public function getList()
  33. {
  34. return $this->field('id,qq,nickname,game_id')->where(['channel_id' => 0, 'type' => 1])->paginate();
  35. }
  36. public function getKefuList()
  37. {
  38. // ->cache(self::CACHE_KEY, Config::get('QUERY_RESULT_CACHE_TIME'))
  39. return $this->where(['channel_id' => 0, 'type' => 1])->field('id,qq,nickname,"周一至周五 09-18点" as time')->select();
  40. }
  41. // 根据游戏ID查询带有缓存的数据
  42. public function getKefuByGameId($where = [])
  43. {
  44. // $cacheName = self::CACHE_KEY;
  45. // if(!empty($where['game_id'])){
  46. // $cacheName .= ":".$where['game_id'];
  47. // }
  48. // ->cache($cacheName, Config::get('QUERY_RESULT_CACHE_TIME'))
  49. return $this->where(['channel_id' => 0, 'type' => 1])->where($where)->field('id,qq,nickname,"周一至周五 09-18点" as time')->select();
  50. }
  51. }