NewsService.php 107 KB

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