PublicRpcService.php 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  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'])->first();
  445. return Result::success($result);
  446. }
  447. public function getPidZhinengbumen(array $data): array
  448. {
  449. if (empty($data['pid'])) {
  450. $data['pid'] = 0;
  451. }
  452. $result = Department::where('pid', $data['pid'])->get();
  453. return Result::success($result);
  454. }
  455. public function modZhinengbumen(array $data): array
  456. {
  457. $result = Department::where('id', $data['id'])->update($data);
  458. if (empty($result)) {
  459. return Result::error("修改失败", 0);
  460. } else {
  461. return Result::success();
  462. }
  463. }
  464. /**
  465. * 查询职能列表
  466. * @param array $data
  467. * @return array
  468. */
  469. public function getDepartment(array $data): array
  470. {
  471. $where = [];
  472. if (isset($data['pid'])) {
  473. $where = [
  474. 'pid' => $data['pid'] ?? 0
  475. ];
  476. }
  477. $result = Department::when(!empty($where), function ($query) use ($where) {
  478. $query->where($where);
  479. })->orderBy("sort", "desc")->get();
  480. if (empty($result)) {
  481. return Result::error("查询失败", 0);
  482. } else {
  483. return Result::success($result);
  484. }
  485. }
  486. /**
  487. * 获取所有的buckets
  488. * @param array $data
  489. * @return array
  490. */
  491. public function getBuckets(array $data): array
  492. {
  493. $result = new MinioService();
  494. // 调用服务层的方法获取存储桶列表
  495. $bucketsResponse = $result->listBuckets();
  496. // 直接返回服务层生成的响应
  497. return Result::success($bucketsResponse['data']);
  498. }
  499. /**
  500. * 上传文件
  501. * @param array $data
  502. * @return array
  503. */
  504. public function uploadFile(array $data): array
  505. {
  506. $result = new MinioService();
  507. $rep = $result->uploadFile($data);
  508. if ($rep['code'] == 200) {
  509. return Result::success($rep['data']);
  510. } else {
  511. return Result::error("上传失败!");
  512. }
  513. }
  514. /**
  515. * 黑名单管理
  516. * @param array $data
  517. * @return array
  518. */
  519. public function getBlackWordList(array $data): array
  520. {
  521. $result = BlackWord::when($data, function ($query) use ($data) {
  522. if (isset($data['name']) && $data['name']) {
  523. $query->where('black_word.name', 'like', '%' . $data['name'] . '%');
  524. }
  525. })->orderBy('black_word.id', 'desc')
  526. ->paginate(
  527. intval($data['pageSize']),
  528. [
  529. 'black_word.*',
  530. ],
  531. 'page',
  532. intval($data['page'])
  533. );
  534. $count = $result->total();
  535. $returnData = [
  536. 'rows' => $result->items(),
  537. 'count' => $count
  538. ];
  539. return Result::success($returnData);
  540. }
  541. /**
  542. * 添加黑名单
  543. * @param array $data
  544. * @return array
  545. */
  546. public function addBlackWord(array $data): array
  547. {
  548. Db::beginTransaction();
  549. try {
  550. $info = BlackWord::where(['name' => $data['name']])->first();
  551. if ($info) {
  552. Db::rollBack();
  553. return Result::error("该黑名单已存在", 0);
  554. }
  555. $data['type'] = 10;
  556. $result = BlackWord::insertGetId($data);
  557. $redisKey = 'black_word';
  558. $this->redis->sAdd($redisKey, $data['name']);
  559. Db::commit();
  560. return Result::success(["id" => $result]);
  561. } catch (\Exception $e) {
  562. Db::rollBack();
  563. return Result::error("创建失败" . $e->getMessage(), 0);
  564. }
  565. }
  566. /**
  567. * 删除黑名单
  568. * @param array $data
  569. * @return array
  570. */
  571. public function delBlackWord(array $data): array
  572. {
  573. Db::beginTransaction();
  574. try {
  575. BlackWord::where(['name' => $data['name']])->delete();
  576. $redisKey = 'black_word';
  577. $this->redis->sRem($redisKey, $data['name']);
  578. Db::commit();
  579. return Result::success([]);
  580. } catch (\Exception $e) {
  581. Db::rollBack();
  582. return Result::error("删除失败" . $e->getMessage(), 0);
  583. }
  584. }
  585. /**
  586. * 修改违禁词
  587. * @param array $data
  588. * @return array
  589. */
  590. public function upBlackWord(array $data): array
  591. {
  592. Db::beginTransaction();
  593. try {
  594. $checkInfo = BlackWord::where(['name' => $data['name']])->first();
  595. if ($checkInfo) {
  596. Db::rollBack();
  597. return Result::error("该违禁词已经存在", 0);
  598. }
  599. $blackWordInfo = BlackWord::where(['id' => $data['id']])->first();
  600. if ($blackWordInfo) {
  601. //先删除redis
  602. $blackWordInfo = $blackWordInfo->toArray();
  603. $redisKey = 'black_word';
  604. $this->redis->sRem($redisKey, $blackWordInfo['name']);
  605. $this->redis->sAdd($redisKey, $data['name']);
  606. BlackWord::where(['id' => $data['id']])->update(['name' => $data['name']]);
  607. Db::commit();
  608. return Result::success([]);
  609. } else {
  610. Db::rollBack();
  611. return Result::error("系统错误", 0);
  612. }
  613. } catch (\Exception $e) {
  614. Db::rollBack();
  615. return Result::error("修改失败" . $e->getMessage(), 0);
  616. }
  617. }
  618. /**
  619. * 获取风格
  620. * @return void
  621. */
  622. public function getTemplateClassList(array $data): array
  623. {
  624. $where = [];
  625. if (isset($data['name']) && $data['name']) {
  626. array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
  627. }
  628. if(isset($data['keyword']) && $data['keyword']){
  629. array_push($where, ['template_class.keyword', 'like', '%'. $data['keyword']. '%']);
  630. }
  631. $template = TemplateClass::when($where, function ($query) use ($where) {
  632. $query->where($where);
  633. });
  634. $count = $template->count();
  635. // $countQuery = clone $template;
  636. $row = $template
  637. ->leftJoin('template', 'template_class.id', '=', 'template.template_class_id')
  638. ->select('template_class.*', DB::raw('COUNT(template.id) as template_count'))
  639. ->groupBy('template_class.id')
  640. ->orderBy('template_class.id', 'desc')
  641. ->offset(($data['page'] - 1) * $data['pageSize'])
  642. ->limit($data['pageSize'])
  643. ->get();
  644. $result = [
  645. 'rows' => $row,
  646. 'count' => $count,
  647. ];
  648. if ($row->isEmpty()) {
  649. return Result::error("暂无风格", 0);
  650. } else {
  651. return Result::success($result);
  652. }
  653. }
  654. /**
  655. * 添加风格
  656. * @param
  657. * @return void
  658. */
  659. public function addTemplateClass(array $data): array
  660. {
  661. $data['keyword'] = json_encode($data['keyword']);
  662. $template_class = TemplateClass::where('name', $data['name'])
  663. ->orWhere('class_id', $data['class_id'])
  664. ->first();
  665. if ($template_class) {
  666. return Result::error("风格名称或者风格编号已存在,不可添加!", 0);
  667. }
  668. $result = TemplateClass::insertGetId($data);
  669. if (empty($result)) {
  670. return Result::error("创建风格失败", 0);
  671. } else {
  672. return Result::success(["id" => $result]);
  673. }
  674. }
  675. /**
  676. * 更新风格
  677. * @param array $data
  678. * @return array
  679. */
  680. public function upTemplateClass(array $data): array
  681. {
  682. $where = [
  683. 'id' => $data['id'],
  684. ];
  685. $template_class = TemplateClass::where($where)->first();
  686. if (empty($template_class)) {
  687. return Result::error("未查询到风格", 0);
  688. }
  689. if($template_class->type == 1){
  690. return Result::error("默认风格不能修改", 0);
  691. }
  692. $template = TemplateClass::where('id','!=',$data['id'])
  693. // ->where(['name' => $data['name']])
  694. // ->orWhere(['class_id' => $data['class_id']])
  695. ->where(function ($query) use ($data) {
  696. $query->where('name', $data['name'])
  697. ->orWhere('class_id', $data['class_id']);
  698. })
  699. ->first();
  700. if ($template) {
  701. return Result::error("风格名称或者风格编号已存在,不可编辑!", 0);
  702. }
  703. $updateData = [
  704. 'name' => $data['name'],
  705. 'keyword' => json_encode($data['keyword']),
  706. 'class_id' => $data['class_id'],
  707. ];
  708. $result = TemplateClass::where($where)->update($updateData);
  709. if (empty($result)) {
  710. return Result::error("更新失败", 0);
  711. } else {
  712. return Result::success($result);
  713. }
  714. }
  715. /**
  716. * 删除风格
  717. * @param array $data
  718. * @return array
  719. */
  720. public function delTemplateClass(array $data): array
  721. {
  722. $where = [
  723. 'id' => $data['id'],
  724. ];
  725. $template = TemplateClass::where($where)->first();
  726. if (empty($template)) {
  727. return Result::error("未查询到风格", 0);
  728. }
  729. if($template->type == 1){
  730. return Result::error("默认风格不能删除", 0);
  731. }
  732. $result = TemplateClass::where($where)->delete();
  733. if (empty($result)) {
  734. return Result::error("删除失败", 0);
  735. } else {
  736. return Result::success($result);
  737. }
  738. }
  739. /**
  740. * 获取getTemplateClass
  741. * @param array $data
  742. * @return array
  743. */
  744. public function getTemplateClass(array $data): array
  745. {
  746. $result = TemplateClass::get();
  747. return Result::success($result);
  748. }
  749. /**
  750. * 获取皮肤列表
  751. * @param array $data
  752. * @return array
  753. */
  754. public function getTemplateList(array $data): array
  755. {
  756. $where = [];
  757. if (!empty($data['template_class_id'])) {
  758. $where['template_class_id'] = $data['template_class_id'];
  759. }
  760. if (!empty($data['template_name'])) {
  761. array_push($where, ['template_name', 'like', '%'. $data['template_name']. '%']);
  762. }
  763. if (!empty($data['template_keyword'])) {
  764. array_push($where, ['template_keyword', 'like', '%'. $data['template_keyword']. '%']);
  765. }
  766. $result = Template::where($where)
  767. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  768. ->select('template.*', 'template_class.name as template_class_name')
  769. ->orderBy('template.id', 'desc')
  770. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  771. if(empty($result)){
  772. return Result::error("暂无皮肤", 0);
  773. }
  774. return Result::success($result);
  775. }
  776. public function getTemplateInfo(array $data): array
  777. {
  778. $result = Template::where('template.id', $data['id'])
  779. ->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
  780. ->select('template.*', 'template_class.name as template_class_name')
  781. ->first();
  782. if(empty($result)){
  783. return Result::error("暂无皮肤", 0);
  784. }
  785. return Result::success($result);
  786. }
  787. /**
  788. * 添加皮肤
  789. * @param array $data
  790. * @return array
  791. */
  792. public function addTemplate(array $data): array
  793. {
  794. var_dump($data);
  795. unset($data['user_id']);
  796. $template = Template::where('template_name', $data['template_name'])
  797. ->orWhere('template_id', $data['template_id'])
  798. ->first();
  799. if ($template) {
  800. return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
  801. }
  802. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  803. $page_type = json_decode($data['page_type'], true);
  804. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  805. $result = Template::insertGetId($data);
  806. if(empty($result)){
  807. return Result::error("创建失败", 0);
  808. }else{
  809. return Result::success($result);
  810. }
  811. }
  812. /**
  813. * 删除皮肤
  814. * @param array $data
  815. * @return array
  816. */
  817. public function delTemplate(array $data): array
  818. {
  819. $result = Template::where('id', $data['id'])->delete();
  820. var_dump($result, '-------------------delete');
  821. if ($result) {
  822. return Result::success($result);
  823. } else {
  824. return Result::error("删除失败", 0);
  825. }
  826. }
  827. /**
  828. * 更新皮肤
  829. * @param array $data
  830. * @return array
  831. */
  832. public function updateTemplate(array $data): array
  833. {
  834. unset($data['user_id']);
  835. $template = Template::where('id', $data['id'])
  836. ->first();
  837. if (empty($template)) {
  838. return Result::error("此皮肤不存在!", 0);
  839. }
  840. $template = Template::where('id', '!=', $data['id'])
  841. ->where(function ($query) use ($data) {
  842. $query->where('template_name', $data['template_name'])
  843. ->orWhere('template_id', $data['template_id']);
  844. })
  845. ->first();
  846. if ($template) {
  847. return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
  848. }
  849. $data['template_keyword'] = json_encode($data['template_keyword']) ?? '';
  850. $page_type = json_decode($data['page_type'], true);
  851. $data['page_type'] = json_encode(array_values(array_unique($page_type)));
  852. $result = Template::where('id', $data['id'])->update($data);
  853. var_dump($result, '-------------------update');
  854. if (!$result) {
  855. return Result::error("更新失败", 0);
  856. } else {
  857. return Result::success('更新成功');
  858. }
  859. }
  860. public function getSectorList(array $data): array
  861. {
  862. $where = [];
  863. if (!empty($data['template_class_id'])) {
  864. $where['template_class.id'] = $data['template_class_id'];
  865. }
  866. if (!empty($data['template_class_name'])) {
  867. $where[] = ['template_class.name', 'like', '%' . $data['template_class_name'] . '%'];
  868. }
  869. if (!empty($data['sector_name'])) {
  870. if (!empty($data['sector_name'])) {
  871. // $where['sector_name'] = $data['sector_name'];
  872. $where[] = ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%'];
  873. }
  874. }
  875. $result = Sector::where($where)
  876. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  877. ->leftJoin('template_class', 'template_class.id', '=', 'sector.template_id') // 添加这一行
  878. ->select('sector.*', 'sector.sector_name', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  879. ->orderBy('sector.id', 'desc')
  880. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  881. return Result::success($result);
  882. }
  883. public function getSectorInfo(array $data): array
  884. {
  885. $where = [];
  886. $where[] = ['sector.id', '=', $data['id']];
  887. $result = Sector::where($where)
  888. ->leftJoin('template', 'template.id', '=', 'sector.template_id')
  889. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  890. ->select('sector.*', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
  891. ->orderBy('sector.id', 'desc')
  892. ->get();
  893. return Result::success($result);
  894. }
  895. /**
  896. * 获取经纬度信息
  897. * @return void
  898. */
  899. public function getIpInfo(array $data) :array
  900. {
  901. $client_ip = isset($data['ip']) && $data['ip']??$_SERVER['REMOTE_ADDR'];
  902. // 使用 IPinfo 服务获取 IP 信息
  903. // $api_url = "https://ipinfo.io/{$client_ip}/json";
  904. //http://ip-api.com/json/117.136.12.79?lang=zh-cn
  905. $api_url = "http://ip-api.com/json/{$client_ip}/?lang=zh-cn";
  906. $ch = curl_init($api_url);
  907. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  908. $response = curl_exec($ch);
  909. curl_close($ch);
  910. // 解析 JSON 响应
  911. $ip_info = json_decode($response, true);
  912. // 提取地址和经纬度
  913. if ($ip_info) {
  914. // $latitude = explode(',', $ip_info['loc'])[0];
  915. // $longitude = explode(',', $ip_info['loc'])[1];
  916. $ip_info['latitude'] = $ip_info['lat'];
  917. $ip_info['longitude'] = $ip_info['lon'];
  918. return Result::success($ip_info);
  919. } else {
  920. $data['ip'] = '101.254.114.212';
  921. $this->getIpinfo(["ip"=>$data['ip']]);
  922. }
  923. }
  924. /**
  925. * 获取天气
  926. * @param array $data
  927. * @return array
  928. */
  929. public function getWeatherInfo(array $data) :array
  930. {
  931. $month = $data['month'] ?? date('m');
  932. $day = $data['day'] ?? date('d');
  933. // 使用缓存键
  934. $cacheKey = "tsbb_data_weather_{$month}_{$day}";
  935. // 尝试从缓存获取数据
  936. $container = \Hyperf\Context\ApplicationContext::getContainer();
  937. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  938. if ($cachedData = $cache->get($cacheKey)) {
  939. return Result::success(unserialize($cachedData));
  940. }
  941. $location = $data['latitude'].":".$data['longitude'];
  942. $api_url = "https://api.seniverse.com/v3/weather/now.json?key=".\Hyperf\Support\env('WEATHER_KEY')."&location=".$location."&language=zh-Hans&unit=c";
  943. $ch = curl_init($api_url);
  944. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  945. $response = curl_exec($ch);
  946. curl_close($ch);
  947. // 解析 JSON 响应
  948. $WeatherInfo = json_decode($response, true);
  949. // 缓存结果,设置1小时过期
  950. $cache->set($cacheKey, serialize($WeatherInfo), 3600);
  951. if($WeatherInfo){
  952. return Result::success($WeatherInfo);
  953. }else{
  954. return Result::error("获取天气失败", 0);
  955. }
  956. }
  957. /**
  958. * 获取农历信息
  959. * @return void
  960. */
  961. public function getCalendar(array $data) :array
  962. {
  963. $calendar = new Calendar();
  964. $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
  965. return Result::success($result);
  966. }
  967. public function addSector(array $data): array
  968. {
  969. unset($data['user_id']);
  970. // $data['page_type'] = json_encode($data['page_type']);
  971. $result = Sector::insertGetId($data);
  972. return Result::success();
  973. }
  974. public function delSector(array $data): array
  975. {
  976. $result = Sector::where('id', $data['id'])->delete();
  977. if ($result == 1) {
  978. return Result::success('删除成功');
  979. } else {
  980. return Result::error('删除失败');
  981. }
  982. }
  983. public function updateSector(array $data): array
  984. {
  985. unset($data['user_id']);
  986. $result = Sector::where('id', $data['id'])->update($data);
  987. if ($result == 1) {
  988. return Result::success('修改成功');
  989. } else {
  990. return Result::error('修改失败');
  991. }
  992. }
  993. public function getComponentList(array $data): array
  994. {
  995. var_dump($data, '---------');
  996. $where = [];
  997. // $where[] = ['sector.id', '=', $data['id']];
  998. if (!empty($data['template_class_id'])) {
  999. $where['template_class.id'] = $data['template_class_id'];
  1000. }
  1001. if (!empty($data['component_name'])) {
  1002. $where['component.component_name'] = $data['component_name'];
  1003. }
  1004. if (!empty($data['sector_id'])) {
  1005. $where['sector.id'] = $data['sector_id'];
  1006. };
  1007. $result = Component::where($where)
  1008. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1009. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1010. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1011. ->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') // 修改这一行)
  1012. ->orderBy('sector.updated_at', 'desc')
  1013. ->orderBy('sector.created_at', 'desc')
  1014. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  1015. return Result::success($result);
  1016. }
  1017. public function getComponentInfo(array $data): array
  1018. {
  1019. $where = [];
  1020. $result = Component::where($where)
  1021. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1022. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1023. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1024. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
  1025. ->get();
  1026. return Result::success($result);
  1027. }
  1028. public function addComponent(array $data): array
  1029. {
  1030. unset($data['user_id']);
  1031. $result = Component::insertGetId($data);
  1032. if ($result) {
  1033. return Result::success($result);
  1034. } else {
  1035. return Result::error('添加失败');
  1036. }
  1037. }
  1038. public function delComponent(array $data): array
  1039. {
  1040. $result = Component::where('id', $data['id'])->delete();
  1041. return Result::success($result);
  1042. }
  1043. public function updateComponent(array $data): array
  1044. {
  1045. $result = Component::where('id', $data['id'])->update($data);
  1046. return Result::success($result);
  1047. }
  1048. public function getWebsiteTemplateInfo(array $data)
  1049. {
  1050. $where = [];
  1051. if (isset($data['id'])) {
  1052. $where[] = ['id', '=', $data['id']];
  1053. }
  1054. $result = WebsiteTemplateInfo::where($where)
  1055. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1056. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  1057. ->select('website_template_info.*', 'website.website_name')
  1058. ->get();
  1059. if ($result) {
  1060. return Result::success($result);
  1061. } else {
  1062. return Result::error('暂无数据');
  1063. }
  1064. }
  1065. /**
  1066. * 自助建站----1.获取页面类型回显
  1067. * @param array $data
  1068. * @return array
  1069. */
  1070. public function getWebPageType(array $data): array
  1071. {
  1072. // 1:图片 2:文字 3:底部
  1073. $friend_link = Link::where('website_id', $data['website_id'])->where('type',3)->get();
  1074. if(empty($friend_link->toArray())){
  1075. return Result::error('暂无友情链接数据!');
  1076. }
  1077. $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
  1078. if(empty($footer_category->toArray())){
  1079. return Result::error('暂无底部导航数据!');
  1080. }
  1081. $result = [
  1082. 'friend_link' => $friend_link,
  1083. 'footer_category' => $footer_category,
  1084. ];
  1085. return Result::success($result);
  1086. }
  1087. /**
  1088. * 自助建站----2.添加页面类型
  1089. * @param array $data
  1090. * @return array
  1091. */
  1092. public function addWebPageType(array $data): array
  1093. {
  1094. // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
  1095. if($data['is_search'] == 1){
  1096. $page_type = json_encode([1,2,3,4,5,6,7]);
  1097. }else{
  1098. $page_type = json_encode([1,2,3,4,6,7]);
  1099. }
  1100. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1101. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type],['action_id' => 1]);
  1102. if ($result) {
  1103. return Result::success($result);
  1104. } else {
  1105. return Result::error('添加失败');
  1106. }
  1107. }
  1108. /**
  1109. * 自助建站---流程---3.选择皮肤列表
  1110. * @param array $data
  1111. * @return array
  1112. */
  1113. public function getWebsiteTemplateList(array $data): array
  1114. {
  1115. $where = [];
  1116. if(isset($data['template_class_id']) && $data['template_class_id']){
  1117. $where[] = ['template_class_id', '=', $data['template_class_id']];
  1118. }
  1119. // 0:未构建 1:未应用 2:已应用 status
  1120. $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1121. if(empty($templste_info)){
  1122. return Result::error('请先填写网站基础信息!');
  1123. }
  1124. if($templste_info['status'] == 2){
  1125. return Result::error('网站已应用,不可再次修改!');
  1126. }
  1127. if(isset($data['keyword']) && !empty($data['keyword'])){
  1128. if (is_array($data['keyword'])) {
  1129. // 拼接多个模糊查询条件
  1130. $query = Template::query();
  1131. foreach ($data['keyword'] as $kw) {
  1132. $escapedKw = addcslashes($kw, '%_'); // 转义通配符
  1133. $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
  1134. }
  1135. } else {
  1136. $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
  1137. $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
  1138. }
  1139. }
  1140. $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
  1141. // return Result::success($template_id);
  1142. if(!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])){
  1143. $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
  1144. }else{
  1145. $template_page = [];
  1146. }
  1147. if(!empty($template_id['template_id'])){
  1148. $result['template_id'] = $templste_info['template_id'];
  1149. }
  1150. // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
  1151. $template_page_str = json_encode($template_page);
  1152. if (isset($query)) {
  1153. $result['template'] = $query->where($where)
  1154. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1155. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1156. } else {
  1157. $result['template'] = Template::where($where)
  1158. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1159. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1160. }
  1161. if (empty($result['template']['data'])) {
  1162. $result['template'] = Template::orderBy('updated_at','desc')
  1163. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1164. }
  1165. return Result::success($result);
  1166. }
  1167. /**
  1168. * 自助建站---流程---4.选择皮肤
  1169. * @param array $data
  1170. * @return array
  1171. */
  1172. public function chooseWebsiteTemplate(array $data): array
  1173. {
  1174. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1175. if(empty($website_template_info)){
  1176. return Result::error('请先填写网站基础信息!');
  1177. }
  1178. // 0:未构建 1:未应用 2:已应用 status
  1179. if($website_template_info['status'] == 2){
  1180. return Result::error('网站已应用,不可再次修改!');
  1181. }
  1182. $template = Template::where('id', $data['template_id'])->first();
  1183. if(empty($template)){
  1184. return Result::error('未查询到皮肤!');
  1185. }
  1186. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1187. $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'],'action_id' => 2]);
  1188. if ($web_template) {
  1189. return Result::success($web_template);
  1190. } else {
  1191. return Result::error('选择皮肤失败!');
  1192. }
  1193. }
  1194. /**
  1195. * 自助建站---流程---5.选择组件
  1196. * @param array $data
  1197. * @return array
  1198. */
  1199. public function saveWebsiteTemplate(array $data): array
  1200. {
  1201. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1202. if(empty($website_template_info)){
  1203. return Result::error('请先填写网站基础信息!');
  1204. }
  1205. // 0:未构建 1:未应用 2:已应用 status
  1206. if($website_template_info['status'] == 2){
  1207. return Result::error('网站已应用,不可再次保存!');
  1208. }
  1209. if($website_template_info['action_id'] != 2){
  1210. return Result::error('请完成之前的步骤!');
  1211. }
  1212. $template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1213. if(empty($template_info)){
  1214. $template = WebsiteTemplate::insertGetId(['website_id' => $data['website_id'],'template_data' => $data['template_data']]);
  1215. }else{
  1216. $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(['template_data' => $data['template_data']]);
  1217. }
  1218. if(empty($template)){
  1219. return Result::error('保存失败!');
  1220. }else{
  1221. return Result::success($template);
  1222. }
  1223. }
  1224. /**
  1225. * 企业管理
  1226. * @param array $data
  1227. * @return array
  1228. */
  1229. public function getCompanyList(array $data): array
  1230. {
  1231. $where = [];
  1232. $user = User::where('id', $data['user_id'])->first();
  1233. if(empty($user)){
  1234. return Result::error('用户不存在!');
  1235. }
  1236. if($user['type_id']!= 10000){
  1237. $where['user_id'] = $data['user_id'];
  1238. }
  1239. if(isset($data['title']) && $data['title']){
  1240. array_push($where, ['title', 'like', '%'. $data['title']. '%']);
  1241. }
  1242. if(isset($data['website_id']) && $data['website_id']){
  1243. $where['website_id'] = $data['website_id'];
  1244. }
  1245. // 状态:0:未审核 1:已审核 2:已拒绝
  1246. $pageSize = isset($data['pageSize']) ? (int)$data['pageSize'] : 10; // 默认每页 10 条记录
  1247. $page = isset($data['page']) ? (int)$data['page'] : 1; // 默认第 1 页
  1248. if(isset($data['ischeck']) && !empty($data['ischeck'])){
  1249. if($data['ischeck'] == 1){
  1250. $query = Company::whereIn('status', [0,2]);
  1251. }else{
  1252. $query = Company::where('status', 1);
  1253. }
  1254. }
  1255. $result = $query->where($where)->paginate($pageSize, ['*'], 'page', $page);
  1256. if(empty($result)){
  1257. return Result::error("暂无企业", 0);
  1258. }
  1259. return Result::success($result);
  1260. }
  1261. /**
  1262. * 添加企业
  1263. * @param array $data
  1264. * @return array
  1265. */
  1266. public function addCompany(array $data): array
  1267. {
  1268. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  1269. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1270. if ($data['imgurl'] == '') {
  1271. //content中提取图片第一个图,正则提取
  1272. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  1273. preg_match_all($reg, $data['content'], $matches);
  1274. if (isset($matches[1][0])) {
  1275. //截取varchar240
  1276. $data['imgurl'] = substr($matches[1][0], 0, 240);
  1277. }
  1278. }
  1279. if ($data['keyword'] == '') {
  1280. //提取标题+内容中的关键词
  1281. $data['keyword'] = $data['title'];
  1282. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  1283. Jieba::init(); // 初始化 jieba-php
  1284. Finalseg::init();
  1285. $segList = Jieba::cut($data['keyword']);
  1286. $segList1 = array_slice($segList, 0, 8);
  1287. $data['keyword'] = implode(',', $segList1);
  1288. }
  1289. if ($data['introduce'] == '') {
  1290. //提取内容中的描述
  1291. $data['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  1292. }
  1293. $user = User::where('id', $data['user_id'])->first();
  1294. if(empty($user)){
  1295. return Result::error('用户不存在!');
  1296. }
  1297. if($user['type_id']== 10000){
  1298. $data['status'] = 1;
  1299. }
  1300. $result = Company::insertGetId($data);
  1301. if ($result) {
  1302. return Result::success($result);
  1303. } else {
  1304. return Result::error('添加失败');
  1305. }
  1306. }
  1307. /**
  1308. * 更新企业
  1309. * @param array $data
  1310. * @return array
  1311. */
  1312. public function upCompany(array $data): array
  1313. {
  1314. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  1315. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1316. if ($data['imgurl'] == '') {
  1317. //content中提取图片第一个图,正则提取
  1318. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  1319. preg_match_all($reg, $data['content'], $matches);
  1320. if (isset($matches[1][0])) {
  1321. //截取varchar240
  1322. $data['imgurl'] = substr($matches[1][0], 0, 240);
  1323. }
  1324. }
  1325. if ($data['keyword'] == '') {
  1326. //提取标题+内容中的关键词
  1327. $data['keyword'] = $data['title'];
  1328. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  1329. Jieba::init(); // 初始化 jieba-php
  1330. Finalseg::init();
  1331. $segList = Jieba::cut($data['keyword']);
  1332. $segList1 = array_slice($segList, 0, 8);
  1333. $data['keyword'] = implode(',', $segList1);
  1334. }
  1335. if ($data['introduce'] == '') {
  1336. //提取内容中的描述
  1337. $data['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  1338. }
  1339. $user = User::where('id', $data['user_id'])->first();
  1340. if(empty($user)){
  1341. return Result::error('用户不存在!');
  1342. }
  1343. if($user['type_id']== 10000){
  1344. $data['status'] = 1;
  1345. }else{
  1346. $data['status'] = 0;
  1347. }
  1348. $result = Company::where('id', $data['id'])->update($data);
  1349. if ($result) {
  1350. return Result::success($result);
  1351. } else {
  1352. return Result::error('修改失败');
  1353. }
  1354. }
  1355. /**
  1356. * 删除企业
  1357. * @param array $data
  1358. * @return array
  1359. */
  1360. public function delCompany(array $data): array
  1361. {
  1362. $result = Company::where('id', $data['id'])->delete();
  1363. if ($result) {
  1364. return Result::success($result);
  1365. } else {
  1366. return Result::error('删除失败');
  1367. }
  1368. }
  1369. /**
  1370. * 审核企业
  1371. * @param array $data
  1372. * @return array
  1373. */
  1374. public function checkCompany(array $data): array
  1375. {
  1376. $user = User::where('id', $data['user_id'])->first();
  1377. if(empty($user)){
  1378. return Result::error('用户不存在!');
  1379. }
  1380. $company = Company::where('id', $data['id'])->first();
  1381. if(empty($company)){
  1382. return Result::error('企业不存在!');
  1383. }
  1384. // 状态:0:未审核 1:已审核 2:已拒绝
  1385. if($company['status'] == 0 || $company['status'] == 1){
  1386. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  1387. }else{
  1388. $result = Company::where('id', $data['id'])->update(['status' => $data['status'],'reject_reason'=> $data['reject_reason']]);
  1389. }
  1390. if(empty($result)){
  1391. return Result::error('审核失败!');
  1392. }else{
  1393. return Result::success($result);
  1394. }
  1395. }
  1396. /**
  1397. * 获取企业信息
  1398. * @param array $data
  1399. * @return array
  1400. */
  1401. public function getCompanyInfo(array $data): array
  1402. {
  1403. $result = Company::where('id', $data['id'])->first();
  1404. if(empty($result)){
  1405. return Result::error('企业不存在!');
  1406. }else{
  1407. return Result::success($result);
  1408. }
  1409. }
  1410. }