NewsService.php 149 KB

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