NewsService.php 120 KB

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