NewsService.php 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067
  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) || count($result) == 0) {
  752. return Result::error("暂无头条新闻");
  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('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. // 检查parent元素是否存在且不是undefined
  1371. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent']!= "") {
  1372. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1373. $website = [
  1374. 'website_id' => $input['website_id'],
  1375. ];
  1376. // 查询栏目名称
  1377. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1378. if(empty($category)){
  1379. $parent_alias = '';
  1380. $parent_pinyin = null;
  1381. $imgArticles = [];
  1382. $textArticles = [];
  1383. }else{
  1384. $parent_alias = $category->alias ?? '';
  1385. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1386. // 查找子分类ID数组
  1387. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1388. array_push($childCategoryIds,$parentCatId);
  1389. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  1390. if($parentImgNum!=0){
  1391. // 查询图片新闻
  1392. $imgArticles = Article::where('article.status', 1)
  1393. ->where(function($query) use ($parentCatId) {
  1394. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1395. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1396. })
  1397. ->where(function ($query) use ($website) {
  1398. $query->where(function ($subQuery) use ($website) {
  1399. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0")
  1400. ->orWhereNull("ignore_ids");
  1401. });
  1402. })
  1403. ->where('imgurl', '!=', '')
  1404. ->leftJoin('website_category', function($join) use ($website) {
  1405. $join->on('article.catid', '=', 'website_category.category_id')
  1406. ->where('website_category.website_id', '=', $website['website_id']);
  1407. })
  1408. ->select(
  1409. 'article.id',
  1410. 'article.title',
  1411. 'article.imgurl',
  1412. 'article.author',
  1413. 'article.updated_at',
  1414. 'article.introduce',
  1415. 'article.islink',
  1416. 'article.linkurl',
  1417. 'article.copyfrom',
  1418. 'article.catid',
  1419. 'website_category.alias as category_name',
  1420. DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin'
  1421. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  1422. )
  1423. ->orderBy('updated_at', 'desc')
  1424. ->limit($parentImgNum)
  1425. ->get()->all();
  1426. // 查询文字新闻
  1427. }
  1428. if($parentTextNum!=0){
  1429. $textArticles = [];
  1430. $textArticles = Article::where('article.status', 1)
  1431. ->where(function($query) use ($parentCatId) {
  1432. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  1433. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  1434. })
  1435. ->where(function ($query) use ($website) {
  1436. $query->where(function ($subQuery) use ($website) {
  1437. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0")
  1438. ->orWhereNull("ignore_ids");
  1439. });
  1440. })
  1441. ->leftJoin('website_category', function($join) use ($website) {
  1442. $join->on('article.catid', '=', 'website_category.category_id')
  1443. ->where('website_category.website_id', '=', $website['website_id']);
  1444. })
  1445. ->select(
  1446. 'article.id',
  1447. 'article.title',
  1448. 'article.imgurl',
  1449. 'article.author',
  1450. 'article.updated_at',
  1451. 'article.introduce',
  1452. 'article.islink',
  1453. 'article.linkurl',
  1454. 'article.copyfrom',
  1455. 'article.catid',
  1456. 'website_category.alias as category_name',
  1457. DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin'
  1458. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  1459. )
  1460. ->orderBy('updated_at', 'desc')
  1461. ->limit($parentTextNum)
  1462. ->get()->all();
  1463. }
  1464. }
  1465. }
  1466. $resultItem = [
  1467. 'alias' => $parent_alias ?? '',
  1468. 'category_id' => $parentCatId ?? 0,
  1469. 'pinyin' => $parent_pinyin ?? null,
  1470. 'imgnum' => $imgArticles ?? [],
  1471. 'textnum' => $textArticles ?? [],
  1472. ];
  1473. if(isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != ""){
  1474. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin.'/' : '';
  1475. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1476. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1477. ->get()->all();
  1478. if (!empty($childCategory)) {
  1479. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1480. // 查询子栏目名称
  1481. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1482. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1483. ->first();
  1484. if(empty($childCategoryInfo) || ($childImgNum==0 && $childTextNum==0)){
  1485. $childImgArticles = [];
  1486. $childTextArticles = [];
  1487. $resultItem['child'] = [];
  1488. }else{
  1489. $child_pinyin = $childCategoryInfo->aLIas_pinyin? $childCategoryInfo->aLIas_pinyin : null;
  1490. // 查询子栏目图片新闻
  1491. $childImgArticles = Article::where('catid', $childCatId)
  1492. ->where('status', 1)
  1493. ->where(function ($query) use ($website) {
  1494. $query->where(function ($subQuery) use ($website) {
  1495. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1496. })->orWhereNull("ignore_ids");
  1497. })
  1498. ->select(
  1499. 'article.id',
  1500. 'article.title',
  1501. 'article.imgurl',
  1502. 'article.author',
  1503. 'article.updated_at',
  1504. 'article.introduce',
  1505. 'article.islink',
  1506. 'article.linkurl',
  1507. 'article.copyfrom',
  1508. DB::raw("'$child_pinyin' as pinyin")
  1509. )
  1510. ->where('imgurl', '!=', '')
  1511. ->orderBy('updated_at', 'desc')
  1512. ->limit($childImgNum)
  1513. ->get()->all();
  1514. // 查询子栏目文字新闻
  1515. $childTextArticles = Article::where('catid', $childCatId)
  1516. ->where('status', 1)
  1517. ->where(function ($query) use ($website) {
  1518. $query->where(function ($subQuery) use ($website) {
  1519. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1520. })->orWhereNull("ignore_ids");
  1521. })
  1522. ->select(
  1523. 'article.id',
  1524. 'article.title',
  1525. 'article.author',
  1526. 'article.updated_at',
  1527. 'article.introduce',
  1528. 'article.islink',
  1529. 'article.linkurl',
  1530. 'article.copyfrom',
  1531. DB::raw("'$child_pinyin' as pinyin")
  1532. )
  1533. ->orderBy('updated_at', 'desc')
  1534. ->limit($childTextNum)
  1535. ->get()->all();
  1536. $resultItem['child'] = [
  1537. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1538. 'category_id' => $childCatId,
  1539. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1540. 'all_childcat' => $childCategory,
  1541. 'imgnum' => $childImgArticles,
  1542. 'textnum' => $childTextArticles,
  1543. ];
  1544. }
  1545. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1546. }
  1547. }else{
  1548. $resultItem['child'] = [];
  1549. }
  1550. return $resultItem;
  1551. }, $data);
  1552. return Result::success($result);
  1553. // return Result::success($data);
  1554. }
  1555. /**
  1556. * 乡村网-获取特殊新闻模块
  1557. * @param array $data
  1558. * @return array
  1559. */
  1560. public function getWebsiteArticles(array $data): array
  1561. {
  1562. $input['id'] = $data['id'];
  1563. $input['website_id'] = $data['website_id'];
  1564. $data = json_decode($input['id'], true);
  1565. // 使用 array_map 处理每个元素
  1566. $result = array_map(function ($item) use ($input) {
  1567. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1568. $website = [
  1569. 'website_id' => $input['website_id']
  1570. ];
  1571. // 查询栏目名称
  1572. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1573. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1574. if (empty($category)) {
  1575. $imgArticles = [];
  1576. $textArticles = [];
  1577. // return Result::error("暂无此栏目",0);
  1578. }else{
  1579. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1580. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin.'/' : null;
  1581. // return Result::success($website);
  1582. // 查询图片新闻
  1583. // 合并查询条件
  1584. $baseQuery = Article::where(function ($query) use ($website) {
  1585. $query->where(function ($subQuery) use ($website) {
  1586. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1587. })->orWhereNull("ignore_ids");
  1588. })
  1589. ->where('article.status', 1)
  1590. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1591. ->where('website_category.website_id', $website['website_id']);
  1592. // 查询文字新闻
  1593. $textArticles = clone $baseQuery;
  1594. $textArticles = $textArticles->whereIn('catid',$child_category)
  1595. ->select(
  1596. 'article.id',
  1597. 'article.title',
  1598. // 'article.imgurl',
  1599. 'article.author',
  1600. 'article.updated_at',
  1601. 'article.introduce',
  1602. 'article.islink',
  1603. 'article.linkurl',
  1604. 'article.copyfrom',
  1605. 'website_category.category_id',
  1606. 'website_category.alias',
  1607. 'website_category.aLIas_pinyin'
  1608. )
  1609. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1610. ->orderBy('article.updated_at', 'desc')
  1611. ->limit($parentTextNum)
  1612. ->get()
  1613. ->all();
  1614. if(empty($textArticles)){
  1615. $textArticles = clone $baseQuery;
  1616. $textArticles = $textArticles->where('catid',$parentCatId)
  1617. ->select(
  1618. 'article.id',
  1619. 'article.title',
  1620. // 'article.imgurl',
  1621. 'article.author',
  1622. 'article.updated_at',
  1623. 'article.introduce',
  1624. 'article.islink',
  1625. 'article.linkurl',
  1626. 'article.copyfrom',
  1627. 'website_category.category_id',
  1628. 'website_category.alias',
  1629. 'website_category.aLIas_pinyin'
  1630. )
  1631. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1632. ->orderBy('article.updated_at', 'desc')
  1633. ->limit($parentTextNum)
  1634. ->get()
  1635. ->all();
  1636. }
  1637. // 查询图片新闻
  1638. $imgArticles = clone $baseQuery;
  1639. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid',$child_category)
  1640. ->select(
  1641. 'article.id',
  1642. 'article.title',
  1643. 'article.imgurl',
  1644. 'article.author',
  1645. 'article.updated_at',
  1646. 'article.introduce',
  1647. 'article.islink',
  1648. 'article.linkurl',
  1649. 'article.copyfrom',
  1650. 'website_category.category_id',
  1651. 'website_category.alias',
  1652. 'website_category.aLIas_pinyin'
  1653. )
  1654. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1655. ->orderBy('article.updated_at', 'desc')
  1656. ->limit($parentImgNum)
  1657. ->get()
  1658. ->all();
  1659. if(empty($imgArticles)){
  1660. $imgArticles = clone $baseQuery;
  1661. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid',$parentCatId)
  1662. ->select(
  1663. 'article.id',
  1664. 'article.title',
  1665. 'article.imgurl',
  1666. 'article.author',
  1667. 'article.updated_at',
  1668. 'article.introduce',
  1669. 'article.islink',
  1670. 'article.linkurl',
  1671. 'article.copyfrom',
  1672. 'website_category.category_id',
  1673. 'website_category.alias',
  1674. 'website_category.aLIas_pinyin'
  1675. )
  1676. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1677. ->orderBy('article.updated_at', 'desc')
  1678. ->limit($parentImgNum)
  1679. ->get()
  1680. ->all();
  1681. }
  1682. }
  1683. $resultItem = [
  1684. 'alias' => $category ? $category->alias : null,
  1685. 'category_id' => $parentCatId,
  1686. 'pinyin' => $pinyin ? $pinyin : null,
  1687. 'imgnum' => $imgArticles ?? [],
  1688. 'textnum' => $textArticles ?? [],
  1689. ];
  1690. return $resultItem;
  1691. }, $data);
  1692. return Result::success($result);
  1693. }
  1694. /**
  1695. *获取头条类新闻模块-合集(暂时用不到)
  1696. * @param array $data
  1697. * @return array
  1698. */
  1699. public function getWebsiteAllArticlett(array $data): array
  1700. {
  1701. $input['id'] = $data['id'];
  1702. $input['website_id'] = $data['website_id'];
  1703. $data = json_decode($input['id'], true);
  1704. // 使用 array_map 处理每个元素
  1705. $result = array_map(function ($item) use ($input) {
  1706. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1707. $website = [
  1708. 'website_id' => $input['website_id']
  1709. ];
  1710. $category = WebsiteCategory::where('website_id', $input['website_id'])->pluck('category_id');
  1711. $category = array_values(array_unique($category->toArray()));
  1712. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1713. $where = [
  1714. 'status' => 1,
  1715. ];
  1716. return $category;
  1717. }, $data); // 添加第二个参数 $data,确保 array_map 函数有两个参数
  1718. return Result::success($result);
  1719. }
  1720. /**
  1721. * 验证导航名称是否重复
  1722. * @return void
  1723. */
  1724. public function checkCategoryName(array $data): array
  1725. {
  1726. $result = Category::when($data, function ($query) use ($data) {
  1727. if (isset($data['name']) && $data['name']) {
  1728. $query->where("name", $data['name']);
  1729. }
  1730. if (isset($data['id']) && $data['id']) {
  1731. $query->where("id", "!=", $data['id']);
  1732. }
  1733. })->first();
  1734. if ($result) {
  1735. return Result::error("已存在");
  1736. } else {
  1737. return Result::success();
  1738. }
  1739. }
  1740. //20250226 产品列表
  1741. public function getGoodList(array $data): array
  1742. {
  1743. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1744. unset($data['type_id']);
  1745. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1746. $where = [];
  1747. if ($type_id != '10000') {
  1748. $where = [
  1749. 'good.user_id' => $user_id,
  1750. ];
  1751. }
  1752. //类型
  1753. if (isset($data['type_id']) && $data['type_id']) {
  1754. $where = [
  1755. 'type_id' => $data['type_id'],
  1756. ];
  1757. }
  1758. //名称
  1759. if (isset($data['name']) && $data['name']) {
  1760. $where = [
  1761. 'good.name' => $data['name'],
  1762. ];
  1763. }
  1764. //status
  1765. if (isset($data['status']) && $data['status'] != '') {
  1766. $where = [
  1767. 'good.status' => $data['status'],
  1768. ];
  1769. }
  1770. //status1
  1771. // if (isset($data['status1']) && $data['status1'] == 1) {
  1772. // $status1 = 1;
  1773. // }
  1774. $where1 = [];
  1775. //website_id
  1776. // if (isset($data['website_id']) && $data['website_id']) {
  1777. // $where1 = [
  1778. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1779. // ];
  1780. // }
  1781. // website_name
  1782. if (isset($data['website_name']) && $data['website_name']) {
  1783. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1784. }
  1785. // catid
  1786. if (isset($data['category_name']) && $data['category_name']) {
  1787. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1788. }
  1789. // $result = Good::where($where)
  1790. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1791. $result = Good::where($where)
  1792. ->when(!empty($where1), function ($query) use ($where1) {
  1793. return $query->where($where1);
  1794. })
  1795. //status 1待审核2已审核3已拒绝
  1796. ->when(isset($data['status1']), function ($query) {
  1797. return $query->whereIn('good.status', [1, 3]);
  1798. })
  1799. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1800. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1801. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1802. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1803. ->orderBy("updated_at", "desc")
  1804. ->limit($data['page_size'])
  1805. ->offset(($data['page'] - 1) * $data['page_size'])
  1806. ->get();
  1807. $count = Good::where($where)
  1808. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1809. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1810. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1811. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1812. ->orderBy("updated_at", "desc")->count();
  1813. $data = [
  1814. 'rows' => $result->toArray(),
  1815. 'count' => $count,
  1816. ];
  1817. if (empty($result)) {
  1818. return Result::error("此栏目暂无相关产品", 0);
  1819. }
  1820. return Result::success($data);
  1821. }
  1822. public function getGoodInfo(array $data): array
  1823. {
  1824. $result = Good::where('id', $data['id'])->first();
  1825. if (empty($result)) {
  1826. return Result::error("此产品不存在", 0);
  1827. }
  1828. return Result::success($result);
  1829. }
  1830. public function addGood(array $data): array
  1831. {
  1832. // unset($data['city_arr_id']);
  1833. // unset($data['cat_arr_id']);
  1834. $data['city_id'] = end($data['city_arr_id']);
  1835. $data['catid'] = end($data['cat_arr_id']);
  1836. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1837. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1838. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1839. unset($data['imgUrl']);
  1840. $result = Good::insert($data);
  1841. if (empty($result)) {
  1842. return Result::error("添加失败", 0);
  1843. }
  1844. return Result::success($result);
  1845. }
  1846. public function updateGood(array $data): array
  1847. {
  1848. $data['city_id'] = end($data['city_arr_id']);
  1849. $data['catid'] = end($data['cat_arr_id']);
  1850. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1851. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1852. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1853. //设置东八区
  1854. date_default_timezone_set('Asia/Shanghai');
  1855. $data['updated_at'] = date('Y-m-d H:i:s');
  1856. $result = Good::where('id', $data['id'])->update($data);
  1857. if (empty($result)) {
  1858. return Result::error("更新失败", 0);
  1859. }
  1860. return Result::success($result);
  1861. }
  1862. public function delGood(array $data): array
  1863. {
  1864. $result = Good::where('id', $data['id'])->delete();
  1865. if (empty($result)) {
  1866. return Result::error("删除失败", 0);
  1867. }
  1868. return Result::success($result);
  1869. }
  1870. //20250226 产品列表
  1871. //20250306 求职信息
  1872. public function getJobHuntingList(array $data): array
  1873. {
  1874. $where = [];
  1875. if (isset($data['username']) && !empty($data['username'])) {
  1876. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1877. }
  1878. //status 1待审核2已审核3已拒绝
  1879. if (isset($data['status']) && $data['status'] != '') {
  1880. $where = [
  1881. 'job_hunting.status' => $data['status'],
  1882. ];
  1883. }
  1884. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1885. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1886. unset($data['type_id']);
  1887. if ($type_id != '10000') {
  1888. $where[] = ['job_hunting.user_id', '=', $user_id];
  1889. }
  1890. $result = JobHunting::where($where)
  1891. ->when(!empty($data['status1']), function ($query) use ($data) {
  1892. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  1893. })
  1894. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1895. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1896. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1897. ->orderBy("id", "desc")
  1898. ->limit($data['page_size'])
  1899. ->offset(($data['page'] - 1) * $data['page_size'])
  1900. ->get();
  1901. if (empty($result)) {
  1902. return Result::error("查询失败", 0);
  1903. }
  1904. $count = JobHunting::where($where)
  1905. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1906. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1907. ->count();
  1908. $data = [
  1909. 'rows' => $result->toArray(),
  1910. 'count' => $count,
  1911. ];
  1912. return Result::success($data);
  1913. }
  1914. public function addJobHunting(array $data): array
  1915. {
  1916. date_default_timezone_set('Asia/Shanghai');
  1917. unset($data['company_name']);
  1918. unset($data['job_industry']);
  1919. unset($data['job_name']);
  1920. unset($data['department']);
  1921. unset($data['job_timeList']);
  1922. unset($data['job_content']);
  1923. $data['created_at'] = date('Y-m-d H:i:s');
  1924. $data['updated_at'] = date('Y-m-d H:i:s');
  1925. var_dump($data, '-----------------test---------');
  1926. $result = JobHunting::create($data);
  1927. if (empty($result)) {
  1928. return Result::error("添加失败", 0);
  1929. }
  1930. return Result::success($result);
  1931. }
  1932. public function delJobHunting(array $data): array
  1933. {
  1934. $result = JobHunting::where('id', $data['id'])->delete();
  1935. if (empty($result)) {
  1936. return Result::error("删除失败", 0);
  1937. }
  1938. return Result::success($result);
  1939. }
  1940. public function updateJobHunting(array $data): array
  1941. {
  1942. //设置东八区
  1943. date_default_timezone_set('Asia/Shanghai');
  1944. unset($data['company_name']);
  1945. unset($data['job_industry']);
  1946. unset($data['job_name']);
  1947. unset($data['department']);
  1948. unset($data['job_timeList']);
  1949. unset($data['job_content']);
  1950. $data['created_at'] = date('Y-m-d H:i:s');
  1951. $data['updated_at'] = date('Y-m-d H:i:s');
  1952. $result = JobHunting::where('id', $data['id'])->update($data);
  1953. if (empty($result)) {
  1954. return Result::error("更新失败", 0);
  1955. }
  1956. return Result::success($result);
  1957. }
  1958. public function getJobHuntingInfo(array $data): array
  1959. {
  1960. $result = JobHunting::where('id', $data['id'])->first();
  1961. if (empty($result)) {
  1962. return Result::error("查询失败", 0);
  1963. }
  1964. return Result::success($result);
  1965. }
  1966. public function getJobHuntingData(array $data): array
  1967. {
  1968. $jobEnum = JobEnum::get();
  1969. $jobIndustry = JobIndustry::get();
  1970. $jobNature = JobNature::get();
  1971. $jobPosition = JobPosition::get();
  1972. $data = [
  1973. 'jobEnum' => $jobEnum,
  1974. 'jobIndustry' => $jobIndustry,
  1975. 'jobNature' => $jobNature,
  1976. 'jobPosition' => $jobPosition,
  1977. ];
  1978. return Result::success($data);
  1979. }
  1980. public function delJobHuntingInfo(array $data): array
  1981. {
  1982. $result = JobHunting::where('id', $data['id'])->delete();
  1983. return Result::success();
  1984. }
  1985. //20250324 通知,公告,消息
  1986. public function delNotice(array $data): array
  1987. {
  1988. $result = Notice::where('id', $data['id'])->delete();
  1989. if ($result) {
  1990. return Result::success();
  1991. } else {
  1992. return Result::error("删除失败", 0);
  1993. }
  1994. }
  1995. public function getNoticeInfo(array $data): array
  1996. {
  1997. $result = Notice::where('id', $data['id'])->first();
  1998. if (empty($result)) {
  1999. return Result::error("查询失败", 0);
  2000. }
  2001. return Result::success($result);
  2002. }
  2003. public function addNotice(array $data): array
  2004. {
  2005. date_default_timezone_set('Asia/Shanghai');
  2006. $data['created_at'] = date('Y-m-d H:i:s');
  2007. $data['updated_at'] = date('Y-m-d H:i:s');
  2008. $user_id = UserInfo::
  2009. //city_id不是null
  2010. whereNotNull('city_id')
  2011. ->whereNotNull('department_id')
  2012. ->where(function ($query) use ($data) {
  2013. $query->where(function ($subQuery) use ($data) {
  2014. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2015. });
  2016. })
  2017. ->where(function ($query) use ($data) {
  2018. $query->where(function ($subQuery) use ($data) {
  2019. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  2020. });
  2021. })
  2022. ->pluck('user_id')->toArray();
  2023. $user_id = array_unique($user_id);
  2024. $chat_ids = $user_id;
  2025. $user_id = json_encode($user_id);
  2026. $data['re_user_ids'] = $user_id;
  2027. $result = Notice::insertGetId($data);
  2028. if ($result && $data['is_group'] == 1) {
  2029. //chat_group
  2030. $group_id = PublicData::uuid();
  2031. $groupData = [
  2032. 'id' => $group_id,
  2033. 'creator_id' => $data['user_id'],
  2034. 'group_name' => $data['group_name'] ?? '',
  2035. 'profile' => $data['profile'] ?? 0,
  2036. ];
  2037. $groupResult = ChatGroups::insertGetId($groupData);
  2038. var_dump($groupResult, '-----------------groupid-------');
  2039. $groupMemberData = [
  2040. 'id' => PublicData::uuid(),
  2041. 'user_id' => $data['user_id'],
  2042. 'group_id' => $group_id,
  2043. 'leader' => 2,
  2044. ];
  2045. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  2046. //$chat_ids 去除掉$data['user_id']
  2047. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  2048. //插入群成员表
  2049. $groupMemberDataUser = [];
  2050. foreach ($chat_ids as $key => $value) {
  2051. $groupMemberDataUser[] = [
  2052. 'id' => PublicData::uuid(),
  2053. 'user_id' => $value,
  2054. 'group_id' => $group_id,
  2055. 'leader' => 1,
  2056. ];
  2057. }
  2058. ChatGroupsMember::insert($groupMemberDataUser);
  2059. //更新result的 group_id
  2060. $data['group_id'] = $group_id;
  2061. Notice::where(['id' => $result])->update($data);
  2062. }
  2063. if (empty($result)) {
  2064. return Result::error("添加失败", 0);
  2065. }
  2066. return Result::success($result);
  2067. }
  2068. public function updateNotice(array $data): array
  2069. {
  2070. date_default_timezone_set('Asia/Shanghai');
  2071. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  2072. $user_id = UserInfo::
  2073. //city_id不是null
  2074. whereNotNull('city_id')
  2075. ->whereNotNull('department_id')
  2076. ->where(function ($query) use ($data) {
  2077. $query->where(function ($subQuery) use ($data) {
  2078. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2079. });
  2080. })
  2081. ->where(function ($query) use ($data) {
  2082. $query->where(function ($subQuery) use ($data) {
  2083. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  2084. });
  2085. })
  2086. ->pluck('user_id')->toArray();
  2087. $user_id = array_unique($user_id);
  2088. $user_id = json_encode($user_id);
  2089. $data['re_user_ids'] = $user_id;
  2090. $data['updated_at'] = date('Y-m-d H:i:s');
  2091. $result = Notice::where('id', $data['id'])->update($data);
  2092. return Result::success($result);
  2093. }
  2094. public function getNoticeList(array $data): array
  2095. {
  2096. $where = [];
  2097. //title
  2098. if (isset($data['title']) && !empty($data['title'])) {
  2099. $where[] = ['title', 'like', '%' . $data['title'] . '%'];
  2100. }
  2101. //level
  2102. if (isset($data['level']) && !empty($data['level'])) {
  2103. $where[] = ['level', '=', $data['level']];
  2104. }
  2105. //status
  2106. if (isset($data['status']) && !empty($data['status'])) {
  2107. $where[] = ['status', '=', $data['status']];
  2108. }
  2109. var_dump($data['type_id'], '-----------------test---------');
  2110. if ($data['type_id'] == 10000) {
  2111. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  2112. return $query->whereIn('status', [1, 3]); //1待审核2已审核3已拒绝
  2113. })
  2114. ->where($where)
  2115. ->orderBy('updated_at', 'desc')
  2116. ->limit($data['page_size'])
  2117. ->offset(($data['page'] - 1) * $data['page_size'])
  2118. ->get();
  2119. } else {
  2120. $result = Notice::where('status', 1)
  2121. ->where($where)
  2122. ->where('user_id', $data['user_id'])
  2123. ->orWhere(function ($query) use ($data) {
  2124. $query->where('re_user_ids', 'like', '%' . $data['user_id'] . '%');
  2125. })
  2126. ->orderBy('updated_at', 'desc')
  2127. ->limit($data['page_size'])
  2128. ->offset(($data['page'] - 1) * $data['page_size'])
  2129. ->get();
  2130. }
  2131. if (empty($result)) {
  2132. return Result::error("查询失败", 0);
  2133. }
  2134. $count = Notice::where('status', 1)->count();
  2135. $data = [
  2136. 'rows' => $result,
  2137. 'count' => $count,
  2138. ];
  2139. return Result::success($data);
  2140. }
  2141. public function getNoticeDetail(array $data): array
  2142. {
  2143. $result = Notice::where('id', $data['id'])->first();
  2144. if (empty($result)) {
  2145. return Result::error("查询失败", 0);
  2146. }
  2147. return Result::success($result);
  2148. }
  2149. public function deleteNotice(array $data): array
  2150. {
  2151. $notice = Notice::where('id', $data['id'])->first();
  2152. if (empty($notice)) {
  2153. return Result::error("删除失败", 0);
  2154. }
  2155. $chat_group_id = $notice->group_id;
  2156. if ($chat_group_id) {
  2157. //删除群聊
  2158. ChatGroups::where('id', $chat_group_id)->delete();
  2159. //删除群成员
  2160. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  2161. //删除群聊记录
  2162. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  2163. }
  2164. $result = Notice::where('id', $data['id'])->delete();
  2165. return Result::success($result);
  2166. }
  2167. public function getMSG(array $data): array
  2168. {
  2169. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  2170. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2171. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  2172. $result = [];
  2173. if ($type_id == 1) {
  2174. //最近的5篇已审的文章
  2175. $apply_articale = Article::where('status', 1)
  2176. ->where('admin_user_id', $user_id)
  2177. ->orderBy('updated_at', 'desc')
  2178. ->limit(5)->get();
  2179. //获取5条单聊未读聊天消息
  2180. $chat = ChatRecords::where('is_read', 0)
  2181. ->where('user_id', $user_id)
  2182. ->where('talk_type', 1)
  2183. ->orderBy('created_at', 'desc')
  2184. ->limit(5)->get();
  2185. //获取5条未读群聊信息
  2186. $chat_group = ChatRecords::where('is_read', 0)
  2187. ->where('user_id', $user_id)
  2188. ->where('talk_type', 2)
  2189. ->orderBy('created_at', 'desc')
  2190. ->limit(5)->get();
  2191. //获取5条用户的已审核商品
  2192. $good = Good::where('status', 2)
  2193. ->where('user_id', $user_id)
  2194. ->orderBy('updated_at', 'desc')
  2195. ->limit(5)->get();
  2196. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  2197. $result = [
  2198. 'apply_articale' => $apply_articale,
  2199. 'chat' => $chat,
  2200. 'chat_group' => $chat_group,
  2201. 'good' => $good,
  2202. 'count' => $count,
  2203. ];
  2204. } elseif ($type_id == 2) {
  2205. //最近的5篇已审的文章
  2206. $apply_articale = Article::where('status', 1)
  2207. ->where('admin_user_id', $user_id)
  2208. ->limit(5)->get();
  2209. //获取5条单聊未读聊天消息
  2210. $chat = ChatRecords::where('is_read', 0)
  2211. ->where('user_id', $user_id)
  2212. ->where('talk_type', 1)
  2213. ->orderBy('created_at', 'desc')
  2214. ->limit(5)->get();
  2215. //获取5条未读群聊信息
  2216. $chat_group = ChatRecords::where('is_read', 0)
  2217. ->where('user_id', $user_id)
  2218. ->where('talk_type', 2)
  2219. ->orderBy('created_at', 'desc')
  2220. ->limit(5)->get();
  2221. //获取5条用户的已审核商品
  2222. $good = Good::where('status', 2)
  2223. ->where('user_id', $user_id)
  2224. ->orderBy('updated_at', 'desc')
  2225. ->limit(5)->get();
  2226. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  2227. $result = [
  2228. 'apply_articale' => $apply_articale,
  2229. 'chat' => $chat,
  2230. 'chat_group' => $chat_group,
  2231. 'good' => $good,
  2232. 'count' => $count,
  2233. ];
  2234. } elseif ($type_id == 3) {
  2235. //最近的5篇已审的文章
  2236. $apply_articale = Article::where('status', 1)
  2237. ->where('admin_user_id', $user_id)
  2238. ->limit(5)->get();
  2239. //获取5条单聊未读聊天消息
  2240. $chat = ChatRecords::where('is_read', 0)
  2241. ->where('user_id', $user_id)
  2242. ->where('talk_type', 1)
  2243. ->orderBy('created_at', 'desc')
  2244. ->limit(5)->get();
  2245. //获取5条未读群聊信息
  2246. $chat_group = ChatRecords::where('is_read', 0)
  2247. ->where('user_id', $user_id)
  2248. ->where('talk_type', 2)
  2249. ->orderBy('created_at', 'desc')
  2250. ->limit(5)->get();
  2251. //获取5条用户的已审核商品
  2252. $good = Good::where('status', 2)
  2253. ->where('user_id', $user_id)
  2254. ->orderBy('updated_at', 'desc')
  2255. ->limit(5)->get();
  2256. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  2257. $result = [
  2258. 'apply_articale' => $apply_articale,
  2259. 'chat' => $chat,
  2260. 'chat_group' => $chat_group,
  2261. 'good' => $good,
  2262. 'count' => $count,
  2263. ];
  2264. } elseif ($type_id == 4) {
  2265. //最近的5篇已审的文章
  2266. $apply_articale = Article::where('status', 1)
  2267. ->where('admin_user_id', $user_id)
  2268. ->limit(5)->get();
  2269. //获取5条用户的已审核商品
  2270. $good = Good::where('status', 2)
  2271. ->where('user_id', $user_id)
  2272. ->orderBy('updated_at', 'desc')
  2273. ->limit(5)->get();
  2274. $count = count($apply_articale) + count($good);
  2275. $result = [
  2276. 'apply_articale' => $apply_articale,
  2277. 'chat' => '',
  2278. 'chat_group' => '',
  2279. 'good' => $good,
  2280. 'count' => $count,
  2281. ];
  2282. } elseif ($type_id == 10000) {
  2283. //获取未审核的5篇文章
  2284. $apply_articale = Article::where('status', 0)
  2285. ->orderBy('updated_at', 'desc')
  2286. ->limit(5)->get();
  2287. //获取5条单聊未读聊天消息
  2288. $chat = ChatRecords::where('is_read', 0)
  2289. ->where('user_id', $user_id)
  2290. ->where('talk_type', 1)
  2291. ->orderBy('created_at', 'desc')
  2292. ->limit(5)->get();
  2293. //获取5条未读群聊信息
  2294. $chat_group = ChatRecords::where('is_read', 0)
  2295. ->where('user_id', $user_id)
  2296. ->where('talk_type', 2)
  2297. ->orderBy('created_at', 'desc')
  2298. ->limit(5)->get();
  2299. //获取5条用户的已审核商品
  2300. $good = Good::where('status', 1)
  2301. // ->where('user_id', $user_id)
  2302. ->orderBy('updated_at', 'desc')
  2303. ->limit(5)->get();
  2304. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  2305. $result = [
  2306. 'apply_articale' => $apply_articale,
  2307. 'chat' => $chat,
  2308. 'chat_group' => $chat_group,
  2309. 'good' => $good,
  2310. 'count' => $count,
  2311. ];
  2312. } elseif ($type_id == 20000) {
  2313. }
  2314. var_dump($type_id, '-----------------test---------');
  2315. return Result::success($result);
  2316. }
  2317. public function getComplaintList(array $data): array
  2318. {
  2319. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  2320. unset($data['type_id']);
  2321. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  2322. $where = [];
  2323. if ($type_id != 10000) {
  2324. $where['user_id'] = $user_id;
  2325. }
  2326. if (!empty($data['title'])) {
  2327. $where['title'] = ['like', '%' . $data['title'] . '%'];
  2328. }
  2329. if (!empty($data['deal'])) {
  2330. $where['deal'] = ['=', $data['deal']];
  2331. }
  2332. if (!empty($data['status'])) {
  2333. $where['status'] = ['=', $data['status']];
  2334. }
  2335. $result = Complaint::where($where)
  2336. ->when(!empty($data['sattus1']), function ($query) use ($data) {
  2337. $query->whereIn('status', [1, 3]); //1待审核2已审核3已拒绝
  2338. })
  2339. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  2340. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  2341. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  2342. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  2343. ->orderBy('updated_at', 'desc')
  2344. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  2345. if (empty($result)) {
  2346. return Result::error("暂无投诉信息", 0);
  2347. }
  2348. // 取出数据
  2349. $rows = $result->items();
  2350. $count = $result->total();
  2351. $responseData = [
  2352. 'rows' => $rows,
  2353. 'count' => $count,
  2354. ];
  2355. return Result::success($responseData);
  2356. }
  2357. public function getComplaintInfo(array $data): array
  2358. {
  2359. $result = Complaint::where('id', $data['id'])->first();
  2360. if (empty($result)) {
  2361. return Result::error("查询失败", 0);
  2362. }
  2363. return Result::success($result);
  2364. }
  2365. public function addComplaint(array $data): array
  2366. {
  2367. date_default_timezone_set('Asia/Shanghai');
  2368. $data['created_at'] = date('Y-m-d H:i:s');
  2369. $data['updated_at'] = date('Y-m-d H:i:s');
  2370. $result = Complaint::create($data);
  2371. return Result::success($result);
  2372. }
  2373. public function updateComplaint(array $data): array
  2374. {
  2375. date_default_timezone_set('Asia/Shanghai');
  2376. $data['updated_at'] = date('Y-m-d H:i:s');
  2377. $result = Complaint::where('id', $data['id'])->update($data);
  2378. return Result::success($result);
  2379. }
  2380. public function deleteComplaint(array $data): array
  2381. {
  2382. $result = Complaint::where('id', $data['id'])->delete();
  2383. return Result::success($result);
  2384. }
  2385. public function getComplainInfo(array $data): array
  2386. {
  2387. $result = Complaint::where('id', $data['id'])->first();
  2388. if (empty($result)) {
  2389. return Result::error("查询失败", 0);
  2390. }
  2391. return Result::success($result);
  2392. }
  2393. public function updateComplaintStatus(array $data): array
  2394. {
  2395. $result = complaint::where('id', $data['id'])->update($data);
  2396. return Result::success($result);
  2397. }
  2398. public function updateGoodStatus(array $data): array
  2399. {
  2400. $result = Good::where('id', $data['id'])->update($data);
  2401. return Result::success($result);
  2402. }
  2403. public function updateJobHuntingStatus(array $data): array
  2404. {
  2405. $result = JobHunting::where('id', $data['id'])->update($data);
  2406. return Result::success($result);
  2407. }
  2408. public function updateNoticeStatus(array $data): array
  2409. {
  2410. $result = Notice::where('id', $data['id'])->update($data);
  2411. return Result::success($result);
  2412. }
  2413. //20250324 通知,公告,消息
  2414. // 20250306 -------招聘--------fr
  2415. /*
  2416. * 招聘列表
  2417. * */
  2418. public function getJobRecruitingList(array $data): array
  2419. {
  2420. $where = [];
  2421. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  2422. if($data['checkout'] == 0){
  2423. $job_status = [0, 2];
  2424. }else{
  2425. $job_status = [1];
  2426. }
  2427. if(isset($data['keyword']) && !empty($data['keyword'])){
  2428. array_push($where, ['job_recruiting.title', 'like', '%'. $data['keyword']. '%']);
  2429. }
  2430. $user = User::where('id', $data['user_id'])->first();
  2431. if (empty($user)) {
  2432. return Result::error("用户不存在", 0);
  2433. }
  2434. // 3:企业会员
  2435. if ($user['type_id'] == 3) {
  2436. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  2437. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  2438. }
  2439. // 如果 $where 为空,则不添加 where 条件
  2440. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2441. return $query->where($where);
  2442. })
  2443. ->whereIn('job_recruiting.status',$job_status)
  2444. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  2445. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  2446. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  2447. ->orderBy("updated_at", "desc")
  2448. ->offset(($data['page'] - 1) * $data['page_size'])
  2449. ->limit($data['page_size'])
  2450. ->get()
  2451. ->all();
  2452. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2453. return $query->where($where);
  2454. })
  2455. ->whereIn('job_recruiting.status',$job_status)
  2456. ->count();
  2457. if (empty($result)) {
  2458. return Result::error("暂无招聘信息", 0);
  2459. }
  2460. return Result::success($result);
  2461. }
  2462. /*
  2463. * 招聘信息添加
  2464. * */
  2465. public function addJobRecruiting(array $data): array
  2466. {
  2467. // return Result::success($data);
  2468. $user = User::where('user.id', $data['user_id'])
  2469. ->where('user.status', 1)
  2470. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2471. ->select(
  2472. 'user.type_id',
  2473. 'user.mobile',
  2474. 'user.email',
  2475. 'user_info.business_name',
  2476. 'user_info.company_hy_id',
  2477. 'user_info.company_nature',
  2478. 'user_info.company_size',
  2479. 'user_info.introduction',
  2480. 'user_info.real_name',
  2481. 'user_info.company_url',
  2482. 'user_info.address_arr_id',
  2483. 'user_info.address'
  2484. )
  2485. ->first();
  2486. if (empty($user) || $user['type_id'] != $data['user_type']) {
  2487. return Result::error("用户不存在", 0);
  2488. }
  2489. $web = Website::where('id', $data['website_id'])->first();
  2490. if (empty($web)) {
  2491. return Result::error("网站不存在", 0);
  2492. }
  2493. // return Result::success($user);
  2494. $data['action_id'] = $data['user_id'];
  2495. $data['user_type'] = $user['type_id'];
  2496. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  2497. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  2498. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  2499. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  2500. // 公司地址 管理员必填
  2501. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  2502. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2503. // 管理员-企业相关信息
  2504. $company = [
  2505. // 'user_id' => $data['user_id']?? null,
  2506. 'business_name' => $data['business_name'] ?? null,
  2507. 'company_hy_id' => $data['company_hy_id'] ?? null,
  2508. 'company_size' => $data['company_size'] ?? null,
  2509. 'company_nature' => $data['company_nature'] ?? null,
  2510. 'introduction' => $data['introduction'] ?? null,
  2511. 'real_name' => $data['real_name'] ?? null,
  2512. 'mobile' => $data['mobile'] ?? null,
  2513. 'company_url' => $data['company_url'] ?? null,
  2514. 'address_arr_id' => $data['address_arr_id'] ?? null,
  2515. 'address' => $data['address'] ?? null,
  2516. 'email' => $data['email'] ?? null,
  2517. ];
  2518. //去掉相关企业信息
  2519. $job = array_diff_key($data, array_flip(array_keys($company)));
  2520. Db::beginTransaction();
  2521. try {
  2522. // 先添加职位相关信息
  2523. if($user['type_id'] == 10000){
  2524. $job['status'] = 1;
  2525. }
  2526. $jobId = JobRecruiting::insertGetId($job);
  2527. if (empty($jobId)) {
  2528. Db::rollBack();
  2529. return Result::error("添加失败");
  2530. }
  2531. // 添加公司信息
  2532. $company['user_id'] = $data['user_id'] ?? null;
  2533. $company['job_id'] = $jobId;
  2534. $company['user_type'] = $user['type_id'] ?? null;
  2535. $company['website_id'] = $data['website_id'] ?? null;
  2536. if ($user['type_id'] == 10000) {
  2537. // 管理员添加企业信息
  2538. // return Result::success($company);
  2539. $companyId = JobCompany::insertGetId($company);
  2540. if (empty($companyId)) {
  2541. Db::rollBack();
  2542. return Result::error("添加失败");
  2543. }
  2544. } else {
  2545. // 企业会员添加企业信息
  2546. $company = [
  2547. 'user_id' => $data['user_id'] ?? null,
  2548. 'business_name' => $user['business_name'] ?? null,
  2549. 'company_hy_id' => $user['company_hy_id'] ?? null,
  2550. 'company_size' => $user['company_size'] ?? null,
  2551. 'company_nature' => $user['company_nature'] ?? null,
  2552. 'introduction' => $user['introduction'] ?? null,
  2553. 'real_name' => $user['real_name'] ?? null,
  2554. 'mobile' => $user['mobile'] ?? null,
  2555. 'company_url' => $user['company_url'] ?? null,
  2556. 'address_arr_id' => $user['address_arr_id'] ?? null,
  2557. 'address' => $user['address'] ?? null,
  2558. 'email' => $user['email'] ?? null,
  2559. 'website_id' => $data['website_id'] ?? null,
  2560. 'user_type' => $user['type_id'] ?? null,
  2561. 'job_id' => $jobId,
  2562. ];
  2563. $companyId = JobCompany::insertGetId($company);
  2564. if (empty($companyId)) {
  2565. Db::rollBack();
  2566. return Result::error("添加失败");
  2567. }
  2568. // return Result::success($company);
  2569. }
  2570. Db::commit();
  2571. } catch (\Exception $e) {
  2572. Db::rollBack();
  2573. return Result::error($e->getMessage(), 0);
  2574. }
  2575. $result = [
  2576. 'job_id' => $jobId,
  2577. 'company_id' => $companyId,
  2578. ];
  2579. if (empty($result)) {
  2580. return Result::error("添加失败", 0);
  2581. }
  2582. return Result::success($result);
  2583. }
  2584. /*
  2585. * 获取招聘信息详情
  2586. * */
  2587. public function getJobRecruitingInfo(array $data): array
  2588. {
  2589. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  2590. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  2591. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2592. ->select(
  2593. 'job_recruiting.*',
  2594. 'website.website_name as website_name',
  2595. 'job_company.business_name',
  2596. 'job_company.company_hy_id',
  2597. 'job_company.company_size',
  2598. 'job_company.company_nature',
  2599. 'job_company.introduction',
  2600. 'job_company.real_name',
  2601. 'job_company.mobile',
  2602. 'job_company.company_url',
  2603. 'job_company.address_arr_id',
  2604. 'job_company.address',
  2605. 'job_company.email'
  2606. )
  2607. ->first();
  2608. if (empty($result)) {
  2609. return Result::error("招聘信息不存在", 0);
  2610. }
  2611. // return Result::success($job);
  2612. return Result::success($result);
  2613. }
  2614. /*
  2615. * 修改招聘信息
  2616. * */
  2617. public function upJobRecruiting(array $data): array
  2618. {
  2619. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  2620. // return Result::success($job);
  2621. if (empty($job)) {
  2622. return Result::error("招聘信息不存在", 0);
  2623. }
  2624. $user = User::where('id', $data['user_id'])->first();
  2625. // return Result::success($user);
  2626. if (empty($user) || $user['type_id'] != $data['user_type']) {
  2627. return Result::error("用户不存在", 0);
  2628. }
  2629. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  2630. return Result::error("用户暂无权限修改此招聘信息!", 0);
  2631. }
  2632. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  2633. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  2634. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  2635. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  2636. // 公司地址 管理员必填
  2637. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  2638. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2639. // 管理员-企业相关信息
  2640. $company = [
  2641. 'business_name' => $data['business_name'] ?? null,
  2642. 'company_hy_id' => $data['hy_id'] ?? null,
  2643. 'company_size' => $data['company_size'] ?? null,
  2644. 'company_nature' => $data['company_nature'] ?? null,
  2645. 'introduction' => $data['introduction'] ?? null,
  2646. 'real_name' => $data['real_name'] ?? null,
  2647. 'mobile' => $data['mobile'] ?? null,
  2648. 'company_url' => $data['company_url'] ?? null,
  2649. 'address_arr_id' => $data['address_arr_id'] ?? null,
  2650. 'address' => $data['address'] ?? null,
  2651. 'email' => $data['email'] ?? null,
  2652. ];
  2653. //去掉相关企业信息
  2654. $data = array_diff_key($data, array_flip(array_keys($company)));
  2655. $jobId = $data['id'];
  2656. $web = $data['website_id'];
  2657. $data['action_id'] = $data['user_id'];
  2658. unset($data['user_id']);
  2659. unset($data['user_type']);
  2660. unset($data['id']);
  2661. unset($data['website_id']);
  2662. // return Result::success($data);
  2663. Db::beginTransaction();
  2664. try {
  2665. // 管理员修改招聘信息
  2666. if ($user['type_id'] == 10000) {
  2667. $data['website_id'] = $web;
  2668. $company['website_id'] = $data['website_id'];
  2669. $data['status'] = 1;
  2670. }else{
  2671. $data['status'] = 0;
  2672. }
  2673. // Db::rollBack();
  2674. // return Result::success($company);
  2675. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  2676. if (empty($result['job'])) {
  2677. Db::rollBack();
  2678. return Result::error("修改招聘信息失败");
  2679. }
  2680. // 管理员修改企业相关信息
  2681. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  2682. if (empty($result['company'])) {
  2683. Db::rollBack();
  2684. return Result::error("修改企业相关信息失败");
  2685. }
  2686. Db::commit();
  2687. // return Result::success($result);
  2688. } catch (\Exception $e) {
  2689. Db::rollBack();
  2690. return Result::error($e->getMessage(), 0);
  2691. }
  2692. return Result::success($result);
  2693. }
  2694. /*
  2695. * 招聘信息删除
  2696. * */
  2697. public function delJobRecruiting(array $data): array
  2698. {
  2699. $user = User::where('id', $data['user_id'])->first();
  2700. if (empty($user)) {
  2701. return Result::error("用户不存在", 0);
  2702. }
  2703. $job = JobRecruiting::where('id', $data['id'])->first();
  2704. if (empty($job)) {
  2705. return Result::error("招聘信息不存在", 0);
  2706. }
  2707. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  2708. return Result::error("用户暂无权限修改此招聘信息!", 0);
  2709. }
  2710. Db::beginTransaction();
  2711. try {
  2712. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  2713. if (empty($result['job'])) {
  2714. Db::rollBack();
  2715. return Result::error("删除招聘信息失败");
  2716. }
  2717. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  2718. if (empty($result['company'])) {
  2719. Db::rollBack();
  2720. return Result::error("删除企业相关信息失败");
  2721. }
  2722. Db::commit();
  2723. } catch (\Exception $e) {
  2724. Db::rollBack();
  2725. return Result::error($e->getMessage(), 0);
  2726. }
  2727. return Result::success($result);
  2728. }
  2729. /*
  2730. * 获取公司信息
  2731. * */
  2732. public function getJobCompany(array $data): array
  2733. {
  2734. $user = User::where('user.id', $data['user_id'])
  2735. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2736. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  2737. ->first();
  2738. // return Result::success($user);
  2739. if (empty($user)) {
  2740. return Result::error("用户不存在", 0);
  2741. }
  2742. if ($user['type_id'] == 3) {
  2743. $result = [
  2744. // 'id' => 0,
  2745. 'user_id' => $data['user_id'],
  2746. 'website_id' => $data['website_id'],
  2747. 'business_name' => $user['business_name'], // 企业名称
  2748. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  2749. 'company_nature' => $user['company_nature'], // 公司性质
  2750. 'company_size' => $user['company_size'], // 公司规模
  2751. 'introduction' => $user['introduction'], // 公司简介
  2752. 'real_name' => $user['real_name'], // 企业联系人
  2753. 'mobile' => $user['mobile'], // 企业联系电话
  2754. 'company_url' => $user['company_url'], // 企业网址
  2755. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  2756. 'address' => $user['address'], // 企业地址
  2757. 'email' => $user['email'], // 企业邮箱
  2758. ];
  2759. } else {
  2760. return Result::error("用户类型错误", 0);
  2761. }
  2762. if (empty($result)) {
  2763. return Result::error("公司信息不存在", 0);
  2764. }
  2765. return Result::success($result);
  2766. }
  2767. /*
  2768. * 修改公司信息
  2769. * */
  2770. public function upJobCompany(array $data): array
  2771. {
  2772. // return Result::success($data);
  2773. $user = User::where('user.id', $data['user_id'])
  2774. ->where('user.status', 1)
  2775. ->select('user.user_name', 'user.type_id')
  2776. ->first();
  2777. if (empty($user)) {
  2778. return Result::error("用户不存在", 0);
  2779. }
  2780. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2781. $company = [
  2782. 'business_name' => $data['business_name'], // 企业名称
  2783. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  2784. 'company_nature' => $data['company_nature'], // 公司性质
  2785. 'company_size' => $data['company_size'], // 公司规模
  2786. 'introduction' => $data['introduction'], // 公司简介
  2787. // 'real_name' => $data['real_name'], // 企业联系人
  2788. 'company_url' => $data['company_url'], // 企业网址
  2789. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  2790. 'address' => $data['address'], // 企业详细地址
  2791. ];
  2792. if ($user['type_id'] == 3) {
  2793. Db::beginTransaction();
  2794. try {
  2795. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  2796. 'business_name' => $data['business_name'], // 企业名称
  2797. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  2798. 'company_nature' => $data['company_nature'], // 公司性质
  2799. 'company_size' => $data['company_size'], // 公司规模
  2800. 'introduction' => $data['introduction'], // 公司简介
  2801. // 'real_name' => $data['real_name'], // 企业联系人
  2802. 'company_url' => $data['company_url'], // 企业网址
  2803. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  2804. 'address' => $data['address'], // 企业详细地址
  2805. ]);
  2806. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  2807. Db::commit();
  2808. } catch (\Exception $e) {
  2809. Db::rollBack();
  2810. return Result::error($e->getMessage(), 0);
  2811. }
  2812. } else {
  2813. return Result::error("用户类型错误", 0);
  2814. }
  2815. if (empty($result)) {
  2816. return Result::error("修改失败", 0);
  2817. }
  2818. return Result::success($result);
  2819. }
  2820. /*
  2821. * 获取省-市
  2822. * */
  2823. public function getJobRecruitingArea(array $data): array
  2824. {
  2825. if (isset($data['province_id']) && $data['province_id'] != null) {
  2826. $result = District::where('pid', $data['pid'])->get()->all();
  2827. } else {
  2828. $result = District::where('level', 1)->get()->all();
  2829. }
  2830. if (empty($result)) {
  2831. return Result::error("暂无此省市", 0);
  2832. }
  2833. return Result::success($result);
  2834. }
  2835. /*
  2836. * 获取行业分类
  2837. * */
  2838. public function getIndustry(array $data): array
  2839. {
  2840. $result = JobIndustry::get()->all();
  2841. if (empty($result)) {
  2842. return Result::error("暂无行业分类", 0);
  2843. }
  2844. return Result::success($result);
  2845. }
  2846. /*
  2847. * 获取职位
  2848. * */
  2849. public function getPositionList(array $data): array
  2850. {
  2851. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  2852. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  2853. } else {
  2854. $result = JobPosition::where('zwpid', 0)->get()->all();
  2855. }
  2856. if (empty($result)) {
  2857. return Result::error("暂无此职位", 0);
  2858. }
  2859. return Result::success($result);
  2860. }
  2861. /*
  2862. * 获取工作性质-菜单
  2863. * */
  2864. public function getJobNature(array $data): array
  2865. {
  2866. $result = JobEnum::where('egroup', 'nature')->get()->all();
  2867. if (empty($result)) {
  2868. return Result::error("暂无工作性质", 0);
  2869. }
  2870. return Result::success($result);
  2871. }
  2872. /*
  2873. * 获取工作经验-菜单
  2874. * */
  2875. public function getExperience(array $data): array
  2876. {
  2877. $result = JobEnum::where('egroup', 'years')->get()->all();
  2878. if (empty($result)) {
  2879. return Result::error("暂无工作经验", 0);
  2880. }
  2881. return Result::success($result);
  2882. }
  2883. /*
  2884. * 获取学历-菜单
  2885. * */
  2886. public function getEducation(array $data): array
  2887. {
  2888. $result = JobEnum::where('egroup', 'education')->get()->all();
  2889. if (empty($result)) {
  2890. return Result::error("暂无学历", 0);
  2891. }
  2892. return Result::success($result);
  2893. }
  2894. /*
  2895. * 获取薪资-菜单
  2896. * */
  2897. public function getSalary(array $data): array
  2898. {
  2899. $result = JobEnum::where('egroup', 'income')->get()->all();
  2900. if (empty($result)) {
  2901. return Result::error("暂无薪资", 0);
  2902. }
  2903. return Result::success($result);
  2904. }
  2905. /*
  2906. * 获取语言-菜单
  2907. * */
  2908. public function getLanguage(array $data): array
  2909. {
  2910. $result = JobEnum::where('egroup', 'language')->get()->all();
  2911. if (empty($result)) {
  2912. return Result::error("暂无语言", 0);
  2913. }
  2914. return Result::success($result);
  2915. }
  2916. /*
  2917. * 获取掌握程度-菜单
  2918. * */
  2919. public function getLevel(array $data): array
  2920. {
  2921. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  2922. if (empty($result)) {
  2923. return Result::error("暂无工作性质", 0);
  2924. }
  2925. return Result::success($result);
  2926. }
  2927. // 公司信息
  2928. /*
  2929. * 获取公司性质-菜单
  2930. * */
  2931. public function getCompanyNature(array $data): array
  2932. {
  2933. $result = JobNature::get()->all();
  2934. if (empty($result)) {
  2935. return Result::error("暂无公司性质", 0);
  2936. }
  2937. return Result::success($result);
  2938. }
  2939. /*
  2940. * 获取公司规模-菜单
  2941. * */
  2942. public function getCompanySize(array $data): array
  2943. {
  2944. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  2945. if (empty($result)) {
  2946. return Result::error("暂无公司规模", 0);
  2947. }
  2948. return Result::success($result);
  2949. }
  2950. /*
  2951. * 招聘信息审核
  2952. * */
  2953. public function checkJobRecruiting(array $data): array
  2954. {
  2955. $user = User::where('id', $data['user_id'])->first();
  2956. if(empty($user)){
  2957. return Result::error("用户不存在", 0);
  2958. }
  2959. $job = JobRecruiting::where('id', $data['id'])->first();
  2960. if(empty($job)){
  2961. return Result::error("招聘信息不存在", 0);
  2962. }
  2963. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  2964. if($user['type_id'] != 10000){
  2965. return Result::error("用户暂无权限审核此招聘信息!", 0);
  2966. }
  2967. // 驳回原因
  2968. if($data['status'] == 2){
  2969. $data['refuse_reason'] = $data['refuse_reason']?? null;
  2970. }
  2971. $data['action_id'] = $data['user_id'];
  2972. unset($data['user_id']);
  2973. $result = JobRecruiting::where('id', $data['id'])->update($data);
  2974. if(empty($result)){
  2975. return Result::error("审核失败", 0);
  2976. }
  2977. return Result::success($result);
  2978. }
  2979. // 20250306 招聘
  2980. }