|
|
<?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 |
...
|
...
|
|