PublicRpcService.php 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  1. <?php
  2. namespace App\JsonRpc;
  3. use _PHPStan_62c6a0a8b\OndraM\CiDetector\Env;
  4. use App\Model\BlackWord;
  5. use App\Model\Department;
  6. use App\Model\District;
  7. use App\Model\LetterOfComplaint;
  8. use App\Model\LetterType;
  9. use App\Model\LevelUser;
  10. use App\Model\UserLevel;
  11. use App\Tools\Result;
  12. use Hyperf\DbConnection\Db;
  13. use Hyperf\Di\Annotation\Inject;
  14. use Hyperf\RpcServer\Annotation\RpcService;
  15. use App\Service\MinioService;
  16. use Hyperf\Redis\Redis;
  17. use Overtrue\ChineseCalendar\Calendar;
  18. use App\Model\TemplateClass;
  19. use App\Model\Template;
  20. use App\Model\WebsiteTemplate;
  21. use App\Model\WebsiteTemplateInfo;
  22. use App\Model\Sector;
  23. use App\Model\Component;
  24. use App\Model\Link;
  25. use App\Model\FooterCategory;
  26. use function Hyperf\Support\retry;
  27. use App\Model\Company;
  28. use Hyperf\Paginator\Paginator;
  29. use App\Model\User;
  30. use Fukuball\Jieba\Jieba;
  31. use Fukuball\Jieba\Finalseg;
  32. #[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  33. class PublicRpcService implements PublicRpcServiceInterface
  34. {
  35. #[Inject]
  36. protected Redis $redis;
  37. /**
  38. * @param array $data
  39. * @return array
  40. */
  41. public function getDistrictList(array $data): array
  42. {
  43. $where = [];
  44. if (isset($data['keyWord'])) {
  45. $where = [
  46. ['name', 'like', '%' . $data['keyWord'] . '%']
  47. ];
  48. }
  49. $result = [];
  50. if (isset($data['pageSize'])) {
  51. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
  52. $count = District::where($where)->count();
  53. $result = [
  54. 'rows' => $rep,
  55. 'count' => $count
  56. ];
  57. } else {
  58. $result = District::where($data)->orderBy("code", "asc")->get();
  59. }
  60. return $result ? Result::success($result) : Result::error("没有查到数据");
  61. }
  62. /**
  63. * @param array $data
  64. * @return array
  65. */
  66. public function getUserLevelList(array $data): array
  67. {
  68. $where = [];
  69. if (isset($data['keyWord'])) {
  70. $where = [
  71. ['name', 'like', '%' . $data['keyWord'] . '%'],
  72. ];
  73. }
  74. $result = [];
  75. if (isset($data['pageSize'])) {
  76. $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get();
  77. $count = UserLevel::where($where)->count();
  78. $result = [
  79. 'rows' => $rep,
  80. 'count' => $count,
  81. ];
  82. } else {
  83. $result = UserLevel::orderBy("id", "asc")->get();
  84. }
  85. return $result ? Result::success($result) : Result::error("没有查到数据");
  86. }
  87. /**
  88. * 添加用户等级
  89. * @param array $data
  90. * @return array
  91. */
  92. public function addUserLevel(array $data): array
  93. {
  94. LevelUser::insertGetId($data);
  95. return Result::success([]);
  96. }
  97. /**
  98. * 更新等级
  99. * @param array $data
  100. * @return array
  101. */
  102. public function updateUserLevel(array $data): array
  103. {
  104. $result = LevelUser::where(['id' => $data['id']])->update($data);
  105. if ($result) {
  106. return Result::success($result);
  107. }
  108. return Result::error("更新失败");
  109. }
  110. /**
  111. * 删除等级
  112. * @param array $data
  113. * @return array
  114. */
  115. public function delUserLevel(array $data): array
  116. {
  117. $result = LevelUser::where(['id' => $data['id']])->delete();
  118. if ($result) {
  119. return Result::success($result);
  120. }
  121. return Result::error("删除失败");
  122. }
  123. /**
  124. * 查询投诉举报信息
  125. * @param array $data
  126. * @return array
  127. */
  128. public function getLetterOfComplaint(array $data = []): array
  129. {
  130. var_dump("====");
  131. $where = [];
  132. if (isset($data['user_id']) && !empty($data['user_id'])) {
  133. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  134. }
  135. if (isset($data['nature']) && !empty($data['nature'])) {
  136. array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]);
  137. }
  138. if (isset($data['nature_level0']) && !empty($data['nature_level0'])) {
  139. array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]);
  140. }
  141. if (isset($data['status']) && !empty($data['status'])) {
  142. array_push($where, ['letter_of_complaint.status', '=', $data['status']]);
  143. }
  144. $result = [];
  145. if (isset($data['pageSize'])) {
  146. $rep = LetterOfComplaint::where($where)
  147. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  148. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  149. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  150. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  151. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  152. ->select(
  153. "letter_of_complaint.*",
  154. "type_a.type_name as nature_name",
  155. "type_b.type_name as nature_name1",
  156. "type_c.type_name as nature_name0",
  157. "type_d.type_name as status_name",
  158. "type_e.type_name as nature_name3"
  159. )
  160. ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get();
  161. $count = LetterOfComplaint::where($where)->count();
  162. if ($rep) {
  163. foreach ($rep as $val) {
  164. if ($val['judgment']) {
  165. $val['judgment'] = json_decode($val['judgment']);
  166. }
  167. if ($val['audio_and_video']) {
  168. $val['audio_and_video'] = json_decode($val['audio_and_video']);
  169. }
  170. if ($val['contract']) {
  171. $val['contract'] = json_decode($val['contract']);
  172. }
  173. if ($val['qualifications']) {
  174. $val['qualifications'] = json_decode($val['qualifications']);
  175. }
  176. }
  177. }
  178. $result = [
  179. 'rows' => $rep,
  180. 'count' => $count,
  181. ];
  182. } else {
  183. $result = LetterOfComplaint::where($where)
  184. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  185. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  186. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  187. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  188. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  189. ->select(
  190. "letter_of_complaint.*",
  191. "type_a.type_name as nature_name",
  192. "type_b.type_name as nature_name1",
  193. "type_c.type_name as nature_name0",
  194. "type_d.type_name as status_name",
  195. "type_e.type_name as nature_name3"
  196. )
  197. ->orderBy("letter_of_complaint.id", "desc")->get();
  198. }
  199. return $result ? Result::success($result) : Result::error("没有查到数据");
  200. }
  201. /**
  202. * 添加投诉举报信息
  203. * @param array $data
  204. * @return array
  205. */
  206. public function addLetterOfComplaint(array $data): array
  207. {
  208. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  209. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  210. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  211. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  212. unset($data['id']);
  213. $result = LetterOfComplaint::insertGetId($data);
  214. if (empty($result)) {
  215. return Result::error("创建失败", 0);
  216. } else {
  217. return Result::success(["id" => $result]);
  218. }
  219. }
  220. /**
  221. * 用户端更新投诉举报
  222. * @param array $data
  223. * @return array
  224. */
  225. public function userUpLetterOfComplaint(array $data): array
  226. {
  227. $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : '';
  228. $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : '';
  229. $data['contract'] = $data['contract'] ? json_encode($data['contract']) : '';
  230. $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : '';
  231. $result = LetterOfComplaint::where(['id' => $data['id']])->update($data);
  232. if (empty($result)) {
  233. return Result::error("创建失败", 0);
  234. } else {
  235. return Result::success(["id" => $result]);
  236. }
  237. }
  238. /**
  239. * 管理后台更新投诉举报信息
  240. * @param array $data
  241. * @return array
  242. */
  243. public function upLetterOfComplaint(array $data): array
  244. {
  245. var_dump("admin:", $data);
  246. $where = [
  247. 'id' => $data['id'],
  248. ];
  249. $filtered_array = array_filter($data, function ($value) {
  250. return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value);
  251. });
  252. $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : '';
  253. $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : '';
  254. $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : '';
  255. $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : '';
  256. unset($filtered_array['nature_name']);
  257. unset($filtered_array['type_name']);
  258. unset($filtered_array['nature_level_name']);
  259. unset($filtered_array['status_name']);
  260. unset($filtered_array['is_admin']);
  261. unset($filtered_array['type_level_name']);
  262. $result = LetterOfComplaint::where($where)->update($filtered_array);
  263. if ($result) {
  264. return Result::success($result);
  265. }
  266. return Result::error("更新失败", 0);
  267. }
  268. /**
  269. * 查询投诉举报记录
  270. * @param array $data
  271. * @return array
  272. */
  273. public function getLetterOfComplaintInfo(array $data): array
  274. {
  275. $where = [
  276. 'letter_of_complaint.id' => $data['id'],
  277. ];
  278. if (isset($data['user_id']) && !empty($data['user_id'])) {
  279. array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]);
  280. }
  281. $result = LetterOfComplaint::where($where)
  282. ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id")
  283. ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id")
  284. ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id")
  285. ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id")
  286. ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id")
  287. ->select(
  288. "letter_of_complaint.*",
  289. "type_a.type_name as nature_name",
  290. "type_b.type_name as nature_name1",
  291. "type_c.type_name as nature_name0",
  292. "type_d.type_name as status_name",
  293. "type_e.type_name as nature_name3"
  294. )
  295. ->first();
  296. return Result::success($result);
  297. }
  298. /**
  299. * 删除投诉举报信息
  300. * @param array $data
  301. * @return array
  302. */
  303. public function delLetterOfComplaint(array $data): array
  304. {
  305. $result = LetterOfComplaint::when($data, function ($query) use ($data) {
  306. if (isset($data['id']) && !empty($data['id'])) {
  307. $query->where(['id' => $data['id']]);
  308. }
  309. if (isset($data['user_id']) && !empty($data['user_id'])) {
  310. $query->where(['user_id' => $data['user_id']]);
  311. }
  312. })->delete();
  313. if (empty($result)) {
  314. return Result::error("删除失败", 0);
  315. } else {
  316. return Result::success();
  317. }
  318. }
  319. /**
  320. * 获取举报信息类型
  321. * @param array $data
  322. * @return array
  323. */
  324. public function getLetterType(array $data): array
  325. {
  326. $where = [];
  327. if (isset($data['type'])) {
  328. array_push($where, ['type', '=', $data['type']]);
  329. }
  330. if (isset($data['pid']) && $data['pid'] > 0) {
  331. array_push($where, ['pid', '=', $data['pid']]);
  332. }
  333. $result = LetterType::where($where)->orderBy('sort', 'asc')->get();
  334. return $result ? Result::success($result) : Result::error("没有查到数据");
  335. }
  336. /**
  337. * 更新举报类型
  338. * @param array $data
  339. * @return array
  340. */
  341. public function upLetterType(array $data): array
  342. {
  343. return [];
  344. }
  345. /**
  346. * 添加举报类型
  347. * @param array $data
  348. * @return array
  349. */
  350. public function addLetterType(array $data): array
  351. {
  352. $result = LetterType::insertGetId($data);
  353. if (empty($result)) {
  354. return Result::error("创建失败", 0);
  355. } else {
  356. return Result::success(["id" => $result]);
  357. }
  358. }
  359. /**
  360. * 删除举报类型
  361. * @param array $data
  362. * @return array
  363. */
  364. public function delLetterType(array $data): array
  365. {
  366. $result = LetterType::where('id', $data['id'])->delete();
  367. if (empty($result)) {
  368. return Result::error("删除失败", 0);
  369. } else {
  370. return Result::success();
  371. }
  372. }
  373. /**
  374. * 检测是否已经被接案
  375. * @param array $data
  376. * @return array
  377. */
  378. public function checkMeasure(array $data): array
  379. {
  380. $where = [
  381. 'id' => $data['id'],
  382. ];
  383. $letterOfComplaintInfo = LetterOfComplaint::where($where)->first();
  384. var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']);
  385. //操作人和当前登陆用户id 相等说明是当前人接收的案件
  386. if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) {
  387. return Result::success();
  388. } else {
  389. return Result::error("您不能处理其他人已经接过的案件", 0);
  390. }
  391. }
  392. /**
  393. * 后台获取职能部门
  394. * @param array $data
  395. * @return array
  396. */
  397. public function getZhinengbumenList(array $data): array
  398. {
  399. // 获取分页参数,默认每页 10 条记录
  400. $page = isset($data['page']) ? (int) $data['page'] : 1;
  401. $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10;
  402. // 查询数据并分页
  403. $query = Department::query();
  404. // 可以在这里添加更多的查询条件
  405. if (isset($data['search'])) {
  406. $query->where('name', 'like', '%' . $data['search'] . '%');
  407. }
  408. // 执行分页查询
  409. $result = $query->paginate($perPage, ['*'], 'page', $page);
  410. // 返回分页结果
  411. return Result::success([
  412. 'count' => $result->total(),
  413. 'current_page' => $result->currentPage(),
  414. 'last_page' => $result->lastPage(),
  415. 'pagesize' => $result->perPage(),
  416. 'rows' => $result->items(),
  417. ]);
  418. }
  419. /**
  420. * 添加获取职能部门
  421. * @param array $data
  422. * @return array
  423. */
  424. public function addZhinengbumen(array $data): array
  425. {
  426. $result = Department::insertGetId($data);
  427. if (empty($result)) {
  428. return Result::error("创建失败", 0);
  429. } else {
  430. return Result::success(["id" => $result]);
  431. }
  432. }
  433. public function delZhinengbumen(array $data): array
  434. {
  435. $result = Department::where('id', $data['id'])->delete();
  436. if (empty($result)) {
  437. return Result::error("删除失败", 0);
  438. } else {
  439. return Result::success();
  440. }
  441. }
  442. public function getZhinengbumen(array $data): array
  443. {
  444. $result = Department::where('id', $data['id'])
  445. ->orderBy('department', 'desc')
  446. ->first();
  447. return Result::success($result);
  448. }
  449. public function getPidZhinengbumen(array $data): array
  450. {
  451. if (empty($data['pid'])) {
  452. $data['pid'] = 0;
  453. }
  454. $result = Department::where('pid', $data['pid'])->get();
  455. return Result::success($result);
  456. }
  457. public function modZhinengbumen(array $data): array
  458. {
  459. $result = Department::where('id', $data['id'])->update($data);
  460. if (empty($result)) {
  461. return Result::error("修改失败", 0);
  462. } else {
  463. return Result::success();
  464. }
  465. }
  466. /**
  467. * 查询职能列表
  468. * @param array $data
  469. * @return array
  470. */
  471. public function getDepartment(array $data): array
  472. {
  473. $where = [];
  474. if (isset($data['pid'])) {
  475. $where = [
  476. 'pid' => $data['pid'] ?? 0
  477. ];
  478. }
  479. $result = Department::when(!empty($where), function ($query) use ($where) {
  480. $query->where($where);
  481. })->orderBy("sort", "desc")->get();
  482. if (empty($result)) {
  483. return Result::error("查询失败", 0);
  484. } else {
  485. return Result::success($result);
  486. }
  487. }
  488. /**
  489. * 获取所有的buckets
  490. * @param array $data
  491. * @return array
  492. */
  493. public function getBuckets(array $data): array
  494. {
  495. $result = new MinioService();
  496. // 调用服务层的方法获取存储桶列表
  497. $bucketsResponse = $result->listBuckets();
  498. // 直接返回服务层生成的响应
  499. return Result::success($bucketsResponse['data']);
  500. }
  501. /**
  502. * 上传文件
  503. * @param array $data
  504. * @return array
  505. */
  506. public function uploadFile(array $data): array
  507. {
  508. $result = new MinioService();
  509. $rep = $result->uploadFile($data);
  510. if ($rep['code'] == 200) {
  511. return Result::success($rep['data']);
  512. } else {
  513. return Result::error("上传失败!");
  514. }
  515. }
  516. /**
  517. * 黑名单管理
  518. * @param array $data
  519. * @return array
  520. */
  521. public function getBlackWordList(array $data): array
  522. {
  523. $result = BlackWord::when($data, function ($query) use ($data) {
  524. if (isset($data['name']) && $data['name']) {
  525. $query->where('black_word.name', 'like', '%' . $data['name'] . '%');
  526. }
  527. })->orderBy('black_word.id', 'desc')
  528. ->paginate(
  529. intval($data['pageSize']),
  530. [
  531. 'black_word.*',
  532. ],
  533. 'page',
  534. intval($data['page'])
  535. );
  536. $count = $result->total();
  537. $returnData = [
  538. 'rows' => $result->items(),
  539. 'count' => $count
  540. ];
  541. return Result::success($returnData);
  542. }
  543. /**
  544. * 添加黑名单
  545. * @param array $data
  546. * @return array
  547. */
  548. public function addBlackWord(array $data): array
  549. {
  550. Db::beginTransaction();
  551. try {
  552. $info = BlackWord::where(['name' => $data['name']])->first();
  553. if ($info) {
  554. Db::rollBack();
  555. return Result::error("该黑名单已存在", 0);
  556. }
  557. $data['type'] = 10;
  558. $result = BlackWord::insertGetId($data);
  559. $redisKey = 'black_word';
  560. $this->redis->sAdd($redisKey, $data['name']);
  561. Db::commit();
  562. return Result::success(["id" => $result]);
  563. } catch (\Exception $e) {
  564. Db::rollBack();
  565. return Result::error("创建失败" . $e->getMessage(), 0);
  566. }
  567. }
  568. /**
  569. * 删除黑名单
  570. * @param array $data
  571. * @return array
  572. */
  573. public function delBlackWord(array $data): array
  574. {
  575. Db::beginTransaction();
  576. try {
  577. BlackWord::where(['name' => $data['name']])->delete();
  578. $redisKey = 'black_word';
  579. $this->redis->sRem($redisKey, $data['name']);
  580. Db::commit();
  581. return Result::success([]);
  582. } catch (\Exception $e) {
  583. Db::rollBack();
  584. return Result::error("删除失败" . $e->getMessage(), 0);
  585. }
  586. }
  587. /**
  588. * 修改违禁词
  589. * @param array $data
  590. * @return array
  591. */
  592. public function upBlackWord(array $data): array
  593. {
  594. Db::beginTransaction();
  595. try {
  596. $checkInfo = BlackWord::where(['name' => $data['name']])->first();
  597. if ($checkInfo) {
  598. Db::rollBack();
  599. return Result::error("该违禁词已经存在", 0);
  600. }
  601. $blackWordInfo = BlackWord::where(['id' => $data['id']])->first();
  602. if ($blackWordInfo) {
  603. //先删除redis
  604. $blackWordInfo = $blackWordInfo->toArray();
  605. $redisKey = 'black_word';
  606. $this->redis->sRem($redisKey, $blackWordInfo['name']);
  607. $this->redis->sAdd($redisKey, $data['name']);
  608. BlackWord::where(['id' => $data['id']])->update(['name' => $data['name']]);
  609. Db::commit();
  610. return Result::success([]);
  611. } else {
  612. Db::rollBack();
  613. return Result::error("系统错误", 0);
  614. }
  615. } catch (\Exception $e) {
  616. Db::rollBack();
  617. return Result::error("修改失败" . $e->getMessage(), 0);
  618. }
  619. }
  620. /**
  621. * 获取风格
  622. * @return void
  623. */
  624. public function getTemplateClassList(array $data): array
  625. {
  626. $where = [];
  627. if (isset($data['name']) && $data['name']) {
  628. array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
  629. }
  630. if (isset($data['keyword']) && $data['keyword']) {
  631. array_push($where, ['template_class.keyword', 'like', '%' . $data['keyword'] . '%']);
  632. }
  633. $template = TemplateClass::when($where, function ($query) use ($where) {
  634. $query->where($where);
  635. });
  636. $count = $template->count();
  637. // $countQuery = clone $template;
  638. $row = $template
  639. ->leftJoin('template', 'template_class.id', '=', 'template.template_class_id')
  640. ->select('template_class.*', DB::raw('COUNT(template.id) as template_count'))
  641. ->groupBy('template_class.id')
  642. ->orderBy('template_class.id', 'desc')
  643. ->offset(($data['page'] - 1) * $data['pageSize'])
  644. ->limit($data['pageSize'])
  645. ->get();
  646. $result = [
  647. 'rows' => $row,
  648. 'count' => $count,
  649. ];
  650. if ($row->isEmpty()) {
  651. return Result::error("暂无风格", 0);
  652. } else {
  653. return Result::success($result);
  654. }
  655. }
  656. /**
  657. * 添加风格
  658. * @param
  659. * @return void
  660. */
  661. public function addTemplateClass(array $data): array
  662. {
  663. $data['keyword'] = json_encode($data['keyword']);
  664. $template_class = TemplateClass::where('name', $data['name'])
  665. ->orWhere('class_id', $data['class_id'])
  666. ->first();
  667. if ($template_class) {
  668. return Result::error("风格名称或者风格编号已存在,不可添加!", 0);
  669. }
  670. $result = TemplateClass::insertGetId($data);
  671. if (empty($result)) {
  672. return Result::error("创建风格失败", 0);
  673. } else {
  674. return Result::success(["id" => $result]);
  675. }
  676. }
  677. /**
  678. * 更新风格
  679. * @param array $data
  680. * @return array
  681. */
  682. public function upTemplateClass(array $data): array
  683. {
  684. $where = [
  685. 'id' => $data['id'],
  686. ];
  687. $template_class = TemplateClass::where($where)->first();
  688. if (empty($template_class)) {
  689. return Result::error("未查询到风格", 0);
  690. }
  691. if ($template_class->type == 1) {
  692. return Result::error("默认风格不能修改", 0);
  693. }
  694. $template = TemplateClass::where('id', '!=', $data['id'])
  695. // ->where(['name' => $data['name']])
  696. // ->orWhere(['class_id' => $data['class_id']])
  697. ->where(function ($query) use ($data) {
  698. $query->where('name', $data['name'])
  699. ->orWhere('class_id', $data['class_id']);
  700. })
  701. ->first();
  702. if ($template) {
  703. return Result::error("风格名称或者风格编号已存在,不可编辑!", 0);
  704. }
  705. $updateData = [
  706. 'name' => $data['name'],
  707. 'keyword' => json_encode($data['keyword']),
  708. 'class_id' => $data['class_id'],
  709. ];
  710. $result = TemplateClass::where($where)->update($updateData);
  711. if (empty($result)) {
  712. return Result::error("更新失败", 0);
  713. } else {
  714. return Result::success($result);
  715. }
  716. }
  717. /**
  718. * 删除风格
  719. * @param array $data
  720. * @return array
  721. */
  722. public function delTemplateClass(array $data): array
  723. {
  724. $where = [
  725. 'id' => $data['id'],
  726. ];
  727. $template = TemplateClass::where($where)->first();
  728. if (empty($template)) {
  729. return Result::error("未查询到风格", 0);
  730. }
  731. if ($template->type == 1) {
  732. return Result::error("默认风格不能删除", 0);
  733. }
  734. $result = TemplateClass::where($where)->delete();
  735. if (empty($result)) {
  736. return Result::error("删除失败", 0);
  737. } else {
  738. return Result::success($result);
  739. }
  740. }
  741. /**
  742. * 获取getTemplateClass
  743. * @param array $data
  744. * @return array
  745. */
  746. public function getTemplateClass(array $data): array
  747. {
  748. $result = TemplateClass::get();
  749. return Result::success($result);
  750. }
  751. /**
  752. * 获取皮肤列表
  753. * @param array $data
  754. * @return array
  755. */
  756. public function getTemplateList(array $data): array
  757. {
  758. $where = [];
  759. if (!empty($data['template_class_id'])) {
  760. $where['template_class_id'] = $data['template_class_id'];
  761. }
  762. if (!empty($data['template_name'])) {
  763. array_push($where, ['template_name', 'like', '%' . $data['template_name'] . '%']);
  764. }
  765. if (!empty($data['template_keyword'])) {
  766. array_push($where, ['template_keyword', 'like', '%' . $data['template_keyword'] . '%']);
  767. }
  768. $result = Template::where($where)
  769. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  770. ->select('template.*', 'template_class.name as template_class_name')
  771. ->orderBy('template.id', 'desc')
  772. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  773. if (empty($result)) {
  774. return Result::error("暂无皮肤", 0);
  775. }
  776. return Result::success($result);
  777. }
  778. public function getTemplateInfo(array $data): array
  779. {
  780. $result = Template::where('template.id', $data['id'])
  781. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  782. ->select('template.*', 'template_class.name as template_class_name')
  783. ->first();
  784. if (empty($result)) {
  785. return Result::error("暂无皮肤", 0);
  786. }
  787. return Result::success($result);
  788. }
  789. /**
  790. * 添加皮肤
  791. * @param array $data
  792. * @return array
  793. */
  794. public function addTemplate(array $data): array
  795. {
  796. var_dump($data);
  797. unset($data['user_id']);
  798. $template = Template::where('template_name', $data['template_name'])
  799. ->orWhere('template_id', $data['template_id'])
  800. ->first();
  801. if ($template) {
  802. return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
  803. }
  804. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  805. $page_type = json_decode($data['page_type'], true);
  806. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  807. $result = Template::insertGetId($data);
  808. if (empty($result)) {
  809. return Result::error("创建失败", 0);
  810. } else {
  811. return Result::success($result);
  812. }
  813. }
  814. /**
  815. * 删除皮肤
  816. * @param array $data
  817. * @return array
  818. */
  819. public function delTemplate(array $data): array
  820. {
  821. $result = Template::where('id', $data['id'])->delete();
  822. var_dump($result, '-------------------delete');
  823. if ($result) {
  824. return Result::success($result);
  825. } else {
  826. return Result::error("删除失败", 0);
  827. }
  828. }
  829. /**
  830. * 更新皮肤
  831. * @param array $data
  832. * @return array
  833. */
  834. public function updateTemplate(array $data): array
  835. {
  836. unset($data['user_id']);
  837. $template = Template::where('id', $data['id'])
  838. ->first();
  839. if (empty($template)) {
  840. return Result::error("此皮肤不存在!", 0);
  841. }
  842. $template = Template::where('id', '!=', $data['id'])
  843. ->where(function ($query) use ($data) {
  844. $query->where('template_name', $data['template_name'])
  845. ->orWhere('template_id', $data['template_id']);
  846. })
  847. ->first();
  848. if ($template) {
  849. return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
  850. }
  851. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  852. $page_type = json_decode($data['page_type'], true);
  853. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  854. $result = Template::where('id', $data['id'])->update($data);
  855. var_dump($result, '-------------------update');
  856. if (!$result) {
  857. return Result::error("更新失败", 0);
  858. } else {
  859. return Result::success('更新成功');
  860. }
  861. }
  862. public function getSectorList(array $data): array
  863. {
  864. $where = [];
  865. if (!empty($data['template_class_id'])) {
  866. $where['template_class.id'] = $data['template_class_id'];
  867. }
  868. if (!empty($data['template_class_name'])) {
  869. $where[] = ['template_class.name', 'like', '%' . $data['template_class_name'] . '%'];
  870. }
  871. if (!empty($data['sector_name'])) {
  872. if (!empty($data['sector_name'])) {
  873. // $where['sector_name'] = $data['sector_name'];
  874. $where[] = ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%'];
  875. }
  876. }
  877. $result = Sector::where($where)
  878. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  879. ->leftJoin('template_class', 'template_class.id', '=', 'sector.template_id') // 添加这一行
  880. ->select('sector.*', 'sector.sector_name', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  881. ->orderBy('sector.id', 'desc')
  882. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  883. return Result::success($result);
  884. }
  885. public function getSectorInfo(array $data): array
  886. {
  887. $where = [];
  888. $where[] = ['sector.id', '=', $data['id']];
  889. $result = Sector::where($where)
  890. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  891. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  892. ->select('sector.*', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  893. ->orderBy('sector.id', 'desc')
  894. ->get();
  895. return Result::success($result);
  896. }
  897. /**
  898. * 获取经纬度信息
  899. * @return void
  900. */
  901. public function getIpInfo(array $data): array
  902. {
  903. $client_ip = isset($data['ip']) && $data['ip'] ?? $_SERVER['REMOTE_ADDR'];
  904. // 使用 IPinfo 服务获取 IP 信息
  905. // $api_url = "https://ipinfo.io/{$client_ip}/json";
  906. //http://ip-api.com/json/117.136.12.79?lang=zh-cn
  907. $api_url = "http://ip-api.com/json/{$client_ip}/?lang=zh-cn";
  908. $ch = curl_init($api_url);
  909. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  910. $response = curl_exec($ch);
  911. curl_close($ch);
  912. // 解析 JSON 响应
  913. $ip_info = json_decode($response, true);
  914. // 提取地址和经纬度
  915. if ($ip_info) {
  916. // $latitude = explode(',', $ip_info['loc'])[0];
  917. // $longitude = explode(',', $ip_info['loc'])[1];
  918. $ip_info['latitude'] = $ip_info['lat'];
  919. $ip_info['longitude'] = $ip_info['lon'];
  920. return Result::success($ip_info);
  921. } else {
  922. $data['ip'] = '101.254.114.212';
  923. $this->getIpinfo(["ip" => $data['ip']]);
  924. }
  925. }
  926. /**
  927. * 获取天气
  928. * @param array $data
  929. * @return array
  930. */
  931. public function getWeatherInfo(array $data): array
  932. {
  933. $month = $data['month'] ?? date('m');
  934. $day = $data['day'] ?? date('d');
  935. // 使用缓存键
  936. $cacheKey = "tsbb_data_weather_{$month}_{$day}";
  937. // 尝试从缓存获取数据
  938. $container = \Hyperf\Context\ApplicationContext::getContainer();
  939. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  940. if ($cachedData = $cache->get($cacheKey)) {
  941. return Result::success(unserialize($cachedData));
  942. }
  943. $location = $data['latitude'] . ":" . $data['longitude'];
  944. $api_url = "https://api.seniverse.com/v3/weather/now.json?key=" . \Hyperf\Support\env('WEATHER_KEY') . "&location=" . $location . "&language=zh-Hans&unit=c";
  945. $ch = curl_init($api_url);
  946. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  947. $response = curl_exec($ch);
  948. curl_close($ch);
  949. // 解析 JSON 响应
  950. $WeatherInfo = json_decode($response, true);
  951. // 缓存结果,设置1小时过期
  952. $cache->set($cacheKey, serialize($WeatherInfo), 3600);
  953. if ($WeatherInfo) {
  954. return Result::success($WeatherInfo);
  955. } else {
  956. return Result::error("获取天气失败", 0);
  957. }
  958. }
  959. /**
  960. * 获取农历信息
  961. * @return void
  962. */
  963. public function getCalendar(array $data): array
  964. {
  965. $calendar = new Calendar();
  966. $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
  967. return Result::success($result);
  968. }
  969. public function addSector(array $data): array
  970. {
  971. unset($data['user_id']);
  972. // $data['page_type'] = json_encode($data['page_type']);
  973. $result = Sector::insertGetId($data);
  974. return Result::success();
  975. }
  976. public function delSector(array $data): array
  977. {
  978. $result = Sector::where('id', $data['id'])->delete();
  979. if ($result == 1) {
  980. return Result::success('删除成功');
  981. } else {
  982. return Result::error('删除失败');
  983. }
  984. }
  985. public function updateSector(array $data): array
  986. {
  987. unset($data['user_id']);
  988. $result = Sector::where('id', $data['id'])->update($data);
  989. if ($result == 1) {
  990. return Result::success('修改成功');
  991. } else {
  992. return Result::error('修改失败');
  993. }
  994. }
  995. public function getComponentList(array $data): array
  996. {
  997. var_dump($data, '---------');
  998. $where = [];
  999. // $where[] = ['sector.id', '=', $data['id']];
  1000. if (!empty($data['template_class_id'])) {
  1001. $where['template_class.id'] = $data['template_class_id'];
  1002. }
  1003. if (!empty($data['component_name'])) {
  1004. $where['component.component_name'] = $data['component_name'];
  1005. }
  1006. if (!empty($data['sector_id'])) {
  1007. $where['sector.id'] = $data['sector_id'];
  1008. };
  1009. $result = Component::where($where)
  1010. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1011. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1012. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1013. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'template_class.id as template_class_id', 'sector.sector_name as sector_name', 'component.*', 'sector.id as sector_id') // 修改这一行)
  1014. ->orderBy('sector.updated_at', 'desc')
  1015. ->orderBy('sector.created_at', 'desc')
  1016. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  1017. return Result::success($result);
  1018. }
  1019. public function getComponentInfo(array $data): array
  1020. {
  1021. $where = [];
  1022. $result = Component::where($where)
  1023. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1024. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1025. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1026. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
  1027. ->get();
  1028. return Result::success($result);
  1029. }
  1030. public function addComponent(array $data): array
  1031. {
  1032. unset($data['user_id']);
  1033. $result = Component::insertGetId($data);
  1034. if ($result) {
  1035. return Result::success($result);
  1036. } else {
  1037. return Result::error('添加失败');
  1038. }
  1039. }
  1040. public function delComponent(array $data): array
  1041. {
  1042. $result = Component::where('id', $data['id'])->delete();
  1043. return Result::success($result);
  1044. }
  1045. public function updateComponent(array $data): array
  1046. {
  1047. $result = Component::where('id', $data['id'])->update($data);
  1048. return Result::success($result);
  1049. }
  1050. public function getWebsiteTemplateInfo(array $data)
  1051. {
  1052. $where = [];
  1053. if (isset($data['id'])) {
  1054. $where[] = ['id', '=', $data['id']];
  1055. }
  1056. $result = WebsiteTemplateInfo::where($where)
  1057. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1058. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  1059. ->select('website_template_info.*', 'website.website_name')
  1060. ->get();
  1061. if ($result) {
  1062. return Result::success($result);
  1063. } else {
  1064. return Result::error('暂无数据');
  1065. }
  1066. }
  1067. /**
  1068. * 自助建站----1.获取页面类型回显
  1069. * @param array $data
  1070. * @return array
  1071. */
  1072. public function getWebPageType(array $data): array
  1073. {
  1074. // 1:图片 2:文字 3:底部
  1075. $friend_link = Link::where('website_id', $data['website_id'])->where('type', 3)->get();
  1076. if (empty($friend_link->toArray())) {
  1077. return Result::error('暂无友情链接数据!');
  1078. }
  1079. $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
  1080. if (empty($footer_category->toArray())) {
  1081. return Result::error('暂无底部导航数据!');
  1082. }
  1083. $result = [
  1084. 'friend_link' => $friend_link,
  1085. 'footer_category' => $footer_category,
  1086. ];
  1087. return Result::success($result);
  1088. }
  1089. /**
  1090. * 自助建站----2.添加页面类型
  1091. * @param array $data
  1092. * @return array
  1093. */
  1094. public function addWebPageType(array $data): array
  1095. {
  1096. // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
  1097. if ($data['is_search'] == 1) {
  1098. $page_type = json_encode([1, 2, 3, 4, 5, 6, 7]);
  1099. } else {
  1100. $page_type = json_encode([1, 2, 3, 4, 6, 7]);
  1101. }
  1102. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1103. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type], ['action_id' => 1]);
  1104. if ($result) {
  1105. return Result::success($result);
  1106. } else {
  1107. return Result::error('添加失败');
  1108. }
  1109. }
  1110. /**
  1111. * 自助建站---流程---3.选择皮肤列表
  1112. * @param array $data
  1113. * @return array
  1114. */
  1115. public function getWebsiteTemplateList(array $data): array
  1116. {
  1117. $where = [];
  1118. if (isset($data['template_class_id']) && $data['template_class_id']) {
  1119. $where[] = ['template_class_id', '=', $data['template_class_id']];
  1120. }
  1121. // 0:未构建 1:未应用 2:已应用 status
  1122. $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1123. if (empty($templste_info)) {
  1124. return Result::error('请先填写网站基础信息!');
  1125. }
  1126. if ($templste_info['status'] == 2) {
  1127. return Result::error('网站已应用,不可再次修改!');
  1128. }
  1129. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1130. if (is_array($data['keyword'])) {
  1131. // 拼接多个模糊查询条件
  1132. $query = Template::query();
  1133. foreach ($data['keyword'] as $kw) {
  1134. $escapedKw = addcslashes($kw, '%_'); // 转义通配符
  1135. $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
  1136. }
  1137. } else {
  1138. $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
  1139. $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
  1140. }
  1141. }
  1142. $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
  1143. // return Result::success($template_id);
  1144. if (!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])) {
  1145. $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
  1146. } else {
  1147. $template_page = [];
  1148. }
  1149. if (!empty($template_id['template_id'])) {
  1150. $result['template_id'] = $templste_info['template_id'];
  1151. }
  1152. // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
  1153. $template_page_str = json_encode($template_page);
  1154. if (isset($query)) {
  1155. $result['template'] = $query->where($where)
  1156. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1157. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1158. } else {
  1159. $result['template'] = Template::where($where)
  1160. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1161. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1162. }
  1163. if (empty($result['template']['data'])) {
  1164. $result['template'] = Template::orderBy('updated_at', 'desc')
  1165. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1166. }
  1167. return Result::success($result);
  1168. }
  1169. /**
  1170. * 自助建站---流程---4.选择皮肤
  1171. * @param array $data
  1172. * @return array
  1173. */
  1174. public function chooseWebsiteTemplate(array $data): array
  1175. {
  1176. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1177. if (empty($website_template_info)) {
  1178. return Result::error('请先填写网站基础信息!');
  1179. }
  1180. // 0:未构建 1:未应用 2:已应用 status
  1181. if ($website_template_info['status'] == 2) {
  1182. return Result::error('网站已应用,不可再次修改!');
  1183. }
  1184. $template = Template::where('id', $data['template_id'])->first();
  1185. if (empty($template)) {
  1186. return Result::error('未查询到皮肤!');
  1187. }
  1188. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1189. $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'], 'action_id' => 2]);
  1190. if ($web_template) {
  1191. return Result::success($web_template);
  1192. } else {
  1193. return Result::error('选择皮肤失败!');
  1194. }
  1195. }
  1196. /**
  1197. * 自助建站---流程---5.选择组件
  1198. * @param array $data
  1199. * @return array
  1200. */
  1201. public function saveWebsiteTemplate(array $data): array
  1202. {
  1203. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1204. if (empty($website_template_info)) {
  1205. return Result::error('请先填写网站基础信息!');
  1206. }
  1207. // 0:未构建 1:未应用 2:已应用 status
  1208. if ($website_template_info['status'] == 2) {
  1209. return Result::error('网站已应用,不可再次保存!');
  1210. }
  1211. if ($website_template_info['action_id'] != 2) {
  1212. return Result::error('请完成之前的步骤!');
  1213. }
  1214. $template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1215. if (empty($template_info)) {
  1216. $template = WebsiteTemplate::insertGetId(['website_id' => $data['website_id'], 'template_data' => $data['template_data']]);
  1217. } else {
  1218. $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(['template_data' => $data['template_data']]);
  1219. }
  1220. if (empty($template)) {
  1221. return Result::error('保存失败!');
  1222. } else {
  1223. return Result::success($template);
  1224. }
  1225. }
  1226. /**
  1227. * 企业管理
  1228. * @param array $data
  1229. * @return array
  1230. */
  1231. public function getCompanyList(array $data): array
  1232. {
  1233. $where = [];
  1234. $user = User::where('id', $data['user_id'])->first();
  1235. if (empty($user)) {
  1236. return Result::error('用户不存在!');
  1237. }
  1238. if ($user['type_id'] != 10000) {
  1239. $where['user_id'] = $data['user_id'];
  1240. }
  1241. if (isset($data['title']) && $data['title']) {
  1242. array_push($where, ['title', 'like', '%' . $data['title'] . '%']);
  1243. }
  1244. if (isset($data['website_id']) && $data['website_id']) {
  1245. $where['website_id'] = $data['website_id'];
  1246. }
  1247. // 状态:0:未审核 1:已审核 2:已拒绝
  1248. $pageSize = isset($data['pageSize']) ? (int)$data['pageSize'] : 10; // 默认每页 10 条记录
  1249. $page = isset($data['page']) ? (int)$data['page'] : 1; // 默认第 1 页
  1250. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  1251. if ($data['ischeck'] == 1) {
  1252. $query = Company::whereIn('status', [0, 2]);
  1253. } else {
  1254. $query = Company::where('status', 1);
  1255. }
  1256. }
  1257. $result = $query->where($where)->paginate($pageSize, ['*'], 'page', $page);
  1258. if (empty($result)) {
  1259. return Result::error("暂无企业", 0);
  1260. }
  1261. return Result::success($result);
  1262. }
  1263. /**
  1264. * 添加企业
  1265. * @param array $data
  1266. * @return array
  1267. */
  1268. public function addCompany(array $data): array
  1269. {
  1270. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  1271. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1272. if ($data['imgurl'] == '') {
  1273. //content中提取图片第一个图,正则提取
  1274. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  1275. preg_match_all($reg, $data['content'], $matches);
  1276. if (isset($matches[1][0])) {
  1277. //截取varchar240
  1278. $data['imgurl'] = substr($matches[1][0], 0, 240);
  1279. }
  1280. }
  1281. if ($data['keyword'] == '') {
  1282. //提取标题+内容中的关键词
  1283. $data['keyword'] = $data['title'];
  1284. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  1285. Jieba::init(); // 初始化 jieba-php
  1286. Finalseg::init();
  1287. $segList = Jieba::cut($data['keyword']);
  1288. $segList1 = array_slice($segList, 0, 8);
  1289. $data['keyword'] = implode(',', $segList1);
  1290. }
  1291. if ($data['introduce'] == '') {
  1292. //提取内容中的描述
  1293. $data['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  1294. }
  1295. $user = User::where('id', $data['user_id'])->first();
  1296. if (empty($user)) {
  1297. return Result::error('用户不存在!');
  1298. }
  1299. if ($user['type_id'] == 10000) {
  1300. $data['status'] = 1;
  1301. }
  1302. $result = Company::insertGetId($data);
  1303. if ($result) {
  1304. return Result::success($result);
  1305. } else {
  1306. return Result::error('添加失败');
  1307. }
  1308. }
  1309. /**
  1310. * 更新企业
  1311. * @param array $data
  1312. * @return array
  1313. */
  1314. public function upCompany(array $data): array
  1315. {
  1316. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  1317. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1318. if ($data['imgurl'] == '') {
  1319. //content中提取图片第一个图,正则提取
  1320. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  1321. preg_match_all($reg, $data['content'], $matches);
  1322. if (isset($matches[1][0])) {
  1323. //截取varchar240
  1324. $data['imgurl'] = substr($matches[1][0], 0, 240);
  1325. }
  1326. }
  1327. if ($data['keyword'] == '') {
  1328. //提取标题+内容中的关键词
  1329. $data['keyword'] = $data['title'];
  1330. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  1331. Jieba::init(); // 初始化 jieba-php
  1332. Finalseg::init();
  1333. $segList = Jieba::cut($data['keyword']);
  1334. $segList1 = array_slice($segList, 0, 8);
  1335. $data['keyword'] = implode(',', $segList1);
  1336. }
  1337. if ($data['introduce'] == '') {
  1338. //提取内容中的描述
  1339. $data['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  1340. }
  1341. $user = User::where('id', $data['user_id'])->first();
  1342. if (empty($user)) {
  1343. return Result::error('用户不存在!');
  1344. }
  1345. if ($user['type_id'] == 10000) {
  1346. $data['status'] = 1;
  1347. } else {
  1348. $data['status'] = 0;
  1349. }
  1350. $result = Company::where('id', $data['id'])->update($data);
  1351. if ($result) {
  1352. return Result::success($result);
  1353. } else {
  1354. return Result::error('修改失败');
  1355. }
  1356. }
  1357. /**
  1358. * 删除企业
  1359. * @param array $data
  1360. * @return array
  1361. */
  1362. public function delCompany(array $data): array
  1363. {
  1364. $result = Company::where('id', $data['id'])->delete();
  1365. if ($result) {
  1366. return Result::success($result);
  1367. } else {
  1368. return Result::error('删除失败');
  1369. }
  1370. }
  1371. /**
  1372. * 审核企业
  1373. * @param array $data
  1374. * @return array
  1375. */
  1376. public function checkCompany(array $data): array
  1377. {
  1378. $user = User::where('id', $data['user_id'])->first();
  1379. if (empty($user)) {
  1380. return Result::error('用户不存在!');
  1381. }
  1382. $company = Company::where('id', $data['id'])->first();
  1383. if (empty($company)) {
  1384. return Result::error('企业不存在!');
  1385. }
  1386. // 状态:0:未审核 1:已审核 2:已拒绝
  1387. if ($company['status'] == 0 || $company['status'] == 1) {
  1388. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  1389. } else {
  1390. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reject_reason']]);
  1391. }
  1392. if (empty($result)) {
  1393. return Result::error('审核失败!');
  1394. } else {
  1395. return Result::success($result);
  1396. }
  1397. }
  1398. /**
  1399. * 获取企业信息
  1400. * @param array $data
  1401. * @return array
  1402. */
  1403. public function getCompanyInfo(array $data): array
  1404. {
  1405. $result = Company::where('id', $data['id'])->first();
  1406. if (empty($result)) {
  1407. return Result::error('企业不存在!');
  1408. } else {
  1409. return Result::success($result);
  1410. }
  1411. }
  1412. }