Commit 392cf986 authored by 卢洪光's avatar 卢洪光

Merge branch 'tuancan_public' into 'pre_release'

拼单接入app

See merge request bp/goods!59
parents bca6245d dec1dbd0
......@@ -7,6 +7,8 @@ use App\Services\marketing\MarketingGoodsService;
use \Validate\MarketingGoodsRateValidate;
use \Validate\MarketingOnlineStatusValidate;
use \Validate\MarketingInfoValidate;
use App\Models\marketing\mysql\Marketing;
use App\Models\marketing\mysql\MarketingPindan;
class MarketingController extends Base
{
......@@ -155,6 +157,69 @@ class MarketingController extends Base
$this->success();
}
/**
* app内团餐活动列表
* @throws \App\Exception\custom\InterfaceException
*/
public function tuancan_listAction()
{
$this->params['marketing_type'] = Marketing::MARKETING_TYPE_PINDAN;//1分销 2团购 3秒杀 4团餐
$this->params['online_status'] = Marketing::ONLINE_STATUS_QIDONG;//状态 , 1启用,2关闭,3 到期
$this->params['from'] = 1;//1 小程序前台 默认0 后台
//正在进行中的 按结束时间正序
$this->params['sort_field'] = 'end_time';
$this->params['sort_type'] = 'asc';
$this->params['need_buy_num'] = false;
$this->params['activity_status'] = MarketingPindan::ACTIVITY_STATUS_IN_PROGRESS;//1 未开始,2进行中,3已结束
$list['doing'] = MarketingService::marketingList($this->params)['result'];
$list['doing'] = $list['doing'] ? array_column($list['doing'], null, 'marketing_id') : [];
$marketingIdsDoing = array_keys($list['doing']);
//当天即将开始的 按开始时间正序
$this->params['page'] = 1;
$this->params['sort_field'] = 'start_time';
$this->params['sort_type'] = 'asc';
$this->params['need_buy_num'] = false;
$this->params['activity_status'] = MarketingPindan::ACTIVITY_STATUS_START_TODAY;//1 未开始,2进行中,3已结束, 4当日上新(即将开始)
$list['prepare'] = MarketingService::marketingList($this->params)['result'];
$list['prepare'] = $list['prepare'] ? array_column((array)$list['prepare'], null, 'marketing_id') : [];
$marketingIdsPrepare = array_keys($list['prepare']);
//已结束的 按结束时间倒序
$this->params['page'] = 1;
$this->params['page_size'] = 10;
$this->params['sort_field'] = 'end_time';
$this->params['sort_type'] = 'desc';
$this->params['need_buy_num'] = false;
$this->params['online_status'] = [Marketing::ONLINE_STATUS_QIDONG, Marketing::ONLINE_STATUS_GUANBI, Marketing::ONLINE_STATUS_DAOQI];//状态 , 1启用,2关闭,3 到期
$this->params['activity_status'] = MarketingPindan::ACTIVITY_STATUS_FINISHED;//1 未开始,2进行中,3已结束, 4当日上新(即将开始)
$list['end'] = MarketingService::marketingList($this->params)['result'];
$list['end'] = $list['end'] ? array_column($list['end'], null, 'marketing_id') : [];
$marketingIdsEnd = array_keys($list['end']);
$marketingIds = array_merge($marketingIdsDoing, $marketingIdsPrepare, $marketingIdsEnd);
//获取活动的sku列表
$skuList = MarketingService::getGoodsSkuListByMarketingIds($marketingIds);
//获取活动支付用户列表
$orderUser = MarketingService::getMarketingOrderUser(['marketing_id' => $marketingIds]);
//获取活动支付用户数
$buyNum = MarketingService::getHaveBuyGoodsUserCount(['marketing_id' => $marketingIds]);
//组合sku和order信息
foreach ($list as &$listPart) {
foreach ($listPart as $marketingId => &$value) {
$value['sku_list'] = $skuList[$marketingId] ?? [];
$value['order_user'] = $orderUser[$marketingId] ?? [];
$value['participate_number'] = $buyNum[$marketingId] ?? 0;
}
unset($value);
$listPart = array_values($listPart);
}
unset($listPart);
$list['life_account_id'] = MarketingService::getPublicLifeAccountId();
$this->success(['result' => $list]);
}
/**
* 切换活动状态
* @throws \App\Exception\custom\ParamException
......
......@@ -1189,6 +1189,78 @@ class MarketingService
return $marketing_list;
}
/**
* 获取多个活动的商品列表
* @param $marketingIds
* @return array
* @throws InterfaceException
*/
public static function getGoodsSkuListByMarketingIds($marketingIds)
{
$marketingGoodsList = MarketingGoods::marketingGoodsList(['marketing_id' => $marketingIds, "ORDER" => ["id" => "ASC"]]);
$goodsSkuList = [];
if (!empty($marketingGoodsList)) {
$goodsSkuId = array_column($marketingGoodsList , 'goods_sku_id');
$goodsSkuList = PindanGoodsSku::select('*', ['goods_sku_id' => $goodsSkuId]);
$goodsSkuList = array_column((array)$goodsSkuList, null, "goods_sku_id");
}
$list = [];
if (!empty($goodsSkuList)) {
//活动sku购买数量
$soldNum = self::getHaveBuyGoodsStatistics(["marketing_id" => $marketingIds]);
//保持排序
foreach ($marketingGoodsList as $key => $value) {
if (empty($goodsSkuList[$value["goods_sku_id"]])) {
continue;
}
$list[$value['marketing_id']][$key] = $value;
$item = $goodsSkuList[$value["goods_sku_id"]];
$list[$value['marketing_id']][$key]['goods_name'] = $item['goods_name'];
$list[$value['marketing_id']][$key]["desc_pic_url_list"] = GoodsService::getUrlList($item["desc_pic_url"]);
$list[$value['marketing_id']][$key]["original_price"] = empty($item["original_price"]) ? '' : sprintf("%.2f", (int)$item["original_price"] / 100);
$list[$value['marketing_id']][$key]["price"] = sprintf("%.2f", $item["price"] / 100);
$list[$value['marketing_id']][$key]["all_have_buy_goods_count"] = $soldNum[$value["goods_sku_id"]] ?? 0;
$list[$value['marketing_id']][$key]['inventory_rest'] = $item['inventory_rest'];
}
//没有库存的放在最下面
foreach ($list as $marketingId => $item) {
foreach($item as $key=>$value) {
if ($value["inventory_rest"] == 0) {
unset($list[$marketingId][$key]);
array_push($list[$marketingId], $value);
}
}
$list[$marketingId] = array_values($list[$marketingId]);
}
}
return $list;
}
/**
* 获取活动支付用户列表
* @param $params
* @return array|mixed
* @throws InterfaceException
*/
public static function getMarketingOrderUser($params)
{
$url = config('interface', 'order.marketing.marketing_user');
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;
}
/**
*判断长度
*
......
......@@ -54,7 +54,8 @@ class Pindan implements DaemonServiceInterface
$params = [
self::emojiFilter($marketing['marketing_name']),
$marketing['start_time'],
$pindan['pindan_desc'] ?: self::DEFAULT_DESC
$pindan['pindan_desc'] ?: self::DEFAULT_DESC,
$marketing['marketing_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