Commit abcdffd6 authored by luhongguang's avatar luhongguang

update:拼单商品add

parent 9b49bed8
...@@ -19,10 +19,14 @@ class GoodsSpu extends MysqlBase ...@@ -19,10 +19,14 @@ class GoodsSpu extends MysqlBase
const SUB_TYPE_TO_SHOP = 1;//到店 const SUB_TYPE_TO_SHOP = 1;//到店
const SUB_TYPE_ONLINE = 2;//线上 const SUB_TYPE_ONLINE = 2;//线上
const SUB_TYPE_INSTANT = 3;//即时(外卖)
const SALE_TYPE_NO_COMBINATION = 1;//非组合商品(无套餐) const SALE_TYPE_NO_COMBINATION = 1;//非组合商品(无套餐)
const SALE_TYPE_COMBINATION = 2;//组合商品(有套餐) const SALE_TYPE_COMBINATION = 2;//组合商品(有套餐)
const BELONG_TYPE_DISANFANG = 1;//第三方商品
const BELONG_TYPE_ZIYING = 2;//自营商品
public static function getRecord($where, $colums = []) public static function getRecord($where, $colums = [])
{ {
if (empty($colums)) { if (empty($colums)) {
......
...@@ -23,6 +23,7 @@ use App\Models\goods\mysql\LifeAccountShopNum; ...@@ -23,6 +23,7 @@ use App\Models\goods\mysql\LifeAccountShopNum;
use App\Models\goods\mysql\PaySuccessGoodsCallbackRecord; use App\Models\goods\mysql\PaySuccessGoodsCallbackRecord;
use App\Models\goods\mysql\Shop; use App\Models\goods\mysql\Shop;
use App\Models\marketing\mysql\Distributor; use App\Models\marketing\mysql\Distributor;
use App\Models\marketing\mysql\Marketing;
use App\Models\marketing\mysql\MarketingGoods; use App\Models\marketing\mysql\MarketingGoods;
use App\Models\shop\mysql\SubShop; use App\Models\shop\mysql\SubShop;
use App\Services\marketing\DistributorService; use App\Services\marketing\DistributorService;
...@@ -73,6 +74,23 @@ class GoodsService ...@@ -73,6 +74,23 @@ class GoodsService
* @throws GoodsException * @throws GoodsException
*/ */
public static function addGoods($params = []) public static function addGoods($params = [])
{
$marketingType = !empty($params['marketing_type']) ? $params['marketing_type'] : 0;
if ($marketingType == Marketing::MARKETING_TYPE_PINDAN) {
return MarketingPindanGoodsService::pindanMarketingAddGoods($params);
} else {
return self::generalAddGoods($params);
}
}
/**
* 普通商品
* @param $params
* @return mixed
* @throws GoodsException
* @throws InterfaceException
*/
private static function generalAddGoods($params)
{ {
GoodsSpu::beginTransaction(); GoodsSpu::beginTransaction();
...@@ -126,7 +144,7 @@ class GoodsService ...@@ -126,7 +144,7 @@ class GoodsService
* @return mixed * @return mixed
* @throws GoodsException * @throws GoodsException
*/ */
private static function addGoodsSpu($shopId, $spuData = []) public static function addGoodsSpu($shopId, $spuData = [])
{ {
$res = self::getIdgenId(substr($shopId, -2), "goods"); $res = self::getIdgenId(substr($shopId, -2), "goods");
if (empty($res)) { if (empty($res)) {
...@@ -1148,7 +1166,7 @@ class GoodsService ...@@ -1148,7 +1166,7 @@ class GoodsService
* @return bool|mixed * @return bool|mixed
* @throws \App\Exception\custom\CodeSpecialException * @throws \App\Exception\custom\CodeSpecialException
*/ */
private static function isHaveSensitive($text, $scene, $businessId = 1) public static function isHaveSensitive($text, $scene, $businessId = 1)
{ {
$params = [ $params = [
'businessId' => $businessId, 'businessId' => $businessId,
...@@ -1469,7 +1487,7 @@ class GoodsService ...@@ -1469,7 +1487,7 @@ class GoodsService
* @param $goodsSkuId * @param $goodsSkuId
* @param $skuData * @param $skuData
*/ */
private static function addGoodsSkuPicRecord($goodsSkuId, $skuData) public static function addGoodsSkuPicRecord($goodsSkuId, $skuData)
{ {
$descPicUrl = $introducePicUrl = []; $descPicUrl = $introducePicUrl = [];
if (!empty($skuData["desc_pic_url"])) { if (!empty($skuData["desc_pic_url"])) {
......
<?php
namespace App\Services\goods;
use Api\PhpServices\Idgen\Idgen;
use Api\PhpServices\Ksy\Ks3Api;
use Api\PhpServices\Ksy\Ksyun;
use Api\PhpServices\Sensitive\Sensitive;
use Api\PhpUtils\Common\BaseConvert;
use Api\PhpUtils\Common\GoodsSkuId;
use Api\PhpUtils\Http\HttpUtil;
use App\Exception\custom\GoodsException;
use App\Models\goods\mysql\Category;
use App\Models\goods\mysql\GoodsOperationRecord;
use App\Models\goods\mysql\GoodsSku;
use App\Models\goods\mysql\GoodsSkuPicRecord;
use App\Models\goods\mysql\GoodsSkuSubShop;
use App\Models\goods\mysql\GoodsSnapshot;
use App\Models\goods\mysql\GoodsSpu;
use App\Models\goods\mysql\LifeAccountShopNum;
use App\Models\goods\mysql\PaySuccessGoodsCallbackRecord;
use App\Models\goods\mysql\PindanGoodsSku;
use App\Models\goods\mysql\Shop;
use App\Models\marketing\mysql\Distributor;
use App\Models\marketing\mysql\Marketing;
use App\Models\marketing\mysql\MarketingGoods;
use App\Models\shop\mysql\SubShop;
use App\Services\marketing\DistributorService;
use App\Services\marketing\MarketingGoodsService;
use App\Services\marketing\MarketingService;
use App\Services\shop\ShopService;
use App\Services\common\CommonService;
use Api\PhpUtils\Http\Request;
use App\Exception\custom\InterfaceException;
class MarketingPindanGoodsService
{
/**
* 拼单商品
* @param $params
* @return string
* @throws GoodsException
* @throws \App\Exception\custom\CodeSpecialException
*/
public static function pindanMarketingAddGoods($params)
{
GoodsSpu::beginTransaction();
//生活号信息
$params["life_account_id"] = MarketingService::PUBLIC_LIFE_ACCOUNT_ID;
$shopId = "00";
$spuData = self::addGoodsSpu($shopId, $params);
$skuId = self::addGoodsSku($spuData, $shopId, $params);
//商品操作记录
$record = [
"goods_spu_id" => $spuData["goods_spu_id"],
"goods_sku_id" => $skuId,
"operator_id" => empty($params["publish_user_id"]) ? 0 : $params["publish_user_id"],
"operator_name" => $params["user_name"],
"goods_status" => GoodsSku::STATUS_PASS,
"online_status" => GoodsSku::ONLINE_STATUS_ONLINE,
"before_version" => 1,
"after_version" => 1,
"note" => empty($params["rejected_reason"]) ? "" : $params["rejected_reason"],
];
GoodsOperationRecord::insertRecord($record);
if (!GoodsSpu::commit()) {
GoodsSpu::rollback();
throw new GoodsException(["cus" => 0]);
}
return $skuId;
}
/**
* 添加spu
* @param $shopId
* @param array $spuData
* @return mixed
* @throws GoodsException
*/
private static function addGoodsSpu($shopId, $spuData = [])
{
$spu = GoodsSpu::get("*", ["goods_name" => $spuData["marketing_name"], "life_account_id" => $spuData["life_account_id"]]);
if (!empty($spu)) {
return $spu;
}
$res = GoodsService::getIdgenId(substr($shopId, -2), "goods");
if (empty($res)) {
throw new GoodsException(['cus' => 2]);
}
$spuId = $res[0];
$spuParams = [
"goods_spu_id" => $spuId,
"shop_id" => $shopId,
"life_account_id" => $spuData["life_account_id"],
"publish_user_id" => $spuData["publish_user_id"],
"goods_name" => $spuData["marketing_name"],
"desc_pic_url" => $spuData["desc_pic_url"],
"desc" => $spuData["desc"],
"goods_type" => empty($spuData["goods_type"]) ? GoodsSpu::TYPE_VIRTUAL : $spuData["goods_type"],
"goods_sub_type" => empty($spuData["goods_sub_type"]) ? GoodsSpu::SUB_TYPE_TO_SHOP : $spuData["goods_sub_type"],
"belong_type" => empty($spuData["belong_type"]) ? GoodsSpu::BELONG_TYPE_DISANFANG : $spuData["belong_type"],
"goods_sale_type" => empty($spuData["setmeal"]) ? GoodsSpu::SALE_TYPE_NO_COMBINATION : GoodsSpu::SALE_TYPE_COMBINATION,
"rule_limit" => $spuData["rule_limit"],
"rule_desc" => $spuData["rule_desc"],
"rule_refund" => $spuData["rule_refund"],
];
GoodsSpu::save($spuParams);
return $spuParams;
}
/**
* 添加拼单活动sku
* @param $spuData
* @param $shopId
* @param array $skuData
* @return string
* @throws GoodsException
* @throws \App\Exception\custom\CodeSpecialException
*/
private static function addGoodsSku($spuData, $shopId, $skuData = [])
{
$pindanSku = PindanGoodsSku::get("pindan_goods_sku_id", ["goods_name" => $skuData["goods_name"]
, "life_account_id" => $skuData["life_account_id"]]);
if (!empty($pindanSku)) {
throw new GoodsException(['cus' => 17]);
}
$res = GoodsService::getIdgenId(substr($shopId, -2), "goods");
if (empty($res)) {
throw new GoodsException(['cus' => 2]);
}
$skuId = GoodsSkuId::generateGoodSkuId($res[0], 0, 0, $spuData["goods_type"], $spuData["belong_type"]);
if ($skuData["price"] <= 0) {
throw new GoodsException(['cus' => 33]);
}
if ($skuData["price"] > 50000) {
throw new GoodsException(['cus' => 34]);
}
$checkGoodsName = GoodsService::isHaveSensitive($skuData["goods_name"], 1);
if ($checkGoodsName) {
throw new GoodsException(['cus' => 19]);
}
$checkGoodsDesc = GoodsService::isHaveSensitive($skuData["desc"], 2);
if ($checkGoodsDesc) {
throw new GoodsException(['cus' => 20]);
}
$skuParams = [
"pindan_goods_sku_id" => $skuId,
"goods_spu_id" => $spuData["goods_spu_id"],
"life_account_id" => $skuData["life_account_id"],
"publish_user_id" => empty($skuData["publish_user_id"]) ? "" : $skuData["publish_user_id"],
"ota_id" => $skuData["ota_id"],
"category_1_id" => 0,
"category_2_id" => 0,
"goods_name" => $skuData["goods_name"],
"desc_pic_url" => $skuData["desc_pic_url"],
"desc" => $skuData["desc"],
"inventory_total" => $skuData["inventory"],
"inventory_rest" => $skuData["inventory"],
"original_price" => empty($skuData["original_price"]) ? "" : $skuData["original_price"] * 100,
"price" => $skuData["price"] * 100,
"audit_status" => PindanGoodsSku::STATUS_PASS,
"online_status" => PindanGoodsSku::ONLINE_STATUS_ONLINE,
];
$res = PindanGoodsSku::save($skuParams);
if ($res === false) {
GoodsSpu::rollback();
throw new GoodsException(["cus" => 0]);
}
GoodsService::addGoodsSkuPicRecord($skuId, $skuData);
return $skuId;
}
}
\ No newline at end of file
...@@ -17,6 +17,8 @@ use Daemon\Goods; ...@@ -17,6 +17,8 @@ use Daemon\Goods;
class MarketingService class MarketingService
{ {
const PUBLIC_LIFE_ACCOUNT_ID = 111;
/** /**
* op 后台获取活动需要参加的商品 * op 后台获取活动需要参加的商品
* *
...@@ -369,13 +371,13 @@ class MarketingService ...@@ -369,13 +371,13 @@ class MarketingService
$endTime = !empty($params['end_time']) ? $params['end_time'] : ''; $endTime = !empty($params['end_time']) ? $params['end_time'] : '';
$type = Marketing::MARKETING_TYPE_PINDAN; $type = Marketing::MARKETING_TYPE_PINDAN;
$goodsSkuId = !empty($params['goods_sku_id']) ? explode(",", $params['goods_sku_id']) : []; $goodsSkuId = !empty($params['goods_sku_id']) ? explode(",", $params['goods_sku_id']) : [];
$publishLifeAccountId = 111; $publicLifeAccountId = self::PUBLIC_LIFE_ACCOUNT_ID;
//重复判断 //重复判断
$marketing = Marketing::getRecord(["marketing_name" => $marketingName], ["marketing_id"]); $marketing = Marketing::getRecord(["marketing_name" => $marketingName], ["marketing_id"]);
if (!empty($marketing)) { if (!empty($marketing)) {
$marketingPindan = MarketingPindan::getRecord(["marketing_id" => $marketing["marketing_id"]]); $marketingPindan = MarketingPindan::getRecord(["marketing_id" => $marketing["marketing_id"]]);
if (!empty($marketingPindan) && $publishLifeAccountId == $marketingPindan["publish_life_account_id"]) { if (!empty($marketingPindan) && $publicLifeAccountId == $marketingPindan["publish_life_account_id"]) {
throw new MarketingException(['cus' => 18]); throw new MarketingException(['cus' => 18]);
} }
} }
...@@ -415,7 +417,7 @@ class MarketingService ...@@ -415,7 +417,7 @@ class MarketingService
$pindanParams = [ $pindanParams = [
"marketing_id" => $marketingId, "marketing_id" => $marketingId,
"publish_life_account_id" => $publishLifeAccountId, "publish_life_account_id" => $publicLifeAccountId,
"pindan_pic" => $pindanPic, "pindan_pic" => $pindanPic,
"pindan_desc" => $pindanDesc, "pindan_desc" => $pindanDesc,
"min_price" => $minPrice, "min_price" => $minPrice,
...@@ -470,7 +472,6 @@ class MarketingService ...@@ -470,7 +472,6 @@ class MarketingService
*/ */
private static function updatePindanMarketing($params) private static function updatePindanMarketing($params)
{ {
$publishLifeAccountId = 111;
$marketingId = $params["marketing_id"]; $marketingId = $params["marketing_id"];
//重复判断 //重复判断
$marketing = Marketing::getRecord(["marketing_id" => $marketingId]); $marketing = Marketing::getRecord(["marketing_id" => $marketingId]);
......
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