NewsService.php 136 KB

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