Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
yoho-activity-platform
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
李奇
6 years ago
Commit
a80c95a793bf6d5bb053e556d05c13c3e852796b
1 parent
2b714ca8
master
...
feature/add-verify
feature/change-admin-static-url
feature/del-privateIps
feature/new-pro-fes
feature/only-for-test
feature/pressure-test
feature/share-link
feature/timezone
feature/yoluck
hotfix/export
hotfix/fix-appSecret
hotfix/republish
release/6.7.9
release/6.8.3
release/6.9.5
release/yohood-lottrey
zero-buy-two
tag1.0
fixed:红包不能重复领取时返回不中奖
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
190 deletions
apps/api/models/wheel-surf.js
public/vue/wheel-surf/components/add-prize.vue
apps/api/models/wheel-surf.js
View file @
a80c95a
...
...
@@ -168,8 +168,6 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
}
}
if
(
getPrize
.
type
!==
1
)
{
console
.
log
(
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'
);
// 校验剩余库存
if
(
getPrize
.
total_left
>
0
)
{
// 减库存
...
...
@@ -198,7 +196,11 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
redpacToken
:
getPrize
.
value
}
});
if
(
sendResult
&&
sendResult
.
code
===
200
)
{
getPrize
.
desc
=
'恭喜您获得'
+
sendResult
.
data
.
amount
+
'元红包'
;
if
(
sendResult
.
data
.
isRepReceive
===
'N'
)
{
sendResult
.
code
=
201
;
// 不能重复领取
}
else
{
getPrize
.
desc
=
'恭喜您获得'
+
sendResult
.
data
.
amount
+
'元红包'
;
}
}
}
else
if
(
getPrize
.
type
===
3
)
{
sendResult
=
await
this
.
get
({
...
...
@@ -218,8 +220,8 @@ class ActWheelSurfModel extends global.yoho.BaseModel {
if
(
sendResult
.
code
!==
200
)
{
getPrize
=
null
;
for
(
let
item
of
prize
)
{
if
(
item
.
type
===
1
)
{
getPrize
=
item
;
if
(
item
.
dataValues
.
type
===
1
)
{
getPrize
=
item
.
dataValues
;
break
;
}
}
...
...
public/vue/wheel-surf/components/add-prize.vue
View file @
a80c95a
...
...
@@ -5,28 +5,30 @@
<div slot="left" class="split-pane">
<Form ref="prizeForm" :model="prize" :rules="prizeRules" :label-width="120">
<FormItem label="奖品位置" prop="prize_idx">
<Input v-model="prize.prize_idx" placeholder="奖品位置序号(竖直方向顺时针从1开始)"></Input>
<Input v-model="prize.prize_idx" placeholder="奖品位置序号(竖直方向顺时针从1开始)"
:maxlength="1"
></Input>
</FormItem>
<FormItem label="奖品名称" prop="name">
<Input v-model="prize.name" placeholder="奖品名称" :maxlength="50"></Input>
</FormItem>
<FormItem label="奖品类型" prop="type">
<Select v-model="prize.type">
<Select v-model="prize.type"
@on-change="typeChange"
>
<Option :value="1">谢谢惠顾</Option>
<Option :value="2">红包</Option>
<Option :value="3">优惠券</Option>
<Option :value="4">实物奖品</Option>
</Select>
</FormItem>
<FormItem label="奖品
值
" prop="value">
<FormItem label="奖品
口令
" prop="value">
<Input v-model="prize.value" placeholder="红包优惠券口令(实物奖品不填)" :maxlenght="200"></Input>
</FormItem>
<FormItem label="奖品总数" prop="total">
<Input v-model="prize.total" placeholder="奖品总数"></Input>
<Input v-model="prize.total" placeholder="奖品总数(不限量奖品可填9999999999)" number
:maxlength="9"></Input>
</FormItem>
<FormItem label="中奖概率" prop="chance">
<Col span="18">
<Input v-model="prize.chance" placeholder="中奖概率请输入小数或者整数"></Input></Col>%
<Input v-model="prize.chance"
placeholder="中奖概率请输入小数或者整数" number :maxlength="10"></Input></Col>%
</FormItem>
<FormItem label="奖品图片" prop="img">
<div class="preview-wrap" v-show="prize.img">
...
...
@@ -39,17 +41,12 @@
</FormItem>
</Form>
<div class="add-btn">
<Button v-show="modifyBottom" type="primary" @click="addPrize">添加</Button>
<Button v-show="!modifyBottom" type="primary" @click="updatePrize">修改</Button>
<Button type="primary" @click="addPrize">添加</Button>
<Button style="" type="error" @click="savePrize">保存右侧已添加商品</Button>
</div>
</div>
<div slot="right" class="split-pane right">
<Table v-show="!modifyBottom" highlight-row ref="currentRowTable"
@on-current-change="handleRowChange" :columns="prizeColumns" :data="prizes"></Table>
<Table v-show="modifyBottom" :columns="prizeAddColumns" :data="prizes"></Table>
<div class="save">
<Button style="" v-show="modifyBottom" type="primary" @click="savePrize">保存</Button>
</div>
<Table :columns="prizeColumns" :data="prizes"></Table>
</div>
</Split>
</div>
...
...
@@ -116,78 +113,37 @@
{
title: '奖品操作',
render: (h, {row}) => {
return h('Button', {
props: {
type: 'error',
size: 'small'
},
on: {
click: () => {
this.deletePrize(row.id, row._index);
}
}
}, '删除');
}
}
],
prizeAddColumns: [
{
title: '位置序号',
key: 'prize_idx'
},
{
title: '奖品名称',
key: 'name'
},
{
title: '奖品类型',
render: (h, {row}) => {
return h('span', {}, pirzeType[row.type]);
}
},
{
title: '奖品值',
key: 'value'
},
{
title: '奖品总数',
key: 'total'
},
{
title: '中奖概率',
render: (h, {row}) => {
return h('span', {}, row.chance + '%');
}
},
{
title: '奖品图片',
key: 'img',
render: (h, {row}) => {
return h('img', {
attrs: {
src: row.img
},
style: {
width: '100%',
height: 'auto'
}
});
}
},
{
title: '奖品操作',
render: (h, {row}) => {
return h('Button', {
props: {
type: 'error',
size: 'small'
},
on: {
click: () => {
this.deletePrize(row.id, row._index);
}
}
}, '删除');
return (h('div', {},
[
h('Button', {
props: {
type: 'error',
size: 'small'
},
style: {
margin: '2px'
},
on: {
click: () => {
this.editPrize(row._index);
}
}
}, '编辑'),
h('Button', {
props: {
type: 'primary',
size: 'small'
},
style: {
margin: '2px'
},
on: {
click: () => {
this.deletePrize(row._index);
}
}
}, '删除')
]));
}
}
],
...
...
@@ -212,13 +168,15 @@
{required: true}
],
value: [
{required: false, message: '
奖品
值不能为空', trigger: 'blur'}
{required: false, message: '
红包和优惠券
值不能为空', trigger: 'blur'}
],
total: [
{required: false, message: '奖品总数不能为空', trigger: 'blur'}
{required: true, message: '奖品总数不能为空'},
{type: 'integer', message: '奖品总数必须是整数', trigger: 'blur'}
],
chance: [
{required: true, message: '中奖概率不能为空', trigger: 'blur'}
{required: true, message: '中奖概率不能为空'},
{type: 'number', message: '奖品总数必须是数字', trigger: 'blur'}
],
img: [
{required: true, message: '奖品图片不能为空', trigger: 'blur'}
...
...
@@ -230,125 +188,108 @@
methods: {
addPrize() {
const form = 'prizeForm';
this.prize.total_left = this.prize.total;
this.validateForm(form).then(() => {
let storage = window.localStorage;
this.prizes.push(this.prize);
storage.setItem(this.actId, JSON.stringify(this.prizes));
this.prizes.push(Object.assign({}, this.prize));
this.prizes.sort((a, b) => {
return +a.prize_idx - +b.prize_idx;
});
this.formReset(form);
this.prizeList();
}).catch(() => {
});
}).catch(() => {});
},
typeChange(type) {
this.prizeRules.value[0].required = (type === 2 || type === 3);
},
savePrize() {
if (!this.prizes.length) {
this.$Modal.error({
let len = this.prizes.length;
if (len !== 6 && len !==8) {
return this.$Modal.error({
title: '错误',
content: '请
添加商品
'
content: '请
确认商品数量是否为6或8
'
});
} else {
let chance = 0;
}
this.prizes.map((value) => {
chance += +value.chance;
let prizeIdxArr = [];
let prizeIdxStatus = true;
this.prizes.map(prize => {
prizeIdxArr.push(+prize.prize_idx);
});
return chance;
});
if (chance !== 100) {
return this.$Modal.error({
title: '错误',
content: '概率有误'
});
for (let i = 1; i < len + 1; i++) {
if (prizeIdxArr.indexOf(i) < 0) {
prizeIdxStatus = false;
break;
}
$.ajax({
method: 'post',
url: '/admin/wheelSurf/api/prize/create',
contentType: 'application/json',
data: JSON.stringify(this.prizes)
}).then(res => {
if (res.code === 200) {
this.$Message.success('奖品新增成功');
let storage = window.localStorage;
}
storage.removeItem(this.actId);
this.prizeList();
} else {
this.$Message.error({
title: '错误',
content: res.msg
});
}
if (!prizeIdxStatus) {
return this.$Modal.error({
title: '错误',
content: `请确认商品位置序号是否为1~${len}`
});
}
},
handleRowChange(currentRow) {
this.prize = currentRow;
},
updatePrize: function () {
const form = 'prizeForm';
this.$Modal.confirm({
title: '修改',
content: '确认修改当前奖品?',
onOk: () => {
$.ajax({
method: 'post',
url: '/admin/wheelSurf/api/prize/modify',
contentType: 'application/json',
data: JSON.stringify(this.prize)
}).then(res => {
if (res.code === 200) {
this.$Message.success('修改奖品成功');
} else {
this.$Message.error({
title: '错误',
content: res.msg
});
}
this.formReset(form);
this.prizeList();
});
},
onCancel: () => {
this.$Message.info('取消成功');
}
let prizeTypeArr = [];
this.prizes.map(prize => {
prizeTypeArr.push(+prize.type);
});
},
deletePrize(id, index) {
let fun;
if (id) {
fun = () => $.ajax({
url: '/admin/wheelSurf/api/prize/delete',
data: {id}
}).then(res => {
if (res.code === 200) {
this.$Message.success('奖品删除成功');
}
this.prizeList();
if (prizeIdxArr.indexOf(1) < 0) {
return this.$Modal.error({
title: '错误',
content: `商品中至少需要包含一条谢谢惠顾`
});
} else {
const form = 'prizeForm';
}
this.formReset(form);
fun = () => this.prizes.splice(index, 1);
// 概率校验
let totalChance = 0;
Number.prototype._chanceAdd = function (arg) {
var r1, r2, m;
try { r1 = this.toString().split('.')[1].length; } catch (e) {r1 = 0;}
try { r2 = arg.toString().split('.')[1].length; } catch (e) {r2 = 0;}
m = Math.pow(10, Math.max(r1, r2));
return (this * m + arg * m) / m
};
this.prizes.map(prize => {
totalChance = totalChance._chanceAdd(+prize.chance)
});
if (totalChance !== 100) {
return this.$Modal.error({
title: '错误',
content: `请确认商品各个商品概率之和为100%`
});
}
this.$Modal.confirm({
title: '删除',
content: '奖品删除后不可恢复,确认删除?',
onOk: fun,
onCancel: () => {
this.$Message.info('取消成功');
$.ajax({
method: 'post',
url: '/admin/wheelSurf/api/prize/create',
contentType: 'application/json',
data: JSON.stringify(this.prizes)
}).then(res => {
if (res.code === 200) {
this.$Message.success('奖品新增成功');
this.prizeList();
} else {
this.$Message.error({
title: '错误',
content: res.msg
});
}
});
},
prizeList() {
let storage = window.localStorage;
editPrize(idx) {
this.prize = this.prizes[idx];
},
deletePrize(index) {
this.prizes.splice(index, 1);
},
prizeList() {
$.ajax({
url: '/admin/wheelSurf/api/prize/list',
data: {act_id: this.actId}
...
...
@@ -357,8 +298,11 @@
if (res.data.length) {
this.modifyBottom = false;
this.prizes = res.data;
this.prizes.sort((a, b) => {
return +a.prize_idx - +b.prize_idx;
});
} else {
this.prizes =
JSON.parse(storage.getItem(this.actId)) ||
[];
this.prizes = [];
this.modifyBottom = true;
}
}
...
...
Please
register
or
login
to post a comment