1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace app\common\model;
- use app\admin\model\Admin;
- use think\Model;
- /**
- */
- class Ad extends Model
- {
- // 表名
- protected $table = 'ad';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- // 定义时间戳字段名
- protected $createTime = 'created_at';
- protected $updateTime = 'updated_at';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- ];
- public static $pos=[
- 'index'=>'首页',
- ];
- protected $readonly=['upload_admin_id'];
-
- public static function getAd($pos=null,$chanId=null){
- $q=self::order('sort','desc');
- if($pos){
- $q->where('pos',$pos);
- }
- if($chanId){
- $q->where('is_sub',1)->where('admin_id',$chanId);
- }else{
- $q->where('is_sub',0);
- }
- return $q->select();
- }
- protected static function init()
- {
- self::beforeInsert(function (self $ad){
- $ad['upload_admin_id']=$_SERVER['admin']['id'];
- $ad['is_sub']=Admin::get($ad['admin_id'])['is_sub']?1:0;
- });
- }
- }
|