Commit c13aa806 authored by luhongguang's avatar luhongguang

update:goods init 脚本

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