| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace app\api\model;
- use think\Model;
- class Channel extends BaseModel
- {
- // 表名
- protected $name = 'channel';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- ];
- public function admin()
- {
- return $this->belongsTo('Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public static function increase($id = null, $key = null, $field = null)
- {
- if ($id) {
- return self::where("id", $id)
- ->where("starttime", "<=", time())
- ->where("endtime", ">=", time())
- ->setInc($field);
- }
- if ($key) {
- return self::where("key", $key)
- ->where("starttime", "<=", time())
- ->where("endtime", ">=", time())
- ->setInc($field);
- }
- return false;
- }
- public static function getChannel($id = null, $key = null)
- {
- if ($id) {
- return self::where("id", $id)
- ->where("starttime", "<=", time())
- ->where("endtime", ">=", time())
- ->find();
- }
- if ($key) {
- return self::where("key", $key)
- ->where("starttime", "<=", time())
- ->where("endtime", ">=", time())
- ->find();
- }
- return null;
- }
- }
|