Commit c13aa806 authored by luhongguang's avatar luhongguang

update:goods init 脚本

parent a0bdd0a2
......@@ -23,7 +23,7 @@ class GoodsToInitController extends Cli
public function runAction()
{
$total = $this->getDataCount();
$pageSize = 100;
$pageSize = 200;
$pageTotal = floor($total / $pageSize) + 1;
for ($i = 0; $i <= $pageTotal; $i++) {
......@@ -32,7 +32,7 @@ class GoodsToInitController extends Cli
//处理 shop 数据
$this->dealShopData($list);
//处理商品数据
$this->dealGoodsData($list);
// $this->dealGoodsData($list);
}
}
......@@ -42,7 +42,8 @@ class GoodsToInitController extends Cli
*/
private function getDataCount()
{
$where["lifeAccountId[>]"] = 0;
$where = [];
// $where["lifeAccountId[>]"] = 0;
return QyqTicketData::count([], $where);
}
......@@ -55,7 +56,7 @@ class GoodsToInitController extends Cli
private function getDataList($page, $limit)
{
$from = $page * $limit;
$where["lifeAccountId[>]"] = 0;
// $where["lifeAccountId[>]"] = 0;
$where["LIMIT"] = [$from, $limit];
return QyqTicketData::select("*", $where);
}
......@@ -67,29 +68,22 @@ class GoodsToInitController extends Cli
{
echo "开始处理 shop 数据 \n";
foreach ($list as $item) {
if (empty($item["lifeAccountId"])) {
$userId = $item["userId"];
$accountRes = $this->getLifeAccountIdAndMerchantId($userId);
if (!empty($accountRes)) {
$lifeAccountId = $accountRes["life_account_id"];
$merchantId = $accountRes["merchant_id"];
} else {
}
$userId = $item["userId"];
$accountRes = $this->getLifeAccountIdAndMerchantId($userId);
if (!empty($accountRes)) {
$lifeAccountId = $accountRes["life_account_id"];
$merchantId = $accountRes["merchant_id"];
} else {
$lifeAccountId = $item["lifeAccountId"];
$merchantId = $this->getMerchantId($lifeAccountId);
}
if (empty($merchantId)) {
// echo "生活号 ".$lifeAccountId." 没有对应的 merchant_id \n";
continue;
$lifeAccountInfo = $this->addCreateUnauthorized($userId);
$lifeAccountId = $lifeAccountInfo["life_account_id"];
$merchantId = $lifeAccountInfo["merchant_id"];
}
$lifeAccount = [
"life_account_id" => $lifeAccountId,
"merchant_id" => $merchantId,
];
$shopId = GoodsService::addShop($lifeAccount);
echo "当前正在处理店铺id: $shopId \n";
$subShop = json_decode($item["shopJson"], true);
......@@ -128,7 +122,6 @@ class GoodsToInitController extends Cli
throw new InterfaceException(['cus' => 0]);
}
$lifeAccountRes = (new Request())->get($url, ["life_account_id" => $lifeAccountId]);
return empty($lifeAccountRes["response"]["result"]["merchant_id"]) ? "" : $lifeAccountRes["response"]["result"]["merchant_id"];
}
......@@ -140,13 +133,24 @@ class GoodsToInitController extends Cli
*/
private function getLifeAccountIdAndMerchantId($userId)
{
sleep(1);
$url = config('interface', 'merchant.lifeaccount.get_lid_by_uid');
if (empty($url)) {
throw new InterfaceException(['cus' => 0]);
}
$res = (new Request())->get($url, ["uid" => $userId]);
return empty($res["response"]["result"]) ? [] : $res["response"]["result"][0];
}
return empty($res["response"]["result"][0]) ? [] : $res["response"]["result"][0];
private function addCreateUnauthorized($userId)
{
echo "add user_id: " . $userId . "\n";
$url = config('interface', 'merchant.life_account.create_unauthorized');
if (empty($url)) {
throw new InterfaceException(['cus' => 0]);
}
$res = (new Request())->get($url, ["user_id" => $userId]);
return empty($res["response"]["result"]) ? [] : $res["response"]["result"];
}
/**
......@@ -155,7 +159,7 @@ class GoodsToInitController extends Cli
*/
private function addSubShop($data)
{
$subShop = SubShop::getRecord(["life_account_id"=>$data["life_account_id"], "shop_name"=>$data["shop_name"]]);
$subShop = SubShop::getRecord(["life_account_id" => $data["life_account_id"], "shop_name" => $data["shop_name"]]);
if (empty($subShop)) {
SubShop::save($data);
}
......@@ -165,18 +169,18 @@ class GoodsToInitController extends Cli
{
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;
$userId = $item["userId"];
$accountRes = $this->getLifeAccountIdAndMerchantId($userId);
if (!empty($accountRes)) {
$lifeAccountId = $accountRes["life_account_id"];
$merchantId = $accountRes["merchant_id"];
} else {
$lifeAccountInfo = $this->addCreateUnauthorized($userId);
$lifeAccountId = $lifeAccountInfo["life_account_id"];
$merchantId = $lifeAccountInfo["merchant_id"];
}
$shopInfo = Shop::getRecord(["life_account_id"=>$lifeAccountId]);
$shopInfo = Shop::getRecord(["life_account_id" => $lifeAccountId]);
$shopId = $shopInfo["shop_id"];
$res = GoodsService::getIdgenId(substr($shopId, -2), "goods", 2);
......@@ -195,7 +199,7 @@ class GoodsToInitController extends Cli
if (!empty($item["images"])) {
$images = explode(",", $item["images"]);
foreach ($images as $image) {
$descPicUrl .= "https://qn.zhiyueapp.cn/".$image.",";
$descPicUrl .= "https://qn.zhiyueapp.cn/" . $image . ",";
}
$descPicUrl = trim($descPicUrl, ",");
}
......@@ -267,9 +271,9 @@ class GoodsToInitController extends Cli
if (!empty($subShop)) {
$subShopIdStr = "";
foreach ($subShop as $sub) {
$subShopId = SubShop::select("sub_shop_id", ["life_account_id"=>$lifeAccountId, "shop_name"=>$sub["shopName"]]);
$subShopId = SubShop::select("sub_shop_id", ["life_account_id" => $lifeAccountId, "shop_name" => $sub["shopName"]]);
if (!empty($subShopId)) {
$subShopIdStr .= $subShopId[0].",";
$subShopIdStr .= $subShopId[0] . ",";
}
}
$subShopIdStr = trim($subShopIdStr, ",");
......
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