SentPrController.php 5.9 KB

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