作者 郭文星
... ... @@ -222,7 +222,6 @@ class Wechat extends Api
return $this->error('请求错误');
}
$my_user_id = $this->auth->id;
$my_user_id = 2;
if(empty($my_user_id)){return $this->error('用户信息错误');}
if(empty($param['store_id'])){return $this->error('门店信息错误');}
//记录门店浏览统计
... ... @@ -291,6 +290,8 @@ class Wechat extends Api
if(empty($order_no)){
return $this->error('预下单信息错误');
}
$my_user_id = $this->auth->id;
if(empty($my_user_id)){return $this->error('用户信息错误');}
$o_w["order_no"] = $order_no;
$order_info = Db::name('verification_order')->where($o_w)->find();
$user_id = $order_info['user_id'];
... ... @@ -372,12 +373,11 @@ class Wechat extends Api
public function sales_distribution($order_info=[]){
//测试
$order_info = Db::name('verification_order')->where("id='14'")->find();
//$order_info = Db::name('verification_order')->where("id='14'")->find();
if(empty($order_info)){ return $this->error('订单信息不存在');}
$w['id'] = $order_info['user_id'];
$myInfo = Db::name('user')->where($w)->find();
//是否与上级
if(!empty($myInfo['pid'])){
//上级
... ... @@ -385,20 +385,17 @@ class Wechat extends Api
$this->getParent($myInfo['pid'],$order_info['verification_store_id'],$order_info['id']);
}catch(\Exception $e){
Common::put_file_log('上级-分销异常',json_encode($e->getMessage()), 'sales_distribution', __CLASS__ . __FUNCTION__ . __LINE__);
}
die;
}die;
//上级的上级
try{
$w1['id'] = $myInfo['pid'];
$myInfoP = Db::name('user')->where($w1)->find();
if(!empty($myInfoP['pid'])){
$this->getParent($myInfoP['id'],$order_info['verification_store_id'],$order_info['id']);
$this->getParent($myInfoP['pid'],$order_info['verification_store_id'],$order_info['id']);
}
}catch(\Exception $e){
Common::put_file_log('上级的上级-分销异常',json_encode($e->getMessage()), 'sales_distribution', __CLASS__ . __FUNCTION__ . __LINE__);
}
}
}
... ... @@ -408,11 +405,11 @@ class Wechat extends Api
$time = time();
$w1 = [];
$w1['user_id'] = $pid;
$w1['verification_store_id'] = $verification_store_id;
// $w1['verification_store_id'] = $verification_store_id;
$role = Db::name('verification_staff')->where($w1)->find();
if(in_array($role['type'],['1','3'])){
//属于代理 企业付款到佣金
//$this->grant_commission($pid,$order_id);
$this->grant_commission($pid,$order_id);
}else{
//属于普通用户 发送代金券
$this->send_voucher($pid,$verification_store_id,$order_id,$time);
... ... @@ -450,22 +447,33 @@ class Wechat extends Api
// 发放佣金 企业付款到零钱
public function grant_commission($pid=0,$order_id=0){
try{
$send_result = 0;
$verification_order = Db::name('verification_order')->where(['id'=>$order_id])->find();
$app = WehcatModule::getInstance()->initWechatPay();
$result = $app->transfer->toBalance([
'partner_trade_no' => '168532907259455', // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
'openid' => 'o5OQw6PPEGaHqIjAir7gqeDV5MzQ',
'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
're_user_name' => '陈程', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
'amount' => 1, // 企业付款金额,单位为分
'desc' => '理赔', // 企业付款操作说明信息。必填
]);
if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
//记录佣金表 后台没有配置
$verification_store = Db::name('verification_store')->where(['id'=>$verification_order['verification_store_id']])->find();
$user_info = Db::name('user')->where(['id'=>$pid])->find();
if(!empty($verification_store['commission'])){
$app = WehcatModule::getInstance()->initWechatPay();
$result = $app->transfer->toBalance([
'partner_trade_no' => '168532907259455', // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
'openid' => 'o5OQw6PPEGaHqIjAir7gqeDV5MzQ',
'check_name' => 'NO_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
're_user_name' => '陈程', // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
'amount' => 1, // 企业付款金额,单位为分
'desc' => '分销佣金', // 企业付款操作说明信息。必填
]);
if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
//记录佣金表 后台没有配置
$send_result = 1;
}else{
Common::put_file_log('失败-佣金发放',json_encode($result), 'grant_commission', __CLASS__ . __FUNCTION__ . __LINE__);
}
}else{
Common::put_file_log('失败-佣金发放',json_encode($result), 'grant_commission', __CLASS__ . __FUNCTION__ . __LINE__);
}
$this->brokerage_record($verification_store,$user_info,$send_result,$verification_order);
}catch(\Exception $e){
Common::put_file_log('异常-佣金发放',json_encode($result), 'grant_commission', __CLASS__ . __FUNCTION__ . __LINE__);
}
... ... @@ -500,4 +508,30 @@ class Wechat extends Api
Common::put_file_log('异常-红包发放',json_encode($result), 'grant_red_packets', __CLASS__ . __FUNCTION__ . __LINE__);
}
}
//佣金发放记录
private function brokerage_record($verification_store,$user_info,$send_result,$verification_order){
//关于该笔订单是否有发送给这个人
$w_re = [];
$w_re['order_id'] = $verification_order['id'];
$w_re['send_user_id'] = $user_info['id'];
$r = Db::name('verification_brokerage_record')->where($w_re)->find();
if(!empty($r)){
return false;
}
try{
$record = [];
$record['verification_store_id'] = $verification_store['id'];
$record['commission'] = $verification_store['commission'];
$record['send_user_id'] = $user_info['id'];
$record['send_createtime'] = time();
$record['send_result'] = $send_result;
$record['send_reason'] = 'ID:'.$user_info['id'].'分享给ID:'.$verification_order['user_id'].',并且成功支付ID:'.$verification_order['id'];
$record['order_id'] = $verification_order['id'];
Db::name('verification_brokerage_record')->insert($record);
}catch(\Exception $e){
Common::put_file_log('佣金记录失败',$e->getMessage(), 'brokerage_record', __CLASS__ . __FUNCTION__ . __LINE__);
}
}
}
... ...