SystemAttachment.php 3.1 KB

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