12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526 |
- <?php
- namespace App\JsonRpc;
- use App\Model\Article;
- use App\Model\ArticleData;
- use App\Model\Category;
- use App\Model\WebsiteCategory;
- use App\Model\ArticleSurvey;
- use App\Model\District;
- use App\Model\Good;
- use App\Model\JobCompany;
- use App\Model\Website;
- use App\Model\JobRecruiting;
- use App\Model\JobIndustry;
- use App\Model\JobPosition;
- use App\Model\JobNature;
- use App\Model\JobEnum;
- use App\Model\User;
- use App\Model\UserRole;
- use App\Model\News;
- use App\Model\UserInfo;
- use App\Model\WebsiteGroup;
- ;
- use Hyperf\DbConnection\Db;
- use Hyperf\RpcServer\Annotation\RpcService;
- use App\Tools\Result;
- use Directory;
- use Ramsey\Uuid\Uuid;
- use Hyperf\Utils\Random;
- #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
- class NewsService implements NewsServiceInterface
- {
- /**
- * 获取导航池列表
- * @param array $data
- * @return array
- */
- public function getCategoryList(array $data): array
- {
- $where = [];
- if (isset($data['name']) && $data['name']) {
- array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
- }
- if (isset($data['department_id']) && $data['department_id']) {
- array_push($where, ['category.department_id', '=', $data['department_id']]);
- }
- $city_id = '';
- if (isset($data['city_id']) && $data['city_id']) {
- $city_id = intval($data['city_id']);
- }
- $rep = Category::where($where)
- ->when($city_id, function ($query) use ($city_id) {
- if (isset($city_id) && $city_id) {
- $query->whereJsonContains("category.city_arr_id", $city_id);
- }
- })
- ->leftJoin('district', 'category.city_id', 'district.id')
- ->leftJoin('department', 'category.department_id', 'department.id')
- ->select("category.*", "district.name as city_name", "department.name as department_name")
- ->limit($data['pageSize'])->orderByDesc('category.updated_at')->offset(($data['page'] - 1) * $data['pageSize'])->get();
- $count = Category::where($where)->when($city_id, function ($query) use ($city_id) {
- if (isset($city_id) && $city_id) {
- $query->whereJsonContains("category.city_arr_id", $city_id);
- }
- })->count();
- $data = [
- 'rows' => $rep->toArray(),
- 'count' => $count,
- ];
- if (empty($rep->toArray())) {
- return Result::error("没有导航池数据");
- }
- return Result::success($data);
- }
- public function myCategoryList(array $data): array
- {
- $sszq = $data['sszq'] ?? '';
- unset($data['sszq']);
- //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
- $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
- $where[] = [
- 'pid', '=', $data['pid'],
- ];
- if (isset($data['name'])) {
- array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
- }
- var_dump($where);
- //根据分类id,从category表中取出分类信息
- $result = Category::where($where)
- ->whereIn('category.id', $catorytids)
- ->select('category.*', 'category.id as category_id')->get();
- if (empty($result)) {
- return Result::error("没有栏目数据");
- }
- return Result::success($result);
- }
- /**
- * @param array $data
- * @return array
- */
- public function categoryList(array $data): array
- {
- $where[] = [
- 'pid', '=', $data['pid'],
- ];
- if (isset($data['name'])) {
- array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
- }
- var_dump($where);
- $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
- if (empty($result)) {
- return Result::error("没有栏目数据");
- }
- return Result::success($result);
- }
- /**
- * @param array $data
- * @return array
- */
- public function addCategory(array $data): array
- {
- $id = Category::insertGetId($data);
- if (empty($id)) {
- return Result::error("添加失败");
- }
- return Result::success(['id' => $id]);
- }
- /**
- * @param array $data
- * @return array
- */
- public function delCategory(array $data): array
- {
- $categoryList = Category::where(['pid' => $data['id']])->get();
- var_dump("分类列表:", $data, $categoryList);
- if ($categoryList->toArray()) {
- return Result::error("分类下面有子分类不能删除");
- }
- $articleList = Article::where(['catid' => $data['id']])->get();
- var_dump("文章列表:", $articleList);
- if ($articleList->toArray()) {
- return Result::error("分类下面有资讯不能删除");
- }
- $result = Category::where($data)->delete();
- if (!$result) {
- return Result::error("删除失败");
- }
- return Result::success($result);
- }
- /**
- * @param array $data
- * @return array
- */
- public function updateCategory(array $data): array
- {
- $where = [
- 'id' => $data['id'],
- ];
- $result = Category::where($where)->update($data);
- if ($result) {
- return Result::success($result);
- } else {
- return Result::error("更新失败");
- }
- }
- /**
- * 获取导航池信息
- * @param array $data
- * @return array
- */
- public function getCategoryInfo(array $data): array
- {
- $where = [
- 'id' => $data['id'],
- ];
- $result = Category::where($where)->first();
- if ($result) {
- return Result::success($result);
- } else {
- return Result::error("更新失败");
- }
- }
- /**
- * @param array $data
- * @return array
- */
- public function getArticleList(array $data): array
- {
- //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
- $type_id = $data['type_id'];
- unset($data['type_id']);
- $user_id = $data['user_id'];
- unset($data['user_id']);
- $where = [];
- if (isset($data['title']) && $data['title']) {
- array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
- }
- if (isset($data['category_name']) && $data['category_name']) {
- array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
- }
- if (isset($data['author']) && $data['author']) {
- array_push($where, ['article.author', '=', $data['author']]);
- }
- if (isset($data['islink']) && $data['islink'] !== "") {
- array_push($where, ['article.islink', '=', $data['islink']]);
- }
- if (isset($data['status']) && $data['status'] !== "") {
- array_push($where, ['article.status', '=', $data['status']]);
- }
- //不是管理员展示个人数据;
- if ($type_id != 10000) {
- $where[] = ['article.admin_user_id', '=', $user_id];
- }
- $rep = Article::where($where)
- ->whereNotIn('article.status', [404])
- ->leftJoin('category', 'article.catid', 'category.id')
- ->select("article.*", "category.name as category_name")
- ->orderBy("article.id", "desc")
- ->limit($data['pageSize'])
- ->offset(($data['page'] - 1) * $data['pageSize'])->get();
- $count = Article::where($where)->whereNotIn('article.status', [404])
- ->leftJoin('category', 'article.catid', 'category.id')->count();
- $data = [
- 'rows' => $rep->toArray(),
- 'count' => $count,
- ];
- if (empty($rep)) {
- return Result::error("没有信息数据");
- }
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function addArticle(array $data): array
- {
- var_dump($data, '----------12-----------1');
- unset($data['user_type']);
- // unset($data['web_site_id']);
- unset($data['nav_add_pool_id']);
- // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
- Db::beginTransaction();
- try {
- //处理投票
- $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
- $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
- $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
- $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
- unset($data['is_survey']);
- unset($data['survey_name']);
- unset($data['suvey_array']);
- unset($data['website_id']);
- $articleData = $data;
- unset($articleData['content']);
- $id = Article::insertGetId($articleData);
- $articleDataContent = [
- 'article_id' => $id,
- 'content' => $data['content'],
- ];
- ArticleData::insertGetId($articleDataContent);
- //处理投票
- if ($is_survey == 1) {
- //生成年月日时分秒+8位随机数
- $uuid = date('YmdHis') . rand(10000000, 99999999);
- var_dump($suvey_array, 'suvey_array________');
- $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
- var_dump($suveys_array, '---------------------1');
- var_dump($suvey_array, '---------------------2');
- $suvey_data = [];
- foreach ($suveys_array as $key => $value) {
- if ($value == '') {
- continue;
- }
- if (is_array($value)) {
- $suvey_data[] = [
- 'sur_id' => $uuid,
- 'art_id' => $id,
- 'website_id' => $website_id ?? 2,
- 'survey_name' => $survey_name,
- 'choice_name' => $value[1],
- 'is_other' => 1,
- 'other_id' => 0,
- 'results' => 0,
- ];
- } else {
- $suvey_data[] = [
- 'sur_id' => $uuid,
- 'art_id' => $id,
- 'website_id' => $website_id ?? 2,
- 'survey_name' => $survey_name,
- 'choice_name' => $value,
- 'is_other' => 0,
- 'other_id' => 0,
- 'results' => 0,
- ];
- }
- if (empty($suvey_data)) {
- throw new \Exception("投票数据为空");
- }
- }
- $result = ArticleSurvey::insert($suvey_data);
- if (!$result) {
- throw new \Exception("投票失败,ArticleSurvey插入失败");
- }
- $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
- if (!$result) {
- throw new \Exception("投票失败,更新主表失败");
- }
- }
- Db::commit();
- return Result::success(['id' => $id]);
- } catch (\Throwable $ex) {
- Db::rollBack();
- var_dump($ex->getMessage());
- return Result::error("创建失败", 0);
- }
- }
- /**
- * @param array $data
- * @return array
- */
- public function delArticle(array $data): array
- {
- $result = Article::where($data)->delete();
- //survey投票删除
- articleSurvey::where(['art_id' => $data['id']])->delete();
- if (!$result) {
- return Result::error("删除失败");
- }
- return Result::success($result);
- }
- /**
- * @param array $data
- * @return array
- */
- public function updateArticle(array $data): array
- {
- var_dump($data, '----------12-----------1');
- Db::beginTransaction();
- unset($data['user_type']);
- // unset($data['web_site_id']);
- unset($data['nav_add_pool_id']);
- try {
- //处理投票
- $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
- $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
- $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
- $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
- unset($data['is_survey']);
- unset($data['survey_name']);
- unset($data['suvey_array']);
- unset($data['website_id']);
- if ($data['hits'] == '') {
- $data['hits'] = 0;
- }
- if ($data['is_original'] == '') {
- $data['is_original'] = 0;
- }
- if ($data['status'] == '') {
- $data['status'] = 0;
- }
- $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
- $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
- $articleData = $data;
- unset($articleData['content']);
- unset($articleData['status_name']);
- unset($articleData['name']);
- unset($articleData['content']);
- unset($articleData['pid_arr']);
- unset($articleData['pid']);
- $id = Article::where(['id' => $data['id']])->update($articleData);
- $articleDataContent = [
- 'content' => $data['content'],
- ];
- ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
- //处理投票
- $id = $data['id'];
- $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
- var_dump($suvey_array, 'suvey_array________delete');
- //处理投票
- if ($is_survey == 1) {
- //生成年月日时分秒+8位随机数
- $uuid = date('YmdHis') . rand(10000000, 99999999);
- $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
- var_dump($suveys_array, '---------------------1');
- var_dump($suvey_array, '---------------------2');
- $suvey_data = [];
- if (is_array($suveys_array)) {
- foreach ($suveys_array as $key => $value) {
- if ($value == '') {
- continue;
- }
- if (is_array($value)) {
- $suvey_data[] = [
- 'sur_id' => $uuid,
- 'art_id' => $id,
- 'website_id' => $website_id ?? 2,
- 'survey_name' => $survey_name,
- 'choice_name' => $value[1],
- 'is_other' => 1,
- 'other_id' => 0,
- 'results' => 0,
- ];
- } else {
- $suvey_data[] = [
- 'sur_id' => $uuid,
- 'art_id' => $id,
- 'website_id' => $website_id ?? 2,
- 'survey_name' => $survey_name,
- 'choice_name' => $value,
- 'is_other' => 0,
- 'other_id' => 0,
- 'results' => 0,
- ];
- }
- if (empty($suvey_data)) {
- throw new \Exception("投票数据为空");
- }
- }
- }
- $result = ArticleSurvey::insert($suvey_data);
- if (!$result) {
- throw new \Exception("投票失败");
- }
- $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
- if (!$result) {
- throw new \Exception("投票失败");
- }
- } else {
- $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
- }
- Db::commit();
- return Result::success([]);
- } catch (\Throwable $ex) {
- Db::rollBack();
- var_dump($ex->getMessage());
- return Result::error("更新失败1" . $ex->getMessage(), 0);
- }
- }
- /**
- * 更新资讯状态
- * @param array $data
- * @return array
- */
- public function upArticleStatus(array $data): array
- {
- $result = Article::where(['id' => $data['id']])->update($data);
- if ($result) {
- return Result::success();
- } else {
- return Result::error("更新状态失败", 0);
- }
- }
- /**
- * @param array $data
- * @return array
- */
- public function getArticleInfo(array $data): array
- {
- $where = [
- 'article.id' => $data['id'],
- // 'article.status' => 1,
- ];
- $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
- $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get()->all();
- var_dump($articleSurvey, 'articleSurvey');
- $info = $result;
- var_dump($info, 'info');
- // $info['survey_array'] = $articleSurvey == null ? [] : $info['survey_array'];
- if ($result) {
- return Result::success($info);
- } else {
- return Result::error("查询失败", 0);
- }
- }
- /**
- * 获取新闻
- * @param array $data
- * @return array
- */
- public function getWebsiteArticlett(array $data): array
- {
- $category = WebsiteCategory::where('website_id', $data['website_id'])->select('category_id')->get();
- $category = $category->toArray();
- $result = [];
- if ($category) {
- $category_ids = [];
- foreach ($category as $val) {
- array_push($category_ids, $val['category_id']);
- }
- if (isset($data['placeid'])) {
- $placeid = $data['placeid'] - 1;
- $result = Article::where('status', 1)->where('level', $data['level'])->whereIn("catid", $category_ids)->orderBy("updated_at", "desc")->offset($placeid)->limit($data['pageSize'])->get();
- } else {
- $result = Article::where('status', 1)->where('level', $data['level'])->whereIn("catid", $category_ids)->orderBy("updated_at", "desc")->offset(0)->limit($data['pageSize'])->get();
- }
- if (empty($result)) {
- return Result::error("暂无头条新闻", 0);
- }
- return Result::success($result);
- } else {
- return Result::error("本网站下暂无相关栏目", 0);
- }
- }
- /**
- * 获取模块新闻
- * @param array $data
- * @return array
- */
- public function getWebsiteModelArticles(array $data): array
- {
- $catid = $data['catid'];
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
- $category = $category->toArray();
- if (!empty($category)) {
- $where = [
- 'status' => 1,
- 'catid' => $catid,
- ];
- if ($data['level'] == 1) {
- $level = [
- 0 => '1',
- 1 => '4',
- 2 => '5',
- 3 => '0',
- ];
- $result = Article::where($where)->whereIn('level', $level)->orderBy("updated_at", "desc")->limit($data['pagesize'])->get();
- } elseif ($data['level'] == 2) {
- $level = '2';
- $result = Article::where($where)->where('level', $level)->orderBy("updated_at", "desc")->limit($data['pagesize'])->get();
- } else {
- $level = '3';
- $result = Article::where($where)->where('level', $level)->orderBy("updated_at", "desc")->limit($data['pagesize'])->get();
- }
- $result = $result->toArray();
- if (!empty($result) && isset($data['placeid']) && !empty($data['placeid'])) {
- $placeid = $data['placeid'] - 1;
- if ($level == 2 || $level == 3) {
- $where = [
- 'level' => $level,
- ];
- $result = Article::where($where)
- ->orderBy("updated_at", "desc")
- ->offset($placeid)
- ->limit($data['pagesize'])->get();
- } else {
- $result = Article::where($where)
- ->whereIn('level', $level)
- ->offset($placeid)
- ->orderBy("updated_at", "desc")
- ->limit($data['pagesize'])->get();
- }
- }
- if (empty($result)) {
- return Result::error("此栏目暂无相关新闻", 0);
- }
- } else {
- return Result::error("此网站暂无此栏目", 0);
- }
- return Result::success($result);
- }
- /**
- *获取新闻列表
- * @param array $data
- * @return array
- */
- public function getWebsiteArticleList(array $data): array
- {
- $where[] = ['status', '=', 1];
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- array_push($where, ['article.title', 'like', '%' . $data['keyword'] . '%']);
- }
- if (isset($data['catid']) && !empty($data['catid'])) {
- if (is_array($data['catid'])) {
- $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
- array_push($where, ['catid', 'in', $data['catid']]);
- } else {
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
- array_push($where, ['catid', '=', $data['catid']]);
- }
- if (empty($category)) {
- return Result::error("此网站暂无此栏目", 0);
- }
- }
- // return Result::success($where);
- $rep = Article::where(function ($query) use ($where) {
- foreach ($where as $condition) {
- if ($condition[1] === 'in') {
- $query->whereIn($condition[0], $condition[2]);
- } else {
- $query->where($condition[0], $condition[1], $condition[2]);
- }
- }
- })
- ->orderBy("updated_at", "desc")
- ->limit($data['pageSize'])
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->get();
- $count = Article::where(function ($query) use ($where) {
- foreach ($where as $condition) {
- if ($condition[1] === 'in') {
- $query->whereIn($condition[0], $condition[2]);
- } else {
- $query->where($condition[0], $condition[1], $condition[2]);
- }
- }
- })->count();
- $data = [
- 'rows' => $rep->toArray(),
- 'count' => $count,
- ];
- if (empty($rep)) {
- return Result::error("没有信息数据");
- }
- return Result::success($data);
- }
- /**
- * 前端-获取新闻详情
- * @param array $data
- * @return array
- */
- public function selectWebsiteArticleInfo(array $data): array
- {
- $where = [
- 'article.id' => $data['id'],
- 'article.status' => 1,
- ];
- $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where(['category_id' => $result['catid']])->first();
- if (empty($category)) {
- return Result::error("查询失败", 0);
- }
- $result['category_id'] = $category['category_id'];
- $result['cat_name'] = $category['alias'];
- return Result::success($result);
- }
- /**
- * 前端-获取网站调查问卷
- * @param array $data
- * @return array
- */
- public function getWebsiteSurvey(array $data): array
- {
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website = Website::where('id', $data['website_id'])->first();
- if (empty($website)) {
- return Result::error("暂无此网站", 0);
- }
- }
- if (isset($data['art_id']) && !empty($data['art_id'])) {
- $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
- if (empty($article)) {
- return Result::error("暂无此文章", 0);
- }
- // return Result::error($data,0);
- $where['art_id'] = $data['art_id'];
- // $query = ArticleSurvey::where('art_id',$data['art_id']);
- } else {
- $survey = ArticleSurvey::where('website_id', $data['website_id'])->orderBy('created_at')->first();
- if (empty($survey)) {
- return Result::error("暂无调查问卷", 0);
- }
- $where['sur_id'] = $survey['sur_id'];
- // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
- }
- $result['survey'] = ArticleSurvey::where($where)->where('is_other', 0)
- ->leftJoin('article', 'article_survey.art_id', 'article.id')
- ->select('article_survey.*', 'article.survey_type')
- ->get()->all();
- $result['other'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
- $result['others'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->first();
- if (empty($result)) {
- return Result::error("此文章暂无调查问卷", 0);
- }
- return Result::success($result);
- }
- /**
- * 前端-添加网站调查问卷选项
- * @param array $data
- * @return array
- */
- public function addWebsiteSurveyOption(array $data): array
- {
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website = Website::where('id', $data['website_id'])->first();
- if (empty($website)) {
- return Result::error("暂无此网站", 0);
- }
- if (isset($data['sur_id']) && !empty($data['sur_id'])) {
- $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
- if (empty($survey)) {
- return Result::error("此调查问卷不可添加选项", 0);
- }
- if (isset($data['choice_name']) && !empty($data['choice_name'])) {
- $choice = [
- 'art_id' => $survey['art_id'],
- 'website_id' => $data['website_id'],
- 'survey_name' => $survey['survey_name'],
- 'choice_name' => $data['choice_name'],
- 'sur_id' => $survey['sur_id'],
- 'is_other' => 1,
- 'other_id' => $survey['id'],
- ];
- $result = ArticleSurvey::insertGetId($choice);
- if (empty($result)) {
- return Result::error("添加失败", 0);
- }
- return Result::success($result);
- }
- }
- return Result::error("添加失败", 0);
- }
- return Result::error("添加失败", 0);
- }
- /**
- * 前端-调查问卷投票
- * @param array $data
- * @return array
- */
- public function addWebsiteSurveyVote(array $data): array
- {
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- $website = Website::where('id', $data['website_id'])->first();
- if (empty($website)) {
- return Result::error("暂无此网站", 0);
- }
- if (isset($data['sur_id']) && !empty($data['sur_id'])) {
- $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->pluck('sur_id');
- if (empty($survey)) {
- return Result::error("此调查问卷不存在", 0);
- }
- // return Result::success($survey);
- // 调查问卷类型 0:单选 1:多选
- $type = Article::where('survey_id', $data['sur_id'])->pluck('survey_type');
- // return Result::success($type);
- if (empty($type) || ($type[0] != 1 && $type[0] != 0)) {
- return Result::error("此调查问卷不可投票", 0);
- }
- // return Result::success($type[0]);
- if (isset($data['choice_id']) && !empty($data['choice_id'])) {
- if ($type[0] == 0) {
- if (is_array($data['choice_id'])) {
- return Result::error("请选择一个选项!", 0);
- }
- $data['choice_id'] = [$data['choice_id']];
- } else {
- if (!is_array($data['choice_id'])) {
- return Result::error("请传递数组!", 0);
- }
- }
- // return Result::success($data['choice_id']);
- $other = ArticleSurvey::whereIn('id', $data['choice_id'])
- ->where('website_id', $data['website_id'])
- ->where('is_other', 1)
- ->where('other_id', 0)
- ->first();
- if (!empty($other)) {
- return Result::error("请选择已有的选项!", 0);
- }
- $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
- ->where('website_id', $data['website_id'])
- ->where('is_other', 1)
- ->where('other_id', '!=', 0)
- ->first();
- // return Result::success($data);
- if (!empty($choice['other'])) {
- array_push($data['choice_id'], $choice['other']['other_id']);
- // return Result::success($data['choice_id']);
- }
- // return Result::success($data);
- $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
- ->where('website_id', $data['website_id'])
- ->increment('results', 1);
- if (empty($choice)) {
- return Result::error("请选择已有的选项!", 0);
- }
- return Result::success($choice);
- }
- return Result::error("参数必填!");
- // if(isset($data['choice_id']) && !empty($data['choice_id'])){
- // $choice = ArticleSurvey::whereIn('id',$data['choice_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
- // }
- }
- return Result::error("此调查问卷不存在", 0);
- }
- return Result::error("参数必填!");
- }
- /**
- * 后端-获取网站调查问卷列表
- * @param array $data
- * @return array
- */
- public function getSurveyList(array $data): array
- {
- $where = [];
- if (isset($data['survey_name']) && !empty($data['survey_name'])) {
- array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
- }
- if (isset($data['survey_type']) && $data['survey_type'] != null) {
- array_push($where, ['survey_type', '=', $data['survey_type']]);
- }
- if (isset($data['is_survey']) && $data['is_survey'] != null) {
- array_push($where, ['is_survey', '=', $data['is_survey']]);
- }
- // return Result::success($where);
- if (!empty($where)) {
- $query = Article::where($where)->whereNotNull('survey_name');
- } else {
- $query = Article::whereNotNull('survey_name');
- }
- $count = $query->count();
- $survey = $query->orderByDesc('id')
- ->limit($data['pageSize'])
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->get();
- if (empty($survey->toArray())) {
- return Result::error("暂无调查问卷!", 0);
- }
- $result = [
- 'rows' => $survey,
- 'count' => $count,
- ];
- return Result::success($result);
- }
- /**
- * 后端-获取网站调查问卷详情
- * @param array $data
- * @return array
- */
- public function getSurveyInfo(array $data): array
- {
- if (isset($data['sur_id']) && !empty($data['sur_id'])) {
- $where = ['sur_id' => $data['sur_id']];
- $choose = ArticleSurvey::where($where)->where('is_other', 0)
- ->leftJoin('article', 'article_survey.art_id', 'article.id')
- ->select('article_survey.*', 'article.survey_type')
- ->get()->all();
- if (empty($choose)) {
- return Result::error("此调查问卷不存在", 0);
- }
- $resultsArray = array_column($choose, 'results');
- $total = array_sum($resultsArray);
- $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
- $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
- // $total = 0;
- if (!empty($other)) {
- $total = $total + $other['results'];
- $other['choice_name'] = $other['choice_name'] . '(其他)';
- if (!empty($others)) {
- $other['hasChildren'] = true;
- // array_push($other,['hasChildren','=',true]);
- $other['children'] = $others;
- $other_choices = [$other->toArray()];
- $mer_choice = array_merge($choose, $other_choices);
- $value_choice = array_values($mer_choice);
- } else {
- // return Result::error('1111');
- $other_choices = [$other->toArray()];
- $other_choices = array_merge($choose, $other_choices);
- $value_choice = array_values($other_choices);
- // return Result::success($result);
- }
- } else {
- $value_choice = $choose;
- }
- $result = [
- 'choose' => $value_choice,
- 'total' => $total,
- ];
- }
- return Result::success($result);
- }
- /**
- * 验证导航名称是否重复
- * @return void
- */
- public function checkCategoryName(array $data): array
- {
- $result = Category::when($data, function ($query) use ($data) {
- if (isset($data['name']) && $data['name']) {
- $query->where("name", $data['name']);
- }
- if (isset($data['id']) && $data['id']) {
- $query->where("id", "!=", $data['id']);
- }
- })->first();
- if ($result) {
- return Result::error("已存在");
- } else {
- return Result::success();
- }
- }
- //20250226 产品列表
- public function getGoodList(array $data): array
- {
- $where = [];
- //类型
- if (isset($data['type_id']) && $data['type_id']) {
- $where = [
- 'type_id' => $data['type_id'],
- ];
- }
- //名称
- if (isset($data['name']) && $data['name']) {
- $where = [
- 'good.name' => $data['name'],
- ];
- }
- $where1 = [];
- //website_id
- // if (isset($data['website_id']) && $data['website_id']) {
- // $where1 = [
- // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
- // ];
- // }
- // website_name
- if (isset($data['website_name']) && $data['website_name']) {
- $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
- }
- // catid
- if (isset($data['category_name']) && $data['category_name']) {
- $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
- }
- // $result = Good::where($where)
- // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
- $result = Good::where($where)
- ->when(!empty($where1), function ($query) use ($where1) {
- return $query->where($where1);
- })
- ->leftJoin('district', 'good.city_id', '=', 'district.id')
- ->leftJoin('website', 'good.website_id', '=', 'website.id')
- ->leftJoin('category', 'good.catid', '=', 'category.id')
- ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
- ->orderBy("id", "desc")
- ->limit($data['page_size'])
- ->offset(($data['page'] - 1) * $data['page_size'])
- ->get();
- $count = Good::where($where)
- ->leftJoin('district', 'good.city_id', '=', 'district.id')
- ->leftJoin('website', 'good.website_id', '=', 'website.id')
- ->leftJoin('category', 'good.catid', '=', 'category.id')
- ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
- ->orderBy("updated_at", "desc")->count();
- $data = [
- 'rows' => $result->toArray(),
- 'count' => $count,
- ];
- if (empty($result)) {
- return Result::error("此栏目暂无相关产品", 0);
- }
- return Result::success($data);
- }
- public function getGoodInfo(array $data): array
- {
- $result = Good::where('id', $data['id'])->first();
- if (empty($result)) {
- return Result::error("此产品不存在", 0);
- }
- return Result::success($result);
- }
- public function addGood(array $data): array
- {
- // unset($data['city_arr_id']);
- // unset($data['cat_arr_id']);
- $data['city_id'] = end($data['city_arr_id']);
- $data['catid'] = end($data['cat_arr_id']);
- $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
- $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
- $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
- unset($data['imgUrl']);
- $result = Good::insert($data);
- if (empty($result)) {
- return Result::error("添加失败", 0);
- }
- return Result::success($result);
- }
- public function updateGood(array $data): array
- {
- $data['city_id'] = end($data['city_arr_id']);
- $data['catid'] = end($data['cat_arr_id']);
- $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
- $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
- $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
- //设置东八区
- date_default_timezone_set('Asia/Shanghai');
- $data['updated_at'] = date('Y-m-d H:i:s');
- $result = Good::where('id', $data['id'])->update($data);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- }
- return Result::success($result);
- }
- public function delGood(array $data): array
- {
- $result = Good::where('id', $data['id'])->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- }
- return Result::success($result);
- }
- //20250226 产品列表
-
- // 20250306 招聘
- /*
- * 招聘列表
- * */
- public function getJobRecruitingList(array $data): array
- {
- $where = [];
- if(isset($data['keyword']) && !empty($data['keyword'])){
- array_push($where, ['job_recruiting.title', 'like', '%'. $data['keyword']. '%']);
- }
- $user = User::where('id', $data['user_id'])->first();
- if(empty($user)){
- return Result::error("用户不存在", 0);
- }
- // 3:企业会员
- if($user['type_id'] == 3){
- array_push($where,['user_id', $data['user_id']]);
- }
- $result = JobRecruiting::where($where)
- ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
- ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
- ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
- ->orderBy("updated_at", "desc")
- ->offset(($data['page'] - 1) * $data['page_size'])
- ->limit($data['page_size'])
- ->get()
- ->all();
- if (empty($result)) {
- return Result::error("暂无招聘信息", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取公司信息
- * */
- public function getJobCompany(array $data): array
- {
- $where = [];
- if(isset($data['job_id']) && !empty($data['job_id'])){
- $where = [ 'job_id' => $data['job_id'] ];
- }
- $user = User::where('id', $data['user_id'])->first();
- if(empty($user)){
- return Result::error("用户不存在", 0);
- }
- if($user['type_id'] != 3){
- $result = JobCompany::where($where)->first();
- }else{
- $result = [
- 'id' => 0,
- 'user_id' => $data['user_id'],
- 'website_id' => $data['website_id'],
- 'business_name' => $user['business_name'], // 企业名称
- 'hy_id' => $user['hy_id'], // 企业所属行业
- 'company_nature' => $user['company_nature'], // 公司性质
- 'company_size' => $user['company_size'], // 公司规模
- 'introduction' => $user['introduction'], // 公司简介
- 'real_name' => $user['real_name'], // 企业联系人
- 'mobile' => $user['mobile'], // 企业联系电话
- 'company_url' => $user['company_url'], // 企业网址
- 'address_arr_id' => $user['address_arr_id'], // 企业网址
- 'address' => $user['address'], // 企业地址
- 'email' => $user['email'], // 企业邮箱
- ];
- }
- if(empty($result)){
- return Result::error("公司信息不存在", 0);
- }
- return Result::success($result);
- }
- /*
- * 修改公司信息
- * */
- public function upJobCompany(array $data): array
- {
- $where = [];
- $where = [ 'user_id' => $data['user_id'] ];
- $user = User::where('id', $data['user_id'])->first();
- if(empty($user)){
- return Result::error("用户不存在", 0);
- }
- if($user['type_id'] != 3){
- $result = JobCompany::where($where)->first();
- }else{
- $result = [
- 'id' => 0,
- 'user_id' => $data['user_id'],
- 'website_id' => $data['website_id'],
- 'business_name' => $user['business_name'], // 企业名称
- 'hy_id' => $user['hy_id'], // 企业所属行业
- 'company_nature' => $user['company_nature'], // 公司性质
- 'company_size' => $user['company_size'], // 公司规模
- 'introduction' => $user['introduction'], // 公司简介
- 'real_name' => $user['real_name'], // 企业联系人
- 'mobile' => $user['mobile'], // 企业联系电话
- 'company_url' => $user['company_url'], // 企业网址
- 'address_arr_id' => $user['address_arr_id'], // 企业网址
- 'address' => $user['address'], // 企业地址
- 'email' => $user['email'], // 企业邮箱
- ];
- }
- if(empty($result)){
- return Result::error("公司信息不存在", 0);
- }
- return Result::success($result);
- }
- /*
- * 招聘信息详情
- * */
- public function getJobRecruitingInfo(array $data): array
- {
- $job = JobRecruiting::where('id', $data['id'])->first();
- if(empty($job)){
- return Result::error("招聘信息不存在", 0);
- }
- $user = User::where('id', $data['user_id'])->first();
- if(empty($user)){
- return Result::error("用户不存在", 0);
- }
- if($job['user_type'] == 3){
- $result = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
- // 假设当前类实例为 $this
- $jobCompanyData = $this->getJobCompany([
- 'user_id' => $data['user_id'],
- 'website_id' => $job['website_id']
- // 假设 $data 是当前方法的参数数组
- ]);
- // ->leftJoin('user_info', 'job_recruiting.user_id', 'user_info.id')
- // ->leftJoin('user', 'job_recruiting.user_id', 'user.id')
- // ->select(
- // 'job_recruiting.*',
- // 'user_info.business_name', // 企业名称
- // 'user_info.hy_id', // 企业所属行业
- // 'user_info.company_size', // 公司规模
- // 'user_info.company_nature', // 公司性质
- // 'user_info.introduction', // 公司简介
- // 'user_info.real_name', // 企业联系人
- // 'user.mobile', // 企业联系电话
- // 'user_info.company_url', // 企业网址
- // 'user_info.address_arr_id', // 企业地址
- // 'user_info.address as address_info', // 企业地址
- // 'user.email', // 企业邮箱
- // )
-
- }else{
- $result = JobRecruiting::where('job_recruiting.id', $data['id'])
- ->leftJoin('job_company', 'job_recruiting.id', 'job_company.job_id')
- ->select(
- 'job_recruiting.*','job_company.id as company_id','job_company.website_id as webid', // 企业名称
- 'job_company.*', // 企业名称
- )
- ->first();
- }
- if (empty($result)) {
- return Result::error("暂无招聘信息", 0);
- }
- if(!empty($result['address_arr_id'])){
- // 假设此处是要将字符串解析为数组,如果是JSON格式可以使用json_decode
- $address_arr = json_decode($result['address_arr_id'], true);
- $address = District::whereIn('id', $address_arr)->pluck('name');
- $result['address'] = $address->toArray();
- }
- return Result::success($result);
- }
- /*
- * 招聘信息添加
- * */
- public function addJobRecruiting(array $data): array
- {
- $user = User::where('id', $data['user_id'])->first();
- if(empty($user) || $user['type_id'] != $data['user_type']){
- return Result::error("用户不存在", 0);
- }
- $data['user_type'] = $user['type_id'];
- $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
- $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
- $data['cat_arr_id'] = isset($data['cat_arr_id'])? json_encode($data['cat_arr_id']) : '';
- $data['city_arr_id'] = isset($data['city_arr_id'])? json_encode($data['city_arr_id']) : '';
- // 公司地址 管理员必填
- if(isset($data['address_arr_id']) &&!empty($data['address_arr_id'])){
- $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
- $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode($data['address_arr_id']) : '';
- }
- // 管理员-企业相关信息
- $company = [
- 'business_name' => $data['business_name']?? null,
- 'company_hy_id' => $data['company_hy_id']?? null,
- 'company_size' => $data['company_size']?? null,
- 'company_nature' => $data['company_nature']?? null,
- 'introduction' => $data['introduction']?? null,
- 'real_name' => $data['real_name']?? null,
- 'mobile' => $data['mobile']?? null,
- 'company_url' => $data['company_url']?? null,
- 'address_arr_id' => $data['address_arr_id']?? null,
- 'address' => $data['address']?? null,
- 'email' => $data['email']?? null,
- ];
- //去掉相关企业信息
- $data = array_diff_key($data, array_flip(array_keys($company)));
- $company['user_id'] = $user['id'];
- // 3:企业会员 10000:管理员
- if($user['type_id'] == 3 || $user['type_id'] == 10000){
- Db::beginTransaction();
- try {
- $jobId = JobRecruiting::insertGetId($data);
- if (empty($jobId)) {
- throw new \Exception("添加失败");
- }
- if($user['type_id'] == 10000){
- if($data['website_id'] == 0 || !isset($data['website_id'])){
- throw new \Exception("请选择所属网站");
- }
- $website = Website::where('id', $data['website_id'])->first();
- if(empty($website)){
- throw new \Exception("网站不存在");
- }
- $company['job_id'] = $jobId;
- $company['website_id'] = $data['website_id'];
- $companyInsertResult = JobCompany::insert($company);
- if (empty($companyInsertResult)) {
- throw new \Exception("添加失败");
- }
- }
- $data['website_id'] = $user['website_id'];
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage(), 0);
- }
- return Result::success($jobId);
- }else{
- return Result::error("此用户暂无权限", 0);
- }
- }
- /*
- * 招聘信息更新
- * */
- public function upJobRecruiting(array $data): array
- {
- $job = JobRecruiting::where('id', $data['id'])->first();
- if(empty($job)){
- return Result::error("招聘信息不存在", 0);
- }
- $user = User::where('id', $data['user_id'])->first();
- if(empty($user) || $user['type_id'] != $data['user_type']){
- return Result::error("用户不存在", 0);
- }
- $data['user_type'] = $user['type_id'];
- $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
- $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
- $data['cat_arr_id'] = isset($data['cat_arr_id'])? json_encode($data['cat_arr_id']) : '';
- $data['city_arr_id'] = isset($data['city_arr_id'])? json_encode($data['city_arr_id']) : '';
- // 公司地址 管理员必填
- if(isset($data['address_arr_id']) &&!empty($data['address_arr_id'])){
- $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
- $data['address_arr_id'] = isset($data['address_arr_id'])? json_encode($data['address_arr_id']) : '';
- }
- // 管理员-企业相关信息
- $company = [
- 'business_name' => $data['business_name']?? null,
- 'company_hy_id' => $data['company_hy_id']?? null,
- 'company_size' => $data['company_size']?? null,
- 'company_nature' => $data['company_nature']?? null,
- 'introduction' => $data['introduction']?? null,
- 'real_name' => $data['real_name']?? null,
- 'mobile' => $data['mobile']?? null,
- 'company_url' => $data['company_url']?? null,
- 'address_arr_id' => $data['address_arr_id']?? null,
- 'address' => $data['address']?? null,
- 'email' => $data['email']?? null,
- ];
- //去掉相关企业信息
- $data = array_diff_key($data, array_flip(array_keys($company)));
- $company['user_id'] = $user['id'];
- // 3:企业会员 10000:管理员
- if($user['type_id'] == 3 || $user['type_id'] == 10000){
- Db::beginTransaction();
- try {
- $jobId = JobRecruiting::where('id',$data['id'])->update($data);
- if (empty($jobId)) {
- throw new \Exception("添加失败");
- }
- if($user['type_id'] == 10000){
- if($data['website_id'] == 0 || !isset($data['website_id'])){
- throw new \Exception("请选择所属网站");
- }
- $website = Website::where('id', $data['website_id'])->first();
- if(empty($website)){
- throw new \Exception("网站不存在");
- }
- $company['job_id'] = $jobId;
- $company['website_id'] = $data['website_id'];
- $companyInsertResult = JobCompany::where('job_id',$data['id'])->update($company);
- if (empty($companyInsertResult)) {
- throw new \Exception("添加失败");
- }
- }
- $data['website_id'] = $user['website_id'];
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage(), 0);
- }
- return Result::success($jobId);
- }else{
- return Result::error("此用户暂无权限", 0);
- }
- }
- /*
- * 招聘信息删除
- * */
- public function delJobRecruiting(array $data): array
- {
- $user = User::where('id', $data['user_id'])->first();
- if(empty($user)){
- return Result::error("用户不存在", 0);
- }
- $job = JobRecruiting::where('id', $data['id'])->first();
- if(empty($job)){
- return Result::error("招聘信息不存在", 0);
- }
- Db::beginTransaction();
- try {
- $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
- if (empty($result['job'])) {
- throw new \Exception("删除招聘信息失败");
- }
- if ($job['type_id'] == 10000) {
- $result['company'] = JobCompany::where('job_id', $data['id'])->delete(); // 修正为JobCompany
- if (empty($result['company'])) {
- throw new \Exception("删除企业相关信息失败");
- }
- }
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage(), 0);
- }
- return Result::success($data);
- }
- /*
- * 获取省-市
- * */
- public function getJobRecruitingArea(array $data): array
- {
- if(isset($data['province_id']) && $data['province_id']!=null){
- $result = District::where('pid',$data['pid'])->get()->all();
- }else{
- $result = District::where('level',1)->get()->all();
- }
- if (empty($result)) {
- return Result::error("暂无此省市", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取行业分类
- * */
- public function getIndustry(array $data): array
- {
- $result = JobIndustry::get()->all();
- if (empty($result)) {
- return Result::error("暂无行业分类", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取职位
- * */
- public function getPositionList(array $data): array
- {
- if(isset($data['zwpid']) && $data['zwpid']!=null){
- $result = JobPosition::where('zwpid',$data['zwpid'])->get()->all();
- }else{
- $result = JobPosition::where('zwpid',0)->get()->all();
- }
- if (empty($result)) {
- return Result::error("暂无此职位", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取工作性质-菜单
- * */
- public function getJobNature(array $data): array
- {
- $result = JobEnum::where('egroup','nature')->get()->all();
- if (empty($result)) {
- return Result::error("暂无工作性质", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取工作经验-菜单
- * */
- public function getExperience(array $data): array
- {
- $result = JobEnum::where('egroup','years')->get()->all();
- if (empty($result)) {
- return Result::error("暂无工作经验", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取学历-菜单
- * */
- public function getEducation(array $data): array
- {
- $result = JobEnum::where('egroup','education')->get()->all();
- if (empty($result)) {
- return Result::error("暂无学历", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取薪资-菜单
- * */
- public function getSalary(array $data): array
- {
- $result = JobEnum::where('egroup','income')->get()->all();
- if (empty($result)) {
- return Result::error("暂无薪资", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取语言-菜单
- * */
- public function getLanguage(array $data): array
- {
- $result = JobEnum::where('egroup','language')->get()->all();
- if (empty($result)) {
- return Result::error("暂无语言", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取掌握程度-菜单
- * */
- public function getLevel(array $data): array
- {
- $result = JobEnum::where('egroup','languagetype')->get()->all();
- if (empty($result)) {
- return Result::error("暂无工作性质", 0);
- }
- return Result::success($result);
- }
- // 公司信息
- /*
- * 获取公司性质-菜单
- * */
- public function getCompanyNature(array $data): array
- {
- $result = JobNature::get()->all();
- if (empty($result)) {
- return Result::error("暂无公司性质", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取公司规模-菜单
- * */
- public function getCompanySize(array $data): array
- {
- $result = JobEnum::where('egroup','cosize')->get()->all();
- if (empty($result)) {
- return Result::error("暂无公司规模", 0);
- }
- return Result::success($result);
- }
- // 20250306 招聘
- }
|