正在显示
1 个修改的文件
包含
43 行增加
和
10 行删除
| @@ -372,12 +372,11 @@ class Wechat extends Api | @@ -372,12 +372,11 @@ class Wechat extends Api | ||
| 372 | 372 | ||
| 373 | public function sales_distribution($order_info=[]){ | 373 | public function sales_distribution($order_info=[]){ |
| 374 | //测试 | 374 | //测试 |
| 375 | - $order_info = Db::name('verification_order')->where("id='14'")->find(); | 375 | + //$order_info = Db::name('verification_order')->where("id='14'")->find(); |
| 376 | 376 | ||
| 377 | if(empty($order_info)){ return $this->error('订单信息不存在');} | 377 | if(empty($order_info)){ return $this->error('订单信息不存在');} |
| 378 | $w['id'] = $order_info['user_id']; | 378 | $w['id'] = $order_info['user_id']; |
| 379 | $myInfo = Db::name('user')->where($w)->find(); | 379 | $myInfo = Db::name('user')->where($w)->find(); |
| 380 | - | ||
| 381 | //是否与上级 | 380 | //是否与上级 |
| 382 | if(!empty($myInfo['pid'])){ | 381 | if(!empty($myInfo['pid'])){ |
| 383 | //上级 | 382 | //上级 |
| @@ -385,20 +384,17 @@ class Wechat extends Api | @@ -385,20 +384,17 @@ class Wechat extends Api | ||
| 385 | $this->getParent($myInfo['pid'],$order_info['verification_store_id'],$order_info['id']); | 384 | $this->getParent($myInfo['pid'],$order_info['verification_store_id'],$order_info['id']); |
| 386 | }catch(\Exception $e){ | 385 | }catch(\Exception $e){ |
| 387 | Common::put_file_log('上级-分销异常',json_encode($e->getMessage()), 'sales_distribution', __CLASS__ . __FUNCTION__ . __LINE__); | 386 | Common::put_file_log('上级-分销异常',json_encode($e->getMessage()), 'sales_distribution', __CLASS__ . __FUNCTION__ . __LINE__); |
| 388 | - } | ||
| 389 | - die; | 387 | + }die; |
| 390 | //上级的上级 | 388 | //上级的上级 |
| 391 | try{ | 389 | try{ |
| 392 | $w1['id'] = $myInfo['pid']; | 390 | $w1['id'] = $myInfo['pid']; |
| 393 | $myInfoP = Db::name('user')->where($w1)->find(); | 391 | $myInfoP = Db::name('user')->where($w1)->find(); |
| 394 | if(!empty($myInfoP['pid'])){ | 392 | if(!empty($myInfoP['pid'])){ |
| 395 | - $this->getParent($myInfoP['id'],$order_info['verification_store_id'],$order_info['id']); | 393 | + $this->getParent($myInfoP['pid'],$order_info['verification_store_id'],$order_info['id']); |
| 396 | } | 394 | } |
| 397 | }catch(\Exception $e){ | 395 | }catch(\Exception $e){ |
| 398 | Common::put_file_log('上级的上级-分销异常',json_encode($e->getMessage()), 'sales_distribution', __CLASS__ . __FUNCTION__ . __LINE__); | 396 | Common::put_file_log('上级的上级-分销异常',json_encode($e->getMessage()), 'sales_distribution', __CLASS__ . __FUNCTION__ . __LINE__); |
| 399 | } | 397 | } |
| 400 | - | ||
| 401 | - | ||
| 402 | } | 398 | } |
| 403 | } | 399 | } |
| 404 | 400 | ||
| @@ -408,11 +404,11 @@ class Wechat extends Api | @@ -408,11 +404,11 @@ class Wechat extends Api | ||
| 408 | $time = time(); | 404 | $time = time(); |
| 409 | $w1 = []; | 405 | $w1 = []; |
| 410 | $w1['user_id'] = $pid; | 406 | $w1['user_id'] = $pid; |
| 411 | - $w1['verification_store_id'] = $verification_store_id; | 407 | + // $w1['verification_store_id'] = $verification_store_id; |
| 412 | $role = Db::name('verification_staff')->where($w1)->find(); | 408 | $role = Db::name('verification_staff')->where($w1)->find(); |
| 413 | if(in_array($role['type'],['1','3'])){ | 409 | if(in_array($role['type'],['1','3'])){ |
| 414 | //属于代理 企业付款到佣金 | 410 | //属于代理 企业付款到佣金 |
| 415 | - //$this->grant_commission($pid,$order_id); | 411 | + $this->grant_commission($pid,$order_id); |
| 416 | }else{ | 412 | }else{ |
| 417 | //属于普通用户 发送代金券 | 413 | //属于普通用户 发送代金券 |
| 418 | $this->send_voucher($pid,$verification_store_id,$order_id,$time); | 414 | $this->send_voucher($pid,$verification_store_id,$order_id,$time); |
| @@ -450,7 +446,12 @@ class Wechat extends Api | @@ -450,7 +446,12 @@ class Wechat extends Api | ||
| 450 | // 发放佣金 企业付款到零钱 | 446 | // 发放佣金 企业付款到零钱 |
| 451 | public function grant_commission($pid=0,$order_id=0){ | 447 | public function grant_commission($pid=0,$order_id=0){ |
| 452 | try{ | 448 | try{ |
| 449 | + $send_result = 0; | ||
| 453 | $verification_order = Db::name('verification_order')->where(['id'=>$order_id])->find(); | 450 | $verification_order = Db::name('verification_order')->where(['id'=>$order_id])->find(); |
| 451 | + $verification_store = Db::name('verification_store')->where(['id'=>$verification_order['verification_store_id']])->find(); | ||
| 452 | + $user_info = Db::name('user')->where(['id'=>$pid])->find(); | ||
| 453 | + | ||
| 454 | + if(!empty($verification_store['commission'])){ | ||
| 454 | $app = WehcatModule::getInstance()->initWechatPay(); | 455 | $app = WehcatModule::getInstance()->initWechatPay(); |
| 455 | $result = $app->transfer->toBalance([ | 456 | $result = $app->transfer->toBalance([ |
| 456 | 'partner_trade_no' => '168532907259455', // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号) | 457 | 'partner_trade_no' => '168532907259455', // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号) |
| @@ -458,14 +459,20 @@ class Wechat extends Api | @@ -458,14 +459,20 @@ class Wechat extends Api | ||
| 458 | 'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名 | 459 | 'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名 |
| 459 | 're_user_name' => '陈程', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名 | 460 | 're_user_name' => '陈程', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名 |
| 460 | 'amount' => 1, // 企业付款金额,单位为分 | 461 | 'amount' => 1, // 企业付款金额,单位为分 |
| 461 | - 'desc' => '理赔', // 企业付款操作说明信息。必填 | 462 | + 'desc' => '分销佣金', // 企业付款操作说明信息。必填 |
| 462 | ]); | 463 | ]); |
| 463 | if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ | 464 | if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){ |
| 464 | //记录佣金表 后台没有配置 | 465 | //记录佣金表 后台没有配置 |
| 466 | + $send_result = 1; | ||
| 465 | 467 | ||
| 466 | }else{ | 468 | }else{ |
| 467 | Common::put_file_log('失败-佣金发放',json_encode($result), 'grant_commission', __CLASS__ . __FUNCTION__ . __LINE__); | 469 | Common::put_file_log('失败-佣金发放',json_encode($result), 'grant_commission', __CLASS__ . __FUNCTION__ . __LINE__); |
| 468 | } | 470 | } |
| 471 | + }else{ | ||
| 472 | + | ||
| 473 | + } | ||
| 474 | + | ||
| 475 | + $this->brokerage_record($verification_store,$user_info,$send_result,$verification_order); | ||
| 469 | }catch(\Exception $e){ | 476 | }catch(\Exception $e){ |
| 470 | Common::put_file_log('异常-佣金发放',json_encode($result), 'grant_commission', __CLASS__ . __FUNCTION__ . __LINE__); | 477 | Common::put_file_log('异常-佣金发放',json_encode($result), 'grant_commission', __CLASS__ . __FUNCTION__ . __LINE__); |
| 471 | } | 478 | } |
| @@ -500,4 +507,30 @@ class Wechat extends Api | @@ -500,4 +507,30 @@ class Wechat extends Api | ||
| 500 | Common::put_file_log('异常-红包发放',json_encode($result), 'grant_red_packets', __CLASS__ . __FUNCTION__ . __LINE__); | 507 | Common::put_file_log('异常-红包发放',json_encode($result), 'grant_red_packets', __CLASS__ . __FUNCTION__ . __LINE__); |
| 501 | } | 508 | } |
| 502 | } | 509 | } |
| 510 | + | ||
| 511 | + //佣金发放记录 | ||
| 512 | + private function brokerage_record($verification_store,$user_info,$send_result,$verification_order){ | ||
| 513 | + //关于该笔订单是否有发送给这个人 | ||
| 514 | + $w_re = []; | ||
| 515 | + $w_re['order_id'] = $verification_order['id']; | ||
| 516 | + $w_re['send_user_id'] = $user_info['id']; | ||
| 517 | + $r = Db::name('verification_brokerage_record')->where($w_re)->find(); | ||
| 518 | + if(!empty($r)){ | ||
| 519 | + return false; | ||
| 520 | + } | ||
| 521 | + try{ | ||
| 522 | + $record = []; | ||
| 523 | + $record['verification_store_id'] = $verification_store['id']; | ||
| 524 | + $record['commission'] = $verification_store['commission']; | ||
| 525 | + $record['send_user_id'] = $user_info['id']; | ||
| 526 | + $record['send_createtime'] = time(); | ||
| 527 | + $record['send_result'] = $send_result; | ||
| 528 | + $record['send_reason'] = 'ID:'.$user_info['id'].'分享给ID:'.$verification_order['user_id'].',并且成功支付ID:'.$verification_order['id']; | ||
| 529 | + $record['order_id'] = $verification_order['id']; | ||
| 530 | + Db::name('verification_brokerage_record')->insert($record); | ||
| 531 | + }catch(\Exception $e){ | ||
| 532 | + Common::put_file_log('佣金记录失败',$e->getMessage(), 'brokerage_record', __CLASS__ . __FUNCTION__ . __LINE__); | ||
| 533 | + } | ||
| 534 | + | ||
| 535 | + } | ||
| 503 | } | 536 | } |
-
请 注册 或 登录 后发表评论