diff --git a/app/cart/controller/ZjCartController.php b/app/cart/controller/ZjCartController.php index ec06241..7767f79 100644 --- a/app/cart/controller/ZjCartController.php +++ b/app/cart/controller/ZjCartController.php @@ -128,12 +128,14 @@ class ZjCartController extends HomeBaseController ->where(['uid' => session('user.id')]) ->select() ->toArray(); + $default_address_id = ''; $default_name = ''; $default_mobile = ''; $default_address = ''; if (!empty($address)) { foreach ($address as $item) { if ($item['is_sta'] == 2) { + $default_address_id = $item['id']; $default_name = $item['name']; $default_mobile = $item['mobile']; $default_address = $item['province'] . $item['city'] . $item['county'] . $item['place']; @@ -144,6 +146,7 @@ class ZjCartController extends HomeBaseController return $this->fetch('order_confirm', [ 'data' => $data, 'address' => $address, + 'default_address_id' => $default_address_id, 'default_name' => $default_name, 'default_mobile' => $default_mobile, 'default_address' => $default_address, diff --git a/app/pay/controller/PayController.php b/app/pay/controller/PayController.php index cc52b99..6550867 100644 --- a/app/pay/controller/PayController.php +++ b/app/pay/controller/PayController.php @@ -1,6 +1,7 @@ <?php namespace app\pay\controller; use cmf\controller\HomeBaseController; +use think\Db; class PayController extends HomeBaseController { @@ -8,7 +9,7 @@ class PayController extends HomeBaseController function _initialize() { parent::_initialize(); // TODO: Change the autogenerated stub - if(empty(session('user.id'))) { + if (empty(session('user.id'))) { $this->error('登录失败'); } } @@ -17,26 +18,73 @@ class PayController extends HomeBaseController public function done() { $request = request(); - if($request->isAjax()) { + if ($request->isAjax()) { + $consignee = Db::name('zj_user_place')->field('name,province,city,county,mobile,place') + ->where(['id' => $request->param('address_id'), 'uid' => session('user.id')]) + ->find(); + $data = Db::name('zj_cart')->alias('c') + ->join('zj_goods g', 'c.gid=g.id') + ->field('c.num,g.price,g.id') + ->where(['c.uid' => session('user.id'), 'c.id' => ['in', session('cart.id')]]) + ->select(); + $whole = 0; + $orderGoods = []; + foreach ($data as $item) { + $whole += $item['num'] * $item['price']; + } + $order = [ - 'order_num' => date('YmdHis').rand(100000, 999999), + 'order_num' => date('YmdHis') . rand(100000, 999999), 'step' => 1, 'uid' => session('user.id'), - 'site' => '收货地址', - 'name' => '收货人姓名', - 'mobile' => '电话', + 'site' => $consignee['province'] . $consignee['city'] . $consignee['county'] . $consignee['place'], + 'name' => $consignee['name'], + 'mobile' => $consignee['mobile'], 'remark' => $request->param('remark'), 'create_time' => time(), - 'whole' => '订单总金额', - 'whole_num' => '订单总积分', + 'whole' => $whole, + 'whole_num' => 0, + 'pay_type' => $request->param('pay_type'), + 'step' => 1 ]; + Db::startTrans(); + if (Db::name('zj_order')->insert($order)) { + $oid = Db::name('zj_order')->getLastInsID(); + foreach ($data as $k => $v) { + $orderGoods[$k] = [ + 'oid' => $oid, + 'gid' => $v['id'], + 'num' => $v['num'] + ]; + } + if (Db::name('zj_order_goods')->insertAll($orderGoods)) { + Db::commit(); + if ($order['pay_type'] == 1) { + $info = [ + 'attach' => $oid, + 'openid' => session('openid'), + 'body' => '微信支付-' . $order['name'], + 'total_fee' => $order['whole'] + ]; + $this->wxPay($info); + } + } + } } } //微信支付 - public function wxPay() + public function wxPay($info) { + require_once EXTEND_PATH . '/Payment.php'; + $pay = new \Payment($info['attach'], $info['openid'], $info['body'], $info['total_fee']); + $this->success('微信支付', '', $pay->pay()); + } + public function notify() { + require_once EXTEND_PATH . '/Payment.php'; + $pay = new \Payment(); + $pay->handleNotify(); } } \ No newline at end of file diff --git a/public/index.php b/public/index.php index c02761e..7b79c6e 100644 --- a/public/index.php +++ b/public/index.php @@ -10,7 +10,7 @@ // [ 入口文件 ] // 调试模式开关 -define("APP_DEBUG", false); +define("APP_DEBUG", true); // 定义CMF根目录,可更改此目录 define('CMF_ROOT', __DIR__ . '/../'); diff --git a/public/themes/simpleboot3/cart/zj_cart/order_confirm.html b/public/themes/simpleboot3/cart/zj_cart/order_confirm.html index aa7d156..46a5dc3 100644 --- a/public/themes/simpleboot3/cart/zj_cart/order_confirm.html +++ b/public/themes/simpleboot3/cart/zj_cart/order_confirm.html @@ -173,18 +173,24 @@ <p class="pay_type">支付方式</p> <div class="pay_line"></div> <div> + <if condition="$caid eq '1'"> <div class="pay_type_list"> <p class="pay_name">微信支付</p> - <p class="iconfont icon-xuanzhong"></p> - </div> - <div class="pay_type_list"> - <p class="pay_name">组合支付(现金金额不少于500)</p> - <p class="iconfont icon-not_Selected-copy"></p> - </div> - <div class="pay_type_list"> - <p class="pay_name">积分(2000积分)</p> - <p class="iconfont icon-not_Selected-copy"></p> + <p class="iconfont pay icon-not_Selected-copy" data-var="1"></p> </div> + </if> + <!--<if condition="$caid eq '2'">--> + <!--<div class="pay_type_list">--> + <!--<p class="pay_name">组合支付(现金金额不少于500)</p>--> + <!--<p class="iconfont pay icon-not_Selected-copy" data-var="2"></p>--> + <!--</div>--> + <!--</if>--> + <!--<if condition="$caid eq '3'">--> + <!--<div class="pay_type_list">--> + <!--<p class="pay_name">积分(2000积分)</p>--> + <!--<p class="iconfont pay icon-not_Selected-copy" data-var="3"></p>--> + <!--</div>--> + <!--</if>--> </div> </div> @@ -199,7 +205,7 @@ <div class="buymessage"> <p class="buysend">买家留言</p> <div class="pay_line"></div> - <textarea name="" id="" cols="30" rows="10" class="message" placeholder="请填写留言"></textarea> + <textarea name="" id="remark" cols="30" rows="10" class="message" placeholder="请填写留言"></textarea> </div> <div class="foot"> <div class="buytotal"> @@ -212,14 +218,36 @@ </body> <script src="__INDEX__/js/jquery.min.js"></script> <script> - $(".iconfont").click(function(){ + var pay_type = ''; + $(".pay").click(function(){ $(this).removeClass("icon-not_Selected-copy"); $(this).addClass("icon-xuanzhong"); $(this).parents(".pay_type_list").siblings(".pay_type_list").children(".iconfont").removeClass("icon-xuanzhong"); $(this).parents(".pay_type_list").siblings(".pay_type_list").children(".iconfont").addClass("icon-not_Selected-copy"); + pay_type = $(this).attr('data-var'); + }) $(".payorder").click(function(){ - $(".wrapper").css("display","block") + //$(".wrapper").css("display","block") + if(pay_type == '') { + return false; + } + $.ajax({ + url:"{:url('pay/Pay/done')}", + data:{ + pay_type:pay_type, + address_id:address_id, + remark:$("#remark").val() + }, + type:"POST", + dataType:"JSON", + + success: function (data) { + if(data.data === true) { + console.log(data.msg); + } + } + }) }) //确认支付 @@ -234,7 +262,7 @@ $(".people_info").click(function(){ $(".addresswrapper").css("display","block") }) - var address_id = ''; + var address_id = '{$default_address_id}'; $(".xuan").click(function(){ $(".addresswrapper").css("display","none") $(this).css("display","none");