1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace app\api\controller\h5;
- use app\hander\HelpHander;
- use EasyWeChat\Factory;
- use think\Controller;
- use think\Db;
- use think\Exception;
- class Notify extends Controller
- {
- public function phorder(){
- $config = config('app.wx_config');
- $app = Factory::payment($config);
- $response = $app->handlePaidNotify(function ($message, $fail) {
- if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') {
-
- $tradeNo = $message['out_trade_no'];
-
- $order = Db::name('ph_order_pay')->where('sn',$tradeNo)->find();
- if (!$order || $order['status'] != 0) {
- return true;
- }
- $ret = model('PhOrderPay')->paySuccess($order['id'],2);
- if(!$ret){
- trace('订单修改失败');
- $fail('订单修改失败');
- }
- } else {
- return $fail('通信失败,请稍后再通知我');
- }
- return true;
- });
- $response->send();
- }
- public function xshopOrder(){
- $config = config('app.wx_config');
- $app = Factory::payment($config);
- $response = $app->handlePaidNotify(function ($message, $fail) {
- if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') {
-
- $tradeNo = $message['out_trade_no'];
-
- $order = Db::name('g_orders')->where('order_sn',$tradeNo)->find();
- if (!$order || $order['status'] != 0) {
- return true;
- }
- $ret = Db::name('g_orders')->where('id',$order['id'])->update(['status'=>1,'pay_time'=>date('Y-m-d H:i:s')]);
- $goods = Db::name('g_order_goods')->where('order_id',$order['id'])->select();
-
- foreach ($goods as $k=>$v){
- Db::name('g_goods')
- ->where('id',$v['id'])
- ->inc('sale',$v['nums'])
- ->update();
- }
- if(!$ret){
- trace('订单修改失败');
- $fail('订单修改失败');
- }
- } else {
- return $fail('通信失败,请稍后再通知我');
- }
- return true;
- });
- $response->send();
- }
- }
|