Skip to content

Commit

Permalink
feat:增加删除商品功能
Browse files Browse the repository at this point in the history
feat:增加商品删除时自动将要清理的图片或视频推送给资源清理队列
feat:商品删除时,自动删除商品相关的SKU、属性
  • Loading branch information
Donny Wong committed Jan 4, 2019
1 parent d44f3d9 commit ff6fd08
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
34 changes: 28 additions & 6 deletions src/Api/Console/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,12 @@ public function getProduct(){
]);


//调用属性集服务
$response = $this->apiRequest('product.propset.get',['id'=>$returnData['propsetId'],'loadPropvalue'=>1]);
$response = json_decode($response,true);
if($response['status']==0 && $response['data']){
$propkeyList = $response['data']['propkeyList'];
}
//API:调用属性集服务
// $response = $this->apiRequest('product.propset.get',['id'=>$returnData['propsetId'],'loadPropvalue'=>1]);
// $response = json_decode($response,true);
// if($response['status']==0 && $response['data']){
// $propkeyList = $response['data']['propkeyList'];
// }

return $returnData;

Expand Down Expand Up @@ -392,4 +392,26 @@ public function listProducts(){
$returnData['limit'] = $data['limit'];
return $returnData;
}

/**
* 删除商品,只是做假删除
*/
public function remove(){
$data = $this->_toParamObject($this->getParams());
$model = ProductModel::findFirst([
'id=:id: and isDeleted=0',
'bind'=>['id'=>$data['id']]
]);
if(!$model){
throw new ApiException(ApiException::$EXCODE_NOTEXIST);
}
$result = false;
if($data['isPhysical']){
$result = $model->delete();
}else{
$model->isDeleted = 1;
$result = $model->update();
}
return $result;
}
}
25 changes: 24 additions & 1 deletion src/Core/Product/ProductImgModel.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
namespace Kuga\Core\Product;
use Kuga\Core\Api\Exception;
use Kuga\Core\Base\ModelException;
use Kuga\Core\Base\AbstractModel;

/**
Expand Down Expand Up @@ -55,4 +55,27 @@ public function columnMap() {
'video_url' =>'videoUrl'
];
}

/**
* 清除之后,图片与视频要清理
*/
public function afterDelete(){
$data = [];
if($this->imgUrl){
$data[] = $this->imgUrl;
}
if($this->videoUrl){
$data[] = $this->videoUrl;
}
try {
if (!empty($data)) {
$queue = new \Qing\Lib\Queue();
//$queue = $this->getDI()->getShared('queue');
$queue->put('mediaRecycle', $data);
}
}catch(ModelException $e){
//无队列处理则跳过
}
return true;
}
}
6 changes: 6 additions & 0 deletions src/Core/Product/ProductModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ public function initialize(){
$this->hasMany('id','ProductDescModel','productId',[
['foreignKey' => ['action' => Relation::ACTION_CASCADE], 'namespace' => 'Kuga\\Core\\Product']
]);
$this->hasMany('id','ProductPropModel','productId',[
['foreignKey' => ['action' => Relation::ACTION_CASCADE], 'namespace' => 'Kuga\\Core\\Product']
]);
$this->hasMany('id','ProductSkuModel','productId',[
['foreignKey' => ['action' => Relation::ACTION_CASCADE], 'namespace' => 'Kuga\\Core\\Product']
]);
}
/**
* Independent Column Mapping.
Expand Down

0 comments on commit ff6fd08

Please sign in to comment.