优惠劵领取
parent
b111b4ac6f
commit
734459d3ba
|
|
@ -30,9 +30,6 @@ class Coupon extends Common
|
|||
{
|
||||
// 调用父类前置方法
|
||||
parent::__construct();
|
||||
|
||||
// 是否登录
|
||||
$this->IsLogin();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -45,6 +42,9 @@ class Coupon extends Common
|
|||
*/
|
||||
public function Index()
|
||||
{
|
||||
// 获取基础配置信息
|
||||
$base = CallPluginsData('coupon');
|
||||
|
||||
// 优惠劵列表
|
||||
$coupon_params = [
|
||||
'where' => [
|
||||
|
|
@ -57,6 +57,13 @@ class Coupon extends Common
|
|||
'user' => $this->user,
|
||||
];
|
||||
$ret = CallPluginsServiceMethod('coupon', 'CouponService', 'CouponList', $coupon_params);
|
||||
|
||||
// 返回数据
|
||||
$result = [
|
||||
'base' => $base['data'],
|
||||
'data' => $ret['data'],
|
||||
];
|
||||
return DataReturn('处理成功', 0, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -64,11 +71,15 @@ class Coupon extends Common
|
|||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2018-07-12
|
||||
* @date 2019-10-15
|
||||
* @desc description
|
||||
*/
|
||||
public function User()
|
||||
{
|
||||
// 是否登录
|
||||
$this->IsLogin();
|
||||
|
||||
// 获取用户优惠劵
|
||||
$coupon_params = [
|
||||
'user' => $this->user,
|
||||
'where' => [
|
||||
|
|
@ -78,5 +89,28 @@ class Coupon extends Common
|
|||
];
|
||||
return CallPluginsServiceMethod('coupon', 'UserCouponService', 'CouponUserList', $coupon_params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取优惠劵
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @date 2019-10-15
|
||||
* @desc description
|
||||
*/
|
||||
public function Receive()
|
||||
{
|
||||
// 是否登录
|
||||
$this->IsLogin();
|
||||
|
||||
// 是否ajax请求
|
||||
if(!IS_AJAX)
|
||||
{
|
||||
return $this->error('非法访问');
|
||||
}
|
||||
|
||||
// 领取优惠劵
|
||||
return CallPluginsServiceMethod('coupon', 'CouponService', 'UserReceiveCoupon', $this->data_post);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
@ -75,6 +75,41 @@ function PathToParams($key = null, $default = null, $path = '')
|
|||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用插件方法 - 获取插件配置信息
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @datetime 2019-10-16T22:03:48+0800
|
||||
* @param [string] $plugins [插件名称]
|
||||
* @param [array] $attachment_field [自定义附件字段]
|
||||
* @param [string] $service_name [附件定义的服务层类名]
|
||||
* @param [string] $attachment_property [附件属性名称]
|
||||
*/
|
||||
function CallPluginsData($plugins, $attachment_field = [], $service_name = '', $attachment_property = 'base_config_attachment_field')
|
||||
{
|
||||
// 未指定附件字段则自动去获取
|
||||
$attachment = [];
|
||||
if(empty($attachment_field) && !empty($attachment_property))
|
||||
{
|
||||
// 类自定义或者默认两个类
|
||||
$service_all = empty($service_name) ? ['BaseService', 'Service'] : [$service_name];
|
||||
foreach($service_all as $service)
|
||||
{
|
||||
// 服务层获取附件属性
|
||||
$plugins_class = 'app\plugins\\'.$plugins.'\service\\'.$service;
|
||||
if(class_exists($plugins_class) && property_exists($plugins_class, $attachment_property))
|
||||
{
|
||||
$attachment = $plugins_class::${$attachment_property};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取配置信息
|
||||
return app\service\PluginsService::PluginsData($plugins, $attachment);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用插件方法 - 访问为静态
|
||||
* @author Devil
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@ class PluginsService
|
|||
{
|
||||
$data = cache($key);
|
||||
}
|
||||
|
||||
// 数据不存在则从数据库读取
|
||||
if(empty($data))
|
||||
{
|
||||
// 获取数据
|
||||
|
|
@ -49,7 +51,7 @@ class PluginsService
|
|||
{
|
||||
$data = json_decode($data, true);
|
||||
|
||||
// 是否有图片需要处理
|
||||
// 是否有自定义附件需要处理
|
||||
if(!empty($attachment_field) && is_array($attachment_field))
|
||||
{
|
||||
foreach($attachment_field as $field)
|
||||
|
|
@ -60,6 +62,26 @@ class PluginsService
|
|||
$data[$field] = ResourcesService::AttachmentPathViewHandle($data[$field]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 所有附件后缀名称
|
||||
$attachment_ext = config('ueditor.fileManagerAllowFiles');
|
||||
|
||||
// 未自定义附件则自动根据内容判断处理附件,建议自定义附件字段名称处理更高效
|
||||
if(!empty($attachment_ext) && is_array($attachment_ext))
|
||||
{
|
||||
foreach($data as $k=>$v)
|
||||
{
|
||||
$ext = strrchr(substr($v, -6), '.');
|
||||
if($ext !== false)
|
||||
{
|
||||
if(in_array($ext, $attachment_ext))
|
||||
{
|
||||
$data[$k.'_old'] = $v;
|
||||
$data[$k] = ResourcesService::AttachmentPathViewHandle($v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 存储缓存
|
||||
|
|
@ -114,6 +136,9 @@ class PluginsService
|
|||
}
|
||||
}
|
||||
|
||||
// 移除多余的字段
|
||||
unset($params['data']['pluginsname'], $params['data']['pluginscontrol'], $params['data']['pluginsaction']);
|
||||
|
||||
// 数据更新
|
||||
if(Db::name('Plugins')->where(['plugins'=>$params['plugins']])->update(['data'=>json_encode($params['data']), 'upd_time'=>time()]))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ App({
|
|||
"user_orderaftersale": "退款/售后",
|
||||
"user_orderaftersale_detail": "订单售后",
|
||||
"user_order_comments": "订单评论",
|
||||
"coupon": "领劵中心",
|
||||
"user_coupon": "优惠劵",
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"pages": ["pages/user-coupon/user-coupon",
|
||||
"pages": [
|
||||
"pages/coupon/coupon",
|
||||
"pages/index/index",
|
||||
"pages/goods-category/goods-category",
|
||||
"pages/cart/cart",
|
||||
|
|
@ -25,7 +26,8 @@
|
|||
"pages/user-integral/user-integral",
|
||||
"pages/user-goods-browse/user-goods-browse",
|
||||
"pages/user-orderaftersale/user-orderaftersale",
|
||||
"pages/user-orderaftersale-detail/user-orderaftersale-detail"
|
||||
"pages/user-orderaftersale-detail/user-orderaftersale-detail",
|
||||
"pages/user-coupon/user-coupon"
|
||||
|
||||
],
|
||||
"window": {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,128 @@
|
|||
const app = getApp();
|
||||
Page({
|
||||
data: {
|
||||
data_bottom_line_status: false,
|
||||
data_list_loding_status: 1,
|
||||
data_list_loding_msg: '',
|
||||
data_list: [],
|
||||
data_base: null,
|
||||
},
|
||||
|
||||
onLoad(params) {
|
||||
this.init();
|
||||
},
|
||||
|
||||
onShow() {
|
||||
wx.setNavigationBarTitle({ title: app.data.common_pages_title.coupon });
|
||||
},
|
||||
|
||||
init() {
|
||||
// 获取数据
|
||||
this.get_data_list();
|
||||
},
|
||||
|
||||
// 获取数据
|
||||
get_data_list() {
|
||||
var self = this;
|
||||
wx.showLoading({ title: "加载中..." });
|
||||
this.setData({
|
||||
data_list_loding_status: 1
|
||||
});
|
||||
|
||||
wx.request({
|
||||
url: app.get_request_url("index", "coupon"),
|
||||
method: "POST",
|
||||
data: {},
|
||||
dataType: "json",
|
||||
success: res => {
|
||||
wx.hideLoading();
|
||||
wx.stopPullDownRefresh();
|
||||
if (res.data.code == 0) {
|
||||
var data = res.data.data;
|
||||
var status = ((data.data || []).length > 0);
|
||||
this.setData({
|
||||
data_base: data.base || null,
|
||||
data_list: data.data || [],
|
||||
data_list_loding_msg: '',
|
||||
data_list_loding_status: status ? 3 : 0,
|
||||
data_bottom_line_status: status,
|
||||
});
|
||||
|
||||
// 导航名称
|
||||
if ((data.base || null) != null && (data.base.application_name || null) != null)
|
||||
{
|
||||
wx.setNavigationBarTitle({ title: data.base.application_name });
|
||||
}
|
||||
} else {
|
||||
self.setData({
|
||||
data_bottom_line_status: false,
|
||||
data_list_loding_status: 2,
|
||||
data_list_loding_msg: res.data.msg,
|
||||
});
|
||||
app.showToast(res.data.msg);
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.hideLoading();
|
||||
wx.stopPullDownRefresh();
|
||||
self.setData({
|
||||
data_bottom_line_status: false,
|
||||
data_list_loding_status: 2,
|
||||
data_list_loding_msg: '服务器请求出错',
|
||||
});
|
||||
app.showToast("服务器请求出错");
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 领取事件
|
||||
receive_event(e) {
|
||||
var user = app.get_user_cache_info(this, "receive_event");
|
||||
// 用户未绑定用户则转到登录页面
|
||||
if (app.user_is_need_login(user)) {
|
||||
wx.redirectTo({
|
||||
url: "/pages/login/login?event_callback=receive_event"
|
||||
});
|
||||
return false;
|
||||
} else {
|
||||
var self = this;
|
||||
var index = e.currentTarget.dataset.index;
|
||||
var value = e.currentTarget.dataset.value;
|
||||
var temp_list = this.data.data_list;
|
||||
if (temp_list[index]['is_operable'] != 0) {
|
||||
wx.showLoading({ title: "处理中..." });
|
||||
wx.request({
|
||||
url: app.get_request_url("receive", "coupon"),
|
||||
method: "POST",
|
||||
data: { "coupon_id": value },
|
||||
dataType: "json",
|
||||
header: { 'content-type': 'application/x-www-form-urlencoded' },
|
||||
success: res => {
|
||||
wx.hideLoading();
|
||||
if (res.data.code == 0) {
|
||||
app.showToast(res.data.msg, "success");
|
||||
if (self.data.data_base != null && self.data.data_base.is_repeat_receive != 1)
|
||||
{
|
||||
temp_list[index]['is_operable'] = 0;
|
||||
temp_list[index]['is_operable_name'] = '已领取';
|
||||
self.setData({ data_list: temp_list });
|
||||
}
|
||||
} else {
|
||||
app.showToast(res.data.msg);
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
wx.hideLoading();
|
||||
app.showToast("服务器请求出错");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 下拉刷新
|
||||
onPullDownRefresh() {
|
||||
this.get_data_list();
|
||||
},
|
||||
|
||||
});
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"enablePullDownRefresh": true
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<image wx:if="{{(data_base || null) != null && (data_base.banner_images || null) != null}}" class="banner wh-auto dis-block" src="{{data_base.banner_images}}" mode="widthFix" />
|
||||
|
||||
<!-- 优惠劵列表 -->
|
||||
<view wx:if="{{data_list.length > 0}}" class="data-list">
|
||||
<block wx:for="{{data_list}}" wx:key="item">
|
||||
<view class="item spacing-mt bg-white {{item.is_operable == 0 ? 'item-disabled' : ''}}" style="border:1px solid {{item.bg_color_value}};">
|
||||
<view class="v-left fl">
|
||||
<view class="base single-text" style="color:{{item.bg_color_value}};">
|
||||
<text class="symbol">¥</text>
|
||||
<text class="price">{{item.discount_value}}</text>
|
||||
<text class="unit">{{item.type == 0 ? '元' : '折'}}</text>
|
||||
<text wx:if="{{(item.desc || null) != null}}" class="desc cr-888">{{item.desc}}</text>
|
||||
</view>
|
||||
<view wx:if="{{(item.use_limit_type_name || null) != null}}" class="base-tips cr-666 single-text">{{item.use_limit_type_name}}</view>
|
||||
</view>
|
||||
<view class="v-right fr" bindtap="receive_event" data-index="{{index}}" data-value="{{item.id}}" style="background:{{item.bg_color_value}};">
|
||||
<text class="circle"></text>
|
||||
<text>{{item.is_operable_name}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{data_list_loding_status != 3}}">
|
||||
<import src="/pages/common/nodata.wxml" />
|
||||
<template is="nodata" data="{{status: data_list_loding_status, msg: data_list_loding_msg}}"></template>
|
||||
</view>
|
||||
|
||||
<import src="/pages/common/bottom_line.wxml" />
|
||||
<template is="bottom_line" data="{{status: data_bottom_line_status}}"></template>
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* 数据列表
|
||||
*/
|
||||
.data-list {
|
||||
padding: 0 10rpx;
|
||||
}
|
||||
.data-list .item {
|
||||
overflow: hidden;
|
||||
height: 180rpx;
|
||||
border: 1px solid #D2364C;
|
||||
}
|
||||
.v-left {
|
||||
width: calc(100% - 140rpx);
|
||||
padding: 30rpx 0 30rpx 20rpx;
|
||||
box-sizing:border-box;
|
||||
-moz-box-sizing:border-box;
|
||||
-webkit-box-sizing:border-box;
|
||||
}
|
||||
.v-left .base {
|
||||
color: #D2364C;
|
||||
}
|
||||
.v-left .base .symbol {
|
||||
font-family: Verdana, Tahoma;
|
||||
font-size: 48rpx;
|
||||
font-weight: 400;
|
||||
}
|
||||
.v-left .base .price {
|
||||
font-weight: 700;
|
||||
font-family: arial;
|
||||
font-size: 76rpx;
|
||||
}
|
||||
.v-left .base .desc {
|
||||
margin-left: 20rpx;
|
||||
}
|
||||
.v-left base-tips, .v-left .base-time {
|
||||
margin-top: 10rpx;
|
||||
}
|
||||
|
||||
.v-right {
|
||||
background: #d2364c;
|
||||
width: 140rpx;
|
||||
height: 180rpx;
|
||||
color: #fff;
|
||||
font-weight: 500;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
}
|
||||
.v-right:before {
|
||||
content: '';
|
||||
display: inline-block;
|
||||
height: 100%;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.v-right .circle {
|
||||
display: block;
|
||||
position: absolute;
|
||||
left: -1px;
|
||||
top: -3px;
|
||||
width: 3px;
|
||||
height: 180rpx;
|
||||
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAACpCAYAAADur4c3AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3NpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8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z//z8DDDAxIAFyOVeBOAHEYfyPMDsLmXMfmfMT2YADDP8h4CEQq4A4aUDMA1LNSKZDXwJxGcg1yJaWIXOeInO+IxuwA+acK0AsA+IEADEbic7hhPOAer4DcQcQMyNb2oLMeYVsADcyZwPMObuBWBTEsQFpI9E54sjO+QvEc0F+YoHKJgHxJ2TnvEM2gBmZswrmnA1AzAXiaJPhHC1k58BNQ3bBTGTOR2QD/iJzFsH8Mw/kHxBHggzn2KA7BxzWyC5Yisz5imwACmc2LLY7QbEN4nCS4ZwAIGZFds5lUEpEdsF6nKn3PTJnAsiAV0BcBsSM5GamFCDmQXYOOJ8iu2Anzrz9HKU8ABlwDYgTKcnbo0XNaFEzWtQgipqOYVLUAAQYAKPWa4c8cIHnAAAAAElFTkSuQmCC) no-repeat;
|
||||
}
|
||||
.item-disabled .v-right {
|
||||
background: #dfdfdf !important;
|
||||
color: #c0c0c0 !important;
|
||||
cursor: no-drop !important;
|
||||
}
|
||||
.item-disabled {
|
||||
border: 1px solid #dfdfdf !important;
|
||||
}
|
||||
|
|
@ -36,6 +36,7 @@ Page({
|
|||
}
|
||||
},
|
||||
|
||||
// 获取数据
|
||||
get_data_list() {
|
||||
var self = this;
|
||||
wx.showLoading({ title: "加载中..." });
|
||||
|
|
|
|||
Loading…
Reference in New Issue