|
@@ -16,7 +16,7 @@ import Dynamic from "./Dynamic"
|
|
|
import Material from "./Material"
|
|
|
import MaterialText from "./MaterialText"
|
|
|
import PageList from "./PageList"
|
|
|
-import { cartesianProduct, randomString } from "@/utils/utils"
|
|
|
+import { cartesianProduct, distributeArray, randomString } from "@/utils/utils"
|
|
|
import columns from "./tableConfig"
|
|
|
import SubmitModal from "./submitModal"
|
|
|
import { createAdgroupTaskApi, getSelectTaskDetailApi } from "@/services/adqV3"
|
|
@@ -33,7 +33,7 @@ const Create: React.FC = () => {
|
|
|
/*******************************************/
|
|
|
const { getAllUserAccount } = useModel('useLaunchAdq.useAdAuthorize')
|
|
|
const { initTargeting } = useModel('useLaunchV3.useTargeting')
|
|
|
- const [addelivery, setAddelivery] = useState<PULLIN.AddeliveryProps>({ adgroups: {}, targeting: [], dynamic: {}, dynamicMaterialDTos: {}, dynamicCreativesTextDTOS: {} })
|
|
|
+ const [addelivery, setAddelivery] = useState<PULLIN.AddeliveryProps>({ adgroups: {}, targeting: [], dynamic: {}, dynamicMaterialDTos: {}, dynamicCreativesTextDTOS: {}, mediaType: 0 })
|
|
|
const { marketingAssetOuterSpec, marketingCarrierType } = addelivery.adgroups
|
|
|
const [accSearch, setAccSearch] = useState<string>()
|
|
|
const [accountCreateLogs, setAccountCreateLogs] = useState<PULLIN.AccountCreateLogsProps[]>([]) // 账户
|
|
@@ -79,7 +79,7 @@ const Create: React.FC = () => {
|
|
|
})
|
|
|
setAccountCreateLogs(userArr?.map((item) => ({ accountId: item?.accountId })))
|
|
|
clearData()
|
|
|
- setAddelivery({ adgroups: {}, targeting: [], dynamic: {}, dynamicMaterialDTos: {}, dynamicCreativesTextDTOS: {} })
|
|
|
+ setAddelivery({ adgroups: {}, targeting: [], dynamic: {}, dynamicMaterialDTos: {}, dynamicCreativesTextDTOS: {}, mediaType: 0 })
|
|
|
} else {
|
|
|
message.error('操作异常')
|
|
|
}
|
|
@@ -112,7 +112,8 @@ const Create: React.FC = () => {
|
|
|
targeting: [],
|
|
|
dynamic: {},
|
|
|
dynamicMaterialDTos: {},
|
|
|
- dynamicCreativesTextDTOS: {}
|
|
|
+ dynamicCreativesTextDTOS: {},
|
|
|
+ mediaType: 0
|
|
|
})
|
|
|
setTableData({})
|
|
|
}
|
|
@@ -125,7 +126,7 @@ const Create: React.FC = () => {
|
|
|
getSelectTaskDetail.run(taskId).then(res => {
|
|
|
console.log(res)
|
|
|
if (res) {
|
|
|
- const { adgroupDTO, accountIdParamVOMap, targetings, dynamicCreativesDTO, dynamicCreativesTextDTO, dynamicMaterialDTOS } = res
|
|
|
+ const { adgroupDTO, accountIdParamVOMap, targetings, dynamicCreativesDTO: { mediaType, ...dynamic }, dynamicCreativesTextDTO, dynamicMaterialDTOS } = res
|
|
|
let beginDate = adgroupDTO.beginDate
|
|
|
let endDate = adgroupDTO.endDate
|
|
|
if (beginDate && moment(beginDate) < moment()) {
|
|
@@ -134,7 +135,7 @@ const Create: React.FC = () => {
|
|
|
message.warning('请注意,检测投放开始日期小于今天,已自动改成今天,如需修改,请重新设置')
|
|
|
}
|
|
|
let dynamicGroup: any[] = []
|
|
|
- if (dynamicCreativesDTO.deliveryMode === 'DELIVERY_MODE_CUSTOMIZE') {
|
|
|
+ if (dynamic.deliveryMode === 'DELIVERY_MODE_CUSTOMIZE') {
|
|
|
dynamicGroup = dynamicMaterialDTOS?.map((item: any[]) => {
|
|
|
let { type, valueJson } = item[0]
|
|
|
let value = JSON.parse(valueJson).value
|
|
@@ -162,9 +163,10 @@ const Create: React.FC = () => {
|
|
|
const { targetingName, ...targeting } = item
|
|
|
return { targetingName, targeting }
|
|
|
}),
|
|
|
- dynamic: dynamicCreativesDTO,
|
|
|
+ dynamic,
|
|
|
dynamicMaterialDTos: dynamicGroup.length > 0 ? { dynamicGroup } : {},
|
|
|
- dynamicCreativesTextDTOS: dynamicCreativesTextDTO
|
|
|
+ dynamicCreativesTextDTOS: dynamicCreativesTextDTO,
|
|
|
+ mediaType: mediaType || 0
|
|
|
})
|
|
|
setAccountCreateLogs(Object.keys(accountIdParamVOMap || {}).map(accountId => {
|
|
|
const { productDTOS, wechatOfficialAccountsVO, pageList, userActionSetsList } = accountIdParamVOMap[accountId]
|
|
@@ -213,7 +215,7 @@ const Create: React.FC = () => {
|
|
|
message.error('请先选择媒体账户')
|
|
|
return
|
|
|
}
|
|
|
- const { adgroups, targeting, dynamic, dynamicMaterialDTos, dynamicCreativesTextDTOS } = addelivery
|
|
|
+ const { adgroups, targeting, dynamic, dynamicMaterialDTos, dynamicCreativesTextDTOS, mediaType } = addelivery
|
|
|
if (!(adgroups && Object.keys(adgroups).length)) {
|
|
|
message.error('请先配置广告信息')
|
|
|
return
|
|
@@ -249,6 +251,54 @@ const Create: React.FC = () => {
|
|
|
|
|
|
let newTableData: any = {}
|
|
|
let newAdCount = 0, newdynamicCount = 0
|
|
|
+ let textType = dynamicCreativesTextDTOS.type
|
|
|
+ let textDto = dynamicCreativesTextDTOS?.dynamicCreativesTextDetailDTOList || []
|
|
|
+ let textDtoLenth = textDto.length
|
|
|
+ let dynamicGroupLength = dynamicMaterialDTos?.dynamicGroup?.length || 0
|
|
|
+ let newDynamicGroup: any = []
|
|
|
+ if (![910].includes(dynamic.creativeTemplateId)) {
|
|
|
+ newDynamicGroup = dynamicMaterialDTos?.dynamicGroup || []
|
|
|
+ if (newDynamicGroup.length > 0 && [0, 1, 2, 3].includes(textType)) {
|
|
|
+ if (textType === 0) {
|
|
|
+ newDynamicGroup = newDynamicGroup.map((item: any) => ({ ...item, textDto: textDto?.[0] }))
|
|
|
+ } else if (textType === 1) {
|
|
|
+ newDynamicGroup = newDynamicGroup.map((item: any, index: number) => ({ ...item, textDto: textDto?.[index] }))
|
|
|
+ } else if (textType === 2) {
|
|
|
+ newDynamicGroup = newDynamicGroup.map((item: any, index: number) => ({ ...item, textDto: textDto?.[index % textDtoLenth] }))
|
|
|
+ } else if (textType === 3) {
|
|
|
+ if (mediaType === 0) {
|
|
|
+ newDynamicGroup = cartesianProduct(newDynamicGroup, textDto || [{}]).map((item) => {
|
|
|
+ let [dynamicGroup, textDtoData] = item
|
|
|
+ return {
|
|
|
+ ...dynamicGroup as any,
|
|
|
+ textDto: textDtoData
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创意组平均分配到广告逻辑
|
|
|
+ let averageAdDynamicList: any[] = []
|
|
|
+ if (mediaType === 1 && newDynamicGroup.length) {
|
|
|
+ let adLength = 0
|
|
|
+ accountCreateLogs.forEach(item => {
|
|
|
+ let productList: any[] = []
|
|
|
+ if (['MARKETING_TARGET_TYPE_FICTION'].includes(marketingAssetOuterSpec?.marketingTargetType)) { // 小说
|
|
|
+ productList = item?.productList || []
|
|
|
+ } else if (['MARKETING_TARGET_TYPE_WECHAT_OFFICIAL_ACCOUNT'].includes(marketingAssetOuterSpec?.marketingTargetType)) { // 公众号
|
|
|
+ productList = item?.wechatChannelList || []
|
|
|
+ }
|
|
|
+ adLength += productList.length * targeting.length
|
|
|
+ if (adLength > dynamicGroupLength) {
|
|
|
+ message.error(`创意组分配规则选择创意组平均分配到广告时,创意组总数必须大于等于广告总数。当前创意组数量:${dynamicGroupLength},广告数量:${adLength}`)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ averageAdDynamicList = distributeArray(newDynamicGroup, adLength)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ let accountIndex = 0
|
|
|
accountCreateLogs.forEach(item => {
|
|
|
let productList: any[] = []
|
|
|
if (['MARKETING_TARGET_TYPE_FICTION'].includes(marketingAssetOuterSpec?.marketingTargetType)) { // 小说
|
|
@@ -256,13 +306,11 @@ const Create: React.FC = () => {
|
|
|
} else if (['MARKETING_TARGET_TYPE_WECHAT_OFFICIAL_ACCOUNT'].includes(marketingAssetOuterSpec?.marketingTargetType)) { // 公众号
|
|
|
productList = item?.wechatChannelList || []
|
|
|
}
|
|
|
- let textType = dynamicCreativesTextDTOS.type
|
|
|
- let textDto = dynamicCreativesTextDTOS?.dynamicCreativesTextDetailDTOList || []
|
|
|
- let textDtoLenth = textDto.length
|
|
|
- let dynamicGroupLength = dynamicMaterialDTos?.dynamicGroup?.length || 0
|
|
|
+
|
|
|
let data = cartesianProduct(productList, targeting).map(newD => {
|
|
|
let [productDto, targetDto, index] = newD
|
|
|
let suffix = '_' + item.accountId + '_' + index
|
|
|
+ let averageAdDynamic = averageAdDynamicList?.[accountIndex]
|
|
|
let dat: any = {
|
|
|
id: item.accountId + '_' + index,
|
|
|
accountId: item.accountId, // 账户
|
|
@@ -278,11 +326,13 @@ const Create: React.FC = () => {
|
|
|
adgroupName: adgroups.adgroupName + suffix
|
|
|
},
|
|
|
dynamicDto: dynamic, // 创意信息
|
|
|
- rowSpan: ([910].includes(dynamic.creativeTemplateId) ? item.pageList?.length : (textType === 3 ? textDtoLenth * dynamicGroupLength : dynamicGroupLength)) || 1
|
|
|
+ averageAdDynamic,
|
|
|
+ rowSpan: mediaType === 1 ? averageAdDynamic.length : ([910].includes(dynamic.creativeTemplateId) ? item.pageList?.length : (textType === 3 ? textDtoLenth * dynamicGroupLength : dynamicGroupLength)) || 1
|
|
|
}
|
|
|
if (marketingCarrierType === 'MARKETING_CARRIER_TYPE_WECHAT_OFFICIAL_ACCOUNT') { // 营销载体
|
|
|
dat.marketingCarrierDto = item?.wechatChannelList
|
|
|
}
|
|
|
+ accountIndex += 1
|
|
|
return dat
|
|
|
})
|
|
|
|
|
@@ -302,33 +352,43 @@ const Create: React.FC = () => {
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
- let newDynamicGroup: any = dynamicMaterialDTos?.dynamicGroup || []
|
|
|
- if (newDynamicGroup.length > 0 && [0, 1, 2, 3].includes(textType)) {
|
|
|
- if (textType === 0) {
|
|
|
- newDynamicGroup = newDynamicGroup.map((item: any) => ({ ...item, textDto: textDto?.[0] }))
|
|
|
- } else if (textType === 1) {
|
|
|
- newDynamicGroup = newDynamicGroup.map((item: any, index: number) => ({ ...item, textDto: textDto?.[index] }))
|
|
|
- } else if (textType === 2) {
|
|
|
- newDynamicGroup = newDynamicGroup.map((item: any, index: number) => ({ ...item, textDto: textDto?.[index % textDtoLenth] }))
|
|
|
- } else if (textType === 3) {
|
|
|
- newDynamicGroup = cartesianProduct(newDynamicGroup, textDto || [{}]).map((item) => {
|
|
|
- let [dynamicGroup, textDtoData] = item
|
|
|
- return {
|
|
|
- ...dynamicGroup as any,
|
|
|
- textDto: textDtoData
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
+ if (mediaType === 1) {
|
|
|
+ data.forEach(item => {
|
|
|
+ const { averageAdDynamic, ...ad } = item
|
|
|
+ if (textType === 3) {
|
|
|
+ let rowSpan = textDtoLenth * averageAdDynamic.length
|
|
|
+ cartesianProduct(textDto, averageAdDynamic).forEach((taad: any, index) => {
|
|
|
+ let [textValue, aad] = taad
|
|
|
+ newData.push({
|
|
|
+ ...ad,
|
|
|
+ id: ad.id + '_' + index,
|
|
|
+ dynamicGroup: aad,
|
|
|
+ textDto: textValue,
|
|
|
+ rowSpan
|
|
|
+ })
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ averageAdDynamic.forEach((aad: any, index: number) => {
|
|
|
+ newData.push({
|
|
|
+ ...ad,
|
|
|
+ id: ad.id + '_' + index,
|
|
|
+ dynamicGroup: aad,
|
|
|
+ textDto: aad?.textDto
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ newData = cartesianProduct(data, newDynamicGroup.length > 0 ? newDynamicGroup : [{}]).map((item, index) => {
|
|
|
+ let [d1, group] = item
|
|
|
+ return {
|
|
|
+ ...d1,
|
|
|
+ id: d1.id + '_' + index,
|
|
|
+ dynamicGroup: group,
|
|
|
+ textDto: (group as any)?.textDto
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
- newData = cartesianProduct(data, newDynamicGroup.length > 0 ? newDynamicGroup : [{}]).map((item, index) => {
|
|
|
- let [d1, group] = item
|
|
|
- return {
|
|
|
- ...d1,
|
|
|
- id: d1.id + '_' + index,
|
|
|
- dynamicGroup: group,
|
|
|
- textDto: (group as any)?.textDto
|
|
|
- }
|
|
|
- })
|
|
|
}
|
|
|
|
|
|
newdynamicCount = newdynamicCount + newData.length
|
|
@@ -342,7 +402,7 @@ const Create: React.FC = () => {
|
|
|
}
|
|
|
|
|
|
const onSubmit = (values: any) => {
|
|
|
- const { adgroups, targeting, dynamic, dynamicMaterialDTos, dynamicCreativesTextDTOS } = addelivery
|
|
|
+ const { adgroups, targeting, dynamic, dynamicMaterialDTos, dynamicCreativesTextDTOS, mediaType } = addelivery
|
|
|
|
|
|
let dynamicMaterialDTOS = []
|
|
|
if ((materialData && Object.keys(materialData).length && dynamicMaterialDTos && Object.keys(dynamicMaterialDTos).length)) {
|
|
@@ -428,7 +488,7 @@ const Create: React.FC = () => {
|
|
|
...values,
|
|
|
adgroupDTO: adgroups,
|
|
|
targetings: targeting.map(item => ({ targetingName: item.targetingName, ...item?.targeting || {} })),
|
|
|
- dynamicCreativesDTO: dynamic,
|
|
|
+ dynamicCreativesDTO: { ...dynamic, mediaType },
|
|
|
dynamicCreativesTextDTOS,
|
|
|
dynamicMaterialDTOS,
|
|
|
accountIdParamDTOMap
|