Ad.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. ];
  23. protected $readonly=['upload_admin_id'];
  24. public static function getAd($pos=null,$chanId=null){
  25. $q=self::order('sort','desc');
  26. if($pos){
  27. $q->where('pos',$pos);
  28. }
  29. if($chanId){
  30. $q->where('is_sub',1)->where('admin_id',$chanId);
  31. }else{
  32. $q->where('is_sub',0);
  33. }
  34. return $q->select();
  35. }
  36. protected static function init()
  37. {
  38. self::beforeInsert(function (self $ad){
  39. $ad['upload_admin_id']=$_SERVER['admin']['id'];
  40. $ad['is_sub']=Admin::get($ad['admin_id'])['is_sub']?1:0;
  41. });
  42. }
  43. }