You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
zhishifufei_php/application/merchant/model/system/SystemAttachment.php

106 lines
3.6 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\merchant\model\system;
use traits\ModelTrait;
use basic\ModelBasic;
use app\admin\model\system\SystemConfig;
/**
* 文件检验model
* Class SystemAttachment
* @package app\merchant\model\system
*/
class SystemAttachment extends ModelBasic
{
use ModelTrait;
/**添加附件记录
*/
public static function attachmentAdd($mer_id, $name, $title, $att_size, $att_type, $att_dir, $satt_dir = '', $pid = 0)
{
$data['mer_id'] = $mer_id;
$data['name'] = $name;
$data['title'] = $title == '' ? $name : $title;
$data['att_dir'] = $att_dir;
$data['satt_dir'] = $satt_dir;
$data['att_size'] = $att_size;
$data['att_type'] = $att_type;
$data['time'] = time();
$data['pid'] = $pid;
return self::create($data);
}
/**编辑修改图片名称
* @param $data
* @return SystemAttachment|bool
*/
public static function attachmentTitle($data)
{
if (self::be(['att_id' => $data['att_id']])) {
return self::where(['att_id' => $data['att_id']])->update(['title' => $data['title']]);
} else {
return false;
}
}
public static function setWhere($where)
{
$model = self::order('att_id desc,time desc');
if (isset($where['pid']) && $where['pid']) $model = $model->where('pid', $where['pid']);
if (isset($where['mer_id']) && $where['mer_id']) $model = $model->where('mer_id', $where['mer_id']);
if ($where['title'] != '') $model = $model->where('title|name', 'like', "%$where[title]%");
return $model;
}
/** 获取图片列表
* @param $where
* @return array
*/
public static function getImageList($where)
{
$list = self::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
$list = count($list) ? $list->toArray() : [];
$site_url = SystemConfig::getValue('site_url');
foreach ($list as &$item) {
if ($site_url) {
$item['satt_dir'] = (strpos($item['satt_dir'], $site_url) !== false || strstr($item['satt_dir'], 'http') !== false) ? $item['satt_dir'] : $site_url . $item['satt_dir'];
$item['att_dir'] = (strpos($item['att_dir'], $site_url) !== false || strstr($item['att_dir'], 'http') !== false) ? $item['satt_dir'] : $site_url . $item['att_dir'];
}
}
$count = self::setWhere($where)->count();
return compact('list', 'count');
}
/**
* 获取分类图
* */
public static function getAll($id)
{
$model = new self;
$where['pid'] = $id;
$model->where($where)->order('att_id desc');
return $model->page($model, $where, '', 30);
}
/**
* 获取单条信息
* */
public static function getinfo($att_id)
{
$model = new self;
$where['att_id'] = $att_id;
return $model->where($where)->select()->toArray()[0];
}
}