提交 fec3daea 编写于 作者: D devil_gong

微信小程序优惠劵

上级 b416af4c
......@@ -169,7 +169,10 @@ class Goods extends Common
$ret = CallPluginsServiceMethod('coupon', 'CouponService', 'CouponList', $coupon_params);
// 排除商品不支持的活动
$ret['data'] = CallPluginsServiceMethod('coupon', 'BaseService', 'CouponListGoodsExclude', ['data'=>$ret['data'], 'goods_id'=>$goods_id]);
if(!empty($ret['data']))
{
$ret['data'] = CallPluginsServiceMethod('coupon', 'BaseService', 'CouponListGoodsExclude', ['data'=>$ret['data'], 'goods_id'=>$goods_id]);
}
// 返回数据
return [
......
......@@ -88,6 +88,12 @@ function PathToParams($key = null, $default = null, $path = '')
*/
function CallPluginsData($plugins, $attachment_field = [], $service_name = '', $attachment_property = 'base_config_attachment_field')
{
// 插件是否启用
if(app\service\PluginsService::PluginsStatus($plugins) != 1)
{
return DataReturn('插件状态异常['.$plugins.']', -1);
}
// 未指定附件字段则自动去获取
$attachment = [];
if(empty($attachment_field) && !empty($attachment_property))
......@@ -128,6 +134,13 @@ function CallPluginsServiceMethod($plugins, $service, $method, $params = null)
{
if(method_exists($plugins_class, $method))
{
// 插件是否启用
if(app\service\PluginsService::PluginsStatus($plugins) != 1)
{
return DataReturn('插件状态异常['.$plugins.']', -1);
}
// 调用方法返回数据
return $plugins_class::$method($params);
} else {
return DataReturn('类方法未定义['.$plugins.'-'.$service.'-'.$method.']', -1);
......
......@@ -46,10 +46,10 @@ class PluginsService
if(empty($data))
{
// 获取数据
$data = Db::name('Plugins')->where(['plugins'=>$plugins])->value('data');
if(!empty($data))
$ret = self::PluginsField($plugins, 'data');
if(!empty($ret['data']))
{
$data = json_decode($data, true);
$data = json_decode($ret['data'], true);
// 是否有自定义附件需要处理
if(!empty($attachment_field) && is_array($attachment_field))
......@@ -166,5 +166,20 @@ class PluginsService
$data = Db::name('Plugins')->where(['plugins'=>$plugins])->value($field);
return DataReturn('操作成功', 0, $data);
}
/**
* 应用状态
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-10-17
* @desc description
* @param [string] $plugins [应用标记]
*/
public static function PluginsStatus($plugins)
{
$ret = self::PluginsField($plugins, 'is_enable');
return $ret['data'];
}
}
?>
\ No newline at end of file
......@@ -75,7 +75,7 @@ Page({
});
},
// 领取事件
// 优惠劵领取事件
receive_event(e) {
var user = app.get_user_cache_info(this, "receive_event");
// 用户未绑定用户则转到登录页面
......
......@@ -8,12 +8,12 @@
<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 class="unit">{{item.type_unit}}</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}};">
<view class="v-right fr" bindtap="coupon_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>
......
......@@ -787,6 +787,50 @@ Page({
}
},
// 优惠劵领取事件
coupon_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.plugins_coupon_data.data;
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.plugins_coupon_data.base != null && self.data.plugins_coupon_data.base.is_repeat_receive != 1) {
temp_list[index]['is_operable'] = 0;
temp_list[index]['is_operable_name'] = '已领取';
self.setData({ 'plugins_coupon_data.data': temp_list });
}
} else {
app.showToast(res.data.msg);
}
},
fail: () => {
wx.hideLoading();
app.showToast("服务器请求出错");
}
});
}
}
},
// 自定义分享
onShareAppMessage() {
var user = app.get_user_cache_info(this, 'goods_favor_event') || null;
......
......@@ -73,12 +73,12 @@
<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>
<text class="unit">{{item.type_unit}}</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 wx:if="{{(item.desc || null) != null}}" class="desc cr-888 single-text">{{item.desc}}</view>
</view>
<view class="v-right fr" bindtap="receive_event" data-index="{{index}}" data-value="{{item.id}}" style="background:{{item.bg_color_value}};">
<view class="v-right fr" bindtap="coupon_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>
......
......@@ -293,15 +293,33 @@
}
/*
* 优惠劵 - 插件
*/
.coupon-container {
white-space: nowrap;
box-sizing: border-box;
padding: 20rpx 10rpx;
}
.coupon-container scroll-view {
height: 174rpx;
}
.coupon-container .item {
display: inline-block;
width: 60vw;
}
.coupon-container .v-left {
padding: 20rpx 0 20rpx 20rpx;
}
.coupon-container .item:not(:last-child) {
margin-right: 20rpx;
}
.coupon-container .item,
.coupon-container .v-right,
.coupon-container .v-right .circle {
height: 170rpx;
}
.coupon-container .v-left .base .price {
font-size: 46rpx;
}
\ No newline at end of file
......@@ -16,7 +16,7 @@
<view class="base single-text" style="color:{{item.coupon.bg_color_value}};">
<text class="symbol">¥</text>
<text class="price">{{item.coupon.discount_value}}</text>
<text class="unit">{{item.coupon.type == 0 ? '元' : '折'}}</text>
<text class="unit">{{item.coupon.type_unit}}</text>
<text wx:if="{{(item.coupon.desc || null) != null}}" class="desc cr-888">{{item.coupon.desc}}</text>
</view>
<view wx:if="{{(item.coupon.use_limit_type_name || null) != null}}" class="base-tips cr-666 single-text">{{item.coupon.use_limit_type_name}}</view>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册