...
|
...
|
@@ -292,6 +292,7 @@ class Wechat extends Api |
|
|
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();
|
...
|
...
|
@@ -300,7 +301,7 @@ class Wechat extends Api |
|
|
$out_trade_no = $order_no;
|
|
|
$o_w["order_no"] = $out_trade_no;
|
|
|
$order_info = Db::name('verification_order')->where($o_w)->find();
|
|
|
$total_fee = $order_info['price'] = mt_rand(1,10);//测试支付1分钱
|
|
|
$total_fee = $order_info['price'] = mt_rand(100,120);//测试支付1分钱
|
|
|
$app = WehcatModule::getInstance()->initWechatPay();
|
|
|
$result = $app->order->unify([
|
|
|
'body' => '优惠券购买',
|
...
|
...
|
@@ -325,35 +326,35 @@ class Wechat extends Api |
|
|
|
|
|
/*
|
|
|
微信支付回调信息
|
|
|
{"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"}
|
|
|
*/
|
|
|
public function notify(){
|
|
|
$app = WehcatModule::getInstance()->initWechatPay();
|
|
|
$xml = file_get_contents("php://input");
|
|
|
file_put_contents('2_notify.log',($xml),FILE_APPEND);
|
|
|
|
|
|
$xmljson= json_encode(simplexml_load_string($xml, 'SimplexmlElement', LIBXML_NOCDATA ));//将对象转换个JSON
|
|
|
file_put_contents('1_notify.log',($xmljson),FILE_APPEND);
|
|
|
$response = $app->handlePaidNotify(function($message, $fail){
|
|
|
// 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
|
|
|
Common::put_file_log('支付成功-微信支付回调信息',json_encode($message), 'pay_notify', __CLASS__ . __FUNCTION__ . __LINE__);
|
|
|
$out_trade_no = $message['out_trade_no'];
|
|
|
if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') {
|
|
|
$o_w["order_no"] = $out_trade_no;
|
|
|
$order_info = Db::name('verification_order')->where($o_w)->find();
|
|
|
if($order_info['type'] != 2){
|
|
|
//1. 更改状态信息
|
|
|
$up['type'] = 2;
|
|
|
$up['paytime'] = time();
|
|
|
$up['payMode'] = '0';
|
|
|
Db::name('verification_order')->where($o_w)->update($up);
|
|
|
//2. 分销处理
|
|
|
$this->sales_distribution($order_info);
|
|
|
}
|
|
|
} else {
|
|
|
Common::put_file_log('支付失败-微信支付回调信息',json_encode($message), 'pay_notify', __CLASS__ . __FUNCTION__ . __LINE__);
|
|
|
$message = json_decode($xmljson,true);
|
|
|
// 使用通知里的 "微信支付订单号" 或者 "商户订单号" 去自己的数据库找到订单
|
|
|
Common::put_file_log('支付成功-微信支付回调信息',json_encode($message), 'pay_notify', __CLASS__ . __FUNCTION__ . __LINE__);
|
|
|
$out_trade_no = $message['out_trade_no'];
|
|
|
if ($message['return_code'] === 'SUCCESS' && $message['result_code'] === 'SUCCESS') {
|
|
|
$o_w["order_no"] = $out_trade_no;
|
|
|
$order_info = Db::name('verification_order')->where($o_w)->find();
|
|
|
if($order_info['type'] != 1){
|
|
|
//1. 更改状态信息
|
|
|
$up['type'] = 1;
|
|
|
$up['paytime'] = time();
|
|
|
$up['payMode'] = '0';
|
|
|
Db::name('verification_order')->where($o_w)->update($up);
|
|
|
//2. 分销处理
|
|
|
$this->sales_distribution($order_info);
|
|
|
}
|
|
|
return true; // 返回处理完成
|
|
|
});
|
|
|
$response->send(); // return $response;
|
|
|
} else {
|
|
|
|
|
|
}
|
|
|
return true; // 返回处理完成
|
|
|
|
|
|
/*
|
|
|
$xml = file_get_contents("php://input");
|
|
|
$xmljson= json_encode(simplexml_load_string($xml, 'SimplexmlElement', LIBxml_NOCDATA));//将对象转换个JSON
|
...
|
...
|
@@ -387,7 +388,7 @@ class Wechat extends Api |
|
|
$this->getParent($myInfo['pid'],$order_info['verification_coupon_ids'],$order_info['id']);
|
|
|
}catch(\Exception $e){
|
|
|
Common::put_file_log('上级-分销异常',json_encode($e->getMessage()), 'sales_distribution', __CLASS__ . __FUNCTION__ . __LINE__);
|
|
|
}die;
|
|
|
}
|
|
|
//上级的上级
|
|
|
try{
|
|
|
$w1['id'] = $myInfo['pid'];
|
...
|
...
|
@@ -411,8 +412,8 @@ class Wechat extends Api |
|
|
// $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_red_packets($pid,$order_id);
|
|
|
}else{
|
|
|
//属于普通用户 发送代金券
|
|
|
$this->send_voucher($pid,$verification_coupon_ids,$order_id,$time);
|
...
|
...
|
@@ -467,8 +468,7 @@ class Wechat extends Api |
|
|
'amount' => 1, // 企业付款金额,单位为分
|
|
|
'desc' => '分销佣金', // 企业付款操作说明信息。必填
|
|
|
]);
|
|
|
return json($result);
|
|
|
die;
|
|
|
|
|
|
if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
|
|
|
//记录佣金表 后台没有配置
|
|
|
$send_result = 1;
|
...
|
...
|
@@ -491,28 +491,31 @@ class Wechat extends Api |
|
|
public function grant_red_packets($pid=0,$order_id=0){
|
|
|
try{
|
|
|
//测试 https://coupon.xp.yn.cn/api/v1/wechat/grant_red_packets
|
|
|
$order_id = 14;
|
|
|
//$order_id = 14;
|
|
|
|
|
|
$send_result = 0;
|
|
|
$verification_order = Db::name('verification_order')->where(['id'=>$order_id])->find();
|
|
|
$verification_store = Db::name('verification_store')->where(['id'=>$verification_order['verification_store_id']])->find();
|
|
|
$user_info = Db::name('user')->where(['id'=>$pid])->find();
|
|
|
$total_amount = $verification_store['commission'] = 100;
|
|
|
$app = WehcatModule::getInstance()->initWechatPay();
|
|
|
$result = $app->redpack->sendNormal([
|
|
|
|
|
|
'mch_billno' => '168532907259455',
|
|
|
'send_name' => '测试红包',
|
|
|
're_openid' => 'o5OQw6PPEGaHqIjAir7gqeDV5MzQ',
|
|
|
'mch_billno' => $verification_order['order_no'],
|
|
|
'send_name' => '佣金红包',
|
|
|
're_openid' => $user_info['openid'],
|
|
|
'total_num' => 1, //固定为1,可不传
|
|
|
'total_amount' => 100, //单位为分,不小于100
|
|
|
'total_amount' => $total_amount, //单位为分,不小于100
|
|
|
'wishing' => '祝福语',
|
|
|
|
|
|
'act_name' => '测试活动',
|
|
|
'remark' => '测试备注',
|
|
|
'act_name' => '佣金分享红包到账',
|
|
|
'remark' => '感谢您的参与',
|
|
|
]);
|
|
|
return json($result);
|
|
|
die;
|
|
|
|
|
|
if($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS'){
|
|
|
//记录佣金表
|
|
|
}else{
|
|
|
Common::put_file_log('失败-红包发放',json_encode($result), 'grant_red_packets', __CLASS__ . __FUNCTION__ . __LINE__);
|
|
|
//记录佣金表 verification_brokerage_record
|
|
|
$send_result = 1;
|
|
|
}
|
|
|
Common::put_file_log('红包发放',json_encode($result), 'grant_red_packets', __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_red_packets', __CLASS__ . __FUNCTION__ . __LINE__);
|
|
|
}
|
...
|
...
|
@@ -521,13 +524,13 @@ class Wechat extends Api |
|
|
//佣金发放记录
|
|
|
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;
|
|
|
}
|
|
|
// $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'];
|
...
|
...
|
|