私域通增加订单归属

This commit is contained in:
chenrx
2024-06-17 14:16:03 +08:00
parent 00352f784f
commit dd20fc6b78
3 changed files with 53 additions and 45 deletions
@@ -611,6 +611,7 @@ class Act extends Wx
if (is_numeric($order_id)) {
//添加kpi
$params = ['a_id' => $a_id, 'uid' => $this->uid, 'cf_uid' => $act_user_row['channelId'], 'kpi' => 'beforeOrder'];
$ac_row['orderType'] && $params['cf_uid'] = $act_user_row['pid'];
$order_id && $params['tagId'] = intval($order_id);
$params['itemId'] = $itemId;
$params['jsondata'] = [
+47 -42
View File
@@ -1,77 +1,82 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH."../api/third_party/WXpay/WxPay.Api.php";
defined('BASEPATH') or exit('No direct script access allowed');
require_once APPPATH . "../api/third_party/WXpay/WxPay.Api.php";
class Notify extends CI_Controller {
class Notify extends CI_Controller
{
private $log_dir = 'market/sylive';
private $log_file = 'wx_pay.log';
private $notify;
private $mch_id;
public function __construct(){
public function __construct()
{
parent::__construct();
$this->load->model('market/market_sylive_activity_user_model', 'act_user_model');
$this->load->model('market/market_sylive_order_model','order_model');
$this->load->model('market/market_sylive_order_model', 'order_model');
$this->load->model('market/market_sylive_activity_model');
$this->load->model('market/market_sylive_activity_orders_model','mdSytActivityOrders');
$this->load->model('market/market_sylive_activity_orders_model', 'mdSytActivityOrders');
$this->load->library('market/sylive_entity');
$this->load->library('market/sylive2_entity');
try{
try {
$WxPayNotifyResults = new WxPayNotifyResults();
$input = file_get_contents("php://input");
debug_log("[input] ". __FUNCTION__ . "# $input:" . json_encode($input,JSON_UNESCAPED_UNICODE), $this->log_file,$this->log_dir);
debug_log("[input] " . __FUNCTION__ . "# $input:" . json_encode($input, JSON_UNESCAPED_UNICODE), $this->log_file, $this->log_dir);
$result = $WxPayNotifyResults->FromXml($input);
$this->mch_id = $result['mch_id'];
$config = $this->market_sylive_activity_model->pay_config($this->mch_id);
if($config && file_exists($config)){
if ($config && file_exists($config)) {
require_once $config;
}else{
require_once APPPATH."../api/third_party/WXconfig/hdy_WxPay.Config.php";
} else {
require_once APPPATH . "../api/third_party/WXconfig/hdy_WxPay.Config.php";
}
//验证签名
$config = new WxPayConfig();
$result = WxPayNotifyResults::Init($config, $input);
$this->notify = $result->GetValues();
debug_log("[info] ". __FUNCTION__ . "# notify:" . json_encode($this->notify,JSON_UNESCAPED_UNICODE), $this->log_file,$this->log_dir);
}catch (WxPayException $e){
debug_log("[error] ". __FUNCTION__ . ":".$e->getMessage(), $this->log_file,$this->log_dir);
debug_log("[info] " . __FUNCTION__ . "# notify:" . json_encode($this->notify, JSON_UNESCAPED_UNICODE), $this->log_file, $this->log_dir);
} catch (WxPayException $e) {
debug_log("[error] " . __FUNCTION__ . ":" . $e->getMessage(), $this->log_file, $this->log_dir);
exit();
}
}
//商品-微信支付异步通知
public function item(){
try{
public function item()
{
try {
$sid = $this->notify['out_trade_no'];
if($sid){
debug_log("[start] ". __FUNCTION__ . ": out_trade_no:".$this->notify['out_trade_no'], $this->log_file,$this->log_dir);
$order = $this->order_model->get(array('sid'=>$sid));
if(!$order){
if ($sid) {
debug_log("[start] " . __FUNCTION__ . ": out_trade_no:" . $this->notify['out_trade_no'], $this->log_file, $this->log_dir);
$order = $this->order_model->get(array('sid' => $sid));
if (!$order) {
throw new Exception("{$sid}_订单不存在");
}
if($order['status']){
if ($order['status']) {
throw new Exception("{$sid}_订单已支付");
}
if($this->notify['result_code'] != 'SUCCESS'){ //支付失败
if ($this->notify['result_code'] != 'SUCCESS') { //支付失败
throw new Exception("支付失败,sid={$sid}");
}else{ //支付成功
$res = $this->order_model->update(['status'=>1,'payTime'=>date('Y-m-d H:i:s')],['id'=>$order['id']]);
$act = $this->market_sylive_activity_model->get(['activityId'=>$order['activityId']]);
$jsondata = json_decode($act['jsondata'],true);
if($jsondata['signBespeak']['status'] && $jsondata['signBespeak']['itemId']==$order['itemId']) { //绑定新增商品订单
} else { //支付成功
$res = $this->order_model->update(['status' => 1, 'payTime' => date('Y-m-d H:i:s')], ['id' => $order['id']]);
$act = $this->market_sylive_activity_model->get(['activityId' => $order['activityId']]);
$jsondata = json_decode($act['jsondata'], true);
if ($jsondata['signBespeak']['status'] && $jsondata['signBespeak']['itemId'] == $order['itemId']) { //绑定新增商品订单
$kpi = 'beforeOrder';
}else{
} else {
$kpi = 'order';
}
if($res){
$act_user = $this->act_user_model->get(['userId'=>$order['userId'],'activityId'=>$order['activityId']]);
if ($res) {
$act_user = $this->act_user_model->get(['userId' => $order['userId'], 'activityId' => $order['activityId']]);
$cf_uid = $act_user['channelId'];
if($kpi == 'order' && in_array($order['activityId'], array(21))) {
if ($kpi == 'order' && in_array($order['activityId'], array(21))) {
$cf_uid = $act_user['channelId'] == $act_user['pid'] ? $act_user['channelId'] : $act_user['pid'];
}else{
$cf_uid = $act_user['channelId'];
}
if ($kpi == 'order' && $act['orderType'] && $act_user['pid']) {
$cf_uid = $act_user['pid'];
}
$params = [
@@ -80,23 +85,23 @@ class Notify extends CI_Controller {
'cf_uid' => $cf_uid,
'kpi' => $kpi,
'tagId' => $order['id'],
'jsondata'=> ['order_id'=>$order['id'],'sid'=>$sid,'mch_id'=>$this->mch_id],
'jsondata' => ['order_id' => $order['id'], 'sid' => $sid, 'mch_id' => $this->mch_id],
'itemId' => $order['itemId']
];
$sy_res = $this->sylive2_entity->kpi_log($params);
debug_log("[info] ". __FUNCTION__ . ":私域通增加记录-".json_encode($sy_res,JSON_UNESCAPED_UNICODE), $this->log_file,$this->log_dir);
debug_log("[success] ". __FUNCTION__ . ":操作成功", $this->log_file,$this->log_dir);
debug_log("[info] " . __FUNCTION__ . ":私域通增加记录-" . json_encode($sy_res, JSON_UNESCAPED_UNICODE), $this->log_file, $this->log_dir);
debug_log("[success] " . __FUNCTION__ . ":操作成功", $this->log_file, $this->log_dir);
}
}
}
}catch (Exception $e){
} catch (Exception $e) {
$msg = $e->getMessage();
debug_log("[error] ". __FUNCTION__ . ":{$msg}", $this->log_file,$this->log_dir);
debug_log("[error] " . __FUNCTION__ . ":{$msg}", $this->log_file, $this->log_dir);
}
if($sid){
debug_log("[finish] ". __FUNCTION__ . ": out_trade_no-".$this->notify['out_trade_no'], $this->log_file,$this->log_dir);
}else{
debug_log("[finish] ". __FUNCTION__ . ": 参数错误-".json_encode($this->notify,JSON_UNESCAPED_UNICODE), $this->log_file,$this->log_dir);
if ($sid) {
debug_log("[finish] " . __FUNCTION__ . ": out_trade_no-" . $this->notify['out_trade_no'], $this->log_file, $this->log_dir);
} else {
debug_log("[finish] " . __FUNCTION__ . ": 参数错误-" . json_encode($this->notify, JSON_UNESCAPED_UNICODE), $this->log_file, $this->log_dir);
}
echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
}
+5 -3
View File
@@ -187,7 +187,7 @@ class Activity extends BaseController
'bgImg' => $bgImg, 'channelImg' => $channelImg, 'banner' => $banner, 'sharePhoto' => $sharePhoto, 'shareImg' => $shareImg, 'item' => $item, 'url' => $url,
'mchId' => $v['mchId'], 'protocolTitle' => $v['protocolTitle'], 'protocol' => $v['protocol'], 'serviceLink' => $serviceLink,
'bottoms' => $bottoms, 'draw' => $draw, 'visitTag' => $visitTag, 'blacklist' => $blacklist,
'signBespeak' => $signBespeak, 'barrage' => $barrage, 'button' => $button,
'signBespeak' => $signBespeak, 'barrage' => $barrage, 'button' => $button, 'orderType' => intval($v['orderType']),
's_time' => $v['timeStart'], 'e_time' => $v['timeEnd'], 'status' => $status, 'groups' => $groups, 'createTime' => $v['createTime']];
}
}
@@ -221,6 +221,7 @@ class Activity extends BaseController
$activityStart = $this->input_param('activityStart');
$bottoms = $this->input_param('bottoms');
$signBespeak = $this->input_param('signBespeak');
$orderType = $this->input_param('orderType') ?: 0;
if (!$title) {
$this->return_json('请输入活动标题');
}
@@ -277,7 +278,7 @@ class Activity extends BaseController
$addData = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId, 'jsondata' => $jsondata
, 'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg, 'organizationId' => $organizationId
, 'drawCode' => $drawCode, 'mchId' => $mchId, 'protocolTitle' => $protocolTitle, 'protocol' => $protocol, 'activityStart' => $activityStart
, 'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'status' => 1, 'createTime' => $createTime];
, 'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'status' => 1, 'createTime' => $createTime, 'orderType' => $orderType];
$activityId = $this->mdSyliveActivity->add($addData);
if (!$activityId) {
$this->return_json('添加活动失败');
@@ -319,6 +320,7 @@ class Activity extends BaseController
$activityStart = $this->input_param('activityStart');
$bottoms = $this->input_param('bottoms');
$signBespeak = $this->input_param('signBespeak');
$orderType = $this->input_param('orderType') ?: 0;
if (!$activityId) {
$this->return_json('参数错误');
}
@@ -384,7 +386,7 @@ class Activity extends BaseController
$upData = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId, 'activityStart' => $activityStart,
'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg, 'jsondata' => $jsondata,
'drawCode' => $drawCode, 'mchId' => $mchId, 'protocolTitle' => $protocolTitle, 'protocol' => $protocol,
'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'organizationId' => $organizationId];
'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'organizationId' => $organizationId, 'orderType' => $orderType];
$this->mdSyliveActivity->update($upData, ['activityId' => $activityId]);
$this->return_response();
}