1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?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'=>[
- 'name'=>'首页轮播',
- 'pos'=>'index_top',
- ],
- 'index_middle'=>[
- 'name'=>'首页中间位置',
- 'pos'=>'index_middle',
- ],
- ];
- protected $readonly=[];
-
- public static function getAd($pos=null){
- $q=self::order('sort','desc');
- if($pos){
- $q->where('pos',$pos);
- }
- return $q->select();
- }
- protected static function init()
- {
- self::beforeInsert(function (self $ad){
- $ad['admin_id']=$_SERVER['admin']['id'];
- });
- }
- /**
- * @return string[]
- */
- public static function getPos(): array
- {
- return self::$pos;
- }
- }
|