Commit 4a6aeffd authored by suntengda's avatar suntengda

Merge branch 'colonel' into develop

parent f9ec77e6
......@@ -22,4 +22,9 @@ class MarketingOnlineStatusValidate extends BaseValidate
"marketing_type" => "marketing_type 不能为空",
"online_status" => "online_status 不能为空",
];
public function sceneYingxiao()
{
return $this->only(['marketing_id','online_status']);
}
}
\ No newline at end of file
......@@ -14,6 +14,8 @@ class Marketing extends MysqlBase
const MARKETING_TYPE_TUANGOU = 2;
const MARKETING_TYPE_MIAOSHA = 3;
const MARKETING_TYPE_PINDAN = 4;
const MARKETING_TYPE_LIEBIAN = 5;
const MARKETING_TYPE_TUANZHANG = 6;
const ONLINE_STATUS_QIDONG = 1;
const ONLINE_STATUS_GUANBI = 2;
......@@ -125,6 +127,10 @@ class Marketing extends MysqlBase
$data['online_status'] = $where['online_status'];
}
if (!empty($where['marketing_type'])) {
$data['marketing_type'] = $where['marketing_type'];
}
return $data;
}
}
......@@ -155,4 +155,25 @@ class MarketingController extends Base
$this->success();
}
/**
* 切换活动状态
* @throws \App\Exception\custom\ParamException
*/
public function toogle_yingxiao_online_statusAction()
{
(new MarketingOnlineStatusValidate())->scene('yingxiao')->validate();
$res = MarketingService::toogleOnlineStatus($this->params['marketing_id'],$this->params['online_status']);
$this->success(['result' => $res]);
}
/**
* 营销中心-活动列表
* @throws Exception
*/
public function yingxiao_listAction()
{
$lists = MarketingService::yingxiaoList($this->params);
$this->success(['result' => $lists]);
}
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ namespace App\Services\marketing;
use Api\PhpServices\Ksy\Ks3Api;
use Api\PhpUtils\Http\HttpUtil;
use App\Exception\custom\InterfaceException;
use Api\PhpUtils\Http\Request;
use App\Models\goods\mysql\Ota;
use App\Models\goods\mysql\PindanGoodsSku;
use App\Models\marketing\mysql\Marketing;
......@@ -147,6 +148,47 @@ class MarketingService
}
}
/**
* 营销中心-活动列表
* @param $params
* @return array
*/
public static function yingxiaoList($params)
{
$where["marketing_type"] = [Marketing::MARKETING_TYPE_LIEBIAN, Marketing::MARKETING_TYPE_TUANZHANG];
$where['ORDER'] = ["create_time" => "DESC"];
$lists = Marketing::getRecords($where);
if ($lists && is_array($lists)) {
$capitalPoolIds = array_column($lists, 'capital_pool_id');
//获取资金池列表信息
$url = config('interface', 'coupon.capitalpool.fetch_map_capitalpool');
$capitalPoolList = (new Request())->get($url, ["capital_pool_ids" => $capitalPoolIds]);
$capitalPoolList = $capitalPoolList['response']['result'] ?: [];
$poolTotal = $poolUsed = $poolLock = 0;
foreach ($lists as &$val) {
if($capitalPoolList[$val['capital_pool_id']]) {
$val['capital_pool'] = $capitalPoolList[$val['capital_pool_id']];
$poolTotal += $val['capital_pool']['capital_pool_total'];
$poolUsed += $val['capital_pool']['capital_pool_used'];
$poolLock += $val['capital_pool']['capital_pool_lock'];
}else {
$val['capital_pool'] = [];
}
$val['online_status_desc'] = Marketing::$onlineStatusDesc[$val['online_status']];
}
unset($val);
}
$poolbalance = $poolTotal - $poolUsed - $poolLock;
$poolAnalysis = ['total'=>$poolTotal,'used'=>$poolUsed,'lock'=>$poolLock,'balance'=>$poolbalance];
return ['anlysis'=>$poolAnalysis,'list' => $lists];
}
/**
* 分销活动列表
* @param $params
......@@ -504,26 +546,8 @@ class MarketingService
throw new GoodsException(['cus' => 48]);
}
}
}else{
//比例计算
if ($commissionMode == Marketing::COMMISSION_MODE_RATE) {
$commissionTotal = ($firstCommissionRate + $secondCommissionRate) / 10000 * $price;
if ($price < ($commissionTotal+$chargeFee)) {
throw new MarketingException(['cus'=>23]);
}
}
//固定金额
if ($commissionMode == Marketing::COMMISSION_MODE_FIXED) {
$commissionTotal = ($firstCommissionRate + $secondCommissionRate);
if ($price < ($commissionTotal+$chargeFee)) {
throw new MarketingException(['cus'=>23]);
}
}
}
$colums[$key]['marketing_id'] = $marketingId;
$colums[$key]['goods_spu_id'] = $value['goods_spu_id'];
$colums[$key]['goods_sku_id'] = $value['goods_sku_id'];
......@@ -850,6 +874,24 @@ class MarketingService
Marketing::updateRecord($marketingParams, ["marketing_id" => $marketingId, "marketing_type" => $marketingType]);
}
/**
* 切换活动状态
* @param $marketingId
* @param $onlineStatus
* @return \Api\PhpUtils\Mysql\MysqlBase
*/
public static function toogleOnlineStatus($marketingId,$onlineStatus)
{
if(!in_array($onlineStatus,array_keys(Marketing::$onlineStatusDesc))) {
return 0;
}
$data = [
'online_status' => $onlineStatus,
];
return Marketing::updateRecord($data, ["marketing_id" => $marketingId]);
}
/**
* 分销活动详情
* @param $params
......@@ -965,15 +1007,6 @@ 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]);
......@@ -986,19 +1019,6 @@ 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"]];
}
//后台展示所有购买的数量
$goodsSkuList[$key]["all_have_buy_goods_count"] = 0;
$allHaveBuyGoodsSkuIds = array_keys($allHaveBuyGoodsStatistics);
if (in_array($item["goods_sku_id"], $allHaveBuyGoodsSkuIds)) {
$goodsSkuList[$key]["all_have_buy_goods_count"] = $allHaveBuyGoodsStatistics[$item["goods_sku_id"]];
}
}
}
......
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