规格bug修复,下订单
parent
8634d9a400
commit
f65c4efd89
|
|
@ -2,13 +2,6 @@
|
|||
.DS_Store
|
||||
.ide
|
||||
*.log
|
||||
Runtime
|
||||
Temp
|
||||
temp
|
||||
Logs
|
||||
logs
|
||||
*.lock
|
||||
#Upload
|
||||
#upload
|
||||
.tea
|
||||
AppMini/New/*
|
||||
|
|
@ -58,6 +58,7 @@ class Goods extends Common
|
|||
'number' => $number,
|
||||
'total' => $total,
|
||||
'where' => $params,
|
||||
'page' => isset($params['page']) ? intval($params['page']) : 1,
|
||||
'url' => url('admin/goods/index'),
|
||||
);
|
||||
$page = new \base\Page($page_params);
|
||||
|
|
@ -127,6 +128,9 @@ class Goods extends Common
|
|||
// 品牌分类
|
||||
$this->assign('brand_list', BrandService::CategoryBrand());
|
||||
|
||||
// 参数
|
||||
$this->assign('params', $params);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@
|
|||
</div>
|
||||
</td>
|
||||
<td class="view-operation">
|
||||
<a href="{{:url('admin/goods/saveInfo', array('id'=>$v['id']))}}">
|
||||
<a href="{{:url('admin/goods/saveInfo', array_merge($params, ['id'=>$v['id']]))}}">
|
||||
<button class="am-btn am-btn-default am-btn-xs am-radius am-icon-edit"></button>
|
||||
</a>
|
||||
<button class="am-btn am-btn-default am-btn-xs am-radius am-icon-trash-o submit-delete" data-url="{{:url('admin/goods/delete')}}" data-id="{{$v.id}}"></button>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<div class="content-right">
|
||||
<div class="content">
|
||||
<!-- form start -->
|
||||
<form class="am-form form-validation view-save" action="{{:url('admin/goods/save')}}" method="POST" request-type="ajax-url" request-value="{{:url('admin/goods/index')}}" enctype="multipart/form-data">
|
||||
<form class="am-form form-validation view-save" action="{{:url('admin/goods/save')}}" method="POST" request-type="ajax-url" request-value="{{:url('admin/goods/index', $params)}}" enctype="multipart/form-data">
|
||||
<input type="hidden" name="max_file_size" value="{{:MyC('home_max_limit_video', 102400000)}}" />
|
||||
<legend>
|
||||
<span class="fs-16">
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
{{:lang('goods_edit_name')}}
|
||||
{{/if}}
|
||||
</span>
|
||||
<a href="{{:url('admin/goods/index')}}" class="fr fs-14 m-t-5 am-icon-mail-reply"> {{:lang('common_operation_back')}}</a>
|
||||
<a href="{{:url('admin/goods/index', $params)}}" class="fr fs-14 m-t-5 am-icon-mail-reply"> {{:lang('common_operation_back')}}</a>
|
||||
</legend>
|
||||
|
||||
<nav class="goods-nav">
|
||||
|
|
@ -109,22 +109,10 @@
|
|||
{{/if}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="am-form-group">
|
||||
<label>{{:lang('goods_inventory_text')}}</label>
|
||||
<input type="number" name="inventory" placeholder="{{:lang('goods_inventory_text')}}" min="1" max="100000000" data-validation-message="{{:lang('goods_inventory_format')}}" class="am-radius" {{if !empty($data)}} value="{{$data.inventory}}"{{/if}} required />
|
||||
</div>
|
||||
<div class="am-form-group">
|
||||
<label>{{:lang('goods_inventory_unit_text')}}</label>
|
||||
<input type="text" name="inventory_unit" placeholder="{{:lang('goods_inventory_unit_text')}}" minlength="1" maxlength="6" data-validation-message="{{:lang('goods_inventory_unit_format')}}" class="am-radius" {{if !empty($data)}} value="{{$data.inventory_unit}}"{{/if}} required />
|
||||
</div>
|
||||
<div class="am-form-group">
|
||||
<label>{{:lang('goods_original_price_text')}}<span class="fs-12 fw-100 cr-999">({{:lang('goods_price_tips')}})</span></label>
|
||||
<input type="text" placeholder="{{:lang('goods_price_text')}}" name="original_price" pattern="{{:lang('common_regex_price')}}" data-validation-message="{{:lang('goods_price_format')}}" class="am-radius" {{if !empty($data['original_price']) and $data['original_price'] gt 0}} value="{{$data.original_price}}"{{/if}} />
|
||||
</div>
|
||||
<div class="am-form-group">
|
||||
<label>{{:lang('goods_price_text')}}<span class="fs-12 fw-100 cr-999">({{:lang('goods_price_tips')}})</span></label>
|
||||
<input type="text" placeholder="{{:lang('goods_price_text')}}" name="price" pattern="{{:lang('common_regex_price')}}" data-validation-message="{{:lang('goods_price_format')}}" class="am-radius" {{if !empty($data)}}value="{{$data.price}}"{{/if}} required />
|
||||
</div>
|
||||
<div class="am-form-group">
|
||||
<label>{{:lang('goods_give_integral_text')}}</label>
|
||||
<input type="number" name="give_integral" placeholder="{{:lang('goods_give_integral_text')}}" max="100000000" data-validation-message="{{:lang('goods_give_integral_format')}}" class="am-radius" value="{{if empty($data)}}0{{else /}}{{$data.give_integral}}{{/if}}" required />
|
||||
|
|
@ -183,7 +171,7 @@
|
|||
<th>库存</th>
|
||||
<th>规格编码</th>
|
||||
<th>条形码</th>
|
||||
<th>成本价(元) </th>
|
||||
<th>原价(元) </th>
|
||||
<th class="operation-btn">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
@ -203,7 +191,7 @@
|
|||
<input type="text" name="specifications_barcode[]" placeholder="条形码" class="am-radius" maxlength="80" data-validation-message="条形码最多80个字符" />
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="specifications_original_price[]" placeholder="成本价" class="am-radius" pattern="^([0-9]{1}\d{0,6})(\.\d{1,2})?$" data-validation-message="请填写有效的销售金额" />
|
||||
<input type="text" name="specifications_original_price[]" placeholder="原价" class="am-radius" pattern="^([0-9]{1}\d{0,6})(\.\d{1,2})?$" data-validation-message="请填写有效的销售金额" />
|
||||
</td>
|
||||
<td>
|
||||
<!--operation-->
|
||||
|
|
@ -237,7 +225,7 @@
|
|||
<input type="text" name="specifications_barcode[]" placeholder="条形码" class="am-radius" maxlength="80" data-validation-message="条形码最多80个字符" value="{{$v.data.barcode}}" />
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="specifications_original_price[]" placeholder="成本价" class="am-radius" pattern="^([0-9]{1}\d{0,6})(\.\d{1,2})?$" data-validation-message="请填写有效的销售金额" value="{{if $v['data']['original_price'] gt 0}}{{$v.data.original_price}}{{/if}}" />
|
||||
<input type="text" name="specifications_original_price[]" placeholder="原价" class="am-radius" pattern="^([0-9]{1}\d{0,6})(\.\d{1,2})?$" data-validation-message="请填写有效的销售金额" value="{{if $v['data']['original_price'] gt 0}}{{$v.data.original_price}}{{/if}}" />
|
||||
</td>
|
||||
<td>
|
||||
{{if $line_k gt 0}}
|
||||
|
|
@ -262,7 +250,7 @@
|
|||
<!-- 相册 -->
|
||||
<div id="goods-nav-photo" class="division-block">
|
||||
<label class="block nav-detail-title">{{:lang('goods_nav_photo_name')}}<span class="fs-12 fw-100 cr-999">({{:lang('goods_images_tips')}})</span></label>
|
||||
<ul class="plug-file-upload-view goods-photo-view" data-form-name="photo[]" data-max-number="10" data-dialog-type="images">
|
||||
<ul class="plug-file-upload-view goods-photo-view" data-form-name="photo[]" data-max-number="5" data-dialog-type="images">
|
||||
{{if !empty($data['photo'])}}
|
||||
{{foreach $data.photo as $v}}
|
||||
<li>
|
||||
|
|
|
|||
|
|
@ -119,10 +119,10 @@
|
|||
</a>
|
||||
<div class="goods-base">
|
||||
<a href="{{$goods.goods_url}}" target="_blank" class="goods-title">{{$goods.title}}</a>
|
||||
{{if !empty($goods.attribute)}}
|
||||
{{if !empty($goods.spec)}}
|
||||
<ul class="goods-attr">
|
||||
{{foreach $goods.attribute as $attr}}
|
||||
<li>{{$attr.attr_type_name}}:{{$attr.attr_name}}</li>
|
||||
{{foreach $goods.spec as $spec}}
|
||||
<li>{{$spec.type}}:{{$spec.value}}</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
{{/if}}
|
||||
|
|
@ -222,7 +222,7 @@
|
|||
<input type="hidden" name="goods_id" value="{{if isset($params['goods_id'])}}{{$params.goods_id}}{{else /}}0{{/if}}" />
|
||||
<input type="hidden" name="buy_type" value="{{if isset($params['buy_type'])}}{{$params.buy_type}}{{else /}}goods{{/if}}" />
|
||||
<input type="hidden" name="stock" value="{{if isset($params['stock'])}}{{$params.stock}}{{else /}}1{{/if}}" />
|
||||
<input type="hidden" name="attr" value='{{if isset($params['attr'])}}{{$params.attr}}{{/if}}' />
|
||||
<input type="hidden" name="spec" value='{{if isset($params['spec'])}}{{$params.spec}}{{/if}}' />
|
||||
<input type="hidden" name="ids" value="{{if isset($params['ids'])}}{{$params.ids}}{{/if}}" />
|
||||
<input type="hidden" name="address_id" value="0" />
|
||||
<input type="hidden" name="payment_id" value="0" />
|
||||
|
|
|
|||
|
|
@ -41,10 +41,10 @@
|
|||
</a>
|
||||
<div class="goods-base">
|
||||
<a href="{{$goods.goods_url}}" target="_blank" class="goods-title">{{$goods.title}}</a>
|
||||
{{if !empty($goods.attribute)}}
|
||||
{{if !empty($goods.spec)}}
|
||||
<ul class="goods-attr">
|
||||
{{foreach $goods.attribute as $attr}}
|
||||
<li>{{$attr.attr_type_name}}:{{$attr.attr_name}}</li>
|
||||
{{foreach $goods.spec as $spec}}
|
||||
<li>{{$spec.type}}:{{$spec.value}}</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
{{/if}}
|
||||
|
|
|
|||
|
|
@ -56,9 +56,11 @@
|
|||
<ul class="tb-thumb" id="thumblist">
|
||||
{{if !empty($goods.photo)}}
|
||||
{{foreach $goods.photo as $photo_key=>$photo}}
|
||||
<li class="{{if $photo_key eq 0}}tb-selected{{else /}} tb-pic tb-s40{{/if}}">
|
||||
<li class="{{if $photo_key eq 0}}tb-selected{{else /}} tb-pic{{/if}}">
|
||||
<div class="tb-pic tb-s40">
|
||||
<a href="javascript:;"><img src="{{$photo.images}}" mid="{{$photo.images}}" big="{{:str_replace('compr', 'original', $photo.images)}}"></a>
|
||||
<a href="javascript:;">
|
||||
<img src="{{$photo.images}}" mid="{{$photo.images}}" big="{{:str_replace('compr', 'original', $photo.images)}}" class="tb-s40" />
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
{{/foreach}}
|
||||
|
|
@ -223,7 +225,7 @@
|
|||
<input type="hidden" name="goods_id" value="{{$goods.id}}" />
|
||||
<input type="hidden" name="buy_type" value="goods" />
|
||||
<input type="hidden" name="stock" value="1" />
|
||||
<input type="hidden" name="attr" value="" />
|
||||
<input type="hidden" name="spec" value="" />
|
||||
<button type="submit"></button>
|
||||
</form>
|
||||
{{else /}}
|
||||
|
|
|
|||
|
|
@ -229,10 +229,10 @@
|
|||
</a>
|
||||
<div class="goods-base">
|
||||
<a href="{{$goods.goods_url}}" target="_blank" class="goods-title">{{$goods.title}}</a>
|
||||
{{if !empty($goods.attribute)}}
|
||||
{{if !empty($goods.spec)}}
|
||||
<ul class="goods-attr">
|
||||
{{foreach $goods.attribute as $attr}}
|
||||
<li>{{$attr.attr_type_name}}:{{$attr.attr_name}}</li>
|
||||
{{foreach $goods.spec as $spec}}
|
||||
<li>{{$spec.type}}:{{$spec.value}}</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
{{/if}}
|
||||
|
|
|
|||
|
|
@ -151,10 +151,10 @@
|
|||
</a>
|
||||
<div class="goods-base">
|
||||
<a href="{{$goods.goods_url}}" target="_blank" class="goods-title">{{$goods.title}}</a>
|
||||
{{if !empty($goods.attribute)}}
|
||||
{{if !empty($goods.spec)}}
|
||||
<ul class="goods-attr">
|
||||
{{foreach $goods.attribute as $attr}}
|
||||
<li>{{$attr.attr_type_name}}:{{$attr.attr_name}}</li>
|
||||
{{foreach $goods.spec as $spec}}
|
||||
<li>{{$spec.type}}:{{$spec.value}}</li>
|
||||
{{/foreach}}
|
||||
</ul>
|
||||
{{/if}}
|
||||
|
|
|
|||
|
|
@ -58,8 +58,15 @@ class BuyService
|
|||
return DataReturn('商品不存在或已删除', -2);
|
||||
}
|
||||
|
||||
// 属性处理
|
||||
$attr = self::GoodsAttrParsing($params);
|
||||
// 规格处理
|
||||
$spec = self::GoodsSpecificationsHandle($params);
|
||||
|
||||
// 获取商品基础信息
|
||||
$goods_base = GoodsService::GoodsSpecDetail(['id'=>$goods_id, 'spec'=>$spec]);
|
||||
if($goods_base['code'] != 0)
|
||||
{
|
||||
return $goods_base;
|
||||
}
|
||||
|
||||
// 添加购物车
|
||||
$data = [
|
||||
|
|
@ -67,20 +74,19 @@ class BuyService
|
|||
'goods_id' => $goods_id,
|
||||
'title' => $goods['title'],
|
||||
'images' => $goods['images'],
|
||||
'original_price'=> $goods['original_price'],
|
||||
'price' => $goods['price'],
|
||||
'original_price'=> $goods_base['data']['original_price'],
|
||||
'price' => $goods_base['data']['price'],
|
||||
'stock' => intval($params['stock']),
|
||||
'attribute' => count($attr) == 0 ? '' : json_encode($attr),
|
||||
'spec' => empty($spec) ? '' : json_encode($spec),
|
||||
];
|
||||
|
||||
// 存在则更新
|
||||
$m = db('Cart');
|
||||
$where = ['user_id'=>$data['user_id'], 'goods_id'=>$data['goods_id'], 'attribute'=>$data['attribute']];
|
||||
$temp = $m->where($where)->find();
|
||||
$where = ['user_id'=>$data['user_id'], 'goods_id'=>$data['goods_id'], 'spec'=>$data['spec']];
|
||||
$temp = db('Cart')->where($where)->find();
|
||||
if(empty($temp))
|
||||
{
|
||||
$data['add_time'] = time();
|
||||
if($m->insertGetId($data) > 0)
|
||||
if(db('Cart')->insertGetId($data) > 0)
|
||||
{
|
||||
return DataReturn(lang('common_join_success'), 0, self::UserCartTotal($params));
|
||||
}
|
||||
|
|
@ -91,7 +97,7 @@ class BuyService
|
|||
{
|
||||
$data['stock'] = $goods['inventory'];
|
||||
}
|
||||
if($m->where($where)->update($data))
|
||||
if(db('Cart')->where($where)->update($data))
|
||||
{
|
||||
return DataReturn(lang('common_join_success'), 0, self::UserCartTotal($params));
|
||||
}
|
||||
|
|
@ -101,7 +107,7 @@ class BuyService
|
|||
}
|
||||
|
||||
/**
|
||||
* 商品属性解析
|
||||
* 商品规格解析
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
|
|
@ -109,31 +115,17 @@ class BuyService
|
|||
* @desc description
|
||||
* @param [array] $params [输入参数]
|
||||
*/
|
||||
private static function GoodsAttrParsing($params = [])
|
||||
private static function GoodsSpecificationsHandle($params = [])
|
||||
{
|
||||
$data = [];
|
||||
if(!empty($params['attr']) && !empty($params['goods_id']))
|
||||
$spec = [];
|
||||
if(!empty($params['spec']))
|
||||
{
|
||||
if(!is_array($params['attr']))
|
||||
if(!is_array($params['spec']))
|
||||
{
|
||||
$params['attr'] = json_decode($params['attr'], true);
|
||||
}
|
||||
foreach($params['attr'] as $k=>$v)
|
||||
{
|
||||
$attr_type_name = db('GoodsAttributeType')->where(['goods_id'=>$params['goods_id'], 'id'=>$k])->value('name');
|
||||
$attr_name = db('GoodsAttribute')->where(['goods_id'=>$params['goods_id'], 'id'=>$v])->value('name');
|
||||
if(!empty($attr_type_name) && !empty($attr_name))
|
||||
{
|
||||
$data[] = [
|
||||
'attr_type_id' => $k,
|
||||
'attr_type_name' => $attr_type_name,
|
||||
'attr_id' => $v,
|
||||
'attr_name' => $attr_name,
|
||||
];
|
||||
}
|
||||
$spec = json_decode($params['spec'], true);
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
return empty($spec) ? '' : $spec;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -164,7 +156,7 @@ class BuyService
|
|||
$where = (!empty($params['where']) && is_array($params['where'])) ? $params['where'] : [];
|
||||
$where['c.user_id'] = $params['user']['id'];
|
||||
|
||||
$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';
|
||||
$field = 'c.*, g.title, g.images, g.inventory_unit, g.is_shelves, g.is_delete_time, g.buy_min_number, g.buy_max_number';
|
||||
$data = db('Cart')->alias('c')->join(['__GOODS__'=>'g'], 'g.id=c.goods_id')->where($where)->field($field)->select();
|
||||
|
||||
|
||||
|
|
@ -174,10 +166,24 @@ class BuyService
|
|||
$images_host = config('IMAGE_HOST');
|
||||
foreach($data as &$v)
|
||||
{
|
||||
// 规格
|
||||
$v['spec'] = empty($v['spec']) ? null : json_decode($v['spec'], true);
|
||||
|
||||
// 获取商品基础信息
|
||||
$goods_base = GoodsService::GoodsSpecDetail(['id'=>$v['goods_id'], 'spec'=>$v['spec']]);
|
||||
if($goods_base['code'] == 0)
|
||||
{
|
||||
$v['inventory'] = $goods_base['data']['inventory'];
|
||||
$v['price'] = $goods_base['data']['price'];
|
||||
$v['original_price'] = $goods_base['data']['original_price'];
|
||||
} else {
|
||||
return $goods_base;
|
||||
}
|
||||
|
||||
// 基础信息
|
||||
$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'];
|
||||
}
|
||||
|
|
@ -310,8 +316,8 @@ class BuyService
|
|||
],
|
||||
[
|
||||
'checked_type' => 'isset',
|
||||
'key_name' => 'attr',
|
||||
'error_msg' => '属性参数有误',
|
||||
'key_name' => 'spec',
|
||||
'error_msg' => '规格参数有误',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
|
|
@ -332,7 +338,7 @@ class BuyService
|
|||
'is_delete_time' => 0,
|
||||
'is_shelves' => 1,
|
||||
],
|
||||
'field' => 'id, id AS goods_id, title, images, original_price, price, inventory, inventory_unit, buy_min_number, buy_max_number',
|
||||
'field' => 'id, id AS goods_id, title, images, inventory_unit, buy_min_number, buy_max_number',
|
||||
];
|
||||
$goods = GoodsService::GoodsList($p);
|
||||
if(empty($goods[0]))
|
||||
|
|
@ -340,13 +346,24 @@ class BuyService
|
|||
return DataReturn(lang('common_data_no_exist_error'), -10);
|
||||
}
|
||||
|
||||
// 规格
|
||||
$goods[0]['spec'] = self::GoodsSpecificationsHandle($params);
|
||||
|
||||
// 获取商品基础信息
|
||||
$goods_base = GoodsService::GoodsSpecDetail(['id'=>$goods[0]['goods_id'], 'spec'=>$goods[0]['spec']]);
|
||||
if($goods_base['code'] == 0)
|
||||
{
|
||||
$goods[0]['inventory'] = $goods_base['data']['inventory'];
|
||||
$goods[0]['price'] = $goods_base['data']['price'];
|
||||
$goods[0]['original_price'] = $goods_base['data']['original_price'];
|
||||
} else {
|
||||
return $goods_base;
|
||||
}
|
||||
|
||||
// 数量/小计
|
||||
$goods[0]['stock'] = $params['stock'];
|
||||
$goods[0]['total_price'] = $params['stock']*$goods[0]['price'];
|
||||
|
||||
// 属性
|
||||
$goods[0]['attribute'] = self::GoodsAttrParsing($params);
|
||||
|
||||
return DataReturn(lang('common_operation_success'), 0, $goods);
|
||||
}
|
||||
|
||||
|
|
@ -467,12 +484,20 @@ class BuyService
|
|||
|
||||
// 数据校验
|
||||
$total_price = 0;
|
||||
$m = db('Goods');
|
||||
$attr_type_m = db('GoodsAttributeType');
|
||||
$attr_m = db('GoodsAttribute');
|
||||
foreach($params['goods'] as $v)
|
||||
{
|
||||
$goods = $m->find($v['goods_id']);
|
||||
// 获取商品信息
|
||||
$goods = db('Goods')->find($v['goods_id']);
|
||||
|
||||
// 规格
|
||||
$goods_base = GoodsService::GoodsSpecDetail(['id'=>$v['goods_id'], 'spec'=>isset($v['spec']) ? $v['spec'] : []]);
|
||||
if($goods_base['code'] == 0)
|
||||
{
|
||||
$goods['price'] = $goods_base['data']['price'];
|
||||
$goods['inventory'] = $goods_base['data']['inventory'];
|
||||
} else {
|
||||
return $goods_base;
|
||||
}
|
||||
|
||||
// 基础判断
|
||||
if(empty($goods))
|
||||
|
|
@ -496,27 +521,6 @@ class BuyService
|
|||
return DataReturn('['.$v['goods_id'].']超过商品限购数量['.$v['stock'].'>'.$goods['buy_max_number'].']', -1);
|
||||
}
|
||||
|
||||
// 属性
|
||||
if(!empty($v['attribute']))
|
||||
{
|
||||
foreach($v['attribute'] as $vs)
|
||||
{
|
||||
// 属性类型
|
||||
$attr_type = $attr_type_m->find($vs['attr_type_id']);
|
||||
if(empty($attr_type))
|
||||
{
|
||||
return DataReturn('['.$v['goods_id'].']商品属性类型有误['.$vs['attr_type_id'].']', -1);
|
||||
}
|
||||
|
||||
// 具体属性
|
||||
$attr_content = $attr_m->find($vs['attr_id']);
|
||||
if(empty($attr_content))
|
||||
{
|
||||
return DataReturn('['.$v['goods_id'].']商品属性有误-'.$vs['attr_id'].']', -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 总价
|
||||
$total_price += $goods['price']*$v['stock'];
|
||||
$result[] = $goods;
|
||||
|
|
@ -634,7 +638,7 @@ class BuyService
|
|||
'images' => $v['images_old'],
|
||||
'original_price' => $v['original_price'],
|
||||
'price' => $v['price'],
|
||||
'attribute' => empty($v['attribute']) ? '' : json_encode($v['attribute']),
|
||||
'spec' => empty($v['spec']) ? '' : json_encode($v['spec']),
|
||||
'buy_number' => $v['stock'],
|
||||
'add_time' => time(),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -924,22 +924,12 @@ class GoodsService
|
|||
'key_name' => 'category_id',
|
||||
'error_msg' => '请至少选择一个商品分类',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'inventory',
|
||||
'error_msg' => '最低起购数量库存数量',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'length',
|
||||
'key_name' => 'inventory_unit',
|
||||
'checked_data' => '1,6',
|
||||
'error_msg' => '库存单位格式 1~6 个字符',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'price',
|
||||
'error_msg' => '请填写有效的销售金额',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'buy_min_number',
|
||||
|
|
@ -987,10 +977,7 @@ class GoodsService
|
|||
'title_color' => $params['title_color'],
|
||||
'model' => $params['model'],
|
||||
'place_origin' => intval($params['place_origin']),
|
||||
'inventory' => intval($params['inventory']),
|
||||
'inventory_unit' => $params['inventory_unit'],
|
||||
'original_price' => round($params['original_price'], 2),
|
||||
'price' => round($params['price'], 2),
|
||||
'give_integral' => intval($params['give_integral']),
|
||||
'buy_min_number' => intval($params['buy_min_number']),
|
||||
'buy_max_number' => intval($params['buy_max_number']),
|
||||
|
|
@ -1041,6 +1028,15 @@ class GoodsService
|
|||
// 回滚事务
|
||||
Db::rollback();
|
||||
return $ret;
|
||||
} else {
|
||||
// 更新商品基础信息
|
||||
$ret = self::GoodsSaveBaseUpdate($params, $goods_id);
|
||||
if($ret['code'] != 0)
|
||||
{
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
// 相册
|
||||
|
|
@ -1078,6 +1074,38 @@ class GoodsService
|
|||
return DataReturn('操作失败', -100);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品保存基础信息更新
|
||||
* @author Devil
|
||||
* @blog http://gong.gg/
|
||||
* @version 1.0.0
|
||||
* @datetime 2018-12-16T01:56:42+0800
|
||||
* @param [array] $params [输入参数]
|
||||
* @param [int] $goods_id [商品id]
|
||||
*/
|
||||
private static function GoodsSaveBaseUpdate($params, $goods_id)
|
||||
{
|
||||
$data = db('GoodsSpecBase')->field('min(price) AS min_price, max(price) AS max_price, sum(inventory) AS inventory, min(original_price) AS min_original_price, max(original_price) AS max_original_price')->where(['goods_id'=>$goods_id])->find();
|
||||
if(empty($data))
|
||||
{
|
||||
return DataReturn('没找到商品基础信息', -1);
|
||||
}
|
||||
|
||||
// 销售价格 - 展示价格
|
||||
$data['price'] = (!empty($data['max_price']) && $data['min_price'] != $data['max_price']) ? $data['min_price'].'-'.$data['max_price'] : $data['min_price'];
|
||||
|
||||
// 原价价格 - 展示价格
|
||||
$data['original_price'] = (!empty($data['max_original_price']) && $data['min_original_price'] != $data['max_original_price']) ? $data['min_original_price'].'-'.$data['max_original_price'] : $data['min_original_price'];
|
||||
|
||||
// 更新商品表
|
||||
$data['upd_time'] = time();
|
||||
if(db('Goods')->where(['id'=>$goods_id])->update($data))
|
||||
{
|
||||
return DataReturn('操作成功', 0);
|
||||
}
|
||||
return DataReturn('操作失败', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取规格参数
|
||||
* @author Devil
|
||||
|
|
@ -1639,11 +1667,13 @@ class GoodsService
|
|||
[
|
||||
'checked_type' => 'empty',
|
||||
'key_name' => 'spec',
|
||||
'is_checked' => 1,
|
||||
'error_msg' => '请选择规格',
|
||||
],
|
||||
[
|
||||
'checked_type' => 'is_array',
|
||||
'key_name' => 'spec',
|
||||
'is_checked' => 1,
|
||||
'error_msg' => '规格有误',
|
||||
],
|
||||
];
|
||||
|
|
@ -1658,51 +1688,62 @@ class GoodsService
|
|||
$where = [
|
||||
'goods_id' => intval($params['id']),
|
||||
];
|
||||
$value = [];
|
||||
foreach($params['spec'] as $v)
|
||||
{
|
||||
$value[] = $v['value'];
|
||||
}
|
||||
$where['value'] = $value;
|
||||
|
||||
// 获取规格值基础值id
|
||||
$ids = db('GoodsSpecValue')->where($where)->column('goods_spec_base_id');
|
||||
if(!empty($ids))
|
||||
// 有规格值
|
||||
if(!empty($params['spec']))
|
||||
{
|
||||
// 根据基础值id获取规格值列表
|
||||
$temp_data = db('GoodsSpecValue')->where(['goods_spec_base_id'=>$ids])->field('goods_spec_base_id,value')->select();
|
||||
if(!empty($temp_data))
|
||||
$value = [];
|
||||
foreach($params['spec'] as $v)
|
||||
{
|
||||
// 根据基础值id分组
|
||||
$data = [];
|
||||
foreach($temp_data as $v)
|
||||
{
|
||||
$data[$v['goods_spec_base_id']][] = $v;
|
||||
}
|
||||
$value[] = $v['value'];
|
||||
}
|
||||
$where['value'] = $value;
|
||||
|
||||
// 从条件中匹配对应的规格值得到最终的基础值id
|
||||
$base_id = 0;
|
||||
$spec_str = implode('', array_column($params['spec'], 'value'));
|
||||
foreach($data as $value_v)
|
||||
// 获取规格值基础值id
|
||||
$ids = db('GoodsSpecValue')->where($where)->column('goods_spec_base_id');
|
||||
if(!empty($ids))
|
||||
{
|
||||
// 根据基础值id获取规格值列表
|
||||
$temp_data = db('GoodsSpecValue')->where(['goods_spec_base_id'=>$ids])->field('goods_spec_base_id,value')->select();
|
||||
if(!empty($temp_data))
|
||||
{
|
||||
$temp_str = implode('', array_column($value_v, 'value'));
|
||||
if($temp_str == $spec_str)
|
||||
// 根据基础值id分组
|
||||
$data = [];
|
||||
foreach($temp_data as $v)
|
||||
{
|
||||
$base_id = $value_v[0]['goods_spec_base_id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取基础值数据
|
||||
if(!empty($base_id))
|
||||
{
|
||||
$base = db('GoodsSpecBase')->field('goods_id,price,inventory,coding,barcode,original_price')->find($base_id);
|
||||
if(!empty($base))
|
||||
{
|
||||
return DataReturn('操作成功', 0, $base);
|
||||
$data[$v['goods_spec_base_id']][] = $v;
|
||||
}
|
||||
|
||||
// 从条件中匹配对应的规格值得到最终的基础值id
|
||||
$base_id = 0;
|
||||
$spec_str = implode('', array_column($params['spec'], 'value'));
|
||||
foreach($data as $value_v)
|
||||
{
|
||||
$temp_str = implode('', array_column($value_v, 'value'));
|
||||
if($temp_str == $spec_str)
|
||||
{
|
||||
$base_id = $value_v[0]['goods_spec_base_id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取基础值数据
|
||||
if(!empty($base_id))
|
||||
{
|
||||
$base = db('GoodsSpecBase')->field('goods_id,price,inventory,coding,barcode,original_price')->find($base_id);
|
||||
if(!empty($base))
|
||||
{
|
||||
return DataReturn('操作成功', 0, $base);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$base = db('GoodsSpecBase')->field('goods_id,price,inventory,coding,barcode,original_price')->where($where)->find();
|
||||
if(!empty($base))
|
||||
{
|
||||
return DataReturn('操作成功', 0, $base);
|
||||
}
|
||||
}
|
||||
return DataReturn('没有相关规格', -100);
|
||||
}
|
||||
|
|
@ -1771,11 +1812,13 @@ class GoodsService
|
|||
|
||||
// 获取当前操作元素索引
|
||||
$last = end($params['spec']);
|
||||
$index = $last['index'];
|
||||
$index = count($params['spec'])-1;
|
||||
$spec_str = implode('', array_column($params['spec'], 'value'));
|
||||
$value = [];
|
||||
foreach($data as $v)
|
||||
{
|
||||
if(isset($v[$index+1]) && $v[$index]['value'] == $last['value'])
|
||||
$temp_str = implode('', array_column($v, 'value'));
|
||||
if(isset($v[$index+1]) && stripos($temp_str, $spec_str) !== false)
|
||||
{
|
||||
// 判断是否还有库存
|
||||
$inventory = db('GoodsSpecBase')->where(['id'=>$v[$index+1]['goods_spec_base_id']])->value('inventory');
|
||||
|
|
|
|||
|
|
@ -558,7 +558,7 @@ class OrderService
|
|||
$data = db('Order')->where($params['where'])->limit($limit_start, $limit_number)->order($order_by)->select();
|
||||
if(!empty($data))
|
||||
{
|
||||
$detail_field = 'id,goods_id,title,images,original_price,price,attribute,buy_number';
|
||||
$detail_field = 'id,goods_id,title,images,original_price,price,spec,buy_number';
|
||||
$images_host = config('IMAGE_HOST');
|
||||
$order_status_list = lang('common_order_user_status');
|
||||
$order_pay_status = lang('common_order_pay_status');
|
||||
|
|
@ -629,8 +629,8 @@ class OrderService
|
|||
foreach($items as &$vs)
|
||||
{
|
||||
$vs['images'] = empty($vs['images']) ? null : $images_host.$vs['images'];
|
||||
$vs['attribute'] = empty($vs['attribute']) ? null : json_decode($vs['attribute'], true);
|
||||
$vs['goods_url'] = HomeUrl('Goods', 'Index', ['id'=>$vs['goods_id']]);
|
||||
$vs['spec'] = empty($vs['spec']) ? null : json_decode($vs['spec'], true);
|
||||
$vs['goods_url'] = HomeUrl('goods', 'index', ['id'=>$vs['goods_id']]);
|
||||
$vs['total_price'] = $vs['buy_number']*$vs['price'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,14 +28,14 @@ class Page
|
|||
* @param [array] $param['where'] [额外条件(键值对)]
|
||||
* @param [string] $param['url'] [url地址]
|
||||
*/
|
||||
public function __construct($param = array())
|
||||
public function __construct($params = array())
|
||||
{
|
||||
$this->page = max(1, isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1);
|
||||
$this->total = max(1, isset($param['total']) ? intval($param['total']) : 1);
|
||||
$this->number = max(1, isset($param['number']) ? intval($param['number']) : 1);
|
||||
$this->bt_number = isset($param['bt_number']) ? intval($param['bt_number']) : 2;
|
||||
$this->where = (isset($param['where']) && is_array($param['where'])) ? $param['where'] : '';
|
||||
$this->url = isset($param['url']) ? $param['url'] : '';
|
||||
$this->page = max(1, isset($params['page']) ? intval($params['page']) : 1);
|
||||
$this->total = max(1, isset($params['total']) ? intval($params['total']) : 1);
|
||||
$this->number = max(1, isset($params['number']) ? intval($params['number']) : 1);
|
||||
$this->bt_number = isset($params['bt_number']) ? intval($params['bt_number']) : 2;
|
||||
$this->where = (isset($params['where']) && is_array($params['where'])) ? $params['where'] : '';
|
||||
$this->url = isset($params['url']) ? $params['url'] : '';
|
||||
$this->page_total = 1;
|
||||
$this->html = '';
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -353,20 +353,20 @@ li.am-comment{ width:100%}
|
|||
/* box */
|
||||
.box { width:700px; margin:0px auto; position: relative; }
|
||||
.tb-pic a { display:table-cell; text-align:center; vertical-align:middle; }
|
||||
.tb-pic a img {vertical-align:middle;width: 100%; }
|
||||
.tb-pic.tb-s40 img{width:100%;}
|
||||
.tb-pic a img {vertical-align:middle; }
|
||||
.tb-pic a {*display:block;*font-family:Arial;*line-height:1;}
|
||||
.tb-thumb {margin:10px 0 0; overflow:hidden; }
|
||||
.tb-thumb li {background:none repeat scroll 0 0 transparent; float:left; width: 62px; height:62px; margin:0 6px 0 0; overflow:hidden; padding:1px; }
|
||||
.tb-thumb li {background:none repeat scroll 0 0 transparent; float:left; margin:0 6px 0 0; overflow:hidden; padding:1px; }
|
||||
.tb-s310, .tb-s310 a { height:350px; width:350px; }
|
||||
|
||||
.tb-s310 a { *font-size:271px;}
|
||||
.tb-s40 a { *font-size:35px;}
|
||||
.tb-s40{ height:60px; width:60px; }
|
||||
.tb-booth { border:1px solid #CDCDCD; position:relative; z-index:1;overflow: hidden; }
|
||||
.tb-booth img { max-width: 100%; max-height: 100%; }
|
||||
.tb-thumb .tb-selected { background:none repeat scroll 0 0 #C30008; height:62px;}
|
||||
.tb-thumb .tb-selected div { background-color:#FFFFFF; border:medium none; }
|
||||
.tb-thumb li div { border:1px solid #CDCDCD; }
|
||||
.tb-thumb li div { border:1px solid #CDCDCD; overflow: hidden;}
|
||||
div.zoomDiv { z-index:999; position:absolute; top:0px; left:0px; width:400px; height:400px; background:#ffffff; border:1px solid #CCCCCC; display:none; text-align:center; overflow:hidden; }
|
||||
div.zoomMask { position:absolute; background:url(../Images/mask.png)repeat scroll 0 0 transparent; cursor:move; z-index:1; }
|
||||
|
||||
|
|
|
|||
|
|
@ -39,12 +39,12 @@ function CartAdd(e)
|
|||
}
|
||||
|
||||
// 规格
|
||||
var attr = {};
|
||||
var spec = [];
|
||||
var sku_count = $('.sku-items').length;
|
||||
if(sku_count > 0)
|
||||
{
|
||||
var attr_count = $('.sku-line.selected').length;
|
||||
if(attr_count < sku_count)
|
||||
var spec_count = $('.sku-line.selected').length;
|
||||
if(spec_count < sku_count)
|
||||
{
|
||||
$('.sku-items').each(function(k, v)
|
||||
{
|
||||
|
|
@ -57,9 +57,9 @@ function CartAdd(e)
|
|||
return false;
|
||||
} else {
|
||||
$('.iteminfo_parameter .sku-items').removeClass('attr-not-active');
|
||||
$('.sku-line.selected').each(function(k, v)
|
||||
$('.theme-signin-left .sku-items li.selected').each(function(k, v)
|
||||
{
|
||||
attr[$(this).data('parent-id')] = $(this).data('id');
|
||||
spec.push({"type": $(this).data('type-value'), "value": $(this).data('value')})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ function CartAdd(e)
|
|||
// 立即购买
|
||||
case 'buy' :
|
||||
var $form_buy = $('form.buy-form');
|
||||
$form_buy.find('input[name="attr"]').val(JSON.stringify(attr));
|
||||
$form_buy.find('input[name="spec"]').val(JSON.stringify(spec));
|
||||
$form_buy.find('input[name="stock"]').val(stock);
|
||||
$form_buy.find('button[type="submit"]').trigger('click');
|
||||
break;
|
||||
|
|
@ -89,7 +89,7 @@ function CartAdd(e)
|
|||
type: 'post',
|
||||
dataType: "json",
|
||||
timeout: 10000,
|
||||
data: {"goods_id": $('.goods-detail').data('id'), "stock": stock, "attr": attr},
|
||||
data: {"goods_id": $('.goods-detail').data('id'), "stock": stock, "spec": spec},
|
||||
success: function(result)
|
||||
{
|
||||
poptit_close();
|
||||
|
|
@ -216,7 +216,7 @@ function GoodsSpecType()
|
|||
var spec = [];
|
||||
$('.theme-signin-left .sku-items li.selected').each(function(k, v)
|
||||
{
|
||||
spec.push({"type": $(this).data('type-value'), "value": $(this).data('value'), "index": $(this).parents('.sku-items').index()})
|
||||
spec.push({"type": $(this).data('type-value'), "value": $(this).data('value')})
|
||||
});
|
||||
|
||||
// 开启进度条
|
||||
|
|
@ -234,7 +234,8 @@ function GoodsSpecType()
|
|||
$.AMUI.progress.done();
|
||||
if(result.code == 0)
|
||||
{
|
||||
var index = (spec.length > 0) ? spec[spec.length-1]['index']+1 : 0;
|
||||
var spec_count = spec.length;
|
||||
var index = (spec_count > 0) ? spec_count : 0;
|
||||
if(index < sku_count)
|
||||
{
|
||||
$('.theme-signin-left .sku-items').eq(index).find('li').each(function(k, v)
|
||||
|
|
@ -323,7 +324,7 @@ $(function() {
|
|||
|
||||
// 放大镜初始化
|
||||
$(".jqzoom").imagezoom();
|
||||
$("#thumblist li a").on('click', function() {
|
||||
$("#thumblist li a").on('mouseover', function() {
|
||||
$(this).parents("li").addClass("tb-selected").siblings().removeClass("tb-selected");
|
||||
$(".jqzoom").attr('src', $(this).find("img").attr("mid"));
|
||||
$(".jqzoom").attr('rel', $(this).find("img").attr("big"));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
||||
Loading…
Reference in New Issue