public function actionSaveVoter()
 {
     $klpCode = 500;
     $qunCode = 500;
     $request = Yii::$app->request;
     $restaurantType = $request->post('restaurantType', null);
     $sample = $request->post('sample', null);
     //Array
     $address = $request->post('address', null);
     $username = $request->post('username', null);
     $userMobile = $request->post('mobile', null);
     $origin = $request->post('origin', null);
     $sampleStr = $this->arrayToStr($sample);
     if ($userMobile != null && $userMobile != '') {
         $voter = PopularVoter::findOne(['mobile' => $userMobile]);
         if ($voter == null) {
             //Has in KLP?
             $voter = new PopularVoter();
             $voter->mobile = $userMobile;
             $voter->name = $username;
             $voter->restaurantType = $restaurantType;
             $voter->sample = $sampleStr;
             $voter->address = $address;
             $voter->smsStatusThree = 0;
             $voter->smsStatusFour = 0;
             $voter->isEnter = 1;
             $voter->hasPrize = 0;
             $voter->reSmsContent = null;
             $voter->reSmsTime = null;
             date_default_timezone_set(TIMEZONE);
             $currentTime = date('Y-m-d H:i:s', time() + 8 * 60 * 60);
             $voter->createAt = new \MongoDate(strtotime($currentTime));
             $voter->submitTime = new \MongoDate(strtotime($currentTime));
             if (!$voter->save()) {
                 $klpCode = 500;
             } else {
                 $klpCode = 200;
             }
         } else {
             if ($voter->sample != null) {
                 //已经答过题
                 $klpCode = 1000;
                 \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
                 return ['klpCode' => $klpCode];
             }
             $voter->name = $username;
             $voter->restaurantType = $restaurantType;
             $voter->sample = $sampleStr;
             $voter->address = $address;
             if (!$voter->save()) {
                 $klpCode = 500;
             } else {
                 $klpCode = 200;
             }
         }
         // $response = $this->saveQuncrm($username, $userMobile, $origin);
         // if ($response == 'failed') {
         //     $qunCode = 500;
         // } else {
         //     $qunCode = 200;
         // }
     }
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     // return ['klpCode' => $klpCode, 'qunCode' => $qunCode ];
     return ['klpCode' => $klpCode, 'qunCode' => 200];
 }
Пример #2
0
 private function saveReceiveSmsToPopularVoter($srcaddress, $smsbody, $retrievedate)
 {
     date_default_timezone_set(TIMEZONE);
     $mobilePre = substr($srcaddress, 0, 3);
     if ($mobilePre == '886') {
         $srcaddress = '09' . substr($srcaddress, 4, strlen($srcaddress) + 1);
     }
     $voter = PopularVoter::findOne(['mobile' => $srcaddress]);
     if ($voter != null) {
         $smsTime = date('Y-m-d H:i:s', time());
         $voter->reSmsContent = $smsbody;
         $voter->reSmsTime = $smsTime;
         $voter->save();
     }
 }