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