Example #1
0
 public function editorPTUploadImgAction()
 {
     $req = $this->request;
     if (!$req->isPost()) {
         $this->view->setVar('callback', $req->getQuery('callback', null, 'parent.setFormResultImg'));
         $this->view->setVar('type', $req->getQuery('type', null, ''));
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, '');
     $response->callbackJavascriptTag = true;
     $contentType = $req->getPost('content_type', null, '');
     if (in_array($contentType, ['bpService', 'activity', 'banner']) == false) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, 'type参数不支持');
         return $response;
     }
     $upload = new UploadPic();
     $upload->request = $req;
     switch ($contentType) {
         case 'bpService':
             $pics = $upload->uploadPicByFile('file', 'beauty_parlor_pics');
             if ($pics && count($pics) > 0) {
                 $response->sendResult($pics[0]);
             } else {
                 if ($_FILES['file']['error'] == 1) {
                     $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了1M!');
                 } else {
                     $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件处理异常!');
                 }
             }
             break;
         case 'activity':
             $pics = $upload->uploadPicByFile('file', 'activity_pics');
             if ($pics && count($pics) > 0) {
                 $response->sendResult($pics[0]);
             } else {
                 if ($_FILES['file']['error'] == 1) {
                     $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了1M!');
                 } else {
                     $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件处理异常!');
                 }
             }
             break;
         case 'banner':
             $pics = $upload->uploadPicByFile('file', 'banner_pics');
             if ($pics && count($pics) > 0) {
                 $response->sendResult($pics[0]);
             } else {
                 if ($_FILES['file']['error'] == 1) {
                     $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了1M!');
                 } else {
                     $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件处理异常!');
                 }
             }
             break;
     }
     return $response;
 }
Example #2
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $questionId = intval($this->getDataItem('question_id', 0));
     $question_content = Keyword::Filter($this->getDataItem('content', ''));
     $up = new UploadPic();
     $question_pics = json_encode($up->questionPic());
     if ($questionId > 0 && !empty($question_content)) {
         // 查询最大楼层
         $floor = QuestionAnswer::maximum(["column" => "answer_floor", "conditions" => "question_id = :qid:", "bind" => ["qid" => $questionId]]);
         $qa = new QuestionAnswer();
         $qa->user_id = $this->getUserAuth()->userId;
         $qa->question_id = $questionId;
         //关键字替换
         $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));
         $qa->answer_content = $question_content;
         $qa->answer_floor = ($floor ? $floor : 0) + 1;
         $qa->answer_pics = $question_pics;
         if ($qa->save()) {
             $this->id = $qa->answer_id;
             $this->success = 1;
             // 记录回答数
             Question::updateAnswerNum($questionId);
         } else {
             return $this->databaseErrorLog($qa);
         }
     } else {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "");
     }
     //回答成功,推送消息
     $num = Question::query()->columns(['b.user_account'])->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\Question.user_id=b.user_id', 'b')->where('Apps\\Common\\Models\\Question.question_id = ' . $questionId)->execute()->toArray();
     $phoneNum = $num[0]['user_account'];
     $param['type'] = 6;
     $param['ispushservice'] = 0;
     $param['phone'] = $phoneNum;
     $param['content'] = '您的问题有人回答了,快去看看吧!';
     $param['shop_id'] = 0;
     $push = new Jpush();
     $rs = $push->setval($param);
     if (!empty($rs) || empty($phoneNum)) {
         $this->setResult(['question_id' => $questionId, 'success' => $this->success, 'files_count' => count($_FILES)]);
     } else {
         $rs = $push->push();
         $this->setResult(['question_id' => $questionId, 'success' => $this->success, 'files_count' => count($_FILES)]);
     }
 }
Example #3
0
 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;
     }
     $questionId = intval($this->getDataItem('question_id', 0));
     $answer_id = intval($this->getDataItem('answer_id', 0));
     $content = Keyword::Filter($this->getDataItem('content', ''));
     $user_id = intval($this->getDataItem('user_id', 0));
     $to_user_id = intval($this->getDataItem('to_user_id', 0));
     if ($questionId == 0 || empty($content) || $user_id == 0 || $to_user_id == 0 || $user_id == $to_user_id) {
         return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, '缺少参数或参数错误,请检查!');
     }
     if (mb_strlen($content) > 300) {
         return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, '回复内容长度不能超过300字符');
     }
     // 身份检查
     if ($Question = Question::findFirst('question_id = ' . $questionId)) {
         $questionData = $Question->toArray();
     } else {
         $questionData = [];
     }
     $UserBase = new UserBase();
     if (!($questionData['user_id'] == $user_id || $UserBase->is_expert($user_id))) {
         return $this->errorLog(ResultStatus::QUERY_DATA_NOT_EXIST, '您没有权限评论!');
     }
     //关键字替换
     $keyword = CosQKeyword::query()->execute()->toArray();
     foreach ($keyword as $k => $v) {
         $content = str_replace($v['keyword'], '***', $content);
     }
     if (!$answer_id) {
         // 获取回复的id
         $QuestionAnswer = \Apps\Common\Models\QuestionAnswer::query()->where("question_id = {$questionId} and user_id = {$user_id}")->execute()->getFirst();
         $answer_id = $QuestionAnswer->answer_id ?: 0;
     }
     $up = new UploadPic();
     $data = ['question_id' => $questionId, 'answer_id' => $answer_id, 'content' => $content, 'pics' => json_encode($up->questionPic()), 'user_id' => $user_id, 'to_user_id' => $to_user_id, 'add_time' => date('Y-m-d H:i:s')];
     $QuestionAnswerComments = new QuestionAnswerComments();
     if ($QuestionAnswerComments->save($data)) {
         $this->setResult(['success' => 1, 'message' => '评论成功!']);
     } else {
         return $this->errorLog(ResultStatus::DATABASE_ERROR, '服务器异常!');
     }
 }
Example #5
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return;
     }
     $area = ['user_cover', 'user_nickname', 'user_gender', 'user_birthday', 'user_realname', 'user_district', 'persional_sign'];
     $field = $this->getDataItem('field');
     //字段
     $value = Keyword::Filter($this->getDataItem('value', ''));
     //值
     if ($field == "persional_sign") {
         if ($this->count_string_len($value) > 40) {
             return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '个性签名字数超过了40个字符');
         } else {
             $value = base64_encode(serialize($value));
         }
     }
     if (!in_array($field, $area)) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '字段名不存在.');
     }
     $fieldsArr = ['user_cover' => 'user_cover', 'user_nickname' => 'user_nickname', 'user_gender' => 'user_gender', 'user_birthday' => 'user_birthday', 'user_realname' => 'user_realname', 'persional_sign' => 'persional_sign', 'user_district' => 'user_district', 'user_money' => 'user_money', 'user_money_virtual' => 'user_money_virtual', 'user_mobile' => 'user_account'];
     $user = UserBase::findFirst('user_id=' . $this->getUserAuth()->userId);
     $f = $fieldsArr[$field];
     if ($field == 'user_cover') {
         $up = new UploadPic();
         $value = $up->userCover();
         if ($value == false) {
             return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '文件流不能为空.');
         }
     }
     $user->{$f} = $value;
     if ($user->save()) {
         $this->success = 1;
         $this->message = $field . ' 更新成功';
     }
     $this->setResult(['success' => $this->success, 'message' => $this->message]);
 }
 /**
  * 跟新活动基础信息
  * @date: 2016年1月5日 
  * @author: chenxiaolin
  */
 public function updateAction()
 {
     $this->setLeftNav('update');
     $req = $this->request;
     if (!$req->isPost()) {
         $id = intval($req->getQuery('id', null, 0));
         $this->view->setVar('id', $id);
         $this->view->setVar('openCity', SysOpenCity::find());
         $this->view->setVar('info', Activity::findFirst('activity_id = ' . $id));
         $this->view->setVar('positionList', Position::valuesExplain());
         return;
     }
     //修改
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $id = intval($req->getPost('activity_id'));
     if ($id < 1) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!');
         return $response;
     }
     $type = intval($req->getPost('activity_type', null, 0));
     $title = $req->getPost('activity_title', null, '');
     $views = $req->getPost('views');
     //$cityId = intval ( $req->getPost ( 'city_id', null, 0 ) );
     //$posion_banner = intval ( $req->getPost ( 'posion_banner', null, 0 ) );
     //$time = $req->getPost ( 'activity_time', null, '' );
     $intro = $req->getPost('activity_intro', null, '');
     $out_link = $req->getPost('out_link', null, '');
     // 判断空数据
     if ($type <= 0 || empty($title)) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!');
         return $response;
     }
     //判断是图文,还是外链地址
     if ($type == 1 && empty($intro)) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!');
         return $response;
     }
     if ($type == 2 && empty($out_link)) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!');
         return $response;
     }
     //判断外链地址是否合法
     if ($type == 2 && !Util::CheckUrl($out_link)) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '外链地址不合法!');
         return $response;
     }
     //$timeArr = explode ( ' 至 ', $time );
     // 保存封面
     $uploadFile = new UploadPic();
     $uploadFile->request = $req;
     $cover = $uploadFile->activityCover();
     if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) {
         if ($_FILES['activity_cover']['error'] == 1) {
             $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了2M!');
             return $response;
         }
     }
     $cover = $cover[0];
     /* if ($cover == false || ! is_array ( $cover ) || count ( $cover ) == 0 || $cover [0] == false) {
     			$cover = null;
     		} else {
     			$cover = $cover [0];
     		} */
     // 保存基础数据
     $info = Activity::findFirst('activity_id = ' . $id);
     $data = [];
     if ($info->activity_type != $type) {
         $data['activity_type'] = $type;
     }
     if ($info->activity_title != $title) {
         $data['activity_title'] = $title;
     }
     /* if ($info->city_id != $cityId) {//其他城市
     			//判断广告位是否存在
     			//$activity2 = Activity::findFirst('city_id = '.$cityId.' and posion_banner = '.$posion_banner);
     			$activity2 = Activity::findFirst("city_id = $cityId and posion_banner = $posion_banner and activity_state in ('1','0')");
     			if($activity2){//广告位已存在
     				$response->sendError ( ResponseResultStatus::BUSINESS, '当前城市的此广告位已存在!' );
     				return $response;
     			}
     			$data ['city_id'] = $cityId;
     			$data ['posion_banner'] = $posion_banner;
     			//推荐到其他城市时:活动状态设置
     			$curTime = time();
     			$startTime = strtotime($timeArr[0]);
     			$endTime = strtotime($timeArr[1]);
     			//1、活动开始时间大于当前时间:未发布--0
     			if(($startTime - $curTime) > 0){
     				$data ['activity_state'] = 0;
     			}elseif(($endTime - $curTime) < 0 ){
     				//2、活动结束时间小于当前时间:已结束--2
     				$data ['activity_state'] = 2;
     			}else{
     				//3、当前时间大于开始时间,小于结束时间:正常--1
     				$data ['activity_state'] = 1;
     			}
     					
     		}else{//本城市			
     			//根据城市id和广告位编号判断该城市的此广告位是否已存在
     			if($info -> posion_banner != $posion_banner){
     				//$activity = Activity::findFirst('city_id = '.$cityId.' and posion_banner = '.$posion_banner);
     				$activity = Activity::findFirst("city_id = $cityId and posion_banner = $posion_banner and activity_state in ('1','0')");
     				if($activity){//广告位已存在
     					$response->sendError ( ResponseResultStatus::BUSINESS, '当前城市的此广告位已存在!' );
     					return $response;
     				}else{//广告位可用
     					$data ['posion_banner'] = $posion_banner;
     				}
     			}			
     			$curTime = time();
     			$startTime = strtotime($timeArr[0]);
     			$endTime = strtotime($timeArr[1]);
     			//1、活动开始时间大于当前时间:未发布--0
     			if(($startTime - $curTime) > 0){
     				$data ['activity_state'] = 0;
     			}elseif(($endTime - $curTime) < 0 ){
     				//2、活动结束时间小于当前时间:已结束--2
     				$data ['activity_state'] = 2;
     			}else{
     				//3、当前时间大于开始时间,小于结束时间:正常--1
     				$data ['activity_state'] = 1;
     			}
     		} */
     if ($type == 1 && $info->activity_intro != $intro) {
         $data['activity_intro'] = $intro;
         $data['out_link'] = "";
     }
     if ($type == 2 && $info->out_link != $out_link) {
         $data['out_link'] = $out_link;
         $data['activity_intro'] = "";
     }
     if ($info->views != $views) {
         $data['views'] = $views;
     }
     /* $data ['activity_start_time'] = $timeArr [0];
     		$data ['activity_end_time'] = $timeArr [1]; */
     if ($cover != null) {
         $data['activity_cover'] = $cover;
     }
     $data['activity_update_time'] = date("Y-m-d H:i:s");
     $info->update($data);
     SearchASync::Instance()->noticeSync($id, SearchDataType::BeautyParlorService);
     $response->sendResult('ok');
     return $response;
 }
Example #7
0
 /**
  * 更新数据
  * @return ResponseResult
  */
 private function updateSave()
 {
     $req = $this->request;
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $id = intval($req->getPost('bp_id'));
     if ($id < 1) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!');
         return $response;
     }
     $name = $req->getPost('bp_name');
     $district = intval($req->getPost('bp_district', null, 0));
     $address = $req->getPost('bp_address');
     $coordinate = $req->getPost('bp_coordinate');
     $tel = $req->getPost('bp_tel');
     $isSell = intval($req->getPost('bp_is_sell', null, 0));
     $medalRefund = intval($req->getPost('bp_medal_refund', null, 0));
     $medalVerify = intval($req->getPost('bp_medal_verify', null, 0));
     $tags = $req->getPost('bp_tags');
     $ownerMobile = $req->getPost('bp_owner_mobile');
     $intro = $req->getPost('bp_intro');
     // 判断空数据
     if (empty($name) || $district <= 0 || empty($address) || empty($coordinate) || empty($tel) || empty($tags) || empty($intro) || empty($ownerMobile)) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!');
         return $response;
     }
     // 保存封面
     $uploadFile = new UploadPic();
     $uploadFile->request = $req;
     $cover = $uploadFile->beautyParlorCover();
     if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) {
         $bpCover = null;
     } else {
         $bpCover = $cover[0];
     }
     // 保存基础数据
     $coordinate = str_replace(',', ' ', $coordinate);
     $bp = BeautyParlor::findFirst('bp_id = ' . $id);
     $data = [];
     if ($bp->bp_name != $name) {
         $data['bp_name'] = $name;
     }
     if (!!$bpCover) {
         $data['bp_cover'] = $bpCover;
     }
     if ($bp->bp_address != $address) {
         $data['bp_address'] = $address;
     }
     if ($bp->bp_district != $district) {
         $data['bp_district'] = $district;
     }
     $data['bp_coordinate'] = new RawValue("GeomFromText('POINT({$coordinate})')");
     if ($bp->bp_tel != $tel) {
         $data['bp_tel'] = $tel;
     }
     if ($bp->bp_owner_mobile != $ownerMobile) {
         $data['bp_owner_mobile'] = $ownerMobile;
     }
     if ($bp->bp_intro != $intro) {
         $data['bp_intro'] = $intro;
     }
     if ($bp->bp_is_sell != $isSell) {
         $data['bp_is_sell'] = $isSell;
     }
     $data['bp_medal'] = strval($medalRefund) . strval($medalVerify);
     $bp->update($data);
     /*标签排序  */
     $tagsarr = explode(",", $tags);
     $status = BeautyParlorTag::find("bp_id = {$id}")->delete();
     if (!$status) {
         $response->sendError(ResponseResultStatus::PARAM_ERROR, '保存标签失败!');
     }
     foreach ($tagsarr as $k => $tag) {
         $taginfo = BeautyParlorTagInfo::find("tag_id = {$tag} and tag_state = 1")->toArray();
         $count = count($taginfo);
         if ($count < 1) {
             $response->sendError(ResponseResultStatus::PARAM_ERROR, '没有ID为' . $tag . '的标签!');
         }
         $tagDb = new BeautyParlorTag();
         $tagDb->bp_id = $id;
         $tagDb->tag_id = $tag;
         $tagDb->sort = $k + 1;
         if ($tagDb->save() == false) {
             $this->databaseErrorLog($tagDb);
         }
     }
     /* 
             $tagsArr = explode(',', $tags);
            	foreach($tagsArr as $tag) {
                 $tagDb = BeautyParlorTag::query()
                     ->columns('bp_tag_id, bp_id, tag_id')
                     ->where('bp_id = :bid: AND tag_id = :tid:')
                     ->bind(['bid'=>$id, 'tid'=>$tag])
                     ->execute()->getFirst();
                 if(!$tagDb) {
                     $tagDb = new BeautyParlorTag();
                     $tagDb->bp_id = $id;
                     $tagDb->tag_id = $tag;
                     if ($tagDb->save() == false) {
                         $this->databaseErrorLog($tagDb);
                     }
                 }
             } */
     // 获取所有的标签
     /* $tagList = BeautyParlorTag::query()
            ->where('bp_id = :bid:')
            ->bind(['bid'=>$id])
            ->execute();
        foreach($tagList as $t) {
            if(in_array(strval($t->tag_id), $tagsArr) == false) {
                $t->delete();
            }
        } */
     // 保存轮播图片
     // 轮播图片
     $pics = $uploadFile->beautyParlorPics();
     if ($pics) {
         foreach ($pics as $pic) {
             $picDb = new BeautyParlorPhotos();
             $picDb->beauty_parlor_id = $id;
             $picDb->photo_url = $pic;
             if ($picDb->save() == false) {
                 $this->databaseErrorLog($picDb);
             }
         }
     }
     SearchASync::Instance()->noticeSync($id, SearchDataType::BeautyParlors);
     $response->sendResult('ok');
     return $response;
 }
Example #8
0
 private function updateSave()
 {
     $req = $this->request;
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $id = intval($req->getPost('service_id'));
     if ($id < 1) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!');
         return $response;
     }
     $name = $req->getPost('service_name', null, '');
     $description = $req->getPost('service_description', null, '');
     $price = $req->getPost('service_price', null, '');
     $unit = $req->getPost('service_unit', null, '');
     $isSell = intval($req->getPost('service_is_sell', null, 0));
     $intro = $req->getPost('service_intro', null, '');
     // 判断空数据
     if (empty($name) || empty($description) || empty($price) || empty($intro)) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!');
         return $response;
     }
     // 保存封面
     $uploadFile = new UploadPic();
     $uploadFile->request = $req;
     $cover = $uploadFile->beautyParlorCover();
     if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) {
         $serviceCover = null;
     } else {
         $serviceCover = $cover[0];
     }
     // 保存基础数据
     $service = BeautyParlorService::findFirst('service_id = ' . $id);
     $data = [];
     if ($service->service_name != $name) {
         $data['service_name'] = $name;
     }
     if (!!$serviceCover) {
         $data['service_cover'] = $serviceCover;
     }
     if ($service->service_description != $description) {
         $data['service_description'] = $description;
     }
     if ($service->service_intro != $intro) {
         $data['service_intro'] = $intro;
     }
     if ($service->service_price != $price) {
         $data['service_price'] = $price;
     }
     if ($service->service_unit != $unit) {
         $data['service_unit'] = $unit;
     }
     if ($service->service_is_sell != $isSell) {
         $data['service_is_sell'] = $isSell;
     }
     $service->update($data);
     SearchASync::Instance()->noticeSync($id, SearchDataType::BeautyParlorService);
     $response->sendResult('ok');
     return $response;
 }
Example #9
0
 /**
  * 回答问题
  */
 public function answerAction()
 {
     $req = $this->request;
     if (!$req->isPost()) {
         $id = intval($req->getQuery('id', null, 0));
         // 查询他匹配的用户
         $data = OmQuestionAnswerUser::query()->columns(['qau_id', 'ub.user_id', 'ub.user_account', 'ub.user_nickname'])->leftJoin('Apps\\Common\\Models\\UserBase', 'ub.user_id = Apps\\Common\\Models\\OmQuestionAnswerUser.user_id', 'ub')->where('op_id = :opId:', ['opId' => $this->operator->id])->execute();
         $this->view->setVar('userList', $data);
         $this->view->setVar('id', $id);
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $id = intval($req->getPost('question_id', null, 0));
     if ($id <= 0) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数问题!');
         return $response;
     }
     $content = Keyword::Filter($req->getPost('answer_content', null, ''));
     $userId = intval($req->getPost('answer_user', null, 0));
     // 判断空数据
     if (empty($content) || $userId < 1) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!');
         return $response;
     }
     $up = new UploadPic();
     $questionPics = json_encode($up->questionPic());
     // 查询最大楼层
     $floor = QuestionAnswer::maximum(["column" => "answer_floor", "conditions" => "question_id = :qid:", "bind" => ["qid" => $id]]);
     $qa = new QuestionAnswer();
     $qa->user_id = $userId;
     $qa->question_id = $id;
     $qa->answer_content = $content;
     $qa->answer_floor = ($floor ? $floor : 0) + 1;
     $qa->answer_pics = $questionPics;
     if ($qa->save()) {
         // 记录回答数
         Question::updateAnswerNum($id);
         $response->sendResult($qa->answer_id);
     } else {
         $this->databaseErrorLog($qa);
         $response->sendError(ResponseResultStatus::DATABASE_ERROR, '保存数据异常!');
     }
     return $response;
 }
Example #10
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $questionId = intval($this->getDataItem('question_id', 0));
     $question_content = Keyword::Filter($this->getDataItem('content', ''));
     $city_code = $this->getDataItem('city_code', '0');
     $original_content = $this->getDataItem('original_content', '');
     if (!($question_content = trim($question_content))) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "回复内容不能为空!");
     }
     if ($questionId > 0 && !empty($question_content)) {
         if (mb_strlen($question_content) > 300) {
             return $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, '回复内容长度不能超过300字符');
         }
         //关键字替换
         $keyword = CosQKeyword::query()->execute()->toArray();
         foreach ($keyword as $k => $v) {
             $question_content = str_replace($v['keyword'], '***', $question_content);
         }
         $up = new UploadPic();
         $user_id = $this->getUserAuth()->userId;
         $type = (new UserBase())->is_expert($user_id) ? 2 : 1;
         // 用户类型(1=》普通,2=》专家)
         $data = ['question_id' => $questionId, 'user_id' => $user_id, 'answer_content' => $question_content, 'answer_pics' => json_encode($up->questionPic()), 'answer_addtime' => date('Y-m-d H:i:s'), 'city_code' => $city_code, 'type' => $type];
         if ($original_content) {
             $data['original_content'] = $original_content;
         }
         $QuestionAnswer = new QuestionAnswer();
         if ($QuestionAnswer->save($data)) {
             $this->success = 1;
             $Question = new Question();
             $Question->setAnswerNum($questionId, 1, true);
             if ($type == 2) {
                 // 修改问答为专家已回复状态
                 $Question->getReadConnection()->query('UPDATE question SET is_expert_reply = 1 WHERE question_id = ' . $questionId);
             }
         } else {
             return $this->databaseErrorLog($QuestionAnswer);
         }
     } else {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "缺少必传参数!");
     }
     //回答成功,推送消息
     $num = Question::query()->columns(['b.user_account'])->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\Question.user_id=b.user_id', 'b')->where('Apps\\Common\\Models\\Question.question_id = ' . $questionId)->execute()->toArray();
     $phoneNum = $num[0]['user_account'];
     $param['type'] = 6;
     $param['ispushservice'] = 0;
     $param['phone'] = $phoneNum;
     $param['content'] = '您的问题有人回答了,快去看看吧!';
     $param['shop_id'] = 0;
     $push = new Jpush();
     $rs = $push->setval($param);
     if (!empty($rs) || empty($phoneNum)) {
         $this->setResult(['question_id' => $questionId, 'success' => $this->success, 'files_count' => count($_FILES)]);
     } else {
         $rs = $push->push();
         $this->setResult(['question_id' => $questionId, 'success' => $this->success, 'files_count' => count($_FILES)]);
     }
 }
Example #11
0
 /**
  * 更新用户信息
  * @date: 2016-1-5 
  * @author: futao
  */
 public function editsaveAction()
 {
     $req = $this->request;
     $district = $req->getPost('district', null, '');
     $nickname = $req->getPost('nickname', null, '');
     $realname = $req->getPost('realname', null, '');
     $phone = $req->getPost('phone', null, '');
     $persional_sign = $req->getPost('persional_sign', null, '');
     $birthday = $req->getPost('birthday', null, '');
     $userId = intval($req->getPost('user_id', null, 0));
     $gender = $req->getPost('sex', null, 2);
     $experience = $req->getPost("experience", null, '');
     //从业经验
     $field = $req->getPost("field", null, '');
     //擅长领域
     $experttitle = $req->getPost("experttitle", null, '');
     //专家头衔
     $echo = function ($msg, $state = false) {
         echo '<script type="text/javascript">';
         echo 'parent.formResult("' . $msg . '", ' . ($state ? 1 : 0) . ')';
         echo '</script>';
     };
     $usermodel = UserBase::findFirst("user_id = {$userId} and is_manage = 1");
     if (!$usermodel) {
         $echo("用户不存在!");
         return;
     }
     if ($field == "" || !is_array($field)) {
         $echo("擅长领域必填!");
         return;
     }
     $data = ['experience' => $experience, 'experttitle' => $experttitle, 'field' => $field];
     $datajson = json_encode($data);
     $info = UserAttribute::findFirst("user_id = {$userId} and attr_type = 103");
     $info->attr_value_json = $datajson;
     $info->save();
     //用户头像
     if ($_FILES['avatar']['name'] != '') {
         $uploadFile = new UploadPic();
         $uploadFile->request = $req;
         $cover = $uploadFile->userCover();
         if ($cover == false) {
             if ($_FILES['avatar']['error'] == 1) {
                 $echo('封面大小超过了2M!');
             } else {
                 $echo('封面必须上传!');
             }
             return;
         }
         $usermodel->user_cover = $cover;
     }
     $usermodel->user_district = $district;
     $usermodel->user_nickname = $nickname;
     $usermodel->user_realname = $realname;
     $usermodel->bind_phone = $phone;
     //个性签名编码
     if ($persional_sign != '') {
         $usermodel->persional_sign = base64_encode(serialize($persional_sign));
     }
     //$usermodel->persional_sign=$persional_sign;
     $usermodel->user_birthday = $birthday;
     $usermodel->user_gender = $gender;
     if ($usermodel->save()) {
         $echo('ok', true);
     } else {
         $echo("添加失败!");
     }
 }
Example #12
0
 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]);
 }
Example #13
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $bp_id = intval($this->getDataItem('beauty_parlor_id', 0));
     $comment_info = Keyword::Filter($this->getDataItem('content', ''));
     $comment_info = trim($comment_info);
     //关键字替换
     $keyword = CosQKeyword::query()->execute()->toArray();
     foreach ($keyword as $k => $v) {
         $comment_info = str_replace($v['keyword'], '***', $comment_info);
     }
     //$type = intval($this -> getDataItem('type'));
     $type = $this->getDataItem('type', 0);
     //评论图片
     $up = new UploadPic();
     $comment_photos = json_encode($up->beautyParlorComment());
     if ($bp_id > 0 && !empty($comment_info)) {
         // 查询最大楼层
         $floor = BeautyParlorComment::maximum(["column" => "comment_floor", "conditions" => "beauty_parlor_id = :id: and type = 0", "bind" => ["id" => $bp_id]]);
         $comment_info = base64_encode(serialize($comment_info));
         $bpc = new BeautyParlorComment();
         $bpc->user_id = $this->getUserAuth()->userId;
         $bpc->comment_floor = ($floor ? $floor : 0) + 1;
         $bpc->beauty_parlor_id = $bp_id;
         $bpc->comment_info = $comment_info;
         $bpc->comment_photos = $comment_photos;
         $bpc->type = $type;
         if ($bpc->save()) {
             $this->id = $bpc->comment_id;
             $this->success = 1;
             return $this->setResult(['id' => $this->id, 'success' => $this->success]);
         } else {
             return $this->databaseErrorLog($bpc);
         }
     } else {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "");
     }
     /* //评论成功,推送消息
     		$branch = BeautyParlor::findFirst("bp_id = $bp_id") -> toArray();
     		$branchId = $branch['branch_id'];
     		if(empty($branchId)){//没有分店,不推送
     			return $this->setResult([
     					'id'=>$this->id,
     					'success'=>$this->success
     			]);
     		}else{
     			$num = Branch::query()
     			->columns('s.shop_uid')
     			-> leftJoin('Apps\Common\Models\CosShop','Apps\Common\Models\Branch.shop_id = s.shop_id','s')
     			-> where('Apps\Common\Models\Branch.branch_id = '.$branchId)
     			-> execute()->toArray();
     			$phoneNum = $num[0]['shop_uid'];
     			
     			$param = array(
     					'type' => 7,
     					'ispushservice' => 0,
     					'phone' => $phoneNum,
     					'content' => '有人对您的美容院进行了评论,快去看看吧!',
     					'shop_id' => 0
     			);
     			$push = new Jpush();
     			$rs = $push -> setval($param);
     			
     			if(!empty($rs)){
     				$data = json_decode($rs,true);
     				$status = $data['status'];
     				if($status == 400){//数据错误
     					return $this->setResult([
     							'id'=>$this->id,
     							'success'=>$this->success
     					]);
     				}
     			}else{
     				$rs = $push -> push();
     				
     			}
     		} */
 }
Example #14
0
 /**
  * 添加首页推荐美容院
  * @date: 2016-1-8 
  * @author: futao
  */
 public function bannerBpAddAction()
 {
     $this->setLeftNav('bannerbp');
     $req = $this->request;
     if (!$req->isPost()) {
         $this->view->setVar('bp_id', $req->getQuery('id', null, 0));
         $this->view->setVar('openCity', $this->openCityList());
         $this->view->pick("bp/bannerBpAdd");
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $bp_id = intval($req->getPost('bp_id'));
     $city = $req->getPost('city');
     $addr = $city;
     $sort = $req->getPost('sort');
     $time = $req->getPost('time');
     // 判断空数据
     if (empty($bp_id) || empty($addr) || empty($sort)) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数异常!');
         return $response;
     }
     //判断要推荐的美容是否存在
     $bp = BeautyParlor::findFirst(" bp_id = {$bp_id} and bp_state = 1");
     if (empty($bp)) {
         $response->sendError(ResponseResultStatus::BUSINESS, '当前推荐的美容院不存在或未发布或已删除!');
         return $response;
     }
     //保存推荐美容院图片
     $uploadFile = new UploadPic();
     $uploadFile->request = $req;
     $cover = $uploadFile->beautyParlorCover();
     if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) {
         if ($_FILES['bp_cover']['error'] == 1) {
             $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了1M!');
         }
         return $response;
     }
     //判断美容院是否已经存在3个
     /* if(CosPointBp::count("addr = $addr") >= 3){
       		$response->sendError(ResponseResultStatus::BUSINESS, '首页推荐美容院只能添加3个!');
       		return $response;
       	} */
     //判断要添加的美容院是否已存在
     /* if(CosPointBp::count('bp_id = ' . $bp_id.' and addr = '.$addr)){
       		$response->sendError(ResponseResultStatus::BUSINESS, '该美容院已经加入首页推荐!');
       		return $response;
       	}elseif(CosPointBp::count('sort = ' . $sort . ' and addr = '.$addr)){
       		$response->sendError(ResponseResultStatus::BUSINESS, '排序已经存在!');
       		return $response;
       	} */
     //实例化Model,组装数据
     $cosPointBp = new CosPointBp();
     $cosPointBp->bp_id = $bp_id;
     $cosPointBp->addr = $addr;
     $cosPointBp->sort = $sort;
     $cosPointBp->img_url = $cover[0];
     if ($time != '') {
         $timeArr = explode("至", $time);
         $show_start_time = trim($timeArr[0]);
         $show_end_time = trim($timeArr[1]);
         $cosPointBp->show_start_time = $show_start_time;
         $cosPointBp->show_end_time = $show_end_time;
     }
     //保存数据
     if ($cosPointBp->save() == false) {
         $this->databaseErrorLog($cosPointBp);
         $response->sendError(ResponseResultStatus::DATABASE_ERROR, '保存数据异常!');
     } else {
         $response->sendResult($cosPointBp->id);
     }
     return $response;
 }
Example #15
0
 /**
  * 编辑器上传文件
  * @date: 2016-1-18
  * @author: futao
  */
 public function uploadloalfileAction()
 {
     $this->view->disable();
     $upload = new UploadPic();
     $cover = $upload->uploadUeditorPic(APP_ROOT_PATH . $_POST['filepath'], $_POST['filename']);
     echo json_encode($cover);
 }
 /**
  *  回答问题
  * @date: 2016-1-16 
  * @author: futao
  */
 public function addanswerAction()
 {
     $this->view->disable();
     $req = $this->request;
     $type = $req->getPost('type', null, 0);
     //1:回复楼主    3:回复网友
     $userId = intval($req->getPost('user_id', null, 0));
     $answerId = intval($req->getPost('answer', null, 0));
     $questionId = intval($req->getPost('question_id', null, 0));
     $content = $req->getPost('content', null, '');
     $echo = function ($msg, $state = false) {
         echo '<script type="text/javascript">';
         echo 'parent.formResult("' . $msg . '", ' . ($state ? 1 : 0) . ')';
         echo '</script>';
     };
     if ($type == 3) {
         if ($answerId < 0) {
             $echo("参数错误!");
             return;
         }
     }
     if ($questionId < 0 || $userId < 0) {
         $echo('参数错误!');
         return;
     }
     $floor = QuestionAnswer::query()->where("question_id = {$questionId}")->orderBy("answer_id desc")->execute()->getFirst();
     if (!floor) {
         $floor = json_encode(['answer_floor' => 0]);
     }
     Question::findFirst($questionId)->update(['is_manager_reply' => 1]);
     $uploadModel = new UploadPic();
     $uploadModel->request = $req;
     $picArr = $uploadModel->questionPic();
     if ($type == 1) {
         $questionModel = new QuestionAnswer();
         $questionModel->answer_floor = $floor->answer_floor + 1;
         $questionModel->answer_content = base64_encode(serialize($content));
         $questionModel->user_id = $userId;
         $questionModel->question_id = $questionId;
         $questionModel->answer_state = 1;
         $questionModel->type = 0;
         $questionModel->answer_pics = json_encode($picArr);
         if ($questionModel->save()) {
             $echo("回复成功!", true);
         }
     } else {
         if ($type == 3) {
             $answerInfo = QuestionAnswer::findFirst($answerId);
             $questionModel = new QuestionAnswer();
             $questionModel->answer_floor = $floor->answer_floor + 1;
             $questionModel->answer_content = base64_encode(serialize($content));
             $questionModel->user_id = $userId;
             $questionModel->question_id = $questionId;
             $questionModel->answer_state = 1;
             $questionModel->type = 0;
             $questionModel->answer_pics = json_encode($picArr);
             $questionModel->original_content = $answerInfo->answer_content;
             if ($questionModel->save()) {
                 $echo('回复成功!', true);
             }
         } else {
             $echo('参数错误!');
         }
     }
 }
Example #17
0
 public function question_recommend_addAction()
 {
     $this->setLeftNav('thumbs');
     $req = $this->request;
     if (!$req->isPost()) {
         $this->view->setVar('openCity', $this->openCityList());
         $this->view->pick("question_recommend/add");
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $uploadFile = new UploadPic();
     $uploadFile->request = $req;
     $cover = $uploadFile->questionPic();
     if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) {
         if ($_FILES['bp_cover']['error'] == 1) {
             $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '文件大小超过了2M!');
         } else {
             $response->sendError(ResponseResultStatus::DATABASE_ERROR, '封面必须上传!');
         }
         return $response;
     }
     $question_cover = $cover[0];
     $q_id = intval($req->getPost("question_id"));
     $addr = $req->getPost("filterCity");
     //判断参数问题
     if ($req->getPost("sort") > 12 || $q_id < 0 || $addr <= 0) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '参数错误!');
         return $response;
     }
     //判断推荐的问题是否存在
     if (Question::count("question_id = " . $q_id) == 0) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '问题不存在!');
         return $response;
     }
     //判断推荐问题是否已经存在12个
     if (CosPointquestion::count("addr = {$addr}") >= 12) {
         $response->sendError(ResponseResultStatus::BUSINESS, '首页推荐问题只能添加12个!');
         return $response;
     }
     //判断问题是否已经推荐
     $list = CosPointquestion::query()->where("q_id = {$q_id} and addr = {$addr}")->execute()->toArray();
     if ($list) {
         $response->sendError(ResponseResultStatus::BUSINESS, '此问题已推荐!');
         return $response;
     }
     $list = CosPointquestion::query()->where("addr = " . $addr . " and sort = " . $req->getPost("sort"))->execute()->toArray();
     if ($list) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '排序已存在!');
         return $response;
     }
     $m = new CosPointquestion();
     $m->q_id = $req->getPost("question_id");
     $m->img_url = $question_cover;
     $m->addr = $req->getPost("filterCity");
     $m->sort = $req->getPost("sort");
     $m->title = $req->getPost("title");
     $id = $m->save();
     if ($id === false) {
         $response->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '添加失败!');
     } else {
         $response->sendResult($id);
     }
     return $response;
 }
Example #18
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $bp_id = intval($this->getDataItem('beauty_parlor_id', 0));
     $appoint_id = intval($this->getDataItem('appoint_id', 0));
     $comment_info = Keyword::Filter($this->getDataItem('content', ''));
     //关键字替换
     $keyword = CosQKeyword::query()->execute()->toArray();
     foreach ($keyword as $k => $v) {
         $comment_info = str_replace($v['keyword'], '***', $comment_info);
     }
     $comment_info = base64_encode(serialize($comment_info));
     //$type = intval($this -> getDataItem('type'));
     $type = $this->getDataItem('type');
     //评论图片
     $up = new UploadPic();
     $comment_photos = json_encode($up->beautyParlorComment());
     if ($type !== null && $type >= 0 && in_array($type, array(0, 1))) {
         if ($type == 0) {
             //添加美容院评论
             if ($bp_id > 0 && !empty($comment_info)) {
                 // 查询最大楼层
                 $floor = BeautyParlorComment::maximum(["column" => "comment_floor", "conditions" => "beauty_parlor_id = :id: and type = 0", "bind" => ["id" => $bp_id]]);
                 $bpc = new BeautyParlorComment();
                 $bpc->user_id = $this->getUserAuth()->userId;
                 $bpc->comment_floor = ($floor ? $floor : 0) + 1;
                 $bpc->beauty_parlor_id = $bp_id;
                 $bpc->comment_info = $comment_info;
                 $bpc->comment_photos = $comment_photos;
                 $bpc->type = $type;
                 if ($bpc->save()) {
                     $this->id = $bpc->comment_id;
                     $this->success = 1;
                 } else {
                     return $this->databaseErrorLog($bpc);
                 }
             } else {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "");
             }
             //评论成功,推送消息
             $branch = BeautyParlor::findFirst("bp_id = {$bp_id}")->toArray();
             $branchId = $branch['branch_id'];
             if (empty($branchId)) {
                 //没有分店,不推送
                 return $this->setResult(['id' => $this->id, 'success' => $this->success]);
             } else {
                 $num = Branch::query()->columns('s.shop_uid')->leftJoin('Apps\\Common\\Models\\CosShop', 'Apps\\Common\\Models\\Branch.shop_id = s.shop_id', 's')->where('Apps\\Common\\Models\\Branch.branch_id = ' . $branchId)->execute()->toArray();
                 $phoneNum = $num[0]['shop_uid'];
                 $param = array('type' => 7, 'ispushservice' => 0, 'phone' => $phoneNum, 'content' => '有人对您的美容院进行了评论,快去看看吧!', 'shop_id' => 0);
                 $push = new Jpush();
                 $rs = $push->setval($param);
                 if (!empty($rs)) {
                     $data = json_decode($rs, true);
                     $status = $data['status'];
                     if ($status == 400) {
                         //数据错误
                         return $this->setResult(['id' => $this->id, 'success' => $this->success]);
                     }
                 } else {
                     $rs = $push->push();
                     return $this->setResult(['id' => $this->id, 'success' => $this->success]);
                 }
             }
         }
         if ($type == 1) {
             //添加预约评论
             if ($bp_id > 0 && $appoint_id > 0 && !empty($comment_info)) {
                 //判断预约是否已被当前用户评论
                 $is_comment = BeautyParlorComment::count(["conditions" => "appointment_id = :id: and beauty_parlor_id = :bp_id: and user_id = :user_id:", "bind" => ["id" => $appoint_id, "bp_id" => $bp_id, "user_id" => $this->getUserAuth()->userId]]);
                 if ($is_comment > 0) {
                     //已评论
                     return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "预约已评论");
                 } else {
                     //查询最大楼层
                     $floor = BeautyParlorComment::maximum(["column" => "comment_floor", "conditions" => "appointment_id = :id: and beauty_parlor_id = :bp_id:", "bind" => ["id" => $appoint_id, "bp_id" => $bp_id]]);
                     $bpc = new BeautyParlorComment();
                     $query = new CosOnlineAppointment();
                     $appoint = $query->findFirst("id = {$appoint_id}");
                     if ($appoint) {
                         $data['state'] = 1;
                         $rs = $appoint->update($data);
                     } else {
                         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "当前预约不存在");
                     }
                     $bpc->user_id = $this->getUserAuth()->userId;
                     $bpc->comment_floor = ($floor ? $floor : 0) + 1;
                     $bpc->beauty_parlor_id = $bp_id;
                     $bpc->comment_info = $comment_info;
                     $bpc->comment_photos = $comment_photos;
                     $bpc->type = $type;
                     $bpc->appointment_id = $appoint_id;
                     if ($bpc->save() && $rs) {
                         $this->id = $bpc->comment_id;
                         $this->success = 1;
                     } else {
                         return $this->databaseErrorLog($bpc);
                     }
                 }
             } else {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "");
             }
             return $this->setResult(['id' => $this->id, 'success' => $this->success]);
         }
     } else {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, "评论类型错误");
     }
     /*  $bp_id = intval($this->getDataItem('beauty_parlor_id',0));
             $comment_info = Keyword::Filter($this->getDataItem('content',''));
             $up = new UploadPic();
             $comment_photos = json_encode($up->beautyParlorComment());
     
             if($bp_id > 0 && !empty($comment_info)) {
                 // 查询最大楼层
                 $floor = BeautyParlorComment::maximum([
                     "column" => "comment_floor",
                     "conditions" => "beauty_parlor_id = :id:",
                     "bind" => [
                         "id" => $bp_id
                     ]
                 ]);
                 //关键字替换
                 $keyword = CosQKeyword::query() -> execute() -> toArray();
                 foreach ($keyword as $k => $v){
                 	
                 	$comment_info = str_replace($v['keyword'], '***', $comment_info);
                 	//$comment_info = str_replace($v['keyword'], str_repeat('*', strlen($v['keyword'])/3), $comment_info);
                 	
                 }
     
                 $bpc = new BeautyParlorComment();
                 $bpc->user_id = $this->getUserAuth()->userId;
                 $bpc->comment_floor = ($floor ? $floor : 0) + 1;
                 $bpc->beauty_parlor_id=$bp_id;
                 $bpc->comment_info=$comment_info;
                 $bpc->comment_photos=$comment_photos;
                 if($bpc->save()){
                     $this->id = $bpc->comment_id;
                     $this->success = 1;
                 }else{
                     return $this->databaseErrorLog($bpc);
                 }
             } 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;
     }
 }
Example #20
0
 public function run()
 {
     /**
      * 验证用户权限
      */
     if (false == $this->verifyUserAuth()) {
         return false;
     }
     $area = ['user_cover', 'user_nickname', 'user_gender', 'user_birthday', 'user_realname', 'user_district', 'persional_sign'];
     $field = $this->getDataItem('field');
     //字段
     $value = trim($this->getDataItem('value', ''));
     //值
     if (!in_array($field, $area)) {
         return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '字段名不存在.');
     }
     if ($user = UserBase::findFirst('user_id=' . $this->getUserAuth()->userId)) {
         if ($field == 'user_cover') {
             $up = new UploadPic();
             $user->user_cover = $up->userCover();
             if (!$user->user_cover) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '文件流不能为空.');
             }
             $value = PicUrl::UserCover($user->user_cover, $this->getDi());
         } elseif ($field == 'user_district') {
             if (!is_numeric($value)) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '城市格式错误.');
             }
             if (!\Apps\Common\Models\SysAreaZipDistrictPhonecode::count('K_ID = ' . $value)) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '城市不存在.');
             }
             $user->user_district = $value;
             // 获取城市信息
             $city = (new SysAreaZipDistrictPhonecode())->getOne($value);
             $value = $city['FULL_NAME'] ?: '';
         } elseif ($field == 'persional_sign') {
             if ($value && $this->utf8_strlen($value) > 30) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '个性签名字数超过了30个字符');
             } else {
                 $user->persional_sign = $value ? base64_encode(serialize($value)) : '';
             }
         } elseif ($field == 'user_nickname') {
             $nicknameLength = $this->utf8_strlen($value);
             if ($nicknameLength < 1 || $nicknameLength > 10) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '昵称长度需在1~10字节之间');
             }
             $user->user_nickname = $value;
         } elseif ($field == 'user_realname') {
             if (empty($value)) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '姓名不能为空');
             }
             if ($this->utf8_strlen($value) > 10) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '姓名不能超过10个字符');
             }
             $user->user_realname = $value;
         } elseif ($field == 'user_gender') {
             if (!in_array($value, ['0', '1', '2'])) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '请输入正确的性别');
             }
             $user->user_gender = $value;
         } elseif ($field == 'user_birthday') {
             if (!$this->validateDate($value)) {
                 return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '日期格式错误');
             }
             $user->user_birthday = $value;
         }
         if ($user->save()) {
             $this->setResult(['success' => 1, 'message' => $field . ' 更新成功', 'value' => $value]);
             return true;
         }
     }
     $this->setResult(['success' => 0, 'message' => '更新失败', 'value' => '']);
 }
 /**
  * 添加美粒宝典
  * @date: 2016年1月4日 
  * @author: chenxiaolin
  */
 public function addAction()
 {
     $this->setLeftNav('add');
     $req = $this->request;
     if (!$req->isPost()) {
         $this->view->setVar('openCity', SysOpenCity::find('city_state = 1'));
         $this->view->setVar("action", '/beautycanon/add');
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $uploadFile = new UploadPic();
     $uploadFile->request = $req;
     $cover = $uploadFile->beautyParlorCover();
     //保存封面图片
     if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) {
         if ($_FILES['bp_cover']['error'] == 1) {
             $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '封面大小超过了1M!');
         } else {
             $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '封面必须上传!');
         }
         return;
     }
     $title = $req->getPost("title");
     $content = $req->getPost("content");
     $fit = $req->getPost("fit");
     $assist = $req->getPost("assist");
     $city = $req->getPost("city");
     $summary = $req->getPost('summary');
     $url = $cover[0];
     $state = 1;
     //循环添加数据
     foreach ($city as $k => $v) {
         $beautyCanon = new CosBeautyCanon();
         $beautyCanon->content = $content;
         $beautyCanon->img_url = $url;
         $beautyCanon->title = $title;
         $beautyCanon->state = $state;
         $beautyCanon->fit = $fit;
         $beautyCanon->assist = $assist;
         $beautyCanon->settime = date("Y-m-d H:i:s");
         $beautyCanon->summary = $summary;
         $beautyCanon->city_id = $v;
         $status = $beautyCanon->save();
         //添加数据失败
         if ($status == false) {
             $this->databaseErrorLog($status);
             $response->sendError(ResponseResultStatus::DATABASE_ERROR, '保存数据异常!');
         }
     }
     $response->sendResult('ok');
     return $response;
 }
 public function addAction()
 {
     $req = $this->request;
     if (!$req->isPost()) {
         $this->view->setVar("action", '/beautycanon/add');
         $this->view->pick("beautycanon/ListEditBase");
         return;
     }
     $response = new ResponseResult();
     $response->callback = $req->getPost('callback', null, 'parent.setFormResult');
     $response->callbackJavascriptTag = true;
     $uploadFile = new UploadPic();
     $uploadFile->request = $req;
     $cover = $uploadFile->beautyParlorCover();
     if ($cover == false || !is_array($cover) || count($cover) == 0 || $cover[0] == false) {
         if ($_FILES['bp_cover']['error'] == 1) {
             $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '封面大小超过了2M!');
         } else {
             $response->sendError(ResponseResultStatus::UPLOAD_FILE_ERROR, '封面必须上传!');
         }
         return;
     }
     $title = $req->getPost("title");
     $content = $req->getPost("content");
     $url = $cover[0];
     $state = 1;
     $BeautyCanon = new CosBeautyCanon();
     $BeautyCanon->content = $content;
     $BeautyCanon->img_url = $url;
     $BeautyCanon->title = $title;
     $BeautyCanon->state = $state;
     $status = $BeautyCanon->save();
     $response->sendResult('ok');
     return $response;
 }