文件
mashangyoujiu/Application/Common/Business/Image.class.php

110 行
2.9 KiB
PHP
可执行文件

<?php
namespace Common\Business;
use Common\Model\GoodsDefaultImgModel;
use Common\Model\ImageGalleryModel;
use Common\Model\RetailGoodsModel;
use Common\Model\RetailMgoodsModel;
use Common\Model\RetailSkuGoodsModel;
use Common\Model\SkuMGoodsModel;
//[1.7.90]
/**
* 图片类
* Class Image
* [
* 根据商品id 规格id 查询商品图片 basisGoodsIdGetImg
* 当前网站url的链接(不包含文件路径) imageUrlTitle
* 商品图片路径 getGoodsImageUrl
* ]
* @package Common\Business
*/
class Image
{
/**
* 根据商品id获取图片
* @param $param
* [
* user_type 3商户 4门店
* goods_id
* sku_id
* ]
* @return mixed
*/
public function basisGoodsIdGetImg($param)
{
switch ($param['user_type']){
case 3:
$GoodsModel = new RetailMgoodsModel();
$SkuGoodsModel = new SkuMGoodsModel();
$fields = 'goods_image_id';
break;
case 4:
$GoodsModel = new RetailGoodsModel();
$SkuGoodsModel = new RetailSkuGoodsModel();
$fields = 'goods_img_id';
break;
}
if(!empty($param['sku_id'])){
$img_id = $SkuGoodsModel->getFindField([
'id'=>$param['sku_id']
],'goods_img_id');
}else if(!empty($param['goods_id'])){
$img_id = $GoodsModel->getFindField([
'id'=>$param['goods_id']
],$fields);
}
$path = $this->getGoodsImageUrl([
'img_id'=>$img_id
]);
return $path;
}
/**
* 商品图片路径
* @param $param
* [
* img_id 图片id
* img_url 本地图片路径
* store_id 门店id
* ]
* @return bool|mixed|string
*/
public function getGoodsImageUrl($param)
{
$img_id = $param['img_id'];
$img_url = $param['img_url']?$param['img_url']:'';
$store_id = $param['store_id'];
$urlTitle = $this->imageUrlTitle();
$ImageGalleryModel = new ImageGalleryModel();
$GoodsDefaultImgModel = new GoodsDefaultImgModel();
if (!empty($img_id)) {
$img_url = $ImageGalleryModel->getFieldPath(array('id' => $img_id));
if (!$img_url) {
$img_url = $GoodsDefaultImgModel->getDefaultImg($store_id);
}
} else {
if (!empty($imgUrl) && $img_url != '/Uploads') { // 处理图片
$img_url = $urlTitle . $img_url;
} else {
$img_url = $GoodsDefaultImgModel->getDefaultImg($store_id);
}
}
return $img_url;
}
/**
* 当前网站url的链接(不包含文件路径)
* @return string
*/
public function imageUrlTitle()
{
$title = 'http';
if ($_SERVER['HTTPS'] == 'on') {
$title .= 's';
}
return $title . '://' . $_SERVER['HTTP_HOST'];
}
}