This commit is contained in:
devil_gong 2018-11-21 17:55:33 +08:00
parent b0d21eedf9
commit 19e2d028c3
27 changed files with 547 additions and 268 deletions

View File

@ -205,14 +205,23 @@ textarea {
width: 100%;
}
.bg-main, .bg-primary, .bg-warning {
color: #fff;
border: 0;
font-size: 34rpx;
}
.bg-main {
background: #d2364c;
color: #fff;
border: 0;
background: #d2364c;
}
.bg-primary {
background: #ed6977;
}
.bg-warning {
background: #F37B1D;
}
.bg-active-main {
background: #d2364c !important;
color: #fff !important;
background: #d2364c !important;
color: #fff !important;
}
.submit-bottom {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@ -1,13 +1,16 @@
/**
* 商品列表
*/
.goods-title {
line-height: 36rpx;
.page {
padding-bottom: 120rpx;
}
.goods-item {
padding: 20rpx 10rpx;
position: relative;
}
.goods-title {
line-height: 36rpx;
}
.goods-item:not(:last-child) {
border-bottom: 1px solid #eee;
}
@ -28,6 +31,12 @@
.buy-number {
margin-left: 20rpx;
}
.goods-item .items {
padding-left: 80rpx;
}
.goods-item .selected {
margin-top: 60rpx;
}
/**
* 数量操作
@ -35,7 +44,7 @@
.number-content {
position: absolute;
right: 20rpx;
top: 120rpx;
top: 100rpx;
}
.number-content button
{
@ -57,4 +66,67 @@
{
border: 1px solid #ddd;
padding: 0;
}
/**
* 空购物车
*/
.no-data-box {
padding: 30% 0 0 0;
}
.no-data-box image {
width: 160rpx;
margin-bottom: 20rpx;
}
.no-data-box .no-data-tips {
font-size: 28rpx;
color: #a6a6a6;
}
.no-data-box button {
margin: 0 auto;
width: 220rpx;
height: 60rpx;
line-height: 60rpx;
font-size: 28rpx;
margin-top: 30rpx;
}
/**
* 操作导航
*/
.buy-nav {
position: fixed;
left: 0;
bottom: 0;
}
.buy-nav, .nav-base, .nav-submit button {
height: 100rpx;
}
.nav-base, .nav-submit button {
line-height: 100rpx;
}
.nav-base {
width: calc(75% - 20rpx);
padding: 0 10rpx;
}
.nav-submit {
width: 25%;
}
.nav-submit button {
border-radius: 0;
}
.page {
padding-bottom: 120rpx;
}
.selected .icon {
width: 50rpx;
height: 50rpx !important;
margin: 0 10rpx;
vertical-align: middle;
}
.buy-nav .price {
width: calc(100% - 140rpx);
}
.buy-nav .sales-price {
max-width: calc(100% - 40px);
}

View File

@ -1,29 +1,72 @@
<view a:for="{{data_list}}" class="goods-item oh bg-white">
<!-- 图片/链接 -->
<navigator url="/pages/goods-detail/goods-detail?goods_id={{item.goods_id}}">
<image class="goods-image fl" src="{{item.images}}" mode="aspectFill" />
</navigator>
<!-- 基础 -->
<view class="goods-base">
<view class="goods-title multi-text">{{item.title}}
</view>
<block a:if="{{item.attribute != null}}">
<view class="goods-attribute cr-888" a:for="{{item.attribute}}" a:for-item="attr"> {{attr.attr_type_name}}:{{attr.attr_name}}
<view class="page">
<view a:for="{{data_list}}" class="goods-item oh bg-white">
<swipe-action index="{{index}}" restore="{{swipe_index === null || swipe_index !== index}}" right="{{item.right}}" onRightItemClick="right_item_event" onSwipeStart="swipe_start_event" extra="{{index}}">
<!-- 选择 -->
<view onTap="selectedt_event" data-type="node" data-index="{{index}}" class="fl selected">
<image a:if="{{(item.selected || false)}}" class="icon" src="/images/default-select-active-icon.png" mode="widthFix" />
<image a:else class="icon" src="/images/default-select-icon.png" mode="widthFix" />
</view>
</block>
</view>
<!-- 数量 -->
<view class="number-content fr tr">
<button type="default" size="mini" catchTap="goods_buy_number_event" data-index="{{index}}" data-type="0" hover-class="none">﹣</button>
<input onBlur="goods_buy_number_blur" class="tc cr-888" type="number" value="{{item.stock}}" data-index="{{index}}" />
<button type="default" size="mini" catchTap="goods_buy_number_event" data-index="{{index}}" data-type="1" hover-class="none"></button>
<view class="bg-white items">
<!-- 图片/链接 -->
<navigator url="/pages/goods-detail/goods-detail?goods_id={{item.goods_id}}">
<image class="goods-image fl" src="{{item.images}}" mode="aspectFill" />
</navigator>
<!-- 基础 -->
<view class="goods-base">
<view class="goods-title multi-text">{{item.title}}
</view>
<block a:if="{{item.attribute != null}}">
<view class="goods-attribute cr-888" a:for="{{item.attribute}}" a:for-item="attr">{{attr.attr_type_name}}:{{attr.attr_name}}</view>
</block>
</view>
<!-- 数量 -->
<view class="number-content fr tr">
<button type="default" size="mini" catchTap="goods_buy_number_event" data-index="{{index}}" data-type="0" hover-class="none">﹣</button>
<input onBlur="goods_buy_number_blur" class="tc cr-888" type="number" value="{{item.stock}}" data-index="{{index}}" />
<button type="default" size="mini" catchTap="goods_buy_number_event" data-index="{{index}}" data-type="1" hover-class="none"></button>
</view>
<!-- 价格 -->
<view class="oh goods-price">
<text class="sales-price">¥{{item.price}}</text>
<text a:if="{{item.original_price > 0}}" class="original-price">¥{{item.original_price}}</text>
<text class="buy-number">x{{item.stock}}</text>
</view>
</view>
</swipe-action>
</view>
<!-- 价格 -->
<view class="oh goods-price">
<text class="sales-price">¥{{item.price}}</text>
<text a:if="{{item.original_price > 0}}" class="original-price">¥{{item.original_price}}</text>
<text class="buy-number">x{{item.stock}}</text>
<!-- 操作导航 -->
<view class="buy-nav oh wh-auto br-t">
<view class="nav-base bg-white fl single-text">
<view onTap="selectedt_event" data-type="all" class="fl selected">
<image a:if="{{is_selected_all}}" class="icon" src="/images/default-select-active-icon.png" mode="widthFix" />
<image a:else class="icon" src="/images/default-select-icon.png" mode="widthFix" />
<text>全选</text>
</view>
<view class="fr price">
<view class="sales-price single-text fr">¥{{total_price}}</view>
<view class="fr">合计:</view>
</view>
</view>
<view class="fr nav-submit">
<button class="bg-main wh-auto" type="default" onTap="buy_submit_event" disabled="{{buy_submit_disabled_status}}" hover-class="none">结算</button>
</view>
</view>
</view>
<!-- 空购物车 -->
<view a:if="{{data_list.length == 0 && data_list_loding_status == 0}}" class="no-data-box tc">
<image src="/images/default-cart-empty.png" mode="widthFix" />
<view class="no-data-tips">购物车空空如也</view>
<button type="default" class="my-btn-default">
<navigator url="/pages/index/index" open-type="switchTab" hover-class="none">去逛逛</navigator>
</button>
</view>
<view a:if="{{data_list.length == 0 && data_list_loding_status != 0}}">
<import src="/pages/common/nodata.axml" />
<template is="nodata" data="{{status: data_list_loding_status}}"></template>
</view>
</view>

View File

@ -5,7 +5,9 @@ Page({
data_list_loding_msg: '',
data_bottom_line_status: false,
data_list: [],
value: 8,
swipe_index: null,
total_price: 0,
is_selected_all: false,
},
onShow() {
@ -13,7 +15,33 @@ Page({
this.init();
},
init() {
init(e) {
var user = app.GetUserInfo(this, "init");
if (user != false) {
// 用户未绑定用户则转到登录页面
if ((user.mobile || null) == null) {
my.confirm({
title: '温馨提示',
content: '绑定手机号码',
confirmButtonText: '确认',
cancelButtonText: '暂不',
success: (result) => {
if (result.confirm) {
my.navigateTo({
url: "/pages/login/login?event_callback=init"
});
}
this.get_data();
},
});
} else {
this.get_data();
}
}
},
// 获取数据
get_data() {
this.setData({
data_list_loding_status: 1
});
@ -25,15 +53,21 @@ Page({
dataType: "json",
success: res => {
my.stopPullDownRefresh();
if (res.data.code == 0) {
if (res.data.code == 0) {
var data = res.data.data;
if (data.length > 0) {
for (var i in data) {
data[i]['right'] = [{ type: 'edit', text: '收藏' }, { type: 'delete', text: '删除' }];
}
}
this.setData({
data_list: res.data.data,
data_list_loding_status: 3,
data_list: data,
data_list_loding_status: data.length == 0 ? 0 : 3,
data_bottom_line_status: true,
data_list_loding_msg: '',
});
} else {
self.setData({
this.setData({
data_list_loding_status: 2,
data_bottom_line_status: false,
data_list_loding_msg: res.data.msg,
@ -46,7 +80,7 @@ Page({
},
fail: () => {
my.stopPullDownRefresh();
self.setData({
this.setData({
data_list_loding_status: 2,
data_bottom_line_status: false,
data_list_loding_msg: '服务器请求出错',
@ -88,10 +122,10 @@ Page({
// 数量处理方法
goods_buy_number_func(index, buy_number) {
var temp_data_list = this.data.data_list;
var buy_min_number = parseInt(temp_data_list['buy_min_number']) || 1;
var buy_max_number = parseInt(temp_data_list['buy_max_number']) || 0;
var inventory = parseInt(temp_data_list['inventory']);
var inventory_unit = temp_data_list['inventory_unit'];
var buy_min_number = parseInt(temp_data_list[index]['buy_min_number']) || 1;
var buy_max_number = parseInt(temp_data_list[index]['buy_max_number']) || 0;
var inventory = parseInt(temp_data_list[index]['inventory']);
var inventory_unit = temp_data_list[index]['inventory_unit'];
if (buy_number < buy_min_number) {
buy_number = buy_min_number;
if (buy_min_number > 1) {
@ -142,4 +176,136 @@ Page({
});
},
// 滑动操作
right_item_event(e) {
var type = e.detail.type;
var index = e.extra;
var id = this.data.data_list[index]['id'];
var goods_id = this.data.data_list[index]['goods_id'];
// 收藏
if (type == 'edit') {
this.goods_favor_event(id, goods_id, type);
} else {
my.confirm({
title: '温馨提示',
content: '删除后不可恢复,确定继续吗?',
confirmButtonText: '确定',
cancelButtonText: '取消',
success: (result) => {
if (result.confirm) {
this.cart_delete(id, type);
} else {
this.setData({ swipe_index: null });
}
}
});
}
},
// 滑动操作
swipe_start_event(e) {
this.setData({ swipe_index: e.index });
},
// 收藏事件
goods_favor_event(id, goods_id, type) {
my.httpRequest({
url: app.get_request_url('Favor', 'Goods'),
method: 'POST',
data: { "id": goods_id, "is_mandatory_favor": 1 },
dataType: 'json',
success: (res) => {
if (res.data.code == 0) {
this.cart_delete(id, type);
} else {
my.showToast({
type: 'fail',
content: res.data.msg
});
}
},
fail: () => {
my.showToast({
type: 'fail',
content: '服务器请求出错'
});
}
});
},
// 购物车删除
cart_delete(id, type) {
my.httpRequest({
url: app.get_request_url('Delete', 'Cart'),
method: 'POST',
data: { "id": id },
dataType: 'json',
success: (res) => {
if (res.data.code == 0) {
var temp_data_list = this.data.data_list;
temp_data_list.splice(this.data.swipe_index, 1);
this.setData({
data_list: temp_data_list,
swipe_index: null,
data_list_loding_status: temp_data_list.length == 0 ? 0 : this.data.data_list_loding_status,
});
my.showToast({
type: 'success',
content: (type == 'delete') ? '删除成功' : '收藏成功'
});
} else {
my.showToast({
type: 'fail',
content: (type == 'delete') ? '删除失败' : '收藏失败'
});
}
},
fail: () => {
my.showToast({
type: 'fail',
content: '服务器请求出错'
});
}
});
},
// 选中处理
selectedt_event(e) {
var type = e.currentTarget.dataset.type || null;
if (type != null)
{
var temp_data_list = this.data.data_list;
var temp_is_selected_all = this.data.is_selected_all;
var total_price = 0;
switch(type) {
case 'all' :
temp_is_selected_all = (temp_is_selected_all == true) ? false : true;
for (var i in temp_data_list) {
temp_data_list[i]['selected'] = temp_is_selected_all;
}
break;
case 'node' :
var index = e.currentTarget.dataset.index || 0;
temp_data_list[index]['selected'] = (temp_data_list[index]['selected'] == true) ? false : true;
break;
}
for (var i in temp_data_list) {
if ((temp_data_list[i]['selected'] || false) == true) {
total_price += temp_data_list[i]['stock'] * temp_data_list[i]['price'];
}
}
this.setData({
data_list: temp_data_list,
is_selected_all: temp_is_selected_all,
total_price: total_price.toFixed(2),
})
}
}
});

View File

@ -1,3 +1,7 @@
{
"pullRefresh": true
"pullRefresh": true,
"usingComponents": {
"list-item": "mini-antui/es/list/list-item/index",
"swipe-action": "mini-antui/es/swipe-action/index"
}
}

View File

@ -11,7 +11,7 @@
</view>
<view class="nav-back tc wh-auto">
<navigator open-type="navigateBack" hover-class="none">
<navigator url="/pages/goods-detail/goods-detail" open-type="navigateBack" hover-class="none">
<button type="default" size="mini" class="cr-888" hover-class="none">返回</button>
</navigator>
</view>

View File

@ -10,7 +10,7 @@
<vtab-content anchor="{{item.anchor}}">
<view class="content">
<block a:if="{{item.items.length > 0}}">
<view a:for="{{item.items}}" a:for-item="v" class="content-items" data-value="{{vs.id}}" onTap="category_event">
<view a:for="{{item.items}}" a:for-item="v" class="content-items" data-value="{{v.id}}" onTap="category_event">
<image a:if="{{v.icon != null}}" src="{{v.icon}}" mode="aspectFit" class="icon" />
<view class="text single-text">{{v.name}}</view>
</view>

View File

@ -7,16 +7,11 @@ Page({
data_list_loding_status: 1,
data_bottom_line_status: false,
data_list: [],
params: null,
},
onLoad(params) {
this.setData({params: params});
this.init();
},
onShow() {
my.setNavigationBar({title: app.data.common_pages_title.goods_category});
this.init();
},
// 获取数据
@ -30,7 +25,7 @@ Page({
my.httpRequest({
url: app.get_request_url("GoodsCategory", "Resources"),
method: "POST",
data: this.data.params,
data: {},
dataType: "json",
success: res => {
my.stopPullDownRefresh();

View File

@ -109,15 +109,15 @@
height: 100rpx;
}
.goods-buy-nav .fl {
width: calc(25% - 1rpx);
width: calc(20% - 1rpx);
}
.goods-buy-nav .fr {
width: 50%;
width: 60%;
}
.goods-buy-nav .fr button {
border: 0;
border-radius: 0;
line-height: 100rpx;
width: 50%;
}
.goods-buy-nav .fr button,
.goods-buy-nav .fl

View File

@ -71,7 +71,8 @@
<text class="dis-block cr-888">{{goods_favor_text}}</text>
</view>
<view class="fr">
<button class="bg-main" type="default" onTap="buy_submit_event" hover-class="none">立即预约</button>
<button class="bg-warning fl" type="default" onTap="cart_submit_event" hover-class="none">加入购物车</button>
<button class="bg-main fl" type="default" onTap="buy_submit_event" hover-class="none">立即购买</button>
</view>
</view>

View File

@ -22,10 +22,11 @@ Page({
goods_favor_icon: '/images/goods-detail-favor-icon-0.png',
temp_attribute_active: {},
temp_buy_number: 1,
buy_event_type: 'buy',
},
onLoad(params) {
//params['goods_id']=1;
//params['goods_id']=16;
this.setData({params: params});
this.init();
},
@ -70,16 +71,16 @@ Page({
if (res.data.code == 0) {
var data = res.data.data;
self.setData({
goods: data.goods,
goods: data,
indicator_dots: (data.photo.length > 1),
autoplay: (data.photo.length > 1),
goods_photo: data.photo,
goods_attribute_show: data.attribute.show || [],
goods_attribute_choose: data.attribute.choose || [],
goods_content_app: data.content_app,
temp_buy_number: (data.goods.buy_min_number) || 1,
goods_favor_text: (data.goods.is_favor == 1) ? '已收藏' : '收藏',
goods_favor_icon: '/images/goods-detail-favor-icon-'+data.goods.is_favor+'.png',
temp_buy_number: (data.buy_min_number) || 1,
goods_favor_text: (data.is_favor == 1) ? '已收藏' : '收藏',
goods_favor_icon: '/images/goods-detail-favor-icon-'+data.is_favor+'.png',
data_bottom_line_status: true,
data_list_loding_status: 3,
});
@ -134,9 +135,14 @@ Page({
});
},
// 加入购物车
cart_submit_event(e) {
this.setData({ popup_status: '', buy_event_type: 'cart' });
},
// 立即购买
buy_submit_event(e) {
this.setData({popup_status: ''});
this.setData({ popup_status: '', buy_event_type: 'buy'});
},
// 收藏事件
@ -151,19 +157,18 @@ Page({
});
return false;
} else {
var self = this;
my.showLoading({content: '处理中...'});
my.httpRequest({
url: app.get_request_url('Favor', 'Goods'),
method: 'POST',
data: {goods_id: self.data.goods.id},
data: {"id": this.data.goods.id},
dataType: 'json',
success: (res) => {
my.hideLoading();
if(res.data.code == 0)
{
var status = (self.data.goods.is_favor == 1) ? 0 : 1;
var status = (this.data.goods.is_favor == 1) ? 0 : 1;
this.setData({
'goods.is_favor': status,
goods_favor_text: (status == 1) ? '已收藏' : '收藏',
@ -193,6 +198,61 @@ Page({
}
},
// 加入购物车事件
goods_cart_event(e) {
var user = app.GetUserInfo(this, 'goods_cart_event');
if (user != false) {
// 用户未绑定用户则转到登录页面
if ((user.mobile || null) == null) {
my.navigateTo({
url: "/pages/login/login?event_callback=init"
});
return false;
} else {
var attribute_all_cart = {};
var temp_attribute_active = this.data.temp_attribute_active;
if (app.get_length(temp_attribute_active) > 0)
{
var goods_attribute_choose = this.data.goods_attribute_choose;
for (var i in temp_attribute_active) {
attribute_all_cart[goods_attribute_choose[i]['id']] = goods_attribute_choose[i]['find'][temp_attribute_active[i]]['id'];
}
}
my.showLoading({ content: '处理中...' });
my.httpRequest({
url: app.get_request_url('Save', 'Cart'),
method: 'POST',
data: { "goods_id": this.data.goods.id, "stock": this.data.temp_buy_number, "attr": JSON.stringify(attribute_all_cart) },
dataType: 'json',
success: (res) => {
my.hideLoading();
if (res.data.code == 0) {
this.popup_close_event();
my.showToast({
type: 'success',
content: res.data.msg
});
} else {
my.showToast({
type: 'fail',
content: res.data.msg
});
}
},
fail: () => {
my.hideLoading();
my.showToast({
type: 'fail',
content: '服务器请求出错'
});
}
});
}
}
},
// 属性事件
goods_attribute_event(e) {
var key = e.currentTarget.dataset.key || 0;
@ -256,7 +316,7 @@ Page({
this.setData({temp_buy_number: buy_number});
},
// 购买确认
// 确认
goods_buy_confirm_event(e) {
var user = app.GetUserInfo(this, 'goods_buy_confirm_event');
if (user != false) {
@ -289,20 +349,37 @@ Page({
}
}
}
// 操作类型
switch (this.data.buy_event_type) {
case 'buy' :
// 进入订单确认页面
var data = [{
"goods_id": this.data.goods.id,
"buy_number": this.data.temp_buy_number,
"attribute": attribute_all.join(',')
}]
my.navigateTo({
url: '/pages/buy/buy?data=' + JSON.stringify(data)
});
break;
// 进入订单确认页面
var data = [{
"goods_id": this.data.goods.id,
"buy_number": this.data.temp_buy_number,
"attribute": attribute_all.join(',')
}]
my.navigateTo({
url: '/pages/buy/buy?data='+JSON.stringify(data)
});
case 'cart' :
this.goods_cart_event();
break;
default :
my.showToast({
type: "fail",
content: "操作事件类型有误"
});
}
}
}
},
// 详情图片查看
goods_detail_images_view_event(e) {
var value = e.currentTarget.dataset.value || null;

View File

@ -16,9 +16,9 @@
</view>
<view a:if="{{data_list.length == 0}}">
<import src="/pages/common/nodata.axml" />
<template is="nodata" data="{{status: data_list_loding_status}}"></template>
</view>
<import src="/pages/common/nodata.axml" />
<template is="nodata" data="{{status: data_list_loding_status}}"></template>
</view>
<import src="/pages/common/bottom_line.axml" />
<template is="bottom_line" data="{{status: data_bottom_line_status}}"></template>

View File

@ -13,8 +13,8 @@
</view>
<view class="operation br-t oh">
<view class="default fl" onTap="address_default_event" data-value="{{item.id}}">
<image a:if="{{is_default == item.id}}" class="item-icon" src="/images/address-select-active-icon.png" mode="widthFix" />
<image a:else class="item-icon" src="/images/address-select-icon.png" mode="widthFix" />
<image a:if="{{is_default == item.id}}" class="item-icon" src="/images/default-select-active-icon.png" mode="widthFix" />
<image a:else class="item-icon" src="/images/default-select-icon.png" mode="widthFix" />
<text>设为默认地址</text>
</view>
<button class="fr cr-666 delete-submit" type="default" size="mini" onTap="address_delete_event" data-index="{{index}}" data-value="{{item.id}}" hover-class="none">删除</button>

View File

@ -102,7 +102,7 @@ class GoodsController extends CommonController
$v['category_text'] = implode('', $category_name);
// 产地
$v['place_origin_text'] = M('Region')->where(['id'=>$v['place_origin']])->getField('name');
$v['place_origin_name'] = ResourcesService::RegionName($v['place_origin']);
// 品牌
$v['brand_name'] = empty($v['brand_id']) ? null : M('Brand')->where(['id'=>$v['brand_id']])->getField('name');

View File

@ -21,7 +21,7 @@ return array(
'goods_category_id_text' => '商品分类',
'goods_category_id_format' => '请至少选择一个商品分类',
'goods_place_origin_text' => '生产地',
'goods_place_origin_name' => '生产地',
'goods_place_origin_format' => '请选择生产地',
'goods_inventory_text' => '库存数量',

View File

@ -123,8 +123,8 @@
<dt>{{:L('goods_brand_id_text')}}</dt>
<dd>{{$v.brand_name}}</dd>
<dt>{{:L('goods_place_origin_text')}}</dt>
<dd>{{$v.place_origin_text}}</dd>
<dt>{{:L('goods_place_origin_name')}}</dt>
<dd>{{$v.place_origin_name}}</dd>
<dt>{{:L('goods_category_id_text')}}</dt>
<dd>{{$v.category_text}}</dd>

View File

@ -98,7 +98,7 @@
</select>
</div>
<div class="am-form-group">
<label>{{:L('goods_place_origin_text')}}</label>
<label>{{:L('goods_place_origin_name')}}</label>
<br />
<select name="place_origin" class="am-radius chosen-select c-p" data-placeholder="{{:L('common_please_select_choose')}}" data-validation-message="{{:L('goods_place_origin_format')}}">
<option value="0">{{:L('common_please_select_choose')}}</option>

View File

@ -58,7 +58,7 @@ class CartController extends CommonController
*/
public function Save()
{
$params = $this->data_post;
$params = $_POST;
$params['user'] = $this->user;
$ret = BuyService::CartAdd($params);
$this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
@ -74,7 +74,6 @@ class CartController extends CommonController
*/
public function Delete()
{
$params = $this->data_post;
$params['user'] = $this->user;
$ret = BuyService::CartDelete($params);

View File

@ -2,7 +2,7 @@
namespace Api\Controller;
use Service\ResourcesService;
use Service\GoodsService;
/**
* 商品
@ -43,143 +43,35 @@ class GoodsController extends CommonController
public function Detail()
{
$goods_id = I('goods_id');
$goods = M('Goods')->where(['id'=>$goods_id, 'is_shelves'=>1, 'is_delete_time'=>0])->find();
if(empty($goods))
$params = [
'where' => [
'g.id' => $goods_id,
'g.is_delete_time' => 0,
],
'is_photo' => true,
'is_attribute' => true,
'is_content_app' => true,
];
$goods = GoodsService::GoodsList($params);
if(empty($goods[0]) || $goods[0]['is_delete_time'] != 0)
{
$this->ajaxReturn(L('common_data_no_exist_error'), -1);
}
$goods['images'] = empty($goods['images']) ? null : C('IMAGE_HOST').$goods['images'];
unset($goods['content_web']);
unset($goods[0]['content_web']);
// 产地
$goods['place_origin_name'] = ResourcesService::RegionName($goods['place_origin']);
// 当前登录用户是否已收藏
$ret_favor = GoodsService::IsUserGoodsFavor(['goods_id'=>$goods_id, 'user'=>$this->user]);
$goods[0]['is_favor'] = ($ret_favor['code'] == 0) ? $ret_favor['data'] : 0;
// 是否已收藏
$goods['is_favor'] = $this->IsGoodsUserFavor($goods_id);
// 商品访问统计
GoodsService::GoodsAccessCountInc(['goods_id'=>$goods_id]);
// 视频
$goods['video'] = empty($goods['video']) ? null : C('IMAGE_HOST').$goods['video'];
// 用户商品浏览
GoodsService::GoodsBrowseSave(['goods_id'=>$goods_id, 'user'=>$this->user]);
$result = [
// 商品基础数据
'goods' => $goods,
// 相册
'photo' => $this->GetGoodsPhoto($goods_id),
// 手机详情
'content_app' => $this->GetGoodsContentApp($goods_id),
// 属性
'attribute' => $this->GetGoodsAttribute($goods_id),
// 客服电话
'customer_service_tel' => MyC('common_customer_service_tel'),
];
$this->ajaxReturn(L('common_operation_success'), 0, $result);
$this->ajaxReturn(L('common_operation_success'), 0, $goods[0]);
}
/**
* 用户是否收藏商品
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-07-17
* @desc description
* @param [int] $goods_id [商品id]
* @return [int] [0,1]
*/
private function IsGoodsUserFavor($goods_id)
{
if(empty($this->user['id']))
{
return 0;
}
$data = M('GoodsFavor')->where(['goods_id'=>$goods_id, 'user_id'=>$this->user['id']])->find();
return empty($data) ? 0 : 1;
}
/**
* 获取商品手机详情
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-07-10
* @desc description
* @param [int] $goods_id [商品id]
* @return [array] [属性]
*/
private function GetGoodsContentApp($goods_id)
{
$data = M('GoodsContentApp')->where(['goods_id'=>$goods_id])->field('id,images,content')->order('sort asc')->select();
if(!empty($data))
{
$images_host = C('IMAGE_HOST');
foreach($data as &$v)
{
$v['images'] = empty($v['images']) ? null : $images_host.$v['images'];
$v['content'] = empty($v['content']) ? null : explode("\n", $v['content']);
}
} else {
$data = [];
}
return $data;
}
/**
* 获取商品相册
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-07-10
* @desc description
* @param [int] $goods_id [商品id]
* @return [array] [属性]
*/
private function GetGoodsPhoto($goods_id)
{
$data = M('GoodsPhoto')->where(['goods_id'=>$goods_id, 'is_show'=>1])->order('sort asc')->getField('images', true);
if(!empty($data))
{
$images_host = C('IMAGE_HOST');
foreach($data as &$v)
{
$v = $images_host.$v;
}
} else {
$data = [];
}
return $data;
}
/**
* 获取商品属性
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-07-10
* @desc description
* @param [int] $goods_id [商品id]
* @return [array] [属性]
*/
private function GetGoodsAttribute($goods_id)
{
$result = [];
$data = M('GoodsAttributeType')->where(['goods_id'=>$goods_id])->field('id,type,name')->order('sort asc')->select();
if(!empty($data))
{
foreach($data as $v)
{
$v['find'] = M('GoodsAttribute')->field('id,name')->where(['goods_id'=>$goods_id, 'attribute_type_id'=>$v['id']])->order('sort asc')->select();
$result[$v['type']][] = $v;
}
} else {
$data = [];
}
return $result;
}
/**
* 用户商品收藏
@ -194,41 +86,11 @@ class GoodsController extends CommonController
// 登录校验
$this->Is_Login();
// 参数校验
$params = [
[
'checked_type' => 'empty',
'key_name' => 'goods_id',
'error_msg' => '商品ID有误',
]
];
$ret = params_checked($this->data_post, $params);
if($ret !== true)
{
$this->ajaxReturn($ret);
}
// 开始操作
$m = M('GoodsFavor');
$data = ['goods_id'=>intval($this->data_post['goods_id']), 'user_id'=>$this->user['id']];
$temp = $m->where($data)->find();
if(empty($temp))
{
$data['add_time'] = time();
if($m->add($data) > 0)
{
$this->ajaxReturn(L('common_favor_success'), 0);
} else {
$this->ajaxReturn(L('common_favor_error'));
}
} else {
if($m->where($data)->delete() > 0)
{
$this->ajaxReturn(L('common_cancel_success'), 0);
} else {
$this->ajaxReturn(L('common_cancel_error'));
}
}
$params = $this->data_post;
$params['user'] = $this->user;
$ret = GoodsService::GoodsFavor($params);
$this->ajaxReturn($ret['msg'], $ret['code'], $ret['data']);
}
}

View File

@ -108,7 +108,8 @@
</form>
</div>
</div>
<else />
</notempty>
<empty name="cart_list">
<div class="mixed-tips">
<i class="am-icon-cart-plus am-fl icon"></i>
<div class="mixed-tips-content am-fl">
@ -125,7 +126,7 @@
</ul>
</div>
</div>
</notempty>
</empty>
</div>
<!-- footer start -->

View File

@ -111,8 +111,12 @@ class BuyService
private static function GoodsAttrParsing($params = [])
{
$data = [];
if(!empty($params['attr']) && is_array($params['attr']) && !empty($params['goods_id']))
if(!empty($params['attr']) && !empty($params['goods_id']))
{
if(!is_array($params['attr']))
{
$params['attr'] = json_decode($params['attr'], true);
}
foreach($params['attr'] as $k=>$v)
{
$attr_type_name = M('GoodsAttributeType')->where(['goods_id'=>$params['goods_id'], 'id'=>$k])->getField('name');
@ -161,21 +165,21 @@ class BuyService
$field = 'c.*, g.title, g.images, g.original_price, g.price, g.inventory, g.inventory_unit, g.is_shelves, g.is_delete_time, g.buy_min_number, g.buy_max_number';
$data = M('Cart')->alias('c')->join(' __GOODS__ AS g ON g.id=c.goods_id')->where($where)->field($field)->select();
if(empty($data) || !is_array($data))
{
return DataReturn(L('common_not_data_tips'), -100);
}
// 数据处理
$images_host = C('IMAGE_HOST');
foreach($data as &$v)
if(!empty($data))
{
$v['goods_url'] = HomeUrl('Goods', 'Index', ['id'=>$v['goods_id']]);
$v['images_old'] = $v['images'];
$v['images'] = empty($v['images']) ? null : $images_host.$v['images'];
$v['attribute'] = empty($v['attribute']) ? null : json_decode($v['attribute'], true);
$v['total_price'] = $v['stock']*$v['price'];
$v['buy_max_number'] = ($v['buy_max_number'] <= 0) ? $v['inventory']: $v['buy_max_number'];
$images_host = C('IMAGE_HOST');
foreach($data as &$v)
{
$v['goods_url'] = HomeUrl('Goods', 'Index', ['id'=>$v['goods_id']]);
$v['images_old'] = $v['images'];
$v['images'] = empty($v['images']) ? null : $images_host.$v['images'];
$v['attribute'] = empty($v['attribute']) ? null : json_decode($v['attribute'], true);
$v['total_price'] = $v['stock']*$v['price'];
$v['buy_max_number'] = ($v['buy_max_number'] <= 0) ? $v['inventory']: $v['buy_max_number'];
}
}
return DataReturn(L('common_operation_success'), 0, $data);

View File

@ -196,6 +196,7 @@ class GoodsService
$is_photo = (isset($params['is_photo']) && $params['is_photo'] == true) ? true : false;
$is_attribute = (isset($params['is_attribute']) && $params['is_attribute'] == true) ? true : false;
$is_content_app = (isset($params['is_content_app']) && $params['is_content_app'] == true) ? true : false;
$is_category = (isset($params['is_category']) && $params['is_category'] == true) ? true : false;
$m = isset($params['m']) ? intval($params['m']) : 0;
@ -242,7 +243,7 @@ class GoodsService
// 产地
if(!empty($v['place_origin']))
{
$v['place_origin_text'] = M('Region')->where(['id'=>$v['place_origin']])->getField('name');
$v['place_origin_name'] = ResourcesService::RegionName($goods['place_origin']);
}
// 时间
@ -281,11 +282,44 @@ class GoodsService
{
$v['attribute'] = self::GoodsAttribute(['goods_id'=>$v['id']]);
}
// 获取app内容
if($is_content_app && !empty($v['id']))
{
$v['content_app'] = self::GoodsContentApp(['goods_id'=>$v['id']]);
}
}
}
return $data;
}
/**
* 获取商品手机详情
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-07-10
* @desc description
* @param [array] $params [输入参数]
* @return [array] [app内容]
*/
public static function GoodsContentApp($params = [])
{
$data = M('GoodsContentApp')->where(['goods_id'=>$params['goods_id']])->field('id,images,content')->order('sort asc')->select();
if(!empty($data))
{
$images_host = C('IMAGE_HOST');
foreach($data as &$v)
{
$v['images'] = empty($v['images']) ? null : $images_host.$v['images'];
$v['content'] = empty($v['content']) ? null : explode("\n", $v['content']);
}
} else {
$data = [];
}
return $data;
}
/**
* 获取商品属性
* @author Devil
@ -348,6 +382,7 @@ class GoodsService
$temp = $m->where($data)->find();
if(empty($temp))
{
// 添加收藏
$data['add_time'] = time();
if($m->add($data) > 0)
{
@ -360,6 +395,17 @@ class GoodsService
return DataReturn(L('common_favor_error'));
}
} else {
// 是否强制收藏
if(isset($params['is_mandatory_favor']) && $params['is_mandatory_favor'] == 1)
{
return DataReturn(L('common_favor_success'), 0, [
'text' => L('common_favor_ok_text'),
'status' => 1,
'count' => self::GoodsFavorTotal(['goods_id'=>$data['goods_id']]),
]);
}
// 删除收藏
if($m->where($data)->delete() > 0)
{
return DataReturn(L('common_cancel_success'), 0, [