Ad.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\common\model;
  3. use app\admin\model\Admin;
  4. use think\Model;
  5. /**
  6. */
  7. class Ad extends Model
  8. {
  9. // 表名
  10. protected $table = 'ad';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = true;
  13. // 定义时间戳字段名
  14. protected $createTime = 'created_at';
  15. protected $updateTime = 'updated_at';
  16. protected $deleteTime = false;
  17. // 追加属性
  18. protected $append = [
  19. ];
  20. public static $pos=[
  21. 'index'=>[
  22. 'name'=>'首页轮播',
  23. 'pos'=>'index_top',
  24. ],
  25. 'index_middle'=>[
  26. 'name'=>'首页中间位置',
  27. 'pos'=>'index_middle',
  28. ],
  29. ];
  30. protected $readonly=[];
  31. public static function getAd($pos=null){
  32. $q=self::order('sort','desc');
  33. if($pos){
  34. $q->where('pos',$pos);
  35. }
  36. return $q->select();
  37. }
  38. protected static function init()
  39. {
  40. self::beforeInsert(function (self $ad){
  41. $ad['admin_id']=$_SERVER['admin']['id'];
  42. });
  43. }
  44. /**
  45. * @return string[]
  46. */
  47. public static function getPos(): array
  48. {
  49. return self::$pos;
  50. }
  51. }