NewsService.php 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\WebsiteCategory;
  7. use App\Model\ArticleSurvey;
  8. use App\Model\jobHunting;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\JobPosition;
  16. use App\Model\Notice;
  17. use App\Model\JobNature;
  18. use App\Model\JobEnum;
  19. use App\Model\User;
  20. use App\Model\UserRole;
  21. use App\Model\News;
  22. use App\Model\UserInfo;
  23. use App\Model\WebsiteGroup;;
  24. use Hyperf\DbConnection\Db;
  25. use Hyperf\RpcServer\Annotation\RpcService;
  26. use App\Tools\Result;
  27. use Directory;
  28. use Ramsey\Uuid\Uuid;
  29. use Hyperf\Utils\Random;
  30. use Fukuball\Jieba\Jieba;
  31. use Fukuball\Jieba\Finalseg;
  32. use App\Model\ChatRecords;
  33. use Hyperf\Utils\Collection;
  34. use function Hyperf\Support\retry;
  35. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  36. class NewsService implements NewsServiceInterface
  37. {
  38. /**
  39. * 获取导航池列表
  40. * @param array $data
  41. * @return array
  42. */
  43. public function getCategoryList(array $data): array
  44. {
  45. $page = (int) $data['page'] ?? 1;
  46. $perPage = (int) $data['pageSize'] ?? 10;
  47. $search = $data['name'] ?? '';
  48. // 查找所有匹配的分类
  49. $matchedCategories = $this->findMatchedCategories($search);
  50. // 查找所有匹配分类的父级分类
  51. $allRequiredCategories = $this->findAllParents($matchedCategories);
  52. // 提取一级分类
  53. $topLevelCategories = [];
  54. foreach ($allRequiredCategories as $category) {
  55. if ($category->pid === 0) {
  56. $topLevelCategories[] = $category;
  57. }
  58. }
  59. // 分页处理
  60. $offset = ($page - 1) * $perPage;
  61. $paginatedTopLevelCategories = array_slice($topLevelCategories, $offset, $perPage);
  62. $categoryTree = [];
  63. foreach ($paginatedTopLevelCategories as $category) {
  64. $categoryTree[] = $this->buildCategoryTree($category, $allRequiredCategories);
  65. }
  66. $return = [
  67. 'rows' => $categoryTree,
  68. 'total' => count($topLevelCategories),
  69. ];
  70. return Result::success($return);
  71. }
  72. private function findMatchedCategories($search)
  73. {
  74. if ($search) {
  75. return Category::where('name', 'like', "%{$search}%")
  76. ->orderBy('updated_at', 'desc')
  77. ->get();
  78. }
  79. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  80. ->get();
  81. }
  82. private function findAllParents($categories)
  83. {
  84. $allCategories = [];
  85. foreach ($categories as $category) {
  86. $parentId = $category->pid;
  87. while ($parentId > 0) {
  88. $parent = Category::find($parentId);
  89. if ($parent) {
  90. $allCategories[$parent->id] = $parent;
  91. $parentId = $parent->pid;
  92. } else {
  93. break;
  94. }
  95. }
  96. $allCategories[$category->id] = $category;
  97. }
  98. return array_values($allCategories);
  99. }
  100. private function buildCategoryTree($category, $allRequiredCategories)
  101. {
  102. $categoryData = $category->toArray();
  103. $children = [];
  104. foreach ($allRequiredCategories as $c) {
  105. if ($c->pid === $category->id) {
  106. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  107. }
  108. }
  109. if (!empty($children)) {
  110. $categoryData['children'] = $children;
  111. }
  112. return $categoryData;
  113. }
  114. public function myCategoryList(array $data): array
  115. {
  116. $sszq = $data['sszq'] ?? '';
  117. unset($data['sszq']);
  118. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  119. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  120. $where[] = [
  121. 'pid',
  122. '=',
  123. $data['pid'],
  124. ];
  125. if (isset($data['name'])) {
  126. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  127. }
  128. var_dump($where);
  129. //根据分类id,从category表中取出分类信息
  130. $result = Category::where($where)
  131. ->whereIn('category.id', $catorytids)
  132. ->select('category.*', 'category.id as category_id')->get();
  133. if (empty($result)) {
  134. return Result::error("没有栏目数据");
  135. }
  136. return Result::success($result);
  137. }
  138. /**
  139. * @param array $data
  140. * @return array
  141. */
  142. public function categoryList(array $data): array
  143. {
  144. $where[] = [
  145. 'pid',
  146. '=',
  147. $data['pid'],
  148. ];
  149. if (isset($data['name'])) {
  150. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  151. }
  152. var_dump($where);
  153. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  154. if (empty($result)) {
  155. return Result::error("没有栏目数据");
  156. }
  157. return Result::success($result);
  158. }
  159. /**
  160. * @param array $data
  161. * @return array
  162. */
  163. public function addCategory(array $data): array
  164. {
  165. if (isset($data['id'])) {
  166. unset($data['id']);
  167. }
  168. $id = Category::insertGetId($data);
  169. if (empty($id)) {
  170. return Result::error("添加失败");
  171. }
  172. return Result::success(['id' => $id]);
  173. }
  174. /**
  175. * @param array $data
  176. * @return array
  177. */
  178. public function delCategory(array $data): array
  179. {
  180. Db::beginTransaction();
  181. try {
  182. $categoryList = Category::where(['pid' => $data['id']])->get();
  183. if ($categoryList->toArray()) {
  184. Db::rollBack();
  185. return Result::error("分类下面有子分类不能删除");
  186. }
  187. $articleList = Article::where(['catid' => $data['id']])->get();
  188. if ($articleList->toArray()) {
  189. Db::rollBack();
  190. return Result::error("分类下面有资讯不能删除");
  191. }
  192. $result = Category::where($data)->delete();
  193. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  194. if (!$result) {
  195. return Result::error("删除失败");
  196. }
  197. return Result::success($result);
  198. Db::commit();
  199. } catch (\Exception $e) {
  200. Db::rollBack();
  201. return Result::error("删除失败");
  202. }
  203. }
  204. /**
  205. * @param array $data
  206. * @return array
  207. */
  208. public function updateCategory(array $data): array
  209. {
  210. $where = [
  211. 'id' => $data['id'],
  212. ];
  213. $result = Category::where($where)->update($data);
  214. if ($result) {
  215. return Result::success($result);
  216. } else {
  217. return Result::error("更新失败");
  218. }
  219. }
  220. /**
  221. * 获取导航池信息
  222. * @param array $data
  223. * @return array
  224. */
  225. public function getCategoryInfo(array $data): array
  226. {
  227. $where = [
  228. 'id' => $data['id'],
  229. ];
  230. $result = Category::where($where)->first();
  231. if ($result) {
  232. return Result::success($result);
  233. } else {
  234. return Result::error("更新失败");
  235. }
  236. }
  237. /**
  238. * @param array $data
  239. * @return array
  240. */
  241. public function getArticleList(array $data): array
  242. {
  243. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  244. $type_id = $data['type_id'];
  245. unset($data['type_id']);
  246. $user_id = $data['user_id'];
  247. unset($data['user_id']);
  248. $where = [];
  249. $status1 = [];
  250. if (isset($data['id']) && $data['id']) {
  251. array_push($where, ['article.id', '=', $data['id']]);
  252. }
  253. if (isset($data['title']) && $data['title']) {
  254. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  255. }
  256. if (isset($data['category_name']) && $data['category_name']) {
  257. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  258. }
  259. if (isset($data['author']) && $data['author']) {
  260. array_push($where, ['article.author', '=', $data['author']]);
  261. }
  262. if (isset($data['islink']) && $data['islink'] !== "") {
  263. array_push($where, ['article.islink', '=', $data['islink']]);
  264. }
  265. if (isset($data['status']) && $data['status'] !== "") {
  266. array_push($where, ['article.status', '=', $data['status']]);
  267. }
  268. if (isset($data['status1'])) {
  269. $status1 = json_decode(($data['status1']));
  270. }
  271. //不是管理员展示个人数据;
  272. if ($type_id != 10000) {
  273. $where[] = ['article.admin_user_id', '=', $user_id];
  274. }
  275. $rep = Article::where($where)
  276. ->whereNotIn('article.status', [404])
  277. ->when($status1, function ($query) use ($status1) {
  278. if (isset($status1) && $status1) {
  279. $query->whereIn('article.status', $status1);
  280. }
  281. })
  282. ->leftJoin('category', 'article.catid', 'category.id')
  283. ->select("article.*", "category.name as category_name")
  284. ->orderBy("article.updated_at", "desc")
  285. ->limit($data['pageSize'])
  286. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  287. $count = Article::where($where)->whereNotIn('article.status', [404])
  288. ->when($status1, function ($query) use ($status1) {
  289. if (isset($status1) && $status1) {
  290. $query->whereIn('article.status', $status1);
  291. }
  292. })
  293. ->leftJoin('category', 'article.catid', 'category.id')->count();
  294. $data = [
  295. 'rows' => $rep->toArray(),
  296. 'count' => $count,
  297. ];
  298. if (empty($rep)) {
  299. return Result::error("没有信息数据");
  300. }
  301. return Result::success($data);
  302. }
  303. /**
  304. * @param array $data
  305. * @return array
  306. */
  307. public function addArticle(array $data): array
  308. {
  309. var_dump($data, '----------12-----------1');
  310. unset($data['user_type']);
  311. unset($data['nav_add_pool_id']);
  312. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  313. Db::beginTransaction();
  314. try {
  315. //处理投票
  316. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  317. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  318. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  319. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  320. unset($data['is_survey']);
  321. unset($data['survey_name']);
  322. unset($data['suvey_array']);
  323. // unset($data['website_id']);
  324. // unset($data['web_site_id']);
  325. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  326. if ($data['hits'] == '') {
  327. $data['hits'] = 0;
  328. }
  329. if ($data['is_original'] == '') {
  330. $data['is_original'] = 0;
  331. }
  332. if ($data['status'] == '') {
  333. $data['status'] = 0;
  334. }
  335. $articleData = $data;
  336. unset($articleData['content']);
  337. //自动处理缩略图、关键字、描述
  338. if ($articleData['imgurl'] == '') {
  339. //如果没有图,设置level=0
  340. $levelArr = json_decode($articleData['level'], true);
  341. var_dump($levelArr, '----------levelArr-----------1');
  342. //content中提取图片第一个图,正则提取
  343. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  344. preg_match_all($reg, $data['content'], $matches);
  345. if (isset($matches[1][0])) {
  346. //截取varchar240
  347. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  348. //如果有图,设置level=3
  349. if (!in_array(3, $levelArr)) {
  350. $levelArr[] = 3;
  351. }
  352. $articleData['level'] = json_encode($levelArr);
  353. } else {
  354. if (!in_array(0, $levelArr)) {
  355. $levelArr[] = 0;
  356. }
  357. $articleData['level'] = json_encode($levelArr);
  358. }
  359. }
  360. var_dump($articleData['level'], '----------$articleData[level]----------1');
  361. if ($articleData['keyword'] == '') {
  362. //提取标题+内容中的关键词
  363. $articleData['keyword'] = $data['title'];
  364. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  365. Jieba::init(); // 初始化 jieba-php
  366. Finalseg::init();
  367. $segList = Jieba::cut($articleData['keyword']);
  368. $segList1 = array_slice($segList, 0, 8);
  369. $articleData['keyword'] = implode(',', $segList1);
  370. }
  371. if ($articleData['introduce'] == '') {
  372. //提取内容中的描述
  373. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  374. }
  375. $id = Article::insertGetId($articleData);
  376. $articleDataContent = [
  377. 'article_id' => $id,
  378. 'content' => $data['content'],
  379. ];
  380. ArticleData::insertGetId($articleDataContent);
  381. //处理投票
  382. if ($is_survey == 1) {
  383. //生成年月日时分秒+8位随机数
  384. $uuid = date('YmdHis') . rand(10000000, 99999999);
  385. var_dump($suvey_array, 'suvey_array________');
  386. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  387. var_dump($suveys_array, '---------------------1');
  388. var_dump($suvey_array, '---------------------2');
  389. $suvey_data = [];
  390. foreach ($suveys_array as $key => $value) {
  391. if ($value == '') {
  392. continue;
  393. }
  394. if (is_array($value)) {
  395. $suvey_data[] = [
  396. 'sur_id' => $uuid,
  397. 'art_id' => $id,
  398. 'website_id' => $website_id ?? 2,
  399. 'survey_name' => $survey_name,
  400. 'choice_name' => $value[1],
  401. 'is_other' => 1,
  402. 'other_id' => 0,
  403. 'results' => 0,
  404. ];
  405. } else {
  406. $suvey_data[] = [
  407. 'sur_id' => $uuid,
  408. 'art_id' => $id,
  409. 'website_id' => $website_id ?? 2,
  410. 'survey_name' => $survey_name,
  411. 'choice_name' => $value,
  412. 'is_other' => 0,
  413. 'other_id' => 0,
  414. 'results' => 0,
  415. ];
  416. }
  417. if (empty($suvey_data)) {
  418. throw new \Exception("投票数据为空");
  419. }
  420. }
  421. $result = ArticleSurvey::insert($suvey_data);
  422. if (!$result) {
  423. throw new \Exception("投票失败,ArticleSurvey插入失败");
  424. }
  425. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  426. if (!$result) {
  427. throw new \Exception("投票失败,更新主表失败");
  428. }
  429. }
  430. Db::commit();
  431. return Result::success(['id' => $id]);
  432. } catch (\Throwable $ex) {
  433. Db::rollBack();
  434. var_dump($ex->getMessage());
  435. return Result::error("创建失败", 0);
  436. }
  437. }
  438. /**
  439. * @param array $data
  440. * @return array
  441. */
  442. public function delArticle(array $data): array
  443. {
  444. $result = Article::where($data)->delete();
  445. //survey投票删除
  446. articleSurvey::where(['art_id' => $data['id']])->delete();
  447. if (!$result) {
  448. return Result::error("删除失败");
  449. }
  450. return Result::success($result);
  451. }
  452. /**
  453. * @param array $data
  454. * @return array
  455. */
  456. public function updateArticle(array $data): array
  457. {
  458. var_dump($data, '----------12-----------1');
  459. Db::beginTransaction();
  460. unset($data['user_type']);
  461. // unset($data['web_site_id']);
  462. unset($data['nav_add_pool_id']);
  463. try {
  464. //处理投票
  465. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  466. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  467. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  468. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  469. unset($data['is_survey']);
  470. unset($data['survey_name']);
  471. unset($data['suvey_array']);
  472. unset($data['website_id']);
  473. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  474. if ($data['hits'] == '') {
  475. $data['hits'] = 0;
  476. }
  477. if ($data['is_original'] == '') {
  478. $data['is_original'] = 0;
  479. }
  480. if ($data['status'] == '') {
  481. $data['status'] = 0;
  482. }
  483. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  484. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  485. $articleData = $data;
  486. unset($articleData['content']);
  487. unset($articleData['status_name']);
  488. unset($articleData['name']);
  489. unset($articleData['content']);
  490. unset($articleData['pid_arr']);
  491. unset($articleData['pid']);
  492. //自动处理缩略图、关键字、描述
  493. if ($articleData['imgurl'] == '') {
  494. //如果没有图,设置level=0
  495. $levelArr = json_decode($articleData['level'], true);
  496. var_dump($levelArr, '----------levelArr-----------1');
  497. //content中提取图片第一个图,正则提取
  498. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  499. preg_match_all($reg, $data['content'], $matches);
  500. if (isset($matches[1][0])) {
  501. //截取varchar240
  502. // 截取到第一个<
  503. $articleData['imgurl'] = $matches[1][0];
  504. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  505. $pos = strpos($articleData['imgurl'], '"');
  506. if ($pos !== false) {
  507. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  508. }
  509. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  510. //如果有图,设置level=3
  511. if (!in_array(3, $levelArr)) {
  512. $levelArr[] = 3;
  513. }
  514. $articleData['level'] = json_encode($levelArr);
  515. } else {
  516. if (!in_array(0, $levelArr)) {
  517. $levelArr[] = 0;
  518. }
  519. $articleData['level'] = json_encode($levelArr);
  520. }
  521. }
  522. var_dump($articleData['level'], '----------$articleData[level]----------1');
  523. if ($articleData['keyword'] == '') {
  524. //提取标题+内容中的关键词
  525. $articleData['keyword'] = $data['title'];
  526. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  527. Jieba::init(); // 初始化 jieba-php
  528. Finalseg::init();
  529. $segList = Jieba::cut($articleData['keyword']);
  530. $segList1 = array_slice($segList, 0, 8);
  531. $articleData['keyword'] = implode(',', $segList1);
  532. }
  533. if ($articleData['introduce'] == '') {
  534. //提取内容中的描述
  535. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  536. }
  537. $id = Article::where(['id' => $data['id']])->update($articleData);
  538. $articleDataContent = [
  539. 'content' => $data['content'],
  540. ];
  541. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  542. //处理投票
  543. $id = $data['id'];
  544. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  545. var_dump($suvey_array, 'suvey_array________delete');
  546. //处理投票
  547. if ($is_survey == 1) {
  548. //生成年月日时分秒+8位随机数
  549. $uuid = date('YmdHis') . rand(10000000, 99999999);
  550. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  551. var_dump($suveys_array, '---------------------1');
  552. $suvey_data = [];
  553. if (is_array($suveys_array)) {
  554. foreach ($suveys_array as $key => $value) {
  555. if ($value == '') {
  556. continue;
  557. }
  558. if (is_array($value)) {
  559. $suvey_data[] = [
  560. 'sur_id' => $uuid,
  561. 'art_id' => $id,
  562. 'website_id' => $website_id ?? 2,
  563. 'survey_name' => $survey_name,
  564. 'choice_name' => $value[1],
  565. 'is_other' => 1,
  566. 'other_id' => 0,
  567. 'results' => 0,
  568. ];
  569. } else {
  570. $suvey_data[] = [
  571. 'sur_id' => $uuid,
  572. 'art_id' => $id,
  573. 'website_id' => $website_id ?? 2,
  574. 'survey_name' => $survey_name,
  575. 'choice_name' => $value,
  576. 'is_other' => 0,
  577. 'other_id' => 0,
  578. 'results' => 0,
  579. ];
  580. }
  581. if (empty($suvey_data)) {
  582. throw new \Exception("投票数据为空");
  583. }
  584. }
  585. }
  586. $result = ArticleSurvey::insert($suvey_data);
  587. if (!$result) {
  588. throw new \Exception("投票失败");
  589. }
  590. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  591. if (!$result) {
  592. throw new \Exception("投票失败");
  593. }
  594. } else {
  595. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  596. }
  597. Db::commit();
  598. return Result::success([]);
  599. } catch (\Throwable $ex) {
  600. Db::rollBack();
  601. var_dump($ex->getMessage());
  602. return Result::error("更新失败" . $ex->getMessage(), 0);
  603. }
  604. }
  605. /**
  606. * 更新资讯状态
  607. * @param array $data
  608. * @return array
  609. */
  610. public function upArticleStatus(array $data): array
  611. {
  612. $result = Article::where(['id' => $data['id']])->update($data);
  613. if ($result) {
  614. return Result::success();
  615. } else {
  616. return Result::error("更新状态失败", 0);
  617. }
  618. }
  619. /**
  620. * @param array $data
  621. * @return array
  622. */
  623. public function getArticleInfo(array $data): array
  624. {
  625. $where = [
  626. 'article.id' => $data['id'],
  627. // 'article.status' => 1,
  628. ];
  629. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  630. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  631. $info = $result;
  632. // var_dump($info, 'info');
  633. $info['survey_array'] = $articleSurvey;
  634. if ($result) {
  635. return Result::success($info);
  636. } else {
  637. return Result::error("查询失败", 0);
  638. }
  639. }
  640. /**
  641. * 获取新闻
  642. * @param array $data
  643. * @return array
  644. */
  645. public function getWebsiteArticlett(array $data): array
  646. {
  647. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  648. $category = array_values(array_unique($category->toArray()));
  649. $result = [];
  650. if ($category) {
  651. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  652. $where = [
  653. 'status' => 1,
  654. ];
  655. var_dump($data, 'data-----------------');
  656. // level=7 根据文章key来匹配文章
  657. if (isset($data['level']) && $data['level'] == 7) {
  658. // 根据文章id获取key
  659. // $data['id'] = 50142;
  660. if (isset($data['id']) && !empty($data['id'])) {
  661. $keyword = Article::where('id', $data['id'])->value('keyword');
  662. $keywordArray = explode(',', $keyword);
  663. $whereL7 = [];
  664. foreach ($keywordArray as $k => $v) {
  665. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  666. }
  667. // 原始查询
  668. $result = Article::where($whereL7)
  669. ->offset($placeid)
  670. ->limit($data['pageSize'])
  671. ->orderBy('updated_at', 'desc')
  672. ->get()
  673. ->map(function ($article) use ($data) {
  674. $catid = $article->catid;
  675. $pinyin = '';
  676. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  677. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  678. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  679. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  680. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  681. }
  682. $article->pinyin = $pinyin;
  683. return $article;
  684. });
  685. if (empty($result)) {
  686. return Result::success([]);
  687. }
  688. return Result::success($result);
  689. } else {
  690. return Result::error("参数错误level=7,id不能为空", 0);
  691. }
  692. }
  693. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  694. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  695. var_dump($where, 'where-----------------');
  696. $result = Article::where($where)
  697. ->whereIn("catid", $category)
  698. // ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  699. // ->where('website_category.website_id', $data['website_id'])
  700. ->where(function ($query) use ($data) {
  701. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  702. ->orWhereNull("ignore_ids");
  703. })
  704. //$data['level'] == 4 || $data['level'] == 5 查询随机
  705. ->when($data['level'] == 5, function ($query) {
  706. $query->inRandomOrder()
  707. //updated_at最近三十天;
  708. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  709. })
  710. ->when($data['level'] == 4, function ($query) {
  711. $query->orderBy("article.updated_at", "desc");
  712. })
  713. ->when(!empty($data['level']), function ($query) use ($data) {
  714. if ($data['level'] != 4 && $data['level'] != 5) {
  715. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  716. ->orderBy("article.updated_at", "desc");
  717. }
  718. })
  719. ->select('article.*')
  720. ->offset($placeid)
  721. ->limit($data['pageSize'])
  722. ->get()
  723. ->map(function ($article) use ($data) {
  724. $catid = $article->catid;
  725. $pinyin = '';
  726. // $category = WebsiteCategory::whereIn('category_id', $catArrId)->where('website_category.website_id', $data['website_id'])->get()->all();
  727. // if ($catArrId) {
  728. // foreach ($catArrId as $categoryId) {
  729. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  730. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  731. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  732. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  733. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  734. }
  735. // }
  736. // }
  737. $article->pinyin = $pinyin;
  738. return $article;
  739. });
  740. if (empty($result)) {
  741. return Result::error("暂无头条新闻", 0);
  742. }
  743. return Result::success($result);
  744. } else {
  745. return Result::error("本网站下暂无相关栏目", 0);
  746. }
  747. }
  748. /**
  749. * 获取模块新闻
  750. * @param array $data
  751. * @return array
  752. */
  753. public function getWebsiteModelArticles(array $data): array
  754. {
  755. $catid = $data['catid'];
  756. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  757. $category = $category->toArray();
  758. if (!empty($category)) {
  759. $where = [
  760. 'status' => 1,
  761. 'catid' => $catid,
  762. ];
  763. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  764. // 1:文字新闻;2:轮播图;3:图文;
  765. // 级别:0:未分类
  766. // 3:推荐图片
  767. if ($data['level'] == 1) {
  768. $data['level'] = 0;
  769. }
  770. $result = Article::where($where)
  771. ->where(function ($query) use ($data) {
  772. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  773. ->orWhereNull("level")
  774. ->orWhereRaw("level = '[]'");
  775. })
  776. ->where(function ($query) use ($data) {
  777. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  778. ->orWhereNull("ignore_ids");
  779. })
  780. ->orderBy("updated_at", "desc")
  781. ->offset($placeid)
  782. ->limit($data['pagesize'])
  783. ->get();
  784. if (empty($result)) {
  785. return Result::error("此栏目暂无相关新闻", 0);
  786. }
  787. } else {
  788. return Result::error("此网站暂无此栏目", 0);
  789. }
  790. return Result::success($result);
  791. }
  792. /**
  793. *获取新闻列表
  794. * @param array $data
  795. * @return array
  796. */
  797. public function getWebsiteArticleList(array $data): array
  798. {
  799. // return Result::success($data);
  800. $where[] = ['status', '=', 1];
  801. if (isset($data['catid']) && !empty($data['catid'])) {
  802. if (is_array($data['catid'])) {
  803. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  804. array_push($where, ['catid', 'in', $data['catid']]);
  805. } else {
  806. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  807. array_push($where, ['catid', '=', $data['catid']]);
  808. }
  809. if (empty($category)) {
  810. return Result::error("此网站暂无此栏目", 0);
  811. }
  812. }
  813. // return Result::success($where);
  814. $rep = Article::where(function ($query) use ($where) {
  815. foreach ($where as $condition) {
  816. if ($condition[1] === 'in') {
  817. $query->whereIn($condition[0], $condition[2]);
  818. } else {
  819. $query->where($condition[0], $condition[1], $condition[2]);
  820. }
  821. }
  822. })
  823. ->where(function ($query) use ($data) {
  824. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  825. ->orWhereNull("ignore_ids");
  826. })
  827. ->select(
  828. 'article.id',
  829. 'article.title',
  830. 'article.imgurl',
  831. 'article.author',
  832. 'article.updated_at',
  833. 'article.introduce',
  834. 'article.islink',
  835. 'article.linkurl',
  836. 'article.copyfrom',
  837. 'article.catid'
  838. )
  839. ->orderBy("updated_at", "desc")
  840. ->limit($data['pageSize'])
  841. ->offset(($data['page'] - 1) * $data['pageSize'])
  842. ->get()
  843. ->map(function ($article) use ($data) {
  844. $catid = $article->catid ?? 0;
  845. $pinyin = '';
  846. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  847. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  848. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  849. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  850. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  851. }
  852. $article->pinyin = $pinyin;
  853. return $article;
  854. });
  855. $count = Article::where(function ($query) use ($where) {
  856. foreach ($where as $condition) {
  857. if ($condition[1] === 'in') {
  858. $query->whereIn($condition[0], $condition[2]);
  859. } else {
  860. $query->where($condition[0], $condition[1], $condition[2]);
  861. }
  862. }
  863. })->count();
  864. $data = [
  865. 'rows' => $rep->toArray(),
  866. 'count' => $count,
  867. ];
  868. if (empty($rep)) {
  869. return Result::error("没有信息数据");
  870. }
  871. return Result::success($data);
  872. }
  873. /**
  874. * 前端-获取新闻详情
  875. * @param array $data
  876. * @return array
  877. */
  878. public function selectWebsiteArticleInfo(array $data): array
  879. {
  880. $where = [
  881. 'article.id' => $data['id'],
  882. 'article.status' => 1,
  883. ];
  884. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
  885. ->where(function ($query) use ($data) {
  886. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  887. ->orWhereNull("ignore_ids");
  888. })
  889. ->first();
  890. if (empty($result)) {
  891. return Result::error("暂无此新闻!", 0);
  892. }
  893. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  894. ->select('website_category.*', 'website.website_name', 'website.suffix')
  895. ->where('website_category.website_id', $data['website_id'])
  896. ->where(['website_category.category_id' => $result['catid']])
  897. ->first();
  898. if (empty($category)) {
  899. return Result::error("查询失败", 0);
  900. }
  901. //手动推荐文章
  902. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  903. $commendArticle = Article::whereIn('id', $commend_ids)
  904. ->where('status', 1)
  905. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  906. ->orderBy('updated_at', 'desc')
  907. ->limit(5)
  908. ->get();
  909. $result['category_id'] = $category['category_id'];
  910. $result['cat_name'] = $category['alias'];
  911. $result['website_name'] = $category['website_name'] ?? "";
  912. $result['suffix'] = $category['suffix'] ?? "";
  913. $result['commendArticle'] = $commendArticle;
  914. return Result::success($result);
  915. }
  916. /**
  917. * 前端-获取网站调查问卷
  918. * @param array $data
  919. * @return array
  920. */
  921. public function getWebsiteSurvey(array $data): array
  922. {
  923. if (isset($data['website_id']) && !empty($data['website_id'])) {
  924. $website = Website::where('id', $data['website_id'])->first();
  925. if (empty($website)) {
  926. return Result::error("暂无此网站", 0);
  927. }
  928. }
  929. if (isset($data['art_id']) && !empty($data['art_id'])) {
  930. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  931. if (empty($article)) {
  932. return Result::error("暂无此文章", 0);
  933. }
  934. // return Result::error($data,0);
  935. $where['art_id'] = $data['art_id'];
  936. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  937. } else {
  938. $survey = Article::where(function ($query) {
  939. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  940. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  941. })
  942. ->where('status', 1)
  943. ->where('is_survey', 1)
  944. ->select('survey_id')
  945. ->orderBy('updated_at', 'desc')
  946. ->first();
  947. if (empty($survey)) {
  948. return Result::error("暂无调查问卷", 0);
  949. }
  950. $where['sur_id'] = $survey['survey_id'];
  951. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  952. }
  953. // return Result::success($where);
  954. $result = ArticleSurvey::where($where)
  955. ->where(function ($query) {
  956. $query->where('is_other', 0)
  957. ->orWhere(function ($subQuery) {
  958. $subQuery->where('is_other', 1)
  959. ->where('other_id', 0);
  960. });
  961. })
  962. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  963. ->select('article_survey.*', 'article.survey_type')
  964. ->get()->all();
  965. if (empty($result)) {
  966. return Result::error("此文章暂无调查问卷", 0);
  967. }
  968. return Result::success($result);
  969. }
  970. /**
  971. * 前端-添加网站调查问卷选项
  972. * @param array $data
  973. * @return array
  974. */
  975. public function addWebsiteSurveyOption(array $data): array
  976. {
  977. if (isset($data['website_id']) && !empty($data['website_id'])) {
  978. $website = Website::where('id', $data['website_id'])->first();
  979. if (empty($website)) {
  980. return Result::error("暂无此网站", 0);
  981. }
  982. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  983. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  984. if (empty($survey)) {
  985. return Result::error("此调查问卷不可添加选项", 0);
  986. }
  987. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  988. $choice = [
  989. 'art_id' => $survey['art_id'],
  990. 'website_id' => $data['website_id'],
  991. 'survey_name' => $survey['survey_name'],
  992. 'choice_name' => $data['choice_name'],
  993. 'sur_id' => $survey['sur_id'],
  994. 'is_other' => 1,
  995. 'other_id' => $survey['id'],
  996. ];
  997. $result = ArticleSurvey::insertGetId($choice);
  998. if (empty($result)) {
  999. return Result::error("添加失败", 0);
  1000. }
  1001. return Result::success($result);
  1002. }
  1003. }
  1004. return Result::error("添加失败", 0);
  1005. }
  1006. return Result::error("添加失败", 0);
  1007. }
  1008. /**
  1009. * 前端-调查问卷投票
  1010. * @param array $data
  1011. * @return array
  1012. */
  1013. public function addWebsiteSurveyVote(array $data): array
  1014. {
  1015. // return Result::success($data);
  1016. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1017. $website = Website::where('id', $data['website_id'])->first();
  1018. if (empty($website)) {
  1019. return Result::error("暂无此网站", 0);
  1020. }
  1021. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1022. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1023. // return Result::success($survey);
  1024. if (empty($is_survey)) {
  1025. return Result::error("此调查问卷不存在", 0);
  1026. }
  1027. // return Result::success($survey);
  1028. // 调查问卷类型
  1029. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1030. //多选 若是json型则转化成数组类型
  1031. if (strpos($data['choice_id'], '[') === 0) {
  1032. $data['choice_id'] = json_decode($data['choice_id'], true);
  1033. } else {
  1034. // 单选 也转换成数组
  1035. $data['choice_id'] = [$data['choice_id']];
  1036. }
  1037. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1038. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1039. ->where('website_id', $data['website_id'])
  1040. ->where('is_other', 1)
  1041. ->where('other_id', 0)
  1042. ->first();
  1043. if (!empty($other)) {
  1044. return Result::error("请选择已有的选项!", 0);
  1045. }
  1046. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1047. ->where('website_id', $data['website_id'])
  1048. ->where('is_other', 1)
  1049. ->where('other_id', '!=', 0)
  1050. ->first();
  1051. // return Result::success($choice['other']);
  1052. $choice_id = $data['choice_id'];
  1053. if (!empty($choice['other'])) {
  1054. // array_push($data['choice_id'],$choice['other']['other_id']);
  1055. if (!empty($choice_id)) {
  1056. $key = array_search($choice['other']['id'], $choice_id);
  1057. if ($key !== false) {
  1058. unset($choice_id[$key]);
  1059. $choice_id = array_values($choice_id);
  1060. }
  1061. array_push($choice_id, $choice['other']['other_id']);
  1062. } else {
  1063. $choice_id[0] = $choice['other']['other_id'];
  1064. }
  1065. array_push($data['choice_id'], $choice['other']['other_id']);
  1066. }
  1067. // return Result::success($data);
  1068. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1069. ->where('website_id', $data['website_id'])
  1070. ->increment('results', 1);
  1071. if (empty($choice)) {
  1072. return Result::error("请选择已有的选项!", 0);
  1073. }
  1074. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1075. ->where('website_id', $data['website_id'])
  1076. ->where('other_id', 0)
  1077. ->get();
  1078. $survey['choice'] = $choice_id;
  1079. return Result::success($survey);
  1080. }
  1081. return Result::error("参数必填!");
  1082. }
  1083. return Result::error("此调查问卷不存在", 0);
  1084. }
  1085. return Result::error("参数必填!");
  1086. }
  1087. /**
  1088. * 后端-获取网站调查问卷列表
  1089. * @param array $data
  1090. * @return array
  1091. */
  1092. public function getSurveyList(array $data): array
  1093. {
  1094. $where = [];
  1095. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1096. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1097. }
  1098. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1099. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1100. }
  1101. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1102. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1103. }
  1104. // return Result::success($where);
  1105. if (!empty($where)) {
  1106. $query = Article::where($where)->where(function ($q) {
  1107. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1108. });
  1109. } else {
  1110. $query = Article::where(function ($q) {
  1111. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1112. });
  1113. }
  1114. $count = $query->count();
  1115. $survey = $query->orderByDesc('id')
  1116. ->limit($data['pageSize'])
  1117. ->offset(($data['page'] - 1) * $data['pageSize'])
  1118. ->get();
  1119. if (empty($survey->toArray())) {
  1120. return Result::error("暂无调查问卷!", 0);
  1121. }
  1122. $result = [
  1123. 'rows' => $survey,
  1124. 'count' => $count,
  1125. ];
  1126. return Result::success($result);
  1127. }
  1128. /**
  1129. * 后端-获取网站调查问卷详情
  1130. * @param array $data
  1131. * @return array
  1132. */
  1133. public function getSurveyInfo(array $data): array
  1134. {
  1135. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1136. $where = ['sur_id' => $data['sur_id']];
  1137. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1138. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1139. ->select('article_survey.*', 'article.survey_type')
  1140. ->get()->all();
  1141. if (empty($choose)) {
  1142. return Result::error("此调查问卷不存在", 0);
  1143. }
  1144. $resultsArray = array_column($choose, 'results');
  1145. $total = array_sum($resultsArray);
  1146. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1147. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1148. // $total = 0;
  1149. if (!empty($other)) {
  1150. $total = $total + $other['results'];
  1151. $other['choice_name'] = '(其他)';
  1152. if (!empty($others)) {
  1153. $other['hasChildren'] = true;
  1154. // array_push($other,['hasChildren','=',true]);
  1155. $other['children'] = $others;
  1156. $other_choices = [$other->toArray()];
  1157. $mer_choice = array_merge($choose, $other_choices);
  1158. $value_choice = array_values($mer_choice);
  1159. } else {
  1160. // return Result::error('1111');
  1161. $other_choices = [$other->toArray()];
  1162. $other_choices = array_merge($choose, $other_choices);
  1163. $value_choice = array_values($other_choices);
  1164. // return Result::success($result);
  1165. }
  1166. } else {
  1167. $value_choice = $choose;
  1168. }
  1169. $result = [
  1170. 'choose' => $value_choice,
  1171. 'total' => $total,
  1172. ];
  1173. }
  1174. return Result::success($result);
  1175. }
  1176. /**
  1177. * 前端-搜索新闻列表
  1178. * @param array $data
  1179. * @return array
  1180. */
  1181. public function selectWebsiteArticle(array $data): array
  1182. {
  1183. $where = [];
  1184. // 初始化查询构造器
  1185. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1186. $query = Article::where('status', 1)
  1187. ->whereIn('catid', $category)
  1188. ->where(function ($query) use ($data) {
  1189. $query->where(function ($subQuery) use ($data) {
  1190. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1191. })->orWhereNull("ignore_ids");
  1192. });
  1193. // return Result::success($all_articles);
  1194. // 检查是否存在 cityid 参数
  1195. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1196. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1197. }
  1198. // 检查是否存在 department_id 参数
  1199. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1200. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1201. }
  1202. // 检查是否存在 keyword 参数
  1203. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1204. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1205. }
  1206. // 计算总数
  1207. $count = $query->count();
  1208. // 分页查询
  1209. $articles = $query
  1210. ->select(
  1211. 'article.id',
  1212. 'article.title',
  1213. 'article.imgurl',
  1214. 'article.author',
  1215. 'article.updated_at',
  1216. 'article.introduce',
  1217. 'article.islink',
  1218. 'article.linkurl',
  1219. 'article.copyfrom',
  1220. 'article.catid',
  1221. 'article.department_arr_id',
  1222. 'article.city_arr_id',
  1223. )
  1224. ->orderBy("updated_at", "desc")
  1225. ->offset(($data['page'] - 1) * $data['pageSize'])
  1226. ->limit($data['pageSize'])
  1227. ->get()
  1228. ->map(function ($article) use ($data) {
  1229. $catid = $article->catid ?? 0;
  1230. $pinyin = '';
  1231. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  1232. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1233. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  1234. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  1235. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  1236. }
  1237. $article->pinyin = $pinyin;
  1238. return $article;
  1239. });
  1240. if (empty($articles)) {
  1241. return Result::error("没有符合条件的资讯数据");
  1242. }
  1243. $data = [
  1244. 'rows' => $articles,
  1245. 'count' => $count,
  1246. ];
  1247. return Result::success($data);
  1248. }
  1249. /**
  1250. * 模块新闻加强版
  1251. * @param array $data
  1252. * @return array
  1253. */
  1254. public function getWebsiteCatidArticle(array $data): array
  1255. {
  1256. // return Result::success($data);
  1257. $where = [
  1258. // 'category.status' => 1,
  1259. 'website_category.category_id' => $data['catid'],
  1260. 'website_category.website_id' => $data['website_id'],
  1261. // 'article.status' => 1,
  1262. ];
  1263. // $category = WebsiteCategory::where($where);
  1264. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1265. $child_catnum = $data['child_catnum'] ?? 1;
  1266. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1267. $childCategoryIds = array_column($category['child'], 'category_id');
  1268. if (empty($childCategoryIds)) {
  1269. return Result::error("暂无子栏目", 0);
  1270. }
  1271. $imgArticles = [];
  1272. $textArticles = [];
  1273. // return Result::success($childCategoryIds);
  1274. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1275. // 初始化子分类图片新闻和文字新闻数组
  1276. // 查询所有子级栏目的图文新闻
  1277. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1278. ->where(function ($query) use ($data) {
  1279. $query->where(function ($subQuery) use ($data) {
  1280. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1281. })->orWhereNull("ignore_ids");
  1282. })
  1283. ->where('status', 1)
  1284. ->where('imgurl', '!=', '')
  1285. ->select('*')
  1286. ->orderBy('updated_at', 'desc')
  1287. ->limit($data['child_imgnum'])
  1288. ->get();
  1289. }
  1290. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1291. // 查询所有子级栏目的文字新闻
  1292. $textArticles = Article::where('catid', $childCategoryIds[0])
  1293. ->where('status', 1)
  1294. ->where(function ($query) use ($data) {
  1295. $query->where(function ($subQuery) use ($data) {
  1296. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1297. })->orWhereNull("ignore_ids");
  1298. })
  1299. // ->where(function ($query) {
  1300. // $query->whereNull('imgurl')
  1301. // ->orWhere('imgurl', '');
  1302. // })
  1303. ->select('*')
  1304. ->orderBy('updated_at', 'desc')
  1305. ->limit($data['child_textnum'])
  1306. ->get();
  1307. }
  1308. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1309. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1310. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1311. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1312. return $child;
  1313. }, $category['child']);
  1314. }
  1315. // }
  1316. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1317. $category['img'] = WebsiteCategory::where($where)
  1318. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1319. ->where('article.status', 1)
  1320. ->where('article.imgurl', '!=', '')
  1321. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1322. ->orderBy('article.updated_at', 'desc')
  1323. ->limit($data['img_num'])
  1324. ->get();
  1325. }
  1326. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1327. $category['text'] = WebsiteCategory::where($where)
  1328. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1329. ->where('article.status', 1)
  1330. // ->where(function ($query) {
  1331. // $query->whereNull('article.imgurl')
  1332. // ->orWhere('article.imgurl', '');
  1333. // })
  1334. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1335. ->orderBy('article.updated_at', 'desc')
  1336. ->limit($data['text_num'])
  1337. ->get();
  1338. }
  1339. // $category = $category->get();
  1340. if (empty($category)) {
  1341. return Result::error("查询失败", 0);
  1342. }
  1343. return Result::success($category);
  1344. }
  1345. /**
  1346. * 模块新闻加强plus版
  1347. * @param array $data
  1348. * @return array
  1349. */
  1350. public function getWebsiteAllArticle(array $data): array
  1351. {
  1352. // 修正传入的字符串,将单引号替换为双引号
  1353. $input['id'] = $data['id'];
  1354. $input['website_id'] = $data['website_id'];
  1355. // 将 JSON 字符串转换为 PHP 数组
  1356. $data = json_decode($input['id'], true);
  1357. // 使用 array_map 处理每个元素
  1358. $result = array_map(function ($item) use ($input) {
  1359. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1360. $website = [
  1361. 'website_id' => $input['website_id'],
  1362. ];
  1363. // 查询栏目名称
  1364. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1365. if (empty($category)) {
  1366. $imgArticles = [];
  1367. $textArticles = [];
  1368. // return Result::error("暂无此栏目",0);
  1369. } else {
  1370. $parent_alias = $category->alias ?? '';
  1371. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1372. // 查询图片新闻
  1373. $imgArticles = Article::where('catid', $parentCatId)
  1374. ->where('status', 1)
  1375. ->where(function ($query) use ($website) {
  1376. $query->where(function ($subQuery) use ($website) {
  1377. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1378. })->orWhereNull("ignore_ids");
  1379. })
  1380. ->where('imgurl', '!=', '')
  1381. ->select(
  1382. 'article.id',
  1383. 'article.title',
  1384. 'article.imgurl',
  1385. 'article.author',
  1386. 'article.updated_at',
  1387. 'article.introduce',
  1388. 'article.islink',
  1389. 'article.linkurl',
  1390. 'article.copyfrom',
  1391. DB::raw("'$parent_pinyin' as pinyin") // 添加 pinyin 字段
  1392. )
  1393. ->orderBy('updated_at', 'desc')
  1394. ->limit($parentImgNum)
  1395. ->get()->all();
  1396. // 查询文字新闻
  1397. $textArticles = Article::where('catid', $parentCatId)
  1398. ->where('status', 1)
  1399. ->where(function ($query) use ($website) {
  1400. $query->where(function ($subQuery) use ($website) {
  1401. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1402. })->orWhereNull("ignore_ids");
  1403. })
  1404. ->select(
  1405. 'article.id',
  1406. 'article.title',
  1407. 'article.author',
  1408. 'article.updated_at',
  1409. 'article.introduce',
  1410. 'article.islink',
  1411. 'article.linkurl',
  1412. 'article.copyfrom',
  1413. DB::raw("'$parent_pinyin' as pinyin")
  1414. )
  1415. ->orderBy('updated_at', 'desc')
  1416. ->limit($parentTextNum)
  1417. ->get()->all();
  1418. }
  1419. $resultItem = [
  1420. 'alias' => $parent_alias,
  1421. 'category_id' => $parentCatId,
  1422. 'pinyin' => $parent_pinyin,
  1423. 'imgnum' => $imgArticles,
  1424. 'textnum' => $textArticles,
  1425. ];
  1426. if (!empty($item['child']) && $item['child'] != "") {
  1427. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  1428. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1429. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1430. ->get()->all();
  1431. if ($childCategory) {
  1432. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1433. // 查询子栏目名称
  1434. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1435. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1436. ->first();
  1437. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  1438. if (empty($childCategoryInfo)) {
  1439. $childImgArticles = [];
  1440. $childTextArticles = [];
  1441. } else {
  1442. // 查询子栏目图片新闻
  1443. $childImgArticles = Article::where('catid', $childCatId)
  1444. ->where('status', 1)
  1445. ->where(function ($query) use ($website) {
  1446. $query->where(function ($subQuery) use ($website) {
  1447. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1448. })->orWhereNull("ignore_ids");
  1449. })
  1450. ->select(
  1451. 'article.id',
  1452. 'article.title',
  1453. 'article.imgurl',
  1454. 'article.author',
  1455. 'article.updated_at',
  1456. 'article.introduce',
  1457. 'article.islink',
  1458. 'article.linkurl',
  1459. 'article.copyfrom',
  1460. DB::raw("'$child_pinyin' as pinyin")
  1461. )
  1462. ->where('imgurl', '!=', '')
  1463. ->orderBy('updated_at', 'desc')
  1464. ->limit($childImgNum)
  1465. ->get()->all();
  1466. // 查询子栏目文字新闻
  1467. $childTextArticles = Article::where('catid', $childCatId)
  1468. ->where('status', 1)
  1469. ->where(function ($query) use ($website) {
  1470. $query->where(function ($subQuery) use ($website) {
  1471. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1472. })->orWhereNull("ignore_ids");
  1473. })
  1474. ->select(
  1475. 'article.id',
  1476. 'article.title',
  1477. 'article.author',
  1478. 'article.updated_at',
  1479. 'article.introduce',
  1480. 'article.islink',
  1481. 'article.linkurl',
  1482. 'article.copyfrom',
  1483. DB::raw("'$child_pinyin' as pinyin")
  1484. )
  1485. ->orderBy('updated_at', 'desc')
  1486. ->limit($childTextNum)
  1487. ->get()->all();
  1488. }
  1489. $resultItem['child'] = [
  1490. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1491. 'category_id' => $childCatId,
  1492. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1493. 'all_childcat' => $childCategory,
  1494. 'imgnum' => $childImgArticles,
  1495. 'textnum' => $childTextArticles,
  1496. ];
  1497. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1498. }
  1499. }
  1500. return $resultItem;
  1501. }, $data);
  1502. return Result::success($result);
  1503. // return Result::success($data);
  1504. }
  1505. /**
  1506. * 乡村网-获取特殊新闻模块
  1507. * @param array $data
  1508. * @return array
  1509. */
  1510. public function getWebsiteArticles(array $data): array
  1511. {
  1512. $input['id'] = $data['id'];
  1513. $input['website_id'] = $data['website_id'];
  1514. $data = json_decode($input['id'], true);
  1515. // 使用 array_map 处理每个元素
  1516. $result = array_map(function ($item) use ($input) {
  1517. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1518. $website = [
  1519. 'website_id' => $input['website_id']
  1520. ];
  1521. // 查询栏目名称
  1522. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1523. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1524. if (empty($category)) {
  1525. $imgArticles = [];
  1526. $textArticles = [];
  1527. // return Result::error("暂无此栏目",0);
  1528. } else {
  1529. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1530. // return Result::success($website);
  1531. // 查询图片新闻
  1532. // 合并查询条件
  1533. $baseQuery = Article::where(function ($query) use ($website) {
  1534. $query->where(function ($subQuery) use ($website) {
  1535. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1536. })->orWhereNull("ignore_ids");
  1537. })
  1538. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
  1539. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1540. ->where('website_category.website_id', $website['website_id'])
  1541. ->where('article.status', 1);
  1542. // 查询文字新闻
  1543. $textArticles = clone $baseQuery;
  1544. $textArticles = $textArticles
  1545. ->select(
  1546. 'article.id',
  1547. 'article.title',
  1548. // 'article.imgurl',
  1549. 'article.author',
  1550. 'article.updated_at',
  1551. 'article.introduce',
  1552. 'article.islink',
  1553. 'article.linkurl',
  1554. 'article.copyfrom',
  1555. 'website_category.category_id',
  1556. 'website_category.alias',
  1557. 'website_category.aLIas_pinyin'
  1558. )
  1559. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1560. ->orderBy('article.updated_at', 'desc')
  1561. ->limit($parentTextNum)
  1562. ->get()
  1563. ->all();
  1564. // 查询图片新闻
  1565. $imgArticles = clone $baseQuery;
  1566. $imgArticles = $imgArticles
  1567. ->select(
  1568. 'article.id',
  1569. 'article.title',
  1570. 'article.imgurl',
  1571. 'article.author',
  1572. 'article.updated_at',
  1573. 'article.introduce',
  1574. 'article.islink',
  1575. 'article.linkurl',
  1576. 'article.copyfrom',
  1577. 'website_category.category_id',
  1578. 'website_category.alias',
  1579. 'website_category.aLIas_pinyin'
  1580. )
  1581. ->selectRaw("CONCAT(?, aLIas_pinyin ) as aLIas_pinyin", [$parent_alias])
  1582. ->orderBy('article.updated_at', 'desc')
  1583. ->where('imgurl', '!=', '')
  1584. ->limit($parentImgNum)
  1585. ->get()
  1586. ->all();
  1587. }
  1588. $resultItem = [
  1589. 'alias' => $category ? $category->alias : null,
  1590. 'category_id' => $parentCatId,
  1591. 'pinyin' => $pinyin ? $pinyin : null,
  1592. 'imgnum' => $imgArticles ?? [],
  1593. 'textnum' => $textArticles ?? [],
  1594. ];
  1595. return $resultItem;
  1596. }, $data);
  1597. return Result::success($result);
  1598. }
  1599. /**
  1600. *获取头条类新闻模块-合集
  1601. * @param array $data
  1602. * @return array
  1603. */
  1604. public function getWebsiteAllArticlett(array $data): array
  1605. {
  1606. $input['id'] = $data['id'];
  1607. $input['website_id'] = $data['website_id'];
  1608. $data = json_decode($input['id'], true);
  1609. // 使用 array_map 处理每个元素
  1610. $result = array_map(function ($item) use ($input) {
  1611. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1612. $website = [
  1613. 'website_id' => $input['website_id']
  1614. ];
  1615. $category = WebsiteCategory::where('website_id', $input['website_id'])->pluck('category_id');
  1616. $category = array_values(array_unique($category->toArray()));
  1617. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1618. $where = [
  1619. 'status' => 1,
  1620. ];
  1621. return $category;
  1622. }, $data); // 添加第二个参数 $data,确保 array_map 函数有两个参数
  1623. return Result::success($result);
  1624. }
  1625. /**
  1626. * 验证导航名称是否重复
  1627. * @return void
  1628. */
  1629. public function checkCategoryName(array $data): array
  1630. {
  1631. $result = Category::when($data, function ($query) use ($data) {
  1632. if (isset($data['name']) && $data['name']) {
  1633. $query->where("name", $data['name']);
  1634. }
  1635. if (isset($data['id']) && $data['id']) {
  1636. $query->where("id", "!=", $data['id']);
  1637. }
  1638. })->first();
  1639. if ($result) {
  1640. return Result::error("已存在");
  1641. } else {
  1642. return Result::success();
  1643. }
  1644. }
  1645. //20250226 产品列表
  1646. public function getGoodList(array $data): array
  1647. {
  1648. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1649. unset($data['type_id']);
  1650. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1651. $where = [];
  1652. if ($type_id != '10000') {
  1653. $where = [
  1654. 'good.user_id' => $user_id,
  1655. ];
  1656. }
  1657. //类型
  1658. if (isset($data['type_id']) && $data['type_id']) {
  1659. $where = [
  1660. 'type_id' => $data['type_id'],
  1661. ];
  1662. }
  1663. //名称
  1664. if (isset($data['name']) && $data['name']) {
  1665. $where = [
  1666. 'good.name' => $data['name'],
  1667. ];
  1668. }
  1669. $where1 = [];
  1670. //website_id
  1671. // if (isset($data['website_id']) && $data['website_id']) {
  1672. // $where1 = [
  1673. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1674. // ];
  1675. // }
  1676. // website_name
  1677. if (isset($data['website_name']) && $data['website_name']) {
  1678. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1679. }
  1680. // catid
  1681. if (isset($data['category_name']) && $data['category_name']) {
  1682. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1683. }
  1684. // $result = Good::where($where)
  1685. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1686. $result = Good::where($where)
  1687. ->when(!empty($where1), function ($query) use ($where1) {
  1688. return $query->where($where1);
  1689. })
  1690. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1691. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1692. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1693. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1694. ->orderBy("id", "desc")
  1695. ->limit($data['page_size'])
  1696. ->offset(($data['page'] - 1) * $data['page_size'])
  1697. ->get();
  1698. $count = Good::where($where)
  1699. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1700. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1701. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1702. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1703. ->orderBy("updated_at", "desc")->count();
  1704. $data = [
  1705. 'rows' => $result->toArray(),
  1706. 'count' => $count,
  1707. ];
  1708. if (empty($result)) {
  1709. return Result::error("此栏目暂无相关产品", 0);
  1710. }
  1711. return Result::success($data);
  1712. }
  1713. public function getGoodInfo(array $data): array
  1714. {
  1715. $result = Good::where('id', $data['id'])->first();
  1716. if (empty($result)) {
  1717. return Result::error("此产品不存在", 0);
  1718. }
  1719. return Result::success($result);
  1720. }
  1721. public function addGood(array $data): array
  1722. {
  1723. // unset($data['city_arr_id']);
  1724. // unset($data['cat_arr_id']);
  1725. $data['city_id'] = end($data['city_arr_id']);
  1726. $data['catid'] = end($data['cat_arr_id']);
  1727. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1728. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1729. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1730. unset($data['imgUrl']);
  1731. $result = Good::insert($data);
  1732. if (empty($result)) {
  1733. return Result::error("添加失败", 0);
  1734. }
  1735. return Result::success($result);
  1736. }
  1737. public function updateGood(array $data): array
  1738. {
  1739. $data['city_id'] = end($data['city_arr_id']);
  1740. $data['catid'] = end($data['cat_arr_id']);
  1741. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1742. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1743. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1744. //设置东八区
  1745. date_default_timezone_set('Asia/Shanghai');
  1746. $data['updated_at'] = date('Y-m-d H:i:s');
  1747. $result = Good::where('id', $data['id'])->update($data);
  1748. if (empty($result)) {
  1749. return Result::error("更新失败", 0);
  1750. }
  1751. return Result::success($result);
  1752. }
  1753. public function delGood(array $data): array
  1754. {
  1755. $result = Good::where('id', $data['id'])->delete();
  1756. if (empty($result)) {
  1757. return Result::error("删除失败", 0);
  1758. }
  1759. return Result::success($result);
  1760. }
  1761. //20250226 产品列表
  1762. //20250306 求职信息
  1763. public function getJobHuntingList(array $data): array
  1764. {
  1765. $where = [];
  1766. if (isset($data['username']) && !empty($data['username'])) {
  1767. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1768. }
  1769. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1770. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1771. unset($data['type_id']);
  1772. if ($type_id != '10000') {
  1773. $where[] = ['job_hunting.user_id', '=', $user_id];
  1774. }
  1775. $result = JobHunting::where($where)
  1776. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1777. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1778. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1779. ->orderBy("id", "desc")
  1780. ->limit($data['page_size'])
  1781. ->offset(($data['page'] - 1) * $data['page_size'])
  1782. ->get();
  1783. if (empty($result)) {
  1784. return Result::error("查询失败", 0);
  1785. }
  1786. $count = JobHunting::where($where)
  1787. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1788. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1789. ->count();
  1790. $data = [
  1791. 'rows' => $result->toArray(),
  1792. 'count' => $count,
  1793. ];
  1794. return Result::success($data);
  1795. }
  1796. public function addJobHunting(array $data): array
  1797. {
  1798. date_default_timezone_set('Asia/Shanghai');
  1799. unset($data['company_name']);
  1800. unset($data['job_industry']);
  1801. unset($data['job_name']);
  1802. unset($data['department']);
  1803. unset($data['job_timeList']);
  1804. unset($data['job_content']);
  1805. $data['created_at'] = date('Y-m-d H:i:s');
  1806. $data['updated_at'] = date('Y-m-d H:i:s');
  1807. var_dump($data, '-----------------test---------');
  1808. $result = JobHunting::create($data);
  1809. if (empty($result)) {
  1810. return Result::error("添加失败", 0);
  1811. }
  1812. return Result::success($result);
  1813. }
  1814. public function delJobHunting(array $data): array
  1815. {
  1816. $result = JobHunting::where('id', $data['id'])->delete();
  1817. if (empty($result)) {
  1818. return Result::error("删除失败", 0);
  1819. }
  1820. return Result::success($result);
  1821. }
  1822. public function updateJobHunting(array $data): array
  1823. {
  1824. //设置东八区
  1825. date_default_timezone_set('Asia/Shanghai');
  1826. unset($data['company_name']);
  1827. unset($data['job_industry']);
  1828. unset($data['job_name']);
  1829. unset($data['department']);
  1830. unset($data['job_timeList']);
  1831. unset($data['job_content']);
  1832. $data['created_at'] = date('Y-m-d H:i:s');
  1833. $data['updated_at'] = date('Y-m-d H:i:s');
  1834. $result = JobHunting::where('id', $data['id'])->update($data);
  1835. if (empty($result)) {
  1836. return Result::error("更新失败", 0);
  1837. }
  1838. return Result::success($result);
  1839. }
  1840. public function getJobHuntingInfo(array $data): array
  1841. {
  1842. $result = JobHunting::where('id', $data['id'])->first();
  1843. if (empty($result)) {
  1844. return Result::error("查询失败", 0);
  1845. }
  1846. return Result::success($result);
  1847. }
  1848. public function getJobHuntingData(array $data): array
  1849. {
  1850. $jobEnum = JobEnum::get();
  1851. $jobIndustry = JobIndustry::get();
  1852. $jobNature = JobNature::get();
  1853. $jobPosition = JobPosition::get();
  1854. $data = [
  1855. 'jobEnum' => $jobEnum,
  1856. 'jobIndustry' => $jobIndustry,
  1857. 'jobNature' => $jobNature,
  1858. 'jobPosition' => $jobPosition,
  1859. ];
  1860. return Result::success($data);
  1861. }
  1862. public function delJobHuntingInfo(array $data): array
  1863. {
  1864. $result = JobHunting::where('id', $data['id'])->delete();
  1865. return Result::success();
  1866. }
  1867. //20250324 通知,公告,消息
  1868. public function delNotice(array $data): array
  1869. {
  1870. return Result::success();
  1871. }
  1872. public function getNoticeInfo(array $data): array
  1873. {
  1874. $result = Notice::where('id', $data['id'])->first();
  1875. if (empty($result)) {
  1876. return Result::error("查询失败", 0);
  1877. }
  1878. return Result::success($result);
  1879. }
  1880. public function addNotice(array $data): array
  1881. {
  1882. date_default_timezone_set('Asia/Shanghai');
  1883. $data['created_at'] = date('Y-m-d H:i:s');
  1884. $data['updated_at'] = date('Y-m-d H:i:s');
  1885. $user_id = UserInfo::
  1886. //city_id不是null
  1887. whereNotNull('city_id')
  1888. ->whereNotNull('department_id')
  1889. ->where(function ($query) use ($data) {
  1890. $query->where(function ($subQuery) use ($data) {
  1891. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  1892. });
  1893. })
  1894. ->where(function ($query) use ($data) {
  1895. $query->where(function ($subQuery) use ($data) {
  1896. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  1897. });
  1898. })
  1899. ->pluck('user_id')->toArray();
  1900. $user_id = array_unique($user_id);
  1901. $user_id = json_encode($user_id);
  1902. $data['re_user_ids'] = $user_id;
  1903. $result = Notice::create($data);
  1904. if (empty($result)) {
  1905. return Result::error("添加失败", 0);
  1906. }
  1907. return Result::success($result);
  1908. }
  1909. public function updateNotice(array $data): array
  1910. {
  1911. date_default_timezone_set('Asia/Shanghai');
  1912. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  1913. $user_id = UserInfo::
  1914. //city_id不是null
  1915. whereNotNull('city_id')
  1916. ->whereNotNull('department_id')
  1917. ->where(function ($query) use ($data) {
  1918. $query->where(function ($subQuery) use ($data) {
  1919. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  1920. });
  1921. })
  1922. ->where(function ($query) use ($data) {
  1923. $query->where(function ($subQuery) use ($data) {
  1924. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  1925. });
  1926. })
  1927. ->pluck('user_id')->toArray();
  1928. $user_id = array_unique($user_id);
  1929. $user_id = json_encode($user_id);
  1930. $data['re_user_ids'] = $user_id;
  1931. $data['updated_at'] = date('Y-m-d H:i:s');
  1932. $result = Notice::where('id', $data['id'])->update($data);
  1933. return Result::success($result);
  1934. }
  1935. public function getNoticeList(array $data): array
  1936. {
  1937. $where = [];
  1938. //title
  1939. if (isset($data['title']) && !empty($data['title'])) {
  1940. $where[] = ['title', 'like', '%' . $data['title'] . '%'];
  1941. }
  1942. //level
  1943. if (isset($data['level']) && !empty($data['level'])) {
  1944. $where[] = ['level', '=', $data['level']];
  1945. }
  1946. var_dump($data['type_id'], '-----------------test---------');
  1947. if ($data['type_id'] == 10000) {
  1948. $result = Notice::where('status', 1)
  1949. ->where($where)
  1950. ->orderBy('updated_at', 'desc')
  1951. ->limit($data['page_size'])
  1952. ->offset(($data['page'] - 1) * $data['page_size'])
  1953. ->get();
  1954. } else {
  1955. $result = Notice::where('status', 1)
  1956. ->where($where)
  1957. ->where('user_id', $data['user_id'])
  1958. ->orWhere(function ($query) use ($data) {
  1959. $query->where('re_user_ids', 'like', '%' . $data['user_id'] . '%');
  1960. })
  1961. ->orderBy('updated_at', 'desc')
  1962. ->limit($data['page_size'])
  1963. ->offset(($data['page'] - 1) * $data['page_size'])
  1964. ->get();
  1965. }
  1966. if (empty($result)) {
  1967. return Result::error("查询失败", 0);
  1968. }
  1969. $count = Notice::where('status', 1)->count();
  1970. $data = [
  1971. 'rows' => $result,
  1972. 'count' => $count,
  1973. ];
  1974. return Result::success($data);
  1975. }
  1976. public function getNoticeDetail(array $data): array
  1977. {
  1978. $result = Notice::where('id', $data['id'])->first();
  1979. if (empty($result)) {
  1980. return Result::error("查询失败", 0);
  1981. }
  1982. return Result::success($result);
  1983. }
  1984. public function deleteNotice(array $data): array
  1985. {
  1986. $result = Notice::where('id', $data['id'])->delete();
  1987. return Result::success($result);
  1988. }
  1989. public function getMSG(array $data): array
  1990. {
  1991. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  1992. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  1993. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  1994. $result = [];
  1995. if ($type_id == 1) {
  1996. //最近的5篇已审的文章
  1997. $apply_articale = Article::where('status', 1)
  1998. ->where('admin_user_id', $user_id)
  1999. ->orderBy('updated_at', 'desc')
  2000. ->limit(5)->get();
  2001. //获取5条单聊未读聊天消息
  2002. $chat = ChatRecords::where('is_read', 0)
  2003. ->where('user_id', $user_id)
  2004. ->where('talk_type', 1)
  2005. ->orderBy('created_at', 'desc')
  2006. ->limit(5)->get();
  2007. //获取5条未读群聊信息
  2008. $chat_group = ChatRecords::where('is_read', 0)
  2009. ->where('user_id', $user_id)
  2010. ->where('talk_type', 2)
  2011. ->orderBy('created_at', 'desc')
  2012. ->limit(5)->get();
  2013. $count = count($chat) + count($chat_group) + count($apply_articale);
  2014. $result = [
  2015. 'apply_articale' => $apply_articale,
  2016. 'chat' => $chat,
  2017. 'chat_group' => $chat_group,
  2018. 'count' => $count,
  2019. ];
  2020. } elseif ($type_id == 2) {
  2021. //最近的5篇已审的文章
  2022. $apply_articale = Article::where('status', 1)
  2023. ->where('admin_user_id', $user_id)
  2024. ->limit(5)->get();
  2025. //获取5条单聊未读聊天消息
  2026. $chat = ChatRecords::where('is_read', 0)
  2027. ->where('user_id', $user_id)
  2028. ->where('talk_type', 1)
  2029. ->orderBy('created_at', 'desc')
  2030. ->limit(5)->get();
  2031. //获取5条未读群聊信息
  2032. $chat_group = ChatRecords::where('is_read', 0)
  2033. ->where('user_id', $user_id)
  2034. ->where('talk_type', 2)
  2035. ->orderBy('created_at', 'desc')
  2036. ->limit(5)->get();
  2037. $count = count($chat) + count($chat_group) + count($apply_articale);
  2038. $result = [
  2039. 'apply_articale' => $apply_articale,
  2040. 'chat' => $chat,
  2041. 'chat_group' => $chat_group,
  2042. 'count' => $count,
  2043. ];
  2044. } elseif ($type_id == 3) {
  2045. //最近的5篇已审的文章
  2046. $apply_articale = Article::where('status', 1)
  2047. ->where('admin_user_id', $user_id)
  2048. ->limit(5)->get();
  2049. //获取5条单聊未读聊天消息
  2050. $chat = ChatRecords::where('is_read', 0)
  2051. ->where('user_id', $user_id)
  2052. ->where('talk_type', 1)
  2053. ->orderBy('created_at', 'desc')
  2054. ->limit(5)->get();
  2055. //获取5条未读群聊信息
  2056. $chat_group = ChatRecords::where('is_read', 0)
  2057. ->where('user_id', $user_id)
  2058. ->where('talk_type', 2)
  2059. ->orderBy('created_at', 'desc')
  2060. ->limit(5)->get();
  2061. $count = count($chat) + count($chat_group) + count($apply_articale);
  2062. $result = [
  2063. 'apply_articale' => $apply_articale,
  2064. 'chat' => $chat,
  2065. 'chat_group' => $chat_group,
  2066. 'count' => $count,
  2067. ];
  2068. } elseif ($type_id == 4) {
  2069. //最近的5篇已审的文章
  2070. $apply_articale = Article::where('status', 1)
  2071. ->where('admin_user_id', $user_id)
  2072. ->limit(5)->get();
  2073. $count = count($apply_articale);
  2074. $result = [
  2075. 'apply_articale' => $apply_articale,
  2076. 'count' => $count,
  2077. ];
  2078. } elseif ($type_id == 10000) {
  2079. //获取未审核的5篇文章
  2080. $apply_articale = Article::where('status', 0)
  2081. ->orderBy('updated_at', 'desc')
  2082. ->limit(5)->get();
  2083. //获取5条单聊未读聊天消息
  2084. $chat = ChatRecords::where('is_read', 0)
  2085. ->where('user_id', $user_id)
  2086. ->where('talk_type', 1)
  2087. ->orderBy('created_at', 'desc')
  2088. ->limit(5)->get();
  2089. //获取5条未读群聊信息
  2090. $chat_group = ChatRecords::where('is_read', 0)
  2091. ->where('user_id', $user_id)
  2092. ->where('talk_type', 2)
  2093. ->orderBy('created_at', 'desc')
  2094. ->limit(5)->get();
  2095. $count = count($chat) + count($chat_group) + count($apply_articale);
  2096. $result = [
  2097. 'apply_articale' => $apply_articale,
  2098. 'chat' => $chat,
  2099. 'chat_group' => $chat_group,
  2100. 'count' => $count,
  2101. ];
  2102. } elseif ($type_id == 20000) {
  2103. }
  2104. var_dump($type_id, '-----------------test---------');
  2105. return Result::success($result);
  2106. }
  2107. public function getComplaintList(array $data): array
  2108. {
  2109. $result = Notice::where('status', 1)->get();
  2110. return Result::success($result);
  2111. }
  2112. public function getComplaintInfo(array $data): array
  2113. {
  2114. $result = Notice::where('id', $data['id'])->first();
  2115. if (empty($result)) {
  2116. return Result::error("查询失败", 0);
  2117. }
  2118. return Result::success($result);
  2119. }
  2120. public function addComplaint(array $data): array
  2121. {
  2122. $result = Notice::create($data);
  2123. return Result::success($result);
  2124. }
  2125. public function updateComplaint(array $data): array
  2126. {
  2127. $result = Notice::where('id', $data['id'])->update($data);
  2128. return Result::success($result);
  2129. }
  2130. public function deleteComplaint(array $data): array
  2131. {
  2132. $result = Notice::where('id', $data['id'])->delete();
  2133. return Result::success($result);
  2134. }
  2135. public function getComplainInfo(array $data): array
  2136. {
  2137. $result = Notice::where('id', $data['id'])->first();
  2138. if (empty($result)) {
  2139. return Result::error("查询失败", 0);
  2140. }
  2141. return Result::success($result);
  2142. }
  2143. //20250324 通知,公告,消息
  2144. // 20250306 -------招聘--------fr
  2145. /*
  2146. * 招聘列表
  2147. * */
  2148. public function getJobRecruitingList(array $data): array
  2149. {
  2150. $where = [];
  2151. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2152. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  2153. }
  2154. $user = User::where('id', $data['user_id'])->first();
  2155. if (empty($user)) {
  2156. return Result::error("用户不存在", 0);
  2157. }
  2158. // 3:企业会员
  2159. if ($user['type_id'] == 3) {
  2160. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  2161. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  2162. }
  2163. // 如果 $where 为空,则不添加 where 条件
  2164. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2165. return $query->where($where);
  2166. })
  2167. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  2168. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  2169. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  2170. ->orderBy("updated_at", "desc")
  2171. ->offset(($data['page'] - 1) * $data['page_size'])
  2172. ->limit($data['page_size'])
  2173. ->get()
  2174. ->all();
  2175. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2176. return $query->where($where);
  2177. })
  2178. ->count();
  2179. if (empty($result)) {
  2180. return Result::error("暂无招聘信息", 0);
  2181. }
  2182. return Result::success($result);
  2183. }
  2184. /*
  2185. * 招聘信息添加
  2186. * */
  2187. public function addJobRecruiting(array $data): array
  2188. {
  2189. // return Result::success($data);
  2190. $user = User::where('user.id', $data['user_id'])
  2191. ->where('user.status', 1)
  2192. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2193. ->select(
  2194. 'user.type_id',
  2195. 'user.mobile',
  2196. 'user.email',
  2197. 'user_info.business_name',
  2198. 'user_info.hy_id',
  2199. 'user_info.company_nature',
  2200. 'user_info.company_size',
  2201. 'user_info.introduction',
  2202. 'user_info.real_name',
  2203. 'user_info.company_url',
  2204. 'user_info.address_arr_id',
  2205. 'user_info.address'
  2206. )
  2207. ->first();
  2208. if (empty($user) || $user['type_id'] != $data['user_type']) {
  2209. return Result::error("用户不存在", 0);
  2210. }
  2211. $web = Website::where('id', $data['website_id'])->first();
  2212. if (empty($web)) {
  2213. return Result::error("网站不存在", 0);
  2214. }
  2215. // return Result::success($user);
  2216. $data['action_id'] = $data['user_id'];
  2217. $data['user_type'] = $user['type_id'];
  2218. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  2219. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  2220. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  2221. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  2222. // 公司地址 管理员必填
  2223. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  2224. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2225. // 管理员-企业相关信息
  2226. $company = [
  2227. // 'user_id' => $data['user_id']?? null,
  2228. 'business_name' => $data['business_name'] ?? null,
  2229. 'company_hy_id' => $data['company_hy_id'] ?? null,
  2230. 'company_size' => $data['company_size'] ?? null,
  2231. 'company_nature' => $data['company_nature'] ?? null,
  2232. 'introduction' => $data['introduction'] ?? null,
  2233. 'real_name' => $data['real_name'] ?? null,
  2234. 'mobile' => $data['mobile'] ?? null,
  2235. 'company_url' => $data['company_url'] ?? null,
  2236. 'address_arr_id' => $data['address_arr_id'] ?? null,
  2237. 'address' => $data['address'] ?? null,
  2238. 'email' => $data['email'] ?? null,
  2239. ];
  2240. //去掉相关企业信息
  2241. $job = array_diff_key($data, array_flip(array_keys($company)));
  2242. Db::beginTransaction();
  2243. try {
  2244. // 先添加职位相关信息
  2245. $jobId = JobRecruiting::insertGetId($job);
  2246. if (empty($jobId)) {
  2247. Db::rollBack();
  2248. return Result::error("添加失败");
  2249. }
  2250. // 添加公司信息
  2251. $company['user_id'] = $data['user_id'] ?? null;
  2252. $company['job_id'] = $jobId;
  2253. $company['user_type'] = $user['type_id'] ?? null;
  2254. $company['website_id'] = $data['website_id'] ?? null;
  2255. if ($user['type_id'] == 10000) {
  2256. // 管理员添加企业信息
  2257. // return Result::success($company);
  2258. $companyId = JobCompany::insertGetId($company);
  2259. if (empty($companyId)) {
  2260. Db::rollBack();
  2261. return Result::error("添加失败");
  2262. }
  2263. } else {
  2264. // 企业会员添加企业信息
  2265. $company = [
  2266. 'user_id' => $data['user_id'] ?? null,
  2267. 'business_name' => $user['business_name'] ?? null,
  2268. 'company_hy_id' => $user['hy_id'] ?? null,
  2269. 'company_size' => $user['company_size'] ?? null,
  2270. 'company_nature' => $user['company_nature'] ?? null,
  2271. 'introduction' => $user['introduction'] ?? null,
  2272. 'real_name' => $user['real_name'] ?? null,
  2273. 'mobile' => $user['mobile'] ?? null,
  2274. 'company_url' => $user['company_url'] ?? null,
  2275. 'address_arr_id' => $user['address_arr_id'] ?? null,
  2276. 'address' => $user['address'] ?? null,
  2277. 'email' => $user['email'] ?? null,
  2278. 'website_id' => $data['website_id'] ?? null,
  2279. 'user_type' => $user['type_id'] ?? null,
  2280. 'job_id' => $jobId,
  2281. ];
  2282. $companyId = JobCompany::insertGetId($company);
  2283. if (empty($companyId)) {
  2284. Db::rollBack();
  2285. return Result::error("添加失败");
  2286. }
  2287. // return Result::success($company);
  2288. }
  2289. Db::commit();
  2290. } catch (\Exception $e) {
  2291. Db::rollBack();
  2292. return Result::error($e->getMessage(), 0);
  2293. }
  2294. $result = [
  2295. 'job_id' => $jobId,
  2296. 'company_id' => $companyId,
  2297. ];
  2298. if (empty($result)) {
  2299. return Result::error("添加失败", 0);
  2300. }
  2301. return Result::success($result);
  2302. }
  2303. /*
  2304. * 获取招聘信息详情
  2305. * */
  2306. public function getJobRecruitingInfo(array $data): array
  2307. {
  2308. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  2309. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  2310. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2311. ->select(
  2312. 'job_recruiting.*',
  2313. 'website.website_name as website_name',
  2314. 'job_company.business_name',
  2315. 'job_company.company_hy_id',
  2316. 'job_company.company_size',
  2317. 'job_company.company_nature',
  2318. 'job_company.introduction',
  2319. 'job_company.real_name',
  2320. 'job_company.mobile',
  2321. 'job_company.company_url',
  2322. 'job_company.address_arr_id',
  2323. 'job_company.address',
  2324. 'job_company.email'
  2325. )
  2326. ->first();
  2327. if (empty($result)) {
  2328. return Result::error("招聘信息不存在", 0);
  2329. }
  2330. // return Result::success($job);
  2331. return Result::success($result);
  2332. }
  2333. /*
  2334. * 修改招聘信息
  2335. * */
  2336. public function upJobRecruiting(array $data): array
  2337. {
  2338. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  2339. // return Result::success($job);
  2340. if (empty($job)) {
  2341. return Result::error("招聘信息不存在", 0);
  2342. }
  2343. $user = User::where('id', $data['user_id'])->first();
  2344. // return Result::success($user);
  2345. if (empty($user) || $user['type_id'] != $data['user_type']) {
  2346. return Result::error("用户不存在", 0);
  2347. }
  2348. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  2349. return Result::error("用户暂无权限修改此招聘信息!", 0);
  2350. }
  2351. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  2352. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  2353. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  2354. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  2355. // 公司地址 管理员必填
  2356. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  2357. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2358. // 管理员-企业相关信息
  2359. $company = [
  2360. 'business_name' => $data['business_name'] ?? null,
  2361. 'company_hy_id' => $data['hy_id'] ?? null,
  2362. 'company_size' => $data['company_size'] ?? null,
  2363. 'company_nature' => $data['company_nature'] ?? null,
  2364. 'introduction' => $data['introduction'] ?? null,
  2365. 'real_name' => $data['real_name'] ?? null,
  2366. 'mobile' => $data['mobile'] ?? null,
  2367. 'company_url' => $data['company_url'] ?? null,
  2368. 'address_arr_id' => $data['address_arr_id'] ?? null,
  2369. 'address' => $data['address'] ?? null,
  2370. 'email' => $data['email'] ?? null,
  2371. ];
  2372. //去掉相关企业信息
  2373. $data = array_diff_key($data, array_flip(array_keys($company)));
  2374. $jobId = $data['id'];
  2375. $web = $data['website_id'];
  2376. $data['action_id'] = $data['user_id'];
  2377. unset($data['user_id']);
  2378. unset($data['user_type']);
  2379. unset($data['id']);
  2380. unset($data['website_id']);
  2381. // return Result::success($data);
  2382. Db::beginTransaction();
  2383. try {
  2384. // 管理员修改招聘信息
  2385. if ($user['type_id'] == 10000) {
  2386. $data['website_id'] = $web;
  2387. $company['website_id'] = $data['website_id'];
  2388. }
  2389. // Db::rollBack();
  2390. // return Result::success($company);
  2391. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  2392. if (empty($result['job'])) {
  2393. Db::rollBack();
  2394. return Result::error("修改招聘信息失败");
  2395. }
  2396. // 管理员修改企业相关信息
  2397. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  2398. if (empty($result['company'])) {
  2399. Db::rollBack();
  2400. return Result::error("修改企业相关信息失败");
  2401. }
  2402. Db::commit();
  2403. // return Result::success($result);
  2404. } catch (\Exception $e) {
  2405. Db::rollBack();
  2406. return Result::error($e->getMessage(), 0);
  2407. }
  2408. return Result::success($result);
  2409. }
  2410. /*
  2411. * 招聘信息删除
  2412. * */
  2413. public function delJobRecruiting(array $data): array
  2414. {
  2415. $user = User::where('id', $data['user_id'])->first();
  2416. if (empty($user)) {
  2417. return Result::error("用户不存在", 0);
  2418. }
  2419. $job = JobRecruiting::where('id', $data['id'])->first();
  2420. if (empty($job)) {
  2421. return Result::error("招聘信息不存在", 0);
  2422. }
  2423. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  2424. return Result::error("用户暂无权限修改此招聘信息!", 0);
  2425. }
  2426. Db::beginTransaction();
  2427. try {
  2428. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  2429. if (empty($result['job'])) {
  2430. Db::rollBack();
  2431. return Result::error("删除招聘信息失败");
  2432. }
  2433. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  2434. if (empty($result['company'])) {
  2435. Db::rollBack();
  2436. return Result::error("删除企业相关信息失败");
  2437. }
  2438. Db::commit();
  2439. } catch (\Exception $e) {
  2440. Db::rollBack();
  2441. return Result::error($e->getMessage(), 0);
  2442. }
  2443. return Result::success($result);
  2444. }
  2445. /*
  2446. * 获取公司信息
  2447. * */
  2448. public function getJobCompany(array $data): array
  2449. {
  2450. $user = User::where('user.id', $data['user_id'])
  2451. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2452. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  2453. ->first();
  2454. // return Result::success($user);
  2455. if (empty($user)) {
  2456. return Result::error("用户不存在", 0);
  2457. }
  2458. if ($user['type_id'] == 3) {
  2459. $result = [
  2460. // 'id' => 0,
  2461. 'user_id' => $data['user_id'],
  2462. 'website_id' => $data['website_id'],
  2463. 'business_name' => $user['business_name'], // 企业名称
  2464. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  2465. 'company_nature' => $user['company_nature'], // 公司性质
  2466. 'company_size' => $user['company_size'], // 公司规模
  2467. 'introduction' => $user['introduction'], // 公司简介
  2468. 'real_name' => $user['real_name'], // 企业联系人
  2469. 'mobile' => $user['mobile'], // 企业联系电话
  2470. 'company_url' => $user['company_url'], // 企业网址
  2471. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  2472. 'address' => $user['address'], // 企业地址
  2473. 'email' => $user['email'], // 企业邮箱
  2474. ];
  2475. } else {
  2476. return Result::error("用户类型错误", 0);
  2477. }
  2478. if (empty($result)) {
  2479. return Result::error("公司信息不存在", 0);
  2480. }
  2481. return Result::success($result);
  2482. }
  2483. /*
  2484. * 修改公司信息
  2485. * */
  2486. public function upJobCompany(array $data): array
  2487. {
  2488. // return Result::success($data);
  2489. $user = User::where('user.id', $data['user_id'])
  2490. ->where('user.status', 1)
  2491. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2492. ->select('user.user_name', 'user.type_id', 'user_info.*')
  2493. ->first();
  2494. if (empty($user)) {
  2495. return Result::error("用户不存在", 0);
  2496. }
  2497. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2498. $company = [
  2499. 'business_name' => $data['business_name'], // 企业名称
  2500. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  2501. 'company_nature' => $data['company_nature'], // 公司性质
  2502. 'company_size' => $data['company_size'], // 公司规模
  2503. 'introduction' => $data['introduction'], // 公司简介
  2504. 'real_name' => $data['real_name'], // 企业联系人
  2505. 'company_url' => $data['company_url'], // 企业网址
  2506. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  2507. 'address' => $data['address'], // 企业详细地址
  2508. ];
  2509. if ($user['type_id'] == 3) {
  2510. $result['user'] = User::where('user.id', $data['user_id'])->update([
  2511. 'mobile' => $data['mobile'], // 企业联系电话
  2512. 'email' => $data['email'], // 企业邮箱
  2513. ]);
  2514. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  2515. 'business_name' => $data['business_name'], // 企业名称
  2516. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  2517. 'company_nature' => $data['company_nature'], // 公司性质
  2518. 'company_size' => $data['company_size'], // 公司规模
  2519. 'introduction' => $data['introduction'], // 公司简介
  2520. 'real_name' => $data['real_name'], // 企业联系人
  2521. 'company_url' => $data['company_url'], // 企业网址
  2522. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  2523. 'address' => $data['address'], // 企业详细地址
  2524. ]);
  2525. $result = JobCompany::where('user_id', $data['user_id'])->update($company);
  2526. } else {
  2527. return Result::error("用户类型错误", 0);
  2528. }
  2529. if (empty($result)) {
  2530. return Result::error("修改失败", 0);
  2531. }
  2532. return Result::success($result);
  2533. }
  2534. /*
  2535. * 获取省-市
  2536. * */
  2537. public function getJobRecruitingArea(array $data): array
  2538. {
  2539. if (isset($data['province_id']) && $data['province_id'] != null) {
  2540. $result = District::where('pid', $data['pid'])->get()->all();
  2541. } else {
  2542. $result = District::where('level', 1)->get()->all();
  2543. }
  2544. if (empty($result)) {
  2545. return Result::error("暂无此省市", 0);
  2546. }
  2547. return Result::success($result);
  2548. }
  2549. /*
  2550. * 获取行业分类
  2551. * */
  2552. public function getIndustry(array $data): array
  2553. {
  2554. $result = JobIndustry::get()->all();
  2555. if (empty($result)) {
  2556. return Result::error("暂无行业分类", 0);
  2557. }
  2558. return Result::success($result);
  2559. }
  2560. /*
  2561. * 获取职位
  2562. * */
  2563. public function getPositionList(array $data): array
  2564. {
  2565. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  2566. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  2567. } else {
  2568. $result = JobPosition::where('zwpid', 0)->get()->all();
  2569. }
  2570. if (empty($result)) {
  2571. return Result::error("暂无此职位", 0);
  2572. }
  2573. return Result::success($result);
  2574. }
  2575. /*
  2576. * 获取工作性质-菜单
  2577. * */
  2578. public function getJobNature(array $data): array
  2579. {
  2580. $result = JobEnum::where('egroup', 'nature')->get()->all();
  2581. if (empty($result)) {
  2582. return Result::error("暂无工作性质", 0);
  2583. }
  2584. return Result::success($result);
  2585. }
  2586. /*
  2587. * 获取工作经验-菜单
  2588. * */
  2589. public function getExperience(array $data): array
  2590. {
  2591. $result = JobEnum::where('egroup', 'years')->get()->all();
  2592. if (empty($result)) {
  2593. return Result::error("暂无工作经验", 0);
  2594. }
  2595. return Result::success($result);
  2596. }
  2597. /*
  2598. * 获取学历-菜单
  2599. * */
  2600. public function getEducation(array $data): array
  2601. {
  2602. $result = JobEnum::where('egroup', 'education')->get()->all();
  2603. if (empty($result)) {
  2604. return Result::error("暂无学历", 0);
  2605. }
  2606. return Result::success($result);
  2607. }
  2608. /*
  2609. * 获取薪资-菜单
  2610. * */
  2611. public function getSalary(array $data): array
  2612. {
  2613. $result = JobEnum::where('egroup', 'income')->get()->all();
  2614. if (empty($result)) {
  2615. return Result::error("暂无薪资", 0);
  2616. }
  2617. return Result::success($result);
  2618. }
  2619. /*
  2620. * 获取语言-菜单
  2621. * */
  2622. public function getLanguage(array $data): array
  2623. {
  2624. $result = JobEnum::where('egroup', 'language')->get()->all();
  2625. if (empty($result)) {
  2626. return Result::error("暂无语言", 0);
  2627. }
  2628. return Result::success($result);
  2629. }
  2630. /*
  2631. * 获取掌握程度-菜单
  2632. * */
  2633. public function getLevel(array $data): array
  2634. {
  2635. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  2636. if (empty($result)) {
  2637. return Result::error("暂无工作性质", 0);
  2638. }
  2639. return Result::success($result);
  2640. }
  2641. // 公司信息
  2642. /*
  2643. * 获取公司性质-菜单
  2644. * */
  2645. public function getCompanyNature(array $data): array
  2646. {
  2647. $result = JobNature::get()->all();
  2648. if (empty($result)) {
  2649. return Result::error("暂无公司性质", 0);
  2650. }
  2651. return Result::success($result);
  2652. }
  2653. /*
  2654. * 获取公司规模-菜单
  2655. * */
  2656. public function getCompanySize(array $data): array
  2657. {
  2658. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  2659. if (empty($result)) {
  2660. return Result::error("暂无公司规模", 0);
  2661. }
  2662. return Result::success($result);
  2663. }
  2664. // 20250306 招聘
  2665. }