SystemAttachment.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\system;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. /**
  15. * 文件检验model
  16. * Class SystemFile
  17. * @package app\admin\model\system
  18. */
  19. class SystemAttachment extends ModelBasic
  20. {
  21. use ModelTrait;
  22. /**添加附件记录
  23. */
  24. public static function attachmentAdd($name, $att_size, $att_type, $att_dir, $satt_dir = '', $pid = 0)
  25. {
  26. $data['name'] = $name;
  27. $data['att_dir'] = $att_dir;
  28. $data['satt_dir'] = $satt_dir;
  29. $data['att_size'] = $att_size;
  30. $data['att_type'] = $att_type;
  31. $data['time'] = time();
  32. $data['pid'] = $pid;
  33. return self::create($data);
  34. }
  35. /** 获取图片列表
  36. * @param $where
  37. * @return array
  38. */
  39. public static function getImageList($where)
  40. {
  41. $model = new self;
  42. if (isset($where['pid']) && $where['pid']) $model = $model->where('pid', $where['pid']);
  43. $model = $model->page((int)$where['page'], (int)$where['limit']);
  44. $model = $model->order('att_id desc,time desc');
  45. $list = $model->select();
  46. $list = count($list) ? $list->toArray() : [];
  47. $site_url = SystemConfig::getValue('site_url');
  48. foreach ($list as &$item) {
  49. if ($site_url) {
  50. $item['satt_dir'] = (strpos($item['satt_dir'], $site_url) !== false || strstr($item['satt_dir'], 'http') !== false) ? $item['satt_dir'] : $site_url . $item['satt_dir'];
  51. $item['att_dir'] = (strpos($item['att_dir'], $site_url) !== false || strstr($item['att_dir'], 'http') !== false) ? $item['satt_dir'] : $site_url . $item['att_dir'];
  52. }
  53. }
  54. $count = isset($where['pid']) && $where['pid'] ? self::where(['pid' => $where['pid']])->count() : self::count();
  55. return compact('list', 'count');
  56. }
  57. /**
  58. * 获取分类图
  59. * */
  60. public static function getAll($id)
  61. {
  62. $model = new self;
  63. $where['pid'] = $id;
  64. $model->where($where)->order('att_id desc');
  65. return $model->page($model, $where, '', 30);
  66. }
  67. /**
  68. * 获取单条信息
  69. * */
  70. public static function getinfo($att_id)
  71. {
  72. $model = new self;
  73. $where['att_id'] = $att_id;
  74. return $model->where($where)->select()->toArray()[0];
  75. }
  76. }