Commit 1f4ff8d9 authored by luhongguang's avatar luhongguang

update:商品编辑

parent 12bfe357
...@@ -26,5 +26,6 @@ class GoodsException extends BaseException ...@@ -26,5 +26,6 @@ class GoodsException extends BaseException
12 => '审核状态错误', 12 => '审核状态错误',
13 => '无权限操作', 13 => '无权限操作',
14 => '当前商品不是审核通过状态,无法做上下架操作', 14 => '当前商品不是审核通过状态,无法做上下架操作',
15 => '当前商品不存在',
]; ];
} }
\ No newline at end of file
...@@ -33,7 +33,9 @@ class GoodsController extends Base ...@@ -33,7 +33,9 @@ class GoodsController extends Base
*/ */
public function editAction() public function editAction()
{ {
$params = $this->params;
GoodsService::editGoods($params);
$this->success();
} }
/** /**
......
...@@ -318,4 +318,80 @@ class GoodsService ...@@ -318,4 +318,80 @@ class GoodsService
} }
return ["can_use" => $nameCanUse]; return ["can_use" => $nameCanUse];
} }
/**
* 编辑商品
* @param array $params
* @return bool
* @throws GoodsException
*/
public static function editGoods($params = [])
{
$goodsSpuId = $params["goods_spu_id"];
$goodsSpu = GoodsSpu::get("*", ["goods_spu_id"=>$goodsSpuId]);
if (empty($goodsSpu)) {
throw new GoodsException(["cus" => 15]);
}
GoodsSpu::beginTransaction();
self::editGoodsSpu($goodsSpuId, $params);
$goodsSkuList = GoodsSku::select("*", ["goods_spu_id" => $goodsSpuId]);
if (!empty($goodsSkuList)) {
foreach ($goodsSkuList as $sku) {
self::editGoodsSku($sku["goods_sku_id"], $sku, $params);
}
}
if (!GoodsSpu::commit()) {
GoodsSpu::rollback();
throw new GoodsException(["cus" => 0]);
}
return true;
}
private static function editGoodsSpu($goodsSpuId, $spuData = [])
{
return GoodsSpu::save([
"name" => $spuData["name"],
"url" => $spuData["url"],
"desc" => $spuData["desc"],
"type" => GoodsSpu::TYPE_VIRTUAL,
"sub_type" => GoodsSpu::SUB_TYPE_TO_SHOP,
"sale_type" => empty($spuData["setmeal"]) ? GoodsSpu::SALE_TYPE_NO_COMBINATION : GoodsSpu::SALE_TYPE_COMBINATION,
"rule_limit" => $spuData["rule_limit"],
"rule_date_type" => $spuData["rule_date_type"],
"rule_start_time" => $spuData["rule_start_time"],
"rule_end_time" => $spuData["rule_end_time"],
"rule_desc" => $spuData["rule_desc"],
"rule_refund" => $spuData["rule_refund"],
], ["goods_spu_id"=>$goodsSpuId]);
}
private static function editGoodsSku($goodsSkuId, $skuData, $params = [])
{
$skuParams = [
"category_1_id" => $params["category_1_id"],
"category_2_id" => $params["category_2_id"],
"name" => $params["name"],
"url" => $params["url"],
"desc" => $params["desc"],
"expiration_time" => $params["expiration_time"],
"rule_limit" => $params["rule_limit"],
"rule_date_type" => $params["rule_date_type"],
"rule_start_time" => $params["rule_start_time"],
"rule_end_time" => $params["rule_end_time"],
"rule_desc" => $params["rule_desc"],
"rule_refund" => $params["rule_refund"],
"inventory_total" => $params["inventory_total"],
"inventory_rest" => $params["inventory_total"],
"original_price" => $params["original_price"] * 100,
"price" => $params["price"] * 100,
"version" => (int)$skuData["version"] + 1,
];
if (!empty($params["setmeal"])) {
$skuParams["setmeal"] = $params["setmeal"];
}
return GoodsSku::save($skuParams, ["goods_sku_id"=>$goodsSkuId]);
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment