提交 2a628b66 编写于 作者: D devil_gong

优化

上级 0eec4a10
......@@ -202,7 +202,7 @@ class AlipayLifeController extends CommonController
}
// 图片
$this->ImagesSave('logo', 'file_logo', 'alipay_life');
$this->FileSave('logo', 'file_logo', 'alipay_life');
// id为空则表示是新增
$m = D('AlipayLife');
......
......@@ -198,7 +198,7 @@ class BrandController extends CommonController
}
// 图片
$this->ImagesSave('logo', 'file_logo', 'brand');
$this->FileSave('logo', 'file_logo', 'brand');
// id为空则表示是新增
$m = D('Brand');
......
......@@ -290,7 +290,7 @@ class CommonController extends Controller
}
/**
* 图片删除
* 文件删除
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
......@@ -298,7 +298,7 @@ class CommonController extends Controller
* @desc description
* @param [string] $img [图片地址 path+name]
*/
protected function ImagesDelete($img)
protected function FileDelete($img)
{
if(empty($img)) return false;
......@@ -310,7 +310,7 @@ class CommonController extends Controller
}
/**
* 图片批量删除
* 文件批量删除
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
......@@ -318,22 +318,22 @@ class CommonController extends Controller
* @desc description
* @param [array] $img_all [图片地址 path+name]
*/
protected function ImagesDeleteAll($img_all)
protected function FileDeleteAll($img_all)
{
if(!empty($img_all) && is_array($img_all))
{
for($i=0; $i<count($img_all); $i++)
{
$this->ImagesDelete($img_all[$i]);
$this->ImagesDelete(str_replace(['compr', 'small'], 'small', $img_all[$i]));
$this->ImagesDelete(str_replace(['compr', 'small'], 'compr', $img_all[$i]));
$this->ImagesDelete(str_replace(['compr', 'small'], 'original', $img_all[$i]));
$this->FileDelete($img_all[$i]);
$this->FileDelete(str_replace(['compr', 'small'], 'small', $img_all[$i]));
$this->FileDelete(str_replace(['compr', 'small'], 'compr', $img_all[$i]));
$this->FileDelete(str_replace(['compr', 'small'], 'original', $img_all[$i]));
}
}
}
/**
* 图片存储
* 文件存储
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
......@@ -343,7 +343,7 @@ class CommonController extends Controller
* @param [string] $post_name [file form name名称]
* @param [string] $dir [存储路径标记]
*/
protected function ImagesSave($field, $post_name, $dir = 'common')
protected function FileSave($field, $post_name, $dir = 'common')
{
if(isset($_FILES[$post_name]['error']))
{
......
......@@ -94,7 +94,7 @@ class ExpressController extends CommonController
}
// 图片
$this->ImagesSave('icon', 'file_icon', 'express');
$this->FileSave('icon', 'file_icon', 'express');
// id为空则表示是新增
$m = D('Express');
......
......@@ -116,10 +116,10 @@ class GoodsCategoryController extends CommonController
}
// icon
$this->ImagesSave('icon', 'file_icon', 'goods_category');
$this->FileSave('icon', 'file_icon', 'goods_category');
// 大图片
$this->ImagesSave('big_images', 'file_big_images', 'goods_category');
$this->FileSave('big_images', 'file_big_images', 'goods_category');
// id为空则表示是新增
$m = D('GoodsCategory');
......
......@@ -342,7 +342,11 @@ class GoodsController extends CommonController
// 添加/编辑
$m = D('Goods');
$type = empty($_POST['id']) ? 1 : 2;
// 商品
$goods_id = I('id');
$goods = $m->find($goods_id);
$type = empty($goods) ? 1 : 2;
if($m->create($_POST, $type))
{
// 开启事务
......@@ -356,14 +360,12 @@ class GoodsController extends CommonController
} else {
// 更新
$data['upd_time'] = time();
if($m->where(['id'=>I('id')])->save($data) === false)
if($m->where(['id'=>$goods_id])->save($data) === false)
{
// 回滚事务
$m->rollback();
$this->ajaxReturn(L('common_operation_edit_error'), -100);
} else {
$goods_id = I('id');
}
}
......@@ -410,6 +412,12 @@ class GoodsController extends CommonController
// 提交事务
$m->commit();
// 删除原来的视频
if(!empty($goods['video']) && !empty($video['data']['file_video']['url']))
{
$this->FileDelete($goods['video']);
}
// 提示
if($type == 1)
{
......@@ -547,7 +555,7 @@ class GoodsController extends CommonController
$result[$key[1]][$key[0]] = DS.$path.'compr'.$date.$small;
} else {
// 如果图片格式有误,则删除原图片
$this->ImagesDelete($path.'original'.$date.$original);
$this->FileDelete($path.'original'.$date.$original);
}
}
}
......@@ -616,7 +624,7 @@ class GoodsController extends CommonController
$result[] = DS.$path.'compr'.$date.$small;
} else {
// 如果图片格式有误,则删除原图片
$this->ImagesDelete($path.'original'.$date.$original);
$this->FileDelete($path.'original'.$date.$original);
}
}
}
......@@ -677,7 +685,7 @@ class GoodsController extends CommonController
$result[$field] = DS.$path.'compr'.$date.$small;
} else {
// 如果图片格式有误,则删除原图片
$this->ImagesDelete($path.'original'.$date.$original);
$this->FileDelete($path.'original'.$date.$original);
}
}
}
......
......@@ -205,7 +205,7 @@ class PaymentController extends CommonController
}
// 图片
$this->ImagesSave('logo', 'file_logo', 'payment');
$this->FileSave('logo', 'file_logo', 'payment');
// id为空则表示是新增
$m = D('Payment');
......
......@@ -72,8 +72,8 @@ class SiteController extends CommonController
public function Save()
{
// logo存储
$this->ImagesSave('home_site_logo', 'home_site_logo_img');
$this->ImagesSave('home_site_logo_wap', 'home_site_logo_wap_img');
$this->FileSave('home_site_logo', 'home_site_logo_img');
$this->FileSave('home_site_logo_wap', 'home_site_logo_wap_img');
// 站点状态值处理
if(!isset($_POST['home_user_reg_state']))
......
......@@ -55,6 +55,9 @@ class GoodsController extends CommonController
// 是否已收藏
$goods['is_favor'] = $this->IsGoodsUserFavor($goods_id);
// 视频
$goods['video'] = empty($goods['video']) ? null : C('IMAGE_HOST').$goods['video'];
$result = [
// 商品基础数据
'goods' => $goods,
......@@ -67,6 +70,9 @@ class GoodsController extends CommonController
// 属性
'attribute' => $this->GetGoodsAttribute($goods_id),
// 客服电话
'customer_service_tel' => MyC('common_customer_service_tel'),
];
$this->ajaxReturn(L('common_operation_success'), 0, $result);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册