SystemAttachment.php 3.6 KB

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