NewsService.php 116 KB

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