Commit 400bb296 authored by luhongguang's avatar luhongguang

update:导商品数据脚本

parent e553537f
<?php <?php
use Api\PhpUtils\Common\GoodsSkuId;
use Api\PhpUtils\Http\Request; use Api\PhpUtils\Http\Request;
use App\Base\Cli; use App\Base\Cli;
use App\Exception\custom\GoodsException;
use App\Exception\custom\InterfaceException; use App\Exception\custom\InterfaceException;
use App\Models\goods\mysql\GoodsSku;
use App\Models\goods\mysql\GoodsSpu;
use \App\Models\tmp\mysql\QyqTicketData; use \App\Models\tmp\mysql\QyqTicketData;
use \App\Services\goods\GoodsService;
use \App\Services\shop\ShopService;
use \App\Models\shop\mysql\SubShop;
use \App\Models\shop\mysql\Shop;
/** /**
* 导入老商品数据 * 导入老商品数据
...@@ -15,20 +23,16 @@ class GoodsToInitController extends Cli ...@@ -15,20 +23,16 @@ class GoodsToInitController extends Cli
public function runAction() public function runAction()
{ {
$total = $this->getDataCount(); $total = $this->getDataCount();
$pageSize = 10; $pageSize = 100;
$pageTotal = floor($total/$pageSize) + 1; $pageTotal = floor($total / $pageSize) + 1;
for ($i = 0; $i <= $pageTotal; $i++) { for ($i = 0; $i <= $pageTotal; $i++) {
echo $i."\n"; echo $i . "\n";
$list = $this->getDataList($i, $pageSize); $list = $this->getDataList($i, $pageSize);
foreach ($list as $item) { //处理 shop 数据
$lifeAccountId = $item["life_account_id"]; $this->dealShopData($list);
$merchantId = $this->getMerchantId($lifeAccountId); //处理商品数据
if (empty($merchantId)) { $this->dealGoodsData($list);
echo "生活号 ".$lifeAccountId." 没有对应的 merchant_id \n";
continue;
}
}
} }
} }
...@@ -38,7 +42,8 @@ class GoodsToInitController extends Cli ...@@ -38,7 +42,8 @@ class GoodsToInitController extends Cli
*/ */
private function getDataCount() private function getDataCount()
{ {
return QyqTicketData::count([]); $where["lifeAccountId[>]"] = 0;
return QyqTicketData::count([], $where);
} }
/** /**
...@@ -50,6 +55,7 @@ class GoodsToInitController extends Cli ...@@ -50,6 +55,7 @@ class GoodsToInitController extends Cli
private function getDataList($page, $limit) private function getDataList($page, $limit)
{ {
$from = $page * $limit; $from = $page * $limit;
$where["lifeAccountId[>]"] = 0;
$where["LIMIT"] = [$from, $limit]; $where["LIMIT"] = [$from, $limit];
return QyqTicketData::select("*", $where); return QyqTicketData::select("*", $where);
} }
...@@ -57,9 +63,48 @@ class GoodsToInitController extends Cli ...@@ -57,9 +63,48 @@ class GoodsToInitController extends Cli
/** /**
* 脚本第一步,把所有的 * 脚本第一步,把所有的
*/ */
private function dealShopData() private function dealShopData($list)
{ {
echo "开始处理 shop 数据 \n";
foreach ($list as $item) {
if (empty($item["lifeAccountId"])) {
// echo $item["userId"] . "没有生活号id \n";
continue;
}
$lifeAccountId = $item["lifeAccountId"];
$merchantId = $this->getMerchantId($lifeAccountId);
if (empty($merchantId)) {
// echo "生活号 ".$lifeAccountId." 没有对应的 merchant_id \n";
continue;
}
$lifeAccount = [
"life_account_id" => $lifeAccountId,
"merchant_id" => $merchantId,
];
$shopId = GoodsService::addShop($lifeAccount);
echo "当前正在处理店铺id: $shopId \n";
$subShop = json_decode($item["shopJson"], true);
if (!empty($subShop)) {
foreach ($subShop as $sub) {
$res = ShopService::getIdgenId(substr($shopId, -2), 'goods');
$subShopId = !empty($res[0]) ? $res[0] : '';
$lbs = explode(",", $sub["lbs"]);
$data["sub_shop_id"] = $subShopId;
$data["life_account_id"] = $lifeAccountId;
$data["shop_id"] = $shopId;
$data["shop_name"] = $sub["shopName"];
$data["longitude"] = $lbs[0];
$data["latitude"] = $lbs[1];
$data["address"] = $sub["address"];
$data["phone"] = $sub["phone"];
$this->addSubShop($data);
}
}
}
echo "门店数据处理完成 \n";
} }
/** /**
...@@ -79,4 +124,136 @@ class GoodsToInitController extends Cli ...@@ -79,4 +124,136 @@ class GoodsToInitController extends Cli
return empty($lifeAccountRes["response"]["result"]["merchant_id"]) ? "" : $lifeAccountRes["response"]["result"]["merchant_id"]; return empty($lifeAccountRes["response"]["result"]["merchant_id"]) ? "" : $lifeAccountRes["response"]["result"]["merchant_id"];
} }
/**
* 添加门店数据
* @param $data
*/
private function addSubShop($data)
{
$subShop = SubShop::getRecord(["life_account_id"=>$data["life_account_id"], "shop_name"=>$data["shop_name"]]);
if (empty($subShop)) {
SubShop::save($data);
}
}
private function dealGoodsData($list)
{
echo "开始 goods 数据处理 \n";
foreach ($list as $item) {
if (empty($item["lifeAccountId"])) {
echo $item["userId"] . "没有生活号id \n";
continue;
}
$lifeAccountId = $item["lifeAccountId"];
$merchantId = $this->getMerchantId($lifeAccountId);
if (empty($merchantId)) {
// echo "生活号 ".$lifeAccountId." 没有对应的 merchant_id \n";
continue;
}
$shopInfo = Shop::getRecord(["life_account_id"=>$lifeAccountId]);
$shopId = $shopInfo["shop_id"];
$res = GoodsService::getIdgenId(substr($shopId, -2), "goods", 2);
if (empty($res)) {
throw new GoodsException(['cus' => 2]);
}
$categoryOneId = 1;
$categoryTwoId = 13;
$goodsSpuId = $res[0];
$goodsSkuId = GoodsSkuId::generateGoodSkuId($res[1], $categoryOneId, $categoryTwoId, 1);
$publicUserId = $item["userId"];
$goodsName = $item["title"];
$descPicUrl = "";
if (!empty($item["images"])) {
$images = explode(",", $item["images"]);
foreach ($images as $image) {
$descPicUrl .= "https://qn.zhiyueapp.cn/".$image.",";
}
$descPicUrl = trim($descPicUrl, ",");
}
$desc = $item["desc"];
$introduce = $item["introduce"];
$introducePicUrl = $item["productImages"];
$expirationTime = $item["outDate"];
$ruleLimit = $item["canBuy"];
$ruleDesc = $item["ruleIntroduce"];
$ruleRefund = $item["useRule"];
$ruleDateType = $item["holidayUse"] == 0 ? 2 : 1;
$ruleStartTime = $item["starTime"];
$ruleEndTime = $item["endTime"];
$inventoryTotal = $item["buyCount"];
$inventoryRest = $item["buyCount"];
$totalAmountOrder = $item["sellCount"];
$originalPrice = $item["price"] * 100;
$price = $item["rawPrice"] * 100;
$spuParams = [
"goods_spu_id" => $goodsSpuId,
"shop_id" => $shopId,
"life_account_id" => $lifeAccountId,
"publish_user_id" => $publicUserId,
"goods_name" => $goodsName,
"desc_pic_url" => $descPicUrl,
"desc" => $desc,
"goods_type" => GoodsSpu::TYPE_VIRTUAL,
"goods_sub_type" => GoodsSpu::SUB_TYPE_TO_SHOP,
"goods_sale_type" => GoodsSpu::SALE_TYPE_NO_COMBINATION,
"rule_limit" => $ruleLimit,
"rule_desc" => $ruleDesc,
"rule_refund" => $ruleRefund,
];
GoodsSpu::save($spuParams);
$skuParams = [
"goods_sku_id" => $goodsSkuId,
"goods_spu_id" => $goodsSpuId,
"life_account_id" => $lifeAccountId,
"shop_id" => $shopId,
"publish_user_id" => $publicUserId,
"category_1_id" => $categoryOneId,
"category_2_id" => $categoryTwoId,
"goods_name" => $goodsName,
"desc_pic_url" => $descPicUrl,
"desc" => $desc,
"introduce" => $introduce,
"introduce_pic_url" => $introducePicUrl,
"expiration_time" => $expirationTime,
"rule_limit" => $ruleLimit,
"rule_desc" => $ruleDesc,
"rule_refund" => $ruleRefund,
"rule_date_type" => $ruleDateType,
"rule_start_time" => $ruleStartTime,
"rule_end_time" => $ruleEndTime,
"inventory_total" => $inventoryTotal,
"inventory_rest" => $inventoryRest,
"total_amount_order" => $totalAmountOrder,
"total_amount_sold" => $totalAmountOrder,
"original_price" => $originalPrice,
"price" => $price,
"is_import" => 1,
];
GoodsSku::save($skuParams);
$subShop = json_decode($item["shopJson"], true);
if (!empty($subShop)) {
$subShopIdStr = "";
foreach ($subShop as $sub) {
$subShopId = SubShop::select("sub_shop_id", ["life_account_id"=>$lifeAccountId, "shop_name"=>$sub["shopName"]]);
if (!empty($subShopId)) {
$subShopIdStr .= $subShopId[0].",";
}
}
$subShopIdStr = trim($subShopIdStr, ",");
}
if (!empty($subShopIdStr)) {
GoodsService::addDealSubShopList($subShopIdStr, $shopId, $goodsSkuId);
}
}
echo "完成 goods 数据处理 \n";
}
} }
\ No newline at end of file
...@@ -222,7 +222,7 @@ class GoodsService ...@@ -222,7 +222,7 @@ class GoodsService
* @return mixed * @return mixed
* @throws GoodsException * @throws GoodsException
*/ */
private static function addShop($lifeAccount) public static function addShop($lifeAccount)
{ {
$lifeAccountId = $lifeAccount["life_account_id"]; $lifeAccountId = $lifeAccount["life_account_id"];
$shop = Shop::getRecordMaster(['life_account_id' => $lifeAccountId]); $shop = Shop::getRecordMaster(['life_account_id' => $lifeAccountId]);
...@@ -251,7 +251,7 @@ class GoodsService ...@@ -251,7 +251,7 @@ class GoodsService
* @param $shopId * @param $shopId
* @param $skuId * @param $skuId
*/ */
private static function addDealSubShopList($subShopIdStr, $shopId, $skuId) public static function addDealSubShopList($subShopIdStr, $shopId, $skuId)
{ {
if (!empty($subShopIdStr)) { if (!empty($subShopIdStr)) {
$subShopIds = explode(",", $subShopIdStr); $subShopIds = explode(",", $subShopIdStr);
......
...@@ -7,6 +7,9 @@ application.dispatcher.throwException = true ...@@ -7,6 +7,9 @@ application.dispatcher.throwException = true
daemon.script_dir = "\\Daemon\\" daemon.script_dir = "\\Daemon\\"
appid = "goods" appid = "goods"
idgen.partner = "bp"
idgen.key = "5cfdb867e96374c7883b31d6928cc4cb"
[product : common] [product : common]
[pre : common ] [pre : common ]
[test: common ] [test: common ]
......
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