增加报名同步至空间站后台

This commit is contained in:
lcc
2024-08-07 17:46:58 +08:00
parent 9aebff654b
commit 010082067a
7 changed files with 186 additions and 4 deletions
+3 -1
View File
@@ -1160,7 +1160,9 @@ if (!function_exists('myTrim')) {
if (!function_exists('is_product')) {
function is_product()
{
if (false !== strpos($_SERVER['HTTP_HOST'], 'dev') || false !== strpos($_SERVER['HTTP_HOST'], 'test')) { //dev 测试
if (false !== strpos($_SERVER['HTTP_HOST'], 'dev') ||
false !== strpos($_SERVER['HTTP_HOST'], 'test') ||
false !== strpos($_SERVER['HTTP_HOST'], 'lc')) { //dev 测试
return false;
} else { // 正式
return true;
+91
View File
@@ -0,0 +1,91 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class SsApi
{
const CF_PLATFORM = "SYSTOPIC";
const CLUES_METHOD = 'openApi/clues';
private $app_id = '1c156bb57cd6984a';
private $sign_key = '71fd71173b776766a2ae1209d9a2c2ed';
private $api_url = 'https://api.haodian.cn/hd/app/'; //空间站报名数据接口
private $ci;
private $log_path;
public function __construct()
{
$this->ci = &get_instance();
if (!is_product()) {
$this->api_url = 'https://api.ss.haodian.cn/hd/app/'; //测试地址
}
$this->ci->load->helper('string');
$this->log_path = 'ss_api.log';
}
/**
* @param $id
* @param $name
* @param $mobile
* @param $en_time
* @param $to_customers 是否添加到客户池
* @param $biz_id
* @return array
*/
public function postClues($id, $name, $mobile, $en_time, $to_customers = 0, $biz_id = 0)
{
$data = [
'name' => $name,
'mobile' => $mobile,
'en_time' => $en_time,
'out_id' => $id,
'cf_platform' => self::CF_PLATFORM,
'biz_id' => $biz_id,
'to_customers' => $to_customers,
'nonce_str' => random_string('alpha'),
'app_id' => $this->app_id,
];
$data['sign'] = $this->sign($data);
$client = new GuzzleHttp\Client();
$options = [
\GuzzleHttp\RequestOptions::HEADERS => ['Content-Type' => 'application/json'],
\GuzzleHttp\RequestOptions::JSON => $data,
];
$url = $this->api_url . self::CLUES_METHOD;
try {
debug_log("[info]#请求地址:" . $url, $this->log_path);
debug_log("[info]#请求参数:" . json_encode($data, JSON_UNESCAPED_UNICODE), $this->log_path);
$response = $client->post($url, $options);
$body = $response->getBody();
debug_log("[info]#返回信息:" . $response->getBody(), $this->log_path);
if ($response->getStatusCode() != 200) {
debug_log("[error]#" . $response->getStatusCode(), $this->log_path);
return ['code' => 0, 'msg' => '网络错误:' . $response->getStatusCode()];
}
$reqInfo = json_decode($response->getBody());
if ($reqInfo->code != 200) {
return ['code' => 0, 'msg' => '保存失败:' . $reqInfo->msg];
}
return ['code' => 1, 'msg' => '保存成功'];
} catch (Exception $e) {
debug_log("[error]#" . $e->getMessage(), $this->log_path);
return ['code' => 0, 'msg' => $e->getMessage()];
}
}
private function sign($param)
{
unset($param['sign']);
//按字典序排序参数
ksort($param);
$buff = "";
foreach ($param as $k => $v) {
if (!is_array($v) && strlen($v) > 0) {
$buff .= $k . "=" . ($v) . "&";
}
}
$buff = trim($buff, "&");
$buff = $buff . "&key=" . $this->sign_key;
return strtoupper(md5($buff));
}
}
@@ -0,0 +1,71 @@
<?php
use GuzzleHttp\Exception\RequestException;
class Sytopic_enroll_entity
{
private $log_file = 'sytopic_enroll_syn.log';
private $ci;
public function __construct()
{
$this->ci = &get_instance();
$this->ci->load->model('market/market_sylive_organization_model');
$this->ci->load->model('market/market_sytopic_enroll_model', 'sytopic_enroll_model');
$this->ci->load->model('market/Market_sytopic_model', 'topic_model');
$this->ci->load->library('ssApi');
}
/**
* 同步专题报名数据
* @param $enrollId 报名id
* @return array
*/
public function synEnroll($enrollId)
{
$enrollModel = new Market_sytopic_enroll_model();
debug_log("[info]# 报名id:" . $enrollId, $this->log_file);
$enrollRow = $this->ci->sytopic_enroll_model->get(['id' => $enrollId]);
$topicRow = $organizationRow = '';
$enrollRow && $topicRow = $this->ci->topic_model->get(['id' => $enrollRow['topicId']]);
$topicRow && $organizationRow = $this->ci->market_sylive_organization_model->get(['organizationId' => $topicRow['organizationId']]);
if (!$enrollRow) {
debug_log("[error]# 报名数据不存在.", $this->log_file);
return ['code' => 0, 'msg' => '报名数据不存在'];
}
if (!$topicRow) {
debug_log("[error]# 专题不存在.", $this->log_file);
return ['code' => 0, 'msg' => '专题不存在'];
}
if (!$organizationRow) {
debug_log("[error]# 机构不存在.", $this->log_file);
return ['code' => 0, 'msg' => '机构不存在'];
}
$enrollDeal = (int)$enrollRow['enrollDeal'];
$ssApi = new SsApi();
if ($enrollDeal === $enrollModel::ENROLL_DEAL_NO) {
debug_log("[info]# 不需要处理.", $this->log_file);
return ['code' => 0, 'msg' => '无需处理'];
} else { //同步到客户
debug_log("[info]# 同步到空间站.", $this->log_file);
$to_customers = 0;
if($enrollDeal==$enrollModel::ENROLL_DEAL_PUSH_CUSTOMER){
$to_customers = 1;
}
$res = $ssApi->postClues($enrollId, $enrollRow['name'],
$enrollRow['mobile'], $enrollRow['enTime'], $to_customers, (int)$organizationRow['comments']);
debug_log("[info]# 接口请求结果:" . json_encode($res, JSON_UNESCAPED_UNICODE), $this->log_file);
return $res;
}
}
public function __get($name)
{
if ('_model' === substr($name, -6)) {
return $this->ci->$name;
} elseif ('load' == $name) {
return $this->ci->load;
}
return null;
}
}
@@ -10,6 +10,10 @@ class Market_sylive_organization_model extends HD_Model
{
private $table_name = 'lc_market_sylive_organization';
const ENROLL_DEAL_NO = 0; // 报名不处理
const ENROLL_DEAL_PUSH_CLUE = 1; // 提交狸车线索池
const ENROLL_DEAL_PUSH_CUSTOMER = 2; // 提交狸车客户池
public function __construct()
{
parent::__construct($this->table_name, 'default');
@@ -5,6 +5,10 @@ class Market_sytopic_enroll_model extends HD_Model
{
private $table_name = 'lc_market_sytopic_enroll';
const ENROLL_DEAL_NO = 0; // 报名不处理
const ENROLL_DEAL_PUSH_CLUE = 1; // 提交狸车线索池
const ENROLL_DEAL_PUSH_CUSTOMER = 2; // 提交狸车客户池
public function __construct()
{
parent::__construct($this->table_name, 'default');
@@ -15,6 +19,8 @@ class Market_sytopic_enroll_model extends HD_Model
{
$this->load->model('market/Market_sytopic_user_model', 'topic_user_model');
$this->load->model('market/market_sytopic_module_option_model');
$this->load->model('market/market_sylive_organization_model');
$this->load->model('market/market_sytopic_model', 'topic_model');
$optionRow = $this->market_sytopic_module_option_model->get(['id' => $id]);
$topicUser = $this->topic_user_model->get(['id' => $topicUserId]);
$row = $this->get(['status' => 0, 'moduleOptionId' => $id, 'userId' => $topicUser['userId']]);
@@ -22,6 +28,8 @@ class Market_sytopic_enroll_model extends HD_Model
// $this->update(['name' => $name, 'mobile' => $mobile], ['id' => $row['id']]);
return ['code' => 0, 'msg' => '您的信息已收到,无需重复操作'];
}
$topic = $this->topic_model->get(['id' => $optionRow['topicId']]);
$org = $this->market_sylive_organization_model->get(['organizationId' => $topic['organizationId']]);
$data = [
'topicUserId' => $topicUserId,
'userId' => $topicUser['userId'],
@@ -30,6 +38,7 @@ class Market_sytopic_enroll_model extends HD_Model
'mobile' => $mobile,
'enTime' => date('Y-m-d H:i:s'),
'createTime' => date('Y-m-d H:i:s'),
'enrollDeal' => $org ? $org['enrollDeal'] : self::ENROLL_DEAL_NO,
];
$optionRow['id'] && $data['moduleOptionId'] = $optionRow['id'];
$optionRow['topicId'] && $data['topicId'] = $optionRow['topicId'];
@@ -38,6 +47,10 @@ class Market_sytopic_enroll_model extends HD_Model
if (!$res) {
return ['code' => 0, 'msg' => '提交失败'];
}
if(is_numeric($res)){ //数据同步到空间站
$this->load->library('market/sytopic_enroll_entity');
$this->sytopic_enroll_entity->synEnroll($res);
}
return ['code' => 1, 'msg' => '保存成功'];
}
+1 -1
View File
@@ -136,7 +136,7 @@ $config['subclass_prefix'] = 'HD_';
| Note: This will NOT disable or override the CodeIgniter-specific
| autoloading (application/config/autoload.php)
*/
$config['composer_autoload'] = FALSE;
$config['composer_autoload'] = COMMPATH.'/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
@@ -129,7 +129,7 @@ class Organization extends BaseController
!$comments && $comments = '';
$logo = $logo[0]['fileUrl'] ? $logo[0]['fileUrl'] : '';
$addDate = ['parentId' => $parentId, 'organizationName' => $organizationName, 'organizationFullName' => $organizationFullName
, 'organizationType' => $organizationType, 'sortNumber' => $sortNumber, 'comments' => $comments, 'logo' => $logo
, 'organizationType' => $organizationType, 'sortNumber' => $sortNumber, 'comments' => $comments, 'logo' => $logo,'enrollDeal'=>$enrollDeal
, 'createTime' => date('Y-m-d H:i:s')];
if ($city) {
$addDate['provinceId'] = intval($city[0]);
@@ -159,6 +159,7 @@ class Organization extends BaseController
$comments = $this->input_param('comments');
$city = $this->input_param('city');
$logo = $this->input_param('logo');
$enrollDeal = $this->input_param('enrollDeal');
if ($_SESSION['brandName']) {//品牌机构
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $organizationId]);
if ($re_org && $re_org['parentId'] == 0) {//一级品牌不可修改字段
@@ -185,7 +186,7 @@ class Organization extends BaseController
!$comments && $comments = '';
$logo = $logo ? $logo[0]['fileUrl'] : '';
$upDate = ['parentId' => $parentId, 'organizationName' => $organizationName, 'organizationFullName' => $organizationFullName
, 'organizationType' => $organizationType, 'sortNumber' => $sortNumber, 'comments' => $comments, 'logo' => $logo];
, 'organizationType' => $organizationType, 'sortNumber' => $sortNumber, 'comments' => $comments, 'logo' => $logo,'enrollDeal'=>$enrollDeal];
if ($city) {
$upDate['provinceId'] = intval($city[0]);
$upDate['cityId'] = intval($city[1]);