提交 fd675b70 编写于 作者: D devil

基础缓存配置+细节优化

上级 0c3dba5a
......@@ -18,7 +18,7 @@ namespace app\admin\form;
* @date 2020-06-20
* @desc description
*/
class Appcenternav
class AppCenterNav
{
// 基础条件
public $condition_base = [];
......
......@@ -18,7 +18,7 @@ namespace app\admin\form;
* @date 2020-06-20
* @desc description
*/
class Apphomenav
class AppHomeNav
{
// 基础条件
public $condition_base = [];
......
......@@ -18,7 +18,7 @@ namespace app\admin\form;
* @date 2020-06-16
* @desc description
*/
class Customview
class CustomView
{
// 基础条件
public $condition_base = [];
......
......@@ -20,7 +20,7 @@ use think\Db;
* @date 2020-06-30
* @desc description
*/
class Goodsbrowse
class GoodsBrowse
{
// 基础条件
public $condition_base = [];
......
......@@ -20,7 +20,7 @@ use think\Db;
* @date 2020-06-08
* @desc description
*/
class Goodscomments
class GoodsComments
{
// 基础条件
public $condition_base = [];
......
......@@ -20,7 +20,7 @@ use think\Db;
* @date 2020-06-30
* @desc description
*/
class Goodsfavor
class GoodsFavor
{
// 基础条件
public $condition_base = [];
......
......@@ -20,7 +20,7 @@ use think\Db;
* @date 2020-06-27
* @desc description
*/
class Integrallog
class IntegralLog
{
// 基础条件
public $condition_base = [];
......
......@@ -20,7 +20,7 @@ use think\Db;
* @date 2020-06-08
* @desc description
*/
class Orderaftersale
class OrderAftersale
{
// 基础条件
public $condition_base = [];
......
......@@ -21,7 +21,7 @@ use app\service\PayLogService;
* @date 2020-06-26
* @desc description
*/
class Paylog
class PayLog
{
// 基础条件
public $condition_base = [];
......
......@@ -18,7 +18,7 @@ namespace app\admin\form;
* @date 2020-06-20
* @desc description
*/
class Quicknav
class QuickNav
{
// 基础条件
public $condition_base = [];
......
......@@ -21,7 +21,7 @@ use app\service\RefundLogService;
* @date 2020-06-27
* @desc description
*/
class Refundlog
class RefundLog
{
// 基础条件
public $condition_base = [];
......
......@@ -22,7 +22,7 @@ use app\service\RegionService;
* @date 2020-07-12
* @desc description
*/
class Warehousegoods
class WarehouseGoods
{
// 基础条件
public $condition_base = [];
......
......@@ -64,7 +64,7 @@ return array(
'Asia/Kolkata' => '(标准时+5:00) 叶卡捷琳堡、伊斯兰堡、卡拉奇',
'Asia/Dhaka' => '(标准时+6:00) 阿拉木图、 达卡、新亚伯利亚',
'Indian/Christmas' => '(标准时+7:00) 曼谷、河内、雅加达',
'Australia/Eucla' => '(标准时+8:00)北京、重庆、香港、新加坡',
'Asia/Shanghai' => '(标准时+8:00)北京、重庆、香港、新加坡',
'Australia/Darwin' => '(标准时+9:00) 东京、汉城、大阪、雅库茨克',
'Australia/Adelaide' => '(标准时+10:00) 悉尼、关岛',
'Australia/Currie' => '(标准时+11:00) 马加丹、索罗门群岛',
......
......@@ -11,6 +11,67 @@
// 应用公共文件
/**
* 文件配置数据读写
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2020-11-13
* @desc description
* @param [string] $key [数据缓存可以]
* @param [mixed] $value [数据值(空字符串:读, null:删除, 其他:写)]
* @param [mixed] $default [默认值]
* @param [boolean] $mandatory[是否强制判断数据值(空字符串|null|0)视为空]
* @return [mixed] [缓存不存在:null, 则缓存数据]
*/
function MyFileConfig($key, $value = '', $default = null, $mandatory = false)
{
// 目录不存在则创建
$config_dir = ROOT.'runtime'.DS.'data'.DS.'config_data'.DS;
\base\FileUtil::CreateDir($config_dir);
// 数据文件
$file = $config_dir.md5($key).'.php';
// 删除
if($value === null)
{
return \base\FileUtil::UnlinkFile($aim_url);
} else {
// 读内容
if($value === '')
{
$value = file_exists($file) ? require $file : $default;
if($mandatory === true)
{
if(empty($value))
{
$value = $default;
}
}
return $value;
// 写内容
} else {
// 目录是否有可写权限
if(!is_writable($config_dir))
{
return false;
}
// 存在则校验写权限
if(file_exists($file) && !is_writable($file))
{
return false;
}
// 存储内容
$content = "<?php\nreturn ".var_export($value, true).";\n?>";
return (file_put_contents($file, $content) !== false);
}
}
}
/**
* 获取参数数据
* @author Devil
......
......@@ -27,6 +27,6 @@ return [
'default_jsonp_handler' => 'jsonpReturn',
// 伪静态后缀
'url_html_suffix' => MyC('home_seo_url_html_suffix', 'html', true),
'url_html_suffix' => MyFileConfig('home_seo_url_html_suffix', '', 'html', true),
];
?>
\ No newline at end of file
......@@ -22,7 +22,7 @@ return [
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
'auto_rule' => 1,
// 模板路径
'view_path' => APP_PATH.'index'.DS.'view'.DS.strtolower(MyC('common_default_theme', 'default', true)).DS,
'view_path' => APP_PATH.'index'.DS.'view'.DS.strtolower(MyFileConfig('common_default_theme', '', 'default', true)).DS,
// 模板后缀
'view_suffix' => 'html',
// 模板文件名分隔符
......
......@@ -207,6 +207,46 @@ class Goods extends Common
'goods' => &$goods,
]));
// 商品页面规格顶部钩子
$hook_name = 'plugins_view_goods_detail_base_sku_top';
$this->assign($hook_name.'_data', Hook::listen($hook_name,
[
'hook_name' => $hook_name,
'is_backend' => false,
'goods_id' => $goods_id,
'goods' => &$goods,
]));
// 商品页面库存数量顶部钩子
$hook_name = 'plugins_view_goods_detail_base_inventory_top';
$this->assign($hook_name.'_data', Hook::listen($hook_name,
[
'hook_name' => $hook_name,
'is_backend' => false,
'goods_id' => $goods_id,
'goods' => &$goods,
]));
// 商品页面库存数量底部钩子
$hook_name = 'plugins_view_goods_detail_base_inventory_bottom';
$this->assign($hook_name.'_data', Hook::listen($hook_name,
[
'hook_name' => $hook_name,
'is_backend' => false,
'goods_id' => $goods_id,
'goods' => &$goods,
]));
// 商品页面购买导航顶部钩子
$hook_name = 'plugins_view_goods_detail_buy_nav_top';
$this->assign($hook_name.'_data', Hook::listen($hook_name,
[
'hook_name' => $hook_name,
'is_backend' => false,
'goods_id' => $goods_id,
'goods' => &$goods,
]));
// 商品页面基础信息面板底部钩子
$hook_name = 'plugins_view_goods_detail_base_bottom';
$this->assign($hook_name.'_data', Hook::listen($hook_name,
......
......@@ -20,7 +20,7 @@ use think\Db;
* @date 2020-06-30
* @desc description
*/
class Orderaftersale
class OrderAftersale
{
// 基础条件
public $condition_base = [];
......
......@@ -20,7 +20,7 @@ use think\Db;
* @date 2020-06-28
* @desc description
*/
class Userintegral
class UserIntegral
{
// 基础条件
public $condition_base = [];
......
......@@ -271,6 +271,19 @@
<div class="theme-popbod dform">
<form class="theme-signin am-padding-sm" action="javascript:;">
<div class="theme-signin-left">
<!-- 商品页面规格顶部钩子 -->
{{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}}
<div class="plugins-tag">
<span>plugins_view_goods_detail_base_sku_top</span>
</div>
{{/if}}
{{if !empty($plugins_view_goods_detail_base_sku_top_data) and is_array($plugins_view_goods_detail_base_sku_top_data)}}
{{foreach $plugins_view_goods_detail_base_sku_top_data as $hook}}
{{if is_string($hook) or is_int($hook)}}
{{$hook|raw}}
{{/if}}
{{/foreach}}
{{/if}}
{{if !empty($goods['specifications']['choose'])}}
{{foreach $goods.specifications.choose as $key=>$spec}}
{{if !empty($spec['value'])}}
......@@ -290,6 +303,22 @@
{{/if}}
{{/foreach}}
{{/if}}
<!-- 商品页面库存数量顶部钩子 -->
{{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}}
<div class="plugins-tag">
<span>plugins_view_goods_detail_base_inventory_top</span>
</div>
{{/if}}
{{if !empty($plugins_view_goods_detail_base_inventory_top_data) and is_array($plugins_view_goods_detail_base_inventory_top_data)}}
{{foreach $plugins_view_goods_detail_base_inventory_top_data as $hook}}
{{if is_string($hook) or is_int($hook)}}
{{$hook|raw}}
{{/if}}
{{/foreach}}
{{/if}}
<!-- 库存数量 -->
<div class="theme-options">
<div class="cart-title number">数量</div>
<dd>
......@@ -302,8 +331,22 @@
</dd>
</div>
<!-- 商品页面库存数量底部钩子 -->
{{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}}
<div class="plugins-tag">
<span>plugins_view_goods_detail_base_inventory_bottom</span>
</div>
{{/if}}
{{if !empty($plugins_view_goods_detail_base_inventory_bottom_data) and is_array($plugins_view_goods_detail_base_inventory_bottom_data)}}
{{foreach $plugins_view_goods_detail_base_inventory_bottom_data as $hook}}
{{if is_string($hook) or is_int($hook)}}
{{$hook|raw}}
{{/if}}
{{/foreach}}
{{/if}}
<div class="btn-op">
<span class="btn am-btn am-btn-default confirm login-event" data-type="cart" data-ajax-url="{{:MyUrl('index/Cart/Save')}}">确认</span>
<span class="btn am-btn am-btn-default confirm login-event" data-type="cart">确认</span>
<span class="btn close am-btn am-btn-danger cancel">取消</span>
</div>
</div>
......@@ -323,6 +366,20 @@
{{/if}}
</div>
<!-- 商品页面购买导航顶部钩子 -->
{{if isset($shopxo_is_develop) and $shopxo_is_develop eq true and (!isset($is_footer) or $is_footer eq 1)}}
<div class="plugins-tag">
<span>plugins_view_goods_detail_buy_nav_top</span>
</div>
{{/if}}
{{if !empty($plugins_view_goods_detail_buy_nav_top_data) and is_array($plugins_view_goods_detail_buy_nav_top_data)}}
{{foreach $plugins_view_goods_detail_buy_nav_top_data as $hook}}
{{if is_string($hook) or is_int($hook)}}
{{$hook|raw}}
{{/if}}
{{/foreach}}
{{/if}}
<!-- 购买导航 -->
<div class="buy-nav {{if $common_site_type eq 1}}exhibition-nav{{else /}}{{if isset($is_goods_site_type_consistent) and $is_goods_site_type_consistent neq 1}}site-type-not-consistent-nav{{/if}}{{/if}}">
{{if !empty($goods.is_shelves)}}
......@@ -367,7 +424,7 @@
{{if $common_site_type eq 1}}
<!-- 站点模式 1 展示型 -->
<div class="submit">
<div class="clearfix tb-btn tb-btn-basket" data-type="cart" data-ajax-url="{{:MyUrl('index/Cart/Save')}}">
<div class="clearfix tb-btn tb-btn-basket" data-type="cart">
<a href="{{if empty($common_customer_store_tel)}}javascript:;{{else /}}tel:{{$common_customer_store_tel}}{{/if}}">
<button title="{{$common_is_exhibition_mode_btn_text}}" href="javascript:;" type="button"><i class="am-icon-phone"></i> {{$common_is_exhibition_mode_btn_text}}</button>
</a>
......@@ -385,7 +442,7 @@
{{if isset($is_goods_site_type_consistent) and $is_goods_site_type_consistent eq 1}}
<!-- 商品类型是否与系统类型一致 -->
<div class="submit">
<div class="clearfix tb-btn tb-btn-basket buy-event login-event cart-submit" data-type="cart" data-ajax-url="{{:MyUrl('index/Cart/Save')}}">
<div class="clearfix tb-btn tb-btn-basket buy-event login-event cart-submit" data-type="cart">
<button title="加入购物车" href="javascript:;" type="button"><i></i>加入购物车</button>
</div>
</div>
......@@ -399,6 +456,14 @@
<input type="hidden" name="spec" value="" />
<button type="submit"></button>
</form>
<!-- 加入购物车表单 -->
<form action="{{:MyUrl('index/cart/save')}}" method="post" class="cart-form" request-type="ajax-view">
<input type="hidden" name="goods_id" value="{{$goods.id}}" />
<input type="hidden" name="stock" value="1" />
<input type="hidden" name="spec" value="" />
<button type="submit" data-am-loading="{loadingText:''}"></button>
</form>
{{/if}}
{{else /}}
<p class="goods-not-buy-tips">商品卖光了</p>
......
......@@ -25,10 +25,6 @@ use app\service\QuickNavService;
*/
class BaseService
{
public static function sss()
{
return MyC('common_timezone', 'Asia/Shanghai', true);
}
/**
* 公共配置信息
* @author Devil
......
......@@ -213,8 +213,11 @@ class ConfigService
$v = ResourcesService::ContentStaticReplace($v, 'get');
}
// 单个缓存
// 公共内置数据缓存
cache($k, $v);
// 数据文件缓存
MyFileConfig($k, $v);
}
// 所有配置缓存集合
......
......@@ -34,7 +34,18 @@ return array (
),
'plugins_css' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
0 => 'app\\plugins\\ordergoodsform\\Hook',
1 => 'app\\plugins\\membershiplevelvip\\Hook',
2 => 'app\\plugins\\multilingual\\Hook',
),
'plugins_js' =>
array (
0 => 'app\\plugins\\ordergoodsform\\Hook',
1 => 'app\\plugins\\multilingual\\Hook',
),
'plugins_view_goods_detail_base_inventory_top' =>
array (
0 => 'app\\plugins\\ordergoodsform\\Hook',
),
'plugins_service_navigation_header_handle' =>
array (
......@@ -95,6 +106,27 @@ return array (
'plugins_service_header_navigation_top_right_handle' =>
array (
0 => 'app\\plugins\\membershiplevelvip\\Hook',
1 => 'app\\plugins\\multilingual\\Hook',
),
'plugins_common_page_bottom' =>
array (
0 => 'app\\plugins\\multilingual\\Hook',
),
'plugins_service_quick_navigation_pc' =>
array (
0 => 'app\\plugins\\multilingual\\Hook',
),
'plugins_service_quick_navigation_h5' =>
array (
0 => 'app\\plugins\\multilingual\\Hook',
),
'plugins_view_common_top' =>
array (
0 => 'app\\plugins\\multilingual\\Hook',
),
'plugins_view_common_bottom' =>
array (
0 => 'app\\plugins\\multilingual\\Hook',
),
);
?>
\ No newline at end of file
......@@ -37,7 +37,7 @@ return [
// 默认JSONP处理方法
'var_jsonp_handler' => 'callback',
// 默认时区
'default_timezone' => MyC('common_timezone', 'Asia/Shanghai', true),
'default_timezone' => MyFileConfig('common_timezone', '', 'Asia/Shanghai', true),
// 是否开启多语言
'lang_switch_on' => false,
// 默认全局过滤方法 用逗号分隔多个
......
......@@ -14,8 +14,8 @@
// +----------------------------------------------------------------------
// cdn地址
$cdn_attachment_host = MyC('common_cdn_attachment_host', __MY_PUBLIC_URL__, true);
$cdn_public_host = MyC('common_cdn_public_host', __MY_PUBLIC_URL__, true);
$cdn_attachment_host = MyFileConfig('common_cdn_attachment_host', '', __MY_PUBLIC_URL__, true);
$cdn_public_host = MyFileConfig('common_cdn_public_host', '', __MY_PUBLIC_URL__, true);
if(substr($cdn_attachment_host, -1) == DS)
{
$cdn_attachment_host = substr($cdn_attachment_host, 0, -1);
......
......@@ -27,7 +27,7 @@ return [
'imageFieldName' => 'upfile',
// 上传大小限制,单位B
'imageMaxSize' => MyC('home_max_limit_image', 2048000, true),
'imageMaxSize' => MyFileConfig('home_max_limit_image', '', 2048000, true),
// 上传图片格式显示
'imageAllowFiles' => ['.png', '.jpg', '.jpeg', '.gif', '.bmp'],
......@@ -59,7 +59,7 @@ return [
'scrawlPathFormat' => __MY_ROOT_PUBLIC__.'static/upload/images/'.$upload_path.'/{yyyy}/{mm}/{dd}/{time}{rand:6}',
// 上传大小限制,单位B
'scrawlMaxSize' => MyC('home_max_limit_image', 2048000, true),
'scrawlMaxSize' => MyFileConfig('home_max_limit_image', '', 2048000, true),
// 上传图片格式显示
'scrawlAllowFiles' => ['.png', '.jpg', '.jpeg', '.gif', '.bmp'],
......@@ -102,7 +102,7 @@ return [
'catcherUrlPrefix' => '',
// 上传大小限制,单位B
'catcherMaxSize' => MyC('home_max_limit_image', 2048000, true),
'catcherMaxSize' => MyFileConfig('home_max_limit_image', '', 2048000, true),
// 抓取图片格式显示
'catcherAllowFiles' => ['.png', '.jpg', '.jpeg', '.gif', '.bmp'],
......@@ -122,7 +122,7 @@ return [
'videoUrlPrefix' => '',
// 上传大小限制,单位B,默认100MB
'videoMaxSize' => MyC('home_max_limit_video', 102400000, true),
'videoMaxSize' => MyFileConfig('home_max_limit_video', '', 102400000, true),
// 上传视频格式显示
'videoAllowFiles' => ['.swf', '.ogg', '.ogv', '.mp4', '.webm', '.mp3'],
......@@ -142,7 +142,7 @@ return [
'fileUrlPrefix' => '',
// 上传大小限制,单位B,默认50MB
'fileMaxSize' => MyC('home_max_limit_file', 51200000, true),
'fileMaxSize' => MyFileConfig('home_max_limit_file', '', 51200000, true),
// 上传文件格式显示
'fileAllowFiles' => ['.png', '.jpg', '.jpeg', '.gif', '.bmp', '.flv', '.swf', '.mkv', '.avi', '.rm', '.rmvb', '.mpeg', '.mpg', '.ogg', '.ogv', '.mov', '.wmv', '.mp4', '.webm', '.mp3', '.wav', '.mid','.rar', '.zip', '.tar', '.gz', '.7z', '.bz2', '.cab', '.iso', '.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.pdf', '.txt', '.md', '.xml'],
......
......@@ -37,6 +37,11 @@ define('__MY_PUBLIC_URL__', empty($_SERVER['HTTP_HOST']) ? '' : __MY_HTTP__.':/
// 当前页面url地址
$request_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
if(!empty($request_url) && !empty($my_root))
{
// 去除多余的子目录路径
$request_url = str_replace($my_root, '', $request_url);
}
define('__MY_VIEW_URL__', substr(__MY_URL__, 0, -1).$request_url);
// 系统根目录,强制转换win反斜杠
......
......@@ -369,15 +369,10 @@ function FromInit(form_name)
// ajax-reload 请求完成后刷新页面
// ajax-url 请求完成后调整到指定的请求值
// ajax-fun 请求完成后调用指定方法
// ajax-view 请求完成后仅提示文本信息
// sync 不发起请求、直接同步调用指定的方法
// jump 不发起请求、拼接数据参数跳转到指定 url 地址
var request_handle = ['ajax-reload', 'ajax-url', 'ajax-fun', 'sync', 'jump'];
// 是form表单直接通过
if(request_type == 'form')
{
return true;
}
var request_handle = ['ajax-reload', 'ajax-url', 'ajax-fun', 'ajax-view', 'sync', 'jump', 'form'];
// 参数校验
if(request_handle.indexOf(request_type) == -1)
......@@ -387,37 +382,46 @@ function FromInit(form_name)
return false;
}
// 类型不等于刷新的时候,类型值必须填写
if(request_type != 'ajax-reload' && request_value == null)
// 类型值必须配置校验
var request_type_value = ['ajax-url', 'ajax-fun', 'sync', 'jump']
if(request_type_value.indexOf(request_type) != -1 && request_value == null)
{
$button.button('reset');
Prompt('表单[类型值]参数配置有误');
return false;
}
// 同步调用方法
if(request_type == 'sync')
// 请求类型
switch(request_type)
{
$button.button('reset');
if(IsExitsFunction(request_value))
{
window[request_value](GetFormVal(form_name, true));
} else {
Prompt('['+request_value+']表单定义的方法未定义');
}
return false;
}
// 是form表单直接通过
case 'form' :
return true;
break;
// 同步调用方法
case 'sync' :
$button.button('reset');
if(IsExitsFunction(request_value))
{
window[request_value](GetFormVal(form_name, true));
} else {
Prompt('['+request_value+']表单定义的方法未定义');
}
return false;
break;
// 拼接参数跳转
case 'jump' :
var params = GetFormVal(form_name, true);
for(var i in params)
{
request_value = UrlFieldReplace(i, encodeURIComponent(params[i]), request_value)
}
window.location.href = request_value;
return false;
break;
// 拼接参数跳转
if(request_type == 'jump')
{
var params = GetFormVal(form_name, true);
for(var i in params)
{
request_value = UrlFieldReplace(i, encodeURIComponent(params[i]), request_value)
}
window.location.href = request_value;
return false;
}
// 请求 url http类型
......@@ -433,15 +437,16 @@ function FromInit(form_name)
// ajax请求
$.ajax({
url:action,
type:method,
dataType:"json",
timeout:$form.attr('timeout') || 30000,
data:GetFormVal(form_name),
processData:false,
contentType:false,
success:function(result)
url: action,
type: method,
dataType: "json",
timeout: $form.attr('timeout') || 30000,
data: GetFormVal(form_name),
processData: false,
contentType: false,
success: function(result)
{
$.AMUI.progress.done();
// 调用自定义回调方法
if(request_type == 'ajax-fun')
{
......@@ -449,40 +454,45 @@ function FromInit(form_name)
{
window[request_value](result);
} else {
$.AMUI.progress.done();
$button.button('reset');
Prompt('['+request_value+']表单定义的方法未定义');
}
} else if(request_type == 'ajax-url' || request_type == 'ajax-reload')
{
$.AMUI.progress.done();
} else {
// 统一处理
if(result.code == 0)
{
// url跳转
if(request_type == 'ajax-url')
switch(request_type)
{
Prompt(result.msg, 'success');
setTimeout(function()
{
window.location.href = request_value;
}, 1500);
// 页面刷新
} else if(request_type == 'ajax-reload')
{
Prompt(result.msg, 'success');
setTimeout(function()
{
window.location.reload();
}, 1500);
}
// url跳转
case 'ajax-url' :
Prompt(result.msg, 'success');
setTimeout(function()
{
window.location.href = request_value;
}, 1500);
break;
// 页面刷新
case 'ajax-reload' :
Prompt(result.msg, 'success');
setTimeout(function()
{
window.location.reload();
}, 1500);
break;
// 默认仅提示
default :
$button.button('reset');
Prompt(result.msg, 'success');
}
} else {
Prompt(result.msg);
$button.button('reset');
}
}
},
error:function(xhr, type)
error: function(xhr, type)
{
$.AMUI.progress.done();
$button.button('reset');
......
......@@ -221,6 +221,9 @@ flex: 1 1 0%;line-height: 16px;cursor: pointer;}
#min, #add{ width: 35px; height: 25px; outline:none; line-height: 23px; padding: 0; cursor: pointer; }
#text_box { width: 60px; height: 25px; text-align: center; font-size: 12px !important; }
.theme-popover .am-input-group { display: inline-flex; }
@media only screen and (min-width: 641px) {
.theme-popover .am-input-group { margin-left: 5px; }
}
/*购物车*/
......
......@@ -66,7 +66,7 @@ function GoodsCommentsHtml(page)
}
/**
* 购买/加入购物车
* 购买/加入购物车校验
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
......@@ -74,10 +74,9 @@ function GoodsCommentsHtml(page)
* @desc description
* @param {[object]} e [当前标签对象]
*/
function CartAdd(e)
function BuyCartCheck(e)
{
// 参数
var type = e.attr('data-type');
var stock = parseInt($('#text_box').val()) || 1;
var inventory = parseInt($('.stock-tips .stock').text());
var min = $('.stock-tips .stock').data('min-limit') || 1;
......@@ -124,55 +123,48 @@ function CartAdd(e)
});
}
}
return {
"stock": stock,
"spec": spec,
"type": e.attr('data-type')
};
}
/**
* 购买/加入购物车处理
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-09-13
* @desc description
* @param {[object]} e [当前标签对象]
*/
function BuyCartHandle(e)
{
// 参数
var params = BuyCartCheck(e);
if(params === false)
{
return false;
}
// 操作类型
switch(type)
switch(params.type)
{
// 立即购买
case 'buy' :
var $form_buy = $('form.buy-form');
$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');
var $form = $('form.buy-form');
$form.find('input[name="spec"]').val(JSON.stringify(params.spec));
$form.find('input[name="stock"]').val(params.stock);
$form.find('button[type="submit"]').trigger('click');
break;
// 加入购物车
case 'cart' :
// 开启进度条
$.AMUI.progress.start();
var $button = e;
$button.attr('disabled', true);
// ajax请求
$.ajax({
url: e.data('ajax-url'),
type: 'post',
dataType: "json",
timeout: 10000,
data: {"goods_id": $('.goods-detail').data('id'), "stock": stock, "spec": spec},
success: function(result)
{
PoptitClose();
$.AMUI.progress.done();
$button.attr('disabled', false);
if(result.code == 0)
{
HomeCartNumberTotalUpdate(parseInt(result.data));
Prompt(result.msg, 'success');
} else {
Prompt(result.msg);
}
},
error: function(xhr, type)
{
PoptitClose();
$.AMUI.progress.done();
$button.attr('disabled', false);
Prompt('服务器错误');
}
});
var $form = $('form.cart-form');
$form.find('input[name="spec"]').val(JSON.stringify(params.spec));
$form.find('input[name="stock"]').val(params.stock);
$form.find('button[type="submit"]').trigger('click');
break;
// 默认
......@@ -385,6 +377,9 @@ function SpecPopupShow(e)
}
$(function() {
// 购物车表单初始化
FromInit('form.cart-form');
// 商品规格选择
$('.theme-options').each(function()
{
......@@ -498,7 +493,7 @@ $(function() {
{
if($(window).width() >= 1025)
{
CartAdd($(this));
BuyCartHandle($(this));
}
}
});
......@@ -509,7 +504,7 @@ $(function() {
{
if($(window).width() < 1025)
{
CartAdd($(this));
BuyCartHandle($(this));
}
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册