NewsService.php 113 KB

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