Ejemplo n.º 1
0
 public function getUserAllData($userArray, $referrer = 1)
 {
     $userString = implode(",", $userArray);
     $typeArray = [0, 1, 2, 3];
     $data = [];
     foreach ($typeArray as $type) {
         $return = self::getUserData($userString, $type, $referrer);
         if ($return["IsSuccess"] && $return["Result"]) {
             foreach ($return["Result"] as $k => $val) {
                 $data[$val["UserName"]]["visitor_datatype_" . $type] = $val["Result"];
             }
         }
     }
     foreach ($data as $user => $val) {
         $data[$user]["visitor_username"] = $user;
         $data[$user]["visitor_referrer"] = $referrer;
         $model = new ApiVisitorDetail();
         $find = ApiVisitorDetail::findone(['visitor_username' => $user, 'visitor_referrer' => $referrer]);
         if ($find) {
             $model = $find;
         }
         $array = ["ApiVisitorDetail" => array_merge(['visitor_username' => $user, 'visitor_referrer' => $referrer], $val)];
         $model->load($array);
         $model->save();
     }
 }
Ejemplo n.º 2
0
 public function getDb($apiData)
 {
     $idvisits = [];
     $data = [];
     foreach ($apiData as $k => $v) {
         $data[$v['idVisit']] = $v;
         $idvisits[] = $v['idVisit'];
     }
     $idvisits = array_unique($idvisits);
     $find = ApiVisitorDetail::find()->where(["in", "idvisit", $idvisits])->asArray()->all();
     //格式化username
     $find = ArrayHelper::index($find, 'idvisit');
     foreach ($data as $k => $v) {
         $array = isset($find[$k]) ? $find[$k] : false;
         $data[$k]['ip'] = $array ? $array['ip'] : '';
         $data[$k]['iptype'] = $array ? $array['iptype'] : '';
         $data[$k]['iptext'] = $array ? $array['iptext'] : '';
         $data[$k]['visitor_referrer'] = $array ? $array['visitor_referrer'] : '';
         for ($i = 0; $i < 10; $i++) {
             $data[$k]['visitor_datatype_' . $i] = $array ? $array['visitor_datatype_' . $i] : '';
         }
     }
     return $data;
 }