NewsService.php 120 KB

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