Channel.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\api\model;
  3. use think\Model;
  4. class Channel extends BaseModel
  5. {
  6. // 表名
  7. protected $name = 'channel';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. ];
  17. public function admin()
  18. {
  19. return $this->belongsTo('Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
  20. }
  21. public static function increase($id = null, $key = null, $field = null)
  22. {
  23. if ($id) {
  24. return self::where("id", $id)
  25. ->where("starttime", "<=", time())
  26. ->where("endtime", ">=", time())
  27. ->setInc($field);
  28. }
  29. if ($key) {
  30. return self::where("key", $key)
  31. ->where("starttime", "<=", time())
  32. ->where("endtime", ">=", time())
  33. ->setInc($field);
  34. }
  35. return false;
  36. }
  37. public static function getChannel($id = null, $key = null)
  38. {
  39. if ($id) {
  40. return self::where("id", $id)
  41. ->where("starttime", "<=", time())
  42. ->where("endtime", ">=", time())
  43. ->find();
  44. }
  45. if ($key) {
  46. return self::where("key", $key)
  47. ->where("starttime", "<=", time())
  48. ->where("endtime", ">=", time())
  49. ->find();
  50. }
  51. return null;
  52. }
  53. }