12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634 |
- <?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\jobHunting;
- 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\Notice;
- use App\Model\Book;
- 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 App\Model\jobResume;
- use Hyperf\DbConnection\Db;
- use Hyperf\RpcServer\Annotation\RpcService;
- use App\Tools\Result;
- use Directory;
- use Ramsey\Uuid\Uuid;
- use Hyperf\Utils\Random;
- use Fukuball\Jieba\Jieba;
- use Fukuball\Jieba\Finalseg;
- use Hyperf\Utils\Collection;
- use function Hyperf\Support\retry;
- use App\Tools\PublicData;
- use App\Model\ChatGroups;
- use App\Model\ChatGroupsMember;
- use App\Model\ChatRecords;
- use App\Model\Complaint;
- use Hamcrest\Arrays\IsArray;
- use Hyperf\Codec\Json;
- use App\Tools\buildMenuTree;
- use App\Model\JobApply;
- use App\Model\JobRemuse;
- class NewsService implements NewsServiceInterface
- {
-
- public function getCategoryList(array $data): array
- {
- $search = $data['name'] ?? '';
- $page = (int)($data['page'] ?? 1);
- $perPage = (int)($data['pageSize'] ?? 10);
-
- if ($search) {
- $matchedIds = Category::where('name', 'like', "%{$search}%")->pluck('id')->toArray();
- if (empty($matchedIds)) {
- return Result::success(['rows' => [], 'total' => 0]);
- }
-
- $idsStr = implode(',', $matchedIds);
- $sql = "
- WITH RECURSIVE parents AS (
- SELECT * FROM category WHERE id IN ($idsStr)
- UNION ALL
- SELECT c.* FROM category c
- INNER JOIN parents p ON c.id = p.pid
- )
- SELECT * FROM parents
- ";
- $parents = Db::select($sql);
- $parentIds = [];
- foreach ($parents as $row) {
- if ($row->pid == 0) {
- $parentIds[] = $row->id;
- }
- }
- $parentIds = array_unique($parentIds);
- } else {
-
- $parentIds = Category::where('pid', 0)->pluck('id')->toArray();
- }
-
- $total = count($parentIds);
- $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
- if (empty($parentIds)) {
- return Result::success(['rows' => [], 'total' => $total]);
- }
-
- $idsStr = implode(',', $parentIds);
- $sql = "
- WITH RECURSIVE subcategories AS (
- SELECT * FROM category WHERE id IN ($idsStr)
- UNION ALL
- SELECT c.* FROM category c
- INNER JOIN subcategories s ON c.pid = s.id
- )
- SELECT * FROM subcategories ORDER BY updated_at DESC
- ";
- $allCategories = Db::select($sql);
-
- $categoryMap = [];
- foreach ($allCategories as $cat) {
- $cat = (array)$cat;
- $cat['children'] = [];
- $categoryMap[$cat['id']] = $cat;
- }
- foreach ($categoryMap as $id => &$cat) {
- if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
- $categoryMap[$cat['pid']]['children'][] = &$cat;
- }
- }
- unset($cat);
- $categoryTree = [];
- foreach ($parentIds as $id) {
- if (isset($categoryMap[$id])) {
- $categoryTree[] = $categoryMap[$id];
- }
- }
- return Result::success([
- 'rows' => $categoryTree,
- 'total' => $total,
- ]);
-
- }
- private function findMatchedCategories($search)
- {
- if ($search) {
- return Category::where('name', 'like', "%{$search}%")
- ->orderBy('updated_at', 'desc')
- ->get();
- }
- return Category::orderBy('updated_at', 'desc')
- ->get();
- }
- private function findAllParents($categories)
- {
- $allCategories = [];
- foreach ($categories as $category) {
- $parentId = $category->pid;
- while ($parentId > 0) {
- $parent = Category::find($parentId);
- if ($parent) {
- $allCategories[$parent->id] = $parent;
- $parentId = $parent->pid;
- } else {
- break;
- }
- }
- $allCategories[$category->id] = $category;
- }
- return array_values($allCategories);
- }
- private function buildCategoryTree($category, $allRequiredCategories)
- {
- $categoryData = $category->toArray();
- $children = [];
- foreach ($allRequiredCategories as $c) {
- if ($c->pid === $category->id) {
- $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
- }
- }
- if (!empty($children)) {
- $categoryData['children'] = $children;
- }
- return $categoryData;
- }
- public function myCategoryList(array $data): array
- {
- $sszq = $data['sszq'] ?? '';
- unset($data['sszq']);
-
- $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);
-
- $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);
- }
-
- 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);
- }
-
- public function addCategory(array $data): array
- {
- if (isset($data['id'])) {
- unset($data['id']);
- }
- $id = Category::insertGetId($data);
- if (empty($id)) {
- return Result::error("添加失败");
- }
- return Result::success(['id' => $id]);
- }
-
- public function delCategory(array $data): array
- {
- Db::beginTransaction();
- try {
- $categoryList = Category::where(['pid' => $data['id']])->get();
- if ($categoryList->toArray()) {
- Db::rollBack();
- return Result::error("分类下面有子分类不能删除");
- }
- $articleList = Article::where(['catid' => $data['id']])->get();
- if ($articleList->toArray()) {
- Db::rollBack();
- return Result::error("分类下面有资讯不能删除");
- }
- $result = Category::where($data)->delete();
- WebsiteCategory::where(['category_id' => $data['id']])->delete();
- if (!$result) {
- return Result::error("删除失败");
- }
- return Result::success($result);
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error("删除失败");
- }
- }
-
- 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("更新失败");
- }
- }
-
- 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("更新失败");
- }
- }
-
- public function getArticleList(array $data): array
- {
-
- $type_id = $data['type_id'];
- unset($data['type_id']);
- $user_id = $data['user_id'];
- unset($data['user_id']);
- $where = [];
- $status1 = [];
- if (isset($data['id']) && $data['id']) {
- array_push($where, ['article.id', '=', $data['id']]);
- }
- 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 (isset($data['status1'])) {
- $status1 = json_decode(($data['status1']));
- }
-
- if ($type_id != 10000) {
- $where[] = ['article.admin_user_id', '=', $user_id];
- }
- $rep = Article::where($where)
- ->whereNotIn('article.status', [404])
- ->when($status1, function ($query) use ($status1) {
- if (isset($status1) && $status1) {
- $query->whereIn('article.status', $status1);
- }
- })
- ->leftJoin('category', 'article.catid', 'category.id')
- ->leftJoin('website_category', function ($join) {
- $join->on('article.web_site_id', '=', 'website_category.website_id')
- ->on('article.catid', '=', 'website_category.category_id');
- })
- ->select("article.*", "category.name as category_name", "website_category.alias")
- ->orderBy("article.updated_at", "desc")
- ->limit($data['pageSize'])
- ->offset(($data['page'] - 1) * $data['pageSize'])->get();
- $count = Article::where($where)->whereNotIn('article.status', [404])
- ->when($status1, function ($query) use ($status1) {
- if (isset($status1) && $status1) {
- $query->whereIn('article.status', $status1);
- }
- })
- ->leftJoin('category', 'article.catid', 'category.id')->count();
- $data = [
- 'rows' => $rep->toArray(),
- 'count' => $count,
- ];
- if (empty($rep)) {
- return Result::error("没有信息数据");
- }
- return Result::success($data);
- }
-
- public function addArticle(array $data): array
- {
- var_dump($data, '----------12-----------1');
- unset($data['user_type']);
- unset($data['nav_add_pool_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']);
-
-
-
- if ($data['hits'] == '') {
- $data['hits'] = 0;
- }
- if ($data['is_original'] == '') {
- $data['is_original'] = 0;
- }
- if ($data['status'] == '') {
- $data['status'] = 0;
- }
- $articleData = $data;
- unset($articleData['content']);
-
- if ($articleData['imgurl'] == '') {
-
- $levelArr = json_decode($articleData['level'], true);
- var_dump($levelArr, '----------levelArr-----------1');
-
- $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
- preg_match_all($reg, $data['content'], $matches);
- if (isset($matches[1][0])) {
-
- $articleData['imgurl'] = substr($matches[1][0], 0, 240);
-
- if (!in_array(3, $levelArr)) {
- $levelArr[] = 3;
- }
- $articleData['level'] = json_encode($levelArr);
- } else {
- if (!in_array(0, $levelArr)) {
- $levelArr[] = 0;
- }
- $articleData['level'] = json_encode($levelArr);
- }
- }
- var_dump($articleData['level'], '----------$articleData[level]----------1');
- if ($articleData['keyword'] == '') {
-
- $articleData['keyword'] = $data['title'];
-
- Jieba::init();
- Finalseg::init();
- $segList = Jieba::cut($articleData['keyword']);
- $segList1 = array_slice($segList, 0, 8);
- $articleData['keyword'] = implode(',', $segList1);
- }
- if ($articleData['introduce'] == '') {
-
- $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
- }
- $id = Article::insertGetId($articleData);
- $articleDataContent = [
- 'article_id' => $id,
- 'content' => $data['content'],
- ];
- ArticleData::insertGetId($articleDataContent);
-
- if ($is_survey == 1) {
-
- $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);
- }
- }
-
- public function delArticle(array $data): array
- {
- $result = Article::where($data)->delete();
-
- articleSurvey::where(['art_id' => $data['id']])->delete();
- if (!$result) {
- return Result::error("删除失败");
- }
- return Result::success($result);
- }
-
- public function updateArticle(array $data): array
- {
- var_dump($data, '----------12-----------1');
- Db::beginTransaction();
- unset($data['user_type']);
-
- 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']);
- $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_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'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $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']);
-
- if ($articleData['imgurl'] == '') {
-
- $levelArr = json_decode($articleData['level'], true);
- var_dump($levelArr, '----------levelArr-----------1');
-
- $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
- preg_match_all($reg, $data['content'], $matches);
- if (isset($matches[1][0])) {
-
-
- $articleData['imgurl'] = $matches[1][0];
- var_dump($articleData['imgurl'], '----------imgurl-----------1');
- $pos = strpos($articleData['imgurl'], '"');
- if ($pos !== false) {
- $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
- }
-
-
- if (!in_array(3, $levelArr)) {
- $levelArr[] = 3;
- }
- $articleData['level'] = json_encode($levelArr);
- } else {
- if (!in_array(0, $levelArr)) {
- $levelArr[] = 0;
- }
- $articleData['level'] = json_encode($levelArr);
- }
- }
- var_dump($articleData['level'], '----------$articleData[level]----------1');
- if ($articleData['keyword'] == '') {
-
- $articleData['keyword'] = $data['title'];
-
- Jieba::init();
- Finalseg::init();
- $segList = Jieba::cut($articleData['keyword']);
- $segList1 = array_slice($segList, 0, 8);
- $articleData['keyword'] = implode(',', $segList1);
- }
- if ($articleData['introduce'] == '') {
-
- $articleData['introduce'] = substr(preg_replace('/\s+/', '', strip_tags($data['content'])), 0, 100);
-
- }
- $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) {
-
- $uuid = date('YmdHis') . rand(10000000, 99999999);
- $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
- var_dump($suveys_array, '---------------------1');
- $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("更新失败" . $ex->getMessage(), 0);
- }
- }
-
- public function upArticleStatus(array $data): array
- {
- $result = Article::where(['id' => $data['id']])->update($data);
- if ($result) {
- return Result::success();
- } else {
- return Result::error("更新状态失败", 0);
- }
- }
-
- public function getArticleInfo(array $data): array
- {
- $where = [
- 'article.id' => $data['id'],
-
- ];
- $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
- $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
- $info = $result;
-
- $info['survey_array'] = $articleSurvey;
- if ($result) {
- return Result::success($info);
- } else {
- return Result::error("查询失败", 0);
- }
- }
-
- public function getWebsiteArticlett(array $data): array
- {
-
- $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
- $category = array_values(array_unique($category->toArray()));
- if ($category) {
- $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
- $where = [
- 'status' => 1,
- ];
- var_dump($data, 'data-----------------');
-
- if (isset($data['level']) && $data['level'] == 7) {
-
-
- if (isset($data['id']) && !empty($data['id'])) {
- $keyword = Article::where('id', $data['id'])->value('keyword');
- $keywordArray = explode(',', $keyword);
- $whereL7 = [];
- foreach ($keywordArray as $k => $v) {
- $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
- }
-
- $result['level7'] = Article::where($whereL7)
- ->when(!empty($data['imgnum']), function ($query) use ($data) {
- $query->where('article.imgurl', '!=', '')
- ->select('article.*')
- ->offset($data['placeid'])
- ->limit($data['imgnum']);
- })
- ->when(!empty($data['textnum']), function ($query) use ($data) {
- $query->select('article.*')
- ->offset($data['placeid'])
- ->limit($data['textnum']);
- })
- ->orderBy('updated_at', 'desc')
- ->get()
- ->map(function ($article) use ($data) {
- $catid = $article->catid;
- $pinyin = '';
- $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
- if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
- $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
- if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
- $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
- }
- } else {
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- }
- $article->pinyin = $pinyin;
- return $article;
- });
- if (empty($result)) {
- return Result::success();
- }
- return Result::success($result);
- } else {
- return Result::error("参数错误level=7,id不能为空", 0);
- }
- }
-
-
- var_dump($where, 'where-----------------');
-
- $query = Article::where($where)
- ->whereIn("catid", $category)
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
- ->orWhereNull("ignore_ids");
- });
-
- $query->when($data['level'] == 5, function ($query) {
- $query->inRandomOrder()
- ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
- })->when($data['level'] == 4, function ($query) {
- $query->orderBy("article.updated_at", "desc");
- })->when(!empty($data['level']), function ($query) use ($data) {
- if ($data['level'] != 4 && $data['level'] != 5) {
- $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
- ->orderBy("article.updated_at", "desc");
- }
- });
-
- $result = [];
-
-
- if (!empty($data['imgnum'])) {
-
-
- $imgQuery = clone $query;
- if ($imgQuery->getBindings() === null) {
- $imgQuery->setBindings([]);
- }
- $result['img'] = $imgQuery->where('article.imgurl', '!=', '')
- ->select(
- 'article.id',
- 'article.title',
- 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'article.catid'
- )
- ->offset($data['placeid'])
- ->limit($data['imgnum'])
- ->get()
- ->map(function ($article) use ($data) {
- $catid = $article->catid;
- $pinyin = '';
- $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
- if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
- $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
- if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
- $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
- }
- } else {
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- }
- $article->pinyin = $pinyin;
- return $article;
- });
-
- }
-
- if (!empty($data['textnum'])) {
- $textQuery = clone $query;
- $result['text'] = $textQuery
- ->select(
- 'article.id',
- 'article.title',
- 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'article.catid'
- )
- ->offset($data['placeid'])
- ->limit($data['textnum'])
- ->get()
- ->map(function ($article) use ($data) {
- $catid = $article->catid;
- $pinyin = '';
- $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
- if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
- $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
- if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
- $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
- }
- } else {
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- }
- $article->pinyin = $pinyin;
- return $article;
- });
-
- }
- if (empty($result) || count($result) == 0) {
- return Result::error("暂无头条新闻");
- }
- return Result::success($result);
- } else {
- return Result::error("本网站下暂无相关栏目", 0);
- }
- }
-
- 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,
- ];
- $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
-
-
-
- if ($data['level'] == 1) {
- $data['level'] = 0;
- }
- $result = Article::where($where)
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
- ->orWhereNull("level")
- ->orWhereRaw("level = '[]'");
- })
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
- ->orWhereNull("ignore_ids");
- })
- ->orderBy("updated_at", "desc")
- ->offset($placeid)
- ->limit($data['pagesize'])
- ->get();
- if (empty($result)) {
- return Result::error("此栏目暂无相关新闻", 0);
- }
- } else {
- return Result::error("此网站暂无此栏目", 0);
- }
- return Result::success($result);
- }
-
- public function getWebsiteArticleList(array $data): array
- {
-
- $where[] = ['status', '=', 1];
- 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);
- }
- }
-
- $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]);
- }
- }
- })
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
- ->orWhereNull("ignore_ids");
- })
- ->select(
- 'article.id',
- 'article.title',
- 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'article.catid'
- )
- ->orderBy("updated_at", "desc")
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get()
- ->map(function ($article) use ($data) {
- $catid = $article->catid ?? 0;
- $pinyin = '';
- $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
- $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
- $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
- }
- $article->pinyin = $pinyin;
- return $article;
- });
- $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);
- }
-
- 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")
- ->where(function ($query) use ($data) {
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
- ->orWhereNull("ignore_ids");
- })
- ->first();
- if (empty($result)) {
- return Result::error("暂无此新闻!", 0);
- }
- $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
- ->select('website_category.*', 'website.website_name', 'website.suffix')
- ->where('website_category.website_id', $data['website_id'])
- ->where(['website_category.category_id' => $result['catid']])
- ->first();
- if (empty($category)) {
- return Result::error("查询失败", 0);
- }
-
- $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
- $commendArticle = Article::whereIn('id', $commend_ids)
- ->where('status', 1)
- ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
- ->orderBy('updated_at', 'desc')
- ->limit(5)
- ->get();
- $result['category_id'] = $category['category_id'];
- $result['cat_name'] = $category['alias'];
- $result['website_name'] = $category['website_name'] ?? "";
- $result['suffix'] = $category['suffix'] ?? "";
- $result['commendArticle'] = $commendArticle;
- return Result::success($result);
- }
-
- 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);
- }
-
- $where['art_id'] = $data['art_id'];
-
- } else {
- $survey = Article::where(function ($query) {
- $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
- ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
- })
- ->where('status', 1)
- ->where('is_survey', 1)
- ->select('survey_id')
- ->orderBy('updated_at', 'desc')
- ->first();
- if (empty($survey)) {
- return Result::error("暂无调查问卷", 0);
- }
- $where['sur_id'] = $survey['survey_id'];
-
- }
-
- $result = ArticleSurvey::where($where)
- ->where(function ($query) {
- $query->where('is_other', 0)
- ->orWhere(function ($subQuery) {
- $subQuery->where('is_other', 1)
- ->where('other_id', 0);
- });
- })
- ->leftJoin('article', 'article_survey.art_id', 'article.id')
- ->select('article_survey.*', 'article.survey_type')
- ->get()->all();
- if (empty($result)) {
- return Result::error("此文章暂无调查问卷", 0);
- }
- return Result::success($result);
- }
-
- 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('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);
- }
-
- 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'])) {
- $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
-
- if (empty($is_survey)) {
- return Result::error("此调查问卷不存在", 0);
- }
-
-
- if (isset($data['choice_id']) && !empty($data['choice_id'])) {
-
- if (strpos($data['choice_id'], '[') === 0) {
- $data['choice_id'] = json_decode($data['choice_id'], true);
- } else {
-
- $data['choice_id'] = [$data['choice_id']];
- }
- $data['choice_id'] = array_map('intval', $data['choice_id']);
- $other = ArticleSurvey::whereIn('id', $data['choice_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('is_other', 1)
- ->where('other_id', '!=', 0)
- ->first();
-
- $choice_id = $data['choice_id'];
- if (!empty($choice['other'])) {
-
- if (!empty($choice_id)) {
- $key = array_search($choice['other']['id'], $choice_id);
- if ($key !== false) {
- unset($choice_id[$key]);
- $choice_id = array_values($choice_id);
- }
- array_push($choice_id, $choice['other']['other_id']);
- } else {
- $choice_id[0] = $choice['other']['other_id'];
- }
- array_push($data['choice_id'], $choice['other']['other_id']);
- }
-
- $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
-
- ->increment('results', 1);
- if (empty($choice)) {
- return Result::error("请选择已有的选项!", 0);
- }
- $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
-
- ->where('other_id', 0)
- ->get();
- $survey['choice'] = $choice_id;
- return Result::success($survey);
- }
- return Result::error("参数必填!");
- }
- return Result::error("此调查问卷不存在", 0);
- }
- return Result::error("参数必填!");
- }
-
- 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']]);
- }
-
- if (!empty($where)) {
- $query = Article::where($where)->where(function ($q) {
- $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
- });
- } else {
- $query = Article::where(function ($q) {
- $q->whereNotNull('survey_name')->where('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);
- }
-
- 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();
-
- if (!empty($other)) {
- $total = $total + $other['results'];
- $other['choice_name'] = '(其他)';
- if (!empty($others)) {
- $other['hasChildren'] = true;
-
- $other['children'] = $others;
- $other_choices = [$other->toArray()];
- $mer_choice = array_merge($choose, $other_choices);
- $value_choice = array_values($mer_choice);
- } else {
-
- $other_choices = [$other->toArray()];
- $other_choices = array_merge($choose, $other_choices);
- $value_choice = array_values($other_choices);
-
- }
- } else {
- $value_choice = $choose;
- }
- $result = [
- 'choose' => $value_choice,
- 'total' => $total,
- ];
- }
- return Result::success($result);
- }
-
- public function selectWebsiteArticle(array $data): array
- {
- $where = [];
-
- $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
- $query = Article::where('status', 1)
- ->whereIn('catid', $category)
- ->where(function ($query) use ($data) {
- $query->where(function ($subQuery) use ($data) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
- })->orWhereNull("ignore_ids");
- });
-
-
- if (isset($data['cityid']) && !empty($data['cityid'])) {
- $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
- }
-
- if (isset($data['department_id']) && !empty($data['department_id'])) {
- $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
- }
-
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- $query->where('title', 'like', '%' . $data['keyword'] . '%');
- }
-
- $count = $query->count();
-
- $articles = $query
- ->select(
- 'article.id',
- 'article.title',
- 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'article.catid',
- 'article.department_arr_id',
- 'article.city_arr_id',
- )
- ->orderBy("updated_at", "desc")
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get()
- ->map(function ($article) use ($data) {
- $catid = $article->catid ?? 0;
- $pinyin = '';
- $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
- $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
- $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
- }
- $article->pinyin = $pinyin;
- return $article;
- });
- if (empty($articles)) {
- return Result::error("没有符合条件的资讯数据");
- }
- $data = [
- 'rows' => $articles,
- 'count' => $count,
- ];
- return Result::success($data);
- }
-
- public function getWebsiteCatidArticle(array $data): array
- {
-
- $where = [
-
- 'website_category.category_id' => $data['catid'],
- 'website_category.website_id' => $data['website_id'],
-
- ];
-
- if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
- $child_catnum = $data['child_catnum'] ?? 1;
- $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
- $childCategoryIds = array_column($category['child'], 'category_id');
- if (empty($childCategoryIds)) {
- return Result::error("暂无子栏目", 0);
- }
- $imgArticles = [];
- $textArticles = [];
-
- if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
-
-
- $imgArticles = Article::where('catid', $childCategoryIds[0])
- ->where(function ($query) use ($data) {
- $query->where(function ($subQuery) use ($data) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
- })->orWhereNull("ignore_ids");
- })
- ->where('status', 1)
- ->where('imgurl', '!=', '')
- ->select('*')
- ->orderBy('updated_at', 'desc')
- ->limit($data['child_imgnum'])
- ->get();
- }
- if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
-
- $textArticles = Article::where('catid', $childCategoryIds[0])
- ->where('status', 1)
- ->where(function ($query) use ($data) {
- $query->where(function ($subQuery) use ($data) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
- })->orWhereNull("ignore_ids");
- })
-
-
-
-
- ->select('*')
- ->orderBy('updated_at', 'desc')
- ->limit($data['child_textnum'])
- ->get();
- }
-
- $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
- $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
- $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
- return $child;
- }, $category['child']);
- }
-
- if (isset($data['img_num']) && !empty($data['img_num'])) {
- $category['img'] = WebsiteCategory::where($where)
- ->leftJoin('article', 'article.catid', 'website_category.category_id')
- ->where('article.status', 1)
- ->where('article.imgurl', '!=', '')
- ->select('article.*', 'website_category.category_id', 'website_category.alias')
- ->orderBy('article.updated_at', 'desc')
- ->limit($data['img_num'])
- ->get();
- }
- if (isset($data['text_num']) && !empty($data['text_num'])) {
- $category['text'] = WebsiteCategory::where($where)
- ->leftJoin('article', 'article.catid', 'website_category.category_id')
- ->where('article.status', 1)
-
-
-
-
- ->select('article.*', 'website_category.category_id', 'website_category.alias')
- ->orderBy('article.updated_at', 'desc')
- ->limit($data['text_num'])
- ->get();
- }
-
- if (empty($category)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($category);
- }
-
- public function getWebsiteAllArticle(array $data): array
- {
-
- $input['id'] = $data['id'];
- $input['website_id'] = $data['website_id'];
-
- $data = json_decode($input['id'], true);
-
- $result = array_map(function ($item) use ($input) {
-
- if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent']!= "") {
- list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
- $website = [
- 'website_id' => $input['website_id'],
- ];
-
- $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
-
- if(empty($category)){
- $parent_alias = '';
- $parent_pinyin = null;
- $imgArticles = [];
- $textArticles = [];
- }else{
- $parent_alias = $category->alias ?? '';
- $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
-
- $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
- array_push($childCategoryIds,$parentCatId);
- $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
- if($parentImgNum!=0){
-
- $imgArticles = Article::where('article.status', 1)
- ->where(function($query) use ($parentCatId) {
- $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
- ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
- })
- ->where(function ($query) use ($website) {
- $query->where(function ($subQuery) use ($website) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0")
- ->orWhereNull("ignore_ids");
- });
- })
- ->where('imgurl', '!=', '')
- ->leftJoin('website_category', function($join) use ($website) {
- $join->on('article.catid', '=', 'website_category.category_id')
- ->where('website_category.website_id', '=', $website['website_id']);
- })
- ->select(
- 'article.id',
- 'article.title',
- 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'article.catid',
- 'website_category.alias as category_name',
- DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin'
- ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
- )
- ->orderBy('updated_at', 'desc')
- ->limit($parentImgNum)
- ->get()->all();
-
-
- }
- if($parentTextNum!=0){
- $textArticles = [];
- $textArticles = Article::where('article.status', 1)
- ->where(function($query) use ($parentCatId) {
- $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
- ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
- })
- ->where(function ($query) use ($website) {
- $query->where(function ($subQuery) use ($website) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0")
- ->orWhereNull("ignore_ids");
- });
- })
- ->leftJoin('website_category', function($join) use ($website) {
- $join->on('article.catid', '=', 'website_category.category_id')
- ->where('website_category.website_id', '=', $website['website_id']);
- })
- ->select(
- 'article.id',
- 'article.title',
- 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'article.catid',
- 'website_category.alias as category_name',
- DB::raw("CASE WHEN article.catid = $parentCatId THEN '$parent_pinyin'
- ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
- )
- ->orderBy('updated_at', 'desc')
- ->limit($parentTextNum)
- ->get()->all();
- }
- }
-
- }
- $resultItem = [
- 'alias' => $parent_alias ?? '',
- 'category_id' => $parentCatId ?? 0,
- 'pinyin' => $parent_pinyin ?? null,
- 'imgnum' => $imgArticles ?? [],
- 'textnum' => $textArticles ?? [],
- ];
- if(isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != ""){
- $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin.'/' : '';
- $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
- ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
- ->get()->all();
- if (!empty($childCategory)) {
- list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
-
- $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
- ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
- ->first();
- if(empty($childCategoryInfo) || ($childImgNum==0 && $childTextNum==0)){
- $childImgArticles = [];
- $childTextArticles = [];
- $resultItem['child'] = [];
- }else{
- $child_pinyin = $childCategoryInfo->aLIas_pinyin? $childCategoryInfo->aLIas_pinyin : null;
-
- $childImgArticles = Article::where('catid', $childCatId)
- ->where('status', 1)
- ->where(function ($query) use ($website) {
- $query->where(function ($subQuery) use ($website) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
- })->orWhereNull("ignore_ids");
- })
- ->select(
- 'article.id',
- 'article.title',
- 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- DB::raw("'$child_pinyin' as pinyin"))
- ->where('imgurl', '!=', '')
- ->orderBy('updated_at', 'desc')
- ->limit($childImgNum)
- ->get()->all();
-
- $childTextArticles = Article::where('catid', $childCatId)
- ->where('status', 1)
- ->where(function ($query) use ($website) {
- $query->where(function ($subQuery) use ($website) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
- })->orWhereNull("ignore_ids");
- })
- ->select(
- 'article.id',
- 'article.title',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- DB::raw("'$child_pinyin' as pinyin"))
- ->orderBy('updated_at', 'desc')
- ->limit($childTextNum)
- ->get()->all();
- $resultItem['child'] = [
- 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
- 'category_id' => $childCatId,
- 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
- 'all_childcat' => $childCategory,
- 'imgnum' => $childImgArticles,
- 'textnum' => $childTextArticles,
- ];
- }
-
-
- }
-
- }else{
- $resultItem['child'] = [];
- }
- return $resultItem;
- }, $data);
- return Result::success($result);
-
- }
-
- public function getWebsiteArticles(array $data): array
- {
- $input['id'] = $data['id'];
- $input['website_id'] = $data['website_id'];
- $data = json_decode($input['id'], true);
-
- $result = array_map(function ($item) use ($input) {
- list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
- $website = [
- 'website_id' => $input['website_id']
- ];
-
- $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
- if (empty($category)) {
- $imgArticles = [];
- $textArticles = [];
-
- } else {
- $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
- $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
-
-
-
- $baseQuery = Article::where(function ($query) use ($website) {
- $query->where(function ($subQuery) use ($website) {
- $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
- })->orWhereNull("ignore_ids");
- })
- ->where('article.status', 1)
- ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
- ->where('website_category.website_id', $website['website_id']);
-
- $textArticles = clone $baseQuery;
- $textArticles = $textArticles->whereIn('catid', $child_category)
- ->select(
- 'article.id',
- 'article.title',
-
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'website_category.category_id',
- 'website_category.alias',
- 'website_category.aLIas_pinyin'
- )
- ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
- ->orderBy('article.updated_at', 'desc')
- ->limit($parentTextNum)
- ->get()
- ->all();
- if (empty($textArticles)) {
- $textArticles = clone $baseQuery;
- $textArticles = $textArticles->where('catid', $parentCatId)
- ->select(
- 'article.id',
- 'article.title',
-
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'website_category.category_id',
- 'website_category.alias',
- 'website_category.aLIas_pinyin'
- )
- ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
- ->orderBy('article.updated_at', 'desc')
- ->limit($parentTextNum)
- ->get()
- ->all();
- }
-
- $imgArticles = clone $baseQuery;
- $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid', $child_category)
- ->select(
- 'article.id',
- 'article.title',
- 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'website_category.category_id',
- 'website_category.alias',
- 'website_category.aLIas_pinyin'
- )
- ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
- ->orderBy('article.updated_at', 'desc')
- ->limit($parentImgNum)
- ->get()
- ->all();
- if (empty($imgArticles)) {
- $imgArticles = clone $baseQuery;
- $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid', $parentCatId)
- ->select(
- 'article.id',
- 'article.title',
- 'article.imgurl',
- 'article.author',
- 'article.updated_at',
- 'article.introduce',
- 'article.islink',
- 'article.linkurl',
- 'article.copyfrom',
- 'website_category.category_id',
- 'website_category.alias',
- 'website_category.aLIas_pinyin'
- )
- ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
- ->orderBy('article.updated_at', 'desc')
- ->limit($parentImgNum)
- ->get()
- ->all();
- }
- }
- $resultItem = [
- 'alias' => $category ? $category->alias : null,
- 'category_id' => $parentCatId,
- 'pinyin' => $pinyin ? $pinyin : null,
- 'imgnum' => $imgArticles ?? [],
- 'textnum' => $textArticles ?? [],
- ];
- return $resultItem;
- }, $data);
- return Result::success($result);
- }
-
- function processGoods($goods, $data)
- {
- return $goods->map(function ($good) use ($data) {
- $catid = $good->catid ?? 0;
- $pinyin = '';
- $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
- if (!empty($category->pid) && $category->pid != 0) {
- $level = json_decode($category->category_arr_id);
- $pinyin = WebsiteCategory::whereIn('category_id', $level)
- ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
- ->get(['aLIas_pinyin'])
- ->pluck('aLIas_pinyin')
- ->implode('/');
- } else {
- $pinyin = $category->aLIas_pinyin ?? '';
- }
- if (isset($good->city_id) && !empty($good->city_id)) {
- $city = District::where('id', $good->city_id)->first(['name']);
- $good->city_name = $city->name ?? '';
- }
-
- $imgUrls = json_decode($good->imgurl, true);
- $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
- $good->pinyin = $pinyin;
- return $good;
- });
- }
-
- public function getWebsiteshop(array $data): array
- {
- $input['id'] = $data['id'];
- $input['website_id'] = $data['website_id'];
-
- $data = json_decode($input['id'] ?? '', true) ?? [];
- $result = array_map(function ($item) use ($input) {
-
- if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
- list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
- $website = $input['website_id'];
- $query = Good::where('good.status', 2)
- ->where('good.website_id', $website);
- switch ($Levelid) {
- case 1:
- case 2:
- case 3:
- $goods = $query->where(function ($q) use ($Levelid) {
- $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 0")
- ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 0");
- });
- break;
- case 4:
- $goods = $query;
- break;
- case 5:
- $goods = $query->where('type_id', 1);
- break;
- case 6:
- $goods = $query->where('type_id', 2);
- break;
- default:
- return [];
- }
- $all_goods = $goods
- ->select(
- 'good.id',
- 'good.name',
- 'good.imgurl',
- 'good.description',
- 'good.updated_at',
- 'good.catid',
- 'good.type_id',
- 'good.price',
- 'good.level',
- 'good.website_id'
- )
- ->orderBy('updated_at', 'desc')
- ->offset($goodStart)
- ->limit($goodNum)
- ->get();
- $all_goods = $this->processGoods($all_goods, $input);
- }
- return $all_goods;
- }, $data);
- return Result::success($result);
- }
-
- public function getWebsiteshopCat(array $data): array
- {
- $category = WebsiteCategory::where('website_id', $data['website_id'])
- ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
- ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
- ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id')
- ->orderBy('sort')
- ->get()
- ->map(function ($item) use ($data) {
- $pinyin = [];
- $level = json_decode($item->category_arr_id);
-
- if ($item->pid != 0) {
- $pinyin = WebsiteCategory::whereIn('category_id', $level)
- ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
- ->get(['aLIas_pinyin'])
- ->pluck('aLIas_pinyin')
- ->implode('/');
- } else {
- $pinyin = $item->aLIas_pinyin;
- }
- $item->aLIas_pinyin = $pinyin;
- return $item;
- });
- $goods = Good::where('website_id', $data['website_id'])
- ->where('status', 2)
- ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
- ->latest('updated_at')
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get();
- $goods = $this->processGoods($goods, $data);
- if (empty($category)) {
- return Result::error("栏目查询失败", 0);
- }
- if (empty($goods)) {
- return Result::error("商品查询失败", 0);
- }
-
- $cat_tree = Result::buildMenuTree($category);
- $result = [
- 'category' => $cat_tree,
- 'goods' => $goods,
- ];
-
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
-
- public function getWebsiteshopList(array $data): array
- {
-
- $where = [
- 'status' => 2,
- 'website_id' => $data['website_id'],
- ];
- if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
- return Result::error("查询失败", 0);
- }
- if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
- $data['catid'] = $category->category_id ?? 0;
- }
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
- }
- if (isset($data['type_id']) && !empty($data['type_id'])) {
- array_push($where, ['type_id', $data['type_id']]);
- }
- $query = Good::where($where)
- ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
- $query->where(function ($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
- ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
- });
- })
- ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
- $query->where(function ($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
- ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
- });
- })
- ->select(
- 'good.id',
- 'good.name',
- 'good.imgurl',
- 'good.description',
- 'good.updated_at',
- 'good.catid',
- 'good.type_id',
- 'good.website_id',
- 'good.cat_arr_id',
- 'good.created_at',
- 'good.city_id'
- )
- ->latest('updated_at');
-
- $result['type1'] = $this->processGoods(
- $query->clone()
- ->where('type_id', 1)
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get(),
- $data
- );
-
- $result['type2'] = $this->processGoods(
- $query->clone()
- ->where('type_id', 2)
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get(),
- $data
- );
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
-
- public function getWebsiteshopInfo(array $data): array
- {
- $where = [
- 'good.status' => 2,
- 'good.website_id' => $data['website_id'],
- ];
- $goods = Good::where($where)
- ->where('good.id', $data['id'])
- ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
- ->select('good.*', 'website_category.alias', 'website_category.category_id')
- ->first();
- if (empty($goods)) {
- return Result::error("查询失败", 0);
- }
- $goods->imgurl = json_decode($goods->imgurl, true);
- return Result::success($goods);
- }
-
- function processArticles($articles, $data)
- {
- if (!is_array($data)) {
-
-
- echo "Error: \$data is not an array in processArticles. It is of type " . gettype($data) . PHP_EOL;
- return $articles;
- }
- return $articles->map(function ($article) use ($data) {
- $catid = $article->cat_arr_id ?? '';
- $level = json_decode($catid, true);
- $pinyin = '';
- $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
- if (!empty($category->pid) && $category->pid != 0) {
- $pinyin = WebsiteCategory::whereIn('category_id', $level)
- ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
- ->get(['aLIas_pinyin'])
- ->pluck('aLIas_pinyin')
- ->implode('/');
- } else {
- $pinyin = $category->aLIas_pinyin ?? '';
- }
- $article->pinyin = $pinyin;
- return $article;
- });
- }
-
- function processJob($job, $data) {
- return $job->map(function ($job) use ($data) {
- $category = $job->cat_arr_id?? '';
- $cityid = $job->city_arr_id?? '';
- $city = json_decode($cityid, true);
- $pinyin = '';
- $level = json_decode($category, true);
-
- if(!empty($level) && is_array($level)){
- $pinyin = WebsiteCategory::whereIn('category_id', $level)
- ->where('website_id', $data['website_id'])
- ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
- ->get(['aLIas_pinyin'])
- ->pluck('aLIas_pinyin')
- ->implode('/');
- if(empty($pinyin)){
- $pinyin = $pinyin->aLIas_pinyin?? '';
- }
- $job->pinyin = $pinyin;
- }
-
- if(!empty($city) && is_array($city)){
- if(isset($city[1] ) && !empty($city[1])){
- $city = District::where('id', $city[1])->first(['name']);
- $job->city_name = $city->name?? '';
- }else if(isset($city[0] ) && !empty($city[0])){
- $city = District::where('id', $city[0])->first(['name']);
- $job->city_name = $city->name?? '';
- }else{
- $job->city_name = '全国';
- }
- }
-
- if(isset($job->address_arr_id) && !empty($job->address_arr_id)){
- $address_id = json_decode($job->address_arr_id, true) ?? [];
- if(is_array($address_id) && !empty($address_id)){
- $address = District::whereIn('id', $address_id)
- ->orderBy('level', 'asc')
- ->get(['name'])
- ->pluck('name')
- ->implode('');
-
- $job->address_name = ($address ?? '') . ($job->address ?? '');
- }
- }
-
- if(!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id)){
- $hy_name = JobIndustry::when($job, function ($query) use ($job) {
- if(!empty($job->industry)){
- $query->where('hyid', $job->industry);
- }else if(!empty($job->hy_id)){
- $query->where('hyid', $job->hy_id);
- }else{
- $query->where('hyid', $job->company_hy_id);
- }
- })->first(['hyname']);
- $job->hy_name = $hy_name->hyname?? '';
- }
-
- if((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job))){
- $zwid = $job->job?? $job->zw_id;
- $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
- $job->zw_name = $zw_name->zwname?? '';
- }
-
- if((isset($job->jtzw_id) &&!empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get))){
- $jtzwid = $job->job_name_get ?? $job->jtzw_id;
- $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
- $job->jtzw_name = $jtzw_name->zwname?? '';
- }
-
- if(isset($job->experience) &&!empty($job->experience)){
- $experience = JobEnum::where('egroup','years')->where('evalue',$job->experience)->first(['ename']);
- $job->experience_name = $experience->ename?? '';
- }
-
- if(isset($job->educational) &&!empty($job->educational)){
- $education = JobEnum::where('egroup','education')->where('evalue',$job->educational)->first(['ename']);
- $job->education_name = $education->ename?? '';
- }
-
- if(isset($job->language) &&!empty($job->language)){
- $language = JobEnum::where('egroup','language')->where('evalue',$job->language)->first(['ename']);
- $job->language_name = $language->ename?? '';
- }
-
- if(isset($job->salary) &&!empty($job->salary)){
- $salary = JobEnum::where('egroup','income')->where('evalue',$job->salary)->first(['ename']);
- $job->salary_name = $salary->ename?? '';
- }
-
- if(isset($job->nature_id) &&!empty($job->nature_id)){
- $job_nature = JobEnum::where('egroup','nature')->where('evalue',$job->nature_id)->first(['ename']);
- $job->job_nature_name = $job_nature->ename?? '';
- }
-
- if(isset($job->company_size) &&!empty($job->company_size)){
- $company_size = JobEnum::where('egroup','cosize')->where('evalue',$job->company_size)->first(['ename']);
- $job->company_size_name = $company_size->ename?? '';
- }
-
- if(isset($job->company_nature) && !empty($job->company_nature)){
- $company_nature = JobNature::where('id',$job->company_nature)->first(['nature_name']);
- $job->company_nature_name = $company_nature->nature_name?? '';
- }
-
- return $job;
- });
- }
-
- public function getWebsiteBook(array $data): array
- {
- $input['id'] = $data['id'];
- $input['website_id'] = $data['website_id'];
-
- $data = json_decode($input['id'], true);
-
- $result = array_map(function ($item) use ($input) {
-
- if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent']!= "") {
- list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
- $website = [
- 'website_id' => $input['website_id'],
- ];
-
- $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
- if(empty($category)){
- $parent_alias = '';
- $parent_pinyin = null;
- $imgBooks = [];
- $textBooks = [];
- }else{
- $parent_alias = $category->alias ?? '';
- $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
-
- $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
- array_push($childCategoryIds,$parentCatId);
- $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
- if($parentImgNum!=0){
-
- $imgBooks = Book::where(function($query) use ($parentCatId) {
- $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
- ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
- })
- ->where('book.status', 2)
- ->where('book.img_url', '!=', '')
- ->leftJoin('website_category', function($join) use ($website) {
- $join->on('book.cat_id', '=', 'website_category.category_id')
- ->where('website_category.website_id', '=', $website['website_id']);
- })
- ->select(
- 'book.id',
- 'book.title',
- 'book.img_url',
- 'book.price',
- 'book.market_price',
- 'book.description',
- 'book.cat_id',
- 'book.description',
- 'book.updated_at',
- 'website_category.alias as category_name',
- DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
- ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
- )
- ->orderBy('updated_at', 'desc')
- ->limit($parentImgNum)
- ->get()->all();
-
- }
- if($parentTextNum!=0){
- $textBooks = [];
- $textBooks = Book::where(function($query) use ($parentCatId) {
- $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
- ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
- })
- ->where('book.status', 2)
- ->leftJoin('website_category', function($join) use ($website) {
- $join->on('book.cat_id', '=', 'website_category.category_id')
- ->where('website_category.website_id', '=', $website['website_id']);
- })
- ->select(
- 'book.id',
- 'book.title',
- 'book.img_url',
- 'book.price',
- 'book.market_price',
- 'book.description',
- 'book.cat_id',
- 'book.description',
- 'book.updated_at',
- 'website_category.alias as category_name',
- DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
- ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
- )
- ->orderBy('updated_at', 'desc')
- ->limit($parentTextNum)
- ->get()->all();
- }
- }
- }
- $resultItem = [
- 'alias' => $parent_alias ?? '',
- 'category_id' => $parentCatId ?? 0,
- 'pinyin' => $parent_pinyin ?? null,
- 'imgnum' => $imgBooks ?? [],
- 'textnum' => $textBooks ?? [],
- ];
- if(isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != ""){
- $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin.'/' : '';
- $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
- ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
- ->get()->all();
- if (!empty($childCategory)) {
- list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
-
- $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
- ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
- ->first();
- if(empty($childCategoryInfo) || ($childImgNum==0 && $childTextNum==0)){
- $childImgArticles = [];
- $childTextArticles = [];
- $resultItem['child'] = [];
- }else{
- $child_pinyin = $childCategoryInfo->aLIas_pinyin? $childCategoryInfo->aLIas_pinyin : null;
-
- $childImgArticles = Book::where('cat_id', $childCatId)
- ->where('status', 2)
- ->where('img_url', '!=', '')
- ->leftJoin('website_category', function($join) use ($website) {
- $join->on('book.cat_id', '=', 'website_category.category_id')
- ->where('website_category.website_id', '=', $website['website_id']);
- })
- ->select(
- 'book.id',
- 'book.title',
- 'book.img_url',
- 'book.price',
- 'book.market_price',
- 'book.description',
- 'book.cat_id',
- 'book.description',
- 'book.updated_at',
- DB::raw("'$child_pinyin' as pinyin"))
- ->orderBy('updated_at', 'desc')
- ->limit($childImgNum)
- ->get()->all();
-
- $childTextArticles = Book::where('cat_id', $childCatId)
- ->where('status', 2)
- ->leftJoin('website_category', function($join) use ($website) {
- $join->on('book.cat_id', '=', 'website_category.category_id')
- ->where('website_category.website_id', '=', $website['website_id']);
- })
- ->select(
- 'book.id',
- 'book.title',
- 'book.img_url',
- 'book.price',
- 'book.market_price',
- 'book.description',
- 'book.cat_id',
- 'book.description',
- 'book.updated_at',
- DB::raw("'$child_pinyin' as pinyin"))
- ->orderBy('updated_at', 'desc')
- ->limit($childTextNum)
- ->get()->all();
- $resultItem['child'] = [
- 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
- 'category_id' => $childCatId,
- 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
- 'all_childcat' => $childCategory,
- 'imgnum' => $childImgArticles,
- 'textnum' => $childTextArticles,
- ];
- }
- }
- }else{
- $resultItem['child'] = [];
- }
- return $resultItem;
- }, $data);
- return Result::success($result);
- }
-
- public function getWebsiteBookList(array $data): array
- {
- $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
- if(empty($web)){
- return Result::error("查询失败", 0);
- }
- $catid = $data['id'];
- $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id',$catid)->orderBy('sort')->first(['pid','category_id','aLias_pinyin']);
- $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id',$category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
- $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
- $category_pinyin = $category ? $category->aLias_pinyin : '';
- $pinyin = $parent_pinyin . '/' . $category_pinyin ;
- $categorys = WebsiteCategory::where('website_id', $data['website_id'])
- ->where('pid',$category['pid'])
- ->select(
- 'category_id','alias','aLIas_pinyin','pid','sort','is_url','web_url',
- 'seo_title','seo_keywords','seo_description',
- DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
- )
- ->orderBy('sort')
- ->get()->all();
- if(empty($category)){
- return Result::error("查询失败", 0);
- }
- $query = Book::where('book.status', 2)
- ->where('book.website_id', $data['website_id'])
- ->where('book.cat_id', $catid)
- ->select(
- 'book.id',
- 'book.title',
- 'book.img_url',
- 'book.description',
- 'book.updated_at',
- 'book.cat_id',
- DB::raw("'$pinyin' as pinyin")
- )
- ->orderBy('book.updated_at', 'desc');
- $count = $query->count();
- $query = clone $query;
- $Book = $query
- ->limit($data['pageSize'])
- ->offset(($data['page']-1)*$data['pageSize'])
- ->get()->all();
- if(empty($Book)){
- return Result::error("查询失败", 0);
- }
- $result = [
- 'category' => $categorys,
- 'books' => $Book,
- 'count' =>$count,
- ];
- return Result::success($result);
- }
-
- public function getWebsiteBookInfo(array $data): array
- {
- $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
- if(empty($web)){
- return Result::error("查询失败", 0);
- }
- $book = Book::where('status', 2)
- ->where('website_id', $data['website_id'])
- ->where('id', $data['id'])
- ->select(
- 'book.*',
- )
- ->orderBy('updated_at', 'desc')
- ->first();
- if(empty($book)){
- return Result::error("查询失败", 0);
- }
-
- $carpid = WebsiteCategory::where('website_id', $data['website_id'])
- ->where('category_id', $book['cat_id'])
- ->first(['pid','category_id']);
- $query = WebsiteCategory::where('website_id', $data['website_id']);
- if(!empty($carpid)){
- if($carpid->pid!=0){
- $pid = $carpid['pid'];
-
- }else{
- $pid = $carpid['category_id'];
-
- }
- }
- $categorys = $query->where('pid', $pid)
- ->select('category_id','alias','aLIas_pinyin','pid','sort','is_url','web_url','category_arr_id as cat_arr_id',
- )
- ->orderBy('sort')
- ->get();
- $category = $this->processArticle($categorys, $data);
- $result = [
- 'category' => $category,
- 'books' => $book,
- ];
- return Result::success($result);
- }
-
- public function test(array $data): array
- {
- $input['id'] = $data['id'];
- $input['website_id'] = $data['website_id'];
-
- $data = json_decode($input['id'], true);
- $result = [];
- $article = $data;
- $result = array_map(function ($item) use ($input) {
- $website = [
- 'website_id' => $input['website_id'],
- ];
- list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
- $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
- $parent = [
- 0 => $category['category_id'] ?? [],
- 1 => $parentImgNum?? [],
- 2 => $parentTextNum?? [],
- ];
- list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
- $child = [];
-
- $resultItem = [
-
- 'category_id' => $parentCatId ?? 0,
- 'pinyin' => $parentImgNum ?? null,
- 'imgnum' => $parentTextNum ?? [],
-
- ]; return $parent;
- }, $data);
- return Result::success($result);
-
- }
-
- function processArticle($article, $data) {
- return $article->map(function ($article) use ($data) {
- $catid = $article->cat_arr_id?? '';
- $level = json_decode($catid, true);
- $pinyin = '';
-
- if (!empty($level) && is_array($level)) {
- $pinyin = WebsiteCategory::whereIn('category_id', $level)
- ->where('website_id', $data['website_id'])
- ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
- ->get(['aLIas_pinyin'])
- ->pluck('aLIas_pinyin')
- ->implode('/');
- } else {
- $pinyin = '';
- }
- $article->pinyin = $pinyin;
- return $article;
- });
- }
-
- public function getWebsiteJob(array $data): array
- {
- $web = Website::where('id', $data['website_id'])->first();
- if(empty($web)){
- return Result::error("该网站不存在", 0);
- }
- $job_hunting = JobHunting::where('job_hunting.status', 2)
- ->where('job_hunting.website_id', $data['website_id'])
- ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
- $query->where(function($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '". intval($data['city_id']). "') = 1");
- });
- })
- ->select('job_hunting.id','job_hunting.cat_arr_id','job_hunting.job','job_hunting.industry',
- 'job_hunting.city_arr_id','job_hunting.experience','job_hunting.updated_at')
- ->orderBy('updated_at', 'desc')
- ->limit($data['job1_num'])
- ->get();
- $web['website_id'] = $data['website_id'];
- if(empty($job_hunting)){
- $job_huntings = "未查询到相关简历信息";
- }else{
- $job_huntings = $this->processJob($job_hunting, $web);
- }
- $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
- ->where('job_recruiting.website_id', $data['website_id'])
- ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
- $query->where(function($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '". intval($data['city_id']). "') = 1");
- });
- })
- ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
- ->select('job_recruiting.id','job_recruiting.cat_arr_id','job_recruiting.title',
- 'job_recruiting.jtzw_id','job_recruiting.hy_id','job_recruiting.city_arr_id',
- 'job_recruiting.due_data','job_recruiting.updated_at','job_recruiting.experience',
- 'job_recruiting.educational','job_company.business_name',)
- ->orderBy('updated_at', 'desc')
- ->limit($data['job2_num'])
- ->get();
- if(empty($job_recruiting->toArray())){
- $job_recruitings = "未查询到相关职位信息";
- }else{
- $job_recruitings = $this->processJob($job_recruiting, $web);
- }
- $hy = JobIndustry::get()->all();
- $zw = JobPosition::where('zwpid',0)->get()->all();
- $jtzw = JobPosition::where('zwpid','!=',0)->get()->all();
- $result = [
- 'job_hunting' => $job_huntings,
- 'job_recuiting' => $job_recruitings,
- 'hy' => $hy,
- 'zw' => $zw,
- 'jtzw' => $jtzw,
- ];
- return Result::success($result);
- }
-
- public function getWebsiteJobList(array $data): array
- {
- $where = [];
- $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
- if(empty($web)){
- return Result::error("此网站不存在", 0);
- }
- $website_id['website_id'] = $data['website_id'];
- if(isset($data['hy_id']) && !empty($data['hy_id'])){
- array_push($where, ['hy_id',$data['hy_id']]);
- }
- if(isset($data['zw_id']) && !empty($data['zw_id'])){
- array_push($where, ['zw_id',$data['zw_id']]);
- }
- if(isset($data['jtzw_id']) &&!empty($data['jtzw_id'])){
- array_push($where, ['jtzw_id',$data['jtzw_id']]);
- }
- $query = JobRecruiting::where('job_recruiting.status', 1)
- ->where('job_recruiting.website_id', $data['website_id'])
- ->where($where)
- ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
- $query->where(function($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '". intval($data['city_id']). "') = 1");
- });
- })
- ->when(isset($data['catid_id']) &&!empty($data['catid_id']), function ($query) use ($data) {
- $query->where(function($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '". intval($data['catid_id']). "') = 1");
- });
- })
- ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
- ->select('job_recruiting.id','job_recruiting.hy_id','job_recruiting.title','job_recruiting.zw_id',
- 'job_recruiting.jtzw_id','job_recruiting.city_arr_id','job_recruiting.due_data',
- 'job_recruiting.cat_arr_id','job_recruiting.updated_at')
- ->orderBy('updated_at', 'desc');
- $recruit_count = $query->count();
- $query = clone $query;
- $JobRecruiting = $query
- ->offset(($data['page']-1)*$data['pageSize'])
- ->limit($data['pageSize'])
- ->get();
- if(empty($JobRecruiting)){
- $JobRecruiting = "暂无相关职位信息";
- }else{
- $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
- }
- $query = JobHunting::where('status', 2)
- ->where('job_hunting.website_id', $data['website_id'])
- ->where($where)
- ->when(isset($data['city_id']) &&!empty($data['city_id']), function ($query) use ($data) {
- $query->where(function($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '". intval($data['city_id']). "') = 1");
- });
- })
- ->when(isset($data['catid_id']) &&!empty($data['catid_id']), function ($query) use ($data) {
- $query->where(function($q) use ($data) {
- $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '". intval($data['catid_id']). "') = 1");
- });
- })
- ->select('id','sexy','experience','origin','industry','name','job','job_name_get','city_arr_id','cat_arr_id','created_at','updated_at')
- ->orderBy('updated_at', 'desc');
- $hunt_count = $query->count();
- $query = clone $query;
- $JobHunting = $query
- ->offset(($data['page']-1)*$data['pageSize'])
- ->limit($data['pageSize'])
- ->get();
- if(empty($JobHunting)){
- $JobRecruiting = "暂无相关简历信息";
- }else{
- $JobHunting = $this->processJob($JobHunting, $website_id);
- }
- $result = [
- 'JobRecruiting' => $JobRecruiting,
- 'recruit_count' =>$recruit_count,
- 'JobHunting' => $JobHunting,
- 'hunt_count' =>$hunt_count,
- ];
- return Result::success($result);
- }
-
- public function getWebsiteJobInfo(array $data): array
- {
- $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
- if(empty($web)){
- return Result::error("该网站不存在", 0);
- }
- $webid = [
- 'website_id' => $data['website_id'],
- ];
-
- if($data['type']==1){
- $query = JobRecruiting::where('status', 1)
- ->where('website_id', $data['website_id'])
- ->select('*');
- $job = $query->where('job_recruiting.id', $data['id'])->get();
- $company = JobCompany::where('job_id', $data['id'])->select('id','business_name','company_hy_id','company_size','company_nature','address_arr_id','address')->get();
- if(!empty($company)){
- $result['company'] = $this->processJob($company, $webid);
- }
- $other_job =JobRecruiting::where('status', 1)
- ->where('website_id', $data['website_id'])
- ->select('title','id','updated_at','cat_arr_id','user_id')
- ->where('id','!=',$data['id'])
- ->where('user_id', '=', $job[0]['user_id'])
- ->limit($data['pageSize'])
- ->get();
- if(!empty($other_job)){
- $result['other_job'] = $this->processJob($other_job, $webid);
- }
- }else{
- $job = JobHunting::where('job_hunting.status', 2)
- ->where('job_hunting.website_id', $data['website_id'])
- ->where('job_hunting.id', $data['id'])
- ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
- ->select('job_hunting.*','user_name')
- ->get();
- $resume = JobRemuse::where('hunt_id',$data['id'])->get();
- if(!empty($resume->toArray())){
- $result['resume'] = 1;
- } else{
- $result['resume'] = 0;
- }
- }
- if(empty($job->toArray())){
- return Result::error("id参数错误", 0);
- }
- $result['job'] = $this->processJob($job, $webid);
-
- $catid = json_decode($job[0]['cat_arr_id'],true) ?? '';
- $category = WebsiteCategory::where('website_id', $data['website_id'])
- ->whereIn('category_id', $catid)
- ->select('category_id','alias','aLIas_pinyin','pid')
- ->orderBy('pid')->get()->all();
- if(!empty($category)){
- $result['category'] = $category;
- }
- if(empty($result)){
- return Result::error("参数错误", 0);
- }
- return Result::success($result);
- }
-
- public function getWebsiteJobApply(array $data): array
- {
-
-
- $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
- if(empty($web)){
- return Result::error("该网站不存在", 0);
- }
-
- $user = User::where('id', $data['user_id'])->first(['id','type_id']);
-
- if(empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)){
- return Result::error("用户不存在", 0);
- }
-
- $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function($value) {
- return !empty($value);
- }));
-
- $recruiting = JobRecruiting::where('status', 1)
- ->where('website_id', $data['website_id'])
- ->whereIn('id',$data['recruit_id'])
- ->get(['id as recruit_id','user_id as receiver_id'])->all();
- if(empty($recruiting)){
- return Result::error("该职位不存在", 0);
- }
-
- $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status',2)->first(['id as hunt_id']);
- if(empty($hunt_id)){
- return Result::error("该简历不存在", 0);
- }
- $data['hunt_id'] = $hunt_id['hunt_id'];
-
- $apply = JobApply::where('user_id', $data['user_id'])
- ->where('hunt_id', $data['hunt_id'])
- ->where('website_id',$data['website_id'])
- ->whereIn('recruit_id',$data['recruit_id'])
- ->get(['recruit_id']);
- if(!empty($apply->toArray())){
- return Result::error("您已投递过该职位!");
- }
- $insertData = array_map(function($recruiting) use ($data) {
- return [
- 'user_id' => $data['user_id'],
- 'hunt_id' => $data['hunt_id'],
- 'website_id' => $data['website_id'],
- 'recruit_id' => $recruiting['recruit_id'],
- 'receiver_id' => $recruiting['receiver_id'],
- 'status' => 1,
- ];
- }, $recruiting);
-
-
- $result = JobApply::insert($insertData);
- if(empty($result)){
- return Result::error("投递失败", 0);
- }
- return Result::success($result);
- }
-
- public function getWebsiteJobResume(array $data): array
- {
-
- $web = Website::where('id', $data['website_id'])->first(['id','website_name']);
- if(empty($web)){
- return Result::error("该网站不存在", 0);
- }
-
-
- $user = User::where('id', $data['user_id'])->first(['id','type_id']);
-
- if(empty($user) || ($user['type_id']!= 3 && $user['type_id']!= 10000)){
- return Result::error("用户不存在", 0);
- }
-
- $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function($value) {
- return !empty($value);
- }));
-
- $hunting = JobHunting::where('status', 2)
- ->where('website_id', $data['website_id'])
- ->whereIn('id',$data['hunt_id'])
- ->get(['id as hunt_id','user_id as receiver_id'])->all();
- if(empty($hunting)){
- return Result::error("该简历不存在", 0);
- }
-
- $remuse = JobRemuse::where('user_id', $data['user_id'])
- ->where('recruit_id', $data['recruit_id'])
- ->where('website_id',$data['website_id'])
- ->whereIn('hunt_id',$data['hunt_id'])
- ->get(['hunt_id']);
- if(!empty($remuse->toArray())){
- return Result::error("您已沟通过该简历!");
- }
-
- $insertData = array_map(function($hunting) use ($data) {
- return [
- 'user_id' => $data['user_id'],
- 'recruit_id' => $data['recruit_id'],
- 'website_id' => $data['website_id'],
- 'hunt_id' => $hunting['hunt_id'],
- 'receiver_id' => $hunting['receiver_id'],
- 'status' => 1,
- ];
- }, $hunting);
-
- $result = JobRemuse::insert($insertData);
- if(empty($result)){
- return Result::error("沟通失败", 0);
- }
- return Result::success($result);
- }
-
- 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();
- }
- }
-
- public function getGoodList(array $data): array
- {
- $type_id = isset($data['type_id']) ? $data['type_id'] : '';
- unset($data['type_id']);
- $user_id = isset($data['user_id']) ? $data['user_id'] : '';
- $where = [];
- if ($type_id != '10000') {
- $where = [
- 'good.user_id' => $user_id,
- ];
- }
-
- 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'],
- ];
- }
-
- if (isset($data['status']) && $data['status'] != '') {
- $where = [
- 'good.status' => $data['status'],
- ];
- }
-
-
-
-
- $where1 = [];
-
-
-
-
-
-
-
- if (isset($data['website_name']) && $data['website_name']) {
- $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
- }
-
- if (isset($data['category_name']) && $data['category_name']) {
- $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
- }
-
-
- $result = Good::where($where)
- ->when(!empty($where1), function ($query) use ($where1) {
- return $query->where($where1);
- })
-
- ->when(isset($data['status1']), function ($query) {
- return $query->whereIn('good.status', [1, 3]);
- })
- ->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")
- ->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
- {
-
-
- $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']);
- if (isset($data['price']) && $data['price'] == '') {
- $data['price'] = 0;
- }
- $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');
- if (isset($data['price']) && $data['price'] == '') {
- $data['price'] = 0;
- }
- $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);
- }
-
-
- public function getJobHuntingList(array $data): array
- {
- $where = [];
- if (isset($data['username']) && !empty($data['username'])) {
- $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
- }
-
- if (isset($data['status']) && $data['status'] != '') {
- $where = [
- 'job_hunting.status' => $data['status'],
- ];
- }
- $type_id = isset($data['type_id']) ? $data['type_id'] : '';
- $user_id = isset($data['user_id']) ? $data['user_id'] : '';
- unset($data['type_id']);
- if ($type_id != '10000') {
- $where[] = ['job_hunting.user_id', '=', $user_id];
- }
- $result = JobHunting::where($where)
- ->when(!empty($data['status1']), function ($query) use ($data) {
- return $query->whereIn('job_hunting.status', [1, 3]);
- })
- ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
- ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
- ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
- ->orderBy("updated_at", "desc")
- ->limit($data['page_size'])
- ->offset(($data['page'] - 1) * $data['page_size'])
- ->get();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- $count = JobHunting::where($where)
- ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
- ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
- ->count();
- $data = [
- 'rows' => $result->toArray(),
- 'count' => $count,
- ];
- return Result::success($data);
- }
- public function getJobHuntingApply(array $data): array
- {
- $where = [];
- if (isset($data['username']) && !empty($data['username'])) {
- $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
- }
- if (isset($data['salary']) && !empty($data['salary'])) {
- $where = [
- 'job_hunting.salary' => $data['salary'],
- ];
- }
- $type_id = isset($data['type_id']) ? $data['type_id'] : '';
- $user_id = isset($data['user_id']) ? $data['user_id'] : '';
- unset($data['type_id']);
- if ($type_id != '10000') {
- $where[] = ['job_resume.user_id', '=', $user_id];
- }
- $result = jobResume::where($where)
-
-
-
-
- ->where('job_enum.egroup', '=', 'income')
- ->where('job_hunting.status', 2)
- ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_resume.hunt_id')
- ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
- ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
- ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
- ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
- ->select('job_resume.*', 'job_position.zwname as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username')
- ->orderBy("job_hunting.updated_at", "desc")
- ->limit($data['page_size'])
- ->offset(($data['page'] - 1) * $data['page_size'])
- ->get();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- $count = jobResume::where($where)
- ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_resume.hunt_id')
- ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
- ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
- ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
- ->select('job_resume.*', 'job_hunting.job_name_get as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username')
- ->count();
- $data = [
- 'rows' => $result->toArray(),
- 'count' => $count,
- ];
- return Result::success($data);
- }
- public function addJobHunting(array $data): array
- {
- date_default_timezone_set('Asia/Shanghai');
- unset($data['company_name']);
- unset($data['job_industry']);
- unset($data['job_name']);
- unset($data['department']);
- unset($data['job_timeList']);
- unset($data['job_content']);
- $data['created_at'] = date('Y-m-d H:i:s');
- $data['updated_at'] = date('Y-m-d H:i:s');
- var_dump($data, '-----------------test---------');
- $result = JobHunting::create($data);
- if (empty($result)) {
- return Result::error("添加失败", 0);
- }
- return Result::success($result);
- }
- public function delJobHunting(array $data): array
- {
- $result = JobHunting::where('id', $data['id'])->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- }
- return Result::success($result);
- }
- public function updateJobHunting(array $data): array
- {
-
- date_default_timezone_set('Asia/Shanghai');
- unset($data['company_name']);
- unset($data['job_industry']);
- unset($data['job_name']);
- unset($data['department']);
- unset($data['job_timeList']);
- unset($data['job_content']);
- $data['created_at'] = date('Y-m-d H:i:s');
- $data['updated_at'] = date('Y-m-d H:i:s');
- $result = JobHunting::where('id', $data['id'])->update($data);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- }
- return Result::success($result);
- }
- public function getJobHuntingInfo(array $data): array
- {
- $result = JobHunting::where('id', $data['id'])->first();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- public function getJobHuntingData(array $data): array
- {
- $jobEnum = JobEnum::get();
- $jobIndustry = JobIndustry::get();
- $jobNature = JobNature::get();
- $jobPosition = JobPosition::get();
- $data = [
- 'jobEnum' => $jobEnum,
- 'jobIndustry' => $jobIndustry,
- 'jobNature' => $jobNature,
- 'jobPosition' => $jobPosition,
- ];
- return Result::success($data);
- }
- public function delJobHuntingInfo(array $data): array
- {
- $result = JobHunting::where('id', $data['id'])->delete();
- return Result::success();
- }
-
- public function delNotice(array $data): array
- {
- $result = Notice::where('id', $data['id'])->delete();
- if ($result) {
- return Result::success();
- } else {
- return Result::error("删除失败", 0);
- }
- }
- public function getNoticeInfo(array $data): array
- {
- $result = Notice::where('id', $data['id'])->first();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- public function addNotice(array $data): array
- {
- date_default_timezone_set('Asia/Shanghai');
- $data['created_at'] = date('Y-m-d H:i:s');
- $data['updated_at'] = date('Y-m-d H:i:s');
- $user_id = UserInfo::
-
- whereNotNull('city_id')
- ->whereNotNull('department_id')
- ->where(function ($query) use ($data) {
- $query->where(function ($subQuery) use ($data) {
- $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
- });
- })
- ->where(function ($query) use ($data) {
- $query->where(function ($subQuery) use ($data) {
- $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
- });
- })
- ->pluck('user_id')->toArray();
- $user_id = array_unique($user_id);
- $chat_ids = $user_id;
- $user_id = json_encode($user_id);
- $data['re_user_ids'] = $user_id;
- $result = Notice::insertGetId($data);
- if ($result && $data['is_group'] == 1) {
-
- $group_id = PublicData::uuid();
- $groupData = [
- 'id' => $group_id,
- 'creator_id' => $data['user_id'],
- 'group_name' => $data['group_name'] ?? '',
- 'profile' => $data['profile'] ?? 0,
- ];
- $groupResult = ChatGroups::insertGetId($groupData);
- var_dump($groupResult, '-----------------groupid-------');
- $groupMemberData = [
- 'id' => PublicData::uuid(),
- 'user_id' => $data['user_id'],
- 'group_id' => $group_id,
- 'leader' => 2,
- ];
- $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
-
- $chat_ids = array_diff($chat_ids, [$data['user_id']]);
-
- $groupMemberDataUser = [];
- foreach ($chat_ids as $key => $value) {
- $groupMemberDataUser[] = [
- 'id' => PublicData::uuid(),
- 'user_id' => $value,
- 'group_id' => $group_id,
- 'leader' => 1,
- ];
- }
- ChatGroupsMember::insert($groupMemberDataUser);
-
- $data['group_id'] = $group_id;
- Notice::where(['id' => $result])->update($data);
- }
- if (empty($result)) {
- return Result::error("添加失败", 0);
- }
- return Result::success($result);
- }
- public function updateNotice(array $data): array
- {
- date_default_timezone_set('Asia/Shanghai');
-
- $user_id = UserInfo::
-
- whereNotNull('city_id')
- ->whereNotNull('department_id')
- ->where(function ($query) use ($data) {
- $query->where(function ($subQuery) use ($data) {
- $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
- });
- })
- ->where(function ($query) use ($data) {
- $query->where(function ($subQuery) use ($data) {
- $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
- });
- })
- ->pluck('user_id')->toArray();
- $user_id = array_unique($user_id);
- $user_id = json_encode($user_id);
- $data['re_user_ids'] = $user_id;
- $data['updated_at'] = date('Y-m-d H:i:s');
- $result = Notice::where('id', $data['id'])->update($data);
- return Result::success($result);
- }
- public function getNoticeList(array $data): array
- {
- $where = [];
-
- if (isset($data['title']) && !empty($data['title'])) {
- $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
- }
-
- if (isset($data['level']) && !empty($data['level'])) {
- $where[] = ['notice.level', '=', $data['level']];
- }
-
- if (isset($data['status']) && !empty($data['status'])) {
- $where[] = ['notice.status', '=', $data['status']];
- }
- var_dump($data['type_id'], '-----------------test---------');
- if ($data['type_id'] == 10000) {
- $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
- return $query->whereIn('notice.status', [1, 3]);
- })
- ->where($where)
- ->orderBy('updated_at', 'desc')
- ->limit($data['page_size'])
- ->offset(($data['page'] - 1) * $data['page_size'])
- ->get();
- } else {
- $result = Notice::where('status', 1)
- ->where($where)
- ->where('user_id', $data['user_id'])
- ->orWhere(function ($query) use ($data) {
- $query->where('re_user_ids', 'like', '%' . $data['user_id'] . '%');
- })
- ->orderBy('updated_at', 'desc')
- ->limit($data['page_size'])
- ->offset(($data['page'] - 1) * $data['page_size'])
- ->get();
- }
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- $count = Notice::where('status', 1)->count();
- $data = [
- 'rows' => $result,
- 'count' => $count,
- ];
- return Result::success($data);
- }
- public function getNoticeDetail(array $data): array
- {
- $result = Notice::where('id', $data['id'])->first();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- public function deleteNotice(array $data): array
- {
- $notice = Notice::where('id', $data['id'])->first();
- if (empty($notice)) {
- return Result::error("删除失败", 0);
- }
- $chat_group_id = $notice->group_id;
- if ($chat_group_id) {
-
- ChatGroups::where('id', $chat_group_id)->delete();
-
- ChatGroupsMember::where('group_id', $chat_group_id)->delete();
-
- ChatRecords::where('receiver_id', $chat_group_id)->delete();
- }
- $result = Notice::where('id', $data['id'])->delete();
- return Result::success($result);
- }
- public function getMSG(array $data): array
- {
- $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
-
- $user_id = isset($data['user_id']) ? $data['user_id'] : 0;
- $result = [];
- if ($type_id == 1) {
-
- $apply_articale = Article::where('status', 1)
- ->where('admin_user_id', $user_id)
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
-
- $chat = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 1)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
-
- $chat_group = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 2)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
-
- $good = Good::where('status', 2)
- ->where('user_id', $user_id)
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
-
- $notice = Notice::where('status', 1)
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
-
- $complaint = Complaint::where('status', 1)
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
-
- $book = Book::where('status', 1)
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
-
- $job_hunting = JobHunting::where('status', 1)
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
- $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
- $result = [
- 'apply_articale' => $apply_articale,
- 'chat' => $chat,
- 'chat_group' => $chat_group,
- 'good' => $good,
- 'notice' => $notice,
- 'complaint' => $complaint,
- 'book' => $book,
- 'job_hunting' => $job_hunting,
- 'count' => $count,
- ];
- } elseif ($type_id == 2) {
-
- $apply_articale = Article::where('status', 1)
- ->where('admin_user_id', $user_id)
- ->limit(5)->get();
-
- $chat = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 1)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
-
- $chat_group = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 2)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
-
- $good = Good::where('status', 2)
- ->where('user_id', $user_id)
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
- $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
- $result = [
- 'apply_articale' => $apply_articale,
- 'chat' => $chat,
- 'chat_group' => $chat_group,
- 'good' => $good,
- 'count' => $count,
- ];
- } elseif ($type_id == 3) {
-
- $apply_articale = Article::where('status', 1)
- ->where('admin_user_id', $user_id)
- ->limit(5)->get();
-
- $chat = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 1)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
-
- $chat_group = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 2)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
-
- $good = Good::where('status', 2)
- ->where('user_id', $user_id)
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
- $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
- $result = [
- 'apply_articale' => $apply_articale,
- 'chat' => $chat,
- 'chat_group' => $chat_group,
- 'good' => $good,
- 'count' => $count,
- ];
- } elseif ($type_id == 4) {
-
- $apply_articale = Article::where('status', 1)
- ->where('admin_user_id', $user_id)
- ->limit(5)->get();
-
- $good = Good::where('status', 2)
- ->where('user_id', $user_id)
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
- $count = count($apply_articale) + count($good);
- $result = [
- 'apply_articale' => $apply_articale,
- 'chat' => '',
- 'chat_group' => '',
- 'good' => $good,
- 'count' => $count,
- ];
- } elseif ($type_id == 10000) {
-
- $apply_articale = Article::where('status', 0)
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
-
- $chat = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 1)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
-
- $chat_group = ChatRecords::where('is_read', 0)
- ->where('user_id', $user_id)
- ->where('talk_type', 2)
- ->orderBy('created_at', 'desc')
- ->limit(5)->get();
-
- $good = Good::where('status', 1)
-
- ->orderBy('updated_at', 'desc')
- ->limit(5)->get();
- $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
- $result = [
- 'apply_articale' => $apply_articale,
- 'chat' => $chat,
- 'chat_group' => $chat_group,
- 'good' => $good,
- 'count' => $count,
- ];
- } elseif ($type_id == 20000) {
- }
- var_dump($type_id, '-----------------test---------');
- return Result::success($result);
- }
- public function getComplaintList(array $data): array
- {
- var_dump($data, '00000001000000000000');
- $type_id = isset($data['type_id']) ? $data['type_id'] : '';
- unset($data['type_id']);
- $user_id = isset($data['user_id']) ? $data['user_id'] : '';
- $where = [];
- if ($type_id != 10000) {
- $where['complaint.user_id'] = $user_id;
- }
- if (!empty($data['title'])) {
- $where['complaint.title'] = ['like', '%' . $data['title'] . '%'];
- }
- if (!empty($data['deal'])) {
- $where['complaint.deal'] = $data['deal'];
- }
- if (!empty($data['status'])) {
- $where['complaint.status'] = $data['status'];
- }
- var_dump(!empty($data['deal_user']), '----------1');
- $result = Complaint::where($where)
- ->when(!empty($data['status1']), function ($query) use ($data) {
- $query->whereIn('complaint.status', [1, 3]);
- })
- ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
-
- $query->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')');
- })
- ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
-
- ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
- ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
- ->orderBy('updated_at', 'desc')
- ->paginate($data['page_size'], ['*'], 'page', $data['page']);
-
- if (empty($result)) {
- return Result::error("暂无投诉信息", 0);
- }
-
- $rows = $result->items();
- $count = $result->total();
- $responseData = [
- 'rows' => $rows,
- 'count' => $count,
- ];
- return Result::success($responseData);
- }
- public function getComplaintInfo(array $data): array
- {
- $result = Complaint::where('id', $data['id'])->first();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- public function addComplaint(array $data): array
- {
- date_default_timezone_set('Asia/Shanghai');
- $data['created_at'] = date('Y-m-d H:i:s');
- $data['updated_at'] = date('Y-m-d H:i:s');
- $result = Complaint::create($data);
- return Result::success($result);
- }
- public function updateComplaint(array $data): array
- {
- date_default_timezone_set('Asia/Shanghai');
- $data['updated_at'] = date('Y-m-d H:i:s');
- $user_id = $data['user_id'] ?? 0;
- $type_id = $data['type_id'] ?? 0;
- unset($data['user_id']);
- unset($data['type_id']);
- $result = Complaint::where('id', $data['id'])->update($data);
- return Result::success($result);
- }
- public function deleteComplaint(array $data): array
- {
- $result = Complaint::where('id', $data['id'])->delete();
- return Result::success($result);
- }
- public function getComplainInfo(array $data): array
- {
- $result = Complaint::where('id', $data['id'])->first();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
- public function updateComplaintStatus(array $data): array
- {
- date_default_timezone_set('Asia/Shanghai');
- $data['updated_at'] = date('Y-m-d H:i:s');
- $user_id = $data['user_id'] ?? 0;
- $type_id = $data['type_id'] ?? 0;
- unset($data['user_id']);
- unset($data['type_id']);
-
- if (isset($data['deal']) && ($data['deal'] == 1 || $data['deal'] == 4)) {
- $data['real_deal_user'] = $user_id;
- }
-
- if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 3) && $type_id != 10000) {
- $complaintInof = Complaint::where('id', $data['id'])
- ->where('real_deal_user', $user_id)
- ->first();
- if (empty($complaintInof)) {
- return Result::error("处理人错误", 0);
- }
- }
- $result = complaint::where('id', $data['id'])->update($data);
- return Result::success($result);
- }
- public function updateGoodStatus(array $data): array
- {
- $user_id = $data['user_id'] ?? 0;
- $type_id = $data['type_id'] ?? 0;
- unset($data['user_id']);
- unset($data['type_id']);
- $result = Good::where('id', $data['id'])->update($data);
- return Result::success($result);
- }
- public function updateJobHuntingStatus(array $data): array
- {
- $user_id = $data['user_id'] ?? 0;
- $type_id = $data['type_id'] ?? 0;
- unset($data['user_id']);
- unset($data['type_id']);
- $result = JobHunting::where('id', $data['id'])->update($data);
- return Result::success($result);
- }
- public function updateNoticeStatus(array $data): array
- {
- $user_id = $data['user_id'] ?? 0;
- $type_id = $data['type_id'] ?? 0;
- unset($data['user_id']);
- unset($data['type_id']);
- $result = Notice::where('id', $data['id'])->update($data);
- return Result::success($result);
- }
- public function getDUser(array $data): array
- {
- if (!empty($data['ids'])) {
- $user = User::whereIn('id', $data['ids'])->getall();
- if (empty($user)) {
- return Result::error('无数据', 0);
- }
- return Result::success($user);
- }
- $where = [];
- if (!empty($data['department_id'])) {
- $where['department_id'] = $data['department_id'];
- }
- if (!empty($data['city_id'])) {
- $where['city_id'] = $data['city_id'];
- }
- $result = User::where('type_id', 2)
- ->where('status', 1)
- ->where($where)
- ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
- ->get();
- if (empty($result)) {
- return Result::error("查询失败", 0);
- }
- return Result::success($result);
- }
-
-
-
- public function getJobRecruitingList(array $data): array
- {
- $where = [];
-
- if ($data['checkout'] == 0) {
- $job_status = [0, 2];
- } else {
- $job_status = [1];
- }
- 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);
- }
-
- if ($user['type_id'] == 3) {
- array_push($where, ['job_recruiting.user_id', $data['user_id']]);
- array_push($where, ['job_recruiting.website_id', $data['website_id']]);
- }
-
- $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
- return $query->where($where);
- })
- ->whereIn('job_recruiting.status', $job_status)
- ->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();
- $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
- return $query->where($where);
- })
- ->whereIn('job_recruiting.status', $job_status)
- ->count();
- if (empty($result)) {
- return Result::error("暂无招聘信息", 0);
- }
- return Result::success($result);
- }
-
- public function addJobRecruiting(array $data): array
- {
-
- $user = User::where('user.id', $data['user_id'])
- ->where('user.status', 1)
- ->leftJoin('user_info', 'user_info.user_id', 'user.id')
- ->select(
- 'user.type_id',
- 'user.mobile',
- 'user.email',
- 'user_info.business_name',
- 'user_info.company_hy_id',
- 'user_info.company_nature',
- 'user_info.company_size',
- 'user_info.introduction',
- 'user_info.real_name',
- 'user_info.company_url',
- 'user_info.address_arr_id',
- 'user_info.address'
- )
- ->first();
- if (empty($user) || $user['type_id'] != $data['user_type']) {
- return Result::error("用户不存在", 0);
- }
- $web = Website::where('id', $data['website_id'])->first();
- if (empty($web)) {
- return Result::error("网站不存在", 0);
- }
-
- $data['action_id'] = $data['user_id'];
- $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(array_map('intval', $data['cat_arr_id'])) : '';
- $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_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(array_map('intval', $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,
- ];
-
- $job = array_diff_key($data, array_flip(array_keys($company)));
- Db::beginTransaction();
- try {
-
- if ($user['type_id'] == 10000) {
- $job['status'] = 1;
- }
- $jobId = JobRecruiting::insertGetId($job);
- if (empty($jobId)) {
- Db::rollBack();
- return Result::error("添加失败");
- }
-
- $company['user_id'] = $data['user_id'] ?? null;
- $company['job_id'] = $jobId;
- $company['user_type'] = $user['type_id'] ?? null;
- $company['website_id'] = $data['website_id'] ?? null;
- if ($user['type_id'] == 10000) {
-
-
- $companyId = JobCompany::insertGetId($company);
- if (empty($companyId)) {
- Db::rollBack();
- return Result::error("添加失败");
- }
- } else {
-
- $company = [
- 'user_id' => $data['user_id'] ?? null,
- 'business_name' => $user['business_name'] ?? null,
- 'company_hy_id' => $user['company_hy_id'] ?? null,
- 'company_size' => $user['company_size'] ?? null,
- 'company_nature' => $user['company_nature'] ?? null,
- 'introduction' => $user['introduction'] ?? null,
- 'real_name' => $user['real_name'] ?? null,
- 'mobile' => $user['mobile'] ?? null,
- 'company_url' => $user['company_url'] ?? null,
- 'address_arr_id' => $user['address_arr_id'] ?? null,
- 'address' => $user['address'] ?? null,
- 'email' => $user['email'] ?? null,
- 'website_id' => $data['website_id'] ?? null,
- 'user_type' => $user['type_id'] ?? null,
- 'job_id' => $jobId,
- ];
- $companyId = JobCompany::insertGetId($company);
- if (empty($companyId)) {
- Db::rollBack();
- return Result::error("添加失败");
- }
-
- }
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage(), 0);
- }
- $result = [
- 'job_id' => $jobId,
- 'company_id' => $companyId,
- ];
- if (empty($result)) {
- return Result::error("添加失败", 0);
- }
- return Result::success($result);
- }
-
- public function getJobRecruitingInfo(array $data): array
- {
- $result = JobRecruiting::where('job_recruiting.id', $data['id'])
- ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
- ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
- ->select(
- 'job_recruiting.*',
- 'website.website_name as website_name',
- 'job_company.business_name',
- 'job_company.company_hy_id',
- 'job_company.company_size',
- 'job_company.company_nature',
- 'job_company.introduction',
- 'job_company.real_name',
- 'job_company.mobile',
- 'job_company.company_url',
- 'job_company.address_arr_id',
- 'job_company.address',
- 'job_company.email'
- )
- ->first();
- $cityId = json_decode($result['city_arr_id'], true) ?? [];
- if(!empty($cityId)){
- if(isset($cityId[1]) && $cityId[1] != null){
- $city = District::where('id', $cityId[1])->first(['name']);
- }else{
- $city = District::where('id', $cityId[0])->first(['name']);
- }
- $result['city'] = $city['name'] ?? '';
- }
- $addressId = json_decode($result['address_arr_id'], true)?? [];
- if(is_array($addressId) && !empty($addressId)){
- $address = District::whereIn('id', $addressId)
- ->orderBy('level', 'asc')
- ->get(['name'])
- ->pluck('name')
- ->implode('');
-
- $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
- }
- if(empty($result)){
- return Result::error("招聘信息不存在", 0);
- }
-
- return Result::success($result);
- }
-
- public function upJobRecruiting(array $data): array
- {
- $job = JobRecruiting::where('job_recruiting.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);
- }
- if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
- return Result::error("用户暂无权限修改此招聘信息!", 0);
- }
- $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(array_map('intval', $data['cat_arr_id'])) : '';
- $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_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(array_map('intval', $data['address_arr_id'])) : '';
-
- $company = [
- 'business_name' => $data['business_name'] ?? null,
- 'company_hy_id' => $data['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)));
- $jobId = $data['id'];
- $web = $data['website_id'];
- $data['action_id'] = $data['user_id'];
- unset($data['user_id']);
- unset($data['user_type']);
- unset($data['id']);
- unset($data['website_id']);
-
- Db::beginTransaction();
- try {
-
- if ($user['type_id'] == 10000) {
- $data['website_id'] = $web;
- $company['website_id'] = $data['website_id'];
- $data['status'] = 1;
- } else {
- $data['status'] = 0;
- }
-
-
- $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
- if (empty($result['job'])) {
- Db::rollBack();
- return Result::error("修改招聘信息失败");
- }
-
- $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
- if (empty($result['company'])) {
- Db::rollBack();
- return Result::error("修改企业相关信息失败");
- }
- Db::commit();
-
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage(), 0);
- }
- return Result::success($result);
- }
-
- 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);
- }
- if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
- return Result::error("用户暂无权限修改此招聘信息!", 0);
- }
- Db::beginTransaction();
- try {
- $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
- if (empty($result['job'])) {
- Db::rollBack();
- return Result::error("删除招聘信息失败");
- }
- $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
- if (empty($result['company'])) {
- Db::rollBack();
- return Result::error("删除企业相关信息失败");
- }
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage(), 0);
- }
- return Result::success($result);
- }
-
- public function getJobCompany(array $data): array
- {
- $user = User::where('user.id', $data['user_id'])
- ->leftJoin('user_info', 'user_info.user_id', 'user.id')
- ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
- ->first();
-
- if (empty($user)) {
- return Result::error("用户不存在", 0);
- }
- if ($user['type_id'] == 3) {
- $result = [
-
- 'user_id' => $data['user_id'],
- 'website_id' => $data['website_id'],
- 'business_name' => $user['business_name'],
- 'company_hy_id' => $user['company_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'],
- ];
- } else {
- return Result::error("用户类型错误", 0);
- }
- if (empty($result)) {
- return Result::error("公司信息不存在", 0);
- }
- return Result::success($result);
- }
-
- public function upJobCompany(array $data): array
- {
-
- $user = User::where('user.id', $data['user_id'])
- ->where('user.status', 1)
- ->select('user.user_name', 'user.type_id')
- ->first();
- if (empty($user)) {
- return Result::error("用户不存在", 0);
- }
- $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
- $company = [
- 'business_name' => $data['business_name'],
- 'company_hy_id' => $data['company_hy_id'],
- 'company_nature' => $data['company_nature'],
- 'company_size' => $data['company_size'],
- 'introduction' => $data['introduction'],
-
- 'company_url' => $data['company_url'],
- 'address_arr_id' => $data['address_arr_id'],
- 'address' => $data['address'],
- ];
- if ($user['type_id'] == 3) {
- Db::beginTransaction();
- try {
- $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
- 'business_name' => $data['business_name'],
- 'company_hy_id' => $data['company_hy_id'],
- 'company_nature' => $data['company_nature'],
- 'company_size' => $data['company_size'],
- 'introduction' => $data['introduction'],
-
- 'company_url' => $data['company_url'],
- 'address_arr_id' => $data['address_arr_id'],
- 'address' => $data['address'],
- ]);
- $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
- Db::commit();
- } catch (\Exception $e) {
- Db::rollBack();
- return Result::error($e->getMessage(), 0);
- }
- } else {
- return Result::error("用户类型错误", 0);
- }
- if (empty($result)) {
- return Result::error("修改失败", 0);
- }
- return Result::success($result);
- }
-
- public function getJobRecruitingArea(array $data): array
- {
- if(isset($data['pid']) && $data['pid']!=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);
- }
-
- public function checkJobRecruiting(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);
- }
-
- if ($user['type_id'] != 10000) {
- return Result::error("用户暂无权限审核此招聘信息!", 0);
- }
-
- if ($data['status'] == 2) {
- $data['refuse_reason'] = $data['refuse_reason'] ?? null;
- }
- $data['action_id'] = $data['user_id'];
- unset($data['user_id']);
- $result = JobRecruiting::where('id', $data['id'])->update($data);
- if (empty($result)) {
- return Result::error("审核失败", 0);
- }
- return Result::success($result);
- }
-
- public function getRecruitingList(array $data): array
- {
- $user = User::where('id', $data['user_id'])->first();
- if(empty($user) || ($user['type_id']!= 10000 && $user['type_id']!= 1)){
- return Result::error("用户不存在", 0);
- }
- if($user['type_id'] == 1){
- $where['user_id'] = $user['id'];
- }
- $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
- $query->where('recruit_id', $user['id']);
- })
- ->pluck('recruit_id');
- $where = [];
- if(isset($data['salary']) && $data['salary']!=null){
- $where['job_recruiting.salary'] = $data['salary'];
- }
- if(isset($data['experience']) && $data['experience']!=null){
- $where['job_recruiting.experience'] = $data['experience'];
- }
- if(isset($data['business_name']) && $data['business_name']!=null){
- array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
- }
- $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
- ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
- ->where($where);
-
- $count = $query->count();
- $query = clone $query;
- $job = $query
- ->leftJoin('job_enum as income_enum', function ($join) {
- $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
- ->where('income_enum.egroup', 'income');
- })
- ->leftJoin('job_enum as years_enum', function ($join) {
- $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
- ->where('years_enum.egroup', 'years');
- })
-
- ->orderBy('job_recruiting.updated_at', 'desc')
- ->select('job_recruiting.id','job_recruiting.title', 'job_company.business_name',
- 'income_enum.evalue as salary_evalue', 'income_enum.ename as salary_ename',
- 'years_enum.evalue as experience_evalue', 'years_enum.ename as experience_ename'
- ,'job_recruiting.updated_at')
- ->offset(($data['page'] - 1) * $data['pageSize'])
- ->limit($data['pageSize'])
- ->get()
- ->all();
-
- if (empty($job)) {
- return Result::error("暂无招聘信息", 0);
- }
- $result = [
- 'row' => $job,
- 'count' => $count,
- ];
- return Result::success($result);
- }
-
- public function getRecruitingInfo(array $data): array
- {
- $user = User::where('id', $data['user_id'])->first();
- if(empty($user) || ($user['type_id']!= 10000 && $user['type_id']!= 1)){
- return Result::error("用户不存在", 0);
- }
- $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
- ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
- ->select('job_recruiting.*', 'job_company.business_name','job_company.company_hy_id',
- 'job_company.company_size','job_company.company_nature','job_company.introduction','job_company.real_name',
- 'job_company.mobile','job_company.company_url','job_company.address_arr_id','job_company.address','job_company.email')
- ->get();
- if (empty($recruiting)) {
- return Result::error("暂无招聘信息", 0);
- }
- return Result::success($recruiting);
- }
-
-
- public function addBook(array $data): array
- {
- $user_id = $data['user_id'] ?? 0;
- $type_id = $data['type_id'] ?? 0;
- $website_id = $data['website_id'] ?? 0;
-
- unset($data['type_id']);
-
-
-
- $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
- $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
- if ($data['img_url'] == '') {
- $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
- preg_match_all($reg, $data['detail'], $matches);
- if (isset($matches[1][0])) {
-
- $data['img_url'] = substr($matches[1][0], 0, 240);
- }
- }
- if ($data['keyword'] == '') {
-
- $data['keyword'] = $data['title'];
-
- Jieba::init();
- Finalseg::init();
- $segList = Jieba::cut($data['keyword']);
- $segList1 = array_slice($segList, 0, 8);
- $data['keyword'] = implode(',', $segList1);
- }
- if ($data['description'] == '') {
-
- $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
- }
- $result = Book::insertGetId($data);
- if (empty($result)) {
- return Result::error("添加失败", 0);
- }
- return Result::success($result);
- }
- public function getBookList(array $data): array
- {
- $where = [];
- if (!empty($data["title"])) {
- $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
- }
- if (!empty($data['website_name'])) {
- $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
- }
- if (!empty($data['status'])) {
- $where[] = ['book.status', '=', $data['status']];
- }
- $user_id = $data['user_id'];
- $type_id = $data['type_id'];
-
- var_dump($type_id, '------1--------');
- if ($type_id != 10000) {
- $where[] = ['book.user_id', '=', $user_id];
- }
- var_dump(!empty($data['status1']), '=-===1');
- $result = Book::where($where)
- ->leftJoin('website', 'book.website_id', '=', 'website.id')
- ->leftJoin('category', 'book.cat_id', '=', 'category.id')
- ->leftJoin('district', 'book.city_id', '=', 'district.id')
- ->when(isset($data['status1']), function ($query) use ($data) {
- $query->whereIn('book.status', [1, 3]);
- })
- ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
- ->orderBy("updated_at", "desc")
- ->paginate($data['page_size'], ['*'], 'page', $data['page']);
- if (empty($result)) {
- return Result::error("暂无数据", 0);
- }
-
- $rows = $result->items();
- $count = $result->total();
- $responseData = [
- 'rows' => $rows,
- 'count' => $count,
- ];
- return Result::success($responseData);
- }
- public function deleteBook(array $data): array
- {
- $result = Book::where('id', $data['id'])->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- }
- return Result::success($result);
- }
- public function updateBook(array $data): array
- {
- $user_id = $data['user_id'] ?? 0;
- $type_id = $data['type_id'] ?? 0;
- $website_id = $data['website_id'] ?? 0;
- unset($data['user_id']);
- unset($data['type_id']);
-
-
-
- if ($data['img_url'] == '') {
- $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
- preg_match_all($reg, $data['detail'], $matches);
- if (isset($matches[1][0])) {
-
- $data['img_url'] = substr($matches[1][0], 0, 240);
- }
- }
- if ($data['keyword'] == '') {
-
- $data['keyword'] = $data['title'];
-
- Jieba::init();
- Finalseg::init();
- $segList = Jieba::cut($data['keyword']);
- $segList1 = array_slice($segList, 0, 8);
- $data['keyword'] = implode(',', $segList1);
- }
- if ($data['description'] == '') {
-
- $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
- }
- $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
- $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
- $result = Book::where("id", $data["id"])->update($data);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- }
- return Result::success($result);
- }
- public function getBookInfo(array $data): array
- {
- $result = Book::where("id", $data["id"])->first();
- if (empty($result)) {
- return Result::error("获取失败", 0);
- }
- return Result::success($result);
- }
- public function updateBookStatus(array $data): array
- {
- $result = Book::where("id", $data["id"])->update($data);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- }
- return Result::success($result);
- }
-
- }
|