diff --git a/.env b/.env
new file mode 100644
index 0000000..39fcbb1
--- /dev/null
+++ b/.env
@@ -0,0 +1,7 @@
+[email]
+;发送建议邮件邮箱
+send_email = tmrweb@tmrjournals.com
+send_email_password = Wu999999tmrwe
+
+;审核建议邮箱
+editor_email = publisher@tmrjournals.com
\ No newline at end of file
diff --git a/application/api/common.php b/application/api/common.php
index b3d9bbc..c34ba2f 100644
--- a/application/api/common.php
+++ b/application/api/common.php
@@ -1 +1,14 @@
';
+ $content .= 'Thank you for contacting TMR Publishing Group Service Center.
'.'Case ID:'.$caseId.'
';
+ $content .='You will receive a response to your inquiry or suggestion shortly.
' ;
+ $content .='Please use your case number: '.$caseId.' for future reference regarding this inquiry.
' ;
+ $content .='Thank you for your support.
' ;
+ $content .='Sincerely,
TMR Publishing Group Service Center
'.date('Y-m-d H:i:s') ;
+ return $content;
+}
+
diff --git a/application/api/controller/Suggest.php b/application/api/controller/Suggest.php
new file mode 100644
index 0000000..326d877
--- /dev/null
+++ b/application/api/controller/Suggest.php
@@ -0,0 +1,300 @@
+problem_obj = Db::name('problem');
+ $this->suggest_obj = Db::name('suggest');
+ $this->user_obj = Db::name('user');
+ }
+
+ /**
+ * @title 获取问题列表
+ * @description 获取问题列表
+ * @author wangzhaocui
+ * @url /api/Suggest/getProblem
+ * @method POST
+ *
+ *
+ * @return problem_id:问题ID#
+ * @return problem_title:问题title#
+ *
+ */
+ public function getProblem(){
+ if (!Request::instance()->isPost()){
+ return json(['code'=>1,'msg'=>"Request method error"]);
+ }
+ $res = $this->problem_obj->where('problem_title_state',0)->field('problem_id,problem_title')->select();
+ return jsonSuccess($res);
+ }
+ /**
+ * @title 新增问题列表选项
+ * @description 新增问题列表选项
+ * @author wangzhaocui
+ * @url /api/Suggest/addProblem
+ * @method POST
+ *
+ * @param name:problem_title type:string require:1 desc:标题
+ * @param name:problem_press type:string require:1 desc:出版集团
+ * @param name:problem_type type:string require:1 desc:类型
+ *
+ * @return problem_id:问题ID#
+ * @return problem_title:问题title#
+ *
+ */
+ public function addProblem(){
+ $data = $this->request->post();
+ // 验证规则
+ $rule = new Validate([
+ 'problem_title'=>'require',
+ 'problem_press'=>'require',
+ 'problem_type'=>'require'
+ ]);
+ if(!$rule->check($data)){
+ return json(['code' => 1,'msg'=>$rule->getError()]);
+ }
+ $insert=[
+ 'problem_title'=>$data['problem_title'],
+ 'problem_press'=>$data['problem_press'],
+ 'problem_type'=>$data['problem_type'],
+ 'problem_ctime'=>time(),
+ ];
+ $this->problem_obj->insert($insert);
+ return jsonSuccess([]);
+
+ }
+
+ public function updateProblem(){
+ $data = $this->request->post();
+ // 验证规则
+ $rule = new Validate([
+ 'problem_id'=>'require|number',
+ 'problem_title'=>'require',
+ 'problem_press'=>'require',
+ 'problem_type'=>'require',
+ 'problem_title_state'=>'require|number'
+ ]);
+ if(!$rule->check($data)){
+ return json(['code' => 1,'msg'=>$rule->getError()]);
+ }
+ $this->problem_obj->where('problem_id',$data['problem_id'])->update($data);
+ return jsonSuccess([]);
+
+ }
+ /**
+ * @title 提交建议
+ * @description 提交建议
+ * @author wangzhaocui
+ * @url /api/Suggest/addSuggest
+ * @method POST
+ *
+ * @param name:user_id type:int require:1 desc:用户id
+ * @param name:problem_id type:int require:1 desc:问题id
+ * @param name:suggest_desc type:string require:1 desc:问题描述
+ * @param name:img type:file require:0 desc:问题图片
+ */
+
+ public function addSuggest(){
+ $data = $this->request->post();
+ // 验证规则
+ $rule = new Validate([
+ 'user_id'=>'require|number',
+ 'problem_id'=>'require|number',
+ 'suggest_desc'=>'require'
+ ]);
+ if(!$rule->check($data)){
+ return json(['code' => 1,'msg'=>$rule->getError()]);
+ }
+ $insert=[
+ 'user_id'=>$data['user_id'],
+ 'problem_id'=>$data['problem_id'],
+ 'suggest_desc'=>$data['suggest_desc'],
+ 'suggest_ctime'=>time()
+ ];
+ $file = request()->file('img');
+ if($file){
+ $info = $file->move(ROOT_PATH . 'public' . DS . 'suggest');
+ if($info){
+ // 输出 suggest/20160820/42a79759f284b767dfcb2a0197904287.jpg
+ $icon = 'suggest/'.str_replace("\\", "/", $info->getSaveName());
+ $insert['suggest_url'] = $icon;
+ }else{
+ // 上传失败获取错误信息
+ return json(['code'=>1,'msg'=>$file->getError()]);
+ }
+ }
+ $userEmail = $this->user_obj->where('user_id',$data['user_id'])->field('email,realname')->find();
+
+ $problemInfo = $this->problem_obj->where(['problem_id'=>$data['problem_id'],'problem_title_state'=>0])->find();
+
+ //建议写入数据表
+ $id = $this->suggest_obj->insertGetId($insert);
+
+ $caseId = $problemInfo['problem_press'].'-'.$problemInfo['problem_type'].'-'.date('Ymd').'-'.sprintf("%03d", $id);
+
+ // 给用户发送感谢邮件
+ $sendUser = self::sendEmailForUser($data['user_id'],$userEmail['email'],$userEmail['realname'],$caseId,$insert);
+
+ // 给编辑发送邮件
+ $sendEditor = self::sendEmailForEditor();
+ $isUserPushed = Queue::push('app\api\job\domail@fire',$sendUser,'domail');
+ $isEditorPushed = Queue::push('app\api\job\domail@fire',$sendEditor,'domail');
+ return jsonSuccess([]);
+ }
+
+
+ /**
+ * @title 获取建议列表和搜索
+ * @description 获取建议列表和搜索
+ * @author wangzhaocui
+ * @url /api/Suggest/getSuggestList
+ * @method POST
+ *
+ * @param name:pageIndex type:int require:1 desc:页数
+ * @param name:pageSize type:int require:1 desc:条数
+ * @param name:problem_id type:int require:0 desc:问题id
+ * @param name:suggest_state type:int require:0 desc:状态
+ *
+ * @return data:建议#
+ * @return total:总数#
+ *
+ */
+
+ public function getSuggestList(){
+ $data = $this->request->post();
+ // 验证规则
+ $rule = new Validate([
+ 'pageIndex'=>'require|number',
+ 'pageSize'=>'require|number'
+ ]);
+ if(!$rule->check($data)){
+ return json(['code' => 1,'msg'=>$rule->getError()]);
+ }
+ $where=[];
+ if(isset($data['problem_id']) && $data['problem_id']>0){
+ $where['t_suggest.problem_id'] = $data['problem_id'];
+ }
+ if(isset($data['suggest_state']) && $data['suggest_state']>=0){
+ $where['t_suggest.suggest_state'] = $data['suggest_state'];
+ }
+ $res['data'] = $this->suggest_obj->field('t_suggest.*,t_user.realname,t_problem.problem_title')
+ ->join('t_user','t_user.user_id = t_suggest.user_id','RIGHT')
+ ->join('t_problem','t_problem.problem_id = t_suggest.problem_id','RIGHT')
+ ->where($where)
+ ->page($data['pageIndex'],$data['pageSize'])
+ ->select();
+ $res['total'] = $this->suggest_obj->where($where)->count();
+ return jsonSuccess($res);
+ }
+
+
+ /**
+ * @title 查看建议详情
+ * @description 查看建议详情
+ * @author wangzhaocui
+ * @url /api/Suggest/getSuggestDetail
+ * @method POST
+ *
+ * @param name:suggest_id type:int require:1 desc:建议id
+ *
+ */
+
+ public function getSuggestDetail(){
+ $data = $this->request->post();
+ // 验证规则
+ $rule = new Validate([
+ 'suggest_id'=>'require|number'
+ ]);
+ if(!$rule->check($data)){
+ return json(['code' => 1,'msg'=>$rule->getError()]);
+ }
+ $res = $this->suggest_obj->field('t_suggest.*,t_user.realname,t_problem.problem_title')
+ ->join('t_user','t_user.user_id = t_suggest.user_id','RIGHT')
+ ->join('t_problem','t_problem.problem_id = t_suggest.problem_id','RIGHT')
+ ->where(['t_suggest.suggest_id'=>$data['suggest_id']])
+ ->find();
+ return jsonSuccess($res);
+ }
+
+ /**
+ * @title 审核建议
+ * @description 审核建议
+ * @author wangzhaocui
+ * @url /api/Suggest/updateSuggest
+ * @method POST
+ *
+ * @param name:suggest_id type:int require:1 desc:建议id
+ *
+ */
+ public function updateSuggest(){
+ $data = $this->request->post();
+ // 验证规则
+ $rule = new Validate([
+ 'suggest_id'=>'require|number'
+ ]);
+ if(!$rule->check($data)){
+ return json(['code' => 1,'msg'=>$rule->getError()]);
+ }
+ // 先查看这条建议是否被审核
+ $state = $this->suggest_obj->where('suggest_id',$data['suggest_id'])->find();
+ if($state['suggest_state']==1 ){
+ return json(['code' => 1,'msg'=>'please do not review again']);
+ }
+ $res = $this->suggest_obj->where('suggest_id',$data['suggest_id'])->update(['suggest_state'=>1]);
+ return jsonSuccess([]);
+ }
+
+
+ private function sendEmailForUser($userID,$email,$realname,$caseId,$insert){
+ $sendData=[
+ 'sendEmail'=>Env::get('email.send_email'), // 发件人邮箱
+ 'sendPassword'=>Env::get('email.send_email_password'), // 发件人密码
+ 'user_id'=>$userID, //收件人ID
+ 'email'=>$email,// 收件人邮箱
+ 'title'=>'TMR', // 邮件标题
+ 'content'=>getUserEmail($realname,$caseId),//邮件内容
+ ];
+ if(isset($insert['suggest_url'])){
+ $sendData['is_attachment'] = 1;
+ $sendData['attachment_url'] = $insert['suggest_url'];
+ }
+
+ return $sendData;
+ }
+
+ private function sendEmailForEditor(){
+ $editorData=[
+ 'sendEmail'=>Env::get('email.send_email'), // 发件人邮箱
+ 'sendPassword'=>Env::get('email.send_email_password'), // 发件人密码
+ 'user_id'=>0,
+ 'email'=>Env::get('email.editor_email'),// 收件人邮箱
+ 'title'=>'TMR', // 邮件标题
+ 'content'=>"Dear editor, please check the new feedback.",//邮件内容
+ ];
+ return $editorData;
+ }
+}
\ No newline at end of file
diff --git a/application/api/job/domail.php b/application/api/job/domail.php
new file mode 100644
index 0000000..501f57f
--- /dev/null
+++ b/application/api/job/domail.php
@@ -0,0 +1,54 @@
+send($data);
+ $job->delete();
+
+ }
+
+ /**
+ * 发送邮件的逻辑
+ * @param type $data
+ */
+ public function send($data){
+ $res = sendEmail($data['email'],$data['title'],$data['title'],$data['content'],$data['sendEmail'],$data['sendPassword']);
+ $insert = [
+ 'title'=>$data['title'],
+ 'content'=>$data['content'],
+ 'recive_id'=>$data['user_id'],
+ 'recive_email'=>$data['email'],
+ 'journal_email'=>$data['sendEmail'],
+ 'journal_password'=>$data['sendPassword'],
+ 'create_time'=>time()
+ ];
+ if(isset($data['attachment_url'])){
+ $insert['is_attachment'] = 1;
+ $insert['attachment_url'] = $data['attachment_url'];
+ }
+ if($res['status']==1){
+ $info = Db::name('email')->insert($insert);
+ if(!$info){
+ Log::write($insert,'thanksEmailError');
+ }
+ return true;
+ }else{
+ $insert['is_success'] = 0;
+ $insert['fail_reason'] = $res['data'];
+ $info = Db::name('email')->insert($insert);
+ if(!$info){
+ Log::write($insert,'thanksEmailError');
+ }
+ return false;
+ }
+ }
+
+}