diff --git a/home/controllers/h5/market/sylive2/Act.php b/home/controllers/h5/market/sylive2/Act.php index 77125b11..8fca01e3 100644 --- a/home/controllers/h5/market/sylive2/Act.php +++ b/home/controllers/h5/market/sylive2/Act.php @@ -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'] = [ diff --git a/home/controllers/h5/market/sylive2/Notify.php b/home/controllers/h5/market/sylive2/Notify.php index 3f2461aa..1d6f928c 100644 --- a/home/controllers/h5/market/sylive2/Notify.php +++ b/home/controllers/h5/market/sylive2/Notify.php @@ -1,77 +1,82 @@ 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 ''; } diff --git a/market/controllers/api/sylive/Activity.php b/market/controllers/api/sylive/Activity.php index 8f9665e5..7f7ffa66 100644 --- a/market/controllers/api/sylive/Activity.php +++ b/market/controllers/api/sylive/Activity.php @@ -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(); }