提交 3a0fd569 编写于 作者: R root

fecshop admin product image edit and product remove

上级 f0265eb9
......@@ -357,23 +357,21 @@ class AppadminbaseBlock extends Object{
* get edit html bar, it contains add ,eidt ,delete button.
*/
public function getEditBar(){
/*
if(!strstr($this->_currentParamUrl,"?")){
$csvUrl = $this->_currentParamUrl."?type=export";
}else{
$csvUrl = $this->_currentParamUrl."&type=export";
}
<li class="line">line</li>
<li><a class="icon csvdownload" href="'.$csvUrl.'" target="dwzExport" targetType="navTab" title="实要导出这些记录吗?"><span>导出EXCEL</span></a></li>
*/
return '<ul class="toolBar">
<li><a class="add" href="'.$this->_editUrl.'" target="dialog" height="580" width="1000" drawable="true" mask="true"><span>添加</span></a></li>
<li><a target="dialog" height="580" width="1000" drawable="true" mask="true" class="edit" href="'.$this->_editUrl.'?'.$this->_primaryKey.'={sid_user}" ><span>修改</span></a></li>
<li><a title="确实要删除这些记录吗?" target="selectedTodo" rel="'.$this->_primaryKey.'s" postType="string" href="'.$this->_deleteUrl.'" class="delete"><span>批量删除</span></a></li>
<li class="line">line</li>
<li><a class="icon csvdownload" href="'.$csvUrl.'" target="dwzExport" targetType="navTab" title="实要导出这些记录吗?"><span>导出EXCEL</span></a></li>
</ul>';
}
/**
* list pager, it contains numPerPage , pageNum , totalNum.
......
......@@ -185,7 +185,11 @@ EOF;
$tabLangTextarea = '';
foreach($langs as $lang){
$langAttrName = Yii::$service->fecshoplang->getLangAttrName($name,$lang);
if($require && $defaultLangCode === $lang){
$inputStringLangRequire = 'required';
}else{
$inputStringLangRequire = 0;
}
$tabLangTitle .= '<li><a href="javascript:;"><span>'.$lang.'</span></a></li>';
$tabLangTextarea .= '
<div>
......@@ -193,7 +197,7 @@ EOF;
<legend style="color:#cc0000">'.$label.'['.$lang.']:</legend>
<div>
<div class="unit">
<textarea class="editor" rows="'.$rows.'" cols="'.$cols.'" name="'.$this->_editFormData.'['.$name.']['.$langAttrName.']" >'.$value[$langAttrName].'</textarea>
<textarea class="editor '.$inputStringLangRequire.'" rows="'.$rows.'" cols="'.$cols.'" name="'.$this->_editFormData.'['.$name.']['.$langAttrName.']" >'.$value[$langAttrName].'</textarea>
</div>
</div>
</fieldset>
......
......@@ -235,14 +235,40 @@ class Manageredit extends AppadminbaseBlockEdit implements AppadminbaseBlockEdi
* save article data, get rewrite url and save to article url key.
*/
public function save(){
$this->initParamType();
/**
* if attribute is date or date time , db storage format is int ,by frontend pass param is int ,
* you must convert string datetime to time , use strtotime function.
*/
// var_dump()
$this->_service->save($this->_param,'catalog/product/index');
$errors = Yii::$service->helper->errors->get();
if(!$errors ){
echo json_encode(array(
"statusCode"=>"200",
"message"=>"save success",
));
exit;
}else{
echo json_encode(array(
"statusCode"=>"300",
"message"=>$errors,
));
exit;
}
}
protected function initParamType(){
$request_param = CRequest::param();
$this->_param = $request_param[$this->_editFormData];
$this->_param['attr_group'] = CRequest::param('attr_group');
$this->_param['custom_option'] = ($custom_option = CRequest::param('custom_option')) ? json_decode($custom_option,true) : '';
$image_gallery = CRequest::param('image_gallery');
$image_main = CRequest::param('image_main');
$save_gallery = [];
// init image gallery
if($image_gallery){
$image_gallery_arr = explode("|||||",$image_gallery);
if(!empty($image_gallery_arr)){
......@@ -254,13 +280,12 @@ class Manageredit extends AppadminbaseBlockEdit implements AppadminbaseBlockEdi
'label' => $gallery_label,
'sort_order' => $gallery_sort_order,
];
}
}
$this->_param['image']['gallery'] = $save_gallery;
}
}
// init image main
if($image_main){
list($main_image,$main_label,$main_sort_order) = explode('#####',$image_main);
$save_main = [
......@@ -270,42 +295,15 @@ class Manageredit extends AppadminbaseBlockEdit implements AppadminbaseBlockEdi
];
$this->_param['image']['main'] = $save_main;
}
$this->initParamType();
/**
* if attribute is date or date time , db storage format is int ,by frontend pass param is int ,
* you must convert string datetime to time , use strtotime function.
*/
// var_dump()
$this->_service->save($this->_param,'catalog/product/index');
$errors = Yii::$service->helper->errors->get();
if(!$errors ){
echo json_encode(array(
"statusCode"=>"200",
"message"=>"save success",
));
exit;
}else{
echo json_encode(array(
"statusCode"=>"300",
"message"=>$errors,
));
exit;
}
}
protected function initParamType(){
//$this->_primaryKey = $this->_service->getPrimaryKey();
//$id = $this->_param[$this->_primaryKey];
//$this->_one = $this->_service->getByPrimaryKey($id);
//weight
$this->_param['weight'] = $this->_param['weight'] ? (float)($this->_param['weight']) : 0;
//status
$this->_param['status'] = $this->_param['status'] ? (float)($this->_param['status']) : 0;
//image main sort order
if(isset($this->_param['image']['main']['sort_order']) && !empty($this->_param['image']['main']['sort_order'])){
$this->_param['image']['main']['sort_order'] = (int)($this->_param['image']['main']['sort_order']);
}
//image gallery
if(isset($this->_param['image']['gallery']) && is_array($this->_param['image']['gallery']) && !empty($this->_param['image']['gallery'])){
$gallery_af = [];
foreach($this->_param['image']['gallery'] as $gallery){
......@@ -316,9 +314,8 @@ class Manageredit extends AppadminbaseBlockEdit implements AppadminbaseBlockEdi
}
$this->_param['image']['gallery'] = $gallery_af;
}
# 自定义属性
# 自定义属性 也就是在 @common\config\fecshop_local_services\Product.php 产品服务的 customAttrGroup 配置的产品属性。
$custom_attr = \Yii::$service->product->getGroupAttrInfo($this->_param['attr_group']);
//var_dump($custom_attr);exit;
if(is_array($custom_attr) && !empty($custom_attr)){
foreach($custom_attr as $attrInfo){
$attr = $attrInfo['name'];
......@@ -353,16 +350,13 @@ class Manageredit extends AppadminbaseBlockEdit implements AppadminbaseBlockEdi
}else{
$this->_param[$attr] = (Float)$this->_param[$attr];
}
}
}
}
}
$custom_option = isset($this->_param['custom_option']) ? $this->_param['custom_option'] : '';
//var_dump($custom_option);exit;
if(is_array($custom_option) && !empty($custom_option) ){
$custom_option_af = [];
foreach($custom_option as $option){
$option['is_require'] = isset($option['is_require']) ? (int)$option['is_require'] : 0;
$option['sort_order'] = isset($option['sort_order']) ? (int)$option['sort_order'] : 0;
......@@ -380,10 +374,6 @@ class Manageredit extends AppadminbaseBlockEdit implements AppadminbaseBlockEdi
}
$this->_param['custom_option'] = $custom_option_af;
}
}
......
......@@ -82,7 +82,7 @@ class Attr
'lang' => false,
],
'require' => 0,
'require' => 1,
],
[
'label'=>'SKU',
......@@ -92,7 +92,7 @@ class Attr
'lang' => false,
],
'require' => 0,
'require' => 1,
],
[
'label'=>'重量',
......@@ -196,7 +196,7 @@ class Attr
'rows' => 14,
'cols' => 100,
],
'require' => 0,
'require' => 1,
],
];
}
......
......@@ -42,9 +42,10 @@ class ProductinfoController extends CatalogController
}
public function actionRemove()
public function actionManagerdelete()
{
$this->getBlock("index")->remove();
$data = $this->getBlock('manageredit')->delete();
}
......
......@@ -55,11 +55,16 @@ function thissubmit(thiss){
if(main_image_image){
image_main = main_image_image+'#####'+main_image_label+'#####'+main_image_sort_order;
$(".tabsContent .image_main").val(image_main);
}else{
alert('您至少上传并选择一张主图');
//DWZ.ajaxDone;
return false;
}
image_gallery = '';
$('.productimg input[type=radio]').each(function(){
if(!$(this).is(':checked')){
gallery_image_image = $(this).val();
gallery_image_label = $(this).parent().parent().find(".image_label").val();
gallery_image_sort_order = $(this).parent().parent().find(".sort_order").val();
......
......@@ -61,20 +61,43 @@ class ProductMongodb implements ProductInterface
*/
public function save($one,$originUrlKey){
//var_dump($one);exit;
if(!$this->initSave($one)){
return;
}
$currentDateTime = \fec\helpers\CDate::getCurrentDateTime();
$primaryVal = isset($one[$this->getPrimaryKey()]) ? $one[$this->getPrimaryKey()] : '';
if($primaryVal){
$model = Product::findOne($primaryVal);
if(!$model){
Yii::$service->helper->errors->add('Product '.$this->getPrimaryKey().' is not exist');
return;
}
#验证sku 是否重复
$product_one = Product::find()->asArray()->where([
'<>',$this->getPrimaryKey(),(new \MongoId($primaryVal))
])->andWhere([
'sku' => $one['sku'],
])->one();
if($product_one['sku']){
Yii::$service->helper->errors->add('Product Sku 已经存在,请使用其他的sku');
return;
}
}else{
$model = new Product;
$model->created_at = time();
$model->created_user_id = \fec\helpers\CUser::getCurrentUserId();
$primaryVal = new \MongoId;
$model->{$this->getPrimaryKey()} = $primaryVal;
#验证sku 是否重复
$product_one = Product::find()->asArray()->where([
'sku' => $one['sku'],
])->one();
if($product_one['sku']){
Yii::$service->helper->errors->add('Product Sku 已经存在,请使用其他的sku');
return;
}
}
$model->updated_at = time();
unset($one['_id']);
......@@ -88,81 +111,67 @@ class ProductMongodb implements ProductInterface
return true;
}
/**
* remove Product
*/
public function remove($id){
if(!$id){
Yii::$service->helper->errors->add('remove id is empty');
protected function initSave($one){
if(!isset($one['sku']) || empty($one['sku'])){
Yii::$service->helper->errors->add(' sku 必须存在 ');
return false;
}
$model = Product::findOne($id);
if(isset($model[$this->getPrimaryKey()]) && !empty($model[$this->getPrimaryKey()]) ){
$url_key = $model['url_key'];
Yii::$service->url->removeRewriteUrlKey($url_key);
$model->delete();
$this->removeChildCate($id);
}else{
Yii::$service->helper->errors->add("Product Remove Errors:ID:$id is not exist.");
if(!isset($one['spu']) || empty($one['spu'])){
Yii::$service->helper->errors->add(' spu 必须存在 ');
return false;
}
$defaultLangName = \Yii::$service->fecshoplang->getDefaultLangAttrName('name');
if(!isset($one['name'][$defaultLangName]) || empty($one['name'][$defaultLangName])){
Yii::$service->helper->errors->add(' name '.$defaultLangName.' 不能为空 ');
return false;
}
$defaultLangDes = \Yii::$service->fecshoplang->getDefaultLangAttrName('description');
if(!isset($one['description'][$defaultLangDes]) || empty($one['description'][$defaultLangDes])){
Yii::$service->helper->errors->add(' description '.$defaultLangDes.'不能为空 ');
return false;
}
return true;
}
protected function removeChildCate($id){
$data = Product::find()->where(['parent_id'=>$id])->all();
if(!empty($data)){
foreach($data as $one){
$idVal = $one['_id']->{'$id'};
if($this->hasChildCategory($idVal)){
$this->removeChildCate($idVal);
/**
* remove Product
*/
public function remove($ids){
if(empty($ids)){
Yii::$service->helper->errors->add('remove id is empty');
return false;
}
if(is_array($ids)){
foreach($ids as $id){
$model = Product::findOne($id);
if(isset($model[$this->getPrimaryKey()]) && !empty($model[$this->getPrimaryKey()]) ){
$url_key = $model['url_key'];
Yii::$service->url->removeRewriteUrlKey($url_key);
$model->delete();
//$this->removeChildCate($id);
}else{
Yii::$service->helper->errors->add("Product Remove Errors:ID:$id is not exist.");
return false;
}
$url_key = $one['url_key'];
Yii::$service->url->removeRewriteUrlKey($url_key);
$one->delete();
}
}
}
public function getTreeArr($rootCategoryId = '',$lang=''){
$arr = [];
if(!$lang){
$lang = Yii::$service->fecshoplang->defaultLangCode;
}
if(!$rootCategoryId){
$where = ['parent_id' => '0'];
}else{
$where = ['parent_id' => $rootCategoryId];
}
$categorys = Product::find()->asArray()->where($where)->all();
//var_dump($categorys);exit;
$idKey= $this->getPrimaryKey();
if(!empty($categorys)){
foreach($categorys as $cate){
$idVal = $cate[$idKey]->{'$id'};
$arr[$idVal] = [
$idKey => $idVal,
'name' => Yii::$service->fecshoplang->getLangAttrVal($cate['name'],'name',$lang),
];
//echo $arr[$idVal]['name'];
if($this->hasChildCategory($idVal)){
$arr[$idVal]['child'] = $this->getTreeArr($idVal,$lang);
}
$id = $ids;
$model = Product::findOne($id);
if(isset($model[$this->getPrimaryKey()]) && !empty($model[$this->getPrimaryKey()]) ){
$url_key = $model['url_key'];
Yii::$service->url->removeRewriteUrlKey($url_key);
$model->delete();
//$this->removeChildCate($id);
}else{
Yii::$service->helper->errors->add("Product Remove Errors:ID:$id is not exist.");
return false;
}
}
return $arr;
}
protected function hasChildCategory($idVal){
$one = Product::find()->asArray()->where(['parent_id'=>$idVal])->one();
if(!empty($one)){
return true;
}
return false;
return true;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册