文件夹主要包括
alipay 支付宝回调,
wx 微信回调
api/add_cart.php 添加购物车,
cms/model 对应的model类,
cms/modules/order 商城模块
cms/modules/pay/classes 相关支付类(如果安装过付费阅读,该文件不需要复制)
二、插件安装
(1)后台---模块---模块管理---安装“商城”插件
(2)后台---模块---充值记录---安装“新版支付宝”和微信支付(如果已安装可以跳过)
(3)给相关模型添加字段:price,价格,如果价格大于0则会出现购买按钮
三、使用说明
(1)会员中心模板添加“我的购物车”和“我的订单”菜单
找到模板:cms\templates\default\member\left.html,在第7行左右添加代码:
添加完毕,更新缓存,测试支付效果即可
(2)在前端页面show.html合适位置添加“加入购物车”和“立即购买”按钮
- {if module_exists('order')}
- <dl>
- <dt> <span class="fa fa-shopping-cart"></span> 订单管理</dt>
- <dd><a href="index.php?m=order&c=cart&a=init"{if ROUTE_A=="init" && ROUTE_C=="cart"} class="left_cur" {/if}>我的购物车</a></dd>
- <dd><a href="index.php?m=order&c=order&a=init"{if ROUTE_A!="init" && ROUTE_C=="order"} class="left_cur" {/if}>我的订单</a></dd>
- </dl>
- {/if}
(3)找到\statics\css\default\css\member-index.css在最下边添加css
- {if $price}
- <style>
- .btnlist{ width: 100%;}
- .btnlist span{ display: inline-block;}
- .btnlist .buybtn{ padding:0 20px; line-height: 35px; height: 35px; background-color: #2196f3; color: #fff; border:none;border-radius: 3px;}
- .btnlist .addcart{ padding:0 20px; line-height: 35px; height: 35px; background-color: #7fbff3; color: #fff;border:none;border-radius: 3px;display: inline-block;}
- </style>
- <div class="btnlist">
- <span>
- <form id="form" name="form" method="POST" action="{APP_PATH}index.php?m=order&c=order&a=add&id={$id}&catid={$catid}" target="_blank">
- <button type="submit" name="button" class="buybtn" id="ico_yuding">立即购买</button>
- </form>
- </span>
- <span><a href="javascript:;" class="addcart" onclick="add_cart()">加入购物车</a></span>
- </div>
- <script>
- function add_cart() {
- var id = '{$id}';
- var catid = '{$catid}';
- var price = '{$price}';
- $.getJSON('{APP_PATH}api.php?op=add_cart&id={$id}&catid={$catid}&price={$price}&'+Math.random()+'&callback=?', function(data){
- if(data.status==1) {
- alert('加入购物车成功');
- //$('#loginframe').attr('src', $('#loginframe').attr('src'));
- }else if(data.status==2) {
- alert('您已经添加过了');
- } else if(data.status== '-1') {
- alert('请登录');
- }else{
- alert('参数错误');
- }
- });
- }
- </script>
- {/if}
.....
- /* 商城css */
- .numbox{ font-size: 0;}
- .numbox .numcalc{ border:solid 1px #e2e2e2; line-height:30px;padding:0 10px; display:inline-block; cursor:pointer; background-color:#f5f5f5; font-size: 13px;}
- .numbox .num-input{line-height:28px; width: 60px; box-sizing: border-box;border:solid 1px #e2e2e2;display:inline-block;font-size: 13px; border-left: none; border-right: none;}
- .tablelista {width: 100%;}
- .tablelista th,td {padding-left: 12px;}
- .tablelista thead th {background: #f2f2f2;border: 1px solid #d5dfe8;font-weight: normal;text-align: left;height: 28px;line-height: 28px;}
- .tablelista tbody tr:nth-child(2n){ background-color: #f5f5f5;}
- .tablelista tbody tr:hover{ background-color: #f2f2f2;}
- .tablelista tbody td {border: 1px solid #eee;padding-bottom: 8px;padding-top: 8px;}
- .tablelista .tablast {background: #f6f6f6 none repeat scroll 0 0;height: 28px;line-height: 28px;}
- .order-thumb{ padding:8px;box-sizing: border-box;}
- .searchbox{ width: 100%;float: left;}
- .searchbox label{ float: left; padding-right: 10px; line-height: 35px;}
- .searchbox .date{ padding:0 !important;}
- .searchbox .date .form-control{ border:none;}
- .searchbox .orderselect{line-height: 35px !important; height: 35px;}
- .goodsinfo{border: solid 1px #e2e2e2; margin-top:5px; margin-bottom:5px;}
- .goodsinfo td{border: solid 1px #e2e2e2;border-collapse:collapse; color:#666666;}
- .goodsbox {padding:8px 0; position:relative;min-height:40px; width:100%; float:left; box-sizing:border-box; border-bottom: solid 1px #e2e2e2;}
- .goodsbox span{ float: left; display: inline-block; }
- .goodsinfo .goodsbox:nth-last-child(1){ border-bottom: none; }
- .goodsinfo .info{ width: 80%;float: left;display: flex;align-content: flex-start;justify-content: space-around; flex-wrap: nowrap;}
- .goodsinfo .info .thumb{ float:left;text-align:center;width:60px; margin:5px 0; position:relative;max-height:60px; overflow: hidden; flex:0 0 60px}
- .goodsinfo .info .thumb img {width: 60px; height: auto;border-radius: 3px; }
- .goodsinfo .info .name{ float:left; line-height:1.4em; text-align:left;padding-left:10px;display:inline-block; width:100%;box-sizing:border-box; padding-top: 2px;}
- .order_price{ width: 20%; text-align:right; line-height:35px;}
- .order_num{ width: 10%; text-align: center; line-height:35px;}
- .order_title { line-height:30px; height:30px; background-color:#f9f8f8; color:#333333;}
- .order_title span { float:left; margin-right:10px; padding-left:10px; }
- .delivery {line-height:25px; text-align:center; color:#FFFFFF; display:inline-block; border-radius: 3px; padding:0 5px; white-space: nowrap;}
添加完毕,更新缓存,测试支付效果即可