diff --git a/api/controllers/plan/Sytopic.php b/api/controllers/plan/Sytopic.php new file mode 100644 index 00000000..f7ba3b2a --- /dev/null +++ b/api/controllers/plan/Sytopic.php @@ -0,0 +1,56 @@ +load->model('market/Market_sytopic_enroll_model', 'sytopic_enroll_model'); + $this->load->library("ssApi"); + } + + //同步私域报名状态 + public function synEnroll() + { + $getPage = $this->input->get('page'); + $redis = &load_cache('redis'); + $pageCacheKey = "SYTOPIC_SYN_ENROLL_PAGE"; + if ($getPage) { + $page = $getPage; + } else { + $page = $redis->get($pageCacheKey) ?: 1; + } + $size = 500; + $enrollModel = new Market_sytopic_enroll_model(); + $enrollDeal = $enrollModel::ENROLL_DEAL_PUSH_CLUE . ',' . $enrollModel::ENROLL_DEAL_PUSH_CUSTOMER; + $where = [ + "enrollDeal in ({$enrollDeal})" => null, + "status!=" => $enrollModel::STATUS_INVALID, + ]; + $rows = $this->sytopic_enroll_model->select($where, 'id asc', $page, $size, 'id'); + if ($rows) { + $ids = array_column($rows, 'id'); + $ssApi = new SsApi(); + $stringIds = implode(',', $ids); + debug_log("开始同步,第{$page}页:" . $stringIds, $this->log_file, $this->log_dir); + $data = $ssApi->getStatus($stringIds); + debug_log("返回结果:" . json_encode($data, JSON_UNESCAPED_UNICODE), $this->log_file, $this->log_dir); + if ($data['lists']) { + foreach ($data['lists'] as $key => $val) { + $this->sytopic_enroll_model->update(['status' => $val['status'], 'status2' => $val['status2']], ['id' => $val['out_id']]); + } + } + $page++; + debug_log("同步结束,执行下一页:" . $page, $this->log_file, $this->log_dir); + $redis->save($pageCacheKey, $page, 24 * 60 * 60); + } else { + $redis->delete($pageCacheKey); + debug_log("执行结束", $this->log_file, $this->log_dir); + } + } +} diff --git a/common/libraries/SsApi.php b/common/libraries/SsApi.php index bd80f226..19d36242 100644 --- a/common/libraries/SsApi.php +++ b/common/libraries/SsApi.php @@ -5,6 +5,7 @@ class SsApi { const CF_PLATFORM = "SYSTOPIC"; const CLUES_METHOD = 'openApi/clues'; + const STATUS_METHOD = 'openApi/status'; private $app_id = '1c156bb57cd6984a'; private $sign_key = '71fd71173b776766a2ae1209d9a2c2ed'; private $api_url = 'https://api.haodian.cn/hd/app/'; //空间站报名数据接口 @@ -55,15 +56,15 @@ class SsApi 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]; + if (!$reqInfo || $reqInfo->code != 200) { + $msg = $reqInfo ? $reqInfo->msg : ''; + return ['code' => 0, 'msg' => '保存失败:' . $msg]; } return ['code' => 1, 'msg' => '保存成功']; } catch (Exception $e) { @@ -72,6 +73,44 @@ class SsApi } } + public function getStatus($out_ids) + { + if(is_array($out_ids)){ + $out_ids = implode(',',$out_ids); + } + $data = [ + 'out_ids' => $out_ids, + 'cf_platform' => self::CF_PLATFORM, + '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::STATUS_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); + 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(), true); + if (!$reqInfo || $reqInfo['code'] != 200) { + $msg = $reqInfo ? $reqInfo['msg'] : ''; + return ['code' => 0, 'msg' => '保存失败:' . $msg]; + } + return ['code' => 1, 'msg' => '保存成功', 'data' => $reqInfo['data']]; + } catch (Exception $e) { + debug_log("[error]#" . $e->getMessage(), $this->log_path); + return ['code' => 0, 'msg' => $e->getMessage()]; + } + } private function sign($param) { diff --git a/common/models/market/Market_sytopic_enroll_model.php b/common/models/market/Market_sytopic_enroll_model.php index 706d52eb..fb99a0d4 100644 --- a/common/models/market/Market_sytopic_enroll_model.php +++ b/common/models/market/Market_sytopic_enroll_model.php @@ -9,6 +9,10 @@ class Market_sytopic_enroll_model extends HD_Model const ENROLL_DEAL_PUSH_CLUE = 1; // 提交狸车线索池 const ENROLL_DEAL_PUSH_CUSTOMER = 2; // 提交狸车客户池 + const STATUS_PENDING = 0; //待处理 + const STATUS_SUCCESS = 1; //已成交 + const STATUS_INVALID = 2; //无效 + public function __construct() { parent::__construct($this->table_name, 'default'); @@ -47,7 +51,7 @@ class Market_sytopic_enroll_model extends HD_Model if (!$res) { return ['code' => 0, 'msg' => '提交失败']; } - if(is_numeric($res)){ //数据同步到空间站 + if (is_numeric($res)) { //数据同步到空间站 $this->load->library('market/sytopic_enroll_entity'); $this->sytopic_enroll_entity->synEnroll($res); } @@ -57,9 +61,9 @@ class Market_sytopic_enroll_model extends HD_Model public function statusCn() { $statusArray = [ - 0 => '待确认', - 1 => '已确认', - 2 => '无效单' + self::STATUS_PENDING => '待确认', + self::STATUS_SUCCESS => '已成交', + self::STATUS_INVALID => '无效' ]; return $statusArray; } diff --git a/home/controllers/h5/market/sylive2/User.php b/home/controllers/h5/market/sylive2/User.php index 81171ffd..330b9f38 100644 --- a/home/controllers/h5/market/sylive2/User.php +++ b/home/controllers/h5/market/sylive2/User.php @@ -219,6 +219,15 @@ class User extends Admin //专题报名 public function enroll() { + $statusCn = $this->sytopic_enroll_model->statusCn(); + $tabList = [['title' => '全部', 'type' => '']]; + foreach ($statusCn as $key => $val) { + $tabList[] = [ + 'title' => $val, + 'type' => $key + ]; + } + $this->data['tabList'] = $tabList; $this->data['_title'] = '我的推广'; $this->show_view('h5/market/sylive2/user/enroll'); } @@ -243,12 +252,14 @@ class User extends Admin } $total = $this->sytopic_enroll_model->count($where); $lists = []; + $statusCn = $this->sytopic_enroll_model->statusCn(); if ($total) { $res = $this->sytopic_enroll_model->select($where, 'id desc', $page, $size); + $enrollModel = new Market_sytopic_enroll_model(); $status_array = [ - 0 => ['name' => '待确认', 'class' => 'bg-f8e26a'], - 1 => ['name' => '已确认', 'class' => 'bg-2fdc53'], - 2 => ['name' => '无效单', 'class' => 'bg-f7'] + $enrollModel::STATUS_PENDING => ['name' => $statusCn[$enrollModel::STATUS_PENDING], 'class' => 'bg-f8e26a'], + $enrollModel::STATUS_SUCCESS => ['name' => $statusCn[$enrollModel::STATUS_SUCCESS], 'class' => 'bg-2fdc53'], + $enrollModel::STATUS_INVALID => ['name' => $statusCn[$enrollModel::STATUS_INVALID], 'class' => 'bg-f7'] ]; $topicIds = array_column($res, 'topicId'); $topicIdsStr = implode(',', $topicIds); @@ -263,7 +274,7 @@ class User extends Admin $channelName = $channelUserMap[$val['channelId']]; $temp = [ 'name' => $val['name'], - 'phone' => mobile_asterisk($val['mobile']), + 'phone' => $val['mobile'], 'time' => date('Y-m-d H:i', strtotime($val['enTime'])), 'source' => [ ['name' => $topicTitle, 'class' => 'bg-f8e26a'], diff --git a/home/views/h5/market/sylive2/user/enroll.php b/home/views/h5/market/sylive2/user/enroll.php index 82d6d47d..3dd1cf39 100644 --- a/home/views/h5/market/sylive2/user/enroll.php +++ b/home/views/h5/market/sylive2/user/enroll.php @@ -35,23 +35,7 @@ el: '#app', data() { return { - tab_list: [{ - title: '全部', - id: 1, - type: 0 - }, { - title: '待确认', - id: 2, - type: 0 - }, { - title: '已确认', - id: 3, - type: 1 - }, { - title: '无效', - id: 4, - type: 2 - }], + tab_list: , active: 0, list: [], loading: false, @@ -76,6 +60,9 @@ $.get('/h5/market/sylive2/user/enLists', {page: that.page, status: type}, function (res) { that.loading = false; if (res.code == 200) { + if(that.page===1){ + this.tab_list = res.data.tabList + } that.page = that.page + 1 that.list = that.list.concat(res.data.list); if (that.list.length >= res.data.total) { diff --git a/market/controllers/api/system/Role.php b/market/controllers/api/system/Role.php index 8317506f..4d838c3a 100644 --- a/market/controllers/api/system/Role.php +++ b/market/controllers/api/system/Role.php @@ -30,7 +30,7 @@ class Role extends BaseController $comments = $this->input_param('comments'); $sort = $this->input_param('sort'); $order = $this->input_param('order'); - $date = $where = []; + $list = $where = []; if (!$page) { $where['status'] = 0; } else { @@ -43,10 +43,12 @@ class Role extends BaseController $roleName && $where['roleName'] = $roleName; $roleCode && $where['roleCode'] = $roleCode; $comments && $where['comments'] = $comments; + $count = $this->mdSysRole->count($where); $res = $this->mdSysRole->select($where, $sort_order, $page, $limit); foreach ($res as $v) { - $date[] = $v; + $list[] = $v; } + $date = ['list' => $list, 'count' => $count]; $this->return_response_list($date); }