标签:
<?php /** * 商品图片统一调用函数 v3-b12 * * * * @package function* www.haoid.cn 专业团队 提供售后服务 */ defined(‘InShopNC‘) or exit(‘Access Invalid!‘); // 七牛外链域名 define(‘QINIU_DOMAIN‘,‘http://pic.121mai.com‘); // 引入七牛sdk require_once __DIR__.‘/../../../data/api/php-sdk-master/autoload.php‘; // 引入鉴权类 use Qiniu\Auth; // 引入资源管理类 use Qiniu\Storage\BucketManager; use Qiniu\Storage\UploadManager; /** * 取得商品缩略图的完整URL路径,接收商品信息数组,返回所需的商品缩略图的完整URL * * @param array $goods 商品信息数组 * @param string $type 缩略图类型 值为60,240,360,1280 * @return string */ //未经加工过的thumb function thumb_raw($goods = array(), $type = ‘‘){ $type_array = explode(‘,_‘, ltrim(GOODS_IMAGES_EXT, ‘_‘)); if (!in_array($type, $type_array)) { $type = ‘240‘; } if (empty($goods)){ return UPLOAD_SITE_URL.‘/‘.defaultGoodsImage($type); } if (array_key_exists(‘apic_cover‘, $goods)) { $goods[‘goods_image‘] = $goods[‘apic_cover‘]; } if (empty($goods[‘goods_image‘])) { return UPLOAD_SITE_URL.‘/‘.defaultGoodsImage($type); } $search_array = explode(‘,‘, GOODS_IMAGES_EXT); $file = str_ireplace($search_array,‘‘,$goods[‘goods_image‘]); $fname = basename($file); //取店铺ID if (preg_match(‘/^(\d+_)/‘,$fname)){ $store_id = substr($fname,0,strpos($fname,‘_‘)); }else{ $store_id = $goods[‘store_id‘]; } $file = $type == ‘‘ ? $file : str_ireplace(‘.‘, ‘_‘ . $type . ‘.‘, $file); if (!file_exists(BASE_UPLOAD_PATH.‘/‘.ATTACH_GOODS.‘/‘.$store_id.‘/‘.$file)){ return UPLOAD_SITE_URL.‘/‘.defaultGoodsImage($type); } $thumb_host = UPLOAD_SITE_URL.‘/‘.ATTACH_GOODS; return $thumb_host.‘/‘.$store_id.‘/‘.$file; } // 七牛上传图片处理 function new_upload($filePath,$newfile){ // 需要填写你的 Access Key 和 Secret Key $accessKey = ‘O9fT4BHnNJgTVlccVCPhcVZsxPQhYE3JEmVT2RR2‘; $secretKey = ‘pgbAMset23cJTKLbnCBfIW_T1rLRWKOQ7kuvIyFo‘; // 构建鉴权对象 $auth = new Auth($accessKey, $secretKey); // 要上传的空间 $bucket = ‘mall‘; // 生成上传 Token $token = $auth->uploadToken($bucket); // 初始化 UploadManager 对象并进行文件的上传 $uploadMgr = new UploadManager(); // 上传到七牛后保存的文件名 $key = $newfile;//$filePath 要上传文件的本地路径 //图片是否存在 if(!empty($filePath) && file_exists($filePath)){ // 调用 UploadManager 的 putFile 方法进行文件的上传 list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath); if ($err !== null) { return 0; // 上传失败 } else { // var_dump($ret); return QINIU_DOMAIN . ‘/‘.$ret[‘key‘]; // 上传成功 } }else if(!file_exists($filePath)){ $not="图片:{$key} 不存在"; return 0; } } /** * 取得商品缩略图的七牛完整URL路径,接收商品信息数组,返回所需的商品缩略图的七牛完整URL * * @param array $goods 商品信息数组 * @param string $type 缩略图类型 值为60,240,360,1280 * @return string */ //加工后的thumb function thumb($goods = array(), $type = ‘‘){ $type_array = explode(‘,_‘, ltrim(GOODS_IMAGES_EXT, ‘_‘)); if (!in_array($type, $type_array)) { $type = ‘240‘; } if (empty($goods)){ return QINIU_DOMAIN.‘/‘.defaultGoodsImage($type); } if (array_key_exists(‘apic_cover‘, $goods)) { $goods[‘goods_image‘] = $goods[‘apic_cover‘]; } if (empty($goods[‘goods_image‘])) { return QINIU_DOMAIN.‘/‘.defaultGoodsImage($type); } //图片路径 $file=$goods[‘goods_image‘]; // 需要填写你的 Access Key 和 Secret Key $accessKey = ‘O9fT4BHnNJgTVlccVCPhcVZsxPQhYE3JEmVT2RR2‘; $secretKey = ‘pgbAMset23cJTKLbnCBfIW_T1rLRWKOQ7kuvIyFo‘; //初始化Auth状态: $auth = new Auth($accessKey, $secretKey); //初始化BucketManager $bucketMgr = new BucketManager($auth); //你要操作的空间, 并且这个key在你空间中存在 $bucket = ‘mall‘; $key = $file; //获取文件的状态信息 list($ret, $err) = $bucketMgr->stat($bucket, $key); if ($err !== null) { //var_dump($err); return QINIU_DOMAIN . ‘/‘ . defaultGoodsImage ( $type ); } else { //var_dump($ret); return QINIU_DOMAIN . ‘/‘ . ($type == ‘‘ ? $file : $file.‘_‘.$type); } } /** * 取得商品缩略图的完整URL路径,接收图片名称与店铺ID * * @param string $file 图片名称 * @param string $type 缩略图尺寸类型,值为60,240,360,1280 * @param mixed $store_id 店铺ID 如果传入,则返回图片完整URL,如果为假,返回系统默认图 * @return string */ //未经加工过的cthumb function cthumb_raw($file, $type = ‘‘, $store_id = false) { $type_array = explode(‘,_‘, ltrim(GOODS_IMAGES_EXT, ‘_‘)); if (!in_array($type, $type_array)) { $type = ‘240‘; } if (empty($file)) { return UPLOAD_SITE_URL . ‘/‘ . defaultGoodsImage ( $type ); } $search_array = explode(‘,‘, GOODS_IMAGES_EXT); $file = str_ireplace($search_array,‘‘,$file); $fname = basename($file); // 取店铺ID if ($store_id === false || !is_numeric($store_id)) { $store_id = substr ( $fname, 0, strpos ( $fname, ‘_‘ ) ); } // 本地存储时,增加判断文件是否存在,用默认图代替 if ( !file_exists(BASE_UPLOAD_PATH . ‘/‘ . ATTACH_GOODS . ‘/‘ . $store_id . ‘/‘ . ($type == ‘‘ ? $file : str_ireplace(‘.‘, ‘_‘ . $type . ‘.‘, $file)) )) { return UPLOAD_SITE_URL.‘/‘.defaultGoodsImage($type); } $thumb_host = UPLOAD_SITE_URL . ‘/‘ . ATTACH_GOODS; return $thumb_host . ‘/‘ . $store_id . ‘/‘ . ($type == ‘‘ ? $file : str_ireplace(‘.‘, ‘_‘ . $type . ‘.‘, $file)); } /** * 取得商品缩略图的七牛完整URL路径,接收图片名称与图片类型 * * @param string $file 图片名称 * @param string $type 缩略图尺寸类型,值为60,240,360,1280 * @return string */ //加工后的cthumb function cthumb($file, $type = ‘‘,$tore_id = false) { $type_array = explode(‘,_‘, ltrim(GOODS_IMAGES_EXT, ‘_‘)); // 图片类型 if (!in_array($type, $type_array)) { $type = ‘240‘; } // 文件为空 显示默认图像 if (empty($file)) { return QINIU_DOMAIN . ‘/‘ . defaultGoodsImage ( $type ); } // 需要填写你的 Access Key 和 Secret Key $accessKey = ‘O9fT4BHnNJgTVlccVCPhcVZsxPQhYE3JEmVT2RR2‘; $secretKey = ‘pgbAMset23cJTKLbnCBfIW_T1rLRWKOQ7kuvIyFo‘; //初始化Auth状态: $auth = new Auth($accessKey, $secretKey); //初始化BucketManager $bucketMgr = new BucketManager($auth); //你要操作的空间, 并且这个key在你空间中存在 $bucket = ‘mall‘; $key = $file; //获取文件的状态信息 list($ret, $err) = $bucketMgr->stat($bucket, $key); if ($err !== null) { //var_dump($err); return QINIU_DOMAIN . ‘/‘ . defaultGoodsImage ( $type ); } else { //var_dump($ret); return QINIU_DOMAIN . ‘/‘ . ($type == ‘‘ ? $file : $file.‘_‘.$type); } } /** * 商品二维码 * @param array $goods_info * @return string */ function goodsQRCode($goods_info) { if (!file_exists(BASE_UPLOAD_PATH. ‘/‘ . ATTACH_STORE . ‘/‘ . $goods_info[‘store_id‘] . ‘/‘ . $goods_info[‘goods_id‘] . ‘.png‘ )) { return UPLOAD_SITE_URL.DS.ATTACH_STORE.DS.‘default_qrcode.png‘; } return UPLOAD_SITE_URL.DS.ATTACH_STORE.DS.$goods_info[‘store_id‘].DS.$goods_info[‘goods_id‘].‘.png‘; } /** * 商品二维码 v3-b12 * @param array $goods_info * @return string */ function storeQRCode($store_id) { if (!file_exists(BASE_UPLOAD_PATH. ‘/‘ . ATTACH_STORE . ‘/‘ . $store_id . ‘/‘ . $store_id . ‘_store.png‘ )) { return UPLOAD_SITE_URL.DS.ATTACH_STORE.DS.‘default_qrcode.png‘; } return UPLOAD_SITE_URL.DS.ATTACH_STORE.DS.$store_id.DS.$store_id.‘_store.png‘; } /** * 取得抢购缩略图的完整URL路径 * * @param string $imgurl 商品名称 * @param string $type 缩略图类型 值为small,mid,max * @return string */ function gthumb($image_name = ‘‘, $type = ‘‘){ if (!in_array($type, array(‘small‘,‘mid‘,‘max‘))) $type = ‘small‘; if (empty($image_name)){ return UPLOAD_SITE_URL.‘/‘.defaultGoodsImage(‘240‘); } list($base_name, $ext) = explode(‘.‘, $image_name); list($store_id) = explode(‘_‘, $base_name); $file_path = ATTACH_GROUPBUY.DS.$store_id.DS.$base_name.‘_‘.$type.‘.‘.$ext; if(!file_exists(BASE_UPLOAD_PATH.DS.$file_path)) { return UPLOAD_SITE_URL.‘/‘.defaultGoodsImage(‘240‘); } return UPLOAD_SITE_URL.DS.$file_path; } /** * 取得买家缩略图的完整URL路径 * * @param string $imgurl 商品名称 * @param string $type 缩略图类型 值为240,1024 * @return string */ function snsThumb($image_name = ‘‘, $type = ‘‘){ if (!in_array($type, array(‘240‘,‘1024‘))) $type = ‘240‘; if (empty($image_name)){ return UPLOAD_SITE_URL.‘/‘.defaultGoodsImage(‘240‘); } list($member_id) = explode(‘_‘, $image_name); $file_path = ATTACH_MALBUM.DS.$member_id.DS.str_ireplace(‘.‘, ‘_‘.$type.‘.‘, $image_name); if(!file_exists(BASE_UPLOAD_PATH.DS.$file_path)) { return UPLOAD_SITE_URL.‘/‘.defaultGoodsImage(‘240‘); } return UPLOAD_SITE_URL.DS.$file_path; } /** * 取得积分商品缩略图的完整URL路径 * * @param string $imgurl 商品名称 * @param string $type 缩略图类型 值为small * @return string */ function pointprodThumb($image_name = ‘‘, $type = ‘‘){ if (!in_array($type, array(‘small‘,‘mid‘))) $type = ‘‘; if (empty($image_name)){ return UPLOAD_SITE_URL.‘/‘.defaultGoodsImage(‘240‘); } if($type) { $file_path = ATTACH_POINTPROD.DS.str_ireplace(‘.‘, ‘_‘.$type.‘.‘, $image_name); } else { $file_path = ATTACH_POINTPROD.DS.$image_name; } if(!file_exists(BASE_UPLOAD_PATH.DS.$file_path)) { return UPLOAD_SITE_URL.‘/‘.defaultGoodsImage(‘240‘); } return UPLOAD_SITE_URL.DS.$file_path; } /** * 取得品牌图片 * * @param string $image_name * @return string */ function brandImage($image_name = ‘‘) { if ($image_name != ‘‘) { return UPLOAD_SITE_URL.‘/‘.ATTACH_BRAND.‘/‘.$image_name; } return UPLOAD_SITE_URL.‘/‘.ATTACH_COMMON.‘/default_brand_image.gif‘; } /** * 取得订单状态文字输出形式 * * @param array $order_info 订单数组 * @return string $order_state 描述输出 */ function orderState($order_info) { switch ($order_info[‘order_state‘]) { case ORDER_STATE_CANCEL: $order_state = L(‘order_state_cancel‘); break; case ORDER_STATE_NEW: $order_state = L(‘order_state_new‘); break; case ORDER_STATE_PAY: $order_state = L(‘order_state_pay‘); break; case ORDER_STATE_SEND: $order_state = L(‘order_state_send‘); break; case ORDER_STATE_SUCCESS: $order_state = L(‘order_state_success‘); break; } return $order_state; } /** * 取得订单支付类型文字输出形式 * * @param array $payment_code * @return string */ function orderPaymentName($payment_code) { return str_replace( array(‘offline‘,‘online‘,‘alipay‘,‘tenpay‘,‘chinabank‘,‘predeposit‘), array(‘货到付款‘,‘在线付款‘,‘支付宝‘,‘财付通‘,‘网银在线‘,‘站内余额支付‘), $payment_code); } /** * 取得订单商品销售类型文字输出形式 * * @param array $goods_type * @return string 描述输出 */ function orderGoodsType($goods_type) { return str_replace( array(‘1‘,‘2‘,‘3‘,‘4‘,‘5‘), array(‘‘,‘抢购‘,‘限时折扣‘,‘优惠套装‘,‘赠品‘), $goods_type); } /** * 取得结算文字输出形式 * * @param array $bill_state * @return string 描述输出 */ function billState($bill_state) { return str_replace( array(‘1‘,‘2‘,‘3‘,‘4‘), array(‘已出账‘,‘商家已确认‘,‘平台已审核‘,‘结算完成‘), $bill_state); } ?>
标签:
原文地址:http://www.cnblogs.com/xiaoxiaomengxiangjia/p/5443100.html