Commit 85a127e5 authored by zhaofei's avatar zhaofei

s

parent f461f713
......@@ -2,7 +2,7 @@ import request from "./utils/request";
const API = {
// 上传数据生成xslx文件 uploadDataCreateFile
uploadDataCreateFile: (params) => request("exportAwardsList", "POST", params),
exportAwardsList: (params) => request("exportAwardsList", "POST", params),
// 保存活动配置 saveActivityInfo
saveActivityInfo: (params) => request("saveActivityInfo", "POST", params),
// 删除活动 delActivity
......@@ -32,10 +32,9 @@ const API = {
request("queryBenefitByEname", "POST", params),
// 复制创建新活动
createCopyActivity: (params) => request("createCopyActivity", "POST", params),
//搜索条件查询中奖信息
exportAwardsInfoBySearch: (params) => request("exportAwardsInfoBySearch", "POST", params),
findWinnerInfoListBySearch: (params) => request("findWinnerInfoListBySearch", "POST", params),
// 搜索条件查询中奖信息
downloadFile: (params) => request("downloadFile", "POST", params),
getAwardsList: (params) => request("getAwardsList", "POST", params),
};
export default API;
......@@ -8,17 +8,25 @@
<view class="probability-prize-content">
<view class="probability-prize-content-form">
<form inline="true">
<form-item
style="width:100%"
size="large"
class="probability-prize-content-formItem"
label="是否降级奖品"
validateState="{{nameTips.status}}" help="{{nameTips.content}}"
required>
</form-item>
<form-item style="width:100%" size="large" class="probability-prize-content-formItem" label="奖品类型" required>
<view class="probability-prize-content-formitem-choosePrize-wrap">
<select onChange="onPrizeTypeChange" defaultValue="{{isEdit ? prizeDialogData.record.type : prizeInitData.type}}">
<option a:if="{{typeChecked.includes(1)}}" value="{{1}}">优惠券</option>
<option a:if="{{typeChecked.includes(2)}}" value="{{2}}">积分</option>
<option a:if="{{typeChecked.includes(3)}}" value="{{3}}">实物</option>
<option a:if="{{typeChecked.includes(5)}}" value="{{5}}">降级奖品</option>
<!-- <option a:if="{{typeChecked.includes(5)}}" value="{{5}}">降级奖品</option> -->
</select>
</view>
</form-item>
<form-item a:if="{{[EQUITY_TYPE, LOWER_TYPE].includes(prizeInitData.type)}}" validateState="{{choosePrizeTips.status}}" style="width:100%" size="large" help="{{choosePrizeTips.content}}" class="probability-prize-content-formItem probability-prize-content-formItem-choosePrize" label="选择奖品" required>
<form-item a:if="{{[EQUITY_TYPE].includes(prizeInitData.type)}}" validateState="{{choosePrizeTips.status}}" style="width:100%" size="large" help="{{choosePrizeTips.content}}" class="probability-prize-content-formItem probability-prize-content-formItem-choosePrize" label="选择奖品" required>
<view class="probability-prize-content-formitem-choosePrize-wrap">
<input a:if="{{prizeInitData.ename}}" class="probability-prize-content-input" style="margin-right:10px" onChange="changeInput" maxLength="10" value="{{prizeInitData.name}}" hasLimitHint="true" name="活动名称" defaultValue="{{prizeDialogEdit ? prizeDialogData.record.name : prizeInitData.name}}" placeholder="请选择奖品"/>
<view class="probability-prize-content-formitem-goequity" onTap="navigateToPlugin" type="primary">{{prizeInitData.ename ? '重新选择' : '选择奖品'}}</view>
......@@ -26,7 +34,7 @@
</form-item>
<form-item
style="width:100%"
a:if="{{[OBJECT_TYPE, CREDITS_TYPE, LOWER_TYPE].includes(prizeInitData.type)}}"
a:if="{{[OBJECT_TYPE, CREDITS_TYPE].includes(prizeInitData.type)}}"
size="large"
class="probability-prize-content-formItem"
label="奖品名称"
......@@ -48,7 +56,7 @@
</form-item>
<form-item
a:if="{{[OBJECT_TYPE,EQUITY_TYPE, LOWER_TYPE].includes(prizeInitData.type) && type !== 'rank'}}"
a:if="{{[OBJECT_TYPE,EQUITY_TYPE].includes(prizeInitData.type) && type !== 'rank'}}"
style="width:100%"
size="large"
class="probability-prize-content-formItem"
......@@ -61,7 +69,7 @@
</form-item>
<form-item
style="width:100%"
a:if="{{[OBJECT_TYPE,EQUITY_TYPE, LOWER_TYPE].includes(prizeInitData.type) && prizeInitData.switchStock==1 && type !== 'rank'}}"
a:if="{{[OBJECT_TYPE,EQUITY_TYPE].includes(prizeInitData.type) && prizeInitData.switchStock==1 && type !== 'rank'}}"
size="large"
class="probability-prize-content-formItem"
label="奖品库存"
......@@ -82,7 +90,7 @@
</form-item>
<form-item
a:if="{{[CREDITS_TYPE, LOWER_TYPE].includes(prizeInitData.type)}}"
a:if="{{[CREDITS_TYPE].includes(prizeInitData.type)}}"
size="large"
class="probability-prize-content-formItem"
label="积分价值"
......@@ -93,7 +101,7 @@
</form-item>
<form-item
a:if="{{[OBJECT_TYPE,EQUITY_TYPE, LOWER_TYPE].includes(prizeInitData.type)}} "
a:if="{{[OBJECT_TYPE,EQUITY_TYPE].includes(prizeInitData.type)}} "
style="width:100%"
size="large"
class="probability-prize-content-formItem"
......@@ -113,7 +121,7 @@
</form-item>
<form-item
a:if="{{[EQUITY_TYPE, LOWER_TYPE].includes(prizeInitData.type)}} "
a:if="{{[EQUITY_TYPE].includes(prizeInitData.type)}} "
style="width:100%"
size="large"
class="probability-prize-content-formItem"
......@@ -174,7 +182,7 @@
</form-item>
<form-item
a:if="{{[OBJECT_TYPE, LOWER_TYPE].includes(prizeInitData.type)}}"
a:if="{{[OBJECT_TYPE].includes(prizeInitData.type)}}"
style="width:100%" size="large"
class="probability-prize-content-formItem probability-prize-content-formItem-choosePrize"
label="商品查看链接">
......
......@@ -272,7 +272,7 @@ Component({
prizeInitData: {
...this.data.prizeInitData,
switchStock: value,
stock: value === 2 ? "" : this.data.prizeInitData.stock,
stock: value === 2 ? "" : this.data.prizeInitData.stock || "",
},
});
},
......
......@@ -17,3 +17,15 @@
justify-content: flex-end;
margin: 10px 0 0 0;
}
.rank-pagination-text {
display: flex;
align-items: center;
}
.rank-dialog-wrap .operator-btns {
margin-bottom: 15px;
width: 300px;
float: right;
}
.rank-dialog-wrap .long-item .next-select {
width: 150px;
}
<dialog-wrap
title="中奖信息"
title="中奖名单"
tips="(为保证您的正常导出,建议单次筛选500条以内进行操作)"
visible="{{visible}}"
onClose="onCloseDialog"
width="1000"
>
<view class="rank-dialog-wrap">
<!-- <view class="other-winner-list">
<button type="text">导出其它中奖名单</button>
</view> -->
<!-- <tab shape="wrapped">
<tab-item
a:for="{{tabs}}"
title="{{item.tab}}"
key="{{item.key}}"
> -->
<!-- 添加筛选条件导出中奖名单 start -->
<form a:if="{{isSearch}}" class="edit-content-form" data-name="form" inline="true" labelTextAlign="right" size="large">
<form class="edit-content-form" data-name="form" inline="true" labelTextAlign="right" size="large">
<form-item class="edit-content-formItem" label="奖品编号" labelTextAlign="right" asterisk="{{false}}">
<input data-type="prize" value="{{searchInfo.prizeId}}" onChange="onInputChange" hasLimitHint="true" name="奖品编号" />
<input value="{{searchInfo.prizeId}}" onChange="handleInputChange" data-name='prizeId' hasLimitHint="true" name="奖品编号" />
</form-item>
<form-item class="edit-content-formItem" label="用户昵称" labelTextAlign="right" asterisk="{{false}}">
<input data-type="user" value="{{searchInfo.userNick}}" onChange="onInputChange" hasLimitHint="true" name="用户id" />
<form-item class="edit-content-formItem" label="用户id" labelTextAlign="right" asterisk="{{false}}">
<input value="{{searchInfo.userNick}}" onChange="handleInputChange" data-name='userNick' hasLimitHint="true" name="用户id" />
</form-item>
<form-item class="edit-content-formItem" label="发奖时间" labelTextAlign="right" asterisk="{{false}}">
<range-picker style="width: 300px" onChange="onChangeTime" hasClear="true" value="{{timeRange}}" data-time="{{timeRange}}" class="block" show-time="{{ format: 'HH:mm' }}" />
<range-picker style="width: 300px" onChange="handleTimeRangeChange" hasClear="true" value="{{searchInfo.timeRange}}" class="block" show-time="{{ format: 'HH:mm' }}" data-time="{{searchInfo.timeRange}}"/>
</form-item>
<form-item class="edit-content-formItem" label="发货状态" labelTextAlign="right">
<select onChange="onSelectShipStatus">
<option value="{{1}}">全部实物</option>
<option value="{{2}}">未发货</option>
<option value="{{3}}">已发货</option>
<select value="{{searchInfo.shipStatus}}" onChange="handleInputChange" data-name='shipStatus'>
<option value="">全部</option>
<option value="1">未填写地址</option>
<option value="2">待发货</option>
<option value="3">已发货</option>
</select>
</form-item>
<form-item class="edit-content-formItem" label="奖品类型">
<select data-type="prizeType" onChange="onSelectPrizeType">
<option value="{{1}}">优惠券</option>
<option value="{{3}}">实物</option>
<form-item class="edit-content-formItem long-item" label="奖品类型">
<select value="{{searchInfo.prizeType}}" onChange="handleInputChange" data-name='prizeType'>
<option value="">全部</option>
<option value="1">优惠券</option>
<!-- <option value="2">积分</option> -->
<option value="3">实物</option>
<option value="5">谢谢参与</option>
</select>
</form-item>
<form-item class="edit-content-formItem" label="发奖来源">
<select data-type="prizeDataType" onChange="onSelectPrizeType">
<option value="{{1}}">排行榜</option>
<option value="{{2}}">抽奖</option>
<option value="{{3}}">大转盘</option>
<form-item class="edit-content-formItem long-item" label="发奖来源">
<select value="{{searchInfo.prizeDataType}}" onChange="handleInputChange" data-name='prizeDataType'>
<option value="">全部</option>
<option value="1">游戏获得</option>
<option value="2">排行榜</option>
<option value="3">分享获得</option>
</select>
</form-item>
<view class="operator-btns" style="textAlign:right">
<button onTap="handleSearch" style="height:32px;" type="primary" size="medium">搜索</button>
<button style="margin-left:20px;height:32px" type="primary" onTap="handleExport" size="medium">导出</button>
<button style="margin-left:20px;height:32px" type="primary" onTap="handleImport" size="medium">导入发货</button>
</view>
</form>
<view a:if="{{isSearch}}" style="textAlign:right">
<button onTap="onChangeSearch" style="height:32px;" type="primary" size="medium">搜索</button>
<button style="margin-left:20px;height:32px" type="primary" data-type="search" onTap="exportWinnerListBySearch" size="medium">导出</button>
<button style="margin-left:20px;height:32px" type="primary" onTap="onChangeUpLoad" size="medium">导入发货</button>
<table dataSource="{{list}}" loading="{{isLoading}}">
<table-column title="奖品编号" dataIndex="_id"/>
<table-column title="用户id" dataIndex="userNick"/>
<table-column title="发奖时间" dataIndex="createTime">
</table-column>
<table-column title="填写地址时间" dataIndex="receiveTime">
<view slot-scope="x">
{{ x.record.type === 3 ? (x.record.receiveName ? x.record.receiveTime : '暂未填写') : '/' }}
</view>
</table-column>
<table-column title="奖品类型" dataIndex="type">
<view slot-scope="x">
<text a:if="{{x.record.type == 1}}">优惠券</text>
<!-- <text a:if="{{x.record.type == 2}}">积分</text> -->
<text a:elif="{{x.record.type == 3}}">实物</text>
<text a:else>/</text>
</view>
</table-column>
<table-column title="奖品名称" dataIndex="name"/>
<table-column title="发奖来源" dataIndex="prizeDataType">
<view slot-scope="x">
<text a:if="{{x.record.prizeDataType == 1}}">关卡获得</text>
<text a:if="{{x.record.prizeDataType == 2}}">排行榜</text>
<text a:if="{{x.record.prizeDataType == 3}}">分享获得</text>
</view>
</table-column>
<table-column title="收货信息(联系人+详细地址)" dataIndex="receiveName">
<view slot-scope="x">
<view a:if="{{x.record.type == 3}}">
<view>{{(x.record.receiveName || '')}}</view>
<view>{{( x.record.phone || '')}} </view>
<view>{{ ( x.record.province + x.record.city + x.record.area + x.record.addressdetail || '') }}</view>
<view a:if="{{!x.record.receiveName}}">暂未填写</view>
</view>
<!-- end -->
<view a:if="{{!isSearch}}" class="now-winner-list">
<button type="primary" data-type="export" onTap="exportWinnerList">导出中奖名单</button>
<view a:else>/</view>
</view>
<table dataSource="{{list}}">
<table-column a:for="{{columns}}" a:key="*this" title="{{item.title}}" dataIndex="{{item.prop}}" width="{{item.width}}"/>
</table-column>
<table-column title="发货状态" dataIndex="shipStatus">
<view slot-scope="x">
<view a:if="{{x.record.type == 3}}">
<text a:if="{{x.record.shipStatus == 1}}">未填写地址</text>
<text a:if="{{x.record.shipStatus == 1 || x.record.shipStatus == 2}}">待发货</text>
<text a:if="{{x.record.shipStatus == 3}}">已发货</text>
</view>
<view a:else>/</view>
</view>
</table-column>
<table-column title="物流信息" dataIndex="shipCompany">
<view slot-scope="x">
<view a:if="{{x.record.type == 3}}">
<view>{{ x.record.shipCompany }}</view>
<view>{{ x.record.shipNum }}</view>
<view a:if="{{!x.record.shipCompany && !x.record.shipNum}}">暂未填写</view>
</view>
<view a:else>/</view>
</view>
</table-column>
</table>
<view class="rank-pagination">
<text class="rank-pagination-text">共{{total}}条</text>
<!-- <pagination shape="arrow-only" hideOnlyOnePage="true" defaultCurrent="1" current="{{pageInfo.pageNo}}" pageSize="{{pageInfo.pageSize}}" onChange="changePagination" pageShowCount="100" total="{{pageInfo.total}}" /> -->
<pagination showJump="{{false}}" defaultCurrent="{{1}}" data-type="all" pageSize="{{pageSize}}" onChange="onChangePageNo" pageShowCount="{{10}}" total="{{total}}" a:if="{{total > 0}}" shape="arrow-only" />
<text class="rank-pagination-text">共 {{total}} 条</text>
<pagination showJump="{{false}}" defaultCurrent="{{1}}" current="{{searchInfo.pageNo}}" data-type="all" pageSize="{{searchInfo.pageSize}}" onChange="handleChangePage" pageShowCount="{{10}}" total="{{total}}" a:if="{{total > 0}}" shape="arrow-only" />
</view>
<!-- </tab-item>
</tab> -->
</view>
</dialog-wrap>
<ship-dialog a:if="{{showShip}}" showShip="{{showShip}}" onClose="onCloseShip" activityId="{{winactivityId}}"></ship-dialog>
\ No newline at end of file
<ship-dialog a:if="{{showShip}}" showShip="{{showShip}}" onClose="handleShipClose" activityId="{{winactivityId}}"></ship-dialog>
import { findWinnerInfoList, getAwardsList, exportAwardsList } from '/api'
import moment from 'moment'
import {
findWinnerInfoList,
uploadDataCreateFile,
// 通过搜索条件筛选中奖名单
exportAwardsInfoBySearch,
findWinnerInfoListBySearch
} from "/api";
import { appId } from "/config";
import { setClipboard } from "/utils";
//每页的展示数量
const PageInfo = {
PAGE_SIZE: 100,
PAGE_NO: 1
}
Component({
mixins: [],
data: {
PageInfo,
tabs: [{
tab: '0608-0712',
key: 111
}, {
tab: '03308-0712',
key: 43
}, {
tab: '064548-0712',
key: 435
}, {
tab: '0608-0712',
key: 436545
}, {
tab: '0608-0712',
key: 65
}, {
tab: '0608-0712',
key: 11561
}, {
tab: '0608-0712',
key: 13311
}, {
tab: '0608-0712',
key: 145611
}, {
tab: '0608-0712',
key: 1178761
}],
dataSource: [],
columns: [
{ title: '奖品编号', prop: 'prizeId' },// prizeId为awards_info中的_id
{ title: '发奖时间', prop: 'createTime' },
{ title: '填地址时间', prop: 'receiveTime' },
{ title: '用户昵称', prop: 'userNick' },
{ title: '发奖来源', prop: 'prizeDataType' },
{ title: '奖品类型', prop: 'type' },
{ title: '奖品名', prop: 'name' },
{ title: '收货人', prop: 'receiveName' },
{ title: '联系方式', prop: 'phone' },
/* 注:需要在接口里将 省+市+区+详细 拼写起来*/
{ title: '收货地址', prop: 'address' },// { title: '收货地址', prop: 'address', width: 240 }
{ title: '物流状态', prop: 'shipStatus' },
{ title: '物流公司', prop: 'shipCompany' },
{ title: '物流单号', prop: 'shipNum' }
],
// pageInfo: {
// pageNo: 1,
// pageSize: 100,
// total: 0
// },
// 《条件搜索》start显示中奖名单搜索条件
// 搜索条件
searchInfo: {
prizeId: null, //奖品编号
userNick: null, //用户id
timeRange: [], //发奖时间
prizeType: null,
prizeDataType: null,
shipStatus: null,
pageNo: 1,
pageSize: 10
},
list: [],
prizeId: "",
userId: "",
startT: "",
endT: "",
shipStatus: "",
timeRange: [],
prizeType: "",
prizeDataType: "",
showShip: false,
winactivityId: "",
pageNo: PageInfo.PAGE_NO,
pageSize: PageInfo.PAGE_SIZE,
total: 0,
// end
//需要筛选查询时改为true
isSearch: true
isLoading: false,
showShip: false,
winactivityId: '',
},
props: {
onClose: () => { },
selectedItem: {},
onShowExportDialog: () => { },
selectedItem: {}
},
didMount() {
if (!this.data.isSearch) {
this.loadWinnerList();
}
this.searchList();
},
didUpdate() { },
didUnmount() { },
methods: {
// 更换页码时调用接口
handleChangePage(e) {
const { value } = e.detail
this.setData({
'searchInfo.pageNo': value
})
this.searchList()
},
// 搜索
async handleSearch() {
// 未选择任何条件搜索
const { prizeId, userNick, timeRange, prizeType, shipStatus, prizeDataType } = this.data.searchInfo
if (!prizeId && !userNick && !timeRange.length && prizeType == null && shipStatus == null && prizeDataType == null) {
this.resetData()
my.showToast({
type: 'fail',
content: '请填写至少一个筛选信息'
})
return
}
this.setData({
'searchInfo.pageNo': 1
})
this.searchList()
},
// start《条件搜索》初始化数据更新
initData() {
resetData() {
this.setData({
searchInfo: {
prizeId: null, //奖品编号
userNick: null, //用户id
timeRange: [], //发奖时间
prizeType: null,
prizeDataType: null,
shipStatus: null,
pageNo: 1,
pageSize: 10
},
list: [],
prizeId: "",
userId: "",
startT: "",
endT: "",
timeRange: [],
shipStatus: "",
prizeType: "",
prizeDataType: "",
pageNo: PageInfo.PAGE_NO,
pageSize: PageInfo.PAGE_SIZE,
total: 0,
});
},
//加载中奖名单
async loadWinnerList() {
let { pageNo, pageSize } = this.data;
let { activityId } = this.props.selectedItem;
const { data, success } = await findWinnerInfoList({ activityId, pageNo, pageSize });
console.log('data>>>>>', data);
if (success) {
this.setData({
list: data.list,
total: data.total
});
}
isLoading: false,
showShip: false,
winactivityId: ''
})
},
// end
onCloseDialog() {
this.initData();
this.props.onClose && this.props.onClose();
this.resetData()
this.props.onClose && this.props.onClose()
},
// 监听input改变
handleInputChange(e) {
const { value } = e.detail;
const { name } = e.target.dataset;
this.setData({
[`searchInfo.${name}`]: value
})
},
async getWinnerList() {
const { avtivityId } = this.props;
const { data } = await findWinnerInfoList({
avtivityId
});
// 监听发奖时间变化
handleTimeRangeChange(e) {
const [startTime, endTime] = e.detail.value
this.setData({
dataSource: data
});
'searchInfo.timeRange': [startTime, endTime]
})
},
// 导出中奖名单
async exportWinnerList(evt) {
const { activityId, title } = this.props.selectedItem;
const { type } = evt.target.dataset;
my.showLoading({ content: "生成文件中..." });
try {
const { success, data, message } = await uploadDataCreateFile({
activityId,
title
});
my.hideLoading();
//搜索
async searchList() {
let params = {
...this.data.searchInfo,
activityId: this.props.selectedItem.activityId
}
params.startTime = new Date(params.timeRange[0]).getTime()
params.endTime = new Date(params.timeRange[1]).getTime()
delete params.timeRange
console.log('搜索参数', params)
try {
this.setData({
isLoading: true
})
console.log(params)
const { data, success } = (await findWinnerInfoList(params)) || {}
const { list, total } = data
console.log(data, 'data-----')
list.map(v => {
v.createTime = moment(+v.createTime).format('YYYY-MM-DD HH:mm:ss')
v.receiveTime = moment(+v.receiveTime).format('YYYY-MM-DD HH:mm:ss')
})
if (success) {
await setClipboard({ text: data.url.replace(/amp;/g, "") });
my.showToast({
type: 'success',
content: '下载链接复制成功,请在浏览器中打开下载'
});
this.setData({
exportDialogVisible: true,
exportUrl: data.url.replace(/amp;/g, "")
});
} else {
my.showToast({
type: "fail",
content: message,
});
list,
total
})
this.setData({
isLoading: false
})
}
} catch (error) {
my.hideLoading();
console.log(error, "exportList-error");
this.setData({
isLoading: false
})
}
},
// 《条件搜索》 导出中奖名单
timeExchange(time) {
console.log("time==", time);
let a = time ? new Date(time) : "";
let times = a ? a.getTime() : "";
return times;
},
async exportWinnerListBySearch(evt) {
const { activityId, title } = this.props.selectedItem;
let { prizeId, userId, startT, endT, shipStatus, pageNo, pageSize, prizeType, prizeDataType } = this.data;
let timeStart = this.timeExchange(startT);
let timeEnd = this.timeExchange(endT);
if (prizeId || userId || (timeStart && timeEnd) || shipStatus || prizeType || prizeDataType) {
try {
console.log("导出名单数据接口");
const { success, data, message } = await exportAwardsInfoBySearch({
activityId,
pageNo, pageSize,
title,
prizeId,
userId,
timeStart,
timeEnd,
shipStatus,
prizeType,
prizeDataType
});
if (success) {
if (!data) {
async handleExport(evt) {
console.log(this.props)
// 未选择任何条件搜索
const { prizeId, userNick, timeRange, prizeType, shipStatus, prizeDataType } = this.data.searchInfo
if (!prizeId && !userNick && !timeRange.length && prizeType == null && shipStatus == null && prizeDataType == null) {
this.resetData()
my.showToast({
type: 'fail',
content: '没有符合条件的订单!'
});
content: '请填写至少一个筛选信息'
})
return
}
const { activityId, title } = this.props.selectedItem
let params = { ...this.data.searchInfo, activityId, title }
params.startTime = new Date(params.timeRange[0]).getTime()
params.endTime = new Date(params.timeRange[1]).getTime()
params.pageNo = 1
params.pageSize = 500
let res = []
delete params.timeRange
my.showLoading({
content: '生成文件中...'
})
try {
let { success, data, message } = (await getAwardsList(params).catch(error => { })) || {}
const { list = [], total } = data || {}
if (success) {
res = [...res, ...list]
while (total > res.length) {
params.pageNo++
let { success, data, message } = (await getAwardsList(params).catch(error => { })) || {}
const { list = [] } = data || {}
if (success) {
res = [...res, ...list]
} else {
}
else {
console.log("导出中奖名单");
my.setClipboard({
text: data.url.replace(/amp;/g, ''),
success(res) {
my.showToast({
type: 'success',
content: '下载链接复制成功,请在浏览器中打开下载'
});
}
});
if (res.length == 0) {
my.showToast({
type: 'fail',
content: '查询结果为空'
})
my.hideLoading()
return
}
let { success, data, message } = (await exportAwardsList({ title, list: res })) || {}
console.log(success, data, message, '复制链接')
if (success) {
this.props.onShowExportDialog({
exportLinkUrl: data.url.replace(/amp;/g, '')
})
console.log(data, '下载链接')
} else {
my.showToast({
type: 'fail',
content: message
});
}
} catch (error) {
my.hideLoading();
console.log('exportList-error', error);
})
}
} else {
}
else {
my.showToast({
type: "fail",
content: "请填写至少一个筛选信息"
});
my.hideLoading()
} catch (error) {
my.hideLoading()
console.log(error, 'exportList-error')
}
},
// 《条件搜索》导入发货信息
onChangeUpLoad() {
const { activityId, title } = this.props.selectedItem;
// 导入发货信息
handleImport() {
const { activityId } = this.props.selectedItem
console.log('打开导入文件弹窗')
this.setData({
showShip: true,
winactivityId: activityId
});
})
console.log('winner====showShip', this.data.showShip)
},
// 《条件搜索》关闭导入发货窗口
onCloseShip() {
// 关闭导入发货窗口
handleShipClose() {
this.setData({
showShip: false,
});
},
// 《条件搜索》搜索
async onChangeSearch() {
const { activityId, title } = this.props.selectedItem;
let { prizeId, userId, startT, endT, pageNo, pageSize, shipStatus, prizeType, prizeDataType } = this.data;
let timeStart = this.timeExchange(startT);
let timeEnd = this.timeExchange(endT);
console.log(prizeId, userId, timeStart, timeEnd, pageNo, pageSize, shipStatus, prizeType, prizeDataType);
if (prizeId || userId || (timeStart && timeEnd) || shipStatus === 0 || shipStatus || prizeType || prizeDataType) {
let rewardList = await findWinnerInfoListBySearch({ activityId, pageNo, pageSize, title, prizeId, userId, timeStart, timeEnd, shipStatus, prizeType, prizeDataType });
if (rewardList.data.list.length == 0) {
this.setData({
list: [],
total: 0
}); 0;
my.showToast({
type: "fail",
content: "没有符合条件的订单!"
});
} else {
console.log("rewardList==", rewardList);
this.setData({
list: rewardList.data.list,
total: rewardList.data.total
});
winactivityId: ''
})
}
}
else {
my.showToast({
type: "fail",
content: "请填写至少一个筛选信息"
});
}
},
// 《条件搜索》按照时间搜索
onChangeTime(e) {
console.log("时间搜索e", e);
const [startTime, endTime] = e.detail.value;
this.setData({
startT: startTime || "",
endT: endTime || "",
timeRange: [startTime, endTime],
pageNo: PageInfo.PAGE_NO,
pageSize: PageInfo.PAGE_SIZE,
total: 0,
});
console.log("this.data.timeRange==", this.data.timeRange, this.data.startT, this.data.endT);
},
// 《条件搜索》输入框查找信息
onInputChange(e) {
let { type } = e.currentTarget.dataset;
let { value } = e.detail;
this.setData({
[type + "Id"]: value,
pageNo: PageInfo.PAGE_NO,
pageSize: PageInfo.PAGE_SIZE,
total: 0,
});
console.log("this.data.prizeId===", this.data.prizeId, "this.data.userId===", this.data.userId);
},
// 《条件搜索》发货状态筛选
onSelectShipStatus(e) {
console.log('筛选发货状态e>>>', e);
this.setData({
shipStatus: e.detail.value,
pageNo: PageInfo.PAGE_NO,
pageSize: PageInfo.PAGE_SIZE,
total: 0,
});
},
// 《条件搜索》奖品类型筛选
onSelectPrizeType(e) {
let { type } = e.target.dataset;
console.log('筛选奖品类型e>>>', e);
this.setData({
[type]: e.detail.value,
pageNo: PageInfo.PAGE_NO,
pageSize: PageInfo.PAGE_SIZE,
total: 0,
});
console.log("type", this.data[type]);
},
// 《条件搜索》更换页码时调用接口
onChangePageNo(e) {
this.setData({
pageNo: e.detail.value
});
if (this.data.isSearch) {
this.onChangeSearch();
} else {
this.loadWinnerList();
}
}
},
});
})
......@@ -3,7 +3,7 @@
width: 100%;
height: 200px;
/* margin-left: 80px; */
margin-top: 100px;
/* margin-top: 100px; */
}
.edit-content-titleLoad {
......@@ -14,9 +14,15 @@
}
.edit-content-shipDialog {
width: 340px;
margin-left: 76px;
margin-top: 40px;
display:flex;
align-items: center;
/* margin-left: 76px;
margin-top: 40px; */
}
.fileIdInp{
width: 240px!important;
margin-right: 20px;
}
.edit-content-buttons {
......@@ -27,3 +33,13 @@
.edit-content-buttonShip {
margin-left: 5px
}
.ship-tips {
margin: 20px 0;
}
.example {
color:rgb(143,208,206);
cursor: pointer;
}
<dialog-wrap title="批量发货" visible="{{showShip}}" onClose="closeShip">
<view class="edit-content-shipDialog1">
<form-item class="edit-content-shipDialog" label="上传附件:" style="display:flex">
<input placeholder="Input" style="80px" value="{{fileName}}" onChange="onChangeInput"/>
<form-item class="edit-content-shipDialog" label="fileId">
<input class="fileIdInp" placeholder="请输入fileId" value="{{fileName}}" onChange="onChangeInput"/>
</form-item>
<view class="ship-tips">
请点击下载模板后,填写完信息发给运营获取fileId 参考示例: <text class="example" onTap="downloadExampleFile">示例.csv</text>
</view>
<view class="edit-content-buttons">
<button class="edit-content-buttonShip" type="primary" onTap="closeShip">
取消
</button>
<button class="edit-content-buttonShip" type="primary" onTap="onChangeLoadFile">
确认发货
</button>
<button onTap="closeShip">取消</button>
<button class="edit-content-buttonShip" disabled="{{!fileName}}" type="primary" onTap="onChangeLoadFile">确认发货</button>
</view>
</view>
</dialog-wrap>
<copy-link-dialog title="如何下载CSV" visible="{{copyLink}}" url="{{url}}" onClose="closeCopyLinkDialog"></copy-link-dialog>
import { downloadFile } from "../../../api";
const { cloud } = getApp();
// import { upLoadFileApi } from "../../utils/my-api";
Component({
data: {
fileName: ""
fileName: "",
copyLink: false,
url: "yun.dui88.com/call/example.xlsx",
},
props: {
activityId: "",
onClose: () => { }
onClose: () => { },
},
didMount() {
console.log(">>>>>>activityId",this.props.activityId);
},
didUpdate() {
console.log(">>>>>>activityId", this.props.activityId);
},
didUpdate() { },
didUnmount() { },
methods: {
//LS20200716关闭弹窗
closeShip() {
this.props.onClose();
this.setData({
fileName: ""
})
fileName: "",
});
console.log("ship-dialog====showShip");
},
closeDialog() {
this.setData({})
this.setData({});
},
//下载示例文件
async downloadExampleFile() {
// let urls = await cloud.file.getTempFileURL({
// fileId: ['cloud://E89396D800766AB3D101FD4DF83F5C7D//示例.xlsx']
// })
// console.log(urls,'urls');
// const { url } = urls[0]
// this.setData({
// copyLink:true,
// url:"yun.dui88.com/call/example.xlsx"
// })
const { url } = this.data
my.setClipboard({
text: url.replace(/amp;/g, ""),
success(res) {
my.showToast({
type: "success",
content: "下载链接复制成功,请在浏览器中打开下载",
});
},
});
},
closeCopyLinkDialog() {
this.setData({
copyLink: false
})
},
//20200717确认发货
//20200717
......@@ -40,32 +67,30 @@ Component({
if (result.data.total == 0) {
my.showToast({
type: "fail",
content: `无用户填写地址,导入信息错误`,
content: `导入信息错误,请导入正确信息`,
});
}
else {
} else {
my.showToast({
type: "success",
content: `成功导入${JSON.stringify(result.data.total)}条发货信息!`,
});
this.props.onClose()
}
} else {
my.showToast({
type: "fail",
content: result.message
content: result.message,
});
}
},
//输入框变化
onChangeInput(e) {
console.log("输入框变化", e);
let { fileName } = this.data;
this.setData({
fileName: e.detail.value
})
fileName: e.detail.value,
});
console.log("====", fileName);
}
}
})
},
},
});
{
"component": true,
"usingComponents": {
"dialog-wrap": "../../basic/dialiog-wrap/dialiog-wrap"
"dialog-wrap": "../../basic/dialiog-wrap/dialiog-wrap",
"copy-link-dialog": "../copy-link-dialog/copy-link-dialog"
}
}
const { passUrlList } = require('../../../cmpUtils/const');
import { passUrlList, urlCheck } from "../../../utils/helper";
import { validateRangeNumber } from "../../../utils/validate";
Component({
......@@ -80,13 +81,6 @@ Component({
[name]: value
})
},
validateLink(link) {
if(!link) return false;
if(link.startsWith('http://') || link.startsWith('https://')) {
return passUrlList.some(url => link.indexOf(url) !== -1);
}
return false;
},
onSaveTask() {
const { title, link, value, taskRateType, times, itemIds } = this.data;
// if(!title.trim()) {
......@@ -97,11 +91,11 @@ Component({
// return;
// }
if(this.props.hasLink && !this.validateLink(link)) {
if (this.props.hasLink && !urlCheck(link, passUrlList).status) {
my.showToast({
type: 'fail',
content: '请输入正确的链接地址'
})
content: urlCheck(link, passUrlList).message
});
return;
}
......
......@@ -14,7 +14,7 @@
<table-column title="操作" dataIndex="id" alignHeader="left">
<view slot-scope="x">
<button a:if="{{buttons.includes('edit')}}" class="tb-list-edit" onTap="handleClickEdit" type="primary" text="true" data-x="{{x}}" >编辑活动</button>
<button a:if="{{buttons.includes('exportWinnerList')}}" class="tb-list-edit" type="primary" text="true" data-x="{{x}}" disabled="{{!x.record.isEnd}}" data-type="object" onTap="handleOpenWinnerList">查看中奖名单</button>
<button a:if="{{buttons.includes('exportWinnerList')}}" class="tb-list-edit" type="primary" text="true" data-x="{{x}}" data-type="object" onTap="handleOpenWinnerList">查看中奖名单</button>
<button a:if="{{buttons.includes('delete')}}" class="tb-list-edit" type="primary" text="true" data-x="{{x}}" onTap="handleTapDelete">删除</button>
<button a:if="{{buttons.includes('copyLink')}}" class="tb-list-edit" type="primary" text="true" data-x="{{x}}" onTap="onCopyLink">复制活动链接</button>
<button a:if="{{buttons.includes('copyNewActivity')}}" class="tb-list-edit" type="primary" text="true" data-x="{{x}}" onTap="onCreateNewActivity">复制新活动</button>
......@@ -29,7 +29,7 @@
</view>
<copy-link-dialog visible="{{exportDialogVisible}}" url="{{exportUrl}}" onClose="onCloseExportDialog"/>
<copy-link-dialog visible="{{exportDialogVisible}}" url="{{exportLinkUrl}}" onClose="onCloseExportDialog"/>
<confirm-dialog
visible="{{confirmDialog.visible}}"
......@@ -39,4 +39,4 @@
/>
<rank-dialog a:if="{{winnerListDialogVisible}}" visible="{{winnerListDialogVisible}}" onClose="onCloseWinnerListDialog" selectedItem="{{selectedItem}}"/>
\ No newline at end of file
<rank-dialog a:if="{{winnerListDialogVisible}}" visible="{{winnerListDialogVisible}}" onClose="onCloseWinnerListDialog" onShowExportDialog="showExportDialog" selectedItem="{{selectedItem}}"/>
\ No newline at end of file
......@@ -14,7 +14,7 @@ Component({
data: {
isLoadingList: false,
exportDialogVisible: false,
exportUrl: '',
exportLinkUrl: '',
dataSource: [],
confirmDialog: {
visible: false,
......@@ -99,6 +99,14 @@ Component({
winnerListDialogVisible: false
});
},
//展示复制链接弹框
showExportDialog(data) {
console.log('展示复制链接弹框', data)
this.setData({
exportDialogVisible: true,
exportLinkUrl: data.exportLinkUrl
})
},
// 复制链接
async onCopyLink(evt) {
......@@ -185,36 +193,6 @@ Component({
console.log(error);
}
},
// 导出中奖名单
async exportWinnerList(evt) {
const { activityId } = evt.target.dataset.x.record;
const { type } = evt.target.dataset;
let isObject = type === "object";
my.showLoading({ content: "生成文件中..." });
try {
const { success, data, message } = await uploadDataCreateFile({
activityId,
isObject,
});
my.hideLoading();
if (success) {
await setClipboard({ text: data.url.replace(/amp;/g, "") });
this.setData({
exportDialogVisible: true,
exportUrl: data.url.replace(/amp;/g, "")
});
} else {
my.showToast({
type: "fail",
content: message,
});
}
} catch (error) {
my.hideLoading();
console.log(error, "exportList-error");
}
},
// 编辑
handleClickEdit(evt) {
let { activityId } = evt.target.dataset.x.record;
......
......@@ -160,9 +160,9 @@ Component({
Object.keys(formState).forEach(key => {
let error = errors.filter(v => target ? v.field === target && v.field === key : v.field === key).length && errors.filter(v => v.field === key)[0];
// 时间实时校验
if (key === 'timeRange' && formState[key].status === 'error') {
return
}
// if (key === 'timeRange' && formState[key].status === 'error') {
// return
// }
newValidator[key] = {
status: error ? 'error' : 'success',
message: error ? error.message : ''
......
import { rankTableValidator, validateRangeNumber, rankTimeValidator, isNumber,validatePositiveInteger,validateInteger,urlChecks } from "../../../utils/validate";
import { rankTableValidator, validateRangeNumber, rankTimeValidator, isNumber,validatePositiveInteger,validateInteger,urlChecks, rateTableValidator } from "../../../utils/validate";
// 使用 async-validator 校验
// 文档地址: https://github.com/yiminghe/async-validator
......
......@@ -34,16 +34,31 @@ export const validateRangeNumber = (number, [min, max] = [], fixed = 0) => {
console.error('数字范围的最小值不能大于最大值');
return;
}
if(number != 0){
if (!pattern.test(number) || number === '') return false;
}
if (number < min || number > max) return false;
return true;
}
};
// 配置验证
// 单个奖池总概率验证
export const rateTableValidator = (rule, value, callback, source, options) => {
let n = 0;
if (!value.length || !value) {
return new Error('请至少配置一个奖品');
}
if(value.length){
value.forEach(item=>{
n += Number(item.probability)
})
}
if(n>100){
return new Error('总概率不能大于100%');
}
return callback()
};
// 排名表格验证
......
/** @format */
import { CODE_TYPES, EIGHT_HOURS } from './../constants'
import { CODE_TYPES, EIGHT_HOURS,PRIZE_TYPE,SHIP_STATUS } from './../constants'
import { services, paramsCheck } from '../decorator'
import { resultsModel } from '../sdk'
import { formatTime } from '../utils'
import { AwardsService } from '../service'
import { formatTime } from '../utils/index'
import * as xlsx from 'node-xlsx'
//奖池类型
const prizePoolType = {
'1': '排行榜奖励',
'2': '兑换奖品',
'3': '大转盘奖品',
'4': '其他奖励'
}
//发货状态
const shipMsg = {
'1': '未填地址',
'2': '未发货',
'3': '已发货'
}
const prizeKind = {
'1': '优惠券',
'2': '权益',
'3': '实物'
}
export default class BaseController {
/**
......@@ -34,193 +15,132 @@ export default class BaseController {
@paramsCheck(['activityId'])
@services([AwardsService])
async findWinnerInfoList(context: Context, { session }, [awardsService]: [AwardsService]) {
const { activityId, pageNo = 1, pageSize = 500 } = context.data
// 获取活动中奖列表
let awardslist = await awardsService.getAwardslistByActivityId(activityId, pageNo, pageSize)
console.log(`awardslist: ${JSON.stringify(awardslist)}`)
const {
activityId = '',
prizeId = null,
userNick = '',
shipStatus = null,
prizeType = null,
prizeDataType = null,
pageNo = 1,
pageSize = 10,
startTime,
endTime
} = context.data
let winnersObj = {}
awardslist.forEach(v => {
if (!winnersObj[v.rank]) {
winnersObj[v.rank] = []
}
winnersObj[v.rank].push({
userNick: v.userNick,
id: v.openId
})
// 获取活动中奖列表
let awardList = await awardsService.getAwardListByActivityId({
activityId,
prizeId,
userNick,
shipStatus,
type: prizeType,
prizeDataType,
pageNo,
pageSize,
startTime,
endTime
})
console.log(`winnersObj: ${JSON.stringify(winnersObj)}`)
let results = []
new Map(Object.entries(winnersObj)).forEach((v, index) => {
results.push({
rank: index,
winnerDetailList: v
})
})
return resultsModel.success(results)
console.log(`awardList: ${JSON.stringify(awardList)}`)
return resultsModel.success(awardList)
}
/**
* 导出活动中奖名单
*/
//获取活动中奖名单 为导出做准备
@paramsCheck(['activityId', 'title'])
@services([AwardsService])
async exportAwardsList(context: Context, { session }, [awardsService]: [AwardsService]) {
const { cloud } = context
const { activityId, title } = context.data
// 获取活动中奖列表
let pageNo = 1
let pageSize = 500
let awardslist = []
// 自动分页
while (awardslist.length >= (pageNo - 1) * 500) {
let nowPageNoList = await awardsService.getAwardslistByActivityId(activityId, pageNo, pageSize)
awardslist = [...awardslist, ...nowPageNoList]
pageNo += 1
}
console.log(`awardslist: ${JSON.stringify(awardslist)}`)
let xlsxData = [['序列', '名次', '昵称', '中奖名称']]
awardslist.forEach((v, index, arr) => {
xlsxData.push([index + 1, v.rank, v.userNick, v.name])
})
let buffer = xlsx.build([
{
name: title + new Date().getTime(),
data: xlsxData
}
])
console.log(`xlsxData: ${JSON.stringify(xlsxData)}`)
let result = await cloud.file.uploadFile({
fileContent: buffer,
fileName: title + new Date().getTime() + '.xlsx'
})
// result.url 需进行处理
if (result.url) {
result.url = result.url.replace('http', 'https').replace('-internal', '')
}
return resultsModel.success(result)
}
@services([AwardsService])
async exportAwardsInfoBySearch(context: Context, { session }, [awardsService]: [AwardsService]) {
/******VV */
async getAwardsList(context: Context, { session }, [awardsService]: [AwardsService]) {
let { cloud } = context
let { activityId, title, prizeId, userId: userNick, timeStart, timeEnd, shipStatus, prizeType: type, prizeDataType } = context.data
if (!activityId) {
return resultsModel.error(CODE_TYPES.PARAMS_ERROR, `缺少activityId`)
}
if (!title) {
return resultsModel.error(CODE_TYPES.PARAMS_ERROR, `缺少title`)
}
console.log('prizeId=====', prizeId)
if (!prizeId && !userNick && !timeStart && !timeEnd && !shipStatus && !prizeDataType && !type) {
return resultsModel.error(CODE_TYPES.PARAMS_ERROR, `未填写筛选信息`)
}
console.log(
'activityId--1--',
let {
activityId,
'prizeId--1-',
title,
prizeId,
'userNick--1-',
userNick,
'timeStart--1-',
timeStart,
'timeEnd--1-',
timeEnd
)
startTime,
endTime,
shipStatus,
prizeType,
prizeDataType,
pageNo,
pageSize
} = context.data
// 获取活动中奖列表
let total = await awardsService.getTotalObjectCount(
let awardList = await awardsService.getAwardListByActivityId({
activityId,
title,
prizeId,
userNick,
timeStart,
timeEnd,
startTime,
endTime,
shipStatus,
type,
prizeDataType
)
let awardslist = []
//导出中奖名单的pagesize和pageNo
let pageSize0 = 500;
let pageNo = 1;
let totalPage = Math.ceil(total / pageSize0);
let result = []
for (let i = 1; i <= totalPage; i++) {
pageNo = i
result.push(awardsService.getUserPrizeByActivityId(
activityId,
type: prizeType,
prizeDataType,
pageNo,
pageSize0,
prizeId,
userNick,
timeStart,
timeEnd,
shipStatus,
prizeDataType
))
}
const res = await Promise.all(result);
for (let i = 1; i <= totalPage; i++) {
awardslist.push(res[i])
pageSize,
isExport: true
})
return resultsModel.success(awardList)
}
// await Promise.all(result).then(res=>{
// for (let i = 1; i <= totalPage; i++) {
// awardslist.push(res[i])
// }
// })
console.log(`awardslist:》》》 ${JSON.stringify(awardslist)}《《《`)
if (awardslist.length > 0) {
/**
* 导出活动中奖名单
*/
@paramsCheck(['title'])
@services([AwardsService])
async exportAwardsList(context: Context, { session }, [awardsService]: [AwardsService]) {
let { cloud } = context
const { list = [], title } = context.data
console.log(list, '导出报表')
let xlsxData = [
[
'序列',
'奖品编号',
'用户id',
'中奖时间',
'地址填写时间',
'用户昵称',
'奖品种类',
'奖品类型',
'中奖名称',
'发奖来源',
'奖品名称',
'收货人',
'手机号',
'省',
'市',
'区',
'详细地址',
'联系方式',
'收货地址',
'发货状态',
'物流公司',
'物流单号'
]
]
awardslist.forEach((v, index, arr) => {
list.forEach((v, index, arr) => {
let prizeDataType = '/';
let prizeType = '/';
let shipTxt = '/';
if (v) {
if (v.prizeDataType == 1) prizeDataType = '关卡获得'
if (v.prizeDataType == 2) prizeDataType = '排行榜'
if (v.prizeDataType == 3) prizeDataType = '分享获得'
if (v.type == PRIZE_TYPE.EQUITY) prizeType = '实物'
if (v.type == PRIZE_TYPE.CREDITS) prizeType = '积分'
if (v.type == PRIZE_TYPE.OBJECT) {
prizeType = '实物'
if (+v.shipStatus == SHIP_STATUS.NO_ADDRESS) shipTxt = '未填写地址'
if (+v.shipStatus == SHIP_STATUS.NO_SHIP) shipTxt = '未发货'
if (+v.shipStatus == SHIP_STATUS.HAS_SHIP) shipTxt = '已发货'
}
if (v.type == PRIZE_TYPE.THANK) prizeType = '谢谢参与'
}
xlsxData.push([
index + 1,
v._id,
//中奖时间-填写地址时间
v.userNick,
v.createTime ? formatTime(new Date(v.createTime + EIGHT_HOURS)) : '',
v.type == 1 ? '/' : v.receiveTime ? formatTime(new Date(v.receiveTime + EIGHT_HOURS)) : '未填',
v.userNick || '/',
prizePoolType[v.prizeDataType],
prizeKind[v.type],
v.name || '',
v.type == 1 ? '/' : v.receiveName || '',
v.type == 1 ? '/' : v.phone || '未填',
v.type == 1 ? '/' : v.province ? v.province : '未填',
v.type == 1 ? '/' : v.city ? v.city : '未填',
v.type == 1 ? '/' : v.area ? v.area : '未填',
v.type == 1 ? '/' : v.addressDetail ? v.addressDetail : '未填',
v.type == 1 ? '/' : shipMsg[v.shipStatus],
v.type == 1 ? '/' : v.shipCompany || '/',
v.type == 1 ? '/' : v.shipNum || '/'
v.type == 3 ? (v.receiveTime ? formatTime(new Date(v.receiveTime + EIGHT_HOURS)) : '暂未填写') : '/',
prizeType,
prizeDataType,
v.type == 2 ? `${v.credits || 0}积分` : v.name || '',
v.type == 3 ? v.receiveName || '' : '/',
v.type == 3 ? (v.phone ? v.phone + '' : '暂未填写') : '/',
v.type == 3 ? v.province + v.city + v.area + v.addressdetail || '暂未填写' : '/',
shipTxt,
v.type == 3 ? v.shipCompany || '' : '/',
v.type == 3 ? (v.shipNum ? v.shipNum + '' : '') : '/'
])
})
let buffer = xlsx.build([
......@@ -229,7 +149,8 @@ export default class BaseController {
data: xlsxData
}
])
try {
console.log(`xlsxData: ${JSON.stringify(xlsxData)}`)
let result = await cloud.file.uploadFile({
fileContent: buffer,
fileName: title + new Date().getTime() + '.xlsx'
......@@ -239,166 +160,49 @@ export default class BaseController {
result.url = result.url.replace('http', 'https').replace('-internal', '')
}
return resultsModel.success(result)
} catch (e) {
console.log('上传文件出错', e)
// 打印日志
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR, `上传文件错误`)
}
} else {
return resultsModel.success(false)
}
}
//筛选中奖名单
@services([AwardsService])
async findWinnerInfoListBySearch(context: Context, { session }, [awardsService]: [AwardsService]) {
let { cloud } = context
let {
activityId,
title,
pageNo,
pageSize,
prizeId,
userId: userNick,
timeStart,
timeEnd,
shipStatus,
prizeType: type,
prizeDataType
} = context.data
console.log('data>>>>>', context.data)
if (!activityId) {
return resultsModel.error(CODE_TYPES.PARAMS_ERROR, `缺少activityId`)
}
if (!title) {
return resultsModel.error(CODE_TYPES.PARAMS_ERROR, `缺少title`)
}
console.log('prizeId=====', prizeId)
if (!prizeId && !userNick && !timeStart && !timeEnd && !shipStatus && !prizeDataType && !type) {
return resultsModel.error(CODE_TYPES.PARAMS_ERROR, `未填写筛选信息`)
}
console.log(
'activityId----',
activityId,
'prizeId---',
prizeId,
'userNick---',
userNick,
'timeStart---',
timeStart,
'timeEnd---',
timeEnd,
shipStatus
)
// 获取活动中奖列表
let total = await awardsService.getTotalObjectCount(
activityId,
prizeId,
userNick,
timeStart,
timeEnd,
shipStatus,
type,
prizeDataType
)
console.log('totle=========', total)
let awardslist = []
if (total > 10) {
let totalPage = Math.ceil(total / pageSize)
let awardMore = await awardsService.getUserPrizeByActivityId(
activityId,
pageNo,
pageSize,
prizeId,
userNick,
timeStart,
timeEnd,
shipStatus,
prizeDataType
)
// console.list()
awardslist = awardslist.concat(awardMore)
} else {
awardslist = await awardsService.getUserPrizeByActivityId(
activityId,
pageNo,
pageSize,
prizeId,
userNick,
timeStart,
timeEnd,
shipStatus,
prizeDataType
)
console.log('awardslist>>>>', awardslist)
}
console.log(`awardslist:》》》 ${JSON.stringify(awardslist)}《《《`)
awardslist.map(item => {
let ad = item.province + item.city + item.area + item.addressDetail,
type0 = item.type
item.prizeId = item._id
item.createTime = formatTime(new Date(item.createTime + EIGHT_HOURS)) || ''
item.receiveTime = item.receiveTime ? formatTime(new Date(item.receiveTime + EIGHT_HOURS)) : '未填'
item.prizeDataType = prizePoolType[item.prizeDataType]
item.type = prizeKind[item.type]
item.receiveName = type0 == 3 ? item.receiveName || '未填' : '/'
item.phone = type0 == 3 ? item.phone || '未填' : '/'
item.address = type0 == 3 ? (item.province ? ad : '未填') : '/'
item.shipStatus = type0 == 3 ? shipMsg[item.shipStatus] : '/'
item.shipCompany = type0 == 3 ? item.shipCompany || '/' : '/'
item.shipNum = type0 == 3 ? item.shipNum || '/' : '/'
})
// console.log(`xlsxData: ${JSON.stringify(xlsxData)}`);
try {
return resultsModel.success({ list: awardslist, total })
} catch (e) {
console.log('上传文件出错', e)
// 打印日志
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR, `查看结果错误`)
}
}
/*
[{
"data": [
["序列", "中奖时间", "收获地址", "邮编"],
["1","creatTime","XXX","XXX"]
],
"name": "测试活动LSS1594797305510"
}]
*/
//导入发货状态信息
/**
* 导入发货
*/
@paramsCheck(['activityId', 'fileName'])
@services([AwardsService])
async downloadFile(context: Context, { session }, [awardsService]: [AwardsService]) {
const cloud = context.cloud
const { cloud } = context
//获取活动id
const { activityId, fileName } = context.data
console.log('====--=-=-=-=-', fileName)
//-----------
let fileId = fileName
let result,
total = 0
let total = 0
let result;
try {
result = await cloud.file.downloadFile({ fileId })
result = await cloud.file.downloadFile({ fileId: fileName })
}
catch{
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR, 'fileId错误')
}
const sheets = xlsx.parse(result)
console.log(sheets, 'sheets-------')
//接口调用
let { data } = sheets[0]
if (data[1].length == 3) {
console.log(JSON.stringify(data), 'data----------')
if (!data[1] || data[1].length !== 0) {
if (data[1].length <= 3) {
for (let i = 1; i < data.length; i++) {
//activityId, prizeId, shipCompany, shipNum,
let prizeId = data[i][0]
let shipCompany = data[i][1]
let shipNum = data[i][2]
// 此处需要判断用户是否填写了地址
let result2 = await awardsService.setUserShipStatus(activityId, prizeId, shipCompany, shipNum)
total += result2
console.log('>>>')
}
console.log(total, data, 'total,data')
return resultsModel.success({ total, data })
} else {
console.log(data[1].length, 'length')
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR, '导入文件格式错误')
}
} catch (e) {
console.log('e', e)
} else {
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR, '导入文件出现错误')
}
}
......
......@@ -52,7 +52,7 @@ export default class ActivitSaveController {
}
// 概率奖品配置需要增加 properiodfrom properiodto字段
// prizeList = activityconfigService.setPrizeProbalityRange(prizeList)
prizeList = activityconfigService.setPrizeProbalityRange(prizeList)
// 所有奖品均存在b_prize_config表里, 根据需求定义的奖品参数都要整合到allPrizeLists里
// level 排序用避免查询乱序
......
......@@ -7,14 +7,13 @@ import RuleController from './controller/rule.controller'
import RaobaoItemController from './controller/taobaoItem.controller'
import SaveController from './controller/save.controller'
const { getActivityList, getActivityDetail, delActivity } = new ActivityController()
const { getActivityList, getActivityDetail, delActivity,createCopyActivity } = new ActivityController()
const { sellerSaasSave, sellerSave } = new SellerController()
const {
findWinnerInfoList,
exportAwardsList,
findWinnerInfoListBySearch,
getAwardsList,
downloadFile,
exportAwardsInfoBySearch
} = new AwardsController()
const { generateRule } = new RuleController()
const { findItemListByStatus, findItemListByIds, queryBenefitByEname } = new RaobaoItemController()
......@@ -28,10 +27,10 @@ export default {
sellerSave,
findWinnerInfoList,
exportAwardsList,
findWinnerInfoListBySearch,
downloadFile,
exportAwardsInfoBySearch,
findItemListByStatus,
findItemListByIds,
queryBenefitByEname
queryBenefitByEname,
createCopyActivity,
getAwardsList
}
......@@ -5,12 +5,12 @@
import { BaseDao } from '../sdk'
import { AWARDS_DB_NAME } from '../db'
import { DRAW_STATUS, SHIP_STATUS } from '../constants'
import { DRAW_STATUS, PRIZE_TYPE, SHIP_STATUS } from '../constants'
export default class AwardsService {
context: Context
awardsdao: IBaseDao
awardsDao: IBaseDao
constructor(context: Context) {
this.awardsdao = new BaseDao(context, AWARDS_DB_NAME)
this.awardsDao = new BaseDao(context, AWARDS_DB_NAME)
}
// 添加排行榜待开奖列表
......@@ -24,7 +24,7 @@ export default class AwardsService {
}
})
try {
await this.awardsdao.insertMany(list)
await this.awardsDao.insertMany(list)
return true
} catch (e) {
console.log(`添加排行榜待开奖列表出错:${e}`)
......@@ -32,134 +32,99 @@ export default class AwardsService {
}
}
// 根据活动id查找中奖名单
async getAwardslistByActivityId(activityId: string, pageNo = 1, pageSize = 500) {
if (!activityId) return false
return await this.awardsdao.find(
{ activityId },
{
sort: {
score: -1,
rankTime: -1
},
limit: pageSize,
skip: (pageNo - 1) * pageSize
}
)
}
//获取中奖名单长度
async getAwardslistCount(activityId: string) {
if (!activityId) {
return false
}
return await this.awardsdao.count({
activityId: activityId
})
}
// 条件搜索--查询中奖信息
async getUserPrizeByActivityId(
activityId: string,
pageNo: number,
pageSize: number,
prizeId: string,
userNick: string,
timeStart: number,
timeEnd: number,
shipStatus: number,
type: number
) {
let p = prizeId ? { _id: prizeId } : ''
let u = userNick ? { userNick: { $regex: '.*' + userNick + '.*' } } : ''
let c = timeStart > 0 && timeEnd > 0 ? { createTime: { $gt: timeStart, $lt: timeEnd } } : ''
let s = shipStatus
? shipStatus == 1
? { shipStatus: { $in: [SHIP_STATUS.NO_ADDRESS, SHIP_STATUS.NO_SHIP, SHIP_STATUS.HAS_SHIP] } }
: shipStatus == 2
? { shipStatus: { $in: [SHIP_STATUS.NO_ADDRESS, SHIP_STATUS.NO_SHIP] } }
: { shipStatus: SHIP_STATUS.HAS_SHIP }
: ''
let t = type ? { type: +type } : ''
let arr = [p, u, c, s, t]
arr = arr.filter(i => {
return i
})
console.log('arr--222---', arr)
return await this.awardsdao.find(
{
activityId,
$and: arr
},
{
limit: pageSize,
skip: (pageNo - 1) * pageSize
}
)
}
//《条件搜索》获取中奖名单长度
async getTotalObjectCount(
activityId: string,
prizeId: string,
userNick: string,
timeStart: number,
timeEnd: number,
shipStatus: number,
type: number,
prizeDataType: number
) {
let p = prizeId ? { _id: prizeId } : ''
let pt = prizeDataType ? { prizeDataType: prizeDataType } : ''
let u = userNick ? { userNick: { $regex: '.*' + userNick + '.*' } } : ''
let c = timeStart > 0 && timeEnd > 0 ? { createTime: { $gt: timeStart, $lt: timeEnd } } : ''
let s = shipStatus
? shipStatus == 1
? { shipStatus: { $in: [SHIP_STATUS.NO_ADDRESS, SHIP_STATUS.NO_SHIP, SHIP_STATUS.HAS_SHIP] } }
: shipStatus == 2
? { shipStatus: { $in: [SHIP_STATUS.NO_ADDRESS, SHIP_STATUS.NO_SHIP] } }
: { shipStatus: SHIP_STATUS.HAS_SHIP }
: ''
let t = type ? { type: +type } : ''
let arr = [p, u, c, s, t, pt]
arr = arr.filter(i => {
return i
})
console.log('arr--111---', arr, 's>>>', s)
return await this.awardsdao.count({
activityId,
$and: arr
})
}
//《条件搜索》导入发货状态
async setUserShipStatus(activityId: string, prizeId: string, shipCompany: string, shipNum: number | string) {
async setUserShipStatus(activityId, prizeId, shipCompany, shipNum) {
prizeId = prizeId ? prizeId : '/'
shipCompany = shipCompany ? shipCompany : ''
shipNum = shipNum !== null ? shipNum : ''
let status = 0
shipNum = shipNum ? shipNum : ''
let status = SHIP_STATUS.NO_SHIP
console.log(shipCompany, shipNum, 'shipCompany,shipNum')
if (shipCompany && shipNum) {
status = SHIP_STATUS.HAS_SHIP
} else {
status = SHIP_STATUS.NO_SHIP
}
if (status == SHIP_STATUS.HAS_SHIP) {
return await this.awardsdao.update(
console.log(activityId, prizeId, PRIZE_TYPE.OBJECT)
const result = await this.awardsDao.update(
{
activityId,
_id: prizeId,
type: PRIZE_TYPE.OBJECT,
shipStatus: SHIP_STATUS.NO_SHIP
},
{
$set: {
shipCompany,
shipNum,
shipStatus: SHIP_STATUS.HAS_SHIP
shipStatus: status
}
}
)
console.log(result, 'result')
return result
} else {
return 0
}
}
// 根据活动id查找中奖名单
async getAwardListByActivityId({
activityId = '',
title = '',
pageNo = 1,
pageSize = 10,
prizeId = null,
userNick = '',
type = null,
prizeDataType = null,
shipStatus = null,
startTime = null,
endTime = null,
isExport = false
}) {
if (!activityId) return false
let p = prizeId ? { _id: prizeId } : null
let u = userNick ? { userNick: { $regex: '.*' + userNick + '.*' } } : null
let c = startTime > 0 && endTime > 0 ? { createTime: { $gt: startTime, $lt: endTime } } : null
let s = shipStatus
? (shipStatus == 1
? { shipStatus: { $in: [SHIP_STATUS.NO_ADDRESS, SHIP_STATUS.NO_SHIP, SHIP_STATUS.HAS_SHIP] } }
: (shipStatus == 2
? { shipStatus: { $in: [SHIP_STATUS.NO_ADDRESS, SHIP_STATUS.NO_SHIP] } }
: { shipStatus: SHIP_STATUS.HAS_SHIP }
)
)
: '';
let t = type ? { type: +type } : null
let pt = prizeDataType ? { prizeDataType: +prizeDataType } : null
let arr = []
if (p) arr.push(p)
if (u) arr.push(u)
if (c) arr.push(c)
if (s) arr.push(s)
if (t) arr.push(t)
if (pt) arr.push(pt)
arr = arr.filter(i => i)
console.log('arr--111---', arr, activityId)
const query = { activityId }
// @ts-ignore
if (arr.length > 0) query.$and = arr
const list = await this.awardsDao.find(query, {
limit: pageSize,
skip: (pageNo - 1) * pageSize,
sort: {
score: -1,
rankTime: -1
}
})
const total = await this.awardsDao.count(query)
return {
list,
total,
message: '成功',
pageNo,
pageSize
}
}
}
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