SentPrController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\SentPr;
  4. use App\Models\Channel;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Http;
  7. class SentPrController extends Controller
  8. {
  9. /**
  10. * Display a listing of the resource.
  11. *
  12. * @return \Illuminate\Http\Response
  13. */
  14. public function index()
  15. {
  16. //
  17. }
  18. /**
  19. * Store a newly created resource in storage.
  20. *
  21. * @param \Illuminate\Http\Request $request
  22. * @return \Illuminate\Http\Response
  23. */
  24. public function store(Request $request)
  25. {
  26. //
  27. if(!isset($_COOKIE['user_uid'])){
  28. return $this->error('not login');
  29. }else{
  30. $user_uid = $_COOKIE['user_uid'];
  31. }
  32. $data = $request->all();
  33. #查询是否存在
  34. #同样的内容只能提交一次
  35. $exists = SentPr::where('book_id',$data['book'])
  36. ->where('paragraph',$data['para'])
  37. ->where('word_start',$data['begin'])
  38. ->where('word_end',$data['end'])
  39. ->where('content',$data['text'])
  40. ->where('channel_uid',$data['channel'])
  41. ->exists();
  42. if(!$exists){
  43. #不存在,新建
  44. $new = new SentPr();
  45. $new->id = app('snowflake')->id();
  46. $new->book_id = $data['book'];
  47. $new->paragraph = $data['para'];
  48. $new->word_start = $data['begin'];
  49. $new->word_end = $data['end'];
  50. $new->channel_uid = $data['channel'];
  51. $new->editor_uid = $user_uid;
  52. $new->content = $data['text'];
  53. $new->language = Channel::where('uid',$data['channel'])->value('lang');
  54. $new->status = 1;//未处理状态
  55. $new->strlen = mb_strlen($data['text'],"UTF-8");
  56. $new->create_time = time()*1000;
  57. $new->modify_time = time()*1000;
  58. $new->save();
  59. }
  60. $webHookMessageOk=false;
  61. $webHookMessage=false;
  62. if(app()->isLocal()==false){
  63. /*
  64. 初译:e5bc5c97-a6fb-4ccb-b7df-be6dcfee9c43
  65. 模版:#用户名 就“##该句子巴利前20字符##”提出了这样的修改建议:“##PR内容前20字##”,欢迎大家[点击链接](句子/段落链接)前往查看并讨论。
  66. 问题集:8622ad73-deef-4525-8e8e-ba3f1462724e
  67. 模版:#用户名 就 “##该句子巴利前20字符##”有这样的疑问:“##PR内容前20字##”,欢迎大家[点击链接](句子/段落链接)参与讨论。
  68. 初步答疑:5ab653d7-1ae3-40b0-ae07-c3d530a2a8f8
  69. 模版:#用户名 就“##该句子巴利前20字符##”中的问题做了这样的回复:“##PR内容前20字##”,欢迎大家[点击链接](句子/段落链接)前往查看并讨论。
  70. 机器人地址:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=25dbd74f-c89c-40e5-8cbc-48b1ef7710b8
  71. 项目范围:
  72. book65 par:829-1306
  73. book67 par:759-1152
  74. */
  75. $username = '';
  76. $palitext = '';
  77. $prtext = '';
  78. $link = '';
  79. if(($data['book']==65 && $data['para']>=829 && $data['para']<=1306) || ($data['book']== 67 && $data['para'] >= 759 && $data['para'] <= 1152)){
  80. switch ($data['channel']) {
  81. case 'e5bc5c97-a6fb-4ccb-b7df-be6dcfee9c43':
  82. $strMessage = "wikipali: {$username} 就“{$palitext}”提出了这样的修改建议:“{$prtext}”,欢迎大家[点击链接]({$link})前往查看并讨论。";
  83. break;
  84. case '8622ad73-deef-4525-8e8e-ba3f1462724e':
  85. $strMessage = "wikipali: {$username} 就“{$palitext}”有这样的疑问:“{$prtext}”,欢迎大家[点击链接]({$link})前往查看并讨论。";
  86. break;
  87. case 'e5bc5c97-a6fb-4ccb-b7df-be6dcfee9c43':
  88. $strMessage = "wikipali: {$username} 就“{$palitext}”中的问题做了这样的回复:“{$prtext}”,欢迎大家[点击链接]({$link})前往查看并讨论。";
  89. break;
  90. default:
  91. $strMessage = "";
  92. break;
  93. }
  94. $url = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=25dbd74f-c89c-40e5-8cbc-48b1ef7710b8";
  95. $param = [
  96. "actionCard"=> [
  97. "title"=> "修改建议",
  98. "text"=> " wikipali: 来自{$_COOKIE['user_uid']}的修改建议:{$data['text']}",
  99. "btnOrientation"=> "0",
  100. "singleTitle" => "详情",
  101. "singleURL"=>"https://staging.wikipali.org/app/article/index.php?view=para&book={$data['book']}&par={$data['para']}&channal={$data['channel']}&display=sent&mode=edit"
  102. ],
  103. "msgtype"=>"actionCard"
  104. ];
  105. $response = Http::post($url, $param);
  106. $webHookMessage = $response->body;
  107. if($response->successful()){
  108. $robotMessageOk = true;
  109. }else{
  110. $robotMessageOk = false;
  111. }
  112. }
  113. }
  114. #同时返回此句子pr数量
  115. $info['book_id'] = $data['book'];
  116. $info['paragraph'] = $data['para'];
  117. $info['word_start'] = $data['begin'];
  118. $info['word_end'] = $data['end'];
  119. $info['channel_uid'] = $data['channel'];
  120. $count = SentPr::where('book_id' , $data['book'])
  121. ->where('paragraph' , $data['para'])
  122. ->where('word_start' , $data['begin'])
  123. ->where('word_end' , $data['end'])
  124. ->where('channel_uid' , $data['channel'])
  125. ->count();
  126. return $this->ok(["new"=>$info,"count"=>$count]);
  127. }
  128. /**
  129. * Display the specified resource.
  130. *
  131. * @param \App\Models\SentPr $sentPr
  132. * @return \Illuminate\Http\Response
  133. */
  134. public function show(SentPr $sentPr)
  135. {
  136. //
  137. }
  138. /**
  139. * Update the specified resource in storage.
  140. *
  141. * @param \Illuminate\Http\Request $request
  142. * @param \App\Models\SentPr $sentPr
  143. * @return \Illuminate\Http\Response
  144. */
  145. public function update(Request $request, SentPr $sentPr)
  146. {
  147. //
  148. if(!isset($_COOKIE['user_uid'])){
  149. return $this->error('not login');
  150. }else{
  151. $user_uid = $_COOKIE['user_uid'];
  152. }
  153. $sentPr = SentPr::where('id',$request->get('id'));
  154. if($sentPr->value('editor_uid')==$user_uid){
  155. $update = $sentPr->update([
  156. "content"=>$request->get('text'),
  157. "modify_time"=>time()*1000,
  158. ]);
  159. if($update >= 0){
  160. $data = SentPr::where('id',$request->get('id'))->first();
  161. $data->id = sprintf("%d",$data->id);
  162. return $this->ok($data);
  163. }else{
  164. return $this->error('没有更新');
  165. }
  166. }else{
  167. return $this->error('not power');
  168. }
  169. }
  170. /**
  171. * Remove the specified resource from storage.
  172. *
  173. * @param \App\Models\SentPr $sentPr
  174. * @return \Illuminate\Http\Response
  175. */
  176. public function destroy(SentPr $sentPr)
  177. {
  178. //
  179. }
  180. }