NewsService.php 105 KB

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