为了方便我们所有的逻辑您都按照我下面的走,然后就会都走余额的控制,这样在一个地方写就可以了,然后如果不懂的可以加我微信或手机咨询17854945210 >自提不会走一下逻辑 [TOC] ## 小程序订单微信支付逻辑 ``/ewei_shopv2/payment/wechat/notify.php`` ``` /** * 小程序 订单支付 */ public function wxapp_order() { $tid = $this->get['out_trade_no']; $transaction_id = $this->get['transaction_id']; if (strexists($tid, 'GJ')) { $tids = explode('GJ', $tid); $tid = $tids[0]; } $sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `module`=:module AND `tid`=:tid limit 1'; $params = array(); $params[':tid'] = $tid; $params[':module'] = 'ewei_shopv2'; $log = pdo_fetch($sql, $params); if (!empty($log) && $log['status'] == '0' && $log['fee'] == $this->total_fee) { $site = WeUtility::createModuleSite($log['module']); if (!is_error($site)) { $method = 'payResult'; if (method_exists($site, $method)) { $ret = array(); $ret['acid'] = $log['acid']; $ret['uniacid'] = $log['uniacid']; $ret['result'] = 'success'; $ret['type'] = $log['type']; $ret['from'] = 'return'; $ret['tid'] = $log['tid']; $ret['user'] = $log['openid']; $ret['fee'] = $log['fee']; $ret['tag'] = $log['tag']; pdo_update('ewei_shop_order', array('paytype' => 21, 'apppay' => 2, 'transid' => $transaction_id), array('ordersn' => $log['tid'], 'uniacid' => $log['uniacid'])); $result = $site->{$method}($ret); if ($result) { //----------------------------------------------------------------------------------------订单成功逻辑 // $log['tag'] = iunserializer($log['tag']); $log['tag']['transaction_id'] = $this->get['transaction_id']; $record = array(); $record['status'] = '1'; $record['tag'] = iserializer($log['tag']); pdo_update('core_paylog', $record, array('plid' => $log['plid'])); } } } } else { $this->fail(); } } ``` ## 余额支付成功走的控制器 路径 ``/addons/ewei_shopv2/core/model/order.php`` ``` public function payResult($params) ``` ## 支付宝支付成功走的逻辑 /addons/ewei_shopv2/payment/alipay/notify.php 在这个位置,然后走payResult的余额逻辑,所有逻辑写在payResult即可 ``` ![](https://img.kancloud.cn/d4/da/d4dacd379001929818b8af832bf81656_773x308.png) /** * 订单支付 */ public function order() { if (!$this->publicMethod()) { exit('order'); } $tid = $this->post['out_trade_no']; if (strexists($tid, 'GJ')) { $tids = explode('GJ', $tid); $tid = $tids[0]; } $sql = 'SELECT * FROM ' . tablename('core_paylog') . ' WHERE `tid`=:tid and `module`=:module limit 1'; $params = array(); $params[':tid'] = $tid; $params[':module'] = 'ewei_shopv2'; $log = pdo_fetch($sql, $params); if (!$this->isapp && $this->post['sign_type'] == 'RSA') { if ($this->post['total_amount'] != $log['fee']) { exit('fail'); } } else { $total_fee = $this->post['total_fee']; if (empty($total_fee)) { $total_fee = $this->post['total_amount']; } if ($total_fee != $log['fee']) { exit('fail'); } } if (!empty($log) && $log['status'] == '0') { $site = WeUtility::createModuleSite($log['module']); if (!is_error($site)) { $method = 'payResult'; if (method_exists($site, $method)) { $ret = array(); $ret['acid'] = $log['acid']; $ret['uniacid'] = $log['uniacid']; $ret['result'] = 'success'; $ret['type'] = 'alipay'; $ret['from'] = 'return'; $ret['tid'] = $log['tid']; $ret['user'] = $log['openid']; $ret['fee'] = $log['fee']; $ret['is_usecard'] = $log['is_usecard']; $ret['card_type'] = $log['card_type']; $ret['card_fee'] = $log['card_fee']; $ret['card_id'] = $log['card_id']; pdo_update('ewei_shop_order', array('paytype' => 22), array('uniacid' => $log['uniacid'], 'ordersn' => $log['tid'])); $result = $site->{$method}($ret); if ($result) { $log['tag'] = iunserializer($log['tag']); $log['tag']['transid'] = $this->post['trade_no']; $record = array(); $record['status'] = '1'; $record['type'] = 'alipay'; $record['tag'] = iserializer($log['tag']); --------------------------------------------------------- 把这行代码加进去 //这里写逻辑 $pay_result = m('order')->payResult($ret); --------------------------------------------------------------- pdo_update('core_paylog', $record, array('plid' => $log['plid'])); pdo_update('ewei_shop_order', array('paytype' => 22, 'apppay' => $this->isapp ? 1 : 0, 'transid' => $this->post['trade_no']), array('ordersn' => $log['tid'], 'uniacid' => $log['uniacid'])); exit('success'); } } } } } ``` ## 微信支付成功后走的逻辑 700来行 /www/wwwroot/www.doujiao.su/addons/ewei_shopv2/core/mobile/order/pay.php ``` if ($go_flag == 1) { $pay_result = true; ----------------------------------------------- 把这行代码加进去 $log = pdo_fetch('SELECT * FROM ' . tablename('core_paylog') . ' WHERE `uniacid`=:uniacid AND `module`=:module AND `tid`=:tid limit 1', array(':uniacid' => $uniacid, ':module' => 'ewei_shopv2', ':tid' => $order['ordersn'])); $ret = array(); $ret['result'] = 'success'; $ret['type'] = 'wechat'; $ret['from'] = 'return'; $ret['tid'] = $log['tid']; $ret['user'] = $order['openid']; $ret['fee'] = $order['price']; $ret['weid'] = $_W['uniacid']; $ret['uniacid'] = $_W['uniacid']; $pay_result = m('order')->payResult($ret); ------------------------------------------------------------------------- if ($_W['ispost']) { $_SESSION[EWEI_SHOPV2_PREFIX . '_order_pay_complete'] = 1; show_json(1, array('result' => $pay_result)); } else { header('location:' . mobileUrl('order/pay/success', array('id' => $order['id'], 'result' => $pay_result))); exit(); } } ``` ## APP微信支付成功后走的逻辑 **ewei_shopv2/core/mobile/account/app_pay.php** orderstatus方法里,最后几行,47行左右 ``` else { //$orderid = intval($_GPC["globe_orderid_"]); //$app_paytype= intval($_GPC["app_paytype"]); $ordersn = $_GPC["ordersn"]; $tradeno = $_GPC["tradeno"]; $log = pdo_fetch('SELECT * FROM ' . tablename('core_paylog') . ' WHERE `uniacid`=:uniacid AND `module`=:module AND `tid`=:tid limit 1', array(':uniacid' => $uniacid, ':module' => 'ewei_shopv2', ':tid' => $order['ordersn'])); $ret = array(); $ret['result'] = 'success'; $ret['type'] = 'wechat'; $ret['from'] = 'return'; $ret['tid'] = $log['tid']; $ret['user'] = $order['openid']; $ret['fee'] = $order['price']; $ret['weid'] = $_W['uniacid']; $ret['uniacid'] = $_W['uniacid']; $pay_result = m('order')->payResult($ret); $result=pdo_update("ewei_shop_order", array( "status" =>1,"paytime"=>time(),"paytype" =>$paytype ), array( "ordersn" => $ordersn, "uniacid" => $_W["uniacid"] )); echo json_encode($result) ; ```