Commit 12bfe357 authored by luhongguang's avatar luhongguang

update:添加商品

parent 06e13e25
<?php
namespace Validate;
/**
* Class GoodsAddValidate
*
* @package Validate
*/
class GoodsAddValidate extends BaseValidate
{
protected $rule = [
// 'goods_spu_id' => 'require',
// 'online_status' => 'require',
// 'uid' => 'require',
// 'username' => 'require',
];
protected $message = [
"goods_spu_id" => "商品id不能为空",
"online_status" => "商品上下架状态不能为空",
"uid" => "用户id不能为空",
"username" => "用户username不能为空",
];
}
\ No newline at end of file
......@@ -14,6 +14,15 @@ class GoodsSpu extends MysqlBase
const TABLE_NAME = 'goods_spu';
const CONFIG_INDEX = 'goods';
const TYPE_VIRTUAL = 1;//虚拟商品
const TYPE_ENTITY = 2;//实体商品
const SUB_TYPE_TO_SHOP = 1;//到店
const SUB_TYPE_ONLINE = 2;//线上
const SALE_TYPE_NO_COMBINATION = 1;//非组合商品(无套餐)
const SALE_TYPE_COMBINATION = 2;//组合商品(有套餐)
public static function getRecord($where, $colums = [])
{
if (empty($colums)) {
......
......@@ -23,24 +23,8 @@ class GoodsController extends Base
*/
public function addAction()
{
$lifeAccountId = 111;
$params = [
"name" => "商品name",
"url" => "url1, url2, url3",
"desc" => "描述描述",
"category_1_id" => 1,
"category_2_id" => 13,
"expiration_time" => "2021-06-10 12:20:30",
"rule_limit" => 3,
"rule_date_type" => 1,
"rule_start_time" => "2021-06-11 12:20:30",
"rule_end_time" => "2021-06-12 12:20:30",
"rule_desc" => "规则描述",
"inventory_total" => 10,
"original_price" => 1500,
"price" => 500,
];
GoodsService::addGoods($lifeAccountId, $params);
$params = $this->params;
GoodsService::addGoods($params);
$this->success();
}
......
......@@ -40,31 +40,21 @@ class GoodsService
/**
* 添加商品
* @param $lifeAccountId
* @param array $params
* @return mixed
* @throws GoodsException
*/
public static function addGoods($lifeAccountId, $params = [])
public static function addGoods($params = [])
{
//todo:: 获取 $lifeAccount信息
$lifeAccount = [
"life_account_id" => 111,
"merchant_id" => 1,
"life_account_name" => "测试测试",
];
GoodsSpu::beginTransaction();
$shopId = self::addShop($lifeAccount);
$spuData = [
"name" => $params["name"],
"url" => $params["url"],
"desc" => $params["desc"],
$lifeAccount = [
"life_account_id" => $params["life_account_id"],
"merchant_id" => $params["merchant_id"],
];
$spuId = self::addGoodsSpu($shopId, $spuData);
$skuId = self::addGoodsSku($spuId, $shopId, $lifeAccountId, $params);
$shopId = self::addShop($lifeAccount);
$spuId = self::addGoodsSpu($shopId, $params);
$skuId = self::addGoodsSku($spuId, $shopId, $params);
if (!GoodsSpu::commit()) {
GoodsSpu::rollback();
......@@ -87,12 +77,23 @@ class GoodsService
throw new GoodsException(['cus' => 2]);
}
$spuId = $res[0];
GoodsSpu::save([
"goods_spu_id" => $spuId,
"shop_id" => $shopId,
"life_account_id" => $spuData["life_account_id"],
"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"],
]);
return $spuId;
}
......@@ -106,18 +107,19 @@ class GoodsService
* @return mixed
* @throws GoodsException
*/
private static function addGoodsSku($spuId, $shopId, $lifeAccountId, $skuData = [])
private static function addGoodsSku($spuId, $shopId, $skuData = [])
{
$res = self::getIdgenId(substr($shopId, -2), "goods");
if (empty($res)) {
throw new GoodsException(['cus' => 2]);
}
$skuId = $res[0];
GoodsSku::save([
$skuParams = [
"goods_spu_id" => $spuId,
"goods_sku_id" => $skuId,
"shop_id" => $shopId,
"life_account_id" => $lifeAccountId,
"life_account_id" => $skuData["life_account_id"],
"category_1_id" => $skuData["category_1_id"],
"category_2_id" => $skuData["category_2_id"],
"name" => $skuData["name"],
......@@ -129,10 +131,16 @@ class GoodsService
"rule_start_time" => $skuData["rule_start_time"],
"rule_end_time" => $skuData["rule_end_time"],
"rule_desc" => $skuData["rule_desc"],
"rule_refund" => $skuData["rule_refund"],
"inventory_total" => $skuData["inventory_total"],
"inventory_rest" => $skuData["inventory_total"],
"original_price" => $skuData["original_price"],
"price" => $skuData["price"],
]);
];
if (!empty($skuData["setmeal"])) {
$skuParams["setmeal"] = $skuData["setmeal"];
}
GoodsSku::save($skuParams);
return $skuId;
}
......
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