WebService.php 150 KB

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