WebService.php 155 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\Ad;
  5. use App\Model\Category;
  6. use App\Model\AdPlace;
  7. use App\Model\Department;
  8. use App\Model\District;
  9. use App\Model\FooterCategory;
  10. use App\Model\FooterContent;
  11. use App\Model\WebsiteTemplateInfo;
  12. use App\Model\Link;
  13. use App\Model\LetterOfComplaint;
  14. use App\Model\User;
  15. use App\Model\UserInfo;
  16. use App\Model\WebsiteRole;
  17. use App\Model\WebsiteRoleUser;
  18. use App\Model\Website;
  19. use App\Model\WebsiteColumn;
  20. use App\Model\Good;
  21. use App\Model\Book;
  22. use App\Model\ChatRecords;
  23. use App\Model\ChatTopic;
  24. use App\Model\JobRecruiting;
  25. use App\Model\JobHunting;
  26. use App\Model\Notice;
  27. use App\Model\Complaint;
  28. use App\Model\Order;
  29. use App\Model\WebsiteImg;
  30. use App\Model\Company;
  31. use App\Model\Project;
  32. use App\Model\ChatTopicsReply;
  33. use App\Model\ArticleSurvey;
  34. use App\Model\JobIndustry;
  35. use App\Model\JobPosition;
  36. use App\Model\JobEnum;
  37. use App\Model\JobRemuse;
  38. use App\Model\JobCompany;
  39. use App\Model\JobNature;
  40. use App\Model\JobApply;
  41. use Hyperf\HttpServer\Contract\RequestInterface;
  42. use Hyperf\DbConnection\Db;
  43. use Hyperf\RpcServer\Annotation\RpcService;
  44. use App\Tools\Result;
  45. use Carbon\Carbon;
  46. use App\Model\WebsiteCategory;
  47. use App\Model\WebsiteGroup;
  48. use App\Model\WebsiteTemplate;
  49. use App\Model\Sector;
  50. use PhpParser\Node\Stmt\Return_;
  51. use SimpleKafkaClient\Metadata\Topic;
  52. use function PHPUnit\Framework\isNull;
  53. use Overtrue\Pinyin\Pinyin;
  54. use App\Tools\buildTree;
  55. use App\Model\WhiteRouter;
  56. use App\Model\Size;
  57. use App\Tools\PinyinHelper;
  58. use Hyperf\HttpServer\Annotation\AutoController;
  59. use Hyperf\Utils\Parallel;
  60. use Hyperf\Coroutine\Concurrent;
  61. use function Hyperf\Coroutine\batch;
  62. use Swoole\Coroutine;
  63. use App\Model\Message;
  64. use App\Model\ResearchTopic;
  65. use App\Model\RetopicUser;
  66. use App\Model\SinglePage;
  67. #[RpcService(name: "WebService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  68. class WebService implements WebServiceInterface
  69. {
  70. /**
  71. * 获取栏目
  72. * @param array $data
  73. * @return array
  74. */
  75. public function getWebsiteModelCategory(array $data): array
  76. {
  77. // return Result::success($data);
  78. $website_id = [
  79. 'website_id' => $data['website_id'],
  80. ];
  81. $website_column_arr = Website::where('id', $data['website_id'])->value('website_column_arr_id');
  82. if (empty($website_column_arr)) {
  83. return Result::error("未查询到此网站所属网系!", 0);
  84. }
  85. $website_column_arr = json_decode($website_column_arr, true);
  86. // return Result::success(!in_array(3,$website_column_arr) && $data['pid'] == 0);
  87. // 初始化 $pid 数组
  88. // $pid = [];
  89. // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
  90. $pidQuery = WebsiteCategory::where($website_id)
  91. ->where('pid', '!=', 0)
  92. ->where('type','!=',8)
  93. ->orderBy('sort')
  94. ->select('pid', 'category_id', 'alias', 'aLIas_pinyin');
  95. $pid = $pidQuery->pluck('pid');
  96. $pid = array_values(array_unique($pid->toArray()));
  97. // 构建查询语句
  98. $query = WebsiteCategory::where($website_id)
  99. ->when(!in_array(3, $website_column_arr) && $data['pid'] == 0, function ($query) use ($website_column_arr) {
  100. $query->where('is_show', 1);
  101. })
  102. ->when(in_array(3, $website_column_arr) || $data['pid'] != 0, function ($query) use ($data) {
  103. $query->where('pid', $data['pid']);
  104. })
  105. ->where('type','!=',8)
  106. ->offset($data['placeid'])
  107. ->limit($data['num'])
  108. ->orderBy('sort')
  109. ->orderBy('updated_at', 'desc');
  110. // 如果 $pid 数组不为空,添加 CASE WHEN 条件
  111. if (!empty($pid)) {
  112. $placeholders = implode(',', array_fill(0, count($pid), '?'));
  113. $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
  114. } else {
  115. // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
  116. $query->select('website_category.*', DB::raw('0 as children_count'));
  117. }
  118. // 执行查询
  119. $placeid = $data['placeid'] - 1;
  120. $result = $query->offset($placeid)->limit($data['num'])->get();
  121. if (!empty($result)) {
  122. $pidResults = $pidQuery->get();
  123. if (isset($data['type']) && $data['type'] == 1) {
  124. $result = $result->map(function ($item) use ($pidResults) {
  125. $children = $pidResults->where('pid', $item->category_id)->map(function ($child) {
  126. if (!empty($child)) {
  127. return $child;
  128. }
  129. });
  130. // 重置索引,使 key 值从 0 开始
  131. $item->children = $children->values();
  132. return $item;
  133. });
  134. } else {
  135. $pidMap = $pidResults->keyBy('pid');
  136. $result->each(function ($record) use ($pidMap, $data) {
  137. if ($data['pid'] == 0) {
  138. $record->aLIas_pinyin = $record->path;
  139. }
  140. // $record->aLIas_pinyin = $record->path;
  141. if ($pidMap->has($record->category_id)) {
  142. $pidResult = $pidMap->get($record->category_id);
  143. $record->chilid_id = $pidResult->category_id;
  144. $record->chilid_alias = $pidResult->alias;
  145. // $record->aLIas_pinyin = $pidResult->aLIas_pinyin;
  146. }
  147. });
  148. }
  149. return Result::success($result);
  150. } else {
  151. return Result::error("本网站暂无栏目", 0);
  152. }
  153. }
  154. /**
  155. * 获取网站栏目seo
  156. * @param array $data
  157. * @return array
  158. */
  159. public function getWebsiteCategoryHead(array $data): array
  160. {
  161. if (isset($data['website_id']) && !empty($data['website_id'])) {
  162. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  163. if (empty($website)) {
  164. return Result::error("找不到网站", 0);
  165. }
  166. } else {
  167. return Result::error("参数错误", 0);
  168. }
  169. if (isset($data['catid']) && !empty($data['catid'])) {
  170. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
  171. }
  172. if (empty($result)) {
  173. return Result::error("暂无导航", 0);
  174. }
  175. $result['aLIas_pinyin'] = $result['path'] ?? '';
  176. $result['website_name'] = $website['website_name'] ?? '';
  177. $result['suffix'] = $website['suffix'] ?? '';
  178. return Result::success($result);
  179. }
  180. /*
  181. * 获取某个栏目
  182. * @param array $data
  183. * @return array
  184. * */
  185. public function getOneWebsiteCategory(array $data): array
  186. {
  187. if (isset($data['website_id']) && !empty($data['website_id'])) {
  188. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  189. if (empty($website)) {
  190. return Result::error("暂无该网站", 0);
  191. }
  192. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->first();
  193. if (empty($category)) {
  194. return Result::error("暂无此导航", 0);
  195. }
  196. $category['children_count'] = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['category_id'])->count();
  197. $parent = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->select('category_id as parent_id', 'alias as parent_name', 'aLIas_pinyin')->first();
  198. // return Result::success($parent);
  199. // $category['aLIas_pinyin'] = $category['path'] ?? '';
  200. $category['parent_id'] = $parent['parent_id'] ?? '';
  201. $category['parent_pinyin'] = $parent['aLIas_pinyin'] ?? '';
  202. $category['parent_name'] = $parent['parent_name'] ?? '';
  203. return Result::success($category);
  204. } else {
  205. return Result::error("参数错误", 0);
  206. }
  207. }
  208. /**
  209. * 路由匹配
  210. * @param array $data
  211. */
  212. public function getWebsiteRoute(array $data): array
  213. {
  214. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  215. if (empty($website)) {
  216. return Result::error("暂无该网站", 0);
  217. }
  218. if (isset($data['pinyin']) &&!empty($data['pinyin'])) {
  219. $result = WebsiteCategory::where('website_id',$data['website_id'])
  220. ->where('path',$data['pinyin'])
  221. // $result = WebsiteCategory::where('category_id', $category_id)
  222. // ->where('website_category.path', $data['pinyin'])
  223. // ->leftJoin('website_category as pc', function ($join) use ($data) {
  224. // $join->on('pc.pid', '=', 'website_category.category_id')
  225. // ->where('pc.website_id', '=', $data['website_id']);
  226. // })
  227. ->select('website_category.category_id', 'website_category.type', 'website_category.alias',)
  228. ->first();
  229. }
  230. if (isset($data['foot_pinyin']) && !empty($data['foot_pinyin'])) {
  231. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('type',8)->where('path', $data['foot_pinyin'])->first(['id']);
  232. }
  233. if (!isset($result) || empty($result)) {
  234. return Result::error("暂无该导航", 0);
  235. }
  236. return Result::success($result);
  237. }
  238. /**
  239. * c端 - 验证路由
  240. * @param array $data
  241. * @return array
  242. */
  243. public function checkWebsiteRoute(array $data): array
  244. {
  245. // 测试001111111222
  246. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  247. if (empty($web)) {
  248. return Result::error("该网站不存在", 0);
  249. } elseif ($web['status'] != 1) {
  250. return Result::error("网站已经关闭", 0);
  251. }
  252. if (isset($data['other_route']) && !empty($data['other_route'])) {
  253. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  254. // 验证路由是否存在
  255. if (empty($whiteRouterInfo)) {
  256. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  257. }
  258. if (!empty($whiteRouterInfo)) {
  259. return Result::success($whiteRouterInfo->toArray());
  260. }
  261. }
  262. // 验证栏目路由
  263. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  264. ->where('path', $data['all_route'])
  265. ->get()->all();
  266. if (count($last_category) == 0) {
  267. return Result::error("该栏目不存在", 0);
  268. }
  269. if (count($last_category) > 1) {
  270. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  271. }
  272. if (count($last_category) == 1) {
  273. $last_category = $last_category[0];
  274. }
  275. // return Result::success($last_category);
  276. if (isset($data['id']) && !empty($data['id'])) {
  277. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  278. switch ($last_category['type']) {
  279. case 1:
  280. // 文章
  281. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  282. $article = Article::where('status', 1)
  283. ->where('id', $data['id'])
  284. ->where(function ($query) use ($data) {
  285. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  286. ->orWhereNull("ignore_ids");
  287. })
  288. ->first(['catid']);
  289. if (empty($article)) {
  290. return Result::error("该文章不存在", 0);
  291. }
  292. // return Result::success($article);
  293. break;
  294. case 2:
  295. // 商品
  296. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  297. $article = Good::where('website_id', $data['website_id'])
  298. ->where('status', 2)
  299. ->where('id', $data['id'])
  300. ->first(['cat_arr_id']);
  301. if (empty($article)) {
  302. return Result::error("该商品不存在", 0);
  303. }
  304. break;
  305. case 3:
  306. // 书刊信息
  307. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  308. $article = Book::where('website_id', $data['website_id'])
  309. ->where('status', 2)
  310. ->where('id', $data['id'])
  311. ->first(['id', 'cat_arr_id']);
  312. if (empty($article)) {
  313. return Result::error("该书刊不存在", 0);
  314. }
  315. break;
  316. case 4:
  317. // 招聘
  318. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  319. $article = JobRecruiting::where('website_id', $data['website_id'])
  320. ->where('status', 1)
  321. ->where('id', $data['id'])
  322. ->first(['cat_arr_id']);
  323. if (empty($article)) {
  324. return Result::error("该招聘不存在", 0);
  325. }
  326. break;
  327. case 5:
  328. // 求职
  329. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  330. $article = JobHunting::where('website_id', $data['website_id'])
  331. ->where('status', 2)
  332. ->where('id', $data['id'])
  333. ->first(['cat_arr_id']);
  334. if (empty($article)) {
  335. return Result::error("该求职不存在", 0);
  336. }
  337. break;
  338. case 6:
  339. // 企业
  340. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  341. $article = Company::
  342. // where('website_id', $data['website_id'])
  343. // ->
  344. where('status', 1)
  345. ->where('id', $data['id'])
  346. ->first(['cat_arr_id']);
  347. if (empty($article)) {
  348. return Result::error("该企业不存在", 0);
  349. }
  350. break;
  351. case 7:
  352. // 项目
  353. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  354. $article = Project::where('website_id', $data['website_id'])
  355. ->where('status', 1)
  356. ->where('id', $data['id'])
  357. ->first(['cat_arr_id']);
  358. if (empty($article)) {
  359. return Result::error("该项目不存在", 0);
  360. }
  361. break;
  362. default:
  363. return Result::error("该数据不存在", 0);
  364. break;
  365. }
  366. // return Result::success($article);
  367. // $catid =0 ;
  368. if (!isset($article['cat_arr_id'])) {
  369. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  370. } else {
  371. $catidArray = json_decode($article['cat_arr_id'], true);
  372. $catid = !empty($catidArray) ? end($catidArray) : null;
  373. }
  374. // return Result::success($catid);
  375. // // return Result::success($article['cat_arr_id']);
  376. if (empty($catid)) {
  377. return Result::error("该栏目路径不存在", 0);
  378. }
  379. $path = WebsiteCategory::where('website_id', $data['website_id'])
  380. ->where('category_id', $catid)
  381. ->first('path');
  382. }
  383. // else{
  384. // // if ($last_category['pid'] != 0) {
  385. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  386. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  387. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  388. // ->where('category_id',$catid)
  389. // ->where('path',$data['all_route'])
  390. // ->first('path');
  391. // // } else {
  392. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  393. // // }
  394. // }
  395. // return Result::success($path);
  396. if (!empty($path) && $path['path'] != $data['all_route']) {
  397. return Result::error('非法路径!');
  398. } else {
  399. return Result::success($last_category['path']);
  400. }
  401. }
  402. /**
  403. * 前端-搜索新闻列表
  404. * @param array $data
  405. * @return array
  406. */
  407. public function selectWebsiteArticle(array $data): array
  408. {
  409. $website = Website::where('id', $data['website_id'])->first();
  410. if (empty($website)) {
  411. return Result::error("网站不存在", 0);
  412. }
  413. // $website_column = $website['column'];
  414. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  415. $website_column = json_decode($website['website_column_arr_id'], true);
  416. }
  417. $website_id = $data['website_id'];
  418. $categorys = $this->processArticlePro($website_id);
  419. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  420. // return Result::success($diff_pid_categoryIds);
  421. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  422. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  423. }
  424. // return Result::success(reset($diff_pid_categoryIds) == 0);
  425. // $cat_1st_arr = $categorys['cat_1st_arr'];
  426. $catiall = $categorys['catiall'];
  427. $categoryIds = $categorys['categoryIds'];
  428. // return Result::success($categoryIds);
  429. $query = Article::where('status', 1)
  430. ->whereIn('catid', $categoryIds)
  431. ->leftJoinSub(function ($query) use ($website_id) {
  432. $query->from('article_ignore')
  433. ->where('website_id', $website_id);
  434. }, 'article_ignore', function ($join) {
  435. $join->on('article_ignore.article_id', '=', 'article.id');
  436. })
  437. ->where(function ($query) {
  438. $query->whereNull('article_ignore.article_id')
  439. ->orWhere(function ($subQuery) {
  440. $subQuery->whereNotNull('article_ignore.article_id')
  441. ->where('article_ignore.is_ignore', 0)
  442. ->where(function ($subSubQuery) {
  443. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  444. ->orWhereNull('article_ignore.c_show_time');
  445. });
  446. });
  447. });
  448. // ->get()->all();
  449. // return Result::success($query);
  450. if (isset($data['cityid']) && !empty($data['cityid'])) {
  451. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  452. }
  453. if (isset($data['department_id']) && !empty($data['department_id'])) {
  454. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  455. }
  456. if (isset($data['keyword']) && !empty($data['keyword'])) {
  457. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  458. }
  459. // 计算总数
  460. $count = $query->count();
  461. // return Result::success($count);
  462. // 分页查询
  463. $articles = $query
  464. ->select(
  465. 'article.id',
  466. 'article.title',
  467. 'article.imgurl',
  468. 'article.author',
  469. 'article.updated_at',
  470. 'article.introduce',
  471. 'article.islink',
  472. 'article.linkurl',
  473. 'article.copyfrom',
  474. 'article.cat_arr_id',
  475. 'article.catid',
  476. 'article.department_arr_id',
  477. 'article.city_arr_id',
  478. // 'article_ignore.c_show_time',
  479. // 'article_ignore.is_ignore'
  480. )
  481. ->orderBy("updated_at", "desc")
  482. ->offset(($data['page'] - 1) * $data['pageSize'])
  483. ->limit($data['pageSize'])
  484. ->get();
  485. // return Result::success($articles);
  486. foreach ($articles as $k => $v) {
  487. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  488. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  489. }
  490. if (empty($articles)) {
  491. return Result::error("没有符合条件的资讯数据");
  492. }
  493. $result = [
  494. 'rows' => $articles,
  495. 'count' => $count,
  496. ];
  497. return Result::success($result);
  498. }
  499. /**
  500. * 获取头条新闻
  501. * @param array $data
  502. * @return array
  503. */
  504. public function getWebsiteArticlett(array $data): array
  505. {
  506. $website_id = $data['website_id'];
  507. $website = Website::where('id', $data['website_id'])->first();
  508. if (empty($website)) {
  509. return Result::error("网站不存在", 0);
  510. }
  511. $categorys = $this->processArticlePro($website_id);
  512. $catiall = $categorys['catiall'];
  513. $categoryIds = $categorys['categoryIds'];
  514. $where = [
  515. 'status' => 1
  516. ];
  517. // $website_column = $website['column'];
  518. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  519. $website_column = json_decode($website['website_column_arr_id'], true);
  520. }
  521. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  522. // return Result::success($diff_pid_categoryIds);
  523. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  524. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  525. }
  526. // $website_id = $data['website_id'];
  527. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  528. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  529. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  530. switch ($data['level']) {
  531. case 1:
  532. case 2:
  533. case 3:
  534. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  535. $query = Article::where($where)
  536. ->where('level', 'like', '%' . $data['level'] . '%')
  537. ->orderBy('updated_at', 'desc');
  538. break;
  539. case 4: //最新资讯
  540. $query = Article::where($where)->orderBy('updated_at', 'desc');
  541. break;
  542. case 5: //资讯推荐
  543. $query = Article::where($where)
  544. ->where('updated_at', '>', $month);
  545. break;
  546. case 7: //资讯分类
  547. if (isset($data['id']) && !empty($data['id'])) {
  548. $keyword = Article::where('id', $data['id'])->value('keyword');
  549. $keywordArray = explode(',', $keyword);
  550. $whereL7 = [];
  551. foreach ($keywordArray as $k => $v) {
  552. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  553. }
  554. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  555. break;
  556. } else {
  557. return Result::error("请输入资讯ID", 0);
  558. break;
  559. }
  560. default:
  561. break;
  562. }
  563. // $whereL7 = [];
  564. // if(isset($data['id']) && !empty($data['id'])){
  565. // $keyword = Article::where('id', $data['id'])->value('keyword');
  566. // $keywordArray = explode(',', $keyword);
  567. // foreach ($keywordArray as $k => $v) {
  568. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  569. // }
  570. // }
  571. // $query = Article::where($where)
  572. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  573. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  574. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  575. // }
  576. // if($data['level'] == 7){
  577. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  578. // }
  579. // if($data['level'] == 4){
  580. // $query = $query->inRandomOrder()
  581. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  582. // }
  583. // if($data['level'] == 5){
  584. // $query = $query->orderBy('updated_at','desc');
  585. // }
  586. // });
  587. if ($data['textnum'] > 0) {
  588. $query = clone $query;
  589. $result['text'] = $query
  590. ->whereIn('catid', $categoryIds)
  591. ->leftJoinSub(function ($query) use ($website_id) {
  592. $query->from('article_ignore')
  593. ->where('website_id', $website_id);
  594. }, 'article_ignore', function ($join) {
  595. $join->on('article_ignore.article_id', '=', 'article.id');
  596. })
  597. ->where(function ($query) {
  598. $query->whereNull('article_ignore.article_id')
  599. ->orWhere(function ($subQuery) {
  600. $subQuery->whereNotNull('article_ignore.article_id')
  601. ->where('article_ignore.is_ignore', 0)
  602. ->where(function ($subSubQuery) {
  603. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  604. ->orWhereNull('article_ignore.c_show_time');
  605. });
  606. });
  607. })
  608. // ->where(function ($query) use ($website_id) {
  609. // $query->whereNull('article_ignore.article_id')
  610. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  611. // })
  612. ->select(
  613. 'article.id',
  614. 'article.title',
  615. 'article.author',
  616. 'article.updated_at',
  617. 'article.introduce',
  618. 'article.islink',
  619. 'article.linkurl',
  620. 'article.copyfrom',
  621. 'article.cat_arr_id',
  622. 'article.catid',
  623. 'article.level',
  624. // 'article_ignore.is_ignore',
  625. // 'article_ignore.c_show_time',
  626. )
  627. ->offset($data['placeid'])
  628. ->limit($data['textnum'])
  629. ->get()->all();
  630. foreach ($result['text'] as $k => $v) {
  631. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  632. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  633. }
  634. }
  635. if ($data['imgnum'] > 0) {
  636. $query = clone $query;
  637. if ($data['textnum'] == 0) {
  638. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  639. $query->from('article_ignore')
  640. ->where('website_id', $website_id);
  641. }, 'article_ignore', function ($join) {
  642. $join->on('article_ignore.article_id', '=', 'article.id');
  643. })
  644. ->where(function ($query) {
  645. $query->whereNull('article_ignore.article_id')
  646. ->orWhere(function ($subQuery) {
  647. $subQuery->whereNotNull('article_ignore.article_id')
  648. ->where('article_ignore.is_ignore', 0)
  649. ->where(function ($subSubQuery) {
  650. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  651. ->orWhereNull('article_ignore.c_show_time');
  652. });
  653. });
  654. });
  655. }
  656. $result['img'] = $query
  657. ->whereIn('catid', $categoryIds)
  658. ->where('article.imgurl', '!=', '')
  659. ->select(
  660. 'article.id',
  661. 'article.title',
  662. 'article.imgurl',
  663. 'article.author',
  664. 'article.updated_at',
  665. 'article.introduce',
  666. 'article.islink',
  667. 'article.linkurl',
  668. 'article.copyfrom',
  669. 'article.cat_arr_id',
  670. 'article.catid',
  671. 'article.level',
  672. // 'article_ignore.is_ignore',
  673. // 'article_ignore.c_show_time',
  674. )
  675. ->offset($data['placeid'])
  676. ->limit($data['imgnum'])
  677. ->get()->all();
  678. foreach ($result['img'] as $k => $v) {
  679. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  680. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  681. }
  682. }
  683. if (empty($result)) {
  684. return Result::error("暂无相关资讯", 0);
  685. }
  686. return Result::success($result);
  687. }
  688. /**
  689. * 模块新闻加强plus版
  690. * @param array $data
  691. * @return array
  692. */
  693. public function getWebsiteAllArticle(array $data): array
  694. {
  695. // return Result::success($data);
  696. $time1 = microtime(true);
  697. $wetbsite_id = $data['website_id'] ?? 2;
  698. $data = json_decode($data['id'], true);
  699. $website = Website::where('id', $wetbsite_id)->first();
  700. if (empty($website)) {
  701. return Result::error("网站不存在", 0);
  702. }
  703. // return Result::success($website);
  704. $website_column = $website['website_column_arr_id'] ?? '[]';
  705. $website_column = json_decode($website_column, true);
  706. $categorys = $this->processArticlePro($wetbsite_id);
  707. $cat_1st_arr = $categorys['cat_1st_arr'];
  708. $catiall = $categorys['catiall'];
  709. // return Result::success($catiall);
  710. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  711. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  712. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  713. }
  714. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  715. // return Result::success($categorys);
  716. $parent_category = array_column($data, 'parent');
  717. $parent_cat = [];
  718. $child_category = array_column($data, 'child');
  719. if (!empty($parent_category)) {
  720. foreach ($parent_category as $key => $value) {
  721. $arr = array_map('intval', explode(',', $value));
  722. $parent_cat[$key] = $arr[0] ?? 0;
  723. $parent_category = $arr[0] ?? 0;
  724. $article_imgnum = $arr[1] ?? 0;
  725. $article_textnum = $arr[2] ?? 0;
  726. if ($parent_category != 0) {
  727. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  728. // return Result::success($category_arr);
  729. if ($article_imgnum != 0) {
  730. $img_article = Article::whereIn('catid', $category_arr)
  731. ->where('status', 1)
  732. ->where('imgurl', '!=', '')
  733. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  734. $query->from('article_ignore')
  735. ->where('website_id', $wetbsite_id);
  736. }, 'article_ignore', function ($join) {
  737. $join->on('article_ignore.article_id', '=', 'article.id');
  738. })
  739. ->where(function ($query) {
  740. $query->whereNull('article_ignore.article_id')
  741. ->orWhere(function ($subQuery) {
  742. $subQuery->whereNotNull('article_ignore.article_id')
  743. ->where('article_ignore.is_ignore', 0)
  744. ->where(function ($subSubQuery) {
  745. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  746. ->orWhereNull('article_ignore.c_show_time');
  747. });
  748. });
  749. })
  750. ->select('article.id', 'article.title', 'article.imgurl', 'article.author', 'article.updated_at', 'article.introduce', 'article.islink', 'article.linkurl', 'article.copyfrom', 'article.cat_arr_id', 'article.catid')
  751. ->orderBy('updated_at', 'desc')
  752. ->limit($article_imgnum)
  753. ->get()->all();
  754. foreach ($img_article as $k => $v) {
  755. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  756. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  757. }
  758. } else {
  759. $img_article = [];
  760. }
  761. if ($article_textnum != 0) {
  762. $text_article = Article::whereIn('catid', $category_arr)
  763. ->where('status', 1)
  764. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  765. $query->from('article_ignore')
  766. ->where('website_id', $wetbsite_id);
  767. }, 'article_ignore', function ($join) {
  768. $join->on('article_ignore.article_id', '=', 'article.id');
  769. })
  770. ->where(function ($query) {
  771. $query->whereNull('article_ignore.article_id')
  772. ->orWhere(function ($subQuery) {
  773. $subQuery->whereNotNull('article_ignore.article_id')
  774. ->where('article_ignore.is_ignore', 0)
  775. ->where(function ($subSubQuery) {
  776. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  777. ->orWhereNull('article_ignore.c_show_time');
  778. });
  779. });
  780. })
  781. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  782. ->orderBy('updated_at', 'desc')
  783. ->limit($article_textnum)
  784. ->get()->all();
  785. foreach ($text_article as $k => $v) {
  786. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  787. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  788. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  789. }
  790. } else {
  791. $text_article = [];
  792. }
  793. $catiall[$parent_category]['imgnum'] = $img_article;
  794. $catiall[$parent_category]['textnum'] = $text_article;
  795. $parent[$key] = $catiall[$parent_category];
  796. } else {
  797. $parent[$key] = '';
  798. }
  799. }
  800. }
  801. if (!empty($child_category)) {
  802. foreach ($child_category as $key => $value) {
  803. $arr = array_map('intval', explode(',', $value));
  804. $parent_category = $parent_cat[$key];
  805. $child_category = $arr[0] ?? 0;
  806. $article_imgnum = $arr[1] ?? 0;
  807. $article_textnum = $arr[2] ?? 0;
  808. if ($child_category != 0) {
  809. $all_childcat = $cat_1st_arr[$parent_category];
  810. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  811. // 从 $websiteInfoIndexed 中获取对应的数据
  812. $info = $websiteInfoIndexed[$v];
  813. // 返回一个包含所需信息的数组
  814. return [
  815. 'alias' => $info->alias,
  816. 'category_id' => $info->category_id,
  817. 'aLIas_pinyin' => $info->aLIas_pinyin,
  818. 'pid' => $info->pid,
  819. 'type' => $info->type,
  820. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  821. 'pinyin' => $info->pinyin,
  822. ];
  823. }, $all_childcat);
  824. if ($article_imgnum != 0) {
  825. $img_article = Article::where('catid', $child_category)
  826. ->where('status', 1)
  827. ->where('imgurl', '!=', '')
  828. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  829. $query->from('article_ignore')
  830. ->where('website_id', $wetbsite_id);
  831. }, 'article_ignore', function ($join) {
  832. $join->on('article_ignore.article_id', '=', 'article.id');
  833. })
  834. ->where(function ($query) {
  835. $query->whereNull('article_ignore.article_id')
  836. ->orWhere(function ($subQuery) {
  837. $subQuery->whereNotNull('article_ignore.article_id')
  838. ->where('article_ignore.is_ignore', 0)
  839. ->where(function ($subSubQuery) {
  840. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  841. ->orWhereNull('article_ignore.c_show_time');
  842. });
  843. });
  844. })
  845. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  846. ->orderBy('updated_at', 'desc')
  847. ->limit($article_imgnum)
  848. ->get()->all();
  849. foreach ($img_article as $k => $v) {
  850. // var_dump($v);
  851. // var_dump($k);
  852. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  853. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  854. }
  855. } else {
  856. $img_article = [];
  857. }
  858. if ($article_textnum != 0) {
  859. $text_article = Article::where('catid', $child_category)
  860. ->where('status', 1)
  861. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  862. $query->from('article_ignore')
  863. ->where('website_id', $wetbsite_id);
  864. }, 'article_ignore', function ($join) {
  865. $join->on('article_ignore.article_id', '=', 'article.id');
  866. })
  867. ->where(function ($query) {
  868. $query->whereNull('article_ignore.article_id')
  869. ->orWhere(function ($subQuery) {
  870. $subQuery->whereNotNull('article_ignore.article_id')
  871. ->where('article_ignore.is_ignore', 0)
  872. ->where(function ($subSubQuery) {
  873. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  874. ->orWhereNull('article_ignore.c_show_time');
  875. });
  876. });
  877. })
  878. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  879. ->orderBy('updated_at', 'desc')
  880. ->limit($article_textnum)
  881. ->get()->all();
  882. foreach ($text_article as $k => $v) {
  883. // var_dump($v);
  884. // var_dump($k);
  885. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  886. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  887. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  888. }
  889. } else {
  890. $text_article = [];
  891. }
  892. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  893. $catiall[$child_category]['imgnum'] = $img_article;
  894. $catiall[$child_category]['textnum'] = $text_article;
  895. $child[$key] = $catiall[$child_category];
  896. // var_dump($pids);
  897. } else {
  898. $child[$key] = '';
  899. }
  900. }
  901. }
  902. foreach ($parent as $key => $value) {
  903. $result[$key] = $value;
  904. if (!empty($child[$key])) {
  905. // var_dump($child[$key]);
  906. $result[$key]['child'] = $child[$key];
  907. // $value[$key]['child'] = $child[$key];
  908. } else {
  909. $result[$key]['child'] = [
  910. "alias" => null,
  911. "category_id" => null,
  912. "type" => null,
  913. "pinyin" => null,
  914. "all_childcat" => [],
  915. "imgnum" => [],
  916. "textnum" => []
  917. ];
  918. }
  919. }
  920. return Result::success($result);
  921. }
  922. /**
  923. * 乡村网-获取特殊新闻模块
  924. * @param array $data
  925. * @return array
  926. */
  927. public function getWebsiteArticles(array $data): array
  928. {
  929. $website_id = $data['website_id'];
  930. $website = Website::where('id', $website_id)->first();
  931. if (empty($website)) {
  932. return Result::error("网站不存在", 0);
  933. }
  934. // return Result::success($website);
  935. $website_column = $website['website_column_arr_id'] ?? '[]';
  936. $website_column = json_decode($website_column, true);
  937. $catids = json_decode($data['id'], true);
  938. $parent_category = array_column($catids, 'parent');
  939. if (!empty($parent_category) && is_array($parent_category)) {
  940. $categorys = $this->processArticlePro($website_id);
  941. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  942. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  943. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  944. }
  945. $catiall = $categorys['catiall'];
  946. $cat_1st_arr = $categorys['cat_1st_arr'];
  947. // return Result::success($categorys);
  948. foreach ($parent_category as $key => $value) {
  949. $arr = array_map('intval', explode(',', $value));
  950. $parent_category = $arr[0] ?? 0;
  951. $article_imgnum = $arr[1] ?? 0;
  952. $article_textnum = $arr[2] ?? 0;
  953. if ($parent_category != 0) {
  954. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  955. // return Result::success($category_arr);
  956. if ($article_imgnum != 0) {
  957. $img_article = Article::whereIn('article.catid', $category_arr)
  958. ->where('article.status', 1)
  959. ->where('article.imgurl', '!=', '')
  960. ->leftJoinSub(function ($query) use ($website_id) {
  961. $query->from('article_ignore')
  962. ->where('website_id', $website_id);
  963. }, 'article_ignore', function ($join) {
  964. $join->on('article_ignore.article_id', '=', 'article.id');
  965. })
  966. ->where(function ($query) {
  967. $query->whereNull('article_ignore.article_id')
  968. ->orWhere(function ($subQuery) {
  969. $subQuery->whereNotNull('article_ignore.article_id')
  970. ->where('article_ignore.is_ignore', 0)
  971. ->where(function ($subSubQuery) {
  972. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  973. ->orWhereNull('article_ignore.c_show_time');
  974. });
  975. });
  976. })
  977. ->select(
  978. 'article.id',
  979. 'article.title',
  980. 'article.imgurl',
  981. 'article.author',
  982. 'article.updated_at',
  983. 'article.introduce',
  984. 'article.islink',
  985. 'article.linkurl',
  986. 'article.copyfrom',
  987. 'article.cat_arr_id',
  988. 'article.catid as category_id'
  989. )
  990. ->orderBy('updated_at', 'desc')
  991. ->limit($article_imgnum)
  992. ->get()->all();
  993. foreach ($img_article as $k => $v) {
  994. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  995. // return Result::success($v);
  996. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  997. }
  998. } else {
  999. $img_article = [];
  1000. }
  1001. if ($article_textnum != 0) {
  1002. $text_article = Article::whereIn('article.catid', $category_arr)
  1003. ->where('article.status', 1)
  1004. ->leftJoinSub(function ($query) use ($website_id) {
  1005. $query->from('article_ignore')
  1006. ->where('website_id', $website_id);
  1007. }, 'article_ignore', function ($join) {
  1008. $join->on('article_ignore.article_id', '=', 'article.id');
  1009. })
  1010. ->where(function ($query) {
  1011. $query->whereNull('article_ignore.article_id')
  1012. ->orWhere(function ($subQuery) {
  1013. $subQuery->whereNotNull('article_ignore.article_id')
  1014. ->where('article_ignore.is_ignore', 0)
  1015. ->where(function ($subSubQuery) {
  1016. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1017. ->orWhereNull('article_ignore.c_show_time');
  1018. });
  1019. });
  1020. })
  1021. ->select(
  1022. 'article.id',
  1023. 'article.title',
  1024. 'article.author',
  1025. 'article.updated_at',
  1026. 'article.introduce',
  1027. 'article.islink',
  1028. 'article.linkurl',
  1029. 'article.copyfrom',
  1030. 'article.cat_arr_id',
  1031. 'article.catid as category_id'
  1032. )
  1033. ->orderBy('updated_at', 'desc')
  1034. ->limit($article_textnum)
  1035. ->get()->all();
  1036. foreach ($text_article as $k => $v) {
  1037. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1038. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1039. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1040. }
  1041. } else {
  1042. $text_article = [];
  1043. }
  1044. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  1045. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  1046. $parent[$key] = $catiall[$parent_category];
  1047. } else {
  1048. $parent[$key] = [];
  1049. }
  1050. }
  1051. }
  1052. return Result::success($parent);
  1053. }
  1054. /**
  1055. *获取新闻列表
  1056. * @param array $data
  1057. * @return array
  1058. */
  1059. public function getWebsiteArticleList(array $data): array
  1060. {
  1061. // return Result::success($data);
  1062. $where[] = ['status', '=', 1];
  1063. $website_id = $data['website_id'];
  1064. $website = Website::where('id', $data['website_id'])->first();
  1065. if (empty($website)) {
  1066. return Result::error("网站不存在", 0);
  1067. }
  1068. // $website_column = $website['column'];
  1069. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1070. $website_column = json_decode($website['website_column_arr_id'], true);
  1071. }
  1072. $categorys = $this->processArticlePro($website_id);
  1073. $cat_1st_arr = $categorys['cat_1st_arr'];
  1074. $catiall = $categorys['catiall'];
  1075. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1076. // return Result::success($diff_pid_categoryIds);
  1077. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1078. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1079. }
  1080. if (isset($data['catid']) && !empty($data['catid'])) {
  1081. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1082. if (empty($category)) {
  1083. return Result::error("此网站暂无此栏目", 0);
  1084. }
  1085. array_push($where, ['catid', '=', $data['catid']]);
  1086. }
  1087. // return Result::success($where);
  1088. $query = Article::where($where)
  1089. ->leftJoinSub(function ($query) use ($website_id) {
  1090. $query->from('article_ignore')
  1091. ->where('website_id', $website_id);
  1092. }, 'article_ignore', function ($join) {
  1093. $join->on('article_ignore.article_id', '=', 'article.id');
  1094. })
  1095. ->where(function ($query) {
  1096. $query->whereNull('article_ignore.article_id')
  1097. ->orWhere(function ($subQuery) {
  1098. $subQuery->whereNotNull('article_ignore.article_id')
  1099. ->where('article_ignore.is_ignore', 0)
  1100. ->where(function ($subSubQuery) {
  1101. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1102. ->orWhereNull('article_ignore.c_show_time');
  1103. });
  1104. });
  1105. })
  1106. ->select(
  1107. 'article.id',
  1108. 'article.title',
  1109. 'article.imgurl',
  1110. 'article.author',
  1111. 'article.updated_at',
  1112. 'article.introduce',
  1113. 'article.islink',
  1114. 'article.linkurl',
  1115. 'article.copyfrom',
  1116. 'article.cat_arr_id',
  1117. 'article.catid'
  1118. );
  1119. $count = $query->count();
  1120. $rep = $query->orderBy("updated_at", "desc")
  1121. ->offset(($data['page'] - 1) * $data['pageSize'])
  1122. ->limit($data['pageSize'])
  1123. ->get()->all();
  1124. $categorys = $this->processArticlePro($website_id);
  1125. $cat_1st_arr = $categorys['cat_1st_arr'];
  1126. $catiall = $categorys['catiall'];
  1127. // $web['website_id'] = $data['website_id'];
  1128. foreach ($rep as $k => $v) {
  1129. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1130. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1131. }
  1132. // $rep = $this->processArticles($rep,$web);
  1133. $data = [
  1134. 'rows' => $rep,
  1135. 'count' => $count,
  1136. ];
  1137. if (empty($rep)) {
  1138. return Result::error("没有信息数据");
  1139. }
  1140. return Result::success($data);
  1141. }
  1142. /**
  1143. * 前端-获取新闻详情
  1144. * @param array $data
  1145. * @return array
  1146. */
  1147. public function selectWebsiteArticleInfo(array $data): array
  1148. {
  1149. $where = [
  1150. 'article.id' => $data['id'],
  1151. 'article.status' => 1,
  1152. ];
  1153. $result = Article::where($where)
  1154. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1155. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1156. // ->where(function ($query) use ($data) {
  1157. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1158. // ->orWhereNull("ignore_ids");
  1159. // })
  1160. ->leftJoinSub(function ($query) use ($data) {
  1161. $query->from('article_ignore')
  1162. ->where('website_id', $data['website_id']);
  1163. }, 'article_ignore', function ($join) {
  1164. $join->on('article_ignore.article_id', '=', 'article.id');
  1165. })
  1166. ->where(function ($query) {
  1167. $query->whereNull('article_ignore.article_id')
  1168. ->orWhere(function ($subQuery) {
  1169. $subQuery->whereNotNull('article_ignore.article_id')
  1170. ->where('article_ignore.is_ignore', 0)
  1171. ->where(function ($subSubQuery) {
  1172. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1173. ->orWhereNull('article_ignore.c_show_time');
  1174. });
  1175. });
  1176. })
  1177. ->select(
  1178. 'article.*',
  1179. 'article_data.content',
  1180. 'article_data.article_id',
  1181. 'article_extend.website_url',
  1182. 'article_extend.email',
  1183. 'article_extend.contacts',
  1184. 'article_extend.contacts_mobile',
  1185. 'article_extend.contacts_address',
  1186. 'article_extend.zip_code',
  1187. 'article_extend.enterprise_name'
  1188. )
  1189. ->first();
  1190. if (empty($result)) {
  1191. return Result::error("暂无此新闻!", 0);
  1192. }
  1193. if (!empty($result['publiced_at'])) {
  1194. $result['updated_at'] = $result['publiced_at'];
  1195. }
  1196. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1197. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1198. ->where('website_category.website_id', $data['website_id'])
  1199. ->where(['website_category.category_id' => $result['catid']])
  1200. ->first();
  1201. if (empty($category)) {
  1202. return Result::error("查询失败", 0);
  1203. }
  1204. //手动推荐文章
  1205. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1206. if (empty($commend_ids)) {
  1207. $commendArticle = [];
  1208. } else {
  1209. //去除不存在的文章ID
  1210. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1211. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1212. ->leftJoinSub(function ($query) use ($data) {
  1213. $query->from('article_ignore')
  1214. ->where('website_id', $data['website_id']);
  1215. }, 'article_ignore', function ($join) {
  1216. $join->on('article_ignore.article_id', '=', 'article.id');
  1217. })
  1218. ->where(function ($query) {
  1219. $query->whereNull('article_ignore.article_id')
  1220. ->orWhere(function ($subQuery) {
  1221. $subQuery->whereNotNull('article_ignore.article_id')
  1222. ->where('article_ignore.is_ignore', 0)
  1223. ->where(function ($subSubQuery) {
  1224. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1225. ->orWhereNull('article_ignore.c_show_time');
  1226. });
  1227. });
  1228. })
  1229. ->where('article.status', 1)
  1230. ->where('website_category.website_id', $data['website_id'])
  1231. ->select('article.id', 'article.cat_arr_id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
  1232. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1233. // ->orderBy('article.updated_at', 'desc')
  1234. ->limit(5)
  1235. ->get();
  1236. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1237. foreach ($commendArticle as $k => $v) {
  1238. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1239. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1240. $cat_arr_id = array_unique($cat_arr_id);
  1241. // 从website_category取出alias_pinyin
  1242. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1243. ->whereIn('category_id', $cat_arr_id)
  1244. ->pluck('alias_pinyin', 'category_id')
  1245. ->toArray();
  1246. // 将cat_arr_id的json转成路径/隔开
  1247. $path_parts = [];
  1248. foreach ($cat_arr_id as $cat_id) {
  1249. if (isset($cat_arr[$cat_id])) {
  1250. $path_parts[] = $cat_arr[$cat_id];
  1251. }
  1252. }
  1253. $v->alias_pinyin = implode('/', $path_parts);
  1254. } else {
  1255. $v->alias_pinyin = '';
  1256. }
  1257. }
  1258. }
  1259. $result['category_id'] = $category['category_id'];
  1260. $result['cat_name'] = $category['alias'];
  1261. $result['website_name'] = $category['website_name'] ?? "";
  1262. $result['suffix'] = $category['suffix'] ?? "";
  1263. $result['commendArticle'] = $commendArticle;
  1264. $result['commend_ids'] = $commend_ids;
  1265. return Result::success($result);
  1266. }
  1267. /**
  1268. * plus pro 处理文章路由问题
  1269. */
  1270. function processArticlePro($website_id)
  1271. {
  1272. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  1273. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  1274. // // 取出category_id 对应的aLIas_pinyin
  1275. // $categoryIds = array_column($categorys, 'category_id');
  1276. // $categoryPIds = array_column($categorys, 'pid');
  1277. // $aliasPinyins = array_column($categorys, 'path');
  1278. // $alias = array_column($categorys, 'alias');
  1279. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  1280. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  1281. // // return Result::success($cat_arr);
  1282. // // $catiall = [];
  1283. // //一级所有子级的记录
  1284. // $cat_alias_arr = array_combine($categoryIds, $alias);
  1285. // return [
  1286. // 'cat_1st_arr' => $cat_alias_arr,
  1287. // 'catiall' => $cat_arr,
  1288. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  1289. // 'categoryIds' => $categoryIds,
  1290. // ];
  1291. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  1292. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  1293. // 取出category_id 对应的aLIas_pinyin
  1294. $categoryIds = array_column($categorys, 'category_id');
  1295. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  1296. return $pid != 0;
  1297. })));
  1298. $category_path = array_column($categorys, 'path');
  1299. $cat_arr = array_combine($categoryIds, $category_path);
  1300. // return Result::success(array_diff($categoryIds, $categoryPIds));
  1301. $catiall = [];
  1302. //一级所有子级的记录
  1303. $cat_1st_arr = [];
  1304. foreach ($categorys as $key => $value) {
  1305. // $category_arr_id = json_decode($value->category_arr_id);
  1306. // $pinyin_str = '';
  1307. // // 算出一级 并且算出子级
  1308. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  1309. $cat_1st_arr[$value->pid][] = $value->category_id;
  1310. }
  1311. // foreach ($category_arr_id as $k => $v) {
  1312. // $pinyin_str .= $cat_arr[$v] . '/';
  1313. // }
  1314. // $pinyin_str = rtrim($pinyin_str, '/');
  1315. $catiall[$value->category_id]['alias'] = $value->alias;
  1316. $catiall[$value->category_id]['category_id'] = $value->category_id;
  1317. $catiall[$value->category_id]['type'] = $value->type;
  1318. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  1319. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  1320. }
  1321. return [
  1322. 'cat_1st_arr' => $cat_1st_arr,
  1323. 'catiall' => $catiall,
  1324. 'websiteInfoIndexed' => $websiteInfoIndexed,
  1325. 'categoryIds' => $categoryIds,
  1326. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  1327. 'categoryPIds' => $categoryPIds,
  1328. ];
  1329. }
  1330. /**
  1331. * 获取网站顶部信息
  1332. * @param array $data
  1333. */
  1334. public function getWebsiteHead(array $data): array
  1335. {
  1336. $result = Website::where('id', $data['website_id'])->where('status', 1)->select('website_name', 'logo')->first();
  1337. if (empty($result)) {
  1338. return Result::error("暂无该网站", 0);
  1339. }
  1340. return Result::success($result);
  1341. }
  1342. /**
  1343. *各省市查询
  1344. * @param array $data
  1345. * @return array
  1346. */
  1347. public function selectWebArea(array $data): array
  1348. {
  1349. // return Result::success($data);
  1350. $pid = $data['pid'] ?? 0;
  1351. $result = District::leftJoin('district as district2', 'district.pid', '=', 'district2.id')
  1352. ->where('district.pid', $pid)
  1353. ->where('district.status', 1)
  1354. ->select('district.*', 'district2.name as pid_name')
  1355. ->orderBy('district.code')->get();
  1356. if (empty($result)) {
  1357. return Result::error("未查询到此地区", 0);
  1358. } else {
  1359. return Result::success($result);
  1360. }
  1361. }
  1362. /**test1
  1363. * @param array $data
  1364. * @return array
  1365. */
  1366. public function getWebsiteDistrit(array $data): array
  1367. {
  1368. $where = [];
  1369. if (isset($data['keyWord'])) {
  1370. $where = [
  1371. ['name', 'like', '%' . $data['keyWord'] . '%']
  1372. ];
  1373. }
  1374. $result = [];
  1375. if (isset($data['pageSize'])) {
  1376. $rep = District::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get();
  1377. $count = District::where($where)->count();
  1378. $result = [
  1379. 'rows' => $rep,
  1380. 'count' => $count
  1381. ];
  1382. } else {
  1383. $result = District::where($data)->orderBy("code", "asc")->get();
  1384. }
  1385. return $result ? Result::success($result) : Result::error("没有查到数据");
  1386. }
  1387. /**
  1388. *
  1389. * @param array $data
  1390. * @return array
  1391. */
  1392. /**网站行政职能搜索 */
  1393. public function selectWebsiteDepartment(array $data): array
  1394. {
  1395. $depart = Department::where('pid', 0)->orderBy('id', 'asc')->get();
  1396. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1397. $departments = Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
  1398. if (empty($departments)) {
  1399. $result['message'] = "未查询到与此相关职能部门";
  1400. } else {
  1401. $count = Department::where('name', 'like', "%{$data['keyword']}%")->count();
  1402. $m = [
  1403. 'department' => $depart,
  1404. 'type' => $departments,
  1405. 'count' => $count,
  1406. ];
  1407. }
  1408. $result['sele'] = $m;
  1409. return Result::success($result['sele']);
  1410. }
  1411. $result = $depart;
  1412. return Result::success($result);
  1413. }
  1414. /**
  1415. * 获取友情链接
  1416. * @param array $data
  1417. * @return array
  1418. */
  1419. public function selectWebsiteLinks(array $data): array
  1420. {
  1421. $where = [
  1422. 'website_id' => $data['website_id'],
  1423. 'status' => 1,
  1424. 'type' => $data['type'],
  1425. ];
  1426. $num = $data['num'];
  1427. $result = Link::where($where)->orderBy('sort')->limit($num)->get();
  1428. if (!empty($result)) {
  1429. return Result::success($result);
  1430. } else {
  1431. return Result::error("本网站暂无此类型友情链接", 0);
  1432. }
  1433. }
  1434. /**
  1435. * 获取网站底部导航
  1436. * @param array $data
  1437. * @return array
  1438. */
  1439. public function getWebsiteFooterCategory(array $data): array
  1440. {
  1441. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1442. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1443. if (empty($website)) {
  1444. return Result::error("找不到网站", 0);
  1445. }
  1446. } else {
  1447. return Result::error("参数错误", 0);
  1448. }
  1449. $result = WebsiteCategory::where('website_id', $data['website_id'])
  1450. ->where('type',8)
  1451. ->where('alias','!=','本网招聘')
  1452. ->where('pid',0)
  1453. ->get();
  1454. if (empty($result)) {
  1455. return Result::error("暂无底部导航", 0);
  1456. }
  1457. return Result::success($result->toArray());
  1458. }
  1459. /**
  1460. * 获取网站底部导航列表
  1461. * @param array $data
  1462. * @return array
  1463. */
  1464. public function getWebsiteFooterCategoryList(array $data): array
  1465. {
  1466. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1467. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1468. if (empty($website)) {
  1469. return Result::error("找不到网站", 0);
  1470. }
  1471. } else {
  1472. return Result::error("参数错误", 0);
  1473. }
  1474. $footercategory = WebsiteCategory::where('website_id', $data['website_id'])
  1475. ->where('category_id', $data['fcat_id'])
  1476. ->first();
  1477. if(empty($footercategory)){
  1478. return Result::error('此网站不存在此单页导航!');
  1479. }
  1480. $child_footercate = WebsiteCategory::where('website_category.website_id', $data['website_id'])
  1481. ->where('website_category.pid', $data['fcat_id'])
  1482. ->get()->all();
  1483. if(!empty($child_footercate)){
  1484. foreach($child_footercate as $key => $value){
  1485. $child_footercate[$key]['article'] = SinglePage::where('catid',$value['category_id'])
  1486. ->where('status',1)
  1487. ->where('website_id',$data['website_id'])
  1488. ->get()
  1489. ->all();
  1490. }
  1491. }
  1492. // '底部导航类型 0:内容型;1:列表型;',
  1493. $result = [
  1494. 'foot_cate' => $footercategory,
  1495. 'child_cate' => $child_footercate
  1496. ];
  1497. return Result::success($result);
  1498. }
  1499. /**
  1500. * 获取网站底部导航
  1501. * @param array $data
  1502. * @return array
  1503. */
  1504. public function getWebsiteFooterCategoryInfo(array $data): array
  1505. {
  1506. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1507. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1508. if (empty($website)) {
  1509. return Result::error("找不到网站", 0);
  1510. }
  1511. } else {
  1512. return Result::error("参数错误", 0);
  1513. }
  1514. // 类似本网概况
  1515. if (!isset($data['type'])) {
  1516. // 本网招聘的内容
  1517. $foot_content = SinglePage::where('id', $data['fcat_id'])
  1518. ->where('website_id',$data['website_id'])
  1519. ->where('status',1)
  1520. ->first();
  1521. if(empty($foot_content)){
  1522. return Result::error('此单页内容不存在!');
  1523. }
  1524. $commend_ids = json_decode($foot_content['commend_id'] ?? '[]',true);
  1525. if(!empty($commend_ids)){
  1526. $commend_art = SinglePage::whereIn('id', $commend_ids)
  1527. ->where('website_id',$data['website_id'])
  1528. ->where('status',1)
  1529. ->get()->all();
  1530. }
  1531. $result = [
  1532. 'content' => $foot_content,
  1533. 'commend_art' => $commend_art ?? []
  1534. ];
  1535. }else{
  1536. $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['fcat_id'])->first();
  1537. }
  1538. if (empty($result)) {
  1539. return Result::error("暂无底部导航内容", 0);
  1540. }
  1541. return Result::success($result);
  1542. }
  1543. /**
  1544. * 获取网站底部基础信息
  1545. * @param array $data
  1546. * @return array
  1547. */
  1548. public function getWebsiteFootInfo(array $data): array
  1549. {
  1550. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1551. $website_head = Website::where('id', $data['website_id'])
  1552. ->where('status', 1)
  1553. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')
  1554. ->first();
  1555. if (empty($website_head)) {
  1556. return Result::error("找不到网站", 0);
  1557. }
  1558. } else {
  1559. return Result::error("参数错误", 0);
  1560. }
  1561. $website_head = Website::where('id', $data['website_id'])
  1562. ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description', 'suffix', 'website_url')->first();
  1563. $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1564. if (empty($website_foot)) {
  1565. return Result::error("暂无底部基础信息", 0);
  1566. }
  1567. $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
  1568. $result = [
  1569. 'website_foot' => $website_foot,
  1570. 'website_head' => $website_head,
  1571. ];
  1572. return Result::success($result);
  1573. }
  1574. /**
  1575. * 获取网站栏目信息
  1576. * @param array $data
  1577. */
  1578. public function getWebsiteFootAll(array $data): array
  1579. {
  1580. if(!isset($data['is_diyweb']) || empty($data['is_diyweb'])){
  1581. $website = Website::where('id',$data['website_id'])->where('status',1)->first();
  1582. }else{
  1583. $website = Website::where('id',$data['website_id'])->first();
  1584. }
  1585. if (empty($website)) {
  1586. return Result::error("暂无该网站", 0);
  1587. }
  1588. // 1:图片 2:文字 3:底部
  1589. $result['foot_cate'] = WebsiteCategory::where('website_id', $data['website_id'])->where('type',8)->where('pid',0)->get()->all();
  1590. $result['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  1591. $result['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  1592. $result['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  1593. $result['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1594. if (empty($result)) {
  1595. return Result::error("暂无此网站信息", 0);
  1596. }
  1597. return Result::success($result);
  1598. }
  1599. /**
  1600. * 获取网站栏目信息
  1601. * @param array $data
  1602. */
  1603. public function getWebsiteAllinfo(array $data): array
  1604. {
  1605. $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
  1606. if (empty($website)) {
  1607. return Result::error("暂无该网站", 0);
  1608. }
  1609. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1610. $website_head = Website::where('id', $data['website_id'])
  1611. ->where('status', 1)
  1612. ->select(
  1613. 'id',
  1614. 'website_name',
  1615. 'logo',
  1616. 'title',
  1617. 'keywords',
  1618. 'description',
  1619. 'suffix',
  1620. 'website_url',
  1621. 'ad_key',
  1622. 'api_url',
  1623. 'login_url',
  1624. 'weblog_url'
  1625. )
  1626. ->first();
  1627. if (empty($website_head)) {
  1628. return Result::error("找不到网站", 0);
  1629. }
  1630. } else {
  1631. return Result::error("参数错误", 0);
  1632. }
  1633. $website_foot['foot_info'] = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
  1634. if (empty($website_foot)) {
  1635. return Result::error("暂无底部基础信息", 0);
  1636. }
  1637. $website_head['website_url'] = $website_head['website_url'] ? json_decode($website_head['website_url']) : [];
  1638. $result['website_head'] = $website_head;
  1639. $result['website_foot'] = $website_foot;
  1640. // return Result::success($result);
  1641. // 1:图片 2:文字 3:底部
  1642. $result['website_foot']['foot_cate'] = WebsiteCategory::where('website_id', $data['website_id'])->where('type',8)->get()->all();
  1643. $result['website_foot']['link_img'] = Link::where('website_id', $data['website_id'])->where('type', 1)->where('status', 1)->limit($data['link_imgnum'])->orderBy('sort')->get()->all();
  1644. $result['website_foot']['link_text'] = Link::where('website_id', $data['website_id'])->where('type', 2)->where('status', 1)->limit($data['link_textnum'])->orderBy('sort')->get()->all();
  1645. $result['website_foot']['link_foot'] = Link::where('website_id', $data['website_id'])->where('type', 3)->where('status', 1)->limit($data['link_footnum'])->orderBy('sort')->get()->all();
  1646. if (empty($result)) {
  1647. return Result::error("暂无此网站信息", 0);
  1648. }
  1649. return Result::success($result);
  1650. }
  1651. /**
  1652. * 查询网站的广告
  1653. * @param array $data
  1654. * @return array
  1655. */
  1656. public function getWebsiteAdvertisement(array $data): array
  1657. {
  1658. $where = [
  1659. 'ad_place.status' => 1,
  1660. ];
  1661. if (isset($data['ad_tag']) && !empty($data['ad_tag'])) {
  1662. $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
  1663. $where[] = ['ad_place.ad_tag', 'like', '%' . $data['ad_tag'] . '%'];
  1664. // return Result::success($where);
  1665. $result = AdPlace::where($where)
  1666. ->leftJoin("ad", function ($join) use ($now) {
  1667. $join->on("ad.pid", "=", "ad_place.id")
  1668. ->where('ad.status', 1)
  1669. ->where('ad.fromtime', '<=', $now)
  1670. ->where('ad.totime', '>=', $now);
  1671. })
  1672. ->select(
  1673. 'ad_place.name as place_name',
  1674. 'ad_place.thumb',
  1675. 'ad_place.ad_tag',
  1676. 'ad_place.introduce',
  1677. 'ad.name as ad_name',
  1678. 'ad.image_src',
  1679. 'ad.image_url',
  1680. 'ad.image_alt',
  1681. 'ad_place.ad_url'
  1682. )
  1683. ->get()->all();
  1684. } else {
  1685. $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
  1686. // return Result::success($where);
  1687. $result = AdPlace::where($where)
  1688. ->where('ad_place.website_id', $data['website_id'])
  1689. ->leftJoin("ad", function ($join) use ($now) {
  1690. $join->on("ad.pid", "=", "ad_place.id")
  1691. ->where('ad.status', 1)
  1692. ->where('ad.fromtime', '<=', $now)
  1693. ->where('ad.totime', '>=', $now);
  1694. })
  1695. ->select(
  1696. 'ad_place.name as place_name',
  1697. 'ad_place.thumb',
  1698. 'ad_place.ad_tag',
  1699. 'ad_place.introduce',
  1700. 'ad.name as ad_name',
  1701. 'ad.image_src',
  1702. 'ad.image_url',
  1703. 'ad.image_alt',
  1704. 'ad_place.ad_url',
  1705. )
  1706. ->get()->all();
  1707. // return Result::error("请选择广告位!",0);
  1708. }
  1709. if (empty($result)) {
  1710. return Result::error("此广告位不存在!", 0);
  1711. }
  1712. return Result::success($result);
  1713. }
  1714. /**
  1715. * 前端-获取网站调查问卷
  1716. * @param array $data
  1717. * @return array
  1718. */
  1719. public function getWebsiteSurvey(array $data): array
  1720. {
  1721. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1722. $website = Website::where('id', $data['website_id'])->first();
  1723. if (empty($website)) {
  1724. return Result::error("暂无此网站", 0);
  1725. }
  1726. }
  1727. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1728. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1729. if (empty($article)) {
  1730. return Result::error("暂无此文章", 0);
  1731. }
  1732. // return Result::error($data,0);
  1733. $where['art_id'] = $data['art_id'];
  1734. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1735. } else {
  1736. $survey = Article::where(function ($query) {
  1737. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1738. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1739. })
  1740. ->where('status', 1)
  1741. ->where('is_survey', 1)
  1742. ->select('survey_id')
  1743. ->orderBy('updated_at', 'desc')
  1744. ->first();
  1745. if (empty($survey)) {
  1746. return Result::error("暂无调查问卷", 0);
  1747. }
  1748. $where['sur_id'] = $survey['survey_id'];
  1749. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1750. }
  1751. // return Result::success($where);
  1752. $result = ArticleSurvey::where($where)
  1753. ->where(function ($query) {
  1754. $query->where('is_other', 0)
  1755. ->orWhere(function ($subQuery) {
  1756. $subQuery->where('is_other', 1)
  1757. ->where('other_id', 0);
  1758. });
  1759. })
  1760. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1761. ->select('article_survey.*', 'article.survey_type')
  1762. ->get()->all();
  1763. if (empty($result)) {
  1764. return Result::error("此文章暂无调查问卷", 0);
  1765. }
  1766. return Result::success($result);
  1767. }
  1768. /**
  1769. * 前端-添加网站调查问卷选项
  1770. * @param array $data
  1771. * @return array
  1772. */
  1773. public function addWebsiteSurveyOption(array $data): array
  1774. {
  1775. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1776. $website = Website::where('id', $data['website_id'])->first();
  1777. if (empty($website)) {
  1778. return Result::error("暂无此网站", 0);
  1779. }
  1780. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1781. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1782. if (empty($survey)) {
  1783. return Result::error("此调查问卷不可添加选项", 0);
  1784. }
  1785. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1786. $choice = [
  1787. 'art_id' => $survey['art_id'],
  1788. 'website_id' => $data['website_id'],
  1789. 'survey_name' => $survey['survey_name'],
  1790. 'choice_name' => $data['choice_name'],
  1791. 'sur_id' => $survey['sur_id'],
  1792. 'is_other' => 1,
  1793. 'other_id' => $survey['id'],
  1794. ];
  1795. $result = ArticleSurvey::insertGetId($choice);
  1796. if (empty($result)) {
  1797. return Result::error("添加失败", 0);
  1798. }
  1799. return Result::success($result);
  1800. }
  1801. }
  1802. return Result::error("添加失败", 0);
  1803. }
  1804. return Result::error("添加失败", 0);
  1805. }
  1806. /**
  1807. * 前端-调查问卷投票
  1808. * @param array $data
  1809. * @return array
  1810. */
  1811. public function addWebsiteSurveyVote(array $data): array
  1812. {
  1813. // return Result::success($data);
  1814. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1815. $website = Website::where('id', $data['website_id'])->first();
  1816. if (empty($website)) {
  1817. return Result::error("暂无此网站", 0);
  1818. }
  1819. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1820. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1821. // return Result::success($survey);
  1822. if (empty($is_survey)) {
  1823. return Result::error("此调查问卷不存在", 0);
  1824. }
  1825. // return Result::success($survey);
  1826. // 调查问卷类型
  1827. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1828. //多选 若是json型则转化成数组类型
  1829. if (strpos($data['choice_id'], '[') === 0) {
  1830. $data['choice_id'] = json_decode($data['choice_id'], true);
  1831. } else {
  1832. // 单选 也转换成数组
  1833. $data['choice_id'] = [$data['choice_id']];
  1834. }
  1835. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1836. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1837. // ->where('website_id',$data['website_id'])
  1838. ->where('is_other', 1)
  1839. ->where('other_id', 0)
  1840. ->first();
  1841. if (!empty($other)) {
  1842. return Result::error("请选择已有的选项!", 0);
  1843. }
  1844. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1845. // ->where('website_id',$data['website_id'])
  1846. ->where('is_other', 1)
  1847. ->where('other_id', '!=', 0)
  1848. ->first();
  1849. // return Result::success($choice['other']);
  1850. $choice_id = $data['choice_id'];
  1851. if (!empty($choice['other'])) {
  1852. // array_push($data['choice_id'],$choice['other']['other_id']);
  1853. if (!empty($choice_id)) {
  1854. $key = array_search($choice['other']['id'], $choice_id);
  1855. if ($key !== false) {
  1856. unset($choice_id[$key]);
  1857. $choice_id = array_values($choice_id);
  1858. }
  1859. array_push($choice_id, $choice['other']['other_id']);
  1860. } else {
  1861. $choice_id[0] = $choice['other']['other_id'];
  1862. }
  1863. array_push($data['choice_id'], $choice['other']['other_id']);
  1864. }
  1865. // return Result::success($data);
  1866. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1867. // ->where('website_id',$data['website_id'])
  1868. ->increment('results', 1);
  1869. if (empty($choice)) {
  1870. return Result::error("请选择已有的选项!", 0);
  1871. }
  1872. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1873. // ->where('website_id',$data['website_id'])
  1874. ->where('other_id', 0)
  1875. ->get();
  1876. $survey['choice'] = $choice_id;
  1877. return Result::success($survey);
  1878. }
  1879. return Result::error("参数必填!");
  1880. }
  1881. return Result::error("此调查问卷不存在", 0);
  1882. }
  1883. return Result::error("参数必填!");
  1884. }
  1885. /**
  1886. * 获取商城首页-根据栏目id
  1887. * @param array $data
  1888. * @return array
  1889. * */
  1890. function getWebsiteCatidshop(array $data): array
  1891. {
  1892. $input['catid'] = $data['catid'];
  1893. $input['website_id'] = $data['website_id'];
  1894. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1895. $result = array_map(function ($item) use ($input) {
  1896. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1897. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1898. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1899. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1900. if (empty($category) || $category->type != 2) {
  1901. return Result::error("暂无此栏目", 0);
  1902. } else {
  1903. $website['website_id'] = $input['website_id'];
  1904. $goods = Good::where('good.status', 2)
  1905. ->where('good.website_id', $website['website_id'])
  1906. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1907. ->select(
  1908. 'good.id',
  1909. 'good.name',
  1910. 'good.imgurl',
  1911. 'good.description',
  1912. 'good.updated_at',
  1913. 'good.catid',
  1914. 'good.type_id',
  1915. 'good.price',
  1916. 'good.com',
  1917. 'good.level',
  1918. 'good.unit'
  1919. )
  1920. ->orderBy('updated_at', 'desc')
  1921. ->offset($goodStart)
  1922. ->limit($goodNum);
  1923. $all_goods = $goods->get();
  1924. $all_goods = $this->processGoods($all_goods, $website);
  1925. }
  1926. return $all_goods ?? [];
  1927. }
  1928. }, $data);
  1929. return Result::success($result);
  1930. }
  1931. /**
  1932. * 获取商品模块
  1933. * @param array $data
  1934. * @return array
  1935. * */
  1936. public function getWebsiteshop(array $data): array
  1937. {
  1938. $input['id'] = $data['id'];
  1939. $input['website_id'] = $data['website_id'];
  1940. $catid = $data['catid'];
  1941. $data = json_decode($input['id'] ?? '', true) ?? [];
  1942. $result['goods'] = array_map(function ($item) use ($input) {
  1943. // 检查parent元素是否存在且不是undefined
  1944. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1945. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1946. $website = $input['website_id'];
  1947. $query = Good::where('good.status', 2)
  1948. ->where('good.website_id', $website);
  1949. switch ($Levelid) {
  1950. case 1:
  1951. case 2:
  1952. case 3:
  1953. $goods = $query->where(function ($q) use ($Levelid) {
  1954. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1955. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1956. });
  1957. break;
  1958. case 4:
  1959. $goods = $query;
  1960. break;
  1961. case 5:
  1962. $goods = $query->where('type_id', 1);
  1963. break;
  1964. case 6:
  1965. $goods = $query->where('type_id', 2);
  1966. break;
  1967. default:
  1968. return [];
  1969. }
  1970. $all_goods = $goods
  1971. ->select(
  1972. 'good.id',
  1973. 'good.name',
  1974. 'good.imgurl',
  1975. 'good.description',
  1976. 'good.updated_at',
  1977. 'good.catid',
  1978. 'good.type_id',
  1979. 'good.price',
  1980. 'good.level',
  1981. 'good.website_id'
  1982. )
  1983. ->orderBy('updated_at', 'desc')
  1984. ->offset($goodStart)
  1985. ->limit($goodNum)
  1986. ->get();
  1987. $web['website_id'] = $website;
  1988. $all_goods = $this->processGoods($all_goods, $web);
  1989. }
  1990. return $all_goods;
  1991. }, $data);
  1992. $website = $input['website_id'];
  1993. $result['article'] = Article::where(function ($query) use ($website) {
  1994. $query->where(function ($subQuery) use ($website) {
  1995. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1996. })->orWhereNull("ignore_ids");
  1997. })
  1998. ->where('catid', $catid)
  1999. ->where('article.status', 1)
  2000. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2001. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2002. ->orderBy('article.updated_at', 'desc')
  2003. ->first();
  2004. return Result::success($result);
  2005. }
  2006. /**
  2007. * 获取商品分类
  2008. * @param array $data
  2009. * @return array
  2010. * */
  2011. public function getWebsiteshopCat(array $data): array
  2012. {
  2013. $website = $data['website_id'];
  2014. $category = WebsiteCategory::where('website_id', $website)
  2015. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2016. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2017. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2018. ->orderBy('sort')
  2019. ->get();
  2020. $cat = $category->map(function ($item) use ($website) {
  2021. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2022. $pid = $item->pid ?? 0;
  2023. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2024. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2025. ->where('website_id', $website)
  2026. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2027. ->get(['aLIas_pinyin'])
  2028. ->pluck('aLIas_pinyin')
  2029. ->implode('/');
  2030. } else {
  2031. $pinyin = $item->aLIas_pinyin ?? '';
  2032. }
  2033. $item->pinyin = $pinyin;
  2034. });
  2035. if (empty($category)) {
  2036. return Result::error("栏目查询失败", 0);
  2037. }
  2038. $cat_tree = Result::buildMenuTree($category);
  2039. $web['website_id'] = $website;
  2040. $goods = Good::where('website_id', $website)
  2041. ->where('status', 2)
  2042. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2043. ->latest('updated_at')
  2044. ->offset(($data['page'] - 1) * $data['pageSize'])
  2045. ->limit($data['pageSize'])
  2046. ->get();
  2047. if (!empty($goods)) {
  2048. if ($goods->count() > 1 && !empty($goods)) {
  2049. $goods = $this->processGoods($goods, $web);
  2050. }
  2051. } else {
  2052. $goods = [];
  2053. }
  2054. $result = [
  2055. 'category' => $cat_tree,
  2056. 'goods' => $goods,
  2057. ];
  2058. // $resul['goods'] = $goods;
  2059. if (empty($result)) {
  2060. return Result::error("查询失败", 0);
  2061. }
  2062. return Result::success($result);
  2063. }
  2064. /*
  2065. * 获取商品列表
  2066. * @param array $data
  2067. * @return array
  2068. * */
  2069. public function getWebsiteshopList(array $data): array
  2070. {
  2071. // return Result::success($data);
  2072. $where = [
  2073. 'status' => 2,
  2074. 'website_id' => $data['website_id'],
  2075. ];
  2076. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2077. // return Result::error("查询失败", 0);
  2078. // }
  2079. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2080. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2081. $data['catid'] = $category->category_id ?? 0;
  2082. }
  2083. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2084. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2085. }
  2086. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2087. array_push($where, ['type_id', $data['type_id']]);
  2088. }
  2089. $query = Good::where($where)
  2090. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2091. $query->where(function ($q) use ($data) {
  2092. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2093. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2094. });
  2095. })
  2096. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2097. $query->where(function ($q) use ($data) {
  2098. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2099. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2100. });
  2101. })
  2102. ->select(
  2103. 'good.id',
  2104. 'good.name',
  2105. 'good.imgurl',
  2106. 'good.description',
  2107. 'good.updated_at',
  2108. 'good.com',
  2109. 'good.catid',
  2110. 'good.type_id',
  2111. 'good.website_id',
  2112. 'good.cat_arr_id',
  2113. 'good.created_at',
  2114. 'good.city_id'
  2115. )
  2116. ->latest('updated_at');
  2117. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2118. $result['count'] = $query->clone()->count();
  2119. $result['goods'] = $this->processGoods(
  2120. $query->clone()
  2121. ->offset(($data['page'] - 1) * $data['pageSize'])
  2122. ->limit($data['pageSize'])
  2123. ->get(),
  2124. $data
  2125. );
  2126. } else {
  2127. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2128. // 获取 type_id 为 1 的数据
  2129. $result['type1'] = $this->processGoods(
  2130. $query->clone()
  2131. ->where('type_id', 1)
  2132. ->offset(($data['page'] - 1) * $data['pageSize'])
  2133. ->limit($data['pageSize'])
  2134. ->get(),
  2135. $data
  2136. );
  2137. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2138. // 获取 type_id 为 2 的数据
  2139. $result['type2'] = $this->processGoods(
  2140. $query->clone()
  2141. ->where('type_id', 2)
  2142. ->offset(($data['page'] - 1) * $data['pageSize'])
  2143. ->limit($data['pageSize'])
  2144. ->get(),
  2145. $data
  2146. );
  2147. }
  2148. if (empty($result)) {
  2149. return Result::error("查询失败", 0);
  2150. }
  2151. return Result::success($result);
  2152. }
  2153. /**
  2154. * 获取商品详情
  2155. * @param array $data
  2156. * @return array
  2157. * */
  2158. public function getWebsiteshopInfo(array $data): array
  2159. {
  2160. $where = [
  2161. 'good.status' => 2,
  2162. 'good.website_id' => $data['website_id'],
  2163. 'good.id' => $data['id'],
  2164. ];
  2165. $goods = Good::where($where)
  2166. ->where('good.id', $data['id'])
  2167. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2168. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2169. ->first();
  2170. if (empty($goods)) {
  2171. return Result::error("查询失败", 0);
  2172. }
  2173. $goods->imgurl = json_decode($goods->imgurl, true);
  2174. return Result::success($goods);
  2175. }
  2176. // 封装处理商品的路由问题
  2177. function processGoods($goods, $data)
  2178. {
  2179. return $goods->map(function ($good) use ($data) {
  2180. $catid = $good->catid ?? 0;
  2181. // $pinyin = '';
  2182. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2183. if (!empty($category->pid) && $category->pid != 0) {
  2184. $level = json_decode($category->category_arr_id, true);
  2185. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2186. ->whereIn('category_id', $level)
  2187. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2188. ->get(['aLIas_pinyin'])
  2189. ->pluck('aLIas_pinyin')
  2190. ->implode('/');
  2191. } else {
  2192. $pinyin = $category->aLIas_pinyin ?? '';
  2193. }
  2194. if (isset($good->city_id) && !empty($good->city_id)) {
  2195. $city = District::where('id', $good->city_id)->first(['name']);
  2196. $good->city_name = $city->name ?? '';
  2197. }
  2198. // 解析imgurl JSON并取第一条数据
  2199. $imgUrls = json_decode($good->imgurl, true);
  2200. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2201. $good->pinyin = $pinyin;
  2202. return $good;
  2203. });
  2204. }
  2205. /**
  2206. * c端-获取招工招聘下拉选框
  2207. * @param array $data
  2208. * @return array
  2209. * */
  2210. public function getWebsiteJobSelect(array $data): array
  2211. {
  2212. $web = Website::where('id', $data['website_id'])->first();
  2213. if (empty($web)) {
  2214. return Result::error("该网站不存在", 0);
  2215. }
  2216. $hy = JobIndustry::get()->all();
  2217. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2218. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2219. $result = [
  2220. 'hy' => $hy,
  2221. 'zw' => $zw,
  2222. 'jtzw' => $jtzw,
  2223. ];
  2224. if (empty($result)) {
  2225. return Result::error("查询失败", 0);
  2226. }
  2227. return Result::success($result);
  2228. }
  2229. /**
  2230. * c端-获取招工招聘
  2231. * @param array $data
  2232. * @return array
  2233. * */
  2234. public function getWebsiteJob(array $data): array
  2235. {
  2236. $web = Website::where('id', $data['website_id'])->first();
  2237. if (empty($web)) {
  2238. return Result::error("该网站不存在", 0);
  2239. }
  2240. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2241. ->where('job_hunting.website_id', $data['website_id'])
  2242. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2243. $query->where(function ($q) use ($data) {
  2244. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2245. });
  2246. })
  2247. ->select(
  2248. 'job_hunting.id',
  2249. 'job_hunting.catid',
  2250. 'job_hunting.cat_arr_id',
  2251. 'job_hunting.job_name_get',
  2252. 'job_hunting.industry',
  2253. 'job_hunting.name',
  2254. 'job_hunting.sexy',
  2255. 'job_hunting.origin',
  2256. 'job_hunting.city_arr_id',
  2257. 'job_hunting.experience',
  2258. 'job_hunting.updated_at',
  2259. 'job_hunting.salary',
  2260. 'job_hunting.skillList',
  2261. 'job_hunting.slelf_evaluation',
  2262. )
  2263. ->orderBy('updated_at', 'desc')
  2264. ->limit($data['job1_num'])
  2265. ->get();
  2266. $web['website_id'] = $data['website_id'];
  2267. if (empty($job_hunting)) {
  2268. $job_huntings = "未查询到相关简历信息";
  2269. } else {
  2270. $job_huntings = $this->processJob($job_hunting, $web);
  2271. }
  2272. // 0:待审核 1:已通过 2:已拒绝
  2273. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2274. ->where('job_recruiting.website_id', $data['website_id'])
  2275. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2276. $query->where(function ($q) use ($data) {
  2277. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2278. });
  2279. })
  2280. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2281. ->select(
  2282. 'job_recruiting.id',
  2283. 'job_recruiting.catid',
  2284. 'job_recruiting.cat_arr_id',
  2285. 'job_recruiting.title',
  2286. 'job_recruiting.jtzw_id',
  2287. 'job_recruiting.hy_id',
  2288. 'job_recruiting.city_arr_id',
  2289. 'job_recruiting.due_data',
  2290. 'job_recruiting.updated_at',
  2291. 'job_recruiting.experience',
  2292. 'job_recruiting.educational',
  2293. 'job_recruiting.salary',
  2294. 'job_recruiting.zw_id',
  2295. 'job_company.business_name',
  2296. 'job_recruiting.keyword',
  2297. 'job_recruiting.description',
  2298. )
  2299. ->orderBy('updated_at', 'desc')
  2300. ->limit($data['job2_num'])
  2301. ->get();
  2302. if (empty($job_recruiting->toArray())) {
  2303. $job_recruitings = "未查询到相关职位信息";
  2304. } else {
  2305. $job_recruitings = $this->processJob($job_recruiting, $web);
  2306. }
  2307. $result = [
  2308. 'job_hunting' => $job_huntings,
  2309. 'job_recuiting' => $job_recruitings,
  2310. ];
  2311. return Result::success($result);
  2312. }
  2313. /**
  2314. * c端-获取招工招聘列表
  2315. * @param array $data
  2316. * @return array
  2317. * */
  2318. public function getWebsiteJobList(array $data): array
  2319. {
  2320. $recruit_where = [];
  2321. $hunt_where = [];
  2322. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2323. if (empty($web)) {
  2324. return Result::error("此网站不存在", 0);
  2325. }
  2326. $website_id['website_id'] = $data['website_id'];
  2327. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2328. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2329. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2330. }
  2331. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2332. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2333. }
  2334. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2335. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2336. }
  2337. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2338. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  2339. }
  2340. $query = JobRecruiting::where('job_recruiting.status', 1)
  2341. ->where('job_recruiting.website_id', $data['website_id'])
  2342. ->where($recruit_where)
  2343. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2344. $query->where(function ($q) use ($data) {
  2345. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2346. });
  2347. })
  2348. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2349. $query->where(function ($q) use ($data) {
  2350. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2351. });
  2352. })
  2353. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2354. ->select(
  2355. 'job_recruiting.id',
  2356. 'job_recruiting.catid',
  2357. 'job_recruiting.hy_id',
  2358. 'job_recruiting.title',
  2359. 'job_recruiting.zw_id',
  2360. 'job_recruiting.educational',
  2361. 'job_recruiting.jtzw_id',
  2362. 'job_recruiting.city_arr_id',
  2363. 'job_recruiting.due_data',
  2364. 'job_recruiting.experience',
  2365. 'job_recruiting.cat_arr_id',
  2366. 'job_recruiting.updated_at',
  2367. 'job_company.business_name',
  2368. 'job_recruiting.keyword',
  2369. 'job_recruiting.description',
  2370. )
  2371. ->orderBy('job_recruiting.updated_at', 'desc');
  2372. $recruit_count = $query->count();
  2373. $query = clone $query;
  2374. $JobRecruiting = $query
  2375. ->offset(($data['page'] - 1) * $data['pageSize'])
  2376. ->limit($data['pageSize'])
  2377. ->get();
  2378. if (empty($JobRecruiting)) {
  2379. $JobRecruiting = "暂无相关职位信息";
  2380. } else {
  2381. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2382. }
  2383. }
  2384. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2385. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2386. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  2387. }
  2388. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2389. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  2390. }
  2391. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2392. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  2393. }
  2394. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2395. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  2396. }
  2397. $query = JobHunting::where('job_hunting.status', 2)
  2398. ->where('job_hunting.website_id', $data['website_id'])
  2399. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  2400. ->where($hunt_where)
  2401. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  2402. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  2403. // })
  2404. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2405. $query->where(function ($q) use ($data) {
  2406. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2407. });
  2408. })
  2409. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2410. $query->where(function ($q) use ($data) {
  2411. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2412. });
  2413. })
  2414. ->select(
  2415. 'job_hunting.id',
  2416. 'job_hunting.catid',
  2417. 'job_hunting.sexy',
  2418. 'job_hunting.experience',
  2419. 'job_hunting.origin',
  2420. 'job_hunting.industry',
  2421. 'job_hunting.name',
  2422. 'job_hunting.job',
  2423. 'job_hunting.job_name_get',
  2424. 'job_hunting.city_arr_id',
  2425. 'job_hunting.cat_arr_id',
  2426. 'job_hunting.created_at',
  2427. 'job_hunting.updated_at',
  2428. 'job_position.zwname as job_name',
  2429. 'job_hunting.skillList',
  2430. 'job_hunting.slelf_evaluation',
  2431. )
  2432. ->orderBy('job_hunting.updated_at', 'desc');
  2433. $hunt_count = $query->count();
  2434. $query = clone $query;
  2435. $JobHunting = $query
  2436. ->offset(($data['page'] - 1) * $data['pageSize'])
  2437. ->limit($data['pageSize'])
  2438. ->get();
  2439. if (empty($JobHunting)) {
  2440. $JobRecruiting = "暂无相关简历信息";
  2441. } else {
  2442. $JobHunting = $this->processJob($JobHunting, $website_id);
  2443. }
  2444. }
  2445. $result = [
  2446. 'JobRecruiting' => $JobRecruiting ?? [],
  2447. 'recruit_count' => $recruit_count ?? 0,
  2448. 'JobHunting' => $JobHunting ?? [],
  2449. 'hunt_count' => $hunt_count ?? 0,
  2450. ];
  2451. return Result::success($result);
  2452. }
  2453. /**
  2454. * c端-获取招工招聘详情
  2455. * @param array $data
  2456. * @return array
  2457. * */
  2458. public function getWebsiteJobInfo(array $data): array
  2459. {
  2460. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2461. if (empty($web)) {
  2462. return Result::error("该网站不存在", 0);
  2463. }
  2464. $webid = [
  2465. 'website_id' => $data['website_id'],
  2466. ];
  2467. // 职位相关信息
  2468. if ($data['type'] == 1) {
  2469. $query = JobRecruiting::where('status', 1)
  2470. ->where('website_id', $data['website_id'])
  2471. ->select('*');
  2472. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2473. $company = JobCompany::where('job_id', $data['id'])->select('id', 'business_name', 'company_hy_id', 'company_size', 'company_nature', 'address_arr_id', 'address', 'job_company.email')->get();
  2474. if (!empty($company)) {
  2475. $result['company'] = $this->processJob($company, $webid);
  2476. }
  2477. $other_job = JobRecruiting::where('status', 1)
  2478. ->where('website_id', $data['website_id'])
  2479. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2480. ->where('id', '!=', $data['id'])
  2481. ->where('user_id', '=', $job[0]['user_id'])
  2482. ->limit($data['pageSize'])
  2483. ->get();
  2484. if (!empty($other_job)) {
  2485. $result['other_job'] = $this->processJob($other_job, $webid);
  2486. }
  2487. } else {
  2488. // 简历相关信息
  2489. $job = JobHunting::where('job_hunting.status', 2)
  2490. ->where('job_hunting.website_id', $data['website_id'])
  2491. ->where('job_hunting.id', $data['id'])
  2492. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2493. ->select('job_hunting.*', 'user_name')
  2494. ->get();
  2495. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2496. if (!empty($resume->toArray())) {
  2497. $result['resume'] = 1;
  2498. } else {
  2499. $result['resume'] = 0;
  2500. }
  2501. }
  2502. if (empty($job->toArray())) {
  2503. return Result::error("id参数错误", 0);
  2504. }
  2505. if (!empty($job[0]['job_experience'])) {
  2506. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2507. if (!empty($job_experience)) {
  2508. // $hy = [];
  2509. foreach ($job_experience as $key => $value) {
  2510. // $id = $value['id'];
  2511. $hy[$key] = $value['job_industry'];
  2512. $zw_id[$key] = $value['job_typename'];
  2513. $jtzw_id[$key] = $value['job_name'];
  2514. }
  2515. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  2516. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  2517. // 先将关联表转换为索引数组,提高查找效率
  2518. $hyLookup = [];
  2519. foreach ($hy_table as $item) {
  2520. $hyLookup[$item['hyid']] = $item['hyname'];
  2521. }
  2522. $zwLookup = [];
  2523. foreach ($zw_table as $item) {
  2524. $zwLookup[$item['zwid']] = $item['zwname'];
  2525. }
  2526. foreach ($job_experience as $key => &$value) {
  2527. // 处理行业名称
  2528. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2529. $value['hy_name'] = $hyLookup[$hy[$key]];
  2530. }
  2531. // 处理职位名称
  2532. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2533. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2534. }
  2535. // 处理具体职位名称
  2536. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2537. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2538. }
  2539. }
  2540. // 释放引用,防止意外修改后续代码
  2541. unset($value);
  2542. }
  2543. $result['job_experience'] = $job_experience ?? [];
  2544. }
  2545. if (!empty($job[0]['education_experience'])) {
  2546. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  2547. if (!empty($education_experience)) {
  2548. foreach ($education_experience as $key => $value) {
  2549. // $id = $value['id'];
  2550. $education[$key] = $value['school_education'];
  2551. }
  2552. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  2553. // // 先将关联表转换为索引数组,提高查找效率
  2554. $educationLookup = [];
  2555. foreach ($education_table as $item) {
  2556. $educationLookup[$item['evalue']] = $item['ename'];
  2557. }
  2558. foreach ($education_experience as $key => &$value) {
  2559. // 处理学历名称
  2560. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2561. $value['education_name'] = $educationLookup[$education[$key]];
  2562. }
  2563. }
  2564. }
  2565. $result['education_experience'] = $job_experience ?? [];
  2566. }
  2567. $result['job'] = $this->processJob($job, $webid);
  2568. // // 返现对应的栏目
  2569. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2570. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2571. ->whereIn('category_id', $catid)
  2572. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2573. ->orderBy('pid')->get()->all();
  2574. if (!empty($category)) {
  2575. $result['category'] = $category;
  2576. }
  2577. $result['job'] = $job;
  2578. $result['job_experience'] = $job_experience ?? [];
  2579. $result['education_experience'] = $education_experience ?? [];
  2580. if (empty($result)) {
  2581. return Result::error("参数错误", 0);
  2582. }
  2583. return Result::success($result);
  2584. }
  2585. /**
  2586. * c端-申请职位
  2587. * @param array $data
  2588. * @return array
  2589. * */
  2590. public function getWebsiteJobApply(array $data): array
  2591. {
  2592. // 首先验证网站是否存在
  2593. // return Result::success($data);
  2594. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2595. if (empty($web)) {
  2596. return Result::error("该网站不存在", 0);
  2597. }
  2598. // 验证用户是否存在且为个人会员/管理员
  2599. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2600. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2601. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  2602. return Result::error("用户不存在", 0);
  2603. }
  2604. // 去除重复元素和空元素,并保持原始顺序
  2605. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  2606. return !empty($value);
  2607. }));
  2608. // 验证职位是否存在 1:审核通过
  2609. $recruiting = JobRecruiting::where('status', 1)
  2610. ->where('website_id', $data['website_id'])
  2611. ->whereIn('id', $data['recruit_id'])
  2612. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  2613. if (empty($recruiting)) {
  2614. return Result::error("该职位不存在", 0);
  2615. }
  2616. // 简历是否存在
  2617. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  2618. if (empty($hunt_id)) {
  2619. return Result::error("该简历不存在", 0);
  2620. }
  2621. $data['hunt_id'] = $hunt_id['hunt_id'];
  2622. // // 验证是否已投递过该职位
  2623. $apply = JobApply::where('user_id', $data['user_id'])
  2624. ->where('hunt_id', $data['hunt_id'])
  2625. ->where('website_id', $data['website_id'])
  2626. ->whereIn('recruit_id', $data['recruit_id'])
  2627. ->get(['recruit_id']);
  2628. if (!empty($apply->toArray())) {
  2629. return Result::error("您已投递过该职位!");
  2630. }
  2631. $insertData = array_map(function ($recruiting) use ($data) {
  2632. return [
  2633. 'user_id' => $data['user_id'],
  2634. 'hunt_id' => $data['hunt_id'],
  2635. 'website_id' => $data['website_id'],
  2636. 'recruit_id' => $recruiting['recruit_id'],
  2637. 'receiver_id' => $recruiting['receiver_id'],
  2638. 'status' => 1,
  2639. ];
  2640. }, $recruiting);
  2641. // 批量插入数据
  2642. $result = JobApply::insert($insertData);
  2643. if (empty($result)) {
  2644. return Result::error("投递失败", 0);
  2645. }
  2646. return Result::success($result);
  2647. }
  2648. /**
  2649. * 招工招聘-沟通简历
  2650. * @param array $data
  2651. * @return array
  2652. * */
  2653. public function getWebsiteJobResume(array $data): array
  2654. {
  2655. // 首先验证网站是否存在
  2656. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2657. if (empty($web)) {
  2658. return Result::error("该网站不存在", 0);
  2659. }
  2660. // return Result::success($data);
  2661. // 验证用户是否存在且为企业会员/管理员
  2662. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2663. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2664. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2665. return Result::error("用户不存在", 0);
  2666. }
  2667. // 去除重复元素和空元素,并保持原始顺序
  2668. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  2669. return !empty($value);
  2670. }));
  2671. // 验证简历是否存在
  2672. $hunting = JobHunting::where('status', 2)
  2673. ->where('website_id', $data['website_id'])
  2674. ->whereIn('id', $data['hunt_id'])
  2675. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  2676. if (empty($hunting)) {
  2677. return Result::error("该简历不存在", 0);
  2678. }
  2679. // 验证是否已沟通过该简历
  2680. $remuse = JobRemuse::where('user_id', $data['user_id'])
  2681. ->where('recruit_id', $data['recruit_id'])
  2682. ->where('website_id', $data['website_id'])
  2683. ->whereIn('hunt_id', $data['hunt_id'])
  2684. ->get(['hunt_id']);
  2685. if (!empty($remuse->toArray())) {
  2686. return Result::error("您已沟通过该简历!");
  2687. }
  2688. // 准备要插入的数据数组
  2689. $insertData = array_map(function ($hunting) use ($data) {
  2690. return [
  2691. 'user_id' => $data['user_id'],
  2692. 'recruit_id' => $data['recruit_id'],
  2693. 'website_id' => $data['website_id'],
  2694. 'hunt_id' => $hunting['hunt_id'],
  2695. 'receiver_id' => $hunting['receiver_id'],
  2696. 'status' => 1,
  2697. ];
  2698. }, $hunting);
  2699. // 批量插入数据
  2700. $result = JobRemuse::insert($insertData);
  2701. if (empty($result)) {
  2702. return Result::error("沟通失败", 0);
  2703. }
  2704. return Result::success($result);
  2705. }
  2706. /**
  2707. * 招工招聘 -我的职位(企业会员)
  2708. * @param array $data
  2709. * @return array
  2710. */
  2711. public function getWebsiteJobRecruiting(array $data): array
  2712. {
  2713. $web = Website::where('id', $data['website_id'])->first('id');
  2714. if (empty($web)) {
  2715. return Result::error("该网站不存在", 0);
  2716. }
  2717. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2718. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  2719. return Result::error("用户暂无权限!", 0);
  2720. }
  2721. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2722. $result = JobRecruiting::where('website_id', $data['website_id'])
  2723. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  2724. $query->where('user_id', $user['id']);
  2725. })
  2726. ->where('status', 1)
  2727. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  2728. ->orderBy('updated_at', 'desc')
  2729. ->limit($data['pageSize'])
  2730. ->get();
  2731. if (empty($result)) {
  2732. return Result::error("暂无相关职位信息", 0);
  2733. }
  2734. return Result::success($result);
  2735. }
  2736. /*
  2737. * 获取职位
  2738. * */
  2739. public function getPositionList(array $data): array
  2740. {
  2741. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  2742. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  2743. } else {
  2744. $result = JobPosition::where('zwpid', 0)->get()->all();
  2745. }
  2746. if (empty($result)) {
  2747. return Result::error("暂无此职位", 0);
  2748. }
  2749. return Result::success($result);
  2750. }
  2751. /**
  2752. * 招工招聘 - 获取推荐职位
  2753. * @param array $data
  2754. * @return array
  2755. */
  2756. public function getWebsiteLevelJob(array $data): array
  2757. {
  2758. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2759. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  2760. ->where('job_recruiting.status', 1)
  2761. ->where('job_level', $data['job_level'])
  2762. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2763. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  2764. ->orderBy('job_recruiting.updated_at', 'desc')
  2765. ->limit($data['pageSize'])
  2766. ->get();
  2767. $web = ['website_id' => $data['website_id']];
  2768. if (!empty($job)) {
  2769. $result = $this->processJob($job, $web);
  2770. }
  2771. if (empty($result)) {
  2772. return Result::error("暂无相关职位信息", 0);
  2773. }
  2774. return Result::success($result);
  2775. }
  2776. /**
  2777. * 招工招聘 - 根据栏目获取职位
  2778. * @param array $data
  2779. * @return array
  2780. */
  2781. public function getWebsiteCategoryJob(array $data): array
  2782. {
  2783. $categorys = json_decode($data['id'], true);
  2784. if (!empty($categorys)) {
  2785. $category_arr = $this->processArticlePro($data['website_id']);
  2786. $cat_1st_arr = $category_arr['cat_1st_arr'];
  2787. $catiall = $category_arr['catiall'];
  2788. foreach ($categorys as $key => $val) {
  2789. if (isset($val['id']) && !empty($val['id'])) {
  2790. $catid = explode(',', $val['id'])[0] ?? null;
  2791. $type = explode(',', $val['id'])[1] ?? null;
  2792. $textnum = explode(',', $val['id'])[2] ?? null;
  2793. }
  2794. // 4:招聘;5:求职;
  2795. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  2796. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  2797. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  2798. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2799. ->where('job_recruiting.status', 1)
  2800. ->where('job_recruiting.website_id', $data['website_id'])
  2801. ->select(
  2802. 'job_recruiting.id',
  2803. 'job_recruiting.title',
  2804. 'job_company.business_name',
  2805. 'job_recruiting.updated_at',
  2806. 'job_recruiting.cat_arr_id',
  2807. 'job_recruiting.keyword',
  2808. 'job_recruiting.description'
  2809. )
  2810. ->orderBy('job_recruiting.updated_at', 'desc')
  2811. ->limit($textnum)
  2812. ->get()->all();
  2813. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  2814. // 状态 审核状态,1待审核2已审核3已拒绝
  2815. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  2816. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  2817. ->where('job_hunting.status', 2)
  2818. ->where('job_hunting.website_id', $data['website_id'])
  2819. ->select(
  2820. 'job_hunting.id',
  2821. 'job_hunting.name',
  2822. 'job_hunting.cat_arr_id',
  2823. 'job_position.zwname as job_name',
  2824. 'job_hunting.updated_at',
  2825. // 'job_hunting.keyword',
  2826. 'job_hunting.slelf_evaluation'
  2827. )
  2828. ->orderBy('updated_at', 'desc')
  2829. ->limit($textnum)
  2830. ->get()->all();
  2831. } else {
  2832. $job = [];
  2833. }
  2834. // var_dump($catid.'222uuuuuuu'.$key);
  2835. if (!empty($job)) {
  2836. foreach ($job as $k => $value) {
  2837. if (isset($value->cat_arr_id)) {
  2838. $catArr = json_decode($value->cat_arr_id, true);
  2839. $catId = end($catArr);
  2840. } else {
  2841. continue;
  2842. }
  2843. if (isset($catiall[$catId])) {
  2844. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  2845. }
  2846. }
  2847. }
  2848. // var_dump($catid.'xxxxx'.$key);
  2849. $result[$key] = $job ?? [];
  2850. }
  2851. }
  2852. if (empty($result)) {
  2853. return Result::error("暂无相关分类信息", 0);
  2854. }
  2855. return Result::success($result);
  2856. }
  2857. // 封装处理由问题
  2858. function processJob($job, $data)
  2859. {
  2860. return $job->map(function ($job) use ($data) {
  2861. $category = $job->cat_arr_id ?? '';
  2862. $cityid = $job->city_arr_id ?? '';
  2863. $city = json_decode($cityid, true);
  2864. $pinyin = '';
  2865. $level = json_decode($category, true);
  2866. // 路由
  2867. if (!empty($level) && is_array($level)) {
  2868. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2869. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2870. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2871. ->get(['aLIas_pinyin'])
  2872. ->pluck('aLIas_pinyin')
  2873. ->implode('/');
  2874. if (empty($pinyin)) {
  2875. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2876. }
  2877. $job->pinyin = $pinyin;
  2878. }
  2879. // 取职位-城市 市??省
  2880. if (!empty($city) && is_array($city)) {
  2881. if (isset($city[1]) && !empty($city[1])) {
  2882. $city = District::where('id', $city[1])->first(['name']);
  2883. $job->city_name = $city->name ?? '';
  2884. } else if (isset($city[0]) && !empty($city[0])) {
  2885. $city = District::where('id', $city[0])->first(['name']);
  2886. $job->city_name = $city->name ?? '';
  2887. } else {
  2888. $job->city_name = '全国';
  2889. }
  2890. }
  2891. // 获取简历最后一级地区
  2892. if (isset($job->city_id) && !empty($job->city_id)) {
  2893. $city = District::where('id', $job->city_id)->first(['name']);
  2894. $job->hunt_cityname = $city->name ?? '';
  2895. }
  2896. // 组合详细地址
  2897. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2898. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2899. if (is_array($address_id) && !empty($address_id)) {
  2900. $address = District::whereIn('id', $address_id)
  2901. ->orderBy('level', 'asc')
  2902. ->get(['name'])
  2903. ->pluck('name')
  2904. ->implode('');
  2905. // $job->address_name = $address ?? '';
  2906. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2907. }
  2908. }
  2909. // 取行业
  2910. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2911. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2912. if (!empty($job->industry)) {
  2913. $query->where('hyid', $job->industry);
  2914. } else if (!empty($job->hy_id)) {
  2915. $query->where('hyid', $job->hy_id);
  2916. } else if (!empty($job->company_hy_id)) {
  2917. $query->where('hyid', $job->company_hy_id);
  2918. } else {
  2919. $query->where('hyid', $job->job_industry);
  2920. }
  2921. })->first(['hyname']);
  2922. $job->hy_name = $hy_name->hyname ?? '';
  2923. }
  2924. // 取职位类别
  2925. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2926. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2927. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2928. $job->zw_name = $zw_name->zwname ?? '';
  2929. }
  2930. // 取具体职位
  2931. if ((isset($job->jtzw_id) && !empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get)) || (isset($job->job_name) && !empty($job->job_name))) {
  2932. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2933. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2934. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2935. }
  2936. // 取工作经验
  2937. if (isset($job->experience) && !empty($job->experience)) {
  2938. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2939. $job->experience_name = $experience->ename ?? '';
  2940. }
  2941. // 取学历
  2942. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2943. $education = $job->educational ?? $job->school_education;
  2944. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2945. $job->education_name = $education->ename ?? '';
  2946. }
  2947. // 语言
  2948. if (isset($job->language) && !empty($job->language)) {
  2949. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2950. $job->language_name = $language->ename ?? '';
  2951. }
  2952. // 薪资
  2953. if (isset($job->salary) && !empty($job->salary)) {
  2954. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2955. $job->salary_name = $salary->ename ?? '';
  2956. }
  2957. // 职位性质
  2958. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2959. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2960. $job->job_nature_name = $job_nature->ename ?? '';
  2961. }
  2962. // 公司规模
  2963. if (isset($job->company_size) && !empty($job->company_size)) {
  2964. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2965. $job->company_size_name = $company_size->ename ?? '';
  2966. }
  2967. // 公司性质
  2968. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2969. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2970. $job->company_nature_name = $company_nature->nature_name ?? '';
  2971. }
  2972. // $job->pinyin = $pinyin;
  2973. return $job;
  2974. });
  2975. }
  2976. /**
  2977. * 获取书籍模块
  2978. * @param array $data
  2979. * @return array
  2980. * */
  2981. public function getWebsiteBook(array $data): array
  2982. {
  2983. $input['id'] = $data['id'];
  2984. $input['website_id'] = $data['website_id'];
  2985. // 将 JSON 字符串转换为 PHP 数组
  2986. $data = json_decode($input['id'], true);
  2987. // 使用 array_map 处理每个元素
  2988. $result = array_map(function ($item) use ($input) {
  2989. // 检查parent元素是否存在且不是undefined
  2990. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2991. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2992. $website = [
  2993. 'website_id' => $input['website_id'],
  2994. ];
  2995. // 查询栏目名称
  2996. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2997. if (empty($category)) {
  2998. $parent_alias = '';
  2999. $parent_pinyin = null;
  3000. $imgBooks = [];
  3001. $textBooks = [];
  3002. } else {
  3003. $parent_alias = $category->alias ?? '';
  3004. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3005. // 查找子分类ID数组
  3006. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3007. array_push($childCategoryIds, $parentCatId);
  3008. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3009. if ($parentImgNum != 0) {
  3010. // 查询图片新闻
  3011. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3012. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3013. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3014. })
  3015. ->where('book.status', 2)
  3016. ->where('book.img_url', '!=', '')
  3017. ->where('book.website_id', $website['website_id'])
  3018. ->leftJoin('website_category', function ($join) use ($website) {
  3019. $join->on('book.cat_id', '=', 'website_category.category_id')
  3020. ->where('website_category.website_id', '=', $website['website_id']);
  3021. })
  3022. ->select(
  3023. 'book.id',
  3024. 'book.title',
  3025. 'book.img_url',
  3026. 'book.price',
  3027. 'book.market_price',
  3028. 'book.description',
  3029. 'book.cat_id',
  3030. 'book.description',
  3031. 'book.updated_at',
  3032. 'website_category.alias as category_name',
  3033. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3034. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3035. )
  3036. ->orderBy('updated_at', 'desc')
  3037. ->limit($parentImgNum)
  3038. ->get()->all();
  3039. // 查询文字新闻
  3040. }
  3041. if ($parentTextNum != 0) {
  3042. $textBooks = [];
  3043. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3044. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3045. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3046. })
  3047. ->where('book.status', 2)
  3048. ->where('book.website_id', $website['website_id'])
  3049. ->leftJoin('website_category', function ($join) use ($website) {
  3050. $join->on('book.cat_id', '=', 'website_category.category_id')
  3051. ->where('website_category.website_id', '=', $website['website_id']);
  3052. })
  3053. ->select(
  3054. 'book.id',
  3055. 'book.title',
  3056. 'book.img_url',
  3057. 'book.price',
  3058. 'book.market_price',
  3059. 'book.description',
  3060. 'book.cat_id',
  3061. 'book.description',
  3062. 'book.updated_at',
  3063. 'website_category.alias as category_name',
  3064. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3065. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3066. )
  3067. ->orderBy('updated_at', 'desc')
  3068. ->limit($parentTextNum)
  3069. ->get()->all();
  3070. }
  3071. }
  3072. }
  3073. $resultItem = [
  3074. 'alias' => $parent_alias ?? '',
  3075. 'category_id' => $parentCatId ?? 0,
  3076. 'pinyin' => $parent_pinyin ?? null,
  3077. 'imgnum' => $imgBooks ?? [],
  3078. 'textnum' => $textBooks ?? [],
  3079. ];
  3080. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3081. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3082. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3083. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3084. ->get()->all();
  3085. if (!empty($childCategory)) {
  3086. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3087. // 查询子栏目名称
  3088. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3089. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3090. ->first();
  3091. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3092. $childImgArticles = [];
  3093. $childTextArticles = [];
  3094. $resultItem['child'] = [];
  3095. } else {
  3096. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3097. // 查询子栏目图片新闻
  3098. $childImgArticles = Book::where('cat_id', $childCatId)
  3099. ->where('status', 2)
  3100. ->where('img_url', '!=', '')
  3101. ->where('book.website_id', $website['website_id'])
  3102. ->leftJoin('website_category', function ($join) use ($website) {
  3103. $join->on('book.cat_id', '=', 'website_category.category_id')
  3104. ->where('website_category.website_id', '=', $website['website_id']);
  3105. })
  3106. ->select(
  3107. 'book.id',
  3108. 'book.title',
  3109. 'book.img_url',
  3110. 'book.price',
  3111. 'book.market_price',
  3112. 'book.description',
  3113. 'book.cat_id',
  3114. 'book.description',
  3115. 'book.updated_at',
  3116. DB::raw("'$child_pinyin' as pinyin")
  3117. )
  3118. ->orderBy('updated_at', 'desc')
  3119. ->limit($childImgNum)
  3120. ->get()->all();
  3121. // 查询子栏目文字新闻
  3122. $childTextArticles = Book::where('cat_id', $childCatId)
  3123. ->where('status', 2)
  3124. ->where('book.website_id', $website['website_id'])
  3125. ->leftJoin('website_category', function ($join) use ($website) {
  3126. $join->on('book.cat_id', '=', 'website_category.category_id')
  3127. ->where('website_category.website_id', '=', $website['website_id']);
  3128. })
  3129. ->select(
  3130. 'book.id',
  3131. 'book.title',
  3132. 'book.img_url',
  3133. 'book.price',
  3134. 'book.market_price',
  3135. 'book.description',
  3136. 'book.cat_id',
  3137. 'book.description',
  3138. 'book.updated_at',
  3139. DB::raw("'$child_pinyin' as pinyin")
  3140. )
  3141. ->orderBy('updated_at', 'desc')
  3142. ->limit($childTextNum)
  3143. ->get()->all();
  3144. $resultItem['child'] = [
  3145. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3146. 'category_id' => $childCatId,
  3147. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3148. 'all_childcat' => $childCategory,
  3149. 'imgnum' => $childImgArticles,
  3150. 'textnum' => $childTextArticles,
  3151. ];
  3152. }
  3153. }
  3154. } else {
  3155. $resultItem['child'] = [];
  3156. }
  3157. return $resultItem;
  3158. }, $data);
  3159. return Result::success($result);
  3160. }
  3161. /**
  3162. * 获取书刊列表
  3163. * @param array $data
  3164. * @return array
  3165. * */
  3166. public function getWebsiteBookList(array $data): array
  3167. {
  3168. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3169. if (empty($web)) {
  3170. return Result::error("查询失败", 0);
  3171. }
  3172. $catid = $data['id'];
  3173. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3174. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3175. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3176. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3177. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3178. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3179. ->where('pid', $category['pid'])
  3180. ->select(
  3181. 'category_id',
  3182. 'alias',
  3183. 'aLIas_pinyin',
  3184. 'pid',
  3185. 'sort',
  3186. 'is_url',
  3187. 'web_url',
  3188. 'seo_title',
  3189. 'seo_keywords',
  3190. 'seo_description',
  3191. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3192. )
  3193. ->orderBy('sort')
  3194. ->get()->all();
  3195. if (empty($category)) {
  3196. return Result::error("查询失败", 0);
  3197. }
  3198. $query = Book::where('book.status', 2)
  3199. ->where('book.website_id', $data['website_id'])
  3200. ->where('book.cat_id', $catid)
  3201. ->select(
  3202. 'book.id',
  3203. 'book.title',
  3204. 'book.img_url',
  3205. 'book.description',
  3206. 'book.updated_at',
  3207. 'book.cat_id',
  3208. DB::raw("'$pinyin' as pinyin")
  3209. )
  3210. ->orderBy('book.updated_at', 'desc');
  3211. $count = $query->count();
  3212. $query = clone $query;
  3213. $Book = $query
  3214. ->limit($data['pageSize'])
  3215. ->offset(($data['page'] - 1) * $data['pageSize'])
  3216. ->get()->all();
  3217. $result = [
  3218. 'category' => $categorys,
  3219. 'books' => $Book,
  3220. 'count' => $count,
  3221. ];
  3222. // if(empty($result)){
  3223. // return Result::error("查询失败", 0);
  3224. // }
  3225. return Result::success($result);
  3226. }
  3227. /**
  3228. * 获取书刊详情
  3229. * @param array $data
  3230. * @return array
  3231. * */
  3232. public function getWebsiteBookInfo(array $data): array
  3233. {
  3234. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3235. if (empty($web)) {
  3236. return Result::error("查询失败", 0);
  3237. }
  3238. $book = Book::where('status', 2)
  3239. ->where('website_id', $data['website_id'])
  3240. ->where('id', $data['id'])
  3241. ->select(
  3242. 'book.*',
  3243. )
  3244. ->orderBy('updated_at', 'desc')
  3245. ->first();
  3246. if (empty($book)) {
  3247. return Result::error("查询失败", 0);
  3248. }
  3249. // 先查询当前分类的 pid
  3250. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3251. ->where('category_id', $book['cat_id'])
  3252. ->first(['pid', 'category_id']);
  3253. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3254. if (!empty($carpid)) {
  3255. if ($carpid->pid != 0) {
  3256. $pid = $carpid['pid'];
  3257. // $parent_pinyin = '';
  3258. } else {
  3259. $pid = $carpid['category_id'];
  3260. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3261. }
  3262. }
  3263. $categorys = $query->where('pid', $pid)
  3264. ->select(
  3265. 'category_id',
  3266. 'alias',
  3267. 'aLIas_pinyin',
  3268. 'pid',
  3269. 'sort',
  3270. 'is_url',
  3271. 'web_url',
  3272. 'category_arr_id as cat_arr_id',
  3273. )
  3274. ->orderBy('sort')
  3275. ->get();
  3276. $category = $this->processArticle($categorys, $data);
  3277. $result = [
  3278. 'category' => $category,
  3279. 'books' => $book,
  3280. ];
  3281. return Result::success($result);
  3282. }
  3283. /**
  3284. * 封装处理文章的路由问题
  3285. * */
  3286. function processArticle($article, $data)
  3287. {
  3288. return $article->map(function ($article) use ($data) {
  3289. $catid = $article->cat_arr_id ?? '';
  3290. $level = json_decode($catid, true);
  3291. $pinyin = '';
  3292. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3293. if (!empty($level) && is_array($level)) {
  3294. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3295. ->where('website_id', $data['website_id'])
  3296. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3297. ->get(['aLIas_pinyin'])
  3298. ->pluck('aLIas_pinyin')
  3299. ->implode('/');
  3300. } else {
  3301. $pinyin = '';
  3302. }
  3303. $article->pinyin = $pinyin;
  3304. return $article;
  3305. });
  3306. }
  3307. /**
  3308. * @param array $data
  3309. * @return array
  3310. */
  3311. public function getWebsiteCompany(array $data): array
  3312. {
  3313. $categorys = json_decode($data['id'], true);
  3314. $category_arr = $this->processArticlePro($data['website_id']);
  3315. $cat_1st_arr = $category_arr['cat_1st_arr'];
  3316. $catiall = $category_arr['catiall'];
  3317. $categoryIds = $category_arr['categoryIds'];
  3318. // return Result::success($category_arr);
  3319. foreach ($categorys as $key => $value) {
  3320. if (array_key_exists('level', $value)) {
  3321. $parts = explode(',', $value['level']);
  3322. $level = $parts[0] ?? null;
  3323. $imgnum = $parts[1] ?? null;
  3324. $textnum = $parts[2] ?? null;
  3325. if (!empty($textnum) && $textnum > 0) {
  3326. $text_num = Company::where('level', $level)
  3327. ->whereIn('category_id', $categoryIds)
  3328. ->where('status', 1)
  3329. ->select(
  3330. 'company.id',
  3331. 'company.title',
  3332. 'company.description',
  3333. 'company.updated_at',
  3334. 'company.category_id',
  3335. 'company.cat_arr_id'
  3336. )
  3337. ->orderBy('updated_at', 'desc')
  3338. ->limit($textnum)
  3339. ->get()->all();
  3340. }
  3341. if (!empty($imgnum) && $imgnum > 0) {
  3342. $img_num = Company::where('level', $level)
  3343. ->whereIn('category_id', $categoryIds)
  3344. ->where('status', 1)
  3345. ->where('imgurl', '!=', '')
  3346. ->whereNotNull('imgurl')
  3347. ->select(
  3348. 'company.id',
  3349. 'company.title',
  3350. 'company.description',
  3351. 'company.updated_at',
  3352. 'company.imgurl as imgs',
  3353. 'company.category_id',
  3354. 'company.cat_arr_id'
  3355. )
  3356. ->orderBy('updated_at', 'desc')
  3357. ->limit($imgnum)
  3358. ->get()->all();
  3359. }
  3360. }
  3361. if (array_key_exists('id', $value)) {
  3362. $parts = explode(',', $value['id']);
  3363. $category_id = $parts[0] ?? null;
  3364. $imgnum = $parts[1] ?? null;
  3365. $textnum = $parts[2] ?? null;
  3366. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  3367. if (!empty($textnum) && $textnum > 0) {
  3368. $text_num = Company::whereIn('category_id', $category_arr)
  3369. // ->where('website_id', $data['website_id'])
  3370. ->where('status', 1)
  3371. ->select(
  3372. 'company.id',
  3373. 'company.title',
  3374. 'company.description',
  3375. 'company.updated_at',
  3376. 'company.category_id',
  3377. 'company.cat_arr_id'
  3378. )
  3379. ->orderBy('updated_at', 'desc')
  3380. ->limit($textnum)
  3381. ->get()->all();
  3382. }
  3383. if (!empty($imgnum) && $imgnum > 0) {
  3384. $img_num = Company::whereIn('category_id', $category_arr)
  3385. // ->where('website_id', $data['website_id'])
  3386. ->where('status', 1)
  3387. ->where('imgurl', '!=', '')
  3388. ->whereNotNull('imgurl')
  3389. ->select(
  3390. 'company.id',
  3391. 'company.title',
  3392. 'company.description',
  3393. 'company.updated_at',
  3394. 'company.imgurl as imgs',
  3395. 'company.category_id',
  3396. 'company.cat_arr_id'
  3397. )
  3398. ->orderBy('updated_at', 'desc')
  3399. ->limit($imgnum)
  3400. ->get()->all();
  3401. }
  3402. }
  3403. if (!empty($text_num)) {
  3404. foreach ($text_num as $k => $v) {
  3405. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  3406. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  3407. }
  3408. }
  3409. if (!empty($img_num)) {
  3410. foreach ($img_num as $k => $v) {
  3411. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  3412. $imgurl = json_decode($v['imgs'], true);
  3413. if (!empty($imgurl)) {
  3414. $img_num[$k]->imgurl = $imgurl[0];
  3415. }
  3416. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  3417. }
  3418. }
  3419. $company[$key]['img_num'] = $img_num ?? [];
  3420. $company[$key]['text_num'] = $text_num ?? [];
  3421. }
  3422. if (empty($company)) {
  3423. return Result::error("暂无相关企业信息", 0);
  3424. }
  3425. return Result::success($company);
  3426. }
  3427. /**
  3428. * @param array $data
  3429. * @return array
  3430. */
  3431. public function getWebsiteCompanyList(array $data): array
  3432. {
  3433. $where['website_id'] = $data['website_id'];
  3434. $where['status'] = 1;
  3435. $categoryIds = [];
  3436. if (isset($data['category_id']) && !empty($data['category_id'])) {
  3437. $category_id = $data['category_id'];
  3438. }
  3439. $category_arr = $this->processArticlePro($data['website_id']);
  3440. $categoryIds = $category_arr['categoryIds'];
  3441. // return Result::success($cat_1st_arr);
  3442. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  3443. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  3444. })
  3445. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  3446. $query->whereIn('category_id', $categoryIds);
  3447. })
  3448. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  3449. $query->where('category_id', $category_id);
  3450. })
  3451. ->where('status',1)
  3452. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  3453. ->orderBy('updated_at', 'desc')
  3454. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  3455. if (empty($company)) {
  3456. return Result::error("暂无相关公司信息", 0);
  3457. }
  3458. $result = [
  3459. 'count' => $company->total(),
  3460. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  3461. ];
  3462. return Result::success($result);
  3463. }
  3464. public function getWebsiteCompanyInfo(array $data): array
  3465. {
  3466. $company = Company::where('id', $data['id'])
  3467. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  3468. ->where('status', 1)
  3469. // ->where('website_id', $data['website_id'])
  3470. ->select('company.*', 'job_industry.hyname as hy_name')
  3471. ->first();
  3472. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  3473. $jobnature_id = $company['jobnature_id'] ?? null;
  3474. if ($jobnature_id !== null) {
  3475. switch ($jobnature_id) {
  3476. case 0:
  3477. $company->jobnature_name = '市场监督';
  3478. break;
  3479. case 1:
  3480. $company->jobnature_name = '信访纪检';
  3481. break;
  3482. case 2:
  3483. $company->jobnature_name = '公检法司';
  3484. break;
  3485. case 3:
  3486. $company->jobnature_name = '高关注机构';
  3487. break;
  3488. default:
  3489. $company->jobnature_name = '';
  3490. break;
  3491. }
  3492. } else {
  3493. $company->jobnature_name = '';
  3494. }
  3495. $city_arr = $company->city_arr_id;
  3496. if (!empty($city_arr)) {
  3497. $city_arr = json_decode($city_arr, true);
  3498. $cityNames = District::whereIn('id', $city_arr)
  3499. ->pluck('name')
  3500. ->implode('-');
  3501. $company->city_name = $cityNames;
  3502. } else {
  3503. $company->city_name = '';
  3504. }
  3505. if (empty($company)) {
  3506. return Result::error("暂无相关公司信息", 0);
  3507. }
  3508. return Result::success($company);
  3509. }
  3510. /**
  3511. * @param array $data
  3512. * @return array
  3513. */
  3514. public function getWebsiteProject(array $data): array
  3515. {
  3516. $categorys = json_decode($data['id'], true);
  3517. if (!empty($categorys)) {
  3518. $category_arr = $this->processArticlePro($data['website_id']);
  3519. $cat_1st_arr = $category_arr['cat_1st_arr'];
  3520. $catiall = $category_arr['catiall'];
  3521. // return Result::success($catiall);
  3522. foreach ($categorys as $key => $val) {
  3523. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  3524. $level = explode(',', $val['level'])[0];
  3525. $imgnum = explode(',', $val['level'])[1] ?? null;
  3526. $textnum = explode(',', $val['level'])[2] ?? null;
  3527. if ($level == 1) {
  3528. if (!empty($textnum) && $textnum > 0) {
  3529. $text_num = Project::where('level', $level)
  3530. ->where('website_id', $data['website_id'])
  3531. ->where('status', 1)
  3532. ->select(
  3533. 'project.id',
  3534. 'project.title',
  3535. 'project.description',
  3536. 'project.updated_at',
  3537. 'project.category_id',
  3538. 'project.cat_arr_id'
  3539. )
  3540. ->orderBy('updated_at', 'desc')
  3541. ->limit($textnum)
  3542. ->get()->all();
  3543. }
  3544. if (!empty($imgnum) && $imgnum > 0) {
  3545. $img_num = Project::where('level', $level)
  3546. ->where('website_id', $data['website_id'])
  3547. ->where('status', 1)
  3548. ->where('imgurl', '!=', '')
  3549. ->whereNotNull('imgurl')
  3550. ->select(
  3551. 'project.id',
  3552. 'project.title',
  3553. 'project.description',
  3554. 'project.updated_at',
  3555. 'project.imgurl as imgs',
  3556. 'project.category_id',
  3557. 'project.cat_arr_id'
  3558. )
  3559. ->orderBy('updated_at', 'desc')
  3560. ->limit($imgnum)
  3561. ->get()->all();
  3562. }
  3563. } else {
  3564. if (!empty($textnum) && $textnum > 0) {
  3565. $text_num = Project::where('website_id', $data['website_id'])
  3566. ->where('status', 1)
  3567. ->select(
  3568. 'project.id',
  3569. 'project.title',
  3570. 'project.description',
  3571. 'project.updated_at',
  3572. 'project.category_id',
  3573. 'project.cat_arr_id',
  3574. 'project.website_id',
  3575. 'project.updated_at',
  3576. 'project.created_at'
  3577. )
  3578. ->orderBy('updated_at', 'desc')
  3579. ->limit($textnum)
  3580. ->get()->all();
  3581. }
  3582. if (!empty($imgnum) && $imgnum > 0) {
  3583. $img_num = Project::where('website_id', $data['website_id'])
  3584. ->where('status', 1)
  3585. ->where('imgurl', '!=', '')
  3586. ->whereNotNull('imgurl')
  3587. ->select(
  3588. 'project.id',
  3589. 'project.title',
  3590. 'project.description',
  3591. 'project.updated_at',
  3592. 'project.imgurl as imgs',
  3593. 'project.category_id',
  3594. 'project.cat_arr_id'
  3595. )
  3596. ->orderBy('updated_at', 'desc')
  3597. ->limit($imgnum)
  3598. ->get()->all();
  3599. }
  3600. }
  3601. }
  3602. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  3603. $category_ids = explode(',', $val['id'])[0];
  3604. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  3605. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  3606. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  3607. if (!empty($cat_textnum) && $cat_textnum > 0) {
  3608. $text_num = Project::whereIn('category_id', $category_arr)
  3609. ->where('website_id', $data['website_id'])
  3610. ->where('status', 1)
  3611. ->select(
  3612. 'project.id',
  3613. 'project.title',
  3614. 'project.description',
  3615. 'project.updated_at',
  3616. 'project.category_id',
  3617. 'project.cat_arr_id'
  3618. )
  3619. ->orderBy('updated_at', 'desc')
  3620. ->limit($cat_textnum)
  3621. ->get()->all();
  3622. }
  3623. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  3624. $img_num = Project::whereIn('category_id', $category_arr)
  3625. ->where('website_id', $data['website_id'])
  3626. ->where('status', 1)
  3627. ->where('imgurl', '!=', '')
  3628. ->whereNotNull('imgurl')
  3629. ->select(
  3630. 'project.id',
  3631. 'project.title',
  3632. 'project.description',
  3633. 'project.updated_at',
  3634. 'project.imgurl as imgs',
  3635. 'project.category_id',
  3636. 'project.cat_arr_id'
  3637. )
  3638. ->orderBy('updated_at', 'desc')
  3639. ->limit($cat_imgnum)
  3640. ->get()->all();
  3641. }
  3642. }
  3643. if (!empty($img_num)) {
  3644. foreach ($img_num as $k => $v) {
  3645. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  3646. $imgurl = json_decode($v['imgs'], true);
  3647. if (!empty($imgurl)) {
  3648. $img_num[$k]->imgurl = $imgurl[0];
  3649. }
  3650. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  3651. }
  3652. }
  3653. if (!empty($text_num)) {
  3654. foreach ($text_num as $k => $v) {
  3655. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  3656. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  3657. }
  3658. }
  3659. $project[$key]['img_num'] = $img_num ?? [];
  3660. $project[$key]['text_num'] = $text_num ?? [];
  3661. }
  3662. }
  3663. if (empty($project)) {
  3664. return Result::error("暂无相关项目信息", 0);
  3665. }
  3666. return Result::success($project);
  3667. }
  3668. /**
  3669. * @param array $data
  3670. * @return array
  3671. */
  3672. public function getWebsiteProjectInfo(array $data): array
  3673. {
  3674. $project = Project::where('id', $data['id'])
  3675. ->where('status', 1)
  3676. ->where('website_id', $data['website_id'])
  3677. ->select('project.*')
  3678. ->first();
  3679. if (empty($project)) {
  3680. return Result::error("暂无相关项目信息", 0);
  3681. }
  3682. return Result::success($project);
  3683. }
  3684. /**
  3685. * @param array $data
  3686. * @return array
  3687. */
  3688. public function getWebsiteProjectList(array $data): array
  3689. {
  3690. $where = [];
  3691. if (isset($data['category_id']) && !empty($data['category_id'])) {
  3692. $where['category_id'] = $data['category_id'];
  3693. }
  3694. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3695. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  3696. }
  3697. $query = Project::where($where)
  3698. ->where('status', 1)
  3699. ->where('website_id', $data['website_id'])
  3700. ->select(
  3701. 'project.id',
  3702. 'project.title',
  3703. 'project.description',
  3704. 'project.imgurl as imgs',
  3705. 'project.category_id',
  3706. 'project.cat_arr_id'
  3707. )
  3708. ->orderBy('updated_at', 'desc');
  3709. $count = $query->count();
  3710. $project = $query->clone()
  3711. ->offset(($data['page'] - 1) * $data['pageSize'])
  3712. ->limit($data['pageSize'])
  3713. ->get()->all();
  3714. if (empty($project)) {
  3715. return Result::error("暂无相关项目信息", 0);
  3716. }
  3717. $categorys = $this->processArticlePro($data['website_id']);
  3718. $catiall = $categorys['catiall'];
  3719. foreach ($project as $key => $val) {
  3720. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  3721. if (!empty($val['imgs'])) {
  3722. $imgurl = json_decode($val['imgs'], true);
  3723. if (!empty($imgurl)) {
  3724. $project[$key]->imgurl = $imgurl[0];
  3725. }
  3726. } else {
  3727. $project[$key]->imgurl = '';
  3728. }
  3729. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  3730. }
  3731. $result = [
  3732. 'rows' => $project,
  3733. 'count' => $count,
  3734. ];
  3735. return Result::success($result);
  3736. }
  3737. /**
  3738. * @param array $data
  3739. * @return array
  3740. */
  3741. public function getWebsiteMessage(array $data): array
  3742. {
  3743. $web = Website::where('id',$data['website_id'])->first();
  3744. if (empty($web)) {
  3745. return Result::error("暂无相关网站信息", 0);
  3746. }
  3747. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  3748. $message = Message::whereIn('message.column_id', $column_arr)
  3749. ->where('message.status', 1)
  3750. ->leftJoin('user', 'message.user_id', '=', 'user.id')
  3751. ->select('message.title', 'message.content','message.reply',
  3752. 'message.updated_at','user.nickname')
  3753. ->orderBy('message.updated_at', 'desc')
  3754. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  3755. if (empty($message->items())) {
  3756. return Result::error("暂无相关消息信息", 0);
  3757. }
  3758. $result = [
  3759. 'data' => $message->items(),
  3760. 'count' => $message->total(),
  3761. ];
  3762. return Result::success($result);
  3763. }
  3764. /**
  3765. * @param array $data
  3766. * @return array
  3767. */
  3768. /**
  3769. * 获取省份城市列表
  3770. * @param array $data
  3771. * @return array
  3772. */
  3773. public function getWebsiteProvinceCity(array $data): array
  3774. {
  3775. $province_city = District::whereIn('level', [1,2])
  3776. ->select('id', 'name', 'pid', 'abbreviation','code')
  3777. ->get()->all();
  3778. if (empty($province_city)) {
  3779. return Result::error("暂无相关省份城市信息", 0);
  3780. }
  3781. $result = Result::buildCityTree($province_city);
  3782. return Result::success($result);
  3783. }
  3784. /**
  3785. * @param array $data
  3786. * @return array
  3787. */
  3788. public function getWebsiteResearchTopic(array $data): array
  3789. {
  3790. $web = Website::where('id',$data['website_id'])->first();
  3791. if (empty($web)) {
  3792. return Result::error("暂无相关网站信息", 0);
  3793. }
  3794. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  3795. $where['research_topic.level'] = 1;
  3796. $where['research_topic.status'] = 1;
  3797. if (isset($data['province_id']) && !empty($data['province_id'])) {
  3798. $where['research_topic.province_id'] = $data['province_id'];
  3799. }
  3800. if (isset($data['city_id']) && !empty($data['city_id'])) {
  3801. $where['research_topic.city_id'] = $data['city_id'];
  3802. }
  3803. if (isset($data['county_id']) && !empty($data['county_id'])) {
  3804. $where['research_topic.county_id'] = $data['county_id'];
  3805. }
  3806. if(isset($data['title']) && !empty($data['title'])){
  3807. array_push($where,['research_topic.title','like','%'.$data['title'].'%']);
  3808. }
  3809. $research_topic = ResearchTopic::whereIn('research_topic.column_id', $column_arr)
  3810. ->leftJoin('user_info', 'research_topic.user_id', '=', 'user_info.user_id')
  3811. ->with(['retopicUsers' => function ($query) {
  3812. $query->select('user_id','retopic_id');
  3813. }
  3814. ])
  3815. ->when(isset($data['number']), function ($query) use ($data) {
  3816. $query->where('user_info.number', $data['number']);
  3817. })
  3818. ->where($where)
  3819. ->select('research_topic.id', 'research_topic.title', 'research_topic.keyword',
  3820. 'research_topic.description','research_topic.province_id','research_topic.city_id',
  3821. 'research_topic.county_id','user_info.number','user_info.real_name','research_topic.due_time',
  3822. 'user_info.updated_at','research_topic.organization')
  3823. ->orderBy('research_topic.updated_at', 'desc')
  3824. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  3825. if (empty($research_topic->items())) {
  3826. return Result::error("暂无相关研究主题信息", 0);
  3827. }
  3828. $result = [
  3829. 'rows' => $research_topic->items(),
  3830. 'count' => $research_topic->total(),
  3831. ];
  3832. if(empty($research_topic->items())){
  3833. return Result::error("暂无相关调研选题!", 0);
  3834. }
  3835. if(isset($data['number'])){
  3836. $retopic_user = $result['rows'][0]['retopicUsers'];
  3837. if(!empty($retopic_user)){
  3838. $retopic_user = $retopic_user->pluck('user_id')->toArray();
  3839. foreach($retopic_user as $key => $value){
  3840. $real_name = UserInfo::where('user_id', $value)->value('real_name');
  3841. $real_name_arr[$key] = $real_name;
  3842. unset($result['rows'][0]['retopicUsers']);
  3843. }
  3844. $result['rows'][0]['txry_name'] = implode(' ',$real_name_arr);
  3845. }
  3846. }
  3847. return Result::success($result);
  3848. }
  3849. public function processWebColumn(): array
  3850. {
  3851. $pidQuery = WebsiteColumn::where('column_name','==','官网')
  3852. ->where('pid', '!=', 0)
  3853. ->where('type','!=',8)
  3854. ->orderBy('sort')
  3855. ->select('pid', 'category_id', 'alias', 'aLIas_pinyin');
  3856. $pid = $pidQuery->pluck('pid');
  3857. $query = WebsiteCategory::where($website_id)
  3858. ->where('type','!=',8)
  3859. ->where('pid', $pid)
  3860. ->offset($data['placeid'])
  3861. ->limit($data['num'])
  3862. ->orderBy('sort')
  3863. ->orderBy('updated_at', 'desc');
  3864. $result = $query->get()->all();
  3865. if (empty($result)) {
  3866. return Result::error("暂无相关分类信息", 0);
  3867. }
  3868. return Result::success($result);
  3869. }
  3870. }