Browse Source

互客接口对接

sandm 3 years ago
parent
commit
118d86c02d
1 changed files with 60 additions and 16 deletions
  1. 60 16
      app/Http/Controllers/Api/Third/ScrmController.php

+ 60 - 16
app/Http/Controllers/Api/Third/ScrmController.php

@@ -39,16 +39,17 @@ class ScrmController extends ApiBaseController
     public function pullData(Request $request)
     {
         $log = [
-            'content'      =>  json_encode($request->all()),
+            'content'      =>  serialize($request->all()),
         ];
         HukeCallback::create($log);
         $data = $request->all();
         //$fields = $this->get_customer_fields();
         switch ($data['type']){
             case '1011':
-                $param = json_decode($data['params']['customerEvent']);
+                $param = json_decode($data['params']['customerEvent'],true);
                 $res = $this->get_customer_query(3,[$param['cid']]);//根据返回的cid查询用户信息
                 if($res){//查询成功
+
                     $customer = $this->format_user($res[0]);
                     switch ($customer['label']){
                         case '硕博人才':
@@ -59,8 +60,15 @@ class ScrmController extends ApiBaseController
                                 $user = $registerService->registerPersonScrm($customer);
                             }
                             //如果手机号在聚才网已存在账户,将信息入库
-                            $customer['uid'] = $user->id;
-                            MemberShuobo::create($customer);
+                            $shuobo_exist = MemberShuobo::where('uid',$user->id)->first();
+                            $shuobo_data = array_only($customer,['uid','realname','sex','mobile','email','birthday','education','school','pro','graduation_time','house','country','weixin','company','job','come_in_time','require','trade_type','speciality']);
+                            if(!$shuobo_exist){
+                                $customer['uid'] = $user->id;
+                                MemberShuobo::create($shuobo_data);
+                            }else{
+                                MemberShuobo::where('uid',$user->id)->update($shuobo_data);
+                            }
+
                             break;
                     }
 
@@ -94,6 +102,13 @@ class ScrmController extends ApiBaseController
         $res = json_decode($response->getBody()->getContents(),true);
         $fields = [];
         foreach ($res['data'] as $k => $v){
+            if(array_key_exists('options',$v)){
+                $options = [];
+                foreach ($v['options'] as $key => $val){
+                    $options[$val['id']] = $val;
+                }
+                $v['options'] = $options;
+            }
             $fields[$v['id']] = $v;
         }
         Cache::put('huke_customer_fields',$fields,'86400');
@@ -142,6 +157,7 @@ class ScrmController extends ApiBaseController
     public function format_user(array $data)
     {
         $user = [];
+        $fields = $this->get_customer_fields();
         if(is_array($data['customFields'])){
             foreach ($data['customFields'] as $k => $v){
                 switch ($v['id']){
@@ -164,7 +180,7 @@ class ScrmController extends ApiBaseController
                         $user['wechat_name'] = $v['fieldValue'];
                         break;
                     case -7:
-                        $user['sex'] = $v['fieldValue'];
+                        $user['sex'] = $fields[-7]['options'][$v['fieldValue']]['optionValue'];
                         break;
                     case -8:
                         $user['area'] = $v['fieldValue'];
@@ -176,7 +192,7 @@ class ScrmController extends ApiBaseController
                         $user['tel_ex'] = $v['fieldValue'];
                         break;
                     case 10018777:
-                        $user['label'] = $v['fieldValue'];
+                        $user['label'] = $fields[10018777]['options'][$v['fieldValue']]['optionValue'];
                         break;
                     case 10019746:
                         $user['address'] = $v['fieldValue'];
@@ -194,7 +210,7 @@ class ScrmController extends ApiBaseController
                         $user['birthday'] = $v['fieldValue'];
                         break;
                     case 10019749:
-                        $user['origin'] = $v['fieldValue'];
+                        $user['origin'] = $fields[10019749]['options'][$v['fieldValue']]['optionValue'];
                         break;
                     case 10018779:
                         $user['remark'] = $v['fieldValue'];
@@ -206,22 +222,22 @@ class ScrmController extends ApiBaseController
                         $user['cid'] = $v['fieldValue'];
                         break;
                     case 10019751:
-                        $user['age_range'] =  $v['fieldValue'];
+                        $user['age_range'] =  $fields[10019751]['options'][$v['fieldValue']]['optionValue'];
                         break;
                     case 10019765:
                         $user['age'] = $v['fieldValue'];
                         break;
                     case 10031724:
-                        $user['level'] = $v['fieldValue'];
+                        $user['level'] = $fields[10031724]['options'][$v['fieldValue']]['optionValue'];
                         break;
                     case 10051871:
                         $user['edu'] = $v['fieldValue'];
                         break;
                     case 15293060:
-                        $user['politic_countenance'] = $v['fieldValue'];
+                        $user['politic_countenance'] = $fields[15293060]['options'][$v['fieldValue']]['optionValue'];
                         break;
                     case 15353563:
-                        $user['education'] = $v['fieldValue'];
+                        $user['education'] = $fields[15353563]['options'][$v['fieldValue']]['optionValue'];
                         break;
                     case 15352635:
                         $user['school'] = $v['fieldValue'];
@@ -230,16 +246,16 @@ class ScrmController extends ApiBaseController
                         $user['pro'] = $v['fieldValue'];
                         break;
                     case 15354507:
-                        $user['graduation_time'] = $v['fieldValue'];
+                        $user['graduation_time'] = date("Y-m-d",$v['fieldValue']/1000);
                         break;
                     case 15352636:
                         $user['country'] = $v['fieldValue'];
                         break;
                     case 15352650:
-                        $user['come_in_time'] = $v['fieldValue'];
+                        $user['come_in_time'] = date("Y-m-d",$v['fieldValue']/1000);
                         break;
                     case 15353579:
-                        $user['require'] = $v['fieldValue'];
+                        $user['require'] = $fields[15353579]['options'][$v['fieldValue']]['optionValue'];
                         break;
                     case 15353580:
                         $user['trade_type'] = $v['fieldValue'];
@@ -290,8 +306,36 @@ class ScrmController extends ApiBaseController
 
     public function test()
     {
-        $res = $this->get_customer_fields();
-        dd($res);
+
+        $curl = curl_init();
+        curl_setopt($curl, CURLOPT_URL, 'https://www.jucai.gov.cn/api/scrm/data');
+        //设置头文件的信息作为数据流输出
+        curl_setopt($curl, CURLOPT_HEADER, 0);
+        //设置获取的信息以文件流的形式返回,而不是直接输出。
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+        // 超时设置
+        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
+
+        // 超时设置,以毫秒为单位
+        // curl_setopt($curl, CURLOPT_TIMEOUT_MS, 500);
+
+        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE );
+        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE );
+
+        //设置post方式提交
+        curl_setopt($curl, CURLOPT_POST, 1);
+        $post = [
+            'eid' => '1000459',
+            'type' => '1011',
+            'cid' => '108720798',
+            'params' => [
+                'customerEvent' => '{"id":1687628552,"eid":1000459,"cid":110762053,"createTime":1637073249037,"eventCode":309,"eventName":"更新客户资料","fieldList":[{"value":"中国福建泉州","name":"15352636"},{"value":"1656604800000","name":"15352650"},{"value":"1656604800000","name":"15354507"}]}'
+            ]
+        ];
+        curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
+        //执行命令
+        $data = curl_exec($curl);
+        dd($data);
         $params = [
             'type' => 3,
             'targets' => [