NewsService.php 124 KB

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