safenotelogic.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2021-10-29 16:16:29
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2021-11-09 16:21:40
  7. */
  8. namespace app\index\logic;
  9. use app\index\model\safenotemodel;
  10. use think\Log;
  11. class safenotelogic
  12. {
  13. /**
  14. * 新增信息
  15. * 20211127
  16. * wj
  17. */
  18. public function newinfo($info)
  19. {
  20. log::info($info);
  21. $fillField = ['Label', 'Suggestion', 'type', 'DataId'];
  22. $fillFieldNum = ['Score'];
  23. foreach ($fillField as $key => $value) {
  24. if (!isset($info[$value]) || empty($info[$value])) {
  25. return backarr(0, "请求错误");
  26. }
  27. }
  28. foreach ($fillFieldNum as $key => $value) {
  29. if (!isset($info[$value]) || !is_numeric($info[$value])) {
  30. return backarr(0, "请求错误");
  31. }
  32. }
  33. $label = $info['Label'];
  34. $suggestion = $info['Suggestion'];
  35. $score = $info['Score'];
  36. $type = $info['type'];
  37. $contentid = $info['DataId'];
  38. $insertData = [
  39. 'label' => $info['Label'],
  40. 'suggestion' => $info['Suggestion'],
  41. 'score' => $info['Score'],
  42. 'contentid' => $contentid,
  43. 'createtime' => date("Y-m-d H:i:s"),
  44. ];
  45. //招工,找活
  46. $tablensme = '';
  47. switch ($type) {
  48. case '1':
  49. $tablensme = "invent";
  50. break;
  51. case '2':
  52. $tablensme = "jobhunting";
  53. break;
  54. }
  55. $insertData['tablename'] = $tablensme;
  56. log::info($insertData);
  57. $m_s = new safenotemodel();
  58. $id = $m_s->insertData($insertData);
  59. if (!$id) {
  60. return backarr(0, "操作失败");
  61. }
  62. return backarr(1, "操作成功", ['id' => $id]);
  63. }
  64. public function getresult($content, $dataid = null, $userid = null)
  65. {
  66. $type = 'wc';
  67. $data = [
  68. 'content' => $content,
  69. 'type' => $type,
  70. ];
  71. if ($dataid) {
  72. $data['dataid'] = $dataid;
  73. }
  74. if ($userid) {
  75. $data['userid'] = $userid;
  76. }
  77. log::info($data);
  78. $url = 'https://app.tjzhxx.cn:5443/api/tencent_cloud/safenote';
  79. $header = ['Content-Type:application/x-www-form-urlencoded'];
  80. $result = requestCurl($url, 'post', $data, $header);
  81. log::info($result);
  82. $result = json_decode($result, true);
  83. log::info($result);
  84. if (empty($result)) {
  85. return backarr(0, "无文本校验结果");
  86. }
  87. return $result;
  88. }
  89. //根据接口返回数据 自动审核
  90. //
  91. public function automaticcheck($data, $type = 1, $strict = true)
  92. {
  93. if ($strict) {
  94. //相应时间段 不严格校验
  95. //招工高峰时间段 13:00 - 17:00
  96. //找活高峰时间段 5:00 - 10:00
  97. $inventTime = ['0500', '1000'];
  98. $jobhuntingTime = ['1300', '1700'];
  99. $time = date('Hi');
  100. switch ($type) {
  101. case 1:
  102. if ($time >= $inventTime[0] && $time <= $inventTime[1]) {
  103. $strict = false;
  104. }
  105. break;
  106. case 2:
  107. if ($time >= $jobhuntingTime[0] && $time <= $jobhuntingTime[1]) {
  108. $strict = false;
  109. }
  110. break;
  111. }
  112. }
  113. //总是模糊校验的label
  114. $noStrictLabel = ['Ad', 'Normal'];
  115. $label = $data['Label'];
  116. $isNoStrictLabel = false;
  117. if (in_array($label, $noStrictLabel)) {
  118. $strict = false;
  119. $isNoStrictLabel = true;
  120. }
  121. //$suggestion = $data['Suggestion'];
  122. $suggestion = 'Block';
  123. if ($strict) {
  124. //Pass 审核通过
  125. $allowSuggestion = ['Pass'];
  126. if (in_array($suggestion, $allowSuggestion)) {
  127. return true;
  128. }
  129. } else {
  130. //Review Pass 审核通过
  131. $allowSuggestion = ['Review', 'Pass'];
  132. if ($isNoStrictLabel) {
  133. array_push($allowSuggestion, 'Block');
  134. }
  135. if (in_array($suggestion, $allowSuggestion)) {
  136. return true;
  137. }
  138. }
  139. return false;
  140. }
  141. public function replaceTel($str)
  142. {
  143. if (!is_string($str)) {
  144. return false;
  145. }
  146. preg_match_all("(1[3-9]{1}\d{9})", $str, $matches);
  147. $matches = $matches[0];
  148. if (is_array($matches)) {
  149. foreach ($matches as $key => $value) {
  150. $telno = $value;
  151. $endNum = substr($telno, -4, 4);
  152. $str = str_replace($endNum, "****", $str);
  153. }
  154. } elseif (is_string($matches)) {
  155. $telno = $matches;
  156. $endNum = substr($telno, -4, 4);
  157. $telstr = str_replace($endNum, "****", $str);
  158. $str = str_replace($telno, $telstr, $str);
  159. }
  160. return $str;
  161. }
  162. }