public function run() { /** * 验证用户权限 */ if (false == $this->verifyUserAuth()) { return false; } $question_tag = intval($this->getDataItem('tag_id', 0)); $question_content = Keyword::Filter($this->getDataItem('content', '')); $up = new UploadPic(); $question_pics = json_encode($up->questionPic()); if (!empty($question_content)) { $q = new Question(); $q->user_id = $this->getUserAuth()->userId; // $q->user_id = 1; $q->question_tag = $question_tag; //关键字替换 $keyword = CosQKeyword::query()->execute()->toArray(); foreach ($keyword as $k => $v) { $question_content = str_replace($v['keyword'], '***', $question_content); } //$question_content = base64_encode(serialize($question_content)); $q->question_content = $question_content; $q->question_pics = $question_pics; if ($q->save()) { $this->id = $q->question_id; $this->success = 1; SearchASync::Instance()->noticeSync($q->question_id, SearchDataType::Question); //推送消息 $phoneNum = ['15823522906', '13883156314', '18725873971', '15086691064', '18996156384', '13752904126', '18523066564', '15723278358', '18523989994', '15111992368', '18123640250', '18323868684']; foreach ($phoneNum as $k => $v) { $param = array('type' => 8, 'ispushservice' => 0, 'phone' => $v, 'content' => '有新的问题啦:' . mb_substr($question_content, 0, 10, 'utf-8') . ',快去回答吧!', 'shop_id' => 0); $push = new Jpush(); $rs = $push->setval($param); if (empty($rs)) { $push->push(); } continue; } } else { return $this->databaseErrorLog($q); } } else { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, ""); } $this->setResult(['id' => $this->id, 'success' => $this->success]); }
public function run() { /** * 验证用户权限 */ if (false == $this->verifyUserAuth()) { return false; } $question_tag = $this->getDataItem('tag', ''); $custom_tag = $this->getDataItem('custom_tag', ''); $question_content = Keyword::Filter($this->getDataItem('content', '')); $city_code = (string) $this->getDataItem('city_code', '0'); $up = new UploadPic(); if ($question_pics = $up->questionPic()) { // $question_pics = json_encode(array_slice($question_pics, 0, 3)); $question_pics = json_encode($question_pics); } else { $question_pics = json_encode([]); } if (!empty($question_content) && $city_code != '0') { $q = new Question(); $q->user_id = $this->getUserAuth()->userId; //关键字替换 $keyword = CosQKeyword::query()->execute()->toArray(); foreach ($keyword as $k => $v) { $question_content = str_replace($v['keyword'], '***', $question_content); } if ($question_tag) { $tag_id = ''; $tagList = []; foreach ($question_tag as $k => $val) { $tagList[] = $val['name']; $tag_id .= $val['id'] . ','; } $tagLists = BeautyParlorTagInfo::query()->where('tag_id in(' . trim($tag_id, ',') . ')')->execute()->toArray(); foreach ($tagLists as $val) { if ($val['parent_id'] == 0) { return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, '不能选择一级标签!'); } } if ($custom_tag) { $tagList[] = $custom_tag; } $q->question_tag = json_encode($tagList); } $q->question_content = $question_content; $q->question_pics = $question_pics; $date = date('Y-m-d H:i:s'); $q->last_reply_time = $date; $q->question_addtime = $date; $q->city_code = $city_code; if ($q->save()) { if ($question_tag) { // 保存问答的标签 $tagData = ''; foreach ($question_tag as $k => $val) { $tagData .= "({$val['id']}, '{$val["name"]}', {$q->question_id}),"; } $tagData = trim($tagData, ','); $q->getReadConnection()->query("INSERT INTO question_tag (tag_id, tag_name, question_id) VALUES {$tagData}"); } $this->id = $q->question_id; $this->success = 1; // SearchASync::Instance()->noticeSync($q->question_id, SearchDataType::Question); //推送消息 /*$phoneNum = [ '15823522906', '13883156314', '18725873971', '15086691064', '18996156384', '13752904126', '18523066564', '15723278358', '18523989994', '15111992368', '18123640250', '18323868684', ]; $push = new Jpush(); foreach($phoneNum as $k => $v){ $param = array( 'type' => 8, 'ispushservice' => 0, 'phone' => $v, 'content' => '有新的问题啦:'.mb_substr($question_content,0,10,'utf-8').',快去回答吧!', 'shop_id' => 0 ); $rs = $push -> setval($param); if(empty($rs)){ $push -> push(); } continue; }*/ // 推送测试(测试用的) $phoneNum = ['18723568681', '17790274639', '18225097233', '18723793180']; $push = new Jpush(); foreach ($phoneNum as $k => $v) { $param = array('type' => 8, 'ispushservice' => 0, 'phone' => $v, 'content' => '有新的问题啦:' . mb_substr($question_content, 0, 10, 'utf-8') . ',快去回答吧!', 'shop_id' => 0); $rs = $push->setval($param); if (empty($rs)) { $push->push(); } continue; } } else { return $this->databaseErrorLog($q); } } else { return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, ""); } $this->setResult(['id' => $this->id, 'success' => $this->success]); }
/** * 添加问题 * @date: 2016-1-15 * @author: futao */ public function addquestionAction() { $this->setLeftNav('addquestion'); $req = $this->request; if (!$req->isPost()) { $userList = UserBase::find("is_manage = 1"); $tag = BeautyParlorTagInfo::find("parent_id != 0 and tag_state = 1"); $this->view->setVar('city_list', $this->openCityList()); $this->view->setVar('userlist', $userList); $this->view->setVar('tag', $tag); $this->view->pick("question/add"); return; } $this->view->disable(); $echo = function ($msg, $state = false) { echo '<script type="text/javascript">'; echo 'parent.formResult("' . $msg . '", ' . ($state ? 1 : 0) . ')'; echo '</script>'; }; $questionContent = $req->getPost('question_content', null, ''); $questionTag = $req->getPost('question_tag', null, ''); $questionBrowsers = intval($req->getPost('question_browsers', null, 0)); $userId = intval($req->getPost('user_id', null, 0)); $cityCode = intval($req->getPost('city_id', null, 0)); if ($userId < 0 || $questionBrowsers < 0) { $echo("添加失败!"); return; } if (is_array($questionTag)) { foreach ($questionTag as $val) { $tagArr = explode(',', $val); $tagName = $tagArr[1]; $tagNameArr[] = $tagName; } } else { $echo("标签必选!"); return; } $questionModel = new Question(); //保存图片 if ($_FILES['q_photos']['name'][0] != '') { $uploadFile = new UploadPic(); $uploadFile->request = $req; $questionPics = $uploadFile->questionPic(); $questionModel->question_pics = json_encode($questionPics); } else { $questionModel->question_pics = json_encode([]); } $questionModel->question_content = $questionContent; $questionModel->city_code = $cityCode; $questionModel->question_browsers = $questionBrowsers; $questionModel->question_tag = json_encode($tagNameArr); $questionModel->user_id = $userId; if (!$questionModel->save()) { $echo("添加失败!"); return; } if ($questionTag != '' && is_array($questionTag)) { unset($tagNameArr); unset($tagName); unset($tagArr); foreach ($questionTag as $val) { unset($tagId); unset($tagName); $tagArr = explode(',', $val); $tagId = $tagArr[0]; $tagName = $tagArr[1]; $tagNameArr[] = $tagName; $questionTagModel = new QuestionTag(); $questionTagModel->question_id = $questionModel->question_id; $questionTagModel->tag_id = $tagId; $questionTagModel->tag_name = $tagName; if ($questionTagModel->save()) { $echo("添加成功!", true); } } } else { $echo("添加失败!"); return; } }