292 行
9.5 KiB
PHP
可执行文件
292 行
9.5 KiB
PHP
可执行文件
<?php
|
|
|
|
namespace Common\Model;
|
|
|
|
use Think\Model;
|
|
|
|
//[1.8.50]
|
|
|
|
/**
|
|
* 图库模型
|
|
* Class ImageGalleryModel
|
|
* @package Common\Model
|
|
*/
|
|
class ImageGalleryModel extends Model
|
|
{
|
|
protected $tableName = 'image_gallery';
|
|
protected $fields = array(
|
|
'id', // bigint(19) NOT NULL AUTO_INCREMENT,
|
|
'agent_id', // int(11) DEFAULT '0',
|
|
'merchant_id', // int(11) DEFAULT '0',
|
|
'store_id', // int(11) DEFAULT '0',
|
|
'guide_id', // int(11) DEFAULT '0' COMMENT '导购员id',
|
|
'path', // varchar(255) DEFAULT NULL COMMENT '图片预览路径',
|
|
'add_time', // varchar(20) DEFAULT NULL,
|
|
'storage_type', // tinyint(1) DEFAULT '1' COMMENT '1本地 2七牛云 3腾讯云 4阿里云',
|
|
'source_type', // tinyint(1) DEFAULT '1' COMMENT '1普通上传的图片 2百度编辑器上传的图片',
|
|
'catalog', // varchar(255) DEFAULT NULL COMMENT '目录',
|
|
'name', // varchar(100) DEFAULT NULL COMMENT '图片名称',
|
|
'original_name',// varchar(255) DEFAULT NULL COMMENT '图片原名',
|
|
'size', // varchar(20) DEFAULT '0' COMMENT '文件大小',
|
|
'from_type_id', // tinyint(3) DEFAULT '0' COMMENT '0合伙人图库上传 1公司环境 2公司简介 3新闻中心 4产品中心 5banner管理 6logo设置 7收银logo 8百度编辑器 9合伙人头像',
|
|
'from_name', // varchar(50) DEFAULT NULL COMMENT '0合伙人图库上传 1公司环境 2公司简介 3新闻中心 4产品中心 5banner管理 6logo设置 7收银logo',
|
|
'user_type', // tinyint(1) DEFAULT '1' COMMENT '1合伙人 2代理商 3商户 4门店 5导购员',
|
|
'type', // tinyint(1) DEFAULT '1' COMMENT '1图片 2视频',
|
|
'user_id', // int(11) DEFAULT '0' COMMENT '上传图片的用户id',
|
|
);
|
|
|
|
public function addOrder($arr)
|
|
{
|
|
if (!$arr['path']) {
|
|
return false;
|
|
}
|
|
if (isset($arr['source_type']) && $arr['source_type'] == 2) {
|
|
if (session('admin_userinfo')) {
|
|
$arr['user_type'] = 1;
|
|
$arr['from_type_id'] = 13;
|
|
} else if (session('agent_userinfo')) {
|
|
$arr['user_type'] = 2;
|
|
} else if (session('guide_userinfo')) {
|
|
//导购员
|
|
$arr['user_type'] = 5;
|
|
} else if (session('ls_userinfo')) {
|
|
$arr['merchant_id'] = session('ls_userinfo')['merchantid'];
|
|
if (session('ls_userinfo')['account_type'] == 1) {
|
|
$arr['user_type'] = 3;
|
|
$arr['from_type_id'] = 17;
|
|
} else {
|
|
$arr['user_type'] = 4;
|
|
$arr['from_type_id'] = 27;
|
|
$arr['store_id'] = session('storeid');
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
$add = array(
|
|
'agent_id' => !empty($arr['agent_id']) ? $arr['agent_id'] : 0,
|
|
'merchant_id' => !empty($arr['merchant_id']) ? $arr['merchant_id'] : 0,
|
|
'store_id' => !empty($arr['store_id']) ? $arr['store_id'] : 0,
|
|
'guide_id' => !empty($arr['guide_id']) ? $arr['guide_id'] : 0,
|
|
'path' => $arr['path'],
|
|
'add_time' => isset($arr['add_time']) ? $arr['add_time'] : time(),
|
|
'storage_type' => !empty($arr['storage_type']) ? $arr['storage_type'] : 1,
|
|
'source_type' => !empty($arr['source_type']) ? $arr['source_type'] : 1,
|
|
'name' => isset($arr['name']) ? $arr['name'] : '',
|
|
'original_name' => isset($arr['original_name']) ? $arr['original_name'] : '',
|
|
'size' => isset($arr['size']) ? $arr['size'] : 0,
|
|
'from_type_id' => !empty($arr['from_type_id']) ? $arr['from_type_id'] : 0,
|
|
'user_type' => !empty($arr['user_type']) ? $arr['user_type'] : 1,
|
|
'catalog' => isset($arr['catalog']) ? $arr['catalog'] : '',
|
|
'type' => !empty($arr['type']) ? $arr['type'] : 1,
|
|
'user_id' => !empty($arr['user_id']) ? $arr['user_id'] : 0,
|
|
);
|
|
// print_r($add);
|
|
// if ($add['from_type_id']) {
|
|
$res = $this->add($add);
|
|
return $res;
|
|
// } else {
|
|
// return false;
|
|
// }
|
|
}
|
|
|
|
/**
|
|
* 查询
|
|
* @param $map
|
|
* @return mixed
|
|
*/
|
|
public function getFind($map)
|
|
{
|
|
$res = $this->where($map)->find();
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 查询某个字段
|
|
* @param string $map
|
|
* @param null $field
|
|
* @return mixed
|
|
*/
|
|
public function getOneField($map, $field)
|
|
{
|
|
if ($field == 'path') {
|
|
$res = $this->getFieldPath($map);
|
|
} else {
|
|
$res = $this->where($map)->getField($field);
|
|
}
|
|
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 获取图片
|
|
* @param $map
|
|
* @return bool|string
|
|
*/
|
|
public function getFieldPath($map)
|
|
{
|
|
$img = $this->where($map)->find();
|
|
if ($img) {
|
|
if ($img['storage_type'] == 1) {
|
|
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
|
|
$res = $http_type . $_SERVER['HTTP_HOST'] . $img['path'];
|
|
} else {
|
|
$res = $img['path'];
|
|
}
|
|
} else {
|
|
$res = '';
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
public function getFieldInfo($map)
|
|
{
|
|
$img = $this->where($map)->find();
|
|
if ($img) {
|
|
if ($img['storage_type'] == 1) {
|
|
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
|
|
$res['path'] = $http_type . $_SERVER['HTTP_HOST'] . $img['path'];
|
|
} else {
|
|
$res['path'] = $img['path'];
|
|
}
|
|
$res['type'] = $img['type'];
|
|
} else {
|
|
$res = false;
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 获取图片
|
|
* @param $map
|
|
* @return bool|string
|
|
*/
|
|
public function getImgPath($map)
|
|
{
|
|
$img = $this->where($map)->find();
|
|
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
|
|
if ($img) {
|
|
if ($img['storage_type'] == 1) {
|
|
$res = $http_type . $_SERVER['HTTP_HOST'] . $img['path'];
|
|
} else {
|
|
$res = $img['path'];
|
|
}
|
|
} else {
|
|
$res = $http_type . $_SERVER['HTTP_HOST'] . '/Public/Retail/goods/default.png';
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 获取图片
|
|
* @param $id
|
|
* @return bool|string
|
|
*/
|
|
public function getImagePath($id)
|
|
{
|
|
$img = $this->where(array('id' => $id))->find();
|
|
if ($img) {
|
|
if ($img['storage_type'] == 1) {
|
|
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
|
|
$res = $http_type . $_SERVER['HTTP_HOST'] . $img['path'];
|
|
} else {
|
|
$res = $img['path'];
|
|
}
|
|
} else {
|
|
$res = '';
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 查询
|
|
* @param $map
|
|
* @param $field
|
|
* @param $order
|
|
* @param $page
|
|
* @param $limit
|
|
* @return mixed
|
|
*/
|
|
public function getSelect($map, $field = '*', $order = 'id desc', $page = '', $limit = '')
|
|
{
|
|
if (!$field) {
|
|
$field = '*';
|
|
}
|
|
if (!$order) {
|
|
$order = 'id asc';
|
|
}
|
|
if ($page && $limit) {
|
|
$res = $this->where($map)->page($page, $limit)->order($order)->field($field)->select();
|
|
} else {
|
|
$res = $this->where($map)->field($field)->select();
|
|
}
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 获取数量
|
|
* @param $map
|
|
* @return mixed
|
|
*/
|
|
public function getCount($map)
|
|
{
|
|
$res = $this->where($map)->count();
|
|
return intval($res);
|
|
}
|
|
|
|
public function doDelete($map)
|
|
{
|
|
if ($map) {
|
|
$res = $this->where($map)->delete();
|
|
return $res;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取某字段
|
|
* @param $map
|
|
* @param string $fields
|
|
* @param $bol //true为获取多条
|
|
* @return mixed
|
|
*/
|
|
public function getFindField($map, $fields = 'id', $bol = false)
|
|
{
|
|
$res = $this->where($map)->getField($fields, $bol);
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 更新数据
|
|
* @param $map
|
|
* @param $save
|
|
* @return mixed
|
|
*/
|
|
public function updateData($map, $save)
|
|
{
|
|
$res = $this->where($map)->save($save);
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 获取多图
|
|
* @param $img_id 图片ID字符','串拼接
|
|
* @return array
|
|
*/
|
|
public function getImageArray($img_id)
|
|
{
|
|
$img_url = array();
|
|
$empty_img = getServerUrl() . '/Public/images/empty-image.png';
|
|
if (!empty($img_id)) {
|
|
$img_id_arr = explode(',', $img_id);
|
|
foreach ($img_id_arr as $key => $value) {
|
|
$img = $this->getFieldPath(array('id' => $value));
|
|
$img_url[] = $img ? $img : $empty_img;
|
|
}
|
|
}
|
|
return $img_url;
|
|
}
|
|
|
|
|
|
} |