NewsService.php 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050
  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('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. // 检查parent元素是否存在且不是undefined
  1371. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent']!= "") {
  1372. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1373. $website = [
  1374. 'website_id' => $input['website_id'],
  1375. ];
  1376. // 查询栏目名称
  1377. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1378. if(empty($category)){
  1379. $parent_alias = '';
  1380. $parent_pinyin = null;
  1381. $imgArticles = [];
  1382. $textArticles = [];
  1383. }else{
  1384. $parent_alias = $category->alias ?? '';
  1385. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1386. if($parentImgNum!=0){
  1387. // 查询图片新闻
  1388. $imgArticles = Article::where('article.status', 1)
  1389. ->where(function ($query) use ($website, $parentCatId) {
  1390. $query->where(function ($subQuery) use ($website, $parentCatId) {
  1391. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0")
  1392. ->whereRaw("JSON_CONTAINS(article.cat_arr_id, '".intval($parentCatId)."') = 0");
  1393. })->orWhereNull("ignore_ids");
  1394. })
  1395. ->where('imgurl', '!=', '')
  1396. ->leftJoin('website_category', function($join) use ($website) {
  1397. $join->on('article.catid', '=', 'website_category.category_id')
  1398. ->where('website_category.website_id', '=', $website['website_id']);
  1399. })
  1400. ->select(
  1401. 'article.id',
  1402. 'article.title',
  1403. 'article.imgurl',
  1404. 'article.author',
  1405. 'article.updated_at',
  1406. 'article.introduce',
  1407. 'article.islink',
  1408. 'article.linkurl',
  1409. 'article.copyfrom',
  1410. 'article.catid',
  1411. 'website_category.alias as category_name',
  1412. DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin'
  1413. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  1414. )
  1415. ->orderBy('updated_at', 'desc')
  1416. ->limit($parentImgNum)
  1417. ->get()->all();
  1418. // 查询文字新闻
  1419. }
  1420. if($parentTextNum!=0){
  1421. $textArticles = Article::where('article.status', 1)
  1422. ->where(function ($query) use ($website, $parentCatId) {
  1423. $query->where(function ($subQuery) use ($website, $parentCatId) {
  1424. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0")
  1425. ->whereRaw("JSON_CONTAINS(article.cat_arr_id, '".intval($parentCatId)."') = 0");
  1426. })->orWhereNull("ignore_ids");
  1427. })
  1428. ->leftJoin('website_category', function($join) use ($website) {
  1429. $join->on('article.catid', '=', 'website_category.category_id')
  1430. ->where('website_category.website_id', '=', $website['website_id']);
  1431. })
  1432. ->select(
  1433. 'article.id',
  1434. 'article.title',
  1435. 'article.imgurl',
  1436. 'article.author',
  1437. 'article.updated_at',
  1438. 'article.introduce',
  1439. 'article.islink',
  1440. 'article.linkurl',
  1441. 'article.copyfrom',
  1442. 'article.catid',
  1443. 'website_category.alias as category_name',
  1444. DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin'
  1445. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  1446. )
  1447. ->orderBy('updated_at', 'desc')
  1448. ->limit($parentTextNum)
  1449. ->get()->all();
  1450. }
  1451. }
  1452. }
  1453. $resultItem = [
  1454. 'alias' => $parent_alias ?? '',
  1455. 'category_id' => $parentCatId ?? 0,
  1456. 'pinyin' => $parent_pinyin ?? null,
  1457. 'imgnum' => $imgArticles ?? [],
  1458. 'textnum' => $textArticles ?? [],
  1459. ];
  1460. if(isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != ""){
  1461. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin.'/' : '';
  1462. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1463. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1464. ->get()->all();
  1465. if (!empty($childCategory)) {
  1466. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1467. // 查询子栏目名称
  1468. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1469. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1470. ->first();
  1471. if(empty($childCategoryInfo) || ($childImgNum==0 && $childTextNum==0)){
  1472. $childImgArticles = [];
  1473. $childTextArticles = [];
  1474. $resultItem['child'] = [];
  1475. }else{
  1476. $child_pinyin = $childCategoryInfo->aLIas_pinyin? $childCategoryInfo->aLIas_pinyin : null;
  1477. // 查询子栏目图片新闻
  1478. $childImgArticles = 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.imgurl',
  1489. 'article.author',
  1490. 'article.updated_at',
  1491. 'article.introduce',
  1492. 'article.islink',
  1493. 'article.linkurl',
  1494. 'article.copyfrom',
  1495. DB::raw("'$child_pinyin' as pinyin")
  1496. )
  1497. ->where('imgurl', '!=', '')
  1498. ->orderBy('updated_at', 'desc')
  1499. ->limit($childImgNum)
  1500. ->get()->all();
  1501. // 查询子栏目文字新闻
  1502. $childTextArticles = Article::where('catid', $childCatId)
  1503. ->where('status', 1)
  1504. ->where(function ($query) use ($website) {
  1505. $query->where(function ($subQuery) use ($website) {
  1506. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1507. })->orWhereNull("ignore_ids");
  1508. })
  1509. ->select(
  1510. 'article.id',
  1511. 'article.title',
  1512. 'article.author',
  1513. 'article.updated_at',
  1514. 'article.introduce',
  1515. 'article.islink',
  1516. 'article.linkurl',
  1517. 'article.copyfrom',
  1518. DB::raw("'$child_pinyin' as pinyin")
  1519. )
  1520. ->orderBy('updated_at', 'desc')
  1521. ->limit($childTextNum)
  1522. ->get()->all();
  1523. $resultItem['child'] = [
  1524. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1525. 'category_id' => $childCatId,
  1526. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1527. 'all_childcat' => $childCategory,
  1528. 'imgnum' => $childImgArticles,
  1529. 'textnum' => $childTextArticles,
  1530. ];
  1531. }
  1532. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1533. }
  1534. }else{
  1535. $resultItem['child'] = [];
  1536. }
  1537. return $resultItem;
  1538. }, $data);
  1539. return Result::success($result);
  1540. // return Result::success($data);
  1541. }
  1542. /**
  1543. * 乡村网-获取特殊新闻模块
  1544. * @param array $data
  1545. * @return array
  1546. */
  1547. public function getWebsiteArticles(array $data): array
  1548. {
  1549. $input['id'] = $data['id'];
  1550. $input['website_id'] = $data['website_id'];
  1551. $data = json_decode($input['id'], true);
  1552. // 使用 array_map 处理每个元素
  1553. $result = array_map(function ($item) use ($input) {
  1554. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1555. $website = [
  1556. 'website_id' => $input['website_id']
  1557. ];
  1558. // 查询栏目名称
  1559. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1560. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1561. if (empty($category)) {
  1562. $imgArticles = [];
  1563. $textArticles = [];
  1564. // return Result::error("暂无此栏目",0);
  1565. }else{
  1566. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1567. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin.'/' : null;
  1568. // return Result::success($website);
  1569. // 查询图片新闻
  1570. // 合并查询条件
  1571. $baseQuery = Article::where(function ($query) use ($website) {
  1572. $query->where(function ($subQuery) use ($website) {
  1573. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1574. })->orWhereNull("ignore_ids");
  1575. })
  1576. ->where('article.status', 1)
  1577. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1578. ->where('website_category.website_id', $website['website_id']);
  1579. // 查询文字新闻
  1580. $textArticles = clone $baseQuery;
  1581. $textArticles = $textArticles->whereIn('catid',$child_category)
  1582. ->select(
  1583. 'article.id',
  1584. 'article.title',
  1585. // 'article.imgurl',
  1586. 'article.author',
  1587. 'article.updated_at',
  1588. 'article.introduce',
  1589. 'article.islink',
  1590. 'article.linkurl',
  1591. 'article.copyfrom',
  1592. 'website_category.category_id',
  1593. 'website_category.alias',
  1594. 'website_category.aLIas_pinyin'
  1595. )
  1596. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1597. ->orderBy('article.updated_at', 'desc')
  1598. ->limit($parentTextNum)
  1599. ->get()
  1600. ->all();
  1601. if(empty($textArticles)){
  1602. $textArticles = clone $baseQuery;
  1603. $textArticles = $textArticles->where('catid',$parentCatId)
  1604. ->select(
  1605. 'article.id',
  1606. 'article.title',
  1607. // 'article.imgurl',
  1608. 'article.author',
  1609. 'article.updated_at',
  1610. 'article.introduce',
  1611. 'article.islink',
  1612. 'article.linkurl',
  1613. 'article.copyfrom',
  1614. 'website_category.category_id',
  1615. 'website_category.alias',
  1616. 'website_category.aLIas_pinyin'
  1617. )
  1618. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1619. ->orderBy('article.updated_at', 'desc')
  1620. ->limit($parentTextNum)
  1621. ->get()
  1622. ->all();
  1623. }
  1624. // 查询图片新闻
  1625. $imgArticles = clone $baseQuery;
  1626. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid',$child_category)
  1627. ->select(
  1628. 'article.id',
  1629. 'article.title',
  1630. 'article.imgurl',
  1631. 'article.author',
  1632. 'article.updated_at',
  1633. 'article.introduce',
  1634. 'article.islink',
  1635. 'article.linkurl',
  1636. 'article.copyfrom',
  1637. 'website_category.category_id',
  1638. 'website_category.alias',
  1639. 'website_category.aLIas_pinyin'
  1640. )
  1641. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1642. ->orderBy('article.updated_at', 'desc')
  1643. ->limit($parentImgNum)
  1644. ->get()
  1645. ->all();
  1646. if(empty($imgArticles)){
  1647. $imgArticles = clone $baseQuery;
  1648. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid',$parentCatId)
  1649. ->select(
  1650. 'article.id',
  1651. 'article.title',
  1652. 'article.imgurl',
  1653. 'article.author',
  1654. 'article.updated_at',
  1655. 'article.introduce',
  1656. 'article.islink',
  1657. 'article.linkurl',
  1658. 'article.copyfrom',
  1659. 'website_category.category_id',
  1660. 'website_category.alias',
  1661. 'website_category.aLIas_pinyin'
  1662. )
  1663. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1664. ->orderBy('article.updated_at', 'desc')
  1665. ->limit($parentImgNum)
  1666. ->get()
  1667. ->all();
  1668. }
  1669. }
  1670. $resultItem = [
  1671. 'alias' => $category ? $category->alias : null,
  1672. 'category_id' => $parentCatId,
  1673. 'pinyin' => $pinyin ? $pinyin : null,
  1674. 'imgnum' => $imgArticles ?? [],
  1675. 'textnum' => $textArticles ?? [],
  1676. ];
  1677. return $resultItem;
  1678. }, $data);
  1679. return Result::success($result);
  1680. }
  1681. /**
  1682. *获取头条类新闻模块-合集(暂时用不到)
  1683. * @param array $data
  1684. * @return array
  1685. */
  1686. public function getWebsiteAllArticlett(array $data): array
  1687. {
  1688. $input['id'] = $data['id'];
  1689. $input['website_id'] = $data['website_id'];
  1690. $data = json_decode($input['id'], true);
  1691. // 使用 array_map 处理每个元素
  1692. $result = array_map(function ($item) use ($input) {
  1693. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1694. $website = [
  1695. 'website_id' => $input['website_id']
  1696. ];
  1697. $category = WebsiteCategory::where('website_id', $input['website_id'])->pluck('category_id');
  1698. $category = array_values(array_unique($category->toArray()));
  1699. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1700. $where = [
  1701. 'status' => 1,
  1702. ];
  1703. return $category;
  1704. }, $data); // 添加第二个参数 $data,确保 array_map 函数有两个参数
  1705. return Result::success($result);
  1706. }
  1707. /**
  1708. * 验证导航名称是否重复
  1709. * @return void
  1710. */
  1711. public function checkCategoryName(array $data): array
  1712. {
  1713. $result = Category::when($data, function ($query) use ($data) {
  1714. if (isset($data['name']) && $data['name']) {
  1715. $query->where("name", $data['name']);
  1716. }
  1717. if (isset($data['id']) && $data['id']) {
  1718. $query->where("id", "!=", $data['id']);
  1719. }
  1720. })->first();
  1721. if ($result) {
  1722. return Result::error("已存在");
  1723. } else {
  1724. return Result::success();
  1725. }
  1726. }
  1727. //20250226 产品列表
  1728. public function getGoodList(array $data): array
  1729. {
  1730. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1731. unset($data['type_id']);
  1732. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1733. $where = [];
  1734. if ($type_id != '10000') {
  1735. $where = [
  1736. 'good.user_id' => $user_id,
  1737. ];
  1738. }
  1739. //类型
  1740. if (isset($data['type_id']) && $data['type_id']) {
  1741. $where = [
  1742. 'type_id' => $data['type_id'],
  1743. ];
  1744. }
  1745. //名称
  1746. if (isset($data['name']) && $data['name']) {
  1747. $where = [
  1748. 'good.name' => $data['name'],
  1749. ];
  1750. }
  1751. //status
  1752. if (isset($data['status']) && $data['status'] != '') {
  1753. $where = [
  1754. 'good.status' => $data['status'],
  1755. ];
  1756. }
  1757. //status1
  1758. // if (isset($data['status1']) && $data['status1'] == 1) {
  1759. // $status1 = 1;
  1760. // }
  1761. $where1 = [];
  1762. //website_id
  1763. // if (isset($data['website_id']) && $data['website_id']) {
  1764. // $where1 = [
  1765. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1766. // ];
  1767. // }
  1768. // website_name
  1769. if (isset($data['website_name']) && $data['website_name']) {
  1770. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1771. }
  1772. // catid
  1773. if (isset($data['category_name']) && $data['category_name']) {
  1774. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1775. }
  1776. // $result = Good::where($where)
  1777. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1778. $result = Good::where($where)
  1779. ->when(!empty($where1), function ($query) use ($where1) {
  1780. return $query->where($where1);
  1781. })
  1782. //status 1待审核2已审核3已拒绝
  1783. ->when(isset($data['status1']), function ($query) {
  1784. return $query->whereIn('good.status', [1, 3]);
  1785. })
  1786. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1787. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1788. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1789. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1790. ->orderBy("updated_at", "desc")
  1791. ->limit($data['page_size'])
  1792. ->offset(($data['page'] - 1) * $data['page_size'])
  1793. ->get();
  1794. $count = Good::where($where)
  1795. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1796. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1797. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1798. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1799. ->orderBy("updated_at", "desc")->count();
  1800. $data = [
  1801. 'rows' => $result->toArray(),
  1802. 'count' => $count,
  1803. ];
  1804. if (empty($result)) {
  1805. return Result::error("此栏目暂无相关产品", 0);
  1806. }
  1807. return Result::success($data);
  1808. }
  1809. public function getGoodInfo(array $data): array
  1810. {
  1811. $result = Good::where('id', $data['id'])->first();
  1812. if (empty($result)) {
  1813. return Result::error("此产品不存在", 0);
  1814. }
  1815. return Result::success($result);
  1816. }
  1817. public function addGood(array $data): array
  1818. {
  1819. // unset($data['city_arr_id']);
  1820. // unset($data['cat_arr_id']);
  1821. $data['city_id'] = end($data['city_arr_id']);
  1822. $data['catid'] = end($data['cat_arr_id']);
  1823. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1824. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1825. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1826. unset($data['imgUrl']);
  1827. $result = Good::insert($data);
  1828. if (empty($result)) {
  1829. return Result::error("添加失败", 0);
  1830. }
  1831. return Result::success($result);
  1832. }
  1833. public function updateGood(array $data): array
  1834. {
  1835. $data['city_id'] = end($data['city_arr_id']);
  1836. $data['catid'] = end($data['cat_arr_id']);
  1837. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1838. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1839. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1840. //设置东八区
  1841. date_default_timezone_set('Asia/Shanghai');
  1842. $data['updated_at'] = date('Y-m-d H:i:s');
  1843. $result = Good::where('id', $data['id'])->update($data);
  1844. if (empty($result)) {
  1845. return Result::error("更新失败", 0);
  1846. }
  1847. return Result::success($result);
  1848. }
  1849. public function delGood(array $data): array
  1850. {
  1851. $result = Good::where('id', $data['id'])->delete();
  1852. if (empty($result)) {
  1853. return Result::error("删除失败", 0);
  1854. }
  1855. return Result::success($result);
  1856. }
  1857. //20250226 产品列表
  1858. //20250306 求职信息
  1859. public function getJobHuntingList(array $data): array
  1860. {
  1861. $where = [];
  1862. if (isset($data['username']) && !empty($data['username'])) {
  1863. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1864. }
  1865. //status 1待审核2已审核3已拒绝
  1866. if (isset($data['status']) && $data['status'] != '') {
  1867. $where = [
  1868. 'job_hunting.status' => $data['status'],
  1869. ];
  1870. }
  1871. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1872. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1873. unset($data['type_id']);
  1874. if ($type_id != '10000') {
  1875. $where[] = ['job_hunting.user_id', '=', $user_id];
  1876. }
  1877. $result = JobHunting::where($where)
  1878. ->when(!empty($data['status1']), function ($query) use ($data) {
  1879. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  1880. })
  1881. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1882. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1883. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1884. ->orderBy("id", "desc")
  1885. ->limit($data['page_size'])
  1886. ->offset(($data['page'] - 1) * $data['page_size'])
  1887. ->get();
  1888. if (empty($result)) {
  1889. return Result::error("查询失败", 0);
  1890. }
  1891. $count = JobHunting::where($where)
  1892. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1893. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1894. ->count();
  1895. $data = [
  1896. 'rows' => $result->toArray(),
  1897. 'count' => $count,
  1898. ];
  1899. return Result::success($data);
  1900. }
  1901. public function addJobHunting(array $data): array
  1902. {
  1903. date_default_timezone_set('Asia/Shanghai');
  1904. unset($data['company_name']);
  1905. unset($data['job_industry']);
  1906. unset($data['job_name']);
  1907. unset($data['department']);
  1908. unset($data['job_timeList']);
  1909. unset($data['job_content']);
  1910. $data['created_at'] = date('Y-m-d H:i:s');
  1911. $data['updated_at'] = date('Y-m-d H:i:s');
  1912. var_dump($data, '-----------------test---------');
  1913. $result = JobHunting::create($data);
  1914. if (empty($result)) {
  1915. return Result::error("添加失败", 0);
  1916. }
  1917. return Result::success($result);
  1918. }
  1919. public function delJobHunting(array $data): array
  1920. {
  1921. $result = JobHunting::where('id', $data['id'])->delete();
  1922. if (empty($result)) {
  1923. return Result::error("删除失败", 0);
  1924. }
  1925. return Result::success($result);
  1926. }
  1927. public function updateJobHunting(array $data): array
  1928. {
  1929. //设置东八区
  1930. date_default_timezone_set('Asia/Shanghai');
  1931. unset($data['company_name']);
  1932. unset($data['job_industry']);
  1933. unset($data['job_name']);
  1934. unset($data['department']);
  1935. unset($data['job_timeList']);
  1936. unset($data['job_content']);
  1937. $data['created_at'] = date('Y-m-d H:i:s');
  1938. $data['updated_at'] = date('Y-m-d H:i:s');
  1939. $result = JobHunting::where('id', $data['id'])->update($data);
  1940. if (empty($result)) {
  1941. return Result::error("更新失败", 0);
  1942. }
  1943. return Result::success($result);
  1944. }
  1945. public function getJobHuntingInfo(array $data): array
  1946. {
  1947. $result = JobHunting::where('id', $data['id'])->first();
  1948. if (empty($result)) {
  1949. return Result::error("查询失败", 0);
  1950. }
  1951. return Result::success($result);
  1952. }
  1953. public function getJobHuntingData(array $data): array
  1954. {
  1955. $jobEnum = JobEnum::get();
  1956. $jobIndustry = JobIndustry::get();
  1957. $jobNature = JobNature::get();
  1958. $jobPosition = JobPosition::get();
  1959. $data = [
  1960. 'jobEnum' => $jobEnum,
  1961. 'jobIndustry' => $jobIndustry,
  1962. 'jobNature' => $jobNature,
  1963. 'jobPosition' => $jobPosition,
  1964. ];
  1965. return Result::success($data);
  1966. }
  1967. public function delJobHuntingInfo(array $data): array
  1968. {
  1969. $result = JobHunting::where('id', $data['id'])->delete();
  1970. return Result::success();
  1971. }
  1972. //20250324 通知,公告,消息
  1973. public function delNotice(array $data): array
  1974. {
  1975. $result = Notice::where('id', $data['id'])->delete();
  1976. if ($result) {
  1977. return Result::success();
  1978. } else {
  1979. return Result::error("删除失败", 0);
  1980. }
  1981. }
  1982. public function getNoticeInfo(array $data): array
  1983. {
  1984. $result = Notice::where('id', $data['id'])->first();
  1985. if (empty($result)) {
  1986. return Result::error("查询失败", 0);
  1987. }
  1988. return Result::success($result);
  1989. }
  1990. public function addNotice(array $data): array
  1991. {
  1992. date_default_timezone_set('Asia/Shanghai');
  1993. $data['created_at'] = date('Y-m-d H:i:s');
  1994. $data['updated_at'] = date('Y-m-d H:i:s');
  1995. $user_id = UserInfo::
  1996. //city_id不是null
  1997. whereNotNull('city_id')
  1998. ->whereNotNull('department_id')
  1999. ->where(function ($query) use ($data) {
  2000. $query->where(function ($subQuery) use ($data) {
  2001. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2002. });
  2003. })
  2004. ->where(function ($query) use ($data) {
  2005. $query->where(function ($subQuery) use ($data) {
  2006. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  2007. });
  2008. })
  2009. ->pluck('user_id')->toArray();
  2010. $user_id = array_unique($user_id);
  2011. $chat_ids = $user_id;
  2012. $user_id = json_encode($user_id);
  2013. $data['re_user_ids'] = $user_id;
  2014. $result = Notice::insertGetId($data);
  2015. if ($result && $data['is_group'] == 1) {
  2016. //chat_group
  2017. $group_id = PublicData::uuid();
  2018. $groupData = [
  2019. 'id' => $group_id,
  2020. 'creator_id' => $data['user_id'],
  2021. 'group_name' => $data['group_name'] ?? '',
  2022. 'profile' => $data['profile'] ?? 0,
  2023. ];
  2024. $groupResult = ChatGroups::insertGetId($groupData);
  2025. var_dump($groupResult, '-----------------groupid-------');
  2026. $groupMemberData = [
  2027. 'id' => PublicData::uuid(),
  2028. 'user_id' => $data['user_id'],
  2029. 'group_id' => $group_id,
  2030. 'leader' => 2,
  2031. ];
  2032. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  2033. //$chat_ids 去除掉$data['user_id']
  2034. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  2035. //插入群成员表
  2036. $groupMemberDataUser = [];
  2037. foreach ($chat_ids as $key => $value) {
  2038. $groupMemberDataUser[] = [
  2039. 'id' => PublicData::uuid(),
  2040. 'user_id' => $value,
  2041. 'group_id' => $group_id,
  2042. 'leader' => 1,
  2043. ];
  2044. }
  2045. ChatGroupsMember::insert($groupMemberDataUser);
  2046. //更新result的 group_id
  2047. $data['group_id'] = $group_id;
  2048. Notice::where(['id' => $result])->update($data);
  2049. }
  2050. if (empty($result)) {
  2051. return Result::error("添加失败", 0);
  2052. }
  2053. return Result::success($result);
  2054. }
  2055. public function updateNotice(array $data): array
  2056. {
  2057. date_default_timezone_set('Asia/Shanghai');
  2058. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  2059. $user_id = UserInfo::
  2060. //city_id不是null
  2061. whereNotNull('city_id')
  2062. ->whereNotNull('department_id')
  2063. ->where(function ($query) use ($data) {
  2064. $query->where(function ($subQuery) use ($data) {
  2065. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2066. });
  2067. })
  2068. ->where(function ($query) use ($data) {
  2069. $query->where(function ($subQuery) use ($data) {
  2070. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  2071. });
  2072. })
  2073. ->pluck('user_id')->toArray();
  2074. $user_id = array_unique($user_id);
  2075. $user_id = json_encode($user_id);
  2076. $data['re_user_ids'] = $user_id;
  2077. $data['updated_at'] = date('Y-m-d H:i:s');
  2078. $result = Notice::where('id', $data['id'])->update($data);
  2079. return Result::success($result);
  2080. }
  2081. public function getNoticeList(array $data): array
  2082. {
  2083. $where = [];
  2084. //title
  2085. if (isset($data['title']) && !empty($data['title'])) {
  2086. $where[] = ['title', 'like', '%' . $data['title'] . '%'];
  2087. }
  2088. //level
  2089. if (isset($data['level']) && !empty($data['level'])) {
  2090. $where[] = ['level', '=', $data['level']];
  2091. }
  2092. //status
  2093. if (isset($data['status']) && !empty($data['status'])) {
  2094. $where[] = ['status', '=', $data['status']];
  2095. }
  2096. var_dump($data['type_id'], '-----------------test---------');
  2097. if ($data['type_id'] == 10000) {
  2098. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  2099. return $query->whereIn('status', [1, 3]); //1待审核2已审核3已拒绝
  2100. })
  2101. ->where($where)
  2102. ->orderBy('updated_at', 'desc')
  2103. ->limit($data['page_size'])
  2104. ->offset(($data['page'] - 1) * $data['page_size'])
  2105. ->get();
  2106. } else {
  2107. $result = Notice::where('status', 1)
  2108. ->where($where)
  2109. ->where('user_id', $data['user_id'])
  2110. ->orWhere(function ($query) use ($data) {
  2111. $query->where('re_user_ids', 'like', '%' . $data['user_id'] . '%');
  2112. })
  2113. ->orderBy('updated_at', 'desc')
  2114. ->limit($data['page_size'])
  2115. ->offset(($data['page'] - 1) * $data['page_size'])
  2116. ->get();
  2117. }
  2118. if (empty($result)) {
  2119. return Result::error("查询失败", 0);
  2120. }
  2121. $count = Notice::where('status', 1)->count();
  2122. $data = [
  2123. 'rows' => $result,
  2124. 'count' => $count,
  2125. ];
  2126. return Result::success($data);
  2127. }
  2128. public function getNoticeDetail(array $data): array
  2129. {
  2130. $result = Notice::where('id', $data['id'])->first();
  2131. if (empty($result)) {
  2132. return Result::error("查询失败", 0);
  2133. }
  2134. return Result::success($result);
  2135. }
  2136. public function deleteNotice(array $data): array
  2137. {
  2138. $notice = Notice::where('id', $data['id'])->first();
  2139. if (empty($notice)) {
  2140. return Result::error("删除失败", 0);
  2141. }
  2142. $chat_group_id = $notice->group_id;
  2143. if ($chat_group_id) {
  2144. //删除群聊
  2145. ChatGroups::where('id', $chat_group_id)->delete();
  2146. //删除群成员
  2147. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  2148. //删除群聊记录
  2149. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  2150. }
  2151. $result = Notice::where('id', $data['id'])->delete();
  2152. return Result::success($result);
  2153. }
  2154. public function getMSG(array $data): array
  2155. {
  2156. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  2157. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2158. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  2159. $result = [];
  2160. if ($type_id == 1) {
  2161. //最近的5篇已审的文章
  2162. $apply_articale = Article::where('status', 1)
  2163. ->where('admin_user_id', $user_id)
  2164. ->orderBy('updated_at', 'desc')
  2165. ->limit(5)->get();
  2166. //获取5条单聊未读聊天消息
  2167. $chat = ChatRecords::where('is_read', 0)
  2168. ->where('user_id', $user_id)
  2169. ->where('talk_type', 1)
  2170. ->orderBy('created_at', 'desc')
  2171. ->limit(5)->get();
  2172. //获取5条未读群聊信息
  2173. $chat_group = ChatRecords::where('is_read', 0)
  2174. ->where('user_id', $user_id)
  2175. ->where('talk_type', 2)
  2176. ->orderBy('created_at', 'desc')
  2177. ->limit(5)->get();
  2178. //获取5条用户的已审核商品
  2179. $good = Good::where('status', 2)
  2180. ->where('user_id', $user_id)
  2181. ->orderBy('updated_at', 'desc')
  2182. ->limit(5)->get();
  2183. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  2184. $result = [
  2185. 'apply_articale' => $apply_articale,
  2186. 'chat' => $chat,
  2187. 'chat_group' => $chat_group,
  2188. 'good' => $good,
  2189. 'count' => $count,
  2190. ];
  2191. } elseif ($type_id == 2) {
  2192. //最近的5篇已审的文章
  2193. $apply_articale = Article::where('status', 1)
  2194. ->where('admin_user_id', $user_id)
  2195. ->limit(5)->get();
  2196. //获取5条单聊未读聊天消息
  2197. $chat = ChatRecords::where('is_read', 0)
  2198. ->where('user_id', $user_id)
  2199. ->where('talk_type', 1)
  2200. ->orderBy('created_at', 'desc')
  2201. ->limit(5)->get();
  2202. //获取5条未读群聊信息
  2203. $chat_group = ChatRecords::where('is_read', 0)
  2204. ->where('user_id', $user_id)
  2205. ->where('talk_type', 2)
  2206. ->orderBy('created_at', 'desc')
  2207. ->limit(5)->get();
  2208. //获取5条用户的已审核商品
  2209. $good = Good::where('status', 2)
  2210. ->where('user_id', $user_id)
  2211. ->orderBy('updated_at', 'desc')
  2212. ->limit(5)->get();
  2213. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  2214. $result = [
  2215. 'apply_articale' => $apply_articale,
  2216. 'chat' => $chat,
  2217. 'chat_group' => $chat_group,
  2218. 'good' => $good,
  2219. 'count' => $count,
  2220. ];
  2221. } elseif ($type_id == 3) {
  2222. //最近的5篇已审的文章
  2223. $apply_articale = Article::where('status', 1)
  2224. ->where('admin_user_id', $user_id)
  2225. ->limit(5)->get();
  2226. //获取5条单聊未读聊天消息
  2227. $chat = ChatRecords::where('is_read', 0)
  2228. ->where('user_id', $user_id)
  2229. ->where('talk_type', 1)
  2230. ->orderBy('created_at', 'desc')
  2231. ->limit(5)->get();
  2232. //获取5条未读群聊信息
  2233. $chat_group = ChatRecords::where('is_read', 0)
  2234. ->where('user_id', $user_id)
  2235. ->where('talk_type', 2)
  2236. ->orderBy('created_at', 'desc')
  2237. ->limit(5)->get();
  2238. //获取5条用户的已审核商品
  2239. $good = Good::where('status', 2)
  2240. ->where('user_id', $user_id)
  2241. ->orderBy('updated_at', 'desc')
  2242. ->limit(5)->get();
  2243. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  2244. $result = [
  2245. 'apply_articale' => $apply_articale,
  2246. 'chat' => $chat,
  2247. 'chat_group' => $chat_group,
  2248. 'good' => $good,
  2249. 'count' => $count,
  2250. ];
  2251. } elseif ($type_id == 4) {
  2252. //最近的5篇已审的文章
  2253. $apply_articale = Article::where('status', 1)
  2254. ->where('admin_user_id', $user_id)
  2255. ->limit(5)->get();
  2256. //获取5条用户的已审核商品
  2257. $good = Good::where('status', 2)
  2258. ->where('user_id', $user_id)
  2259. ->orderBy('updated_at', 'desc')
  2260. ->limit(5)->get();
  2261. $count = count($apply_articale) + count($good);
  2262. $result = [
  2263. 'apply_articale' => $apply_articale,
  2264. 'chat' => '',
  2265. 'chat_group' => '',
  2266. 'good' => $good,
  2267. 'count' => $count,
  2268. ];
  2269. } elseif ($type_id == 10000) {
  2270. //获取未审核的5篇文章
  2271. $apply_articale = Article::where('status', 0)
  2272. ->orderBy('updated_at', 'desc')
  2273. ->limit(5)->get();
  2274. //获取5条单聊未读聊天消息
  2275. $chat = ChatRecords::where('is_read', 0)
  2276. ->where('user_id', $user_id)
  2277. ->where('talk_type', 1)
  2278. ->orderBy('created_at', 'desc')
  2279. ->limit(5)->get();
  2280. //获取5条未读群聊信息
  2281. $chat_group = ChatRecords::where('is_read', 0)
  2282. ->where('user_id', $user_id)
  2283. ->where('talk_type', 2)
  2284. ->orderBy('created_at', 'desc')
  2285. ->limit(5)->get();
  2286. //获取5条用户的已审核商品
  2287. $good = Good::where('status', 1)
  2288. // ->where('user_id', $user_id)
  2289. ->orderBy('updated_at', 'desc')
  2290. ->limit(5)->get();
  2291. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  2292. $result = [
  2293. 'apply_articale' => $apply_articale,
  2294. 'chat' => $chat,
  2295. 'chat_group' => $chat_group,
  2296. 'good' => $good,
  2297. 'count' => $count,
  2298. ];
  2299. } elseif ($type_id == 20000) {
  2300. }
  2301. var_dump($type_id, '-----------------test---------');
  2302. return Result::success($result);
  2303. }
  2304. public function getComplaintList(array $data): array
  2305. {
  2306. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  2307. unset($data['type_id']);
  2308. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  2309. $where = [];
  2310. if ($type_id != 10000) {
  2311. $where['user_id'] = $user_id;
  2312. }
  2313. if (!empty($data['title'])) {
  2314. $where['title'] = ['like', '%' . $data['title'] . '%'];
  2315. }
  2316. if (!empty($data['deal'])) {
  2317. $where['deal'] = ['=', $data['deal']];
  2318. }
  2319. if (!empty($data['status'])) {
  2320. $where['status'] = ['=', $data['status']];
  2321. }
  2322. $result = Complaint::where($where)
  2323. ->when(!empty($data['sattus1']), function ($query) use ($data) {
  2324. $query->whereIn('status', [1, 3]); //1待审核2已审核3已拒绝
  2325. })
  2326. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  2327. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  2328. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  2329. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  2330. ->orderBy('updated_at', 'desc')
  2331. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  2332. if (empty($result)) {
  2333. return Result::error("暂无投诉信息", 0);
  2334. }
  2335. // 取出数据
  2336. $rows = $result->items();
  2337. $count = $result->total();
  2338. $responseData = [
  2339. 'rows' => $rows,
  2340. 'count' => $count,
  2341. ];
  2342. return Result::success($responseData);
  2343. }
  2344. public function getComplaintInfo(array $data): array
  2345. {
  2346. $result = Complaint::where('id', $data['id'])->first();
  2347. if (empty($result)) {
  2348. return Result::error("查询失败", 0);
  2349. }
  2350. return Result::success($result);
  2351. }
  2352. public function addComplaint(array $data): array
  2353. {
  2354. date_default_timezone_set('Asia/Shanghai');
  2355. $data['created_at'] = date('Y-m-d H:i:s');
  2356. $data['updated_at'] = date('Y-m-d H:i:s');
  2357. $result = Complaint::create($data);
  2358. return Result::success($result);
  2359. }
  2360. public function updateComplaint(array $data): array
  2361. {
  2362. date_default_timezone_set('Asia/Shanghai');
  2363. $data['updated_at'] = date('Y-m-d H:i:s');
  2364. $result = Complaint::where('id', $data['id'])->update($data);
  2365. return Result::success($result);
  2366. }
  2367. public function deleteComplaint(array $data): array
  2368. {
  2369. $result = Complaint::where('id', $data['id'])->delete();
  2370. return Result::success($result);
  2371. }
  2372. public function getComplainInfo(array $data): array
  2373. {
  2374. $result = Complaint::where('id', $data['id'])->first();
  2375. if (empty($result)) {
  2376. return Result::error("查询失败", 0);
  2377. }
  2378. return Result::success($result);
  2379. }
  2380. public function updateComplaintStatus(array $data): array
  2381. {
  2382. $result = complaint::where('id', $data['id'])->update($data);
  2383. return Result::success($result);
  2384. }
  2385. public function updateGoodStatus(array $data): array
  2386. {
  2387. $result = Good::where('id', $data['id'])->update($data);
  2388. return Result::success($result);
  2389. }
  2390. public function updateJobHuntingStatus(array $data): array
  2391. {
  2392. $result = JobHunting::where('id', $data['id'])->update($data);
  2393. return Result::success($result);
  2394. }
  2395. public function updateNoticeStatus(array $data): array
  2396. {
  2397. $result = Notice::where('id', $data['id'])->update($data);
  2398. return Result::success($result);
  2399. }
  2400. //20250324 通知,公告,消息
  2401. // 20250306 -------招聘--------fr
  2402. /*
  2403. * 招聘列表
  2404. * */
  2405. public function getJobRecruitingList(array $data): array
  2406. {
  2407. $where = [];
  2408. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  2409. if($data['checkout'] == 0){
  2410. $job_status = [0, 2];
  2411. }else{
  2412. $job_status = [1];
  2413. }
  2414. if(isset($data['keyword']) && !empty($data['keyword'])){
  2415. array_push($where, ['job_recruiting.title', 'like', '%'. $data['keyword']. '%']);
  2416. }
  2417. $user = User::where('id', $data['user_id'])->first();
  2418. if (empty($user)) {
  2419. return Result::error("用户不存在", 0);
  2420. }
  2421. // 3:企业会员
  2422. if ($user['type_id'] == 3) {
  2423. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  2424. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  2425. }
  2426. // 如果 $where 为空,则不添加 where 条件
  2427. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2428. return $query->where($where);
  2429. })
  2430. ->whereIn('job_recruiting.status',$job_status)
  2431. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  2432. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  2433. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  2434. ->orderBy("updated_at", "desc")
  2435. ->offset(($data['page'] - 1) * $data['page_size'])
  2436. ->limit($data['page_size'])
  2437. ->get()
  2438. ->all();
  2439. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2440. return $query->where($where);
  2441. })
  2442. ->whereIn('job_recruiting.status',$job_status)
  2443. ->count();
  2444. if (empty($result)) {
  2445. return Result::error("暂无招聘信息", 0);
  2446. }
  2447. return Result::success($result);
  2448. }
  2449. /*
  2450. * 招聘信息添加
  2451. * */
  2452. public function addJobRecruiting(array $data): array
  2453. {
  2454. // return Result::success($data);
  2455. $user = User::where('user.id', $data['user_id'])
  2456. ->where('user.status', 1)
  2457. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2458. ->select(
  2459. 'user.type_id',
  2460. 'user.mobile',
  2461. 'user.email',
  2462. 'user_info.business_name',
  2463. 'user_info.company_hy_id',
  2464. 'user_info.company_nature',
  2465. 'user_info.company_size',
  2466. 'user_info.introduction',
  2467. 'user_info.real_name',
  2468. 'user_info.company_url',
  2469. 'user_info.address_arr_id',
  2470. 'user_info.address'
  2471. )
  2472. ->first();
  2473. if (empty($user) || $user['type_id'] != $data['user_type']) {
  2474. return Result::error("用户不存在", 0);
  2475. }
  2476. $web = Website::where('id', $data['website_id'])->first();
  2477. if (empty($web)) {
  2478. return Result::error("网站不存在", 0);
  2479. }
  2480. // return Result::success($user);
  2481. $data['action_id'] = $data['user_id'];
  2482. $data['user_type'] = $user['type_id'];
  2483. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  2484. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  2485. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  2486. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  2487. // 公司地址 管理员必填
  2488. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  2489. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2490. // 管理员-企业相关信息
  2491. $company = [
  2492. // 'user_id' => $data['user_id']?? null,
  2493. 'business_name' => $data['business_name'] ?? null,
  2494. 'company_hy_id' => $data['company_hy_id'] ?? null,
  2495. 'company_size' => $data['company_size'] ?? null,
  2496. 'company_nature' => $data['company_nature'] ?? null,
  2497. 'introduction' => $data['introduction'] ?? null,
  2498. 'real_name' => $data['real_name'] ?? null,
  2499. 'mobile' => $data['mobile'] ?? null,
  2500. 'company_url' => $data['company_url'] ?? null,
  2501. 'address_arr_id' => $data['address_arr_id'] ?? null,
  2502. 'address' => $data['address'] ?? null,
  2503. 'email' => $data['email'] ?? null,
  2504. ];
  2505. //去掉相关企业信息
  2506. $job = array_diff_key($data, array_flip(array_keys($company)));
  2507. Db::beginTransaction();
  2508. try {
  2509. // 先添加职位相关信息
  2510. if($user['type_id'] == 10000){
  2511. $job['status'] = 1;
  2512. }
  2513. $jobId = JobRecruiting::insertGetId($job);
  2514. if (empty($jobId)) {
  2515. Db::rollBack();
  2516. return Result::error("添加失败");
  2517. }
  2518. // 添加公司信息
  2519. $company['user_id'] = $data['user_id'] ?? null;
  2520. $company['job_id'] = $jobId;
  2521. $company['user_type'] = $user['type_id'] ?? null;
  2522. $company['website_id'] = $data['website_id'] ?? null;
  2523. if ($user['type_id'] == 10000) {
  2524. // 管理员添加企业信息
  2525. // return Result::success($company);
  2526. $companyId = JobCompany::insertGetId($company);
  2527. if (empty($companyId)) {
  2528. Db::rollBack();
  2529. return Result::error("添加失败");
  2530. }
  2531. } else {
  2532. // 企业会员添加企业信息
  2533. $company = [
  2534. 'user_id' => $data['user_id'] ?? null,
  2535. 'business_name' => $user['business_name'] ?? null,
  2536. 'company_hy_id' => $user['company_hy_id'] ?? null,
  2537. 'company_size' => $user['company_size'] ?? null,
  2538. 'company_nature' => $user['company_nature'] ?? null,
  2539. 'introduction' => $user['introduction'] ?? null,
  2540. 'real_name' => $user['real_name'] ?? null,
  2541. 'mobile' => $user['mobile'] ?? null,
  2542. 'company_url' => $user['company_url'] ?? null,
  2543. 'address_arr_id' => $user['address_arr_id'] ?? null,
  2544. 'address' => $user['address'] ?? null,
  2545. 'email' => $user['email'] ?? null,
  2546. 'website_id' => $data['website_id'] ?? null,
  2547. 'user_type' => $user['type_id'] ?? null,
  2548. 'job_id' => $jobId,
  2549. ];
  2550. $companyId = JobCompany::insertGetId($company);
  2551. if (empty($companyId)) {
  2552. Db::rollBack();
  2553. return Result::error("添加失败");
  2554. }
  2555. // return Result::success($company);
  2556. }
  2557. Db::commit();
  2558. } catch (\Exception $e) {
  2559. Db::rollBack();
  2560. return Result::error($e->getMessage(), 0);
  2561. }
  2562. $result = [
  2563. 'job_id' => $jobId,
  2564. 'company_id' => $companyId,
  2565. ];
  2566. if (empty($result)) {
  2567. return Result::error("添加失败", 0);
  2568. }
  2569. return Result::success($result);
  2570. }
  2571. /*
  2572. * 获取招聘信息详情
  2573. * */
  2574. public function getJobRecruitingInfo(array $data): array
  2575. {
  2576. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  2577. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  2578. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2579. ->select(
  2580. 'job_recruiting.*',
  2581. 'website.website_name as website_name',
  2582. 'job_company.business_name',
  2583. 'job_company.company_hy_id',
  2584. 'job_company.company_size',
  2585. 'job_company.company_nature',
  2586. 'job_company.introduction',
  2587. 'job_company.real_name',
  2588. 'job_company.mobile',
  2589. 'job_company.company_url',
  2590. 'job_company.address_arr_id',
  2591. 'job_company.address',
  2592. 'job_company.email'
  2593. )
  2594. ->first();
  2595. if (empty($result)) {
  2596. return Result::error("招聘信息不存在", 0);
  2597. }
  2598. // return Result::success($job);
  2599. return Result::success($result);
  2600. }
  2601. /*
  2602. * 修改招聘信息
  2603. * */
  2604. public function upJobRecruiting(array $data): array
  2605. {
  2606. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  2607. // return Result::success($job);
  2608. if (empty($job)) {
  2609. return Result::error("招聘信息不存在", 0);
  2610. }
  2611. $user = User::where('id', $data['user_id'])->first();
  2612. // return Result::success($user);
  2613. if (empty($user) || $user['type_id'] != $data['user_type']) {
  2614. return Result::error("用户不存在", 0);
  2615. }
  2616. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  2617. return Result::error("用户暂无权限修改此招聘信息!", 0);
  2618. }
  2619. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  2620. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  2621. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  2622. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  2623. // 公司地址 管理员必填
  2624. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  2625. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2626. // 管理员-企业相关信息
  2627. $company = [
  2628. 'business_name' => $data['business_name'] ?? null,
  2629. 'company_hy_id' => $data['hy_id'] ?? null,
  2630. 'company_size' => $data['company_size'] ?? null,
  2631. 'company_nature' => $data['company_nature'] ?? null,
  2632. 'introduction' => $data['introduction'] ?? null,
  2633. 'real_name' => $data['real_name'] ?? null,
  2634. 'mobile' => $data['mobile'] ?? null,
  2635. 'company_url' => $data['company_url'] ?? null,
  2636. 'address_arr_id' => $data['address_arr_id'] ?? null,
  2637. 'address' => $data['address'] ?? null,
  2638. 'email' => $data['email'] ?? null,
  2639. ];
  2640. //去掉相关企业信息
  2641. $data = array_diff_key($data, array_flip(array_keys($company)));
  2642. $jobId = $data['id'];
  2643. $web = $data['website_id'];
  2644. $data['action_id'] = $data['user_id'];
  2645. unset($data['user_id']);
  2646. unset($data['user_type']);
  2647. unset($data['id']);
  2648. unset($data['website_id']);
  2649. // return Result::success($data);
  2650. Db::beginTransaction();
  2651. try {
  2652. // 管理员修改招聘信息
  2653. if ($user['type_id'] == 10000) {
  2654. $data['website_id'] = $web;
  2655. $company['website_id'] = $data['website_id'];
  2656. $data['status'] = 1;
  2657. }else{
  2658. $data['status'] = 0;
  2659. }
  2660. // Db::rollBack();
  2661. // return Result::success($company);
  2662. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  2663. if (empty($result['job'])) {
  2664. Db::rollBack();
  2665. return Result::error("修改招聘信息失败");
  2666. }
  2667. // 管理员修改企业相关信息
  2668. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  2669. if (empty($result['company'])) {
  2670. Db::rollBack();
  2671. return Result::error("修改企业相关信息失败");
  2672. }
  2673. Db::commit();
  2674. // return Result::success($result);
  2675. } catch (\Exception $e) {
  2676. Db::rollBack();
  2677. return Result::error($e->getMessage(), 0);
  2678. }
  2679. return Result::success($result);
  2680. }
  2681. /*
  2682. * 招聘信息删除
  2683. * */
  2684. public function delJobRecruiting(array $data): array
  2685. {
  2686. $user = User::where('id', $data['user_id'])->first();
  2687. if (empty($user)) {
  2688. return Result::error("用户不存在", 0);
  2689. }
  2690. $job = JobRecruiting::where('id', $data['id'])->first();
  2691. if (empty($job)) {
  2692. return Result::error("招聘信息不存在", 0);
  2693. }
  2694. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  2695. return Result::error("用户暂无权限修改此招聘信息!", 0);
  2696. }
  2697. Db::beginTransaction();
  2698. try {
  2699. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  2700. if (empty($result['job'])) {
  2701. Db::rollBack();
  2702. return Result::error("删除招聘信息失败");
  2703. }
  2704. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  2705. if (empty($result['company'])) {
  2706. Db::rollBack();
  2707. return Result::error("删除企业相关信息失败");
  2708. }
  2709. Db::commit();
  2710. } catch (\Exception $e) {
  2711. Db::rollBack();
  2712. return Result::error($e->getMessage(), 0);
  2713. }
  2714. return Result::success($result);
  2715. }
  2716. /*
  2717. * 获取公司信息
  2718. * */
  2719. public function getJobCompany(array $data): array
  2720. {
  2721. $user = User::where('user.id', $data['user_id'])
  2722. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2723. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  2724. ->first();
  2725. // return Result::success($user);
  2726. if (empty($user)) {
  2727. return Result::error("用户不存在", 0);
  2728. }
  2729. if ($user['type_id'] == 3) {
  2730. $result = [
  2731. // 'id' => 0,
  2732. 'user_id' => $data['user_id'],
  2733. 'website_id' => $data['website_id'],
  2734. 'business_name' => $user['business_name'], // 企业名称
  2735. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  2736. 'company_nature' => $user['company_nature'], // 公司性质
  2737. 'company_size' => $user['company_size'], // 公司规模
  2738. 'introduction' => $user['introduction'], // 公司简介
  2739. 'real_name' => $user['real_name'], // 企业联系人
  2740. 'mobile' => $user['mobile'], // 企业联系电话
  2741. 'company_url' => $user['company_url'], // 企业网址
  2742. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  2743. 'address' => $user['address'], // 企业地址
  2744. 'email' => $user['email'], // 企业邮箱
  2745. ];
  2746. } else {
  2747. return Result::error("用户类型错误", 0);
  2748. }
  2749. if (empty($result)) {
  2750. return Result::error("公司信息不存在", 0);
  2751. }
  2752. return Result::success($result);
  2753. }
  2754. /*
  2755. * 修改公司信息
  2756. * */
  2757. public function upJobCompany(array $data): array
  2758. {
  2759. // return Result::success($data);
  2760. $user = User::where('user.id', $data['user_id'])
  2761. ->where('user.status', 1)
  2762. ->select('user.user_name', 'user.type_id')
  2763. ->first();
  2764. if (empty($user)) {
  2765. return Result::error("用户不存在", 0);
  2766. }
  2767. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2768. $company = [
  2769. 'business_name' => $data['business_name'], // 企业名称
  2770. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  2771. 'company_nature' => $data['company_nature'], // 公司性质
  2772. 'company_size' => $data['company_size'], // 公司规模
  2773. 'introduction' => $data['introduction'], // 公司简介
  2774. // 'real_name' => $data['real_name'], // 企业联系人
  2775. 'company_url' => $data['company_url'], // 企业网址
  2776. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  2777. 'address' => $data['address'], // 企业详细地址
  2778. ];
  2779. if ($user['type_id'] == 3) {
  2780. Db::beginTransaction();
  2781. try {
  2782. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  2783. 'business_name' => $data['business_name'], // 企业名称
  2784. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  2785. 'company_nature' => $data['company_nature'], // 公司性质
  2786. 'company_size' => $data['company_size'], // 公司规模
  2787. 'introduction' => $data['introduction'], // 公司简介
  2788. // 'real_name' => $data['real_name'], // 企业联系人
  2789. 'company_url' => $data['company_url'], // 企业网址
  2790. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  2791. 'address' => $data['address'], // 企业详细地址
  2792. ]);
  2793. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  2794. Db::commit();
  2795. } catch (\Exception $e) {
  2796. Db::rollBack();
  2797. return Result::error($e->getMessage(), 0);
  2798. }
  2799. } else {
  2800. return Result::error("用户类型错误", 0);
  2801. }
  2802. if (empty($result)) {
  2803. return Result::error("修改失败", 0);
  2804. }
  2805. return Result::success($result);
  2806. }
  2807. /*
  2808. * 获取省-市
  2809. * */
  2810. public function getJobRecruitingArea(array $data): array
  2811. {
  2812. if (isset($data['province_id']) && $data['province_id'] != null) {
  2813. $result = District::where('pid', $data['pid'])->get()->all();
  2814. } else {
  2815. $result = District::where('level', 1)->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 getIndustry(array $data): array
  2826. {
  2827. $result = JobIndustry::get()->all();
  2828. if (empty($result)) {
  2829. return Result::error("暂无行业分类", 0);
  2830. }
  2831. return Result::success($result);
  2832. }
  2833. /*
  2834. * 获取职位
  2835. * */
  2836. public function getPositionList(array $data): array
  2837. {
  2838. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  2839. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  2840. } else {
  2841. $result = JobPosition::where('zwpid', 0)->get()->all();
  2842. }
  2843. if (empty($result)) {
  2844. return Result::error("暂无此职位", 0);
  2845. }
  2846. return Result::success($result);
  2847. }
  2848. /*
  2849. * 获取工作性质-菜单
  2850. * */
  2851. public function getJobNature(array $data): array
  2852. {
  2853. $result = JobEnum::where('egroup', 'nature')->get()->all();
  2854. if (empty($result)) {
  2855. return Result::error("暂无工作性质", 0);
  2856. }
  2857. return Result::success($result);
  2858. }
  2859. /*
  2860. * 获取工作经验-菜单
  2861. * */
  2862. public function getExperience(array $data): array
  2863. {
  2864. $result = JobEnum::where('egroup', 'years')->get()->all();
  2865. if (empty($result)) {
  2866. return Result::error("暂无工作经验", 0);
  2867. }
  2868. return Result::success($result);
  2869. }
  2870. /*
  2871. * 获取学历-菜单
  2872. * */
  2873. public function getEducation(array $data): array
  2874. {
  2875. $result = JobEnum::where('egroup', 'education')->get()->all();
  2876. if (empty($result)) {
  2877. return Result::error("暂无学历", 0);
  2878. }
  2879. return Result::success($result);
  2880. }
  2881. /*
  2882. * 获取薪资-菜单
  2883. * */
  2884. public function getSalary(array $data): array
  2885. {
  2886. $result = JobEnum::where('egroup', 'income')->get()->all();
  2887. if (empty($result)) {
  2888. return Result::error("暂无薪资", 0);
  2889. }
  2890. return Result::success($result);
  2891. }
  2892. /*
  2893. * 获取语言-菜单
  2894. * */
  2895. public function getLanguage(array $data): array
  2896. {
  2897. $result = JobEnum::where('egroup', 'language')->get()->all();
  2898. if (empty($result)) {
  2899. return Result::error("暂无语言", 0);
  2900. }
  2901. return Result::success($result);
  2902. }
  2903. /*
  2904. * 获取掌握程度-菜单
  2905. * */
  2906. public function getLevel(array $data): array
  2907. {
  2908. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  2909. if (empty($result)) {
  2910. return Result::error("暂无工作性质", 0);
  2911. }
  2912. return Result::success($result);
  2913. }
  2914. // 公司信息
  2915. /*
  2916. * 获取公司性质-菜单
  2917. * */
  2918. public function getCompanyNature(array $data): array
  2919. {
  2920. $result = JobNature::get()->all();
  2921. if (empty($result)) {
  2922. return Result::error("暂无公司性质", 0);
  2923. }
  2924. return Result::success($result);
  2925. }
  2926. /*
  2927. * 获取公司规模-菜单
  2928. * */
  2929. public function getCompanySize(array $data): array
  2930. {
  2931. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  2932. if (empty($result)) {
  2933. return Result::error("暂无公司规模", 0);
  2934. }
  2935. return Result::success($result);
  2936. }
  2937. /*
  2938. * 招聘信息审核
  2939. * */
  2940. public function checkJobRecruiting(array $data): array
  2941. {
  2942. $user = User::where('id', $data['user_id'])->first();
  2943. if(empty($user)){
  2944. return Result::error("用户不存在", 0);
  2945. }
  2946. $job = JobRecruiting::where('id', $data['id'])->first();
  2947. if(empty($job)){
  2948. return Result::error("招聘信息不存在", 0);
  2949. }
  2950. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已驳回;
  2951. if($user['type_id']== 3 && ($data['status'] == 1 || $data['status'] == 2)){
  2952. return Result::error("用户暂无权限审核此招聘信息!", 0);
  2953. }
  2954. // 驳回原因
  2955. if($data['status'] == 2){
  2956. $data['refuse_reason'] = $data['refuse_reason']?? null;
  2957. }
  2958. $result = JobRecruiting::where('id', $data['id'])->update($data);
  2959. if(empty($result)){
  2960. return Result::error("审核失败", 0);
  2961. }
  2962. return Result::success($result);
  2963. }
  2964. // 20250306 招聘
  2965. }