NewsService.php 143 KB

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