Ejemplo n.º 1
0
 public function invoke($arrInput)
 {
     //用于登录
     $row = array();
     $row['type'] = $arrInput['type'];
     $row['title'] = $arrInput['title'];
     $cids = $arrInput['cids'];
     if ($arrInput['content']) {
         $row['content'] = stripslashes($arrInput['content']);
     }
     if ($arrInput['ria_content']) {
         $row['ria_content'] = stripslashes($arrInput['ria_content']);
     }
     if (is_numeric($arrInput['start_time'])) {
         $row['start_time'] = intval($arrInput['start_time']);
     } else {
         $row['start_time'] = strtotime($arrInput['start_time']);
     }
     if (is_numeric($arrInput['stop_time'])) {
         $row['stop_time'] = intval($arrInput['stop_time']);
     } else {
         $row['stop_time'] = strtotime($arrInput['stop_time']);
     }
     if (isset($arrInput['is_push'])) {
         $row['is_push'] = $arrInput['is_push'];
     } else {
         $row['is_push'] = 0;
     }
     $row['push_title'] = $arrInput['push_title'] ? $arrInput['push_title'] : '';
     $row['cid'] = 0;
     $row['os'] = isset($arrInput['os']) ? $arrInput['os'] : -1;
     if (isset($arrInput['push_cond']) && $arrInput['push_cond'] == 0 && $arrInput['app_version']) {
         //按版本推送
         $row['app_version'] = $arrInput['app_version'];
     } else {
         //按城市推送
         $city_ids = array();
         if ($cids) {
             //过略重复,避免重复推送
             foreach ($cids as $k => $v) {
                 $v = intval($v);
                 if ($v == 0) {
                     //全国
                     $city_ids = array();
                     break;
                 }
                 $city_ids[$v] = $v;
             }
         }
         if ($city_ids) {
             sort($city_ids);
             $opt['city_list'] = $city_ids;
             $row['opt'] = json_encode($opt);
         }
     }
     $row['position'] = $arrInput['position'] ? $arrInput['position'] : 0;
     if ($arrInput['link']) {
         $row['link'] = $arrInput['link'];
     }
     if ($arrInput['from_title']) {
         $row['from_type'] = 1;
         $row['from_title'] = $arrInput['from_title'];
     }
     foreach ($_FILES as $k => $v) {
         if ($v['error'] === 0) {
             //文件上传成功
             if (strpos($v['type'], 'image') !== 0) {
                 return array('errno' => 1, "errmsg" => '上传文件不是图片');
             }
             $imgurl = Net_Util::uploadPic($v);
             if ($imgurl === false) {
                 return array('errno' => 1, "errmsg" => "图片上传百度云失败");
             }
             $row[$k] = $imgurl;
         }
     }
     $row['status'] = isset($arrInput['status']) ? $arrInput['status'] : 0;
     $dataService = new Service_Data_Message_V2_Message();
     $ret = $dataService->addMessage($row);
     if ($ret) {
         // 如果是来自情报系统,则需要反调其接口通知状态
         if ($arrInput['timestamp']) {
             $callRet = Net_Util::updateIntelligenceStatus($arrInput['timestamp'], 2);
             if (!$callRet) {
                 $errmsg = "\\n通知情报系统失败";
             }
         }
         //获取短连接
         $lastId = $dataService->getInsertId();
         $linkInfo['id'] = $lastId;
         $linkInfo['type'] = $row['type'];
         $linkInfo['origin'] = 'share';
         $messgeLink = Net_Util::getMessageLink($linkInfo);
         $update['opt'] = $opt['shortUrl'] = Net_Util::shortUrl($messgeLink);
         $ret = $dataService->updateMessage($lastId, $update);
         return array('errno' => 0, 'errmsg' => '添加成功' . $errmsg);
     }
     return array('errno' => 1, 'errmsg' => '添加失败' . $errmsg);
 }