NewsService.php 150 KB

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