提交 1947136d 编写于 作者: G gongfuxiang

goods

上级 ed4c41e1
......@@ -13,7 +13,7 @@ use app\service\BannerService;
class Banner extends Common
{
/**
* [_initialize 前置操作-继承公共前置方法]
* [__construct 构造方法]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
......
<?php
namespace app\api\controller;
use app\service\GoodsService;
/**
* 商品
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class Goods extends Common
{
/**
* [__construct 构造方法]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-03T12:39:08+0800
*/
public function __construct()
{
// 调用父类前置方法
parent::__construct();
}
/**
* 获取商品详情
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-07-12
* @desc description
*/
public function Detail()
{
// 参数
if(empty($this->data_post['goods_id']))
{
return json(DataReturn('参数有误', -1));
}
// 获取商品
$goods_id = intval($this->data_post['goods_id']);
$params = [
'where' => [
'id' => $goods_id,
'is_delete_time' => 0,
],
'is_photo' => true,
'is_spec' => true,
'is_content_app' => true,
];
$goods = GoodsService::GoodsList($params);
if(empty($goods[0]) || $goods[0]['is_delete_time'] != 0)
{
return json(DataReturn('商品不存在或已删除', -1));
}
unset($goods[0]['content_web']);
// 当前登录用户是否已收藏
$ret_favor = GoodsService::IsUserGoodsFavor(['goods_id'=>$goods_id, 'user'=>$this->user]);
$goods[0]['is_favor'] = ($ret_favor['code'] == 0) ? $ret_favor['data'] : 0;
// 商品访问统计
GoodsService::GoodsAccessCountInc(['goods_id'=>$goods_id]);
// 用户商品浏览
GoodsService::GoodsBrowseSave(['goods_id'=>$goods_id, 'user'=>$this->user]);
// 数据返回
$result = [
'goods' => $goods[0],
'common_order_is_booking' => (int) MyC('common_order_is_booking', 0),
];
return json(DataReturn('success', 0, $result));
}
/**
* 用户商品收藏
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-07-17
* @desc description
*/
public function Favor()
{
// 登录校验
$this->Is_Login();
// 开始操作
$params = $this->data_post;
$params['user'] = $this->user;
$ret = GoodsService::GoodsFavor($params);
return json($ret);
}
}
?>
\ No newline at end of file
......@@ -13,7 +13,7 @@ use app\service\GoodsService;
class Index extends Common
{
/**
* [_initialize 前置操作-继承公共前置方法]
* [__construct 构造方法]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
......
......@@ -13,7 +13,7 @@ use app\service\AppNavService;
class Navigation extends Common
{
/**
* [_initialize 前置操作-继承公共前置方法]
* [__construct 构造方法]
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
......
......@@ -137,8 +137,8 @@
<div class="theme-popbod dform">
<form class="theme-signin" name="loginform" action="javascript:;">
<div class="theme-signin-left">
{{if !empty($goods['specifications']['type'])}}
{{foreach $goods.specifications.type as $key=>$spec}}
{{if !empty($goods['specifications']['choose'])}}
{{foreach $goods.specifications.choose as $key=>$spec}}
{{if !empty($spec['value'])}}
<div class="theme-options sku-items">
<div class="cart-title">{{$spec.name}}</div>
......
......@@ -368,12 +368,12 @@ class GoodsService
$where = ['goods_id'=>$params['goods_id']];
// 规格类型
$type = Db::name('GoodsSpecType')->where($where)->order('id asc')->select();
if(!empty($type))
$choose = Db::name('GoodsSpecType')->where($where)->order('id asc')->select();
if(!empty($choose))
{
// 数据处理
$images_host = config('images_host');
foreach($type as &$temp_type)
foreach($choose as &$temp_type)
{
$temp_type_value = json_decode($temp_type['value'], true);
foreach($temp_type_value as &$vs)
......@@ -384,7 +384,7 @@ class GoodsService
$temp_type['add_time'] = date('Y-m-d H:i:s');
}
}
return ['type'=>$type];
return ['choose'=>$choose];
}
/**
......
......@@ -30,14 +30,18 @@
.goods-attr-choose .item .attribute button {
margin-top: 20rpx;
margin-right: 25rpx;
}
.goods-attr-choose .item .attribute button {
padding: 0 30rpx;
background: #eee;
color: #666;
line-height: 28px;
line-height: 27px;
height: 27px;
}
.goods-attr-choose .item .attribute button image {
width: 20px;
height: 20px;
vertical-align: middle;
margin-right: 10rpx;
}
.goods-attr-choose .item .attribute button,
.goods-popup-submit
{
......
......@@ -10,7 +10,7 @@
a:if="{{goods_photo.length > 0}}">
<block a:for="{{goods_photo}}">
<swiper-item>
<image class="swiper-item wh-auto" onTap="goods_photo_view_event" data-index="{{index}}" src="{{item}}" mode="aspectFit" onTap="banner_event" />
<image class="swiper-item wh-auto" onTap="goods_photo_view_event" data-index="{{index}}" src="{{item.images}}" mode="aspectFit" onTap="banner_event" />
</swiper-item>
</block>
</swiper>
......@@ -36,11 +36,11 @@
</view>
<!-- 属性导航 -->
<view a:if="{{goods_attribute_show.length > 0}}" class="spacing">
<!-- <view a:if="{{false}}" class="spacing">
<view class="goods-attr-show-title bg-white arrow-right cr-666" onTap="good_attribute_nav_event">
属性
</view>
</view>
</view> -->
<!-- 商品详情 -->
<view a:if="{{goods_content_app.length > 0}}" class="goods-detail spacing">
......@@ -86,13 +86,19 @@
</view>
<view class="goods-popup-content">
<!-- 商品属性 -->
<view a:if="{{goods_attribute_choose.length > 0}}" class="goods-attr-choose">
<view a:for="{{goods_attribute_choose}}" a:for-index="key" a:if="{{item.type == 'choose'}}" class="item br-b">
<view a:if="{{goods_specifications_choose.length > 0}}" class="goods-attr-choose">
<view a:for="{{goods_specifications_choose}}" a:for-index="key" class="item br-b">
<view class="title">{{item.name}}</view>
<view a:if="{{item.find.length > 0}}" class="attribute">
<block a:for="{{item.find}}" a:for-index="keys" a:for-item="items">
<button a:if="{{temp_attribute_active[key] == keys}}" catchTap="goods_attribute_event" data-key="{{key}}" data-keys="{{keys}}" class="bg-active-main" type="default" size="mini" hover-class="none">{{items.name}}</button>
<button a:else catchTap="goods_attribute_event" data-key="{{key}}" data-keys="{{keys}}" type="default" size="mini" hover-class="none">{{items.name}}</button>
<view a:if="{{item.value.length > 0}}" class="attribute">
<block a:for="{{item.value}}" a:for-index="keys" a:for-item="items">
<button a:if="{{temp_attribute_active[key] == keys}}" catchTap="goods_attribute_event" data-key="{{key}}" data-keys="{{keys}}" class="bg-active-main" type="default" size="mini" hover-class="none">
<image a:if="{{(items.images || null) != null}}" src="{{items.images}}" mode="scaleToFill" />
{{items.name}}
</button>
<button a:else catchTap="goods_attribute_event" data-key="{{key}}" data-keys="{{keys}}" type="default" size="mini" hover-class="none">
<image a:if="{{(items.images || null) != null}}" src="{{items.images}}" mode="scaleToFill" />
{{items.name}}
</button>
</block>
</view>
</view>
......
......@@ -13,8 +13,7 @@ Page({
goods: null,
goods_photo: [],
goods_attribute_show: [],
goods_attribute_choose: [],
goods_specifications_choose: [],
goods_content_app: [],
popup_status: false,
......@@ -63,7 +62,7 @@ Page({
});
my.httpRequest({
url: app.get_request_url("Detail", "Goods"),
url: app.get_request_url("detail", "goods"),
method: "POST",
data: {goods_id: this.data.params.goods_id},
dataType: "json",
......@@ -77,8 +76,6 @@ Page({
indicator_dots: (data.goods.photo.length > 1),
autoplay: (data.goods.photo.length > 1),
goods_photo: data.goods.photo,
goods_attribute_show: data.goods.attribute.show || [],
goods_attribute_choose: data.goods.attribute.choose || [],
goods_content_app: data.goods.content_app,
temp_buy_number: (data.goods.buy_min_number) || 1,
goods_favor_text: (data.goods.is_favor == 1) ? '已收藏' : '收藏',
......@@ -89,6 +86,9 @@ Page({
nav_submit_is_disabled: (data.goods.is_shelves == 1 && data.goods.inventory > 0) ? false : true,
});
// 规格处理
this.goods_specifications_choose_handle_dont(data.goods.specifications.choose, 0);
if (data.goods.is_shelves != 1) {
this.setData({
nav_submit_text: '商品已下架',
......@@ -128,6 +128,26 @@ Page({
}
},
// 规格处理
goods_specifications_choose_handle_dont(data, key) {
if((data || null) == null)
{
this.setData({goods_specifications_choose: []});
return false;
}
// 是否不能选择
for(var i in data)
{
for(var k in data[i]['value'])
{
data[i]['value'][k]['is_dont'] = (key > 0) ? 'spec-dont' : '',
data[i]['value'][k]['is_disabled'] = '';
}
}
this.setData({goods_specifications_choose: data});
},
// 下拉刷新
onPullDownRefresh() {
this.init();
......@@ -178,7 +198,7 @@ Page({
my.showLoading({content: '处理中...'});
my.httpRequest({
url: app.get_request_url('Favor', 'Goods'),
url: app.get_request_url('favor', 'goods'),
method: 'POST',
data: {"id": this.data.goods.id},
dataType: 'json',
......@@ -231,15 +251,15 @@ Page({
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;
var goods_specifications_choose = this.data.goods_specifications_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'];
attribute_all_cart[goods_specifications_choose[i]['id']] = goods_specifications_choose[i]['find'][temp_attribute_active[i]]['id'];
}
}
my.showLoading({ content: '处理中...' });
my.httpRequest({
url: app.get_request_url('Save', 'Cart'),
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',
......@@ -346,9 +366,9 @@ Page({
return false;
} else {
// 属性
var goods_attribute_choose = this.data.goods_attribute_choose;
var goods_specifications_choose = this.data.goods_specifications_choose;
var temp_attribute_active = this.data.temp_attribute_active;
var attr_count = goods_attribute_choose.length;
var attr_count = goods_specifications_choose.length;
var attribute_all = {};
if(attr_count > 0)
{
......@@ -363,7 +383,7 @@ Page({
} else {
for(var i in temp_attribute_active)
{
attribute_all[goods_attribute_choose[i]['id']] = goods_attribute_choose[i]['find'][temp_attribute_active[i]]['id'];
attribute_all[goods_specifications_choose[i]['id']] = goods_specifications_choose[i]['find'][temp_attribute_active[i]]['id'];
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册