SystemAttachment.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /**
  3. * @author: xaboy<365615158@qq.com>
  4. * @day: 2017/11/13
  5. */
  6. namespace app\admin\model\system;
  7. use crmeb\traits\ModelTrait;
  8. use crmeb\basic\BaseModel;
  9. /**
  10. * 文件检验model
  11. * Class SystemFile
  12. * @package app\admin\model\system
  13. */
  14. class SystemAttachment extends BaseModel
  15. {
  16. /**
  17. * 数据表主键
  18. * @var string
  19. */
  20. protected $pk = 'att_id';
  21. /**
  22. * 模型名称
  23. * @var string
  24. */
  25. protected $name = 'system_attachment';
  26. use ModelTrait;
  27. /**
  28. * TODO 添加附件记录
  29. * @param $name
  30. * @param $att_size
  31. * @param $att_type
  32. * @param $att_dir
  33. * @param string $satt_dir
  34. * @param int $pid
  35. * @param int $imageType
  36. * @param int $time
  37. * @return SystemAttachment
  38. */
  39. public static function attachmentAdd($name,$att_size,$att_type,$att_dir,$satt_dir='',$pid = 0,$imageType = 1 ,$time = 0 , $module_type=1)
  40. {
  41. $data['name'] = $name;
  42. $data['att_dir'] = $att_dir;
  43. $data['satt_dir'] = $satt_dir;
  44. $data['att_size'] = $att_size;
  45. $data['att_type'] = $att_type;
  46. $data['image_type'] = $imageType;
  47. $data['module_type'] = $module_type;
  48. $data['time'] = $time ? $time : time();
  49. $data['pid'] = $pid;
  50. return self::create($data);
  51. }
  52. /**
  53. * TODO 获取分类图
  54. * @param $id
  55. * @return array
  56. */
  57. public static function getAll($id){
  58. $model = new self;
  59. $where['pid'] = $id;
  60. $where['module_type'] = 1;
  61. $model->where($where)->order('att_id desc');
  62. return $model->page($model,$where,'',24);
  63. }
  64. /** 获取图片列表
  65. * @param $where
  66. * @return array
  67. */
  68. public static function getImageList($where)
  69. {
  70. $model = new self;
  71. $model = $model->where('module_type', 1);
  72. if(isset($where['pid']) && $where['pid']) $model = $model->where('pid', $where['pid']);
  73. $model = $model->page((int)$where['page'],(int)$where['limit']);
  74. $model = $model->order('att_id desc,time desc');
  75. $list = $model->select();
  76. $list = count($list) ? $list->toArray() : [];
  77. $site_url = SystemConfig::getConfigValue('site_url');
  78. foreach ($list as &$item){
  79. if($site_url) {
  80. $item['satt_dir'] = (strpos($item['satt_dir'], $site_url) !== false || strstr($item['satt_dir'], 'http') !== false) ? $item['satt_dir'] : $site_url . $item['satt_dir'];
  81. $item['att_dir'] = (strpos($item['att_dir'], $site_url) !== false || strstr($item['att_dir'], 'http') !== false) ? $item['satt_dir'] : $site_url . $item['att_dir'];
  82. }
  83. }
  84. $count = self::where(['pid'=>$where['pid'],'module_type'=>1])->count();
  85. return compact('list','count');
  86. }
  87. /**
  88. * TODO 获取单条信息
  89. * @param $value
  90. * @param string $field
  91. * @return array
  92. * @throws \think\Exception
  93. * @throws \think\db\exception\DataNotFoundException
  94. * @throws \think\db\exception\ModelNotFoundException
  95. * @throws \think\exception\DbException
  96. */
  97. public static function getInfo($value,$field = 'att_id'){
  98. $where[$field] = $value;
  99. $count = self::where($where)->count();
  100. if(!$count) return false;
  101. return self::where($where)->find()->toArray();
  102. }
  103. /**
  104. * 清除昨日海报
  105. * @return bool
  106. * @throws \Exception
  107. */
  108. public static function emptyYesterdayAttachment()
  109. {
  110. return self::whereTime('time','yesterday')->where(['module_type'=>2])->delete();
  111. }
  112. }