PublicRpcService.php 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464
  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. $ch = curl_init($api_url);
  905. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  906. $response = curl_exec($ch);
  907. curl_close($ch);
  908. // 解析 JSON 响应
  909. $ip_info = json_decode($response, true);
  910. // 提取地址和经纬度
  911. if ($ip_info && !isset($ip_info['bogon'])) {
  912. $latitude = explode(',', $ip_info['loc'])[0];
  913. $longitude = explode(',', $ip_info['loc'])[1];
  914. $ip_info['latitude'] = $latitude;
  915. $ip_info['longitude'] = $longitude;
  916. return Result::success($ip_info);
  917. } else {
  918. $data['ip'] = '101.254.114.212';
  919. $this->getIpinfo(["ip"=>$data['ip']]);
  920. }
  921. }
  922. /**
  923. * 获取天气
  924. * @param array $data
  925. * @return array
  926. */
  927. public function getWeatherInfo(array $data) :array
  928. {
  929. $month = $data['month'] ?? date('m');
  930. $day = $data['day'] ?? date('d');
  931. // 使用缓存键
  932. $cacheKey = "tsbb_data_weather_{$month}_{$day}";
  933. // 尝试从缓存获取数据
  934. $container = \Hyperf\Context\ApplicationContext::getContainer();
  935. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  936. if ($cachedData = $cache->get($cacheKey)) {
  937. return Result::success(unserialize($cachedData));
  938. }
  939. $location = $data['latitude'].":".$data['longitude'];
  940. $api_url = "https://api.seniverse.com/v3/weather/now.json?key=".\Hyperf\Support\env('WEATHER_KEY')."&location=".$location."&language=zh-Hans&unit=c";
  941. $ch = curl_init($api_url);
  942. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  943. $response = curl_exec($ch);
  944. curl_close($ch);
  945. // 解析 JSON 响应
  946. $WeatherInfo = json_decode($response, true);
  947. // 缓存结果,设置1小时过期
  948. $cache->set($cacheKey, serialize($WeatherInfo), 3600);
  949. if($WeatherInfo){
  950. return Result::success($WeatherInfo);
  951. }else{
  952. return Result::error("获取天气失败", 0);
  953. }
  954. }
  955. /**
  956. * 获取农历信息
  957. * @return void
  958. */
  959. public function getCalendar(array $data) :array
  960. {
  961. $calendar = new Calendar();
  962. $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
  963. return Result::success($result);
  964. }
  965. public function addSector(array $data): array
  966. {
  967. unset($data['user_id']);
  968. // $data['page_type'] = json_encode($data['page_type']);
  969. $result = Sector::insertGetId($data);
  970. return Result::success();
  971. }
  972. public function delSector(array $data): array
  973. {
  974. $result = Sector::where('id', $data['id'])->delete();
  975. if ($result == 1) {
  976. return Result::success('删除成功');
  977. } else {
  978. return Result::error('删除失败');
  979. }
  980. }
  981. public function updateSector(array $data): array
  982. {
  983. unset($data['user_id']);
  984. $result = Sector::where('id', $data['id'])->update($data);
  985. if ($result == 1) {
  986. return Result::success('修改成功');
  987. } else {
  988. return Result::error('修改失败');
  989. }
  990. }
  991. public function getComponentList(array $data): array
  992. {
  993. var_dump($data, '---------');
  994. $where = [];
  995. // $where[] = ['sector.id', '=', $data['id']];
  996. if (!empty($data['template_class_id'])) {
  997. $where['template_class.id'] = $data['template_class_id'];
  998. }
  999. if (!empty($data['component_name'])) {
  1000. $where['component.component_name'] = $data['component_name'];
  1001. }
  1002. if (!empty($data['sector_id'])) {
  1003. $where['sector.id'] = $data['sector_id'];
  1004. };
  1005. $result = Component::where($where)
  1006. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1007. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1008. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1009. ->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') // 修改这一行)
  1010. ->orderBy('sector.updated_at', 'desc')
  1011. ->orderBy('sector.created_at', 'desc')
  1012. ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
  1013. return Result::success($result);
  1014. }
  1015. public function getComponentInfo(array $data): array
  1016. {
  1017. $where = [];
  1018. $result = Component::where($where)
  1019. ->leftJoin('template', 'template.id', '=', 'component.template_id')
  1020. ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
  1021. ->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
  1022. ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
  1023. ->get();
  1024. return Result::success($result);
  1025. }
  1026. public function addComponent(array $data): array
  1027. {
  1028. unset($data['user_id']);
  1029. $result = Component::insertGetId($data);
  1030. if ($result) {
  1031. return Result::success($result);
  1032. } else {
  1033. return Result::error('添加失败');
  1034. }
  1035. }
  1036. public function delComponent(array $data): array
  1037. {
  1038. $result = Component::where('id', $data['id'])->delete();
  1039. return Result::success($result);
  1040. }
  1041. public function updateComponent(array $data): array
  1042. {
  1043. $result = Component::where('id', $data['id'])->update($data);
  1044. return Result::success($result);
  1045. }
  1046. public function getWebsiteTemplateInfo(array $data)
  1047. {
  1048. $where = [];
  1049. if (isset($data['id'])) {
  1050. $where[] = ['id', '=', $data['id']];
  1051. }
  1052. $result = WebsiteTemplateInfo::where($where)
  1053. ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id')
  1054. ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id')
  1055. ->select('website_template_info.*', 'website.website_name')
  1056. ->get();
  1057. if ($result) {
  1058. return Result::success($result);
  1059. } else {
  1060. return Result::error('暂无数据');
  1061. }
  1062. }
  1063. /**
  1064. * 自助建站----1.获取页面类型回显
  1065. * @param array $data
  1066. * @return array
  1067. */
  1068. public function getWebPageType(array $data): array
  1069. {
  1070. // 1:图片 2:文字 3:底部
  1071. $friend_link = Link::where('website_id', $data['website_id'])->where('type',3)->get();
  1072. if(empty($friend_link->toArray())){
  1073. return Result::error('暂无友情链接数据!');
  1074. }
  1075. $footer_category = FooterCategory::where('website_id', $data['website_id'])->get();
  1076. if(empty($footer_category->toArray())){
  1077. return Result::error('暂无底部导航数据!');
  1078. }
  1079. $result = [
  1080. 'friend_link' => $friend_link,
  1081. 'footer_category' => $footer_category,
  1082. ];
  1083. return Result::success($result);
  1084. }
  1085. /**
  1086. * 自助建站----2.添加页面类型
  1087. * @param array $data
  1088. * @return array
  1089. */
  1090. public function addWebPageType(array $data): array
  1091. {
  1092. // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页'
  1093. if($data['is_search'] == 1){
  1094. $page_type = json_encode([1,2,3,4,5,6,7]);
  1095. }else{
  1096. $page_type = json_encode([1,2,3,4,6,7]);
  1097. }
  1098. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1099. $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type],['action_id' => 1]);
  1100. if ($result) {
  1101. return Result::success($result);
  1102. } else {
  1103. return Result::error('添加失败');
  1104. }
  1105. }
  1106. /**
  1107. * 自助建站---流程---3.选择皮肤列表
  1108. * @param array $data
  1109. * @return array
  1110. */
  1111. public function getWebsiteTemplateList(array $data): array
  1112. {
  1113. $where = [];
  1114. if(isset($data['template_class_id']) && $data['template_class_id']){
  1115. $where[] = ['template_class_id', '=', $data['template_class_id']];
  1116. }
  1117. // 0:未构建 1:未应用 2:已应用 status
  1118. $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1119. if(empty($templste_info)){
  1120. return Result::error('请先填写网站基础信息!');
  1121. }
  1122. if($templste_info['status'] == 2){
  1123. return Result::error('网站已应用,不可再次修改!');
  1124. }
  1125. if(isset($data['keyword']) && !empty($data['keyword'])){
  1126. if (is_array($data['keyword'])) {
  1127. // 拼接多个模糊查询条件
  1128. $query = Template::query();
  1129. foreach ($data['keyword'] as $kw) {
  1130. $escapedKw = addcslashes($kw, '%_'); // 转义通配符
  1131. $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]);
  1132. }
  1133. } else {
  1134. $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符
  1135. $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"];
  1136. }
  1137. }
  1138. $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']);
  1139. // return Result::success($template_id);
  1140. if(!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])){
  1141. $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : [];
  1142. }else{
  1143. $template_page = [];
  1144. }
  1145. if(!empty($template_id['template_id'])){
  1146. $result['template_id'] = $templste_info['template_id'];
  1147. }
  1148. // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定
  1149. $template_page_str = json_encode($template_page);
  1150. if (isset($query)) {
  1151. $result['template'] = $query->where($where)
  1152. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1153. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1154. } else {
  1155. $result['template'] = Template::where($where)
  1156. ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str])
  1157. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1158. }
  1159. if (empty($result['template']['data'])) {
  1160. $result['template'] = Template::orderBy('updated_at','desc')
  1161. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  1162. }
  1163. return Result::success($result);
  1164. }
  1165. /**
  1166. * 自助建站---流程---4.选择皮肤
  1167. * @param array $data
  1168. * @return array
  1169. */
  1170. public function chooseWebsiteTemplate(array $data): array
  1171. {
  1172. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1173. if(empty($website_template_info)){
  1174. return Result::error('请先填写网站基础信息!');
  1175. }
  1176. // 0:未构建 1:未应用 2:已应用 status
  1177. if($website_template_info['status'] == 2){
  1178. return Result::error('网站已应用,不可再次修改!');
  1179. }
  1180. $template = Template::where('id', $data['template_id'])->first();
  1181. if(empty($template)){
  1182. return Result::error('未查询到皮肤!');
  1183. }
  1184. // 0:未构建;1:已填写基础信息;2:已选择模板; action_id
  1185. $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'],'action_id' => 2]);
  1186. if ($web_template) {
  1187. return Result::success($web_template);
  1188. } else {
  1189. return Result::error('选择皮肤失败!');
  1190. }
  1191. }
  1192. /**
  1193. * 自助建站---流程---5.选择组件
  1194. * @param array $data
  1195. * @return array
  1196. */
  1197. public function saveWebsiteTemplate(array $data): array
  1198. {
  1199. $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1200. if(empty($website_template_info)){
  1201. return Result::error('请先填写网站基础信息!');
  1202. }
  1203. // 0:未构建 1:未应用 2:已应用 status
  1204. if($website_template_info['status'] == 2){
  1205. return Result::error('网站已应用,不可再次保存!');
  1206. }
  1207. if($website_template_info['action_id'] != 2){
  1208. return Result::error('请完成之前的步骤!');
  1209. }
  1210. $template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1211. if(empty($template_info)){
  1212. $template = WebsiteTemplate::insertGetId(['website_id' => $data['website_id'],'template_data' => $data['template_data']]);
  1213. }else{
  1214. $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(['template_data' => $data['template_data']]);
  1215. }
  1216. if(empty($template)){
  1217. return Result::error('保存失败!');
  1218. }else{
  1219. return Result::success($template);
  1220. }
  1221. }
  1222. /**
  1223. * 企业管理
  1224. * @param array $data
  1225. * @return array
  1226. */
  1227. public function getCompanyList(array $data): array
  1228. {
  1229. $where = [];
  1230. $user = User::where('id', $data['user_id'])->first();
  1231. if(empty($user)){
  1232. return Result::error('用户不存在!');
  1233. }
  1234. if($user['type_id']!= 10000){
  1235. $where['user_id'] = $data['user_id'];
  1236. }
  1237. if(isset($data['title']) && $data['title']){
  1238. array_push($where, ['title', 'like', '%'. $data['title']. '%']);
  1239. }
  1240. if(isset($data['website_id']) && $data['website_id']){
  1241. $where['website_id'] = $data['website_id'];
  1242. }
  1243. // 状态:0:未审核 1:已审核 2:已拒绝
  1244. $pageSize = isset($data['pageSize']) ? (int)$data['pageSize'] : 10; // 默认每页 10 条记录
  1245. $page = isset($data['page']) ? (int)$data['page'] : 1; // 默认第 1 页
  1246. if(isset($data['ischeck']) && !empty($data['ischeck'])){
  1247. if($data['ischeck'] == 1){
  1248. $query = Company::whereIn('status', [0,2]);
  1249. }else{
  1250. $query = Company::where('status', 1);
  1251. }
  1252. }
  1253. $result = $query->where($where)->paginate($pageSize, ['*'], 'page', $page);
  1254. if(empty($result)){
  1255. return Result::error("暂无企业", 0);
  1256. }
  1257. return Result::success($result);
  1258. }
  1259. /**
  1260. * 添加企业
  1261. * @param array $data
  1262. * @return array
  1263. */
  1264. public function addCompany(array $data): array
  1265. {
  1266. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  1267. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1268. if ($data['imgurl'] == '') {
  1269. //content中提取图片第一个图,正则提取
  1270. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  1271. preg_match_all($reg, $data['content'], $matches);
  1272. if (isset($matches[1][0])) {
  1273. //截取varchar240
  1274. $data['imgurl'] = substr($matches[1][0], 0, 240);
  1275. }
  1276. }
  1277. if ($data['keyword'] == '') {
  1278. //提取标题+内容中的关键词
  1279. $data['keyword'] = $data['title'];
  1280. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  1281. Jieba::init(); // 初始化 jieba-php
  1282. Finalseg::init();
  1283. $segList = Jieba::cut($data['keyword']);
  1284. $segList1 = array_slice($segList, 0, 8);
  1285. $data['keyword'] = implode(',', $segList1);
  1286. }
  1287. if ($data['introduce'] == '') {
  1288. //提取内容中的描述
  1289. $data['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  1290. }
  1291. $user = User::where('id', $data['user_id'])->first();
  1292. if(empty($user)){
  1293. return Result::error('用户不存在!');
  1294. }
  1295. if($user['type_id']== 10000){
  1296. $data['status'] = 1;
  1297. }
  1298. $result = Company::insertGetId($data);
  1299. if ($result) {
  1300. return Result::success($result);
  1301. } else {
  1302. return Result::error('添加失败');
  1303. }
  1304. }
  1305. /**
  1306. * 更新企业
  1307. * @param array $data
  1308. * @return array
  1309. */
  1310. public function upCompany(array $data): array
  1311. {
  1312. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  1313. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1314. if ($data['imgurl'] == '') {
  1315. //content中提取图片第一个图,正则提取
  1316. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  1317. preg_match_all($reg, $data['content'], $matches);
  1318. if (isset($matches[1][0])) {
  1319. //截取varchar240
  1320. $data['imgurl'] = substr($matches[1][0], 0, 240);
  1321. }
  1322. }
  1323. if ($data['keyword'] == '') {
  1324. //提取标题+内容中的关键词
  1325. $data['keyword'] = $data['title'];
  1326. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  1327. Jieba::init(); // 初始化 jieba-php
  1328. Finalseg::init();
  1329. $segList = Jieba::cut($data['keyword']);
  1330. $segList1 = array_slice($segList, 0, 8);
  1331. $data['keyword'] = implode(',', $segList1);
  1332. }
  1333. if ($data['introduce'] == '') {
  1334. //提取内容中的描述
  1335. $data['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  1336. }
  1337. $user = User::where('id', $data['user_id'])->first();
  1338. if(empty($user)){
  1339. return Result::error('用户不存在!');
  1340. }
  1341. if($user['type_id']== 10000){
  1342. $data['status'] = 1;
  1343. }else{
  1344. $data['status'] = 0;
  1345. }
  1346. $result = Company::where('id', $data['id'])->update($data);
  1347. if ($result) {
  1348. return Result::success($result);
  1349. } else {
  1350. return Result::error('修改失败');
  1351. }
  1352. }
  1353. /**
  1354. * 删除企业
  1355. * @param array $data
  1356. * @return array
  1357. */
  1358. public function delCompany(array $data): array
  1359. {
  1360. $result = Company::where('id', $data['id'])->delete();
  1361. if ($result) {
  1362. return Result::success($result);
  1363. } else {
  1364. return Result::error('删除失败');
  1365. }
  1366. }
  1367. /**
  1368. * 审核企业
  1369. * @param array $data
  1370. * @return array
  1371. */
  1372. public function checkCompany(array $data): array
  1373. {
  1374. $user = User::where('id', $data['user_id'])->first();
  1375. if(empty($user)){
  1376. return Result::error('用户不存在!');
  1377. }
  1378. $company = Company::where('id', $data['id'])->first();
  1379. if(empty($company)){
  1380. return Result::error('企业不存在!');
  1381. }
  1382. // 状态:0:未审核 1:已审核 2:已拒绝
  1383. if($company['status'] == 0 || $company['status'] == 1){
  1384. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  1385. }else{
  1386. $result = Company::where('id', $data['id'])->update(['status' => $data['status'],'reject_reason'=> $data['reject_reason']]);
  1387. }
  1388. if(empty($result)){
  1389. return Result::error('审核失败!');
  1390. }else{
  1391. return Result::success($result);
  1392. }
  1393. }
  1394. /**
  1395. * 获取企业信息
  1396. * @param array $data
  1397. * @return array
  1398. */
  1399. public function getCompanyInfo(array $data): array
  1400. {
  1401. $result = Company::where('id', $data['id'])->first();
  1402. if(empty($result)){
  1403. return Result::error('企业不存在!');
  1404. }else{
  1405. return Result::success($result);
  1406. }
  1407. }
  1408. }