NewsService.php 153 KB

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