NewsService.php 115 KB

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