Commit 83829666 authored by luhongguang's avatar luhongguang

update: 活动详情接口调整

parent b3d2d4c6
......@@ -4,6 +4,8 @@
namespace App\Services\marketing;
use Api\PhpServices\Ksy\Ks3Api;
use Api\PhpUtils\Http\HttpUtil;
use App\Exception\custom\InterfaceException;
use App\Models\goods\mysql\Ota;
use App\Models\goods\mysql\PindanGoodsSku;
use App\Models\marketing\mysql\Marketing;
......@@ -951,6 +953,15 @@ class MarketingService
$info['marketing_info'] = $marketingData;
//有用户登录时候,当前用户购买的商品数量信息
$haveBuyGoodsStatistics = [];
if (!empty($params["user_id"])) {
$haveBuyGoodsStatistics = self::getHaveBuyGoodsStatistics(["user_id" => $params["user_id"], "marketing_id" => $marketingData["id"]]);
}
//活动中所有购买的商品数量信息
$allHaveBuyGoodsStatistics = self::getHaveBuyGoodsStatistics(["marketing_id" => $marketingData["id"]]);
if (!empty($goodsSkuList)) {
$otaIds = array_unique(array_column($goodsSkuList, "ota_id"));
$otas = Ota::select(["ota_id", "ota_name"], ["ota_id" => $otaIds]);
......@@ -963,6 +974,18 @@ class MarketingService
$goodsSkuList[$key]["ota_name"] = empty($otasData[$item["ota_id"]]["ota_name"]) ? "" : $otasData[$item["ota_id"]]["ota_name"];
$goodsSkuList[$key]["original_price"] = empty($item["original_price"]) ? '' : sprintf("%.2f", (int)$item["original_price"] / 100);
$goodsSkuList[$key]["price"] = sprintf("%.2f", $item["price"] / 100);
$goodsSkuList[$key]["have_buy_goods_count"] = 0;
//前端当前登录人的数据
$haveBuyGoodsSkuIds = array_keys($haveBuyGoodsStatistics);
if (in_array($item["goods_sku_id"], $haveBuyGoodsSkuIds)) {
$goodsSkuList[$key]["have_buy_goods_count"] = $haveBuyGoodsStatistics[$item["goods_sku_id"]];
}
//后台展示所有购买的数量
$allHaveBuyGoodsSkuIds = array_keys($allHaveBuyGoodsStatistics);
if (in_array($item["goods_sku_id"], $allHaveBuyGoodsSkuIds)) {
$goodsSkuList[$key]["all_have_buy_goods_count"] = $allHaveBuyGoodsStatistics[$item["goods_sku_id"]];
}
}
}
......@@ -1020,4 +1043,24 @@ class MarketingService
"count" => $count]], []);
return $res['id_snow'][$type] ?? [];
}
/**
* 指定活动的已购买商品统计
* @param array $params
* @return array|mixed
* @throws InterfaceException
*/
public static function getHaveBuyGoodsStatistics($params = [])
{
$url = config('interface', 'order.order.have_buy_order_statistics');
if (empty($url)) {
throw new InterfaceException(['cus' => 0]);
}
$res = HttpUtil::get($url, $params);
$data = [];
if ($res['code'] == 0 && isset($res['response']["result"])) {
$data = $res["response"]["result"];
}
return $data;
}
}
\ No newline at end of file
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