作者 chencheng

0531-14

@@ -222,7 +222,8 @@ class Client extends Base @@ -222,7 +222,8 @@ class Client extends Base
222 $order_no=$time.rand(10000,99999); 222 $order_no=$time.rand(10000,99999);
223 $verification_store_id=$this->store_id; 223 $verification_store_id=$this->store_id;
224 $user_id=$this->auth->id; 224 $user_id=$this->auth->id;
225 - 225 + //测试
  226 + $user_id = 4;
226 $createtime=$time; 227 $createtime=$time;
227 $type=0; 228 $type=0;
228 //整理数组 229 //整理数组
@@ -292,6 +292,7 @@ class Wechat extends Api @@ -292,6 +292,7 @@ class Wechat extends Api
292 return $this->error('预下单信息错误'); 292 return $this->error('预下单信息错误');
293 } 293 }
294 $my_user_id = $this->auth->id; 294 $my_user_id = $this->auth->id;
  295 +
295 if(empty($my_user_id)){return $this->error('用户信息错误');} 296 if(empty($my_user_id)){return $this->error('用户信息错误');}
296 $o_w["order_no"] = $order_no; 297 $o_w["order_no"] = $order_no;
297 $order_info = Db::name('verification_order')->where($o_w)->find(); 298 $order_info = Db::name('verification_order')->where($o_w)->find();
@@ -300,7 +301,7 @@ class Wechat extends Api @@ -300,7 +301,7 @@ class Wechat extends Api
300 $out_trade_no = $order_no; 301 $out_trade_no = $order_no;
301 $o_w["order_no"] = $out_trade_no; 302 $o_w["order_no"] = $out_trade_no;
302 $order_info = Db::name('verification_order')->where($o_w)->find(); 303 $order_info = Db::name('verification_order')->where($o_w)->find();
303 - $total_fee = $order_info['price'] = mt_rand(1,10);//测试支付1分钱 304 + $total_fee = $order_info['price'] = mt_rand(100,120);//测试支付1分钱
304 $app = WehcatModule::getInstance()->initWechatPay(); 305 $app = WehcatModule::getInstance()->initWechatPay();
305 $result = $app->order->unify([ 306 $result = $app->order->unify([
306 'body' => '优惠券购买', 307 'body' => '优惠券购买',
@@ -325,35 +326,35 @@ class Wechat extends Api @@ -325,35 +326,35 @@ class Wechat extends Api
325 326
326 /* 327 /*
327 微信支付回调信息 328 微信支付回调信息
  329 + {"appid":"wx1c3cc5b4e2006be2","bank_type":"OTHERS","cash_fee":"10","fee_type":"CNY","is_subscribe":"Y","mch_id":"1609190540","nonce_str":"6477162663358","openid":"o5OQw6LSZr1gGhXWeYutDwjsu7UY","out_trade_no":"168552605462002","result_code":"SUCCESS","return_code":"SUCCESS","sign":"B3148E770FAEC4F6B6B0B40718D314DA","time_end":"20230531174105","total_fee":"10","trade_type":"JSAPI","transaction_id":"4200001852202305311195060106"}
328 */ 330 */
329 public function notify(){ 331 public function notify(){
330 $app = WehcatModule::getInstance()->initWechatPay(); 332 $app = WehcatModule::getInstance()->initWechatPay();
331 $xml = file_get_contents("php://input"); 333 $xml = file_get_contents("php://input");
332 - file_put_contents('2_notify.log',($xml),FILE_APPEND); 334 +
333 $xmljson= json_encode(simplexml_load_string($xml, 'SimplexmlElement', LIBXML_NOCDATA ));//将对象转换个JSON 335 $xmljson= json_encode(simplexml_load_string($xml, 'SimplexmlElement', LIBXML_NOCDATA ));//将对象转换个JSON
334 file_put_contents('1_notify.log',($xmljson),FILE_APPEND); 336 file_put_contents('1_notify.log',($xmljson),FILE_APPEND);
335 - $response = $app->handlePaidNotify(function($message, $fail){  
336 - // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单  
337 - Common::put_file_log('支付成功-微信支付回调信息',json_encode($message), 'pay_notify', __CLASS__ . __FUNCTION__ . __LINE__);  
338 - $out_trade_no = $message['out_trade_no'];  
339 - if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') {  
340 - $o_w["order_no"] = $out_trade_no;  
341 - $order_info = Db::name('verification_order')->where($o_w)->find();  
342 - if($order_info['type'] != 2){  
343 - //1. 更改状态信息  
344 - $up['type'] = 2;  
345 - $up['paytime'] = time();  
346 - $up['payMode'] = '0';  
347 - Db::name('verification_order')->where($o_w)->update($up);  
348 - //2. 分销处理  
349 - $this->sales_distribution($order_info);  
350 - }  
351 - } else {  
352 - Common::put_file_log('支付失败-微信支付回调信息',json_encode($message), 'pay_notify', __CLASS__ . __FUNCTION__ . __LINE__); 337 + $message = json_decode($xmljson,true);
  338 + // 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
  339 + Common::put_file_log('支付成功-微信支付回调信息',json_encode($message), 'pay_notify', __CLASS__ . __FUNCTION__ . __LINE__);
  340 + $out_trade_no = $message['out_trade_no'];
  341 + if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') {
  342 + $o_w["order_no"] = $out_trade_no;
  343 + $order_info = Db::name('verification_order')->where($o_w)->find();
  344 + if($order_info['type'] != 1){
  345 + //1. 更改状态信息
  346 + $up['type'] = 1;
  347 + $up['paytime'] = time();
  348 + $up['payMode'] = '0';
  349 + Db::name('verification_order')->where($o_w)->update($up);
  350 + //2. 分销处理
  351 + $this->sales_distribution($order_info);
353 } 352 }
354 - return true; // 返回处理完成  
355 - });  
356 - $response->send(); // return $response; 353 + } else {
  354 +
  355 + }
  356 + return true; // 返回处理完成
  357 +
357 /* 358 /*
358 $xml = file_get_contents("php://input"); 359 $xml = file_get_contents("php://input");
359 $xmljson= json_encode(simplexml_load_string($xml, 'SimplexmlElement', LIBxml_NOCDATA));//将对象转换个JSON 360 $xmljson= json_encode(simplexml_load_string($xml, 'SimplexmlElement', LIBxml_NOCDATA));//将对象转换个JSON
@@ -387,7 +388,7 @@ class Wechat extends Api @@ -387,7 +388,7 @@ class Wechat extends Api
387 $this->getParent($myInfo['pid'],$order_info['verification_coupon_ids'],$order_info['id']); 388 $this->getParent($myInfo['pid'],$order_info['verification_coupon_ids'],$order_info['id']);
388 }catch(\Exception $e){ 389 }catch(\Exception $e){
389 Common::put_file_log('上级-分销异常',json_encode($e->getMessage()), 'sales_distribution', __CLASS__ . __FUNCTION__ . __LINE__); 390 Common::put_file_log('上级-分销异常',json_encode($e->getMessage()), 'sales_distribution', __CLASS__ . __FUNCTION__ . __LINE__);
390 - }die; 391 + }
391 //上级的上级 392 //上级的上级
392 try{ 393 try{
393 $w1['id'] = $myInfo['pid']; 394 $w1['id'] = $myInfo['pid'];
@@ -411,8 +412,8 @@ class Wechat extends Api @@ -411,8 +412,8 @@ class Wechat extends Api
411 // $w1['verification_store_id'] = $verification_store_id; 412 // $w1['verification_store_id'] = $verification_store_id;
412 $role = Db::name('verification_staff')->where($w1)->find(); 413 $role = Db::name('verification_staff')->where($w1)->find();
413 if(in_array($role['type'],['1','3'])){ 414 if(in_array($role['type'],['1','3'])){
414 - //属于代理 企业付款到佣金  
415 - $this->grant_commission($pid,$order_id); 415 + //属于代理 发送红包
  416 + $this->grant_red_packets($pid,$order_id);
416 }else{ 417 }else{
417 //属于普通用户 发送代金券 418 //属于普通用户 发送代金券
418 $this->send_voucher($pid,$verification_coupon_ids,$order_id,$time); 419 $this->send_voucher($pid,$verification_coupon_ids,$order_id,$time);
@@ -467,8 +468,7 @@ class Wechat extends Api @@ -467,8 +468,7 @@ class Wechat extends Api
467 'amount' => 1, // 企业付款金额,单位为分 468 'amount' => 1, // 企业付款金额,单位为分
468 'desc' => '分销佣金', // 企业付款操作说明信息。必填 469 'desc' => '分销佣金', // 企业付款操作说明信息。必填
469 ]); 470 ]);
470 - return json($result);  
471 - die; 471 +
472 if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ 472 if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
473 //记录佣金表 后台没有配置 473 //记录佣金表 后台没有配置
474 $send_result = 1; 474 $send_result = 1;
@@ -491,28 +491,31 @@ class Wechat extends Api @@ -491,28 +491,31 @@ class Wechat extends Api
491 public function grant_red_packets($pid=0,$order_id=0){ 491 public function grant_red_packets($pid=0,$order_id=0){
492 try{ 492 try{
493 //测试 https://coupon.xp.yn.cn/api/v1/wechat/grant_red_packets 493 //测试 https://coupon.xp.yn.cn/api/v1/wechat/grant_red_packets
494 - $order_id = 14; 494 + //$order_id = 14;
  495 +
  496 + $send_result = 0;
495 $verification_order = Db::name('verification_order')->where(['id'=>$order_id])->find(); 497 $verification_order = Db::name('verification_order')->where(['id'=>$order_id])->find();
  498 + $verification_store = Db::name('verification_store')->where(['id'=>$verification_order['verification_store_id']])->find();
  499 + $user_info = Db::name('user')->where(['id'=>$pid])->find();
  500 + $total_amount = $verification_store['commission'] = 100;
496 $app = WehcatModule::getInstance()->initWechatPay(); 501 $app = WehcatModule::getInstance()->initWechatPay();
497 $result = $app->redpack->sendNormal([ 502 $result = $app->redpack->sendNormal([
498 -  
499 - 'mch_billno' => '168532907259455',  
500 - 'send_name' => '测试红包',  
501 - 're_openid' => 'o5OQw6PPEGaHqIjAir7gqeDV5MzQ', 503 + 'mch_billno' => $verification_order['order_no'],
  504 + 'send_name' => '佣金红包',
  505 + 're_openid' => $user_info['openid'],
502 'total_num' => 1, //固定为1,可不传 506 'total_num' => 1, //固定为1,可不传
503 - 'total_amount' => 100, //单位为分,不小于100 507 + 'total_amount' => $total_amount, //单位为分,不小于100
504 'wishing' => '祝福语', 508 'wishing' => '祝福语',
505 -  
506 - 'act_name' => '测试活动',  
507 - 'remark' => '测试备注', 509 + 'act_name' => '佣金分享红包到账',
  510 + 'remark' => '感谢您的参与',
508 ]); 511 ]);
509 - return json($result);  
510 - die; 512 +
511 if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ 513 if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
512 - //记录佣金表  
513 - }else{  
514 - Common::put_file_log('失败-红包发放',json_encode($result), 'grant_red_packets', __CLASS__ . __FUNCTION__ . __LINE__); 514 + //记录佣金表 verification_brokerage_record
  515 + $send_result = 1;
515 } 516 }
  517 + Common::put_file_log('红包发放',json_encode($result), 'grant_red_packets', __CLASS__ . __FUNCTION__ . __LINE__);
  518 + $this->brokerage_record($verification_store,$user_info,$send_result,$verification_order);
516 }catch(\Exception $e){ 519 }catch(\Exception $e){
517 Common::put_file_log('异常-红包发放',json_encode($result), 'grant_red_packets', __CLASS__ . __FUNCTION__ . __LINE__); 520 Common::put_file_log('异常-红包发放',json_encode($result), 'grant_red_packets', __CLASS__ . __FUNCTION__ . __LINE__);
518 } 521 }
@@ -521,13 +524,13 @@ class Wechat extends Api @@ -521,13 +524,13 @@ class Wechat extends Api
521 //佣金发放记录 524 //佣金发放记录
522 private function brokerage_record($verification_store,$user_info,$send_result,$verification_order){ 525 private function brokerage_record($verification_store,$user_info,$send_result,$verification_order){
523 //关于该笔订单是否有发送给这个人 526 //关于该笔订单是否有发送给这个人
524 - $w_re = [];  
525 - $w_re['order_id'] = $verification_order['id'];  
526 - $w_re['send_user_id'] = $user_info['id'];  
527 - $r = Db::name('verification_brokerage_record')->where($w_re)->find();  
528 - if(!empty($r)){  
529 - return false;  
530 - } 527 + // $w_re = [];
  528 + // $w_re['order_id'] = $verification_order['id'];
  529 + // $w_re['send_user_id'] = $user_info['id'];
  530 + // $r = Db::name('verification_brokerage_record')->where($w_re)->find();
  531 + // if(!empty($r)){
  532 + // return false;
  533 + // }
531 try{ 534 try{
532 $record = []; 535 $record = [];
533 $record['verification_store_id'] = $verification_store['id']; 536 $record['verification_store_id'] = $verification_store['id'];