PublicRpcService.php 50 KB

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