Commit ac2c46c4 authored by jianghaiming's avatar jianghaiming

Merge branch 'develop' of https://gitlab.yidian-inc.com/bp/goods into develop

parents 8d22fc43 91eb71b6
...@@ -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,22 +68,19 @@ class GoodsToInitController extends Cli ...@@ -67,22 +68,19 @@ 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 {
$lifeAccountInfo = $this->addCreateUnauthorized($userId);
} $lifeAccountId = empty($lifeAccountInfo["life_account_id"]) ? "" : $lifeAccountInfo["life_account_id"];
} else { $merchantId = empty($lifeAccountInfo["merchant_id"]) ? "" : $lifeAccountInfo["merchant_id"];
$lifeAccountId = $item["lifeAccountId"];
$merchantId = $this->getMerchantId($lifeAccountId);
} }
if (empty($merchantId)) { if (empty($lifeAccountId) || empty($merchantId)) {
// echo "生活号 ".$lifeAccountId." 没有对应的 merchant_id \n"; echo "add goods data, user_id: $userId 没有 life_account_id \n";
continue; continue;
} }
...@@ -90,6 +88,7 @@ class GoodsToInitController extends Cli ...@@ -90,6 +88,7 @@ class GoodsToInitController extends Cli
"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);
...@@ -98,13 +97,15 @@ class GoodsToInitController extends Cli ...@@ -98,13 +97,15 @@ class GoodsToInitController extends Cli
$res = ShopService::getIdgenId(substr($shopId, -2), 'goods'); $res = ShopService::getIdgenId(substr($shopId, -2), 'goods');
$subShopId = !empty($res[0]) ? $res[0] : ''; $subShopId = !empty($res[0]) ? $res[0] : '';
if (!empty($sub["lbs"])) {
$lbs = explode(",", $sub["lbs"]); $lbs = explode(",", $sub["lbs"]);
}
$data["sub_shop_id"] = $subShopId; $data["sub_shop_id"] = $subShopId;
$data["life_account_id"] = $lifeAccountId; $data["life_account_id"] = $lifeAccountId;
$data["shop_id"] = $shopId; $data["shop_id"] = $shopId;
$data["shop_name"] = $sub["shopName"]; $data["shop_name"] = $sub["shopName"];
$data["longitude"] = $lbs[0]; $data["longitude"] = empty($lbs[0]) ? "" : $lbs[0];
$data["latitude"] = $lbs[1]; $data["latitude"] = empty($lbs[1]) ? "" : $lbs[1];
$data["address"] = $sub["address"]; $data["address"] = $sub["address"];
$data["phone"] = $sub["phone"]; $data["phone"] = $sub["phone"];
...@@ -128,7 +129,6 @@ class GoodsToInitController extends Cli ...@@ -128,7 +129,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"];
} }
...@@ -145,8 +145,18 @@ class GoodsToInitController extends Cli ...@@ -145,8 +145,18 @@ class GoodsToInitController extends Cli
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 +165,7 @@ class GoodsToInitController extends Cli ...@@ -155,7 +165,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 +175,21 @@ class GoodsToInitController extends Cli ...@@ -165,18 +175,21 @@ 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"];
$merchantId = $accountRes["merchant_id"];
} else {
$lifeAccountInfo = $this->addCreateUnauthorized($userId);
$lifeAccountId = $lifeAccountInfo["life_account_id"];
$merchantId = $lifeAccountInfo["merchant_id"];
} }
$lifeAccountId = $item["lifeAccountId"]; if (empty($lifeAccountId)) {
$merchantId = $this->getMerchantId($lifeAccountId); echo "add goods data, user_id: $userId 没有 life_account_id \n";
if (empty($merchantId)) {
// echo "生活号 ".$lifeAccountId." 没有对应的 merchant_id \n";
continue; continue;
} }
$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 +208,7 @@ class GoodsToInitController extends Cli ...@@ -195,7 +208,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 +280,9 @@ class GoodsToInitController extends Cli ...@@ -267,9 +280,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, ",");
......
...@@ -331,10 +331,20 @@ class GoodsService ...@@ -331,10 +331,20 @@ class GoodsService
$goodsSkuId = $sku["goods_sku_id"]; $goodsSkuId = $sku["goods_sku_id"];
$rejectedReason = empty($params["rejected_reason"]) ? "" : $params["rejected_reason"]; $rejectedReason = empty($params["rejected_reason"]) ? "" : $params["rejected_reason"];
GoodsSku::save([ if ($status == GoodsSku::STATUS_PASS) {
$statusData = [
"online_status" => GoodsSku::ONLINE_STATUS_ONLINE,
"audit_status" => $status, "audit_status" => $status,
"rejected_reason" => $rejectedReason "rejected_reason" => $rejectedReason
], ["goods_sku_id" => $sku["goods_sku_id"]]); ];
} else {
$statusData = [
"audit_status" => $status,
"rejected_reason" => $rejectedReason
];
}
GoodsSku::save($statusData, ["goods_sku_id" => $sku["goods_sku_id"]]);
//商品操作记录 //商品操作记录
$record = [ $record = [
...@@ -853,11 +863,11 @@ class GoodsService ...@@ -853,11 +863,11 @@ class GoodsService
if (!empty($params["life_account_id"])) { if (!empty($params["life_account_id"])) {
$where["life_account_id"] = $params["life_account_id"]; $where["life_account_id"] = $params["life_account_id"];
} }
if (!empty($params["audit_status"])) { if (!empty($params["audit_status"]) || (isset($params["audit_status"]) && $params["audit_status"] == 0)) {
$status = explode(",", $params["audit_status"]); $status = explode(",", $params["audit_status"]);
$where["audit_status"] = $status; $where["audit_status"] = $status;
} }
if (!empty($params["online_status"])) { if (!empty($params["online_status"]) || (isset($params["online_status"]) && $params["online_status"] == 0)) {
$onlineStatus = explode(",", $params["online_status"]); $onlineStatus = explode(",", $params["online_status"]);
$where["online_status"] = $onlineStatus; $where["online_status"] = $onlineStatus;
} }
......
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