作者 chencheng

5

@@ -9,7 +9,7 @@ use think\Config; @@ -9,7 +9,7 @@ use think\Config;
9 use think\Db; 9 use think\Db;
10 use think\Response; 10 use think\Response;
11 use think\Validate; 11 use think\Validate;
12 - 12 +use app\api\controller\Common;
13 /** 13 /**
14 * 首页公共 14 * 首页公共
15 */ 15 */
@@ -289,7 +289,7 @@ class Wechat extends Api @@ -289,7 +289,7 @@ class Wechat extends Api
289 $user_id = $this->auth->id; 289 $user_id = $this->auth->id;
290 290
291 if(empty($user_id)){ 291 if(empty($user_id)){
292 - return $this->error('用户信息错误'); 292 + return $this->error('预下单的用户信息错误');
293 } 293 }
294 $userInfo = Db::name('user')->where(['id'=>$user_id])->find(); 294 $userInfo = Db::name('user')->where(['id'=>$user_id])->find();
295 295
@@ -322,15 +322,15 @@ class Wechat extends Api @@ -322,15 +322,15 @@ class Wechat extends Api
322 $app = WehcatModule::getInstance()->initWechatPay(); 322 $app = WehcatModule::getInstance()->initWechatPay();
323 $response = $app->handlePaidNotify(function($message, $fail){ 323 $response = $app->handlePaidNotify(function($message, $fail){
324 // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单 324 // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
325 - file_put_contents("1_cc.log",json_encode($message),FILE_APPEND);  
326 - $order = $message['out_trade_no']; 325 + Common::put_file_log('支付成功-微信支付回调信息',json_encode($message), 'pay_notify', __CLASS__ . __FUNCTION__ . __LINE__);
  326 + $out_trade_no = $message['out_trade_no'];
327 if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') { 327 if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') {
328 - 328 + $o_w["order_no"] = $out_trade_no;
  329 + $order_info = Db::name('verification_order')->where($o_w)->find();
  330 + $this->sales_distribution($order_info);
329 } else { 331 } else {
330 - return $fail('通信失败,请稍后再通知我'); 332 + Common::put_file_log('支付失败-微信支付回调信息',json_encode($message), 'pay_notify', __CLASS__ . __FUNCTION__ . __LINE__);
331 } 333 }
332 -  
333 -  
334 return true; // 返回处理完成 334 return true; // 返回处理完成
335 }); 335 });
336 $response->send(); // return $response; 336 $response->send(); // return $response;
@@ -412,15 +412,24 @@ class Wechat extends Api @@ -412,15 +412,24 @@ class Wechat extends Api
412 } 412 }
413 // 发放佣金 413 // 发放佣金
414 public function grant_commission($pid=0,$order_id=0){ 414 public function grant_commission($pid=0,$order_id=0){
415 - $app = WehcatModule::getInstance()->initWechatPay();  
416 - $result = $app->transfer->toBalance([  
417 - 'partner_trade_no' => '168532907259455', // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)  
418 - 'openid' => 'o5OQw6PPEGaHqIjAir7gqeDV5MzQ',  
419 - 'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名  
420 - 're_user_name' => '陈程', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名  
421 - 'amount' => 1, // 企业付款金额,单位为分  
422 - 'desc' => '理赔', // 企业付款操作说明信息。必填  
423 - ]);  
424 - dump($result); 415 + try{
  416 + $verification_order = Db::name('verification_order')->where(['id'=>$order_id])->find();
  417 + $app = WehcatModule::getInstance()->initWechatPay();
  418 + $result = $app->transfer->toBalance([
  419 + 'partner_trade_no' => '168532907259455', // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
  420 + 'openid' => 'o5OQw6PPEGaHqIjAir7gqeDV5MzQ',
  421 + 'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
  422 + 're_user_name' => '陈程', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
  423 + 'amount' => 1, // 企业付款金额,单位为分
  424 + 'desc' => '理赔', // 企业付款操作说明信息。必填
  425 + ]);
  426 + if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
  427 + //记录佣金表
  428 + }else{
  429 + Common::put_file_log('失败-佣金发放',json_encode($result), 'grant_commission', __CLASS__ . __FUNCTION__ . __LINE__);
  430 + }
  431 + }catch(\Exception $e){
  432 + Common::put_file_log('异常-佣金发放',json_encode($result), 'grant_commission', __CLASS__ . __FUNCTION__ . __LINE__);
  433 + }
425 } 434 }
426 } 435 }