User.php 192 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020/6/18
  7. *
  8. *
  9. */
  10. namespace app\controller\api\user;
  11. use app\common\repositories\article\AgreementRepository;
  12. use app\common\repositories\merchant\order\OrderGzcRepository;
  13. use app\common\repositories\merchant\order\OrderMerchantRepository;
  14. use app\common\repositories\store\product\ProductRepository;
  15. use app\common\repositories\user\UnionUsersRepository;
  16. use app\controller\api\merchant\sxy\Access;
  17. use app\controller\api\store\product\DaTaoKe;
  18. use app\controller\api\store\product\Jd;
  19. use app\controller\api\store\product\TaoBao;
  20. use app\controller\api\store\product\TaoKe;
  21. use app\controller\api\store\product\Vip;
  22. use app\model\common\UserThirdModel;
  23. use app\traits\GzcApiRequest;
  24. use app\traits\HuiPay;
  25. use crmeb\basic\BaseController;
  26. use app\common\repositories\user\UserBillRepository;
  27. use app\common\repositories\user\UserRepository;
  28. use app\common\repositories\user\UserVisitRepository;
  29. use crmeb\services\QrcodeService;
  30. use crmeb\services\WechatService;
  31. use Symfony\Component\HttpFoundation\Request;
  32. use think\App;
  33. use think\facade\Db;
  34. use think\Exception;
  35. use think\exception\ValidateException;
  36. use think\facade\Cache;
  37. use BaiduAi\controller\Ocr;
  38. use think\facade\Log;
  39. use think\facade\Request as r;
  40. use app\common\common;
  41. class User extends BaseController
  42. {
  43. use HuiPay;
  44. public $repository;
  45. private $merId;
  46. private $source;
  47. public function __construct(App $app, UserRepository $repository)
  48. {
  49. parent::__construct($app);
  50. $this->repository = $repository;
  51. $this->source = $this->request->header('source');
  52. $this->merId = $this->request->header('merId');
  53. }
  54. /**
  55. * 创建环信账户
  56. * @return mixed
  57. */
  58. public function hxim_create()
  59. {
  60. $uid = $this->request->uid();
  61. try {
  62. $im = new Im();
  63. $user = Db::name('user')->where('uid', $uid)->field('im_uuid,im_userid as im_user_id,im,uid,nickname,im_password as im_pass')->find();
  64. if (isset($user['im_uuid']) && $user['im_user_id']) {
  65. return app('json')->success($user);
  66. }
  67. $im_user_id = 'user' . $user['uid'];
  68. $data = [];
  69. $data['im_pass'] = mt_rand(100000, 999999);
  70. $data['im_user_id'] = $im_user_id;
  71. // 获取用户是否存在
  72. $imUser = $im->getImUser('user' . $uid);
  73. if (isset($imUser['activated']) && $imUser['activated'] == true) {
  74. $data['im_uuid'] = $imUser['uuid'];
  75. } else {
  76. $data['im_uuid'] = $im->createImUser($im_user_id, $user['nickname'], $data['im_pass']);
  77. }
  78. Db::name('User')->where(['uid' => $uid])->update([
  79. 'im' => 1,
  80. 'im_uuid' => $data['im_uuid'],
  81. 'im_userid' => $im_user_id,
  82. 'im_password' => $data['im_pass']
  83. ]);
  84. return app('json')->success($data);
  85. } catch (\Exception $e) {
  86. Db::name('log')->insert(['data' => '注册异常' . $e->getFile() . $e->getMessage() . $e->getLine()]);
  87. }
  88. return app('json')->fail('注册失败');
  89. }
  90. /**
  91. * @return mixed
  92. * @author xaboy
  93. * @day 2020/6/22
  94. */
  95. public function we_com()
  96. {
  97. $where2['mer_id'] = $this->merId;
  98. $user = Db::name('enterprise')->field('we_com,we_com_url')->where($where2)->find();
  99. return app('json')->success($user);
  100. }
  101. public function spread_image()
  102. {
  103. $type = $this->request->param('type');
  104. $res = $type == 'routine'
  105. ? $this->repository->routineSpreadImage($this->request->userInfo())
  106. : $this->repository->wxSpreadImage($this->request->userInfo());
  107. return app('json')->success($res);
  108. }
  109. /**
  110. * @return mixed
  111. * 分享每日海报
  112. */
  113. public function share_day()
  114. {
  115. /**
  116. * 1242
  117. * 2208
  118. */
  119. $user = $this->request->userInfo();
  120. $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_wap.jpg';
  121. $siteUrl = systemConfig('site_url');
  122. $codeUrl = set_http_type($siteUrl . '/share?spread=' . $user['uid'], request()->isSsl() ? 0 : 1);//二维码链接
  123. $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name, $user['avatar']);
  124. if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
  125. $filename = 'https://88yx.xyz/qqh/uploads/20211101074257444.jpg';
  126. $qrcode = $imageInfo['dir'];
  127. dump($qrcode);
  128. $config = array(
  129. 'image' => array(
  130. array(
  131. 'url' => $qrcode,//二维码资源
  132. 'stream' => 0,
  133. 'left' => 533,
  134. 'top' => 1941,
  135. 'right' => 0,
  136. 'bottom' => 0,
  137. 'width' => 184,
  138. 'height' => 182,
  139. 'opacity' => 100
  140. )
  141. ),
  142. 'background' => $filename
  143. );
  144. $data = setSharePoster($config, 'routine/spread/poster');
  145. dump($data);
  146. return app('json')->success($data);
  147. }
  148. public function spread_info()
  149. {
  150. $user = $this->request->userInfo();
  151. $user->append(['one_level_count', 'lock_brokerage', 'two_level_count', 'spread_total', 'yesterday_brokerage', 'total_extract', 'total_brokerage']);
  152. $data = [
  153. 'lock_brokerage' => $user->lock_brokerage,
  154. 'one_level_count' => $user->one_level_count,
  155. 'two_level_count' => $user->two_level_count,
  156. 'spread_total' => $user->spread_total,
  157. 'yesterday_brokerage' => $user->yesterday_brokerage,
  158. 'total_extract' => $user->total_extract,
  159. 'total_brokerage' => $user->total_brokerage,
  160. 'brokerage_price' => $user->brokerage_price,
  161. 'member_brokerage_price' => $user->member_brokerage_price,
  162. 'now_money' => $user->now_money,
  163. 'broken_day' => (int)systemConfig('lock_brokerage_timer')
  164. ];
  165. return app('json')->success($data);
  166. }
  167. //红包
  168. public function hongbao_info(){
  169. log::info("============hongbao");
  170. $user = $this->request->userInfo();
  171. if($user->uid>0){
  172. //已经入账红包
  173. $data['total_source']=$user->hongbao;
  174. //为生效红包
  175. $data['no_total_source']=Db::name('user_sign_hongbao')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  176. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  177. return app('json')->success($data);
  178. }
  179. }
  180. public function vr_name()
  181. {
  182. $uid = $this->request->uid();
  183. $data = [
  184. "name"=>"VR转账",
  185. "url"=>'https://show.hxxfb.com/?uid=' .$uid,
  186. ];
  187. return app('json')->success($data);
  188. }
  189. public function hongbao_list(){
  190. $pm = $this->request->param('pm');
  191. [$page, $limit] = $this->getPage();
  192. $uid = $this->request->uid();
  193. log::info("hongbao_list==={$uid}");
  194. $where['uid'] = $uid;
  195. if ($pm==0){
  196. $data = DB::name('user_sign_hongbao')->where($where)->where('type', 1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  197. }
  198. if($pm==1){
  199. $data = DB::name('user_sign_hongbao')->where($where)->where('type', 2)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  200. }
  201. if($pm==2){
  202. $data = DB::name('user_sign_hongbao')->where($where)->where('status', -1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  203. }
  204. log::info("=======date==={$data}");
  205. return app("json")->success($data);
  206. }
  207. //贡献值
  208. public function gongxian_info(){
  209. log::info("============gongxianinfo");
  210. $user = $this->request->userInfo();
  211. if($user->uid>0){
  212. // $dateObj=DB::name('user_sign_hongbao')->where('uid', $user->uid)->select();
  213. //已经入账贡献值
  214. $data['total_source']=$user->contribute;
  215. //我的团队贡献值
  216. $data['team_gongxian_num']=$user->contribute;
  217. //为生贡献值
  218. $data['no_total_source']=Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  219. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  220. return app('json')->success($data);
  221. }
  222. }
  223. public function gongxian_list(){
  224. $pm = $this->request->param('pm');
  225. [$page, $limit] = $this->getPage();
  226. $uid = $this->request->uid();
  227. log::info("green_integral_list==={$uid}");
  228. $where['uid'] = $uid;
  229. if ($pm==0){
  230. $data = DB::name('user_sign_gongxian')->where($where)->where('status', 1)->field('id,mark,number,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  231. }
  232. // if($pm==1){
  233. // $data = DB::name('user_sign_gongxian')->where($where)->where('pm', 2)->field('id,mark,number,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  234. //
  235. // }
  236. if($pm==2){
  237. $data = DB::name('user_sign_gongxian')->where($where)->where('status', -1)->field('id,mark,number,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  238. }
  239. log::info("=======date==={$data}");
  240. return app("json")->success($data);
  241. }
  242. //京豆
  243. public function jingdou_info(){
  244. log::info("============hongbao");
  245. $user = $this->request->userInfo();
  246. if($user->uid>0){
  247. //已经入账京豆
  248. //$data['total_source']=$user->vr;//原件
  249. $data['total_source'] = 0;//临时使用
  250. //为生效京豆
  251. $data['no_total_source']=Db::name('user_sign_jingdou')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  252. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  253. return app('json')->success($data);
  254. }
  255. }
  256. public function jingdou_list(){
  257. return;
  258. $pm = $this->request->param('pm');
  259. [$page, $limit] = $this->getPage();
  260. $uid = $this->request->uid();
  261. log::info("jingdou_list==={$uid}");
  262. $where['uid'] = $uid;
  263. if ($pm==0){
  264. $data = DB::name('user_sign_jingdou')->where($where)->where('type', 1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  265. }
  266. if($pm==1){
  267. $data = DB::name('user_sign_jingdou')->where($where)->where('type', 2)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  268. }
  269. // if($pm==2){
  270. // $data = DB::name('user_sign_jingdou')->where($where)->where('status', -1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  271. // }
  272. // $data['total'] =111;
  273. log::info("=======date==={$data}");
  274. return app("json")->success($data);
  275. }
  276. //复购金
  277. public function fugou_info(){
  278. log::info("============fugou");
  279. $user = $this->request->userInfo();
  280. if($user->uid>0){
  281. //已经入账京豆
  282. $data['total_source']=$user->fugou;
  283. //为生效京豆
  284. $data['no_total_source']=Db::name('user_sign_fugou')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  285. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  286. return app('json')->success($data);
  287. }
  288. }
  289. public function fugou_list(){
  290. $pm = $this->request->param('pm');
  291. [$page, $limit] = $this->getPage();
  292. $uid = $this->request->uid();
  293. log::info("fugou_list==={$uid}");
  294. $where['uid'] = $uid;
  295. if ($pm==0){
  296. $data = DB::name('user_sign_fugou')->where($where)->where('type', 1)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  297. }
  298. if($pm==1){
  299. $data = DB::name('user_sign_fugou')->where($where)->where('type', 2)->field('id,mark,number,type,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  300. }
  301. if($pm==2){
  302. $data = DB::name('user_sign_fugou')->where($where)->where('status', -1)->field('id,mark,number,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  303. }
  304. log::info("=======date==={$data}");
  305. return app("json")->success($data);
  306. }
  307. //VR 购物金
  308. public function vr_info(){
  309. log::info("============vr");
  310. $user = $this->request->userInfo();
  311. if($user->uid>0){
  312. //已经入账京豆
  313. $data['total_source'] = $user->vr;
  314. //为生效京豆
  315. $data['no_total_source']=0;
  316. //$data['no_total_source']=Db::name('user_sign_vr')->where('status', -1)->where('uid', $user->uid)->sum('number');;
  317. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  318. return app('json')->success($data);
  319. }
  320. }
  321. public function vr_list(){
  322. $pm = $this->request->param('pm');
  323. [$page, $limit] = $this->getPage();
  324. $uid = $this->request->uid();
  325. log::info("vr_list==={$uid}");
  326. $where['uid'] = $uid;
  327. $data = DB::name('user_sign_vr')->page($page, $limit)->order("id desc")->select();
  328. if ($pm==0){
  329. $data = DB::name('user_sign_vr')->where($where)->where('type', 1)->page($page, $limit)->order("id desc")->select();
  330. }
  331. if($pm==2){
  332. $data = DB::name('user_sign_vr')->where($where)->where('type', 2)->page($page, $limit)->order("id desc")->select();
  333. }
  334. // if($pm==2){
  335. // $data = DB::name('user_sign_vr')->where($where)->where('status', -1)->field('id,mark,number,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  336. //
  337. // }
  338. log::info("=======date==={$data}");
  339. return app("json")->success($data);
  340. }
  341. public function spread_info_yhc()
  342. {
  343. log::info("============ddddddddd");
  344. $user = $this->request->userInfo();
  345. if($user->uid>0){
  346. //已经入账积分
  347. $data['total_source']=$user->score;
  348. //为生效积分
  349. $data['no_total_source']=Db::name('user_sign_score')->where('status', -1)->where('uid', $user->uid)->sum('reward_socre');;
  350. log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
  351. return app('json')->success($data);
  352. }
  353. // if ($this->source == 'yhc' && $this->merId) {
  354. // $where['mer_id'] = $this->merId;
  355. // $where['uid'] = $user->uid;
  356. // $enterprise_user = Db::name('enterprise_user')->where($where)->find();
  357. // if ($enterprise_user) {
  358. // $data['current_balance'] = set_price_rtrim($enterprise_user['commission']);//收益余额
  359. // $data['unsettled_balance'] = 0;//未结算
  360. // $extract_price = Db::name('user_extract')->where($where)->whereIn('status', [0, 1])->sum('extract_price');
  361. // $data['withdrawn_balance'] = set_price_rtrim($extract_price); //已提现
  362. // $data['total_balance'] = set_price_rtrim($enterprise_user['commission'] + $data['withdrawn_balance']);//总收益=收益余额+已提现
  363. // $data['identity'] = $enterprise_user['identity'];
  364. // $data['level'] = $enterprise_user['level'];
  365. // $data['partnership'] = $enterprise_user['partnership'];
  366. // $data['green_integral'] = $enterprise_user['green_integral'];
  367. // $data['green_integral_is'] = $enterprise_user['green_integral_is'];
  368. // $data['operate'] = $enterprise_user['operate'];
  369. // $data['operate_icon'] = '';
  370. // $data['operate_text'] = '';
  371. // $member_settings = merchantConfig($this->merId, 'member_settings');
  372. // if ($data['operate'] == 101) {
  373. // $data['operate_icon'] = $member_settings['yy_one_img'];
  374. // $data['operate_text'] = $member_settings['yy_one_text'];
  375. // }
  376. // if ($data['operate'] == 102) {
  377. // $data['operate_icon'] = $member_settings['yy_two_img'];
  378. // $data['operate_text'] = $member_settings['yy_two_text'];
  379. // }
  380. //
  381. //
  382. // $data['nickname'] = $user->nickname;
  383. // $data['avatar'] = $enterprise_user['avatar'];
  384. //
  385. // $arr = $this->jisuan_fans($user->uid);
  386. // $data['fans_num'] = count($arr);//粉丝总数
  387. //
  388. // $yanglao = 0;
  389. // $offLinewhere = ['mer_id' => $this->merId, 'uid' => $user->uid, 'commission_type' => '5', 'type_shop' => 0];
  390. // $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
  391. // $yanglao += $offLine1;
  392. // $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
  393. // $yanglao += $offLine2;
  394. //
  395. //
  396. // $data['ylj'] = set_price_rtrim($yanglao);
  397. //
  398. // $data['yhc_withdrawal_money'] = merchantConfig($this->merId, 'yhc_withdrawal_money');
  399. //
  400. //
  401. // $data['uid'] = $enterprise_user['uid'];
  402. // if ($enterprise_user['identity'] > 100) {
  403. // $data['identity_data'] = Db::name('enterprise_performance_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['identity'])->find();
  404. // if (!$data['identity_data']) {
  405. // $data['identity_data'] = null;
  406. // $data['identity'] = '100';
  407. // }
  408. // } else {
  409. // $data['identity_data'] = null;
  410. // }
  411. //
  412. // $data['level_data'] = Db::name('enterprise_agent_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['level'])->find();
  413. //
  414. //
  415. // return app('json')->success($data);
  416. // }
  417. // }
  418. return app('json')->fail('用户不存在');
  419. }
  420. /**
  421. * @param UserBillRepository $billRepository
  422. * @return mixed
  423. * @author xaboy
  424. * @day 2020/6/22
  425. */
  426. public function bill(UserBillRepository $billRepository)
  427. {
  428. [$page, $limit] = $this->getPage();
  429. $where = [
  430. // 'now_money' => $this->request->param('type', 0),
  431. 'status' => $this->request->param('status'),
  432. ];
  433. if ($this->request->param('is_red') == true) {
  434. $where['is_red_brokerage'] = 1;
  435. }
  436. return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit));
  437. }
  438. /**
  439. * @param UserBillRepository $billRepository
  440. * @return mixed
  441. * @author xaboy
  442. * @day 2020/6/22
  443. */
  444. public function brokerage_list(UserBillRepository $billRepository)
  445. {
  446. [$page, $limit] = $this->getPage();
  447. return app('json')->success($billRepository->userList([
  448. 'category' => 'brokerage',
  449. ], $this->request->uid(), $page, $limit));
  450. }
  451. /**
  452. * @return mixed
  453. * @throws \think\db\exception\DataNotFoundException
  454. * @throws \think\db\exception\DbException
  455. * @throws \think\db\exception\ModelNotFoundException
  456. * @author xaboy
  457. * @day 2020/6/22
  458. */
  459. public function spread_order()
  460. {
  461. [$page, $limit] = $this->getPage();
  462. return app('json')->success($this->repository->subOrder($this->request->uid(), $page, $limit));
  463. }
  464. /**
  465. * TODO
  466. * @return mixed
  467. * @author Qinii
  468. * @day 2020-06-18
  469. */
  470. public function binding()
  471. {
  472. $data = $this->request->params(['phone', 'sms_code']);
  473. if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
  474. $user = $this->repository->accountByUser($data['phone']);
  475. if ($user) {
  476. $data = ['phone' => $data['phone']];
  477. } else {
  478. $data = ['account' => $data['phone'], 'phone' => $data['phone']];
  479. }
  480. $this->repository->update($this->request->uid(), $data);
  481. return app('json')->success('绑定成功');
  482. }
  483. /**
  484. * TODO
  485. * @return mixed
  486. * @author Qinii
  487. * @day 2020-06-18
  488. */
  489. public function binding_verify()
  490. {
  491. $data = $this->request->params(['user_id', 'captcha']);
  492. $data['phone'] = \think\facade\Db::name("user")->where(["uid" => $data['user_id']])->value("phone");
  493. $data['sms_code'] = $data['captcha'];
  494. if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
  495. return app('json')->success('验证成功');
  496. }
  497. public function checkSmsCode($phone, $code)
  498. {
  499. $sms_key = 'api.auth.sms.' . $phone;
  500. if (!$cache_code = Cache::get($sms_key)) return false;
  501. if ($code != $cache_code) return false;
  502. Cache::delete($sms_key);
  503. return true;
  504. }
  505. /**
  506. * @return mixed
  507. * @throws \think\db\exception\DataNotFoundException
  508. * @throws \think\db\exception\DbException
  509. * @throws \think\db\exception\ModelNotFoundException
  510. * @author xaboy
  511. * @day 2020/6/22
  512. */
  513. public function spread_list()
  514. {
  515. [$level, $sort, $nickname] = $this->request->params(['level', 'sort', 'keyword'], true);
  516. $uid = $this->request->uid();
  517. [$page, $limit] = $this->getPage();
  518. return app('json')->success($level == 2
  519. ? $this->repository->getTwoLevelList($uid, $nickname, $sort, $page, $limit)
  520. : $this->repository->getOneLevelList($uid, $nickname, $sort, $page, $limit));
  521. }
  522. /**
  523. * @return mixed
  524. * @author xaboy
  525. * @day 2020/6/22
  526. */
  527. public function spread_top()
  528. {
  529. [$page, $limit] = $this->getPage();
  530. $type = $this->request->param('type', 0);
  531. return app('json')->success($type == 1
  532. ? $this->repository->spreadMonthTop($page, $limit)
  533. : $this->repository->spreadWeekTop($page, $limit));
  534. }
  535. /**
  536. * @return mixed
  537. * @author xaboy
  538. * @day 2020/6/22
  539. */
  540. public function brokerage_top()
  541. {
  542. [$page, $limit] = $this->getPage();
  543. $type = $this->request->param('type', 0);
  544. return app('json')->success($type == 1
  545. ? $this->repository->brokerageMonthTop($page, $limit)
  546. : $this->repository->brokerageWeekTop($page, $limit));
  547. }
  548. public function history(UserVisitRepository $repository)
  549. {
  550. $uid = $this->request->uid();
  551. [$page, $limit] = $this->getPage();
  552. return app('json')->success($repository->getHistory($uid, $page, $limit));
  553. }
  554. public function deleteHistory($id, UserVisitRepository $repository)
  555. {
  556. $uid = $this->request->uid();
  557. if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid]))
  558. return app('json')->fail('数据不存在');
  559. $repository->delete($id);
  560. return app('json')->success('删除成功');
  561. }
  562. public function account()
  563. {
  564. $user = $this->request->userInfo();
  565. if (!$user->phone) return app('json')->fail('请绑定手机号');
  566. return app('json')->success($this->repository->selfUserList($user->phone));
  567. }
  568. public function switchUser()
  569. {
  570. $uid = (int)$this->request->param('uid');
  571. if (!$uid) return app('json')->fail('用户不存在');
  572. $userInfo = $this->request->userInfo();
  573. if (!$userInfo->phone) return app('json')->fail('请绑定手机号');
  574. $user = $this->repository->switchUser($userInfo, $uid);
  575. $tokenInfo = $this->repository->createToken($user);
  576. $this->repository->loginAfter($user);
  577. return app('json')->success($this->repository->returnToken($user, $tokenInfo));
  578. }
  579. /**
  580. * 签到 获取积分
  581. * @return mixed
  582. * @throws \think\db\exception\DataNotFoundException
  583. * @throws \think\db\exception\DbException
  584. * @throws \think\db\exception\ModelNotFoundException
  585. */
  586. public function sub_signin()
  587. {
  588. $member_id = $this->request->uid();
  589. if (!$member_id) return app('json')->fail('用户不存在');
  590. $res = $this->repository->sub_signin($member_id);
  591. return app('json')->success($res);
  592. }
  593. /**
  594. * 获取用户签到记录
  595. * data1 开始时间
  596. * data2 结束时间
  597. * @return mixed
  598. * @throws \think\db\exception\DataNotFoundException
  599. * @throws \think\db\exception\DbException
  600. * @throws \think\db\exception\ModelNotFoundException
  601. */
  602. public function get_signin()
  603. {
  604. $member_id = $this->request->uid();
  605. if (!$member_id) return app('json')->fail('用户不存在');
  606. $where = [];
  607. $data1 = input('data1');
  608. $data2 = input('data2');
  609. if ($data1 && $data2) {
  610. $where["data1"] = $data1;
  611. $where["data2"] = $data2;
  612. }
  613. $res = $this->repository->get_signin($member_id, $where);
  614. return app('json')->success($res);
  615. }
  616. /**
  617. * 提交实名认证
  618. *
  619. * @return void
  620. */
  621. public function add_certification()
  622. {
  623. $member_id = $this->request->uid();
  624. $type = input("type", 0);
  625. if ($type == 1) {
  626. $data = $this->repository->get_cer(["uid" => $member_id]);
  627. return app('json')->success($data);
  628. }
  629. if (!$member_id) return app('json')->fail('用户不存在');
  630. $params = $this->request->params([
  631. 'user_name',
  632. 'mobile',
  633. 'user_card',
  634. 'card_positive',
  635. 'card_reverse',
  636. ]);
  637. $params['create_time'] = time();
  638. $params['uid'] = $member_id;
  639. $baidu = new Ocr();
  640. $image = file_get_contents($params['card_positive']);
  641. $idCardSide = "front";
  642. $result = $baidu->idcard($image, $idCardSide);
  643. $real_user_name = $result['words_result']['姓名']['words'] ?? '';
  644. $real_user_card = $result['words_result']['公民身份号码']['words'] ?? '';
  645. if ($real_user_name != $params['user_name']) {
  646. return app('json')->fail('姓名或身份证号输入有误~');
  647. }
  648. if ($real_user_card != $params['user_card']) {
  649. return app('json')->fail('姓名或身份证号输入有误~');
  650. }
  651. if ($result['image_status'] == "normal" && $result['idcard_number_type'] == 1) {
  652. $params['status'] = 1;
  653. $res = $this->repository->add_cer($params, $member_id);
  654. if ($res) {
  655. $userRepository = app()->make(UserRepository::class);
  656. //赠送积分 完善实名送90个积分,同时送邀请人50个积分
  657. $userRepository->sign_add($member_id, 90,1,'完善实名系统赠送90个积分','','', '', 1, '', 1);
  658. $member_info = Db::name('user')->where( array('uid' => $member_id) )->find();
  659. if($member_info['spread_uid']){
  660. //好友完善实名系统赠送50个积分
  661. $spreadUid = $member_info['spread_uid'];
  662. $userRepository->sign_add($spreadUid, 50,1,'好友完善实名系统赠送50个积分','','', '', 1, '', 1);
  663. }
  664. return app('json')->success($res);
  665. } else {
  666. return app('json')->fail('认证失败');
  667. }
  668. } else {
  669. return app('json')->fail('认证失败,请重新认证');
  670. }
  671. }
  672. /**
  673. * 申请代理
  674. * name:公司名称
  675. * identity:身份
  676. * license:营业执照
  677. */
  678. public function apply_agent()
  679. {
  680. $name = input("name", "");
  681. $identity = input("identity", 1);
  682. $license = input("license", "");
  683. $province_id = input("province_id", "");
  684. $city_id = input("city_id", "");
  685. $area_id = input("area_id", "");
  686. $street_id = input("street_id", "");
  687. $spread_account = input("spread_account", "");
  688. $member_id = $this->request->uid();
  689. if ($identity != 6 && (!$name || !$identity || !$license)) {
  690. return app('json')->fail('请检查参数');
  691. }
  692. if ($identity == 6 && (!$name || !$identity)) {
  693. return app('json')->fail('请检查参数');
  694. }
  695. $data = [
  696. "name" => $name,
  697. "identity" => $identity,
  698. "license" => $license,
  699. "user_id" => $member_id,
  700. "province_id" => $province_id,
  701. "city_id" => $city_id,
  702. "area_id" => $area_id,
  703. "street_id" => $street_id,
  704. 'spread_account' => $spread_account,
  705. "add_time" => time(),
  706. "update_time" => time()
  707. ];
  708. $res = $this->repository->agent($data);
  709. if ($res['code'] == 400) {
  710. return app('json')->fail($res['msg']);
  711. }
  712. return app('json')->success("申请成功", $res);
  713. }
  714. /*查询是否有已申请或者审核中的代理信息*/
  715. public function isAgent()
  716. {
  717. $uid = $this->request->uid();
  718. $data = $this->repository->isAgent($uid);
  719. return app("json")->success($data);
  720. }
  721. /*查询是否有审核成功的未支付或支付失败的订单*/
  722. public function AgentPayDetail()
  723. {
  724. $uid = $this->request->uid();
  725. if (!$uid) {
  726. return app('json')->fail('请检查参数');
  727. }
  728. $where = ['status' => 1, 'pay_status' => ['0', '2'], 'user_id' => $uid];
  729. $data = $this->repository->getAgentPayDetail($where);
  730. return app('json')->success("成功", $data);
  731. }
  732. /**
  733. * 获取信息 全民营销首页
  734. * @return mixed
  735. */
  736. public function get_agent_info()
  737. {
  738. $member_id = $this->request->uid();
  739. $res = $this->repository->get_agent_info($member_id);
  740. if ($res) {
  741. return app('json')->success($res);
  742. } else {
  743. return app('json')->fail('获取失败');
  744. }
  745. }
  746. /**
  747. * 推广统计
  748. * search 搜索
  749. * @return mixed
  750. */
  751. public function get_extension_info()
  752. {
  753. $search = input("search", "");
  754. $where = $this->request->params(["identity"]);
  755. $member_id = $this->request->uid();
  756. $res = $this->repository->get_extension_info($member_id, $search, $where);
  757. if ($res) {
  758. return app('json')->success($res);
  759. } else {
  760. return app('json')->fail('获取失败');
  761. }
  762. }
  763. /**
  764. * 收益统计
  765. * type 搜索
  766. * @return mixed
  767. */
  768. public function get_profit_info()
  769. {
  770. $where = $this->request->params([
  771. 'commission_type',
  772. 'date_on',
  773. 'date_off',
  774. 'order'
  775. ]);
  776. $member_id = $this->request->uid();
  777. $res = $this->repository->get_profit_info($member_id, $where);
  778. if ($res) {
  779. return app('json')->success($res);
  780. } else {
  781. return app('json')->fail('获取失败');
  782. }
  783. }
  784. /**
  785. * 订单统计
  786. * search 搜索
  787. * @return mixed
  788. */
  789. public function get_tuiguang_order()
  790. {
  791. $member_id = $this->request->uid();
  792. $res = $this->repository->get_tuiguang_order($member_id);
  793. if ($res) {
  794. return app('json')->success($res);
  795. } else {
  796. return app('json')->fail('获取失败');
  797. }
  798. }
  799. /*
  800. * 攒金明细统计
  801. * */
  802. public function get_commission_all()
  803. {
  804. $uid = $this->request->uid();
  805. $where['date_on'] = 1;
  806. $where['date_off'] = 0;
  807. // $where['commission_type'] = '';
  808. $date = $this->request->params(['date']);//"today","yesterday","week","month","year"
  809. $where['order'] = $date['date'];
  810. $res = $this->repository->get_profit_info($uid, $where);
  811. return app('json')->success($res);
  812. }
  813. /*
  814. * 攒金明细列表
  815. * */
  816. public function get_commission_list()
  817. {
  818. $uid = $this->request->uid();
  819. [$where['page'], $where['limit']] = $this->getPage();
  820. $data = $this->request->params(['type', 'date']);//"today","yesterday","week","month","year"
  821. $where['type'] = $data['type'];//0线上;1线下
  822. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  823. $res = $this->repository->get_tuiguang_list($uid, $where);
  824. return app('json')->success($res);
  825. }
  826. /*
  827. * 越攒越多佣金
  828. * */
  829. public function get_com_list()
  830. {
  831. $uid = $this->request->uid();
  832. [$where['page'], $where['limit']] = $this->getPage();
  833. $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
  834. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  835. $res = $this->repository->get_com_list($uid, $where);
  836. return app('json')->success($res);
  837. }
  838. /*
  839. * 越攒越多统计
  840. * */
  841. public function get_com_all()
  842. {
  843. $uid = $this->request->uid();
  844. $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
  845. $where['order'] = $data['date'];//"today","yesterday","week","month","year"
  846. $res = $this->repository->get_com_all($uid, $where);
  847. return app('json')->success($res);
  848. }
  849. /**
  850. * 养老金详情
  851. * @return mixed
  852. */
  853. public function get_yanglao()
  854. {
  855. $member_id = $this->request->uid();
  856. $res = $this->repository->get_yanglao($member_id);
  857. if ($res) {
  858. return app('json')->success($res);
  859. } else {
  860. return app('json')->fail('获取失败');
  861. }
  862. }
  863. /**
  864. * 养老金明细
  865. */
  866. public function yanglaolog()
  867. {
  868. $member_id = $this->request->uid();
  869. [$page, $limit] = $this->getPage();
  870. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "type_shop" => 0];
  871. if ($this->source == 'yhc' && $this->merId) {
  872. $where['mer_id'] = $this->merId;
  873. }
  874. $month = $this->request->param('month', '');//年月搜索
  875. $status = $this->request->param('status', 1);
  876. //1-全部 2-已结算 3-未结算 4-已取消
  877. if ($status == 2) {
  878. $where['status'] = 1;
  879. } else if ($status == 3) {
  880. // $where['gzc']=0;
  881. $where['status'] = 0;
  882. } else if ($status == 4) {
  883. $where['status'] = -1;
  884. }
  885. $source = $this->request->param('source', -1);
  886. if ($source > -1) {
  887. $where['source'] = $source;
  888. }
  889. $res = $this->repository->yanglaolog($where, $page, $limit, $month);
  890. if ($res) {
  891. return app('json')->success($res);
  892. } else {
  893. return app('json')->fail('获取失败');
  894. }
  895. }
  896. /*养老金详情*/
  897. public function YangLaoDetail($id)
  898. {
  899. $member_id = $this->request->uid();
  900. $data = $this->request->params([
  901. 'type',
  902. ]);
  903. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => $data['type'], 'bill_id' => $id];
  904. $res = $this->repository->yanglaoDetail($where);
  905. return app('json')->success($res);
  906. }
  907. /**
  908. * 消费明细
  909. * @return mixed
  910. */
  911. public function tripartite()
  912. {
  913. $member_id = $this->request->uid();
  914. $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "tripartite" => ["<>", 0]];
  915. $res = $this->repository->yanglaolog($where);
  916. if ($res) {
  917. return app('json')->success($res);
  918. } else {
  919. return app('json')->fail('获取失败');
  920. }
  921. }
  922. /**
  923. * 提现明细
  924. * @return mixed
  925. */
  926. public function withdrawal()
  927. {
  928. $member_id = $this->request->uid();
  929. $data = $this->request->params([
  930. 'type',
  931. ]);
  932. $where = ["uid" => $member_id, "type" => $data['type'] ? $data['type'] : 2];
  933. if ($this->source == 'yhc') {
  934. $where['mer_id'] = $this->merId;
  935. }
  936. $res = $this->repository->withdrawal_user($where);
  937. if ($res) {
  938. return app('json')->success($res);
  939. } else {
  940. return app('json')->fail('获取失败');
  941. }
  942. }
  943. /**
  944. * 提现详情
  945. * @return mixed
  946. * @author cabbage
  947. * @day 2020/10/31
  948. */
  949. public function withdrawalDetail()
  950. {
  951. $member_id = $this->request->uid();
  952. $extract_id = input("extract_id", 0);
  953. return app('json')->success($this->repository->withdrawalDetail($extract_id, $member_id));
  954. }
  955. /*
  956. * 修改个人信息*/
  957. public function updateUser()
  958. {
  959. $data = $this->request->params([
  960. 'nickname',
  961. 'avatar',
  962. 'sex',
  963. 'birthday',
  964. 'addres',
  965. 'mark'
  966. ]);
  967. $uid = $this->request->uid();
  968. $res = '';
  969. if ($this->source == 'yhc') {
  970. $res = Db::name('enterprise_user')->where('mer_id', $this->merId)->where('uid', $uid)->update(['avatar' => $data['avatar']]);
  971. unset($data['avatar']);
  972. }
  973. $data = $this->repository->updateUser($uid, $data);
  974. if ($data || $res) {
  975. return app("json")->success("修改成功", $data);
  976. }
  977. return app("json")->fail("未做任何修改");
  978. }
  979. /*积分记录*/
  980. public function socreList()
  981. {
  982. [$page, $limit] = $this->getPage();
  983. $uid = $this->request->uid();
  984. $data = $this->repository->socreList($uid, $page, $limit);
  985. return app("json")->success($data);
  986. }
  987. function jisuan_fans($uid)
  988. {
  989. $where22['node_uid'] = $uid;
  990. $where22['mer_id'] = $this->merId;
  991. $arr = $this->jisuantuandui($where22);
  992. $where['puid'] = $uid;
  993. $where['mer_id'] = $this->merId;
  994. $direct_fans = Db::name('enterprise_user')->where($where)->column('uid');//直属粉丝数量
  995. $result = array_unique(array_merge($arr, $direct_fans));
  996. return $result;
  997. }
  998. function jisuantuandui($where, $data = [])
  999. {
  1000. $enterprise_user_team = DB::name('enterprise_user')->where($where)->column('uid');
  1001. $arr = array_merge($data, $enterprise_user_team);
  1002. foreach ($enterprise_user_team as $v) {
  1003. $where['node_uid'] = $v;
  1004. $arr = $this->jisuantuandui($where, $arr);
  1005. }
  1006. return $arr;
  1007. }
  1008. /**
  1009. * 一壶茶-团队列表
  1010. */
  1011. public function team_list_1()
  1012. {
  1013. $teamid = $this->request->uid();
  1014. //$teamid = $this->request->param('teamid');//测试ID
  1015. $teamid = 17;
  1016. $datas_jbp = Db::name('old_user_jbp')->where("id",$teamid)->find();//查询旧系统是否有当前会员
  1017. $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推
  1018. if(!empty($datas_jbp)){
  1019. $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
  1020. //判断大小团队(业绩多的是大部门,业绩小的是小部门)
  1021. $tes = $this->teamPeople($teamid,$type);//1:团队,2:个人
  1022. // 获取分页参数
  1023. $data1= [
  1024. "total"=>100,
  1025. "per_page"=> 10,
  1026. "current_page"=> 1,
  1027. "last_page"=> 1,
  1028. ];
  1029. if($type != 2){
  1030. //小部门和大部门列表数据
  1031. foreach($tes as $k=>$v){
  1032. $curr_pv = '';
  1033. if($v['curr_type']==0){
  1034. $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
  1035. }else if($v['curr_type']==1){
  1036. $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
  1037. }else{
  1038. $curr_pv = 0;
  1039. }
  1040. $data1['data'][$k] = [
  1041. "uid"=>$v["id"],
  1042. "nickname"=> $v['user_name'] . $curr_pv,
  1043. "phone"=> "137****3315",
  1044. "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
  1045. "create_time"=>"2025-01-25 11:00:18",
  1046. "identity"=>"11",
  1047. "level"=> "40002",
  1048. "partnership"=>"22",
  1049. "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩
  1050. "new_performance"=> 0,//新增业绩
  1051. "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,//团购人数(加的这个1 是当前用户的数)
  1052. ];
  1053. }
  1054. }else{
  1055. //直推列表
  1056. foreach($tes as $k=>$v){
  1057. $data1['data'][$k] = [
  1058. "uid"=>$v["uid"],
  1059. "nickname"=> $v['nickname'],
  1060. "avatar"=>$v['avatar'],
  1061. "create_time"=>"2025-01-25 11:00:18",
  1062. ];
  1063. }
  1064. }
  1065. $data['team_list'] = $data1;
  1066. $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;//粉丝数
  1067. $data['new_performance'] = 0;//新增业绩
  1068. $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];//总业绩
  1069. $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];//个人联盟
  1070. $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];//共建联盟
  1071. $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//公共联盟PV
  1072. $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//个人联盟PV
  1073. // $data['effective_fans_num'] = DB::name('enterprise_user')
  1074. }
  1075. //var_dump($data);
  1076. //把新表中的新增邀请用户加到数组中
  1077. //$spread_usersdata = Db::name('user')->where("spread_uid",$teamid)->select();//查询旗下会员
  1078. // 查询当前会员旗下的会员数据
  1079. // 获取分页参数
  1080. [$page, $limit] = $this->getPage();
  1081. // 查询当前会员旗下的会员数据(分页)
  1082. $subordinate_members = Db::name('user')
  1083. ->alias('u')
  1084. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1085. ->where("u.spread_uid", $teamid) // 查询旗下会员
  1086. ->where("so.mer_id", 496)
  1087. // ->where("so.douhuomall", 1)
  1088. // ->where("so.douhuomall_status", 9)
  1089. // ->where("so.status", 0)
  1090. ->group('u.uid') // 确保每个用户只出现一次
  1091. ->page($page, $limit) // 分页查询
  1092. ->select(); // 获取分页数据
  1093. //计算团队总业绩
  1094. // $total_amount=0;
  1095. // foreach($subordinate_members as $k=>$v){
  1096. // }
  1097. // 获取总会员数
  1098. $total_members = Db::name('user') ->alias('u')
  1099. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1100. ->where("u.spread_uid", $teamid) // 查询旗下会员
  1101. ->where("so.mer_id", 496)
  1102. // ->where("so.douhuomall", 1)
  1103. // ->where("so.douhuomall_status", 9)
  1104. // ->where("so.status", 0)
  1105. ->group('u.uid') // 确保每个用户只出现一次
  1106. ->page($page, $limit) // 分页查询
  1107. ->count(); // 获取分页数据
  1108. // 构造分页信息
  1109. $data1 = [
  1110. "total" => $total_members,
  1111. "per_page" => $limit,
  1112. "current_page" => $page,
  1113. "last_page" => ceil($total_members / $limit),
  1114. "data" => []
  1115. ];
  1116. $total_amount_pv_team = 0;//计算总业绩
  1117. //获取团队总数量
  1118. $team_count_total = 0;
  1119. $small_count = 0;//小部门人数
  1120. //var_dump($this->calculatePerformance($subordinate_members));
  1121. //获取大小部门数据(新表)
  1122. $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);//下标0是大部门
  1123. //var_dump( $get_big_small_datas);
  1124. //判断大小部门的人数(根据业绩多的就是大部门,业绩小的就是小部门来计算展示的部门人数);
  1125. $big_team_count = $get_big_small_datas[0]['team_count'];
  1126. $smallteam_count = $get_big_small_datas[1]['team_count'];
  1127. //end
  1128. // 遍历分页数据,构造每个会员的详细信息
  1129. foreach ($subordinate_members as $k => $v) {
  1130. //计算自己和旗下的业绩
  1131. $t_teams_pv = $this->calculatePerformance($v['uid']);
  1132. $total_amount_pv_team += $t_teams_pv['total_performance'];
  1133. $data1['data'][$k] = [
  1134. "uid" => $v["uid"],
  1135. "nickname" => $v['nickname'], // 假设昵称字段为 nickname
  1136. "phone" => substr_replace($v['phone'], '****', 3, 4), // 隐藏手机号中间四位
  1137. "avatar" => $v['avatar'], // 假设头像字段为 avatar
  1138. "create_time" => $v['create_time'], // 假设创建时间为 create_time
  1139. "total_performance" => $t_teams_pv['total_performance'], // 假设总业绩字段需要额外计算
  1140. "new_performance" => $t_teams_pv['total_performance'], // 假设新增业绩字段需要额外计算
  1141. "team_count" => $t_teams_pv['team_count'], // 假设团购人数需要额外计算
  1142. ];
  1143. }
  1144. // 根据 type 参数处理数据
  1145. if ($type == 1) {
  1146. // 大部门:取 total_performance 最大的一个数组
  1147. usort($data1['data'], function ($a, $b) {
  1148. return $b['total_performance'] <=> $a['total_performance'];
  1149. });
  1150. $data1['data'] = array_slice($data1['data'], 0, 1); // 只保留最大的一个
  1151. } elseif ($type == 0) {
  1152. // 小部门:去掉 total_performance 最大的一个数组
  1153. usort($data1['data'], function ($a, $b) {
  1154. return $b['total_performance'] <=> $a['total_performance'];
  1155. });
  1156. $data1['data'] = array_slice($data1['data'], 1); // 去掉第一个
  1157. } elseif ($type == 2) {
  1158. // 直推:不做任何处理
  1159. }
  1160. // 构造最终返回的数据
  1161. $data = [
  1162. 'team_list' => $data1,
  1163. 'fans_num' => $get_big_small_datas[0]['team_count'] + $get_big_small_datas[1]['team_count'], // 粉丝数
  1164. 'new_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 新增业绩
  1165. 'total_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 总业绩
  1166. 'person_nums' => $big_team_count, // 大部门人数
  1167. 'common_nums' => $smallteam_count, // 小部门人数
  1168. 'common_nums_pv' => $get_big_small_datas[0]['total_performance'], // 公共联盟PV
  1169. 'person_nums_pv' => $get_big_small_datas[1]['total_performance'], // 个人联盟PV
  1170. ];
  1171. return app("json")->success($data);
  1172. }
  1173. /**
  1174. * 一壶茶-团队列表
  1175. */
  1176. public function team_list()
  1177. {
  1178. $teamid = $this->request->uid();
  1179. //$teamid = $this->request->param('teamid');//测试ID
  1180. //$teamid = 17;
  1181. if($teamid == 592){
  1182. $teamid = 17;//593,873
  1183. $s = $this->userupdates(873);
  1184. var_dump($s);
  1185. return;
  1186. $team_userinfo_old_jbp1 = $this->getPerformance22($teamid);
  1187. var_dump($team_userinfo_old_jbp1);return;
  1188. }
  1189. //根据用户找jbp1.0的节点人数组 end
  1190. $datas_jbp = Db::name('old_user_jbp')->where("id",$teamid)->find();//查询旧系统是否有当前会员
  1191. $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推
  1192. // 初始化最终返回的数据
  1193. $data = [
  1194. 'team_list' => [],
  1195. 'fans_num' => 0, // 粉丝数
  1196. 'new_performance' => 0, // 新增业绩
  1197. 'total_performance' => 0, // 总业绩
  1198. 'person_nums' => 0, // 个人联盟人数
  1199. 'common_nums' => 0, // 公共联盟人数
  1200. 'common_nums_pv' => 0, // 公共联盟PV
  1201. 'person_nums_pv' => 0, // 个人联盟PV
  1202. ];
  1203. // 如果在旧系统中有数据
  1204. //if (!empty($datas_jbp)) {
  1205. $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
  1206. $tes = $this->teamPeople($teamid, $type); // 1:团队, 2:个人
  1207. $data1 = [
  1208. "total" => 100,
  1209. "per_page" => 10,
  1210. "current_page" => 1,
  1211. "last_page" => 1,
  1212. "data" => []
  1213. ];
  1214. if ($type != 2) {
  1215. foreach ($tes as $k => $v) {
  1216. $curr_pv = '';
  1217. if ($v['curr_type'] == 0) {
  1218. $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
  1219. } elseif ($v['curr_type'] == 1) {
  1220. $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
  1221. } else {
  1222. $curr_pv = 0;
  1223. }
  1224. $data1['data'][$k] = [
  1225. "uid" => $v["id"],
  1226. "nickname" => $v['user_name'] . $curr_pv,
  1227. "phone" => "137****3315",
  1228. "avatar" => "https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
  1229. "create_time" => "2025-01-25 11:00:18",
  1230. "identity" => "11",
  1231. "level" => "40002",
  1232. "partnership" => "22",
  1233. "total_performance" => $curr_pv,
  1234. "new_performance" => 0,
  1235. "team_count" => $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,
  1236. ];
  1237. }
  1238. } else {
  1239. foreach ($tes as $k => $v) {
  1240. $data1['data'][$k] = [
  1241. "uid" => $v["uid"],
  1242. "nickname" => $v['nickname'],
  1243. "avatar" => $v['avatar'],
  1244. "create_time" => "2025-01-25 11:00:18",
  1245. ];
  1246. }
  1247. }
  1248. // 旧系统中的公共部分数据
  1249. $data['team_list'] = $data1;
  1250. $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'];
  1251. $data['new_performance'] = 0;
  1252. $data['total_performance'] = $team_userinfo_old_jbp1['sum_nums_pv'];
  1253. $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];
  1254. $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];
  1255. $data['common_nums_pv'] = max($team_userinfo_old_jbp1['common_nums_pv'], $team_userinfo_old_jbp1['person_nums_pv']);
  1256. $data['person_nums_pv'] = min($team_userinfo_old_jbp1['common_nums_pv'], $team_userinfo_old_jbp1['person_nums_pv']);
  1257. // }
  1258. return app("json")->success($data);
  1259. // // 查询当前会员旗下的会员数据(分页)
  1260. // [$page, $limit] = $this->getPage();
  1261. // $subordinate_members = Db::name('user')
  1262. // // ->alias('u')
  1263. // // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1264. // ->where("spread_uid", $teamid)
  1265. // // ->where("so.mer_id", 496)
  1266. // // ->group('u.uid')
  1267. // ->page($page, $limit)
  1268. // ->select();
  1269. // $total_members = Db::name('user')
  1270. // // ->alias('u')
  1271. // // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1272. // ->where("spread_uid", $teamid)
  1273. // // ->where("so.mer_id", 496)
  1274. // // ->group('u.uid')
  1275. // ->count();
  1276. // $data1 = [
  1277. // "total" => $total_members,
  1278. // "per_page" => $limit,
  1279. // "current_page" => $page,
  1280. // "last_page" => ceil($total_members / $limit),
  1281. // "data" => []
  1282. // ];
  1283. // $total_amount_pv_team = 0;
  1284. // $team_count_total = 0;
  1285. // foreach ($subordinate_members as $k => $v) {
  1286. // $t_teams_pv = $this->calculatePerformance($v['uid']);
  1287. // $total_amount_pv_team += $t_teams_pv['total_performance'];
  1288. // $team_count_total += $t_teams_pv['team_count'];
  1289. // $data1['data'][$k] = [
  1290. // "uid" => $v["uid"],
  1291. // "nickname" => $v['nickname'],
  1292. // "phone" => substr_replace($v['phone'], '****', 3, 4),
  1293. // "avatar" => $v['avatar'],
  1294. // "create_time" => $v['create_time'],
  1295. // "total_performance" => $t_teams_pv['total_performance'],
  1296. // "new_performance" => $t_teams_pv['total_performance'],
  1297. // "team_count" => $t_teams_pv['team_count'],
  1298. // ];
  1299. // }
  1300. // // 获取大小部门数据
  1301. // $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);
  1302. // // 判断大小部门的人数
  1303. // $big_team_count = $get_big_small_datas[0]['team_count'];
  1304. // $small_team_count = $get_big_small_datas[1]['team_count'];
  1305. // // 根据 type 参数处理数据
  1306. // if ($type == 1) {
  1307. // usort($data1['data'], function ($a, $b) {
  1308. // return $b['total_performance'] <=> $a['total_performance'];
  1309. // });
  1310. // $data1['data'] = array_slice($data1['data'], 0, 1);
  1311. // } elseif ($type == 0) {
  1312. // usort($data1['data'], function ($a, $b) {
  1313. // return $b['total_performance'] <=> $a['total_performance'];
  1314. // });
  1315. // $data1['data'] = array_slice($data1['data'], 1);
  1316. // }
  1317. // // 合并数据
  1318. // if (!empty($datas_jbp)) {
  1319. // // 如果旧系统中有数据,合并新旧数据
  1320. // $data['team_list']['data'] = array_merge($data['team_list']['data'], $data1['data']);
  1321. // $data['fans_num'] += $team_count_total;
  1322. // $data['new_performance'] += $total_amount_pv_team;
  1323. // $data['total_performance'] += $total_amount_pv_team;
  1324. // $data['person_nums'] += $big_team_count;
  1325. // $data['common_nums'] += $small_team_count;
  1326. // $data['common_nums_pv'] += $get_big_small_datas[0]['total_performance'];
  1327. // $data['person_nums_pv'] += $get_big_small_datas[1]['total_performance'];
  1328. // } else {
  1329. // // 如果旧系统中没有数据,直接使用新数据
  1330. // $data['team_list'] = $data1;
  1331. // $data['fans_num'] = $team_count_total;
  1332. // $data['new_performance'] = $total_amount_pv_team;
  1333. // $data['total_performance'] = $total_amount_pv_team;
  1334. // $data['person_nums'] = $big_team_count;
  1335. // $data['common_nums'] = $small_team_count;
  1336. // $data['common_nums_pv'] = $get_big_small_datas[0]['total_performance'];
  1337. // $data['person_nums_pv'] = $get_big_small_datas[1]['total_performance'];
  1338. // }
  1339. // return app("json")->success($data);
  1340. }
  1341. //计算自己和自己团队下面的业绩。新表
  1342. //计算自己和自己团队下面的业绩。新表
  1343. public function calculatePerformance($uid)
  1344. {
  1345. // 初始化业绩数组
  1346. $performance = [
  1347. 'personal_performance' => 0, // 个人业绩
  1348. 'team_performance' => 0, // 团队业绩
  1349. 'total_performance' => 0, // 总业绩
  1350. 'team_count' => 0, // 加上自己的团队数量
  1351. ];
  1352. // 定义业绩换算规则
  1353. $performanceMapping = [
  1354. 1180 => 700,
  1355. 10620 => 6300,
  1356. 11800 => 7000
  1357. ];
  1358. // 计算个人业绩
  1359. $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
  1360. if ($personalOrder) {
  1361. // 将浮点数转换为整数
  1362. $totalPrice = (int)$personalOrder['total_price'];
  1363. if (isset($performanceMapping[$totalPrice])) {
  1364. $performance['personal_performance'] = $performanceMapping[$totalPrice];
  1365. }
  1366. }
  1367. // 计算旗下团队成员的业绩
  1368. $teamOrders = Db::name('user')
  1369. ->alias('u')
  1370. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1371. ->where("u.spread_uid", $uid) // 查询旗下会员
  1372. ->where("so.mer_id", 496)
  1373. // ->where("so.douhuomall", 1)
  1374. // ->where("so.douhuomall_status", 9)
  1375. // ->where("so.status", 0)
  1376. ->select();
  1377. $teamOrders_count = Db::name('user')
  1378. ->alias('u')
  1379. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1380. ->where("u.spread_uid", $uid) // 查询旗下会员
  1381. ->where("so.mer_id", 496)
  1382. // ->where("so.douhuomall", 1)
  1383. // ->where("so.douhuomall_status", 9)
  1384. // ->where("so.status", 0)
  1385. ->count();
  1386. $performance['team_count'] = $teamOrders_count + 1; // 赋值团队数量
  1387. foreach ($teamOrders as $order) {
  1388. if ($order['total_price']) {
  1389. // 将浮点数转换为整数
  1390. $totalPrice = (int)$order['total_price'];
  1391. if (isset($performanceMapping[$totalPrice])) {
  1392. $performance['team_performance'] += $performanceMapping[$totalPrice];
  1393. }
  1394. }
  1395. }
  1396. // 计算总业绩
  1397. $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
  1398. // 假设总业绩最大值需要通过后续逻辑判断,这里暂时设置为 false
  1399. return $performance;
  1400. }
  1401. //获取大小部门业绩(新表)
  1402. public function getbig_samll_datas($subordinate_members){
  1403. //单独写一个方法获取大小部门的数据
  1404. $arr_team = [];
  1405. foreach ($subordinate_members as $k => $v) {
  1406. //计算自己和旗下的业绩
  1407. $arr_team[] = $this->calculatePerformance($v['uid']);
  1408. }
  1409. // 初始化变量
  1410. $maxPerformance = 0;
  1411. $maxIndex = -1;
  1412. // 找出 total_performance 最高的记录
  1413. foreach ($arr_team as $index => $item) {
  1414. if ($item['total_performance'] > $maxPerformance) {
  1415. $maxPerformance = $item['total_performance'];
  1416. $maxIndex = $index;
  1417. }
  1418. }
  1419. // 如果找到了最高记录
  1420. if ($maxIndex !== -1) {
  1421. // 提取最高记录
  1422. $maxRecord = $arr_team[$maxIndex];
  1423. // 从原数组中移除该记录
  1424. unset($arr_team[$maxIndex]);
  1425. // 重新索引数组
  1426. $arr_team = array_values($arr_team);
  1427. } else {
  1428. // 如果没有找到记录,可以设置一个默认值
  1429. $maxRecord = null;
  1430. }
  1431. // 计算大部门和小部门的汇总信息
  1432. $majorDepartmentSummary = [
  1433. "total_person_performance" => $maxRecord ? $maxRecord['personal_performance'] : 0,
  1434. "total_team_performance" => $maxRecord ? $maxRecord['team_performance'] : 0,
  1435. "total_performance" => $maxRecord ? $maxRecord['total_performance'] : 0,
  1436. "team_count" => $maxRecord ? $maxRecord['team_count'] : 0,
  1437. "data" => $maxRecord ? [$maxRecord] : []
  1438. ];
  1439. $minorDepartmentSummary = [
  1440. "total_person_performance" => array_sum(array_column($arr_team, 'personal_performance')),
  1441. "total_team_performance" => array_sum(array_column($arr_team, 'team_performance')),
  1442. "total_performance" => array_sum(array_column($arr_team, 'total_performance')),
  1443. "team_count" => array_sum(array_column($arr_team, 'team_count')),
  1444. "data" => $arr_team
  1445. ];
  1446. // 输出结果
  1447. // echo "大部门汇总信息:\n";
  1448. // print_r($majorDepartmentSummary);
  1449. // echo "小部门汇总信息:\n";
  1450. // print_r($minorDepartmentSummary);
  1451. return array($majorDepartmentSummary,$minorDepartmentSummary);
  1452. }
  1453. //计算自己和自己团队下面的业绩。新表
  1454. public function calculatePerformance_copy($uid)
  1455. {
  1456. // 初始化业绩数组
  1457. $performance = [
  1458. 'personal_performance' => 0, // 个人业绩
  1459. 'team_performance' => 0, // 团队业绩
  1460. 'total_performance' => 0, // 总业绩
  1461. 'team_count' =>0, //加上自己的团队数量
  1462. //'team_count_pr'=>0,//实际团队数量(没有加上自己)
  1463. ];
  1464. // 定义业绩换算规则
  1465. $performanceMapping = [
  1466. 1180 => 700,
  1467. 10620 => 6300,
  1468. 11800 => 7000
  1469. ];
  1470. // 计算个人业绩
  1471. $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
  1472. if ($personalOrder) {
  1473. // 将浮点数转换为整数
  1474. $totalPrice = (int)$personalOrder['total_price'];
  1475. if (isset($performanceMapping[$totalPrice])) {
  1476. $performance['personal_performance'] = $performanceMapping[$totalPrice];
  1477. }
  1478. }
  1479. // 计算旗下团队成员的业绩
  1480. $teamOrders = Db::name('user')
  1481. ->alias('u')
  1482. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1483. ->where("u.spread_uid", $uid) // 查询旗下会员
  1484. ->where("so.mer_id", 496)
  1485. // ->where("so.douhuomall", 1)
  1486. // ->where("so.douhuomall_status", 9)
  1487. // ->where("so.status", 0)
  1488. ->select();
  1489. $teamOrders_count = Db::name('user')
  1490. ->alias('u')
  1491. ->join('store_order so', 'u.uid = so.uid', 'LEFT')
  1492. ->where("u.spread_uid", $uid) // 查询旗下会员
  1493. ->where("so.mer_id", 496)
  1494. // ->where("so.douhuomall", 1)
  1495. // ->where("so.douhuomall_status", 9)
  1496. // ->where("so.status", 0)
  1497. ->count();
  1498. $performance['team_count'] = $teamOrders_count+1;//赋值团队数量
  1499. //$performance['team_count_pr'] = $teamOrders_count;//没有加上父级赋值团队数量
  1500. foreach ($teamOrders as $order) {
  1501. if ($order['total_price']) {
  1502. // 将浮点数转换为整数
  1503. $totalPrice = (int)$order['total_price'];
  1504. if (isset($performanceMapping[$totalPrice])) {
  1505. $performance['team_performance'] += $performanceMapping[$totalPrice];
  1506. }
  1507. }
  1508. }
  1509. // 计算总业绩
  1510. $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
  1511. return $performance;
  1512. }
  1513. public function team_list_copy旧表使用()
  1514. {
  1515. $teamid = $this->request->uid();
  1516. //$teamid = $this->request->param('teamid');//测试ID
  1517. $teamid = 17;
  1518. $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推
  1519. $team_userinfo_old_jbp1= $this->getPerformance($teamid);
  1520. //判断大小团队(业绩多的是大部门,业绩小的是小部门)
  1521. $tes = $this->teamPeople($teamid,$type);//1:团队,2:个人
  1522. $data1= [
  1523. "total"=>100,
  1524. "per_page"=> 10,
  1525. "current_page"=> 1,
  1526. "last_page"=> 1,
  1527. ];
  1528. if($type != 2){
  1529. //小部门和大部门列表数据
  1530. foreach($tes as $k=>$v){
  1531. $curr_pv = '';
  1532. if($v['curr_type']==0){
  1533. $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
  1534. }else if($v['curr_type']==1){
  1535. $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
  1536. }else{
  1537. $curr_pv = 0;
  1538. }
  1539. $data1['data'][$k] = [
  1540. "uid"=>$v["id"],
  1541. "nickname"=> $v['user_name'] . $curr_pv,
  1542. "phone"=> "137****3315",
  1543. "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
  1544. "create_time"=>"2025-01-25 11:00:18",
  1545. "identity"=>"11",
  1546. "level"=> "40002",
  1547. "partnership"=>"22",
  1548. "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩
  1549. "new_performance"=> 0,//新增业绩
  1550. "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,//团购人数(加的这个1 是当前用户的数)
  1551. ];
  1552. }
  1553. }else{
  1554. //直推列表
  1555. foreach($tes as $k=>$v){
  1556. $data1['data'][$k] = [
  1557. "uid"=>$v["uid"],
  1558. "nickname"=> $v['nickname'],
  1559. "avatar"=>$v['avatar'],
  1560. "create_time"=>"2025-01-25 11:00:18",
  1561. ];
  1562. }
  1563. }
  1564. $data['team_list'] = $data1;
  1565. $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;//粉丝数
  1566. $data['new_performance'] = 0;//新增业绩
  1567. $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];//总业绩
  1568. $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];//个人联盟
  1569. $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];//共建联盟
  1570. $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//公共联盟PV
  1571. $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//个人联盟PV
  1572. // $data['effective_fans_num'] = DB::name('enterprise_user')
  1573. //把新表中的新增邀请用户加到数组中
  1574. return app("json")->success($data);
  1575. }
  1576. /**
  1577. * 一壶茶-团队列表
  1578. */
  1579. public function team_list_copy()
  1580. {
  1581. $uid = $this->request->uid();
  1582. $where['puid'] = $uid;
  1583. $where['mer_id'] = $this->merId;
  1584. $data['direct_fans_num'] = Db::name('enterprise_user')->where($where)->count();//直属粉丝数量
  1585. //var_dump($uid);
  1586. $arr = $this->jisuan_fans($uid);
  1587. $data['fans_num'] = count($arr);//粉丝总数
  1588. $data['total_performance'] = 12555;//总业绩
  1589. $data['new_performance'] = 15;//新增业绩
  1590. [$page, $limit] = $this->getPage();
  1591. $where2['eu.mer_id'] = $this->merId;
  1592. $type = $this->request->param('type', 0);//1:大部门,0:小部门
  1593. // var_dump($where2);
  1594. $enterprise_user_team = DB::name('enterprise_user')
  1595. ->alias('eu')
  1596. ->join('user u', 'eu.uid=u.uid')
  1597. ->where($where2)
  1598. ->when($type < 1 || $type == 2, function ($q) use ($arr) {
  1599. $q->whereIn('eu.uid', $arr);
  1600. })
  1601. ->when($type == 1, function ($q) use ($uid) {
  1602. $q->whereIn('eu.puid', $uid);
  1603. })
  1604. ->when($type == 2, function ($q) use ($uid) {
  1605. $q->whereIn('eu.identity', [100, 101, 102, 103, 104, 105]);
  1606. })
  1607. ->field('eu.uid,u.nickname,u.phone,eu.avatar,eu.create_time,eu.identity,eu.level,eu.partnership')
  1608. ->order('eu.enterprise_user_id desc')
  1609. ->paginate($limit)
  1610. ->each(function ($item) {
  1611. $item['phone'] = substr_replace($item['phone'], '****', 3, 4);
  1612. return $item;
  1613. });
  1614. //var_dump($enterprise_user_team);
  1615. $data['team_list'] = $enterprise_user_team;
  1616. $data['effective_fans_num'] = DB::name('enterprise_user')
  1617. ->alias('eu')
  1618. ->join('user u', 'eu.uid=u.uid')
  1619. ->where($where2)
  1620. ->whereIn('eu.uid', $arr)
  1621. ->whereIn('eu.identity', [100, 101, 102, 103, 104, 105])
  1622. ->count();//有效粉丝数量
  1623. return app("json")->success($data);
  1624. }
  1625. public function team_details()
  1626. {
  1627. $uid = $this->request->param('uid', 0);
  1628. $where2['eu.uid'] = $uid;
  1629. $where2['eu.mer_id'] = $this->merId;
  1630. $enterprise_user_team = DB::name('enterprise_user')
  1631. ->alias('eu')
  1632. ->join('user u', 'eu.uid=u.uid')
  1633. ->where($where2)
  1634. ->field('eu.uid,u.nickname,u.phone,u.avatar,eu.create_time,eu.identity,eu.level,eu.partnership,eu.puid')
  1635. ->find();;
  1636. if ($enterprise_user_team) {
  1637. $enterprise_user_team['phone'] = substr_replace($enterprise_user_team['phone'], '****', 3, 4);
  1638. $enterprise_user_team['p_nickname'] = '';
  1639. $enterprise_user_team['p_phone'] = '';
  1640. $yanglao = 0;
  1641. $offLinewhere = ['mer_id' => $this->merId, 'uid' => $uid, 'commission_type' => '5', 'type_shop' => 0];
  1642. $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
  1643. $yanglao += $offLine1;
  1644. $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
  1645. $yanglao += $offLine2;
  1646. $enterprise_user_team['ylj'] = set_price_rtrim($yanglao);
  1647. if ($enterprise_user_team['puid'] > 0) {
  1648. $user = Db::name('user')->where('uid', $enterprise_user_team['puid'])->find();
  1649. if ($user) {
  1650. $enterprise_user_team['p_nickname'] = $user['nickname'];
  1651. $enterprise_user_team['p_phone'] = substr_replace($user['phone'], '****', 3, 4);
  1652. }
  1653. }
  1654. }
  1655. return app("json")->success($enterprise_user_team);
  1656. }
  1657. /**
  1658. * 率积分明细
  1659. */
  1660. public function green_integral_list()
  1661. {
  1662. $pm = $this->request->param('pm');
  1663. $status = $this->request->param('status');
  1664. [$page, $limit] = $this->getPage();
  1665. $uid = $this->request->uid();
  1666. log::info("green_integral_list==={$uid}");
  1667. $where['uid'] = $uid;
  1668. // $where['mer_id'] = $this->merId;
  1669. // if ($pm == 1) {
  1670. // $pm_arr = [1, 3];
  1671. // } else {
  1672. // $pm_arr = [2, 4];
  1673. // }
  1674. if ($pm==0){
  1675. $data = DB::name('user_sign_score')->where($where)->where('pm', 1)->where('status', 1)->field('id,mark,reward_socre,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  1676. }
  1677. if($pm==1){
  1678. $data = DB::name('user_sign_score')->where($where)->where('pm', 2)->where('status', 1)->field('id,mark,reward_socre,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  1679. }
  1680. if($pm==2){
  1681. $data = DB::name('user_sign_score')->where($where)->where('status', -1)->field('id,mark,reward_socre,pm,addtime,order_id')->page($page, $limit)->order("id desc")->select();
  1682. }
  1683. log::info("=======date==={$data}");
  1684. return app("json")->success($data);
  1685. }
  1686. public function user_invite_profit_list()
  1687. {
  1688. $uid = $this->request->uid();
  1689. [$page, $limit] = $this->getPage();
  1690. $commission_type = $this->request->param('commission_type', 0);
  1691. if ($commission_type) {
  1692. $where['commission_type'] = $commission_type;
  1693. }
  1694. $month = $this->request->param('month', '') ?: date('Y-m');
  1695. $startMonth = date('Y-m-01 00:00:00', strtotime($month));
  1696. $endMonth = date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month)));
  1697. $data['yanglao_clear_all'] = Db::name('user_bill')
  1698. ->where('uid', $uid)
  1699. ->whereBetween('create_time', [$startMonth, $endMonth])
  1700. ->where('commission_type', 5)
  1701. ->where('pm', 1)
  1702. ->where('status', 1)
  1703. ->sum('number');
  1704. $data['yanglao_nclear_all'] = Db::name('user_bill')
  1705. ->where('uid', $uid)
  1706. ->whereBetween('create_time', [$startMonth, $endMonth])
  1707. ->where('commission_type', 5)
  1708. ->where('pm', 1)
  1709. ->where('status', 0)
  1710. ->sum('number');
  1711. $data['yanglao_yugu_all'] = $data['yanglao_clear_all'] + $data['yanglao_nclear_all'];
  1712. $where['uid'] = $uid;
  1713. $data['totel_money'] = Db::name('user_bill')->where($where)
  1714. ->whereNotIn('commission_type', [5, 7, 17, 19])
  1715. ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
  1716. $query->whereBetween('create_time', [$startMonth, $endMonth]);
  1717. }, function ($query) use ($where, $month, $startMonth, $endMonth) {
  1718. $query->where('commission_type', '<>', 5)
  1719. ->whereBetween('create_time', [$startMonth, $endMonth]);
  1720. })
  1721. ->sum('number');
  1722. $pageInfo = Db::name('user_bill')
  1723. ->where($where)
  1724. ->whereNotIn('commission_type', [5, 7, 17, 19])
  1725. ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
  1726. $query->whereBetween('create_time', [$startMonth, $endMonth]);
  1727. }, function ($query) use ($where, $month, $startMonth, $endMonth) {
  1728. $query->where('commission_type', '<>', 5)
  1729. ->whereBetween('create_time', [$startMonth, $endMonth]);
  1730. })
  1731. ->order('bill_id desc')
  1732. ->paginate($limit);
  1733. $data_arr = [];
  1734. foreach ($pageInfo->items() as $k => $v) {
  1735. $v['money'] = set_price_rtrim($v['number']);
  1736. $v['order_money'] = set_price_rtrim(0);
  1737. $v['commission_rate'] = set_price_rtrim(0);
  1738. $order = Db::name('store_order')->where('order_sn', $v['order_sn'])->find();
  1739. if (!empty($order)) {
  1740. $v['order_money'] = set_price_rtrim($order['total_price']);
  1741. $v['commission_rate'] = set_price_rtrim(bcdiv($v['money'], $v['order_money'], 2));
  1742. }
  1743. if ($v['status'] == 0) {
  1744. // $v['create_time'] = '--';
  1745. }
  1746. if ($v['status'] == 1) {
  1747. // $v['create_time'] = $v['take_time'];
  1748. }
  1749. $data_arr[] = $v;
  1750. }
  1751. $data['pageInfo']['current_page'] = $pageInfo->currentPage();
  1752. $data['pageInfo']['data'] = $data_arr;
  1753. $data['pageInfo']['last_page'] = $pageInfo->lastPage();
  1754. return app("json")->success($data);
  1755. }
  1756. /*导航转链-用于用户下单绑定*/
  1757. public function changeLink()
  1758. {
  1759. $uid = $this->request->uid();
  1760. if (!$uid) {
  1761. return app("json")->error("请登录");
  1762. }
  1763. $data = $data = $this->request->params([
  1764. 'url',
  1765. 'name'
  1766. ]);
  1767. $data['url'] = urldecode($data['url']);
  1768. $data['name'] = urldecode($data['name']);
  1769. if (in_array($data['name'], ['京东', '苏宁易购', '饿了么', '唯品会', '拼多多'])) {
  1770. if ($data['name'] == '京东') {
  1771. $url = app()->make(Jd::class)->linkChange($data['url'], $uid);
  1772. }
  1773. if ($data['name'] == '拼多多') {
  1774. $url = app()->make(TaoKe::class)->changeLink($data['url'], $uid);
  1775. }
  1776. if ($data['name'] == '唯品会') {
  1777. $url = app()->make(Vip::class)->changeLink($data['url'], $uid);
  1778. }
  1779. if ($data['name'] == '苏宁易购') {
  1780. $url = $data['url'];
  1781. //$url = app()->make(Su::class)->changeLink($data['url'],$uid);
  1782. }
  1783. if ($data['name'] == '饿了么') {//获取饿了么官方活动链接
  1784. //如果用户没有拉取relation_id,
  1785. $where = ['uid' => $uid, 'type' => 5];
  1786. $isRelation = UserThirdModel::where($where)->find();
  1787. if ($isRelation) {
  1788. $result = DaTaoKe::activityChangeLink('20150318020002597', $uid);
  1789. if ($result['code'] == 0) {
  1790. return \app('json')->fail("获取饿了么链接出错", $result['raw']);
  1791. }
  1792. $url = $result['link'];
  1793. } else {//如果还没有获取用户的relation_id还需要拉淘宝授权
  1794. $state = "{$uid}_h5";
  1795. $url = \app()->make(TaoBao::class)->getAuthUrl($state);
  1796. }
  1797. }
  1798. }
  1799. return app("json")->success($url);
  1800. }
  1801. /*获取协议*/
  1802. public function xieyi()
  1803. {
  1804. $data = $this->request->params([
  1805. 'type'
  1806. ]);
  1807. $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($data['type']);
  1808. return app("json")->success($data);
  1809. }
  1810. /*获取规则文章*/
  1811. public function guize()
  1812. {
  1813. $id = $this->request->param('id');
  1814. $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($id);
  1815. if(!$data){
  1816. $data['title']='';
  1817. $data['content']='';
  1818. }
  1819. $html='<!DOCTYPE html>
  1820. <html lang="en">
  1821. <head>
  1822. <meta charset="UTF-8">
  1823. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  1824. <title>'.$data['title'].'</title>
  1825. <style>
  1826. body {
  1827. font-family: Arial, sans-serif;
  1828. margin: 0;
  1829. padding: 0;
  1830. }
  1831. .container {
  1832. margin: 0 auto;
  1833. padding: 20px;
  1834. }
  1835. </style>
  1836. </head>
  1837. <body>
  1838. <div class="container">
  1839. '.$data['content'].'
  1840. </div>
  1841. </body>
  1842. </html';
  1843. return $html;
  1844. }
  1845. /**
  1846. * 支付宝获取授权
  1847. * @return mixed
  1848. * @author php迷途小书童
  1849. * @created 2021/1/16 17:03
  1850. */
  1851. public function alipayAuthorization(UserRepository $userRepository)
  1852. {
  1853. $authorization_code = $this->request->param('code');
  1854. $type = $this->request->param('type', 'h5');
  1855. $paramStr = $userRepository->getTokenByCode($authorization_code, false, $type);
  1856. return app("json")->success($paramStr);
  1857. }
  1858. /**
  1859. * 微信获取授权
  1860. * @return mixed
  1861. * @author php迷途小书童
  1862. * @created 2021/1/16 19:08
  1863. */
  1864. public function wechatAuthorization()
  1865. {
  1866. $request = $this->request;
  1867. $wxConfig = [
  1868. "appid" => "wx66f5f8def2b755da",
  1869. "appsecret" => "891572d83222105a635cf9f502363ff8"
  1870. ];
  1871. $oauth = WechatService::create()->getApplication()->oauth;
  1872. // dump($oauth);
  1873. $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
  1874. try {
  1875. $wechatInfo = $oauth->user()->getOriginal();
  1876. } catch (\Exception $e) {
  1877. return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]);
  1878. }
  1879. if (!isset($wechatInfo['nickname'])) {
  1880. return app('json')->fail('授权失败[002]');
  1881. }
  1882. return app("json")->success($wechatInfo);
  1883. }
  1884. /**
  1885. * 更新绑定微信支付宝账号
  1886. * type=1 微信 2 支付宝
  1887. * openid openid
  1888. */
  1889. public function updateAccount(UserRepository $userRepository)
  1890. {
  1891. $type = $this->request->param('type');
  1892. $openid = $this->request->param('openid');//前端传的是unionid
  1893. $nickname = $this->request->param('nickname');
  1894. $avater = $this->request->param('avater');
  1895. $alinfo = $this->request->param('alinfo');
  1896. $uid = $this->request->uid();
  1897. $user = $this->request->userInfo();
  1898. if (!$type) {
  1899. return app("json")->fail("失败");
  1900. }
  1901. makeLock()->lock();
  1902. try {
  1903. if ($type == 1) {
  1904. $data = ["wechat_user_id" => $openid];
  1905. $unionId = $openid;
  1906. $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
  1907. if ($check) throw new \Exception("此微信号已被绑定");
  1908. } else {
  1909. $alinfo = json_decode($alinfo, true);
  1910. if (!$alinfo) throw new \Exception("参数异常");
  1911. $data = ["ali_user_id" => $alinfo["userId"]];
  1912. $unionId = $alinfo["userId"];
  1913. $check = Db::name("user")->where("ali_user_id", $unionId)->find();
  1914. if ($check) throw new \Exception("此支付宝号已被绑定");
  1915. $paramStr = $userRepository->getTokenByCode($alinfo["authCode"], true);
  1916. // \think\facade\Db::name('log')->insert(['data'=>'支付宝授权信息'.json_encode($paramStr)]);
  1917. $nickname = empty($paramStr["nick_name"]) ? "al" . $alinfo["userId"] : $paramStr["nick_name"];
  1918. $avater = empty($paramStr["avatar"]) ? "http://app.bjtdba.com/uploads/def/20201118/5984361a2e00f5407776bcd6eaaae1ce.png" : $paramStr["avatar"];
  1919. }
  1920. $data2 = [
  1921. "type" => $type,
  1922. "uid" => $uid,
  1923. "nickname" => $nickname,
  1924. "avater" => $avater,
  1925. ];
  1926. $result = $this->repository->updateUser($uid, $data, $data2);
  1927. if (!$result) throw new \Exception("修改失败");
  1928. $userRepository = app()->make(UserRepository::class);
  1929. $userInfo = $userRepository->getOne(['uid' => $uid]);
  1930. //绑定线下充值金额
  1931. $unionUsersRepository = app()->make(UnionUsersRepository::class);
  1932. $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1933. $notBind = $unionUsersRepository->getAllNotBind($unionId);
  1934. if ($notBind) {
  1935. $orderMerchantRepository->doBindUser($userInfo, $type);
  1936. }
  1937. } catch (\Throwable $e) {
  1938. makeLock()->unlock();
  1939. return app("json")->fail("失败" . $e->getMessage());
  1940. }
  1941. makeLock()->unlock();
  1942. return app("json")->success("修改成功", $data);
  1943. }
  1944. /**
  1945. * 获取账号绑定信息
  1946. * @return mixed
  1947. */
  1948. public function getAccount()
  1949. {
  1950. $uid = $this->request->uid();
  1951. // $data = $this->repository->getUser($uid, "wechat_user_id,ali_user_id");
  1952. $data = $this->repository->getAccount($uid);
  1953. if ($data) {
  1954. return app("json")->success("查询成功", $data);
  1955. }
  1956. return app("json")->fail("未绑定");
  1957. }
  1958. // /*
  1959. // * 养老金统计
  1960. // * */
  1961. // public function get_yanglao_statistics()
  1962. // {
  1963. // $uid = $this->request->uid();
  1964. // //线下数量
  1965. // // 查询未结算
  1966. //
  1967. // $gzc_order_list = Db::name('gzc_logs')->where('uid', $uid)->column('out_trade_no');
  1968. //
  1969. // $onlineYanglaoUserBill = Db::name('user_bill')->where('commission_type', 5)->whereNotIn('order_sn',$gzc_order_list)->where('status', 0)->where('uid', $uid)->sum('number');
  1970. // $onlineYanglaoGzc = Db::name('gzc_logs')->where('success', 0)->where('uid', $uid)->sum('pension');
  1971. // $clearYanglao = Db::name('gzc_logs')->where('success', 1)->where('uid', $uid)->sum('pension');
  1972. //
  1973. // $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
  1974. // $res = GzcApiRequest::checkAmount($userInfo);
  1975. // $gzc = $res['extendData']['amount'] * 0.01;
  1976. // // PCPC-中信公证处
  1977. // $data['all_gzc'] = set_price_rtrim(sprintf("%01.2f", $gzc));
  1978. // // 总养老金
  1979. // $data['all_yanglao'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao + $gzc);
  1980. // // 平台养老金
  1981. // $data['all_yanglao_yhc'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao);
  1982. // // 未结算养老金=预估养老金,不能包含进入公证处未成功的记录(这部分是已结算的)
  1983. // $data['all_yanglao_yugu'] = set_price_rtrim(round($onlineYanglaoUserBill, 2));
  1984. // // 已结算养老金 已入账
  1985. // $data['all_yanglao_clear'] = set_price_rtrim(round($onlineYanglaoGzc+$clearYanglao, 2));
  1986. // // 已入账养老金
  1987. // $data['all_yanglao_in'] = set_price_rtrim(round($clearYanglao, 2));
  1988. // // 平台未入账养老金
  1989. // $data['all_yanglao_nclear'] = set_price_rtrim(round($onlineYanglaoGzc + $onlineYanglaoUserBill, 2));
  1990. // // 待发起
  1991. // $data['all_yanglao_wait'] = set_price_rtrim(round($onlineYanglaoGzc, 2));
  1992. //
  1993. // return app("json")->success("查询成功", $data);
  1994. // }
  1995. /*
  1996. * 养老金统计
  1997. * */
  1998. public function get_yanglao_statistics()
  1999. {
  2000. $uid = $this->request->uid();
  2001. //线下数量
  2002. $offLine = \think\facade\Db::name('order_merchant')->where('uid', $uid)->where('status', 1)->field('pension yanglao')->select()->toArray();
  2003. $data['offLine'] = array(
  2004. 'num' => count($offLine),
  2005. 'yanglao' => round($this->num($offLine, 'yanglao'), 2)
  2006. );
  2007. $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>1,'type_shop'=>0];
  2008. if($this->source=='yhc' && $this->merId){
  2009. $offLinewhere['mer_id']=$this->merId;
  2010. }
  2011. $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
  2012. $data['offLine'] = array(
  2013. 'num' => count($offLine),
  2014. 'yanglao' => round($this->num($offLine, 'number'), 2)
  2015. );
  2016. // $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
  2017. // $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
  2018. // $data['offLine'] = array(
  2019. // 'num' => count($offLine),
  2020. // 'yanglao' => round($this->num($offLine, 'number'), 2)
  2021. // );
  2022. //线上已确认收货
  2023. // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '2,3')->select()
  2024. // ->each(function ($item) {
  2025. // //查询养老金金额
  2026. // $UserBillRepository = app()->make(UserBillRepository::class);
  2027. // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
  2028. // $pension = $bill->number ?? 0;
  2029. // $item['yanglao'] = $pension;
  2030. // return $item;
  2031. // })
  2032. // ->toArray();
  2033. $onLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
  2034. if($this->source=='yhc' && $this->merId){
  2035. $onLinewhere['mer_id']=$this->merId;
  2036. }
  2037. $onLine= \think\facade\Db::name('user_bill')->where($onLinewhere)->select()->toArray();
  2038. $data['onLine'] = array(
  2039. 'num' => count($onLine),
  2040. 'yanglao' => round($this->num($onLine, 'number'), 2)
  2041. );
  2042. //线上未确认收货
  2043. // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '0,1')->select()
  2044. // ->each(function ($item) {
  2045. // //查询养老金金额
  2046. // $UserBillRepository = app()->make(UserBillRepository::class);
  2047. // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
  2048. // $pension = $bill->number ?? 0;
  2049. // $item['yanglao'] = $pension;
  2050. // return $item;
  2051. // })
  2052. // ->toArray();
  2053. $onLine_take_nowhere=['uid'=>$uid,'status'=>'0','commission_type' => '5','source'=>0,'type_shop'=>0];
  2054. if($this->source=='yhc' && $this->merId){
  2055. $onLine_take_nowhere['mer_id']=$this->merId;
  2056. }
  2057. $onLine_take_no=\think\facade\Db::name('user_bill')->where($onLine_take_nowhere)->select()->toArray();
  2058. $data['onLine_take_no'] = array(
  2059. 'num' => count($onLine_take_no),
  2060. 'yanglao' => round($this->num($onLine_take_no, 'number'), 2)
  2061. );
  2062. if($this->source=='yhc' && $this->merId){
  2063. $data['all_num'] = $data['offLine']['num'] +$data['onLine_take_no']['num'] + $data['onLine']['num'];
  2064. $data['all_yanglao_yhc'] = set_price_rtrim(round($data['offLine']['yanglao']+$data['onLine']['yanglao'] + $data['onLine_take_no']['yanglao'] , 2));//总养老金
  2065. $data['all_yanglao_a'] = set_price_rtrim(round($data['offLine']['yanglao'] + $data['onLine']['yanglao'], 2));//已结算养老金
  2066. $data['all_yanglao_yugu'] = set_price_rtrim(round($data['all_yanglao_yhc']-$data['all_yanglao_a'],2));//预估养老金
  2067. $userInfo = Db::name('UserCertification') -> where('uid',$uid) -> field('user_name,user_card') -> find();
  2068. $res = GzcApiRequest::checkAmount($userInfo);
  2069. $data['all_gzc']=set_price_rtrim(sprintf("%01.2f", $res['extendData']['amount'] * 0.01));
  2070. $data['all_yanglao']=set_price_rtrim( $data['all_yanglao_yhc'] + $data['all_gzc']);
  2071. return app("json")->success("查询成功", $data);
  2072. }
  2073. //淘宝
  2074. $tb_a = 0;
  2075. $tb_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>5];
  2076. $tb = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($tb_where)->where('status','<>','-1')->select()->each(function ($value) use (&$tb_a) {
  2077. $value['yanglao'] = 0;
  2078. $value['yanglao'] = $value['number'];
  2079. $value['yanglao_a'] = 0;
  2080. if ($value['status'] == 1) {
  2081. $value['yanglao_a'] = $value['yanglao'];
  2082. $tb_a++;
  2083. }
  2084. return $value;
  2085. })->toArray();
  2086. $data['tb'] = array(
  2087. 'num' => count($tb),
  2088. 'num_a' => $tb_a,
  2089. 'yanglao' => round($this->num($tb, 'yanglao'), 2),
  2090. 'yanglao_a' => round($this->num($tb, 'yanglao_a'), 2),
  2091. );
  2092. //京东
  2093. $jd_a = 0;
  2094. $jd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>6];
  2095. $jd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($jd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$jd_a) {
  2096. $value['yanglao'] = 0;
  2097. $value['yanglao'] = $value['number'];
  2098. $value['yanglao_a'] = 0;
  2099. if ($value['status'] == 1) {
  2100. $value['yanglao_a'] = $value['yanglao'];
  2101. $jd_a++;
  2102. }
  2103. return $value;
  2104. })->toArray();
  2105. $data['jd'] = array(
  2106. 'num' => count($jd),
  2107. 'num_a' => $jd_a,
  2108. 'yanglao' => round($this->num($jd, 'yanglao'), 2),
  2109. 'yanglao_a' => round($this->num($jd, 'yanglao_a'), 2),
  2110. );
  2111. //苏宁
  2112. $su_a = 0;
  2113. $su_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>3];
  2114. $su = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($su_where)->where('status','<>','-1')->select()->each(function ($value) use (&$su_a) {
  2115. $value['yanglao'] = 0;
  2116. $value['yanglao'] = $value['number'];
  2117. $value['yanglao_a'] = 0;
  2118. if ($value['status'] == 1) {
  2119. $value['yanglao_a'] = $value['yanglao'];
  2120. $su_a++;
  2121. }
  2122. return $value;
  2123. })->toArray();
  2124. $data['su'] = array(
  2125. 'num' => count($su),
  2126. 'num_a' => $su_a,
  2127. 'yanglao' => round($this->num($su, 'yanglao'), 2),
  2128. 'yanglao_a' => round($this->num($su, 'yanglao_a'), 2),
  2129. );
  2130. //拼多多
  2131. $pdd_a = 0;
  2132. $pdd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>1];
  2133. $pdd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($pdd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$pdd_a) {
  2134. $value['yanglao'] = 0;
  2135. $value['yanglao'] = $value['number'];
  2136. $value['yanglao_a'] = 0;
  2137. if ($value['status'] == 1) {
  2138. $value['yanglao_a'] = $value['yanglao'];
  2139. $pdd_a++;
  2140. }
  2141. return $value;
  2142. })->toArray();
  2143. $data['pdd'] = array(
  2144. 'num' => count($pdd),
  2145. 'num_a' => $pdd_a,
  2146. 'yanglao' => round($this->num($pdd, 'yanglao'), 2),
  2147. 'yanglao_a' => round($this->num($pdd, 'yanglao_a'), 2),
  2148. );
  2149. //唯品会
  2150. $vip_a = 0;
  2151. $vip_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>2];
  2152. $vip = \think\facade\Db::name('user_bill')->where($vip_where)->where('uid', $uid)->where('status','<>','-1')->select()->each(function ($value) use (&$vip_a) {
  2153. $value['yanglao'] = 0;
  2154. $value['yanglao'] = $value['number'];
  2155. $value['yanglao_a'] = 0;
  2156. if ($value['status'] == 1) {
  2157. $value['yanglao_a'] = $value['yanglao'];
  2158. $vip_a++;
  2159. }
  2160. return $value;
  2161. })->toArray();
  2162. $data['vip'] = array(
  2163. 'num' => count($vip),
  2164. 'num_a' => $vip_a,
  2165. 'yanglao' => round($this->num($vip, 'yanglao'), 2),
  2166. 'yanglao_a' => round($this->num($vip, 'yanglao_a'), 2),
  2167. );
  2168. // 抖音
  2169. $dy_a = 0;
  2170. $dy_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>9];
  2171. $dy = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($dy_where)->where('status','<>','-1')->select()->each(function ($value) use (&$dy_a) {
  2172. $value['yanglao'] = 0;
  2173. $value['yanglao'] = $value['number'];
  2174. $value['yanglao_a'] = 0;
  2175. if ($value['status'] == 1) {
  2176. $value['yanglao_a'] = $value['yanglao'];
  2177. $dy_a++;
  2178. }
  2179. return $value;
  2180. })->toArray();
  2181. $data['dy'] = array(
  2182. 'num' => count($dy),
  2183. 'num_a' => $dy_a,
  2184. 'yanglao' => round($this->num($dy, 'yanglao'), 2),
  2185. 'yanglao_a' => round($this->num($dy, 'yanglao_a'), 2),
  2186. );
  2187. $data['all_num'] = $data['offLine']['num'] +$data['onLine_take_no']['num'] + $data['onLine']['num'] + $data['tb']['num'] + $data['jd']['num'] + $data['su']['num'] + $data['pdd']['num'] + $data['vip']['num'] + $data['dy']['num'];
  2188. $data['all_yanglao'] = round($data['offLine']['yanglao']+$data['onLine']['yanglao'] + $data['onLine_take_no']['yanglao'] + $data['tb']['yanglao'] + $data['jd']['yanglao'] + $data['su']['yanglao'] + $data['pdd']['yanglao'] + $data['vip']['yanglao'] + $data['dy']['yanglao'], 2);
  2189. $data['all_yanglao_a'] = round($data['offLine']['yanglao'] + $data['onLine']['yanglao'] + $data['tb']['yanglao_a'] + $data['jd']['yanglao_a'] + $data['su']['yanglao_a'] + $data['pdd']['yanglao_a'] + $data['vip']['yanglao_a'] + $data['dy']['yanglao_a'], 2);
  2190. $data['third_party_num']=['all_num'=>$data['tb']['num']+$data['jd']['num']+$data['su']['num']+ $data['pdd']['num'] + $data['vip']['num']+ $data['dy']['num']];
  2191. $data['third_party_num_a']=['all_num_a'=>$data['tb']['num_a']+$data['jd']['num_a']+$data['su']['num_a']+ $data['pdd']['num_a'] + $data['vip']['num_a']+ $data['dy']['num_a']];
  2192. $data['third_party_num_n']=['all_num_n'=>$data['third_party_num']['all_num']-$data['third_party_num_a']['all_num_a']];
  2193. return app("json")->success("查询成功", $data);
  2194. }
  2195. public function num($data, $field)
  2196. {
  2197. $sum = 0;
  2198. foreach ($data as $item) {
  2199. $sum += $item[$field];
  2200. }
  2201. return $sum;
  2202. }
  2203. //志愿者升级
  2204. public function changeVolunteer()
  2205. {
  2206. $uid = $this->request->uid();
  2207. //志愿者条件
  2208. $volunteer_achievement = systemConfig("volunteer_achievement");//volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  2209. $volunteer_class = new Volunteer();
  2210. $volunteer = $volunteer_class->volunteer($uid);
  2211. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  2212. $data['grade'] = 0;
  2213. $data['self_yanglao'] = $volunteer['self_yanglao'];
  2214. $data['condition_one'] = systemConfig("volunteer_achievement");//用户本人满足养老金要求可升级为志愿者
  2215. return app('json')->success($data);
  2216. }
  2217. $volunteer_class->grade($uid, 1, $volunteer);
  2218. return app('json')->success('申请成功');
  2219. }
  2220. public function GZC($uid)
  2221. {
  2222. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  2223. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  2224. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  2225. $where = [
  2226. 'uid' => $uid,
  2227. 'pm' => 1,
  2228. 'status' => 1,
  2229. 'type' => 'commission'
  2230. ];
  2231. $user_data = \think\facade\Db::name('user')->where('uid', $uid)->find();
  2232. $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']];
  2233. $user_data['real_name'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_name');
  2234. $user_data['account'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('mobile');
  2235. $user_data['card_id'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_card');
  2236. Db::name('user_bill')->where($where)->select()->each(function ($item) use ($uid, $orderId, $OrderGzcRepository, $user_data, $certification) {
  2237. $is_implement = 1;
  2238. if ($item['source'] == 0) {
  2239. $order_data = \think\facade\Db::name('store_order')->where('order_sn', $item['order_sn'])->value('uid');
  2240. if ($order_data['uid'] == $item['uid']) {
  2241. $is_implement = 0;
  2242. } else {
  2243. $is_implement = 1;
  2244. }
  2245. } else {
  2246. $order_data = \think\facade\Db::name('order_merchant')->where('out_trade_no', $item['order_sn'])->value('uid');
  2247. if ($order_data['uid'] == $item['uid']) {
  2248. $is_implement = 0;
  2249. } else {
  2250. $is_implement = 1;
  2251. }
  2252. }
  2253. if ($is_implement == 1) {
  2254. $online = ['uid' => $uid, 'pay_type' => '1', 'order_sn' => $item['order_sn'], 'order_id' => $item['link_id']];
  2255. $create = [
  2256. 'uid' => $online['uid'],
  2257. 'platform_no' => $orderId,
  2258. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  2259. 'user_name' => $certification['user_name'],
  2260. 'mobile' => $certification['mobile'],
  2261. 'user_card' => $certification['user_card'],
  2262. 'pension' => $item['number'],
  2263. 'order_type' => 2,
  2264. 'out_trade_no' => $online['order_sn']
  2265. ];
  2266. $OrderGzcRepository->create($create);
  2267. }
  2268. });
  2269. }
  2270. //20220712版签到
  2271. public function new_sign()
  2272. {
  2273. // return app('json')->fail('不允许签到');
  2274. $uid = $this->request->uid();//签到用户
  2275. $user = Db::name('user')->where('uid', $uid)->field("spread_uid,first_sign")->find();//上级用户
  2276. //第一天签到获得2积分,第二天获得4积分,第三天获得6积分,第四天获得 10 积分,第五天获得 14积分第六天获得 20积分,
  2277. //连续签到从第七天开始,每日签到获得3积分,第七天连续签到额外奖励 38积分,第 14 天连续签到额外奖励 68 积分,第 21天连续签到额外奖励 128 积分第 30 天连续签到额外奖励 188 积分
  2278. //前6天积分
  2279. $score = [
  2280. 2,//1
  2281. 4,//2
  2282. 6,//3
  2283. 10,//4
  2284. 14,//5
  2285. 20//6
  2286. ];
  2287. //7-30天积分
  2288. $scoreS = 3;
  2289. //额外积分
  2290. $scoreExtra = [
  2291. 7 => 38,
  2292. 14 => 68,
  2293. 21 => 128,
  2294. 30 => 188
  2295. ];
  2296. $today_signintime = strtotime(date('Y-m-d', time()));
  2297. $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
  2298. if (!empty($today_signin_info)) {
  2299. return app('json')->fail('今天已经签到过了');
  2300. } else {
  2301. //查询昨天是否已经签到了
  2302. $yes_signintime = strtotime(date('Y-m-d')) - 86400;
  2303. $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
  2304. $has_qian = 1;
  2305. if (!empty($yes_signin_info)) {
  2306. $has_qian = $yes_signin_info['continuity_day'] + 1;
  2307. $has_qian = $has_qian > 30 ? 1 : $has_qian;
  2308. }
  2309. $get_score = 0;
  2310. $get_gw_score = 0;
  2311. if ($has_qian <= 6) {
  2312. $get_score = $score[$has_qian - 1];
  2313. } else {
  2314. $get_score = $scoreS;
  2315. if (isset($scoreExtra[$has_qian])) {
  2316. $get_gw_score = $scoreExtra[$has_qian];
  2317. }
  2318. }
  2319. $userRepository = app()->make(UserRepository::class);
  2320. $userRepository->sign_add($uid, $get_score, 1, '签到赠送积分', $has_qian, $today_signintime, '', 1, '', 1);
  2321. if($get_gw_score > 0){
  2322. $userRepository->sign_add($uid, $get_gw_score,1,'连续签到赠送额外奖励积分', $has_qian, $today_signintime, '', 1, '', 1);
  2323. }
  2324. //首次签到
  2325. if ($user['first_sign'] == 0) {
  2326. // //首次签到送30积分,同时赠送邀请人30积分
  2327. // $userRepository->sign_add($uid, 30,1,'首次签到送30积分','','', '', 1, '', 1);
  2328. // $member_info = Db::name('user')->where( array('uid' => $uid) )->find();
  2329. // if($member_info['spread_uid']){
  2330. // $spreadUid = $member_info['spread_uid'];
  2331. // $userRepository->sign_add($spreadUid, 30,1,'邀请人首次签到送30积分','','', '', 1, '', 1);
  2332. // }
  2333. Db::name('user')->where('uid', $uid)->update(['first_sign' => 1]);
  2334. } elseif ($user['first_sign'] == 1 && $has_qian == 1) {
  2335. Db::name('user')->where('uid', $uid)->update(['first_sign' => 2]);
  2336. }
  2337. // //非首次签到,第一天,断签
  2338. // //好友连续签到3天 奖励50
  2339. // //好友连续签到14天 奖励100
  2340. // //好友联系签到30天 奖励300
  2341. // if ($user['first_sign'] < 2) {
  2342. // if ($has_qian == 3) {
  2343. // $userRepository->sign_add($user['spread_uid'], 50, 1, '好友签到赠送积分', '', $today_signintime, '');
  2344. // } elseif ($has_qian == 14) {
  2345. // $userRepository->sign_add($user['spread_uid'], 100, 1, '好友签到赠送积分', '', $today_signintime, '');
  2346. // } elseif ($has_qian == 30) {
  2347. // $userRepository->sign_add($user['spread_uid'], 300, 1, '好友签到赠送积分', '', $today_signintime, '');
  2348. // Db::name('user')->where('uid', $uid)->update(['first_sign' => 3]);
  2349. // }
  2350. // }
  2351. return app('json')->success('签到成功', ['score' => $get_score]);
  2352. }
  2353. }
  2354. public function new_sign_info()
  2355. {
  2356. $uid = $this->request->uid();
  2357. //查询今天是否已经签到
  2358. $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
  2359. //查询昨天是否已经签到了
  2360. $yes_signintime = strtotime(date('Y-m-d')) - 86400;
  2361. $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
  2362. $data = [
  2363. 'today' => 0,
  2364. 'day' => 0
  2365. ];
  2366. if ($yes_signin_info) $data['day'] = (int)$yes_signin_info['continuity_day'];
  2367. if ($yes_signin_info['continuity_day'] >= 30) $data['day'] = 0;
  2368. if ($today_signin_info) {
  2369. $data['today'] = 1;
  2370. $data['day'] = $data['day'] + 1;
  2371. }
  2372. return app('json')->success($data);
  2373. }
  2374. /**
  2375. * 积分列表
  2376. * @return mixed
  2377. * @throws \think\db\exception\DataNotFoundException
  2378. * @throws \think\db\exception\DbException
  2379. * @throws \think\db\exception\ModelNotFoundException
  2380. */
  2381. public function sign_list()
  2382. {
  2383. [$page, $limit] = $this->getPage();
  2384. $uid = $this->request->uid();
  2385. $month = $this->request->param('month', '') ?: date('Y-m');
  2386. $status = $this->request->param('status');
  2387. $pm = $this->request->param('pm');
  2388. $startMonth = strtotime(date('Y-m-01 00:00:00', strtotime($month)));
  2389. $endMonth = strtotime(date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month))));
  2390. $count = Db::name('user_sign_score')
  2391. ->whereBetween('addtime', [$startMonth, $endMonth])
  2392. ->when(isset($status) && $status !== '', function ($query) use ($status) {
  2393. $query->where('status', $status);
  2394. })
  2395. ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
  2396. $query->where('pm', $pm);
  2397. })
  2398. ->where('uid', $uid)->count();
  2399. $list = Db::name('user_sign_score')
  2400. ->whereBetween('addtime', [$startMonth, $endMonth])
  2401. ->where('uid', $uid)
  2402. ->when(isset($status) && $status !== '', function ($query) use ($status) {
  2403. $query->where('status', $status);
  2404. })
  2405. ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
  2406. $query->where('pm', $pm);
  2407. })
  2408. ->page($page, $limit)->order('id DESC')->select()->each(function ($item) {
  2409. $item['signin_time'] = date('Y-m-d', $item['signin_time']);
  2410. $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']);
  2411. if (!empty($item['order_id'])) {
  2412. //线上订单
  2413. if ($item['order_type'] == 'store_order' || $item['order_type'] == 'store_order_beishengtang') {
  2414. $item['order_sn'] = Db::name("store_order")->where("order_id", $item['order_id'])->value("order_sn");
  2415. } elseif ($item['order_type'] == 'order_merchant') {
  2416. $item['order_sn'] = Db::name("order_merchant")->where("id", $item['order_id'])->value("out_trade_no");
  2417. } elseif ($item['order_type'] == 'extract') {
  2418. $item['order_sn'] = Db::name("user_extract")->where("extract_id", $item['order_id'])->value("order_sn");
  2419. } else {
  2420. $item['order_sn'] = '';
  2421. }
  2422. } else {
  2423. $item['order_sn'] = '';
  2424. }
  2425. return $item;
  2426. });
  2427. $data['list'] = $list;
  2428. $data['count'] = $count;
  2429. return app('json')->success($data);
  2430. }
  2431. public function getAmountFromGzc()
  2432. {
  2433. $uid = $this->request->uid();
  2434. $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
  2435. $res = GzcApiRequest::checkAmount($userInfo);
  2436. return app('json')->success(['amount' => sprintf("%01.2f", $res['extendData']['amount'] * 0.01)]);
  2437. }
  2438. public function check_user_annual_fee()
  2439. {
  2440. //INSERT INTO rrx_user_pension_account (uid) SELECT uid FROM rrx_user;
  2441. //UPDATE `renrenxiang`.`rrx_user_pension_account` SET `start_time` = '2023-04-07 00:00:00', `end_time` = '2024-04-07 23:59:59', `status` = 1, `give` = 1 WHERE `id` > 0;
  2442. $uid = $this->request->uid();
  2443. $check = Db::name("user_pension_account")->where("uid", $uid)->find();
  2444. $data = [
  2445. "status" => 3,//0:未交年费,1:年费到期。2:未实名认证,3:正常
  2446. ];
  2447. // //未交年费
  2448. // if (!$check || $check["status"] == 0) {
  2449. // $data["status"] = 0;
  2450. // return app('json')->success($data);
  2451. // }
  2452. // //到期时间小于当前时间。年费到期
  2453. // if (strtotime($check['end_time']) < time()){
  2454. // $data["status"] = 1;
  2455. // return app('json')->success($data);
  2456. // }
  2457. // $data["start_time"] = $check['start_time'];
  2458. // $data["end_time"] = $check['end_time'];
  2459. //
  2460. // //检查实名认证
  2461. // $checkCertification = Db::name("user_certification") -> where("uid",$uid) -> find();
  2462. // if (!$checkCertification){
  2463. // $data["status"] = 2;
  2464. // return app('json')->success($data);
  2465. // }
  2466. return app('json')->success($data);
  2467. }
  2468. /**
  2469. *
  2470. * @remarks 创建年费订单
  2471. * @author 小菜菜
  2472. * @created 2023/04/10 14:37
  2473. */
  2474. public function create_annual_order()
  2475. {
  2476. $uid = $this->request->uid();
  2477. $type = $this->request->param('type', 1);
  2478. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  2479. if ($type == 1) $price = "12.00";
  2480. elseif ($type == 2) $price = systemConfig('offline_a');
  2481. elseif ($type == 3) $price = systemConfig('offline_b');
  2482. elseif ($type == 4) $price = systemConfig('offline_c');
  2483. else return app('json')->fail("参数错误");
  2484. $check = Db::name("user_pension_account")->where("uid", $uid)->find();
  2485. //到期时间小于当前时间。年费到期
  2486. if (strtotime($check['end_time']) > time() && $check['status'] == 1) {
  2487. return app('json')->fail("账户已开通,不可重复开通账户");
  2488. }
  2489. $insertData = [
  2490. 'pay_price' => $price,
  2491. 'status' => 0,
  2492. 'order_no' => $OrderMerchantRepository->getNewOrderId("mt"),
  2493. 'uid' => $uid,
  2494. 'type' => $type,
  2495. ];
  2496. $order_id = Db::name('user_pension_account_order')->insertGetId($insertData);
  2497. try {
  2498. return app('json')->success(['order_id' => $order_id]);
  2499. } catch (\Exception $e) {
  2500. return app('json')->status('error', $e->getMessage(), ['order_id' => $order_id]);
  2501. }
  2502. }
  2503. /**
  2504. * @remarks 会员支付
  2505. * @author Tang
  2506. * @created 2021/8/27 9:18
  2507. */
  2508. public function pay_user_annual()
  2509. {
  2510. try {
  2511. $oid = r::param('oid', '');
  2512. $code = r::param('code', '');
  2513. $payType = r::param('type', '');//wx.ALI
  2514. if ($oid == '') return app('json')->fail("请检查参数是否正确");
  2515. $groupOrder = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
  2516. if (!$groupOrder) return app('json')->fail('订单不存在或已支付');
  2517. $access = new Access();
  2518. $res = $access->pay_huifu($payType, $code, $groupOrder, "年费", env('APP_URL') . "/api/hf_notify/pay_user_annual");
  2519. Db::name('log')->insert(['data' => '汇付用户年费支付---' . json_encode($res)]);
  2520. Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
  2521. return app('json')->success($res);
  2522. } catch (\Exception $exception) {
  2523. return app('json')->fail();
  2524. }
  2525. }
  2526. /**
  2527. * @remarks 会员支付 线下
  2528. * @author Tang
  2529. * @created 2021/8/27 9:18
  2530. */
  2531. public function pay_user_annual_offline()
  2532. {
  2533. try {
  2534. $oid = r::param('oid', '');
  2535. $payType = r::param('type', '');//WX.ALI
  2536. $pay_user_id = r::param('pay_user_id', '');//如果是微信。传open_id 如果是支付宝。传user_id
  2537. if ($oid == '') return app('json')->fail("请检查参数是否正确");
  2538. if ($pay_user_id == '') return app('json')->fail("请检查参数是否正确");
  2539. $order = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
  2540. if (!$order) return app('json')->fail('订单不存在或已支付');
  2541. if ($order['type'] == 1) {
  2542. $title = "开通账户";
  2543. } elseif ($order['type'] == 2) {
  2544. $title = "大礼包1";
  2545. } elseif ($order['type'] == 3) {
  2546. $title = "大礼包2";
  2547. } elseif ($order['type'] == 4) {
  2548. $title = "大礼包3";
  2549. } else {
  2550. return app('json')->fail('订单异常');
  2551. }
  2552. if ($order['type'] > 1) {
  2553. //本人给养老金10%
  2554. $ylj = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));//10%的养老金
  2555. $commission = 0;
  2556. //上级给佣金10%
  2557. $order_user = Db::name("user")->where("uid", $order["uid"])->field("spread_uid")->find();
  2558. //推广员id
  2559. $spread_uid = $order_user["spread_uid"];
  2560. if (!empty($spread_uid)) {
  2561. $commission = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));//10%的佣金
  2562. }
  2563. $pt = sprintf("%01.2f", 12 + $ylj + $commission);
  2564. $merchant_money = sprintf("%01.2f", $order['pay_price'] - $pt);
  2565. } else {
  2566. $pt = "12.00";
  2567. $merchant_money = "0.00";
  2568. }
  2569. if ($payType == 'WX') {
  2570. $pay_wx = systemConfig('pay_wx');
  2571. //微信
  2572. if ($pay_wx == 3) {
  2573. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 3)->value('member_id');
  2574. $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  2575. $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
  2576. } else {
  2577. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 2)->value('member_id');
  2578. $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  2579. $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
  2580. }
  2581. $type = '2';
  2582. $pay_channel = 'wx_pub';
  2583. $expend = [
  2584. 'open_id' => $pay_user_id
  2585. ];
  2586. } elseif ($payType == 'ALI') {
  2587. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 1)->value('member_id');
  2588. $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';
  2589. $type = '1';
  2590. $pay_channel = 'alipay_pub';
  2591. $expend = [
  2592. 'buyer_id' => $pay_user_id
  2593. ];
  2594. $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  2595. }
  2596. if ($merchant_money == '0.00') {
  2597. $div_members = [
  2598. [
  2599. 'member_id' => 0,
  2600. 'amount' => $pt,
  2601. 'fee_flag' => 'Y'
  2602. ]
  2603. ];
  2604. } else {
  2605. $div_members = [
  2606. [
  2607. 'member_id' => $member_id,
  2608. 'amount' => $merchant_money,
  2609. 'fee_flag' => 'Y'
  2610. ],
  2611. [
  2612. 'member_id' => 0,
  2613. 'amount' => $pt,
  2614. 'fee_flag' => 'N'
  2615. ]
  2616. ];
  2617. }
  2618. $params = [
  2619. 'order_no' => $order['order_no'] . '_' . rand(000, 999),
  2620. 'app_id' => $app_id,
  2621. 'pay_channel' => $pay_channel,
  2622. 'pay_amt' => (string)$order['pay_price'],
  2623. 'goods_title' => "储蓄保",
  2624. 'goods_desc' => $title,
  2625. 'device_info' => [
  2626. 'device_ip' => app('request')->ip()
  2627. // 'device_ip'=>'115.171.134.68'
  2628. ],
  2629. 'expend' => json_encode($expend),
  2630. 'div_members' => json_encode($div_members),
  2631. 'fee_mode' => 'I',
  2632. 'notify_url' => env('APP_URL') . "/api/jsapiPay/notify/HF_pay_user_annual"
  2633. ];
  2634. $res = $this->Payment_create_traits($params, $type, $key);
  2635. if (!empty($res['error_code'])) {
  2636. return app('json')->fail($res['return_msg']);
  2637. } else {
  2638. Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
  2639. return app('json')->success($res);
  2640. }
  2641. } catch (\Exception $exception) {
  2642. Db::name('log')->insert(['data' => '大礼包支付error:' . $exception->getFile() . ':' . $exception->getLine() . '【' . $exception->getMessage() . '】']);
  2643. return app('json')->fail();
  2644. }
  2645. }
  2646. public function red_log()
  2647. {
  2648. $uid = $this->request->uid();
  2649. [$page, $limit] = $this->getPage();
  2650. $user_rich_log = Db::name('user_rich_log')->where('uid', $uid)->field('uid,red,pm,time,mark')->page($page, $limit)->order('id DESC')->select()->each(function ($item) {
  2651. $item['create_time'] = date('Y-m-d H:i:s', $item['time']);
  2652. $item['red'] = set_price_rtrim($item['red']);
  2653. return $item;
  2654. });
  2655. return app('json')->success($user_rich_log);
  2656. }
  2657. public function apply_bang_fu()
  2658. {
  2659. $uid = $this->request->uid();
  2660. $check = Db::name('user_rich')->where('uid', $uid)->find();
  2661. if ($check['type'] < 3) {
  2662. return app('json')->fail("不满足申请条件");
  2663. }
  2664. $check = Db::name('user_bangfu')->where('uid', $uid)->value('status');
  2665. if ($check == 0) {
  2666. return app('json')->fail("审核中");
  2667. }
  2668. if ($check == 1) {
  2669. return app('json')->fail("已是帮扶中心");
  2670. }
  2671. if ($check == 2) {
  2672. return app('json')->fail("审核被拒绝");
  2673. }
  2674. $bang_fu_number = systemConfig("bang_fu_number");
  2675. //检测用户是否满足条件
  2676. $number = $this->getNumber($uid, $bang_fu_number) - 1;//满足条件人数 减去自己
  2677. //条件
  2678. if ($number >= $bang_fu_number) {
  2679. // echo '满足';
  2680. Db::name('user_bangfu')->insert([
  2681. 'uid' => $uid,
  2682. 'time' => time(),
  2683. 'status' => 0
  2684. ]);
  2685. return app('json')->success("提交申请成功");
  2686. }
  2687. return app('json')->fail("不满足申请条件");
  2688. // echo '不满足';
  2689. }
  2690. //获得满足 1+5 的下级数量
  2691. public function getNumber($uid, $bang_fu_number): int
  2692. {
  2693. $number = 0;
  2694. $getUid = Db::name('user')->where('level_id', $uid)->field('uid')->select();
  2695. $count = count($getUid);
  2696. if ($count >= 5) {
  2697. $number = 1;
  2698. foreach ($getUid as $value) {
  2699. $number += $this->getNumber($value['uid'], $bang_fu_number);
  2700. if ($number >= $bang_fu_number) {
  2701. break;
  2702. }
  2703. }
  2704. }
  2705. return $number;
  2706. }
  2707. /**
  2708. * 积分明细
  2709. * @return mixed
  2710. */
  2711. public function score_info()
  2712. {
  2713. $uid = $this->request->uid();;
  2714. $data['score'] = decimal2(Db::name('user_sign_score')
  2715. ->where('uid', $uid)
  2716. ->where('status', 1)
  2717. ->where('pm', 1)
  2718. ->sum('reward_socre'));;
  2719. $data['no_clear_score'] = decimal2(Db::name('user_sign_score')
  2720. ->where('uid', $uid)
  2721. ->where('status', -1)
  2722. ->where('pm', 1)
  2723. ->sum('reward_socre'));
  2724. $data['lose_score'] = decimal2(Db::name('user_sign_score')
  2725. ->where('uid', $uid)
  2726. ->where('pm', 2)
  2727. ->sum('reward_socre'));
  2728. $data['clear_score'] = $score = decimal2($data['score'] - $data['lose_score']);
  2729. $data['score'] = $data['clear_score'] + $data['no_clear_score'] + $data['lose_score'];
  2730. $data['score'] = decimal2($data['score']);
  2731. Db::name('user')->where('uid', $uid)->update([
  2732. 'score' => $score
  2733. ]);
  2734. //clear_score 可用积分,score 积分总数 lose_score 已使用积分 no_clear_score 未结算积分
  2735. return app('json')->success($data);
  2736. }
  2737. /**
  2738. * 新版我的团队
  2739. */
  2740. public function get_team_list()
  2741. {
  2742. $data = [];
  2743. [$page, $limit] = $this->getPage();
  2744. $uid = $this->request->uid();
  2745. $type = intval($this->request->param('type'));
  2746. //查询团队列表
  2747. $userRepository = app()->make(UserRepository::class);
  2748. $chilid_userids = $userRepository->getSpreadUidBreak($uid);
  2749. $data['fans_count'] = count($chilid_userids);
  2750. $direct_uid_list = Db::name('user')->where('spread_uid', $uid)->where('is_del', 0)->column('uid');
  2751. $data['direct_count'] = count($direct_uid_list);
  2752. $valid_uid_list = Db::name('store_order')
  2753. ->whereIn('uid', $chilid_userids)
  2754. ->where('paid', 1)
  2755. ->group('uid')
  2756. ->column('uid');
  2757. $data['valid_count'] = count($valid_uid_list);
  2758. $data['count'] = Db::name('user')
  2759. ->whereIn('uid', $chilid_userids)
  2760. ->count();
  2761. $data['list'] = Db::name('user')
  2762. ->field('uid,phone,nickname,user_group,create_time,avatar as picture')
  2763. ->page($page, $limit)
  2764. ->whereIn('uid', $chilid_userids)
  2765. ->when($type == 1, function ($query) use ($direct_uid_list) {
  2766. return $query->whereIn('uid', $direct_uid_list);
  2767. })
  2768. ->when($type == 2, function ($query) use ($valid_uid_list) {
  2769. return $query->whereIn('uid', $valid_uid_list);
  2770. })
  2771. ->order('uid DESC')
  2772. ->select()
  2773. ->toArray();
  2774. foreach ($data['list'] as &$user) {
  2775. $user ['phone'] = substr_replace($user['phone'], '****', 3, 4);
  2776. }
  2777. return app('json')->success($data);
  2778. }
  2779. /**
  2780. * 我的粉丝详情
  2781. */
  2782. public function get_team_info()
  2783. {
  2784. $uid = $this->request->param('uid', '');
  2785. if (!$uid)
  2786. return app('json')->fail("uid不正确");
  2787. $userRepository = app()->make(UserRepository::class);
  2788. $chilid_userids = $userRepository->getSpreadUidBreak($this->request->uid());
  2789. if (!in_array($uid, $chilid_userids))
  2790. return app('json')->fail("该用户不在所属团队内");
  2791. $data = Db::name('user')
  2792. ->field('uid,phone,nickname,spread_uid,user_group,create_time,manage_address')
  2793. ->where('uid', $uid)
  2794. ->find();
  2795. $data['regimental_commander_count'] = Db::name('user')
  2796. ->where('spread_uid', $uid)
  2797. ->where('user_group', 2)
  2798. ->count();
  2799. $data['clear_order_amount'] = Db::name('store_order')
  2800. ->where('uid', $uid)
  2801. ->where('is_settlement', 1)
  2802. ->sum('pay_price');
  2803. $data['mybuy_order_amount'] = Db::name('store_order')
  2804. ->where('uid', $uid)
  2805. ->where('paid', 1)
  2806. ->sum('pay_price');
  2807. $spread_user = Db::name('user')
  2808. ->field('nickname as spread_nickname,phone as spread_phone')
  2809. ->where('uid', $data['spread_uid'])
  2810. ->find();
  2811. $spread_user ['spread_phone'] = substr_replace($spread_user['spread_phone'], '****', 3, 4);
  2812. $spread_user ['spread_nick_name'] = $spread_user['spread_nickname'] ?? '';
  2813. $data ['phone'] = substr_replace($data['phone'], '****', 3, 4);
  2814. $data = array_merge($data, $spread_user);
  2815. if (in_array($data['user_group'], [5, 6])) {
  2816. $data['area_name'] = Db::name('regions')->field('type,code_list')->where('id', 'in', $data['manage_address'])->cache('code:' . $data['manage_address'], 7200)->column('name');
  2817. $data['area_name'] = join($data['area_name']);
  2818. $data['area_bonus_money'] = Db::name('user_bill')
  2819. ->where('uid', $uid)
  2820. ->sum('number');
  2821. }
  2822. unset($data['manage_address']);
  2823. if (in_array($data['user_group'], [4])) {
  2824. $merchant = Db::name('merchant')->where('uid', $uid)->field('mer_id,mer_name')->find();
  2825. $data['mer_id'] = $merchant['mer_id'] ?? 0;
  2826. $data['mer_name'] = $merchant['mer_name'] ?? '';
  2827. }
  2828. return app('json')->success($data);
  2829. }
  2830. /**
  2831. * 我的佣金
  2832. */
  2833. public function get_brokerage_info()
  2834. {
  2835. $uid = $this->request->uid();
  2836. //佣金余额
  2837. $data['brokerage_price'] = Db::name('user')->where('uid', $uid)->value('brokerage_price');
  2838. //总收益
  2839. $data['sum_amount'] = Db::name('user_bill')
  2840. ->where('uid', $uid)
  2841. ->where('commission_type', '<>', 5)
  2842. ->where('pm', 1)
  2843. ->sum('number');
  2844. //未结算
  2845. $data['no_clear_amount'] = Db::name('user_bill')
  2846. ->where('uid', $uid)
  2847. ->where('commission_type', '<>', 5)
  2848. ->where('pm', 1)
  2849. ->where('status', 0)
  2850. ->sum('number');
  2851. //已提现
  2852. $data['withdraw_amount'] = Db::name('user_extract')
  2853. ->where('uid', $uid)
  2854. ->whereIn('status', [0, 1])
  2855. ->sum('extract_price');
  2856. //转VR
  2857. $data['transition_vr_amount'] = Db::name('user_transition_vr')
  2858. ->where('uid', $uid)
  2859. ->where('type', 1)
  2860. ->sum('number');
  2861. //最终 总收益是 = 佣金余额 + 已提现 + 已转VR
  2862. $data['sum_amount'] = $data['sum_amount'] + $data['transition_vr_amount'];
  2863. return app('json')->success($data);
  2864. }
  2865. public function get_token_by_phone(UserRepository $repository){
  2866. $user = $repository->accountByUser($this->request->param('phone'));
  2867. $tokenInfo = $repository->createToken($user);
  2868. return app('json')->success($repository->returnToken($user, $tokenInfo));
  2869. }
  2870. /**
  2871. * 转VR
  2872. */
  2873. public function transition_vr()
  2874. {
  2875. $uid = $this->request->uid();
  2876. $user = $this->request->userInfo();
  2877. $type = $this->request->param('type', 'brokerage');
  2878. $extract_amount = $this->request->param('extract_amount', 0);
  2879. if ($type == 'brokerage') {
  2880. $brokerage_price = Db::name('user')->where('uid', $uid)->value('brokerage_price');
  2881. $no_clear_amount = Db::name('user_bill')
  2882. ->where('uid', $uid)
  2883. ->where('commission_type', '<>', 5)
  2884. ->where('pm', 1)
  2885. ->where('status', 0)
  2886. ->sum('number');
  2887. $clear_amount = $brokerage_price - $no_clear_amount;
  2888. if ($user['brokerage_price'] < (systemConfig('withdrawal_money'))){
  2889. return app('json')->fail('未到达提现最低额度');
  2890. }
  2891. if($extract_amount > $clear_amount){
  2892. return app('json')->fail("可用金额不足提现");
  2893. }
  2894. $brokerage_price = bcsub($user['brokerage_price'], $extract_amount,2);
  2895. $user->brokerage_price = $brokerage_price;
  2896. $vr = bcadd($user['vr'], $extract_amount, 2);
  2897. $user->vr = $vr;
  2898. $res = $user->save();
  2899. if ($res){
  2900. //加入转VR记录
  2901. $insertdata = [
  2902. 'uid'=> $uid,
  2903. 'number' => $extract_amount,
  2904. 'surplus' => $vr,
  2905. 'mark' => '佣金转VR',
  2906. 'type' => 1,
  2907. 'create_time' => time(),
  2908. ];
  2909. Db::name('user_transition_vr')->insertGetId($insertdata);
  2910. //VR入账
  2911. $insertdata = [
  2912. 'uid'=> $uid,
  2913. 'number' => $extract_amount,
  2914. 'surplus' => $vr,
  2915. 'mark' => '佣金转VR',
  2916. 'order_id'=> 0,
  2917. 'type' => 1,
  2918. 'addtime' => time(),
  2919. 'settlement_time'=> date('Y-m-d H:i:s', time())
  2920. ];
  2921. Db::name('user_sign_vr')->insertGetId($insertdata);
  2922. return app('json')->success('转VR成功');
  2923. }else{
  2924. return app('json')->fail('转VR失败');
  2925. }
  2926. }
  2927. if ($type == 'hongbao') {
  2928. $hongbao = Db::name('user')->where('uid', $uid)->value('hongbao');
  2929. $no_clear_amount = Db::name('user_sign_hongbao')
  2930. ->where('uid', $uid)
  2931. ->where('type', 1)
  2932. ->where('status', -1)
  2933. ->sum('number');
  2934. $clear_amount = $hongbao - $no_clear_amount;
  2935. if ($user['hongbao'] < (systemConfig('withdrawal_money'))){
  2936. return app('json')->fail('未到达提现最低额度');
  2937. }
  2938. if($extract_amount > $clear_amount){
  2939. return app('json')->fail("可用金额不足提现");
  2940. }
  2941. $hongbao = bcsub($user['hongbao'], $extract_amount,2);
  2942. $user->hongbao = $hongbao;
  2943. $vr = bcadd($user['vr'], $extract_amount, 2);
  2944. $user->vr = $vr;
  2945. $res = $user->save();
  2946. if ($res){
  2947. //加入转VR记录
  2948. $insertdata = [
  2949. 'uid'=> $uid,
  2950. 'number' => $extract_amount,
  2951. 'surplus' => $vr,
  2952. 'mark' => '红包转VR',
  2953. 'type' => 2,
  2954. 'status' => -1,
  2955. 'addtime' => time(),
  2956. ];
  2957. Db::name('user_sign_hongbao')->insertGetId($insertdata);
  2958. //VR入账
  2959. $insertdata = [
  2960. 'uid'=> $uid,
  2961. 'number' => $extract_amount,
  2962. 'surplus' => $vr,
  2963. 'mark' => '红包转VR',
  2964. 'order_id'=> 0,
  2965. 'type' => 1,
  2966. 'addtime' => time(),
  2967. 'settlement_time'=> date('Y-m-d H:i:s', time())
  2968. ];
  2969. Db::name('user_sign_vr')->insertGetId($insertdata);
  2970. return app('json')->success('转VR成功');
  2971. }else{
  2972. return app('json')->fail('转VR失败');
  2973. }
  2974. }
  2975. return app('json')->fail('转VR失败');
  2976. }
  2977. /**
  2978. * 转VR记录
  2979. */
  2980. public function transition_vr_log()
  2981. {
  2982. $uid = $this->request->uid();
  2983. $type = $this->request->param('type', 1);
  2984. [$page, $limit] = $this->getPage();
  2985. $where = [];
  2986. $where[] = ['uid', '=', $uid];
  2987. $where[] = ['type', '=', $type];
  2988. $query = Db::name("user_transition_vr");
  2989. $count = $query->where($where)->count();
  2990. $list = $query->page($page, $limit)->where($where)->select()->each(function ($item){
  2991. $item['create_time'] = date("Y-m-d H:i:s", $item['create_time']);
  2992. return $item;
  2993. });
  2994. return app('json')->success('获取转VR记录成功', ['list'=>$list, 'count'=>$count]);
  2995. }
  2996. // 根据父级uid,递归获取所有子级UID数组
  2997. function getRecursiveChildren($parentUid) {
  2998. $result = []; // 用于存储所有子级的 uid
  2999. // 定义递归函数
  3000. $recursion = function ($parentUid) use (&$result, &$recursion) {
  3001. // 查询当前父级的所有直接子级
  3002. $children = Db::name("user")
  3003. ->where("spread_uid", $parentUid)
  3004. ->column("uid"); // 获取子级的 uid 列表
  3005. // 如果没有子级,直接返回
  3006. if (empty($children)) {
  3007. return;
  3008. }
  3009. // 遍历每个子级
  3010. foreach ($children as $childUid) {
  3011. $result[] = $childUid; // 将子级的 uid 添加到结果数组
  3012. $recursion($childUid); // 递归查询子级的子级
  3013. }
  3014. };
  3015. // 从初始父级开始递归查询
  3016. $recursion($parentUid);
  3017. return array_unique($result); // 返回结果数组,并去重
  3018. }
  3019. // 2.0 根据父级uid,找到当前用户下面的UID
  3020. function getChildren($parentUid) {
  3021. $result = []; // 用于存储所有子级的 uid
  3022. $children = Db::name("user")
  3023. ->where("spread_uid", $parentUid)
  3024. ->column("uid"); // 获取子级的 uid 列表
  3025. return $children; // 返回结果数组,并去重
  3026. }
  3027. public function getNewTeamPv($common_nums) {
  3028. // 初始化结果数组
  3029. $result = [
  3030. 'max_value' => null,
  3031. 'max_uid' => null,
  3032. 'remaining_values' => 0, // 剩余值的总和
  3033. 'remaining_uids' => [] // 剩余值对应的 UID
  3034. ];
  3035. // 递归获取所有子级 UID 的函数
  3036. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3037. $children = Db::name("user")
  3038. ->where("spread_uid", $parentUid)
  3039. ->column("uid");
  3040. $allChildren = [];
  3041. foreach ($children as $childUid) {
  3042. $allChildren[] = $childUid;
  3043. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3044. }
  3045. return $allChildren;
  3046. };
  3047. // 获取每个用户的总业绩,包括子级的业绩
  3048. $userTotalPv = [];
  3049. foreach ($common_nums as $uid) {
  3050. // 获取当前用户及其所有子级的 UID
  3051. $allUids = array_merge([$uid], $getRecursiveChildren($uid));
  3052. // 查询当前用户及其子级的所有订单
  3053. $orders = Db::name("store_order")
  3054. ->whereIn('status', [0, 1, 2, 3])
  3055. ->whereIn("uid", $allUids)
  3056. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3057. ->select();
  3058. // 计算总业绩
  3059. $totalPv = 0;
  3060. foreach ($orders as $order) {
  3061. if ($order['total_price'] == 1180) {
  3062. $totalPv += 700;
  3063. } else if ($order['total_price'] == 11800) {
  3064. $totalPv += 7000;
  3065. } else if ($order['total_price'] == 10620) {
  3066. $totalPv += 6300;
  3067. } else if ($order['total_price'] == 2360) {
  3068. $totalPv += 1400;
  3069. } else if ($order['total_price'] == 9440) {
  3070. $totalPv += 5600;
  3071. }
  3072. }
  3073. // 将当前用户的总业绩和 UID 存入数组
  3074. $userTotalPv[] = ['uid' => $uid, 'totalPv' => $totalPv];
  3075. }
  3076. // 如果没有符合条件的订单,直接返回空数组
  3077. if (empty($userTotalPv)) {
  3078. return [];
  3079. }
  3080. // 找到最大值及其对应的 UID
  3081. usort($userTotalPv, function($a, $b) {
  3082. return $b['totalPv'] <=> $a['totalPv']; // 按 totalPv 降序排序
  3083. });
  3084. // 获取最大值及其 UID
  3085. $result['max_value'] = $userTotalPv[0]['totalPv'];
  3086. $result['max_uid'] = $userTotalPv[0]['uid'];
  3087. // 计算剩余值的总和和对应的 UID
  3088. foreach ($userTotalPv as $index => $user) {
  3089. if ($index > 0) { // 跳过第一个(最大值)
  3090. $result['remaining_values'] += $user['totalPv'];
  3091. $result['remaining_uids'][] = $user['uid'];
  3092. }
  3093. }
  3094. return $result;
  3095. }
  3096. //只获取数组中的业绩
  3097. public function getteampv($common_nums) {
  3098. // 查询当前用户及其子级的所有订单
  3099. $orders = Db::name("store_order")
  3100. ->whereIn('status', [0, 1, 2, 3])
  3101. ->whereIn("uid", $common_nums)
  3102. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3103. ->select();
  3104. // 初始化业绩和人数
  3105. $totalPv = 0;
  3106. $totalUsers = count($common_nums); // 初始化人数为子级总数
  3107. // 遍历订单计算业绩
  3108. foreach ($orders as $order) {
  3109. if ($order['total_price'] == 1180) {
  3110. $totalPv += 700;
  3111. } else if ($order['total_price'] == 11800) {
  3112. $totalPv += 7000;
  3113. } else if ($order['total_price'] == 10620) {
  3114. $totalPv += 6300;
  3115. } else if ($order['total_price'] == 2360) {
  3116. $totalPv += 1400;
  3117. } else if ($order['total_price'] == 9440) {
  3118. $totalPv += 5600;
  3119. }
  3120. }
  3121. // 返回业绩和人数
  3122. return [
  3123. 'totalPv' => $totalPv,
  3124. 'totalUsers' => $totalUsers
  3125. ];
  3126. }
  3127. // 递归获取所有子级 UID 的业绩
  3128. public function getTeamPv11($parentUid) {
  3129. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3130. $children = Db::name("user")
  3131. ->where("spread_uid", $parentUid)
  3132. ->column("uid");
  3133. $allChildren = [];
  3134. foreach ($children as $childUid) {
  3135. $allChildren[] = $childUid;
  3136. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3137. }
  3138. return $allChildren;
  3139. };
  3140. // 获取当前用户及其所有子级的 UID
  3141. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  3142. // 查询当前用户及其子级的所有订单
  3143. $orders = Db::name("store_order")
  3144. ->whereIn('status', [0, 1, 2, 3])
  3145. ->whereIn("uid", $allUids)
  3146. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  3147. ->select();
  3148. // 计算总业绩
  3149. $totalPv = 0;
  3150. foreach ($orders as $order) {
  3151. switch ($order['total_price']) {
  3152. case 1180:
  3153. $totalPv += 700;
  3154. break;
  3155. case 11800:
  3156. $totalPv += 7000;
  3157. break;
  3158. case 10620:
  3159. $totalPv += 6300;
  3160. break;
  3161. case 2360:
  3162. $totalPv += 1400;
  3163. break;
  3164. case 9440:
  3165. $totalPv += 5600;
  3166. break;
  3167. }
  3168. }
  3169. return $totalPv;
  3170. }
  3171. //根据传递的父级数组,返回他的对应子级的个数
  3172. public function getTeamSize($parentUids) {
  3173. // 初始化结果数组
  3174. $result = [];
  3175. // 遍历每个父级ID
  3176. foreach ($parentUids as $parentUid) {
  3177. // 递归获取所有子级 UID
  3178. $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
  3179. $children = Db::name("user")
  3180. ->where("spread_uid", $parentUid)
  3181. ->column("uid");
  3182. // 确保返回的是数组
  3183. if (!is_array($children)) {
  3184. return [];
  3185. }
  3186. $allChildren = [];
  3187. foreach ($children as $childUid) {
  3188. $allChildren[] = $childUid;
  3189. $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
  3190. }
  3191. return $allChildren;
  3192. };
  3193. // 获取当前父级及其所有子级的 UID
  3194. $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
  3195. // 计算总个数(包括父级自身)
  3196. $totalUids = count($allUids);
  3197. // 将结果存入数组
  3198. $result[] = [
  3199. 'parent_uid' => $parentUid,
  3200. 'total_count' => $totalUids
  3201. ];
  3202. }
  3203. return $result;
  3204. }
  3205. public function processArray($array) {
  3206. // 初始化结果数组
  3207. $result = [
  3208. 'max_value' => null, // 最大值
  3209. 'max_index' => null, // 最大值的下标
  3210. 'remaining_sum' => 0 // 剩余值的总和
  3211. ];
  3212. // 检查数组是否为空
  3213. if (empty($array)) {
  3214. return $result;
  3215. }
  3216. // 找出最大值及其下标
  3217. $maxValue = $array[0];
  3218. $maxIndex = 0;
  3219. for ($i = 1; $i < count($array); $i++) {
  3220. if ($array[$i] > $maxValue) {
  3221. $maxValue = $array[$i];
  3222. $maxIndex = $i;
  3223. }
  3224. }
  3225. // 计算剩余值的总和
  3226. $remainingSum = 0;
  3227. for ($i = 0; $i < count($array); $i++) {
  3228. if ($i != $maxIndex) {
  3229. $remainingSum += $array[$i];
  3230. }
  3231. }
  3232. // 将结果存入数组
  3233. $result['max_value'] = $maxValue;
  3234. $result['max_index'] = $maxIndex;
  3235. $result['remaining_sum'] = $remainingSum;
  3236. return $result;
  3237. }
  3238. //获取当前uesr_id下面在2.0中是否还有直接下级,并计算她的大部门和小部门
  3239. public function getparents_child_pv($user_id){
  3240. // 获取直接下级的 UID 列表
  3241. $get_childs = Db::name("user")
  3242. ->where("spread_uid", $user_id)
  3243. ->column("uid");
  3244. // 初始化总业绩和总人数
  3245. $total_value = 0;
  3246. $total_count = 0;
  3247. $max_value = 0;
  3248. $max_count = 0;
  3249. // 遍历每个直接下级
  3250. foreach ($get_childs as $child) {
  3251. // 获取当前下级及其子级
  3252. $child_group = [$child];
  3253. $recursive_children = $this->getRecursiveChildren($child);
  3254. $child_group = array_merge($child_group, $recursive_children);
  3255. // 获取当前分组的业绩和人数
  3256. $result = $this->getteampv($child_group);
  3257. $group_pv = $result['totalPv'];
  3258. $group_count = $result['totalUsers'];
  3259. // 累加总业绩和总人数
  3260. $total_value += $group_pv;
  3261. $total_count += $group_count;
  3262. // 更新最大业绩及其对应的人数
  3263. if ($group_pv > $max_value) {
  3264. $max_value = $group_pv;
  3265. $max_count = $group_count;
  3266. }
  3267. }
  3268. // 计算小部门的业绩和人数
  3269. $small_department_value = $total_value - $max_value;
  3270. $small_department_count = $total_count - $max_count;
  3271. // 返回结果
  3272. return [
  3273. 'team_pv' => $max_value,
  3274. 'team_num' => $max_count,
  3275. 'per_pv' => $small_department_value,
  3276. 'per_num' => $small_department_count
  3277. ];
  3278. }
  3279. //根据父级IDS获取伞下的所有子级ID
  3280. function getRecursiveChildren_s($parentUid) {
  3281. $result = []; // 用于存储所有子级的 uid
  3282. // 定义递归函数
  3283. $recursion = function ($currentUid) use (&$result, &$recursion) {
  3284. // 查询当前父级的所有直接子级
  3285. $children = Db::name("user")
  3286. ->where("spread_uid", $currentUid)
  3287. ->column("uid"); // 获取子级的 uid 列表
  3288. // 如果没有子级,直接返回
  3289. if (empty($children)) {
  3290. return;
  3291. }
  3292. // 遍历每个子级
  3293. foreach ($children as $childUid) {
  3294. $result[] = $childUid; // 将子级的 uid 添加到结果数组
  3295. $recursion($childUid); // 递归查询子级的子级
  3296. }
  3297. };
  3298. // 从初始父级开始递归查询
  3299. $recursion($parentUid);
  3300. return array_unique($result); // 返回结果数组,并去重
  3301. }
  3302. /**
  3303. * 获取当前用户业绩
  3304. */
  3305. public function userupdates($user_id) {
  3306. $children = Db::name("user")
  3307. ->where("spread_uid", $user_id)
  3308. ->select(); // 获取子级的 uid 列表
  3309. $total_pv = 0;
  3310. foreach($children as $k=>$v){
  3311. //$children_pv = Db::name("store_order")->where("uid", $v['uid'])->whereIn("status",[0,1,2,3])->select();
  3312. $children_pv = Db::name("user_sign_gongxian")->where("uid", $v['uid'])->where("status",1)->select();
  3313. foreach($children_pv as $k1=>$v1){
  3314. $total_pv += $v1['number'];
  3315. }
  3316. }
  3317. //return $total_pv;
  3318. $userdatas = Db::name("user")->where("uid", $user_id)->find();
  3319. //var_dump($userdatas['user_group']);
  3320. //return;
  3321. //如果当前用户是普通消费者的情况下
  3322. if($userdatas['user_group'] == 1){
  3323. if($total_pv != 0){
  3324. if($total_pv >= 1180 && $total_pv < 11800){
  3325. Db::name("user")->where("uid", $user_id)->update(['user_group',2]);
  3326. }
  3327. }
  3328. }
  3329. //如果当前用户是业务员消费者的情况下
  3330. if($userdatas['user_group'] <= 2){
  3331. if($total_pv != 0){
  3332. if(11800 <= $total_pv){
  3333. Db::name("user")->where("uid", $user_id)->update(['user_group',3]);
  3334. }
  3335. }
  3336. }
  3337. }
  3338. /**
  3339. * 获取当前用户业绩
  3340. */
  3341. public function getPerformance22($user_id) {
  3342. $team_amount = 0;
  3343. $person_amount = 0;
  3344. //$user_id = 17;
  3345. $result_big_team_arr = [];
  3346. $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
  3347. //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  3348. $common_nums = $this->getCommonNums($user_id);
  3349. //var_dump($common_nums);
  3350. $get_teams_comm_num = 0;
  3351. $get_teams_comm_pv = 0;
  3352. $get_teams_per_num = 0;//小部门人数
  3353. //1.0系统中有下级,需要在2.0中再加下级数据
  3354. if($user_id < 611){
  3355. //梅红在2.0中的ID是780
  3356. //用户三峡所有在2.0系统下面的业绩和人数 start
  3357. $child_nums = [];
  3358. //获取当前用户
  3359. foreach($common_nums as $v){
  3360. $child_nums[] = $this->getRecursiveChildren($v);
  3361. }
  3362. //去除空数组,并重新组合有数据的数组
  3363. $filteredData = array_filter($child_nums, function($array) {
  3364. return !empty($array); // 如果数组不为空,则保留
  3365. });
  3366. // 合并所有非空数组
  3367. foreach ($filteredData as $array) {
  3368. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  3369. }
  3370. //var_dump($result_big_team_arr);
  3371. //获取当前用户下面在2.0中的下级所有PV
  3372. //$get_teams_comm_pv = $this->getteampv($result_big_team_arr);
  3373. $t_pv = $this->getteampv($result_big_team_arr);
  3374. $get_teams_comm_pv =$t_pv['totalPv'];
  3375. //var_dump($get_teams_comm_pv);
  3376. //获取当前用户下面在2.0中的下级所有人数
  3377. $get_teams_comm_num = count($result_big_team_arr);
  3378. //用户伞下小部门所有在2.0系统下面的业绩和人数 end
  3379. }else{
  3380. //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  3381. $child_nums = $this->getChildren($user_id);
  3382. //获取父级子级下面的个人
  3383. $num_teams = $this->getTeamSize($child_nums);
  3384. foreach($child_nums as $v){
  3385. $get_teams_comm_datas[] = $this->getTeamPv11($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  3386. }
  3387. //$s = $this->getparents_child_pv($user_id);
  3388. //var_dump($get_teams_comm_datas);
  3389. //如果只有一个部门,就是默认大部门
  3390. if( count($get_teams_comm_datas) ==1 ){
  3391. $get_teams_comm_pv =$get_teams_comm_datas[0];
  3392. $get_teams_comm_num = $num_teams[0]['total_count'];
  3393. }else if(count($get_teams_comm_datas) >1){
  3394. // var_dump( $get_teams_comm_datas);
  3395. //获取一个最大值,设为大部门,其他的加载一块是小部门
  3396. $getss = $this->processArray($get_teams_comm_datas);
  3397. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  3398. unset($num_teams[$getss['max_index']]);
  3399. //获取小部门的人数
  3400. $per_num = 0;
  3401. foreach($num_teams as $k=>$v){
  3402. $per_num +=$v['total_count'];
  3403. }
  3404. //找到最大值的(大部门)
  3405. $get_teams_comm_num = $max_value_count;
  3406. //小部门的数量
  3407. $get_teams_per_num = $per_num;
  3408. //var_dump($getss['max_value']);
  3409. $person_amount = $getss['remaining_sum'];
  3410. $get_teams_comm_pv = $getss['max_value'];
  3411. }
  3412. }
  3413. //合并业绩和人数
  3414. $team_amount += $get_teams_comm_pv;
  3415. //var_dump($team_amount);
  3416. //1.0获取小区业绩
  3417. $person_nums = $this->getPersonageNums($user_id);
  3418. // var_dump($person_nums);
  3419. $result_small_team_arr = [];
  3420. //1.0系统中有下级,需要在2.0中再加下级数据
  3421. //用户三峡所有在2.0系统下面的业绩和人数 start
  3422. $child_nums_mix = [];
  3423. //获取当前用户
  3424. foreach($person_nums as $v){
  3425. $child_nums_mix[] = $this->getRecursiveChildren($v);
  3426. }
  3427. //去除空数组,并重新组合有数据的数组
  3428. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  3429. return !empty($array); // 如果数组不为空,则保留
  3430. });
  3431. // 合并所有非空数组
  3432. $result_small_team_arr = [];
  3433. foreach ($filteredData_1 as $array) {
  3434. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  3435. }
  3436. //var_dump($result_small_team_arr);
  3437. //获取当前用户下面在2.0中的下级所有PV
  3438. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  3439. $t_pv = $this->getteampv($result_small_team_arr);
  3440. $get_teams_per_pv =$t_pv['totalPv'];
  3441. //var_dump( $get_teams_per_pv);
  3442. //获取当前用户下面在2.0中的下级所有人数
  3443. $get_teams_per_num += count($result_small_team_arr);
  3444. //合并业绩和人数
  3445. $person_amount += $get_teams_per_pv;
  3446. // if($user_id == 593){
  3447. // $person_amount = 2800;
  3448. // }
  3449. //var_dump($person_amount);
  3450. //用户小部门所有在2.0系统下面的业绩和人数 end
  3451. // $common_nums[] = $user_id;
  3452. foreach ($common_nums as $key => $value) {
  3453. # code...
  3454. $amount = $this->getPerformance1($value);
  3455. $team_amount += $amount;
  3456. }
  3457. foreach ($person_nums as $key => $value) {
  3458. # code...
  3459. $amount = $this->getPerformance1($value);
  3460. $person_amount += $amount;
  3461. }
  3462. //var_dump($team_amount);
  3463. //
  3464. if($user_id < 611){
  3465. //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  3466. //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  3467. $b_s = $this->getparents_child_pv($user_id);
  3468. //var_dump( $b_s);echo "yyyyyyyyyyyyy";
  3469. $team_amount += $b_s['team_pv'];
  3470. $get_teams_comm_num += $b_s['team_num'];
  3471. $person_amount += $b_s['per_pv'];
  3472. $get_teams_per_num += $b_s['per_num'];//小部门人数
  3473. //var_dump( $b_s['team_num'],$b_s['per_num']);
  3474. }
  3475. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  3476. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  3477. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  3478. $money1180Sum = 0;
  3479. foreach ($user_team_amount as $record) {
  3480. $money1180Sum += $record['money'] - 300 - 180;
  3481. }
  3482. // 获取 status 为 1 且 money 为 11800 的记录集合
  3483. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  3484. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3485. $money11800Sum = 0;
  3486. foreach ($money11800Records as $record) {
  3487. $money11800Sum += $record['money'] - 3000 - 1800;
  3488. }
  3489. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  3490. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3491. $money10620Sum = 0;
  3492. foreach ($money10620Records as $record) {
  3493. $money10620Sum += $record['money'] - 2700 - 1620;
  3494. }
  3495. // 计算除去特定值后的总和
  3496. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  3497. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3498. $otherMoneySum = 0;
  3499. foreach ($otherMoneyRecords as $record) {
  3500. $otherMoneySum += $record['money'];
  3501. }
  3502. // 分别处理特定值的情况并加上其他值的总和
  3503. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  3504. // var_dump($all_record_nums);
  3505. $team_amount += $all_record_nums;
  3506. // var_dump($user_team_amount);
  3507. //计算自己的个人联盟总流水
  3508. // // //计算自己的个人联盟总流水
  3509. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  3510. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  3511. // $person_amount += $user_person_amount;
  3512. //计算个人的1180单价的业绩 集合
  3513. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  3514. $money1180Sum = 0;
  3515. foreach ($money1180Records as $record) {
  3516. $money1180Sum += $record['money'] - 300 - 180;
  3517. }
  3518. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  3519. //var_dump($person_nums);
  3520. //计算个人的11800单价的业绩 集合
  3521. $money11800Sum = 0;
  3522. foreach ($money11800Records as $record) {
  3523. $money11800Sum += $record['money'] - 3000 - 1800;
  3524. }
  3525. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  3526. //var_dump($person_nums);
  3527. //计算个人的10620单价的业绩 集合
  3528. $money10620Sum = 0;
  3529. foreach ($money10620Records as $record) {
  3530. $money10620Sum += $record['money'] - 2700 - 1620;
  3531. }
  3532. // 计算除去特定值后的总和
  3533. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3534. $otherMoneySum = 0;
  3535. foreach ($otherMoneyRecords as $record) {
  3536. $otherMoneySum += $record['money'];
  3537. }
  3538. // 分别处理特定值的情况并加上其他值的总和
  3539. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  3540. $person_amount += $user_person_amount;
  3541. //级别信息
  3542. $userInfo = Db::name("user")->find($user_id);//
  3543. $zk_level = 4;
  3544. $is_zk = false;
  3545. if($userInfo['user_level_id_old'] == $zk_level) {
  3546. $is_zk = true;
  3547. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  3548. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  3549. } else{
  3550. $sales_incentive = 0;
  3551. }
  3552. $return_data = [
  3553. 'common_nums'=>count($common_nums) + $get_teams_comm_num,
  3554. 'person_nums'=>count($person_nums) + $get_teams_per_num,
  3555. 'common_nums_pv'=> $team_amount,
  3556. 'person_nums_pv'=> $person_amount,
  3557. 'sum_nums_pv' =>$team_amount + $person_amount,
  3558. 'sales_incentive' => $sales_incentive,
  3559. "is_zk"=>$is_zk
  3560. ];
  3561. return $return_data;
  3562. }
  3563. /**
  3564. * 获取当前用户业绩
  3565. */
  3566. public function getPerformance($user_id) {
  3567. $team_amount = 0;
  3568. $person_amount = 0;
  3569. $result_big_team_arr = [];
  3570. $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
  3571. //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  3572. $common_nums = $this->getCommonNums($user_id);
  3573. //var_dump($user_id);
  3574. $get_teams_comm_num = 0;
  3575. $get_teams_comm_pv = 0;
  3576. $get_teams_per_num = 0;//小部门人数
  3577. //1.0系统中有下级,需要在2.0中再加下级数据
  3578. if($user_id < 611){
  3579. //梅红在2.0中的ID是780
  3580. // if($user_id == 593){
  3581. // $common_nums[] = 780;
  3582. // unset($common_nums[0]);
  3583. // }
  3584. //var_dump($common_nums);
  3585. //用户三峡所有在2.0系统下面的业绩和人数 start
  3586. $child_nums = [];
  3587. //再加上当前用户直属的子级
  3588. $common_ns = $common_nums;
  3589. $common_ns[] = $user_id;
  3590. //var_dump($common_ns);return;
  3591. //获取当前用户
  3592. foreach($common_nums as $v){
  3593. $child_nums[] = $this->getRecursiveChildren($v);
  3594. }
  3595. //梅红在2.0中的ID是780
  3596. // if($user_id == 593){
  3597. // $child_nums[0][] = 780;
  3598. // }
  3599. //去除空数组,并重新组合有数据的数组
  3600. $filteredData = array_filter($child_nums, function($array) {
  3601. return !empty($array); // 如果数组不为空,则保留
  3602. });
  3603. // 合并所有非空数组
  3604. foreach ($filteredData as $array) {
  3605. $result_big_team_arr = array_merge($result_big_team_arr, $array);
  3606. }
  3607. //var_dump($result_big_team_arr);echo "ppppppppppppppppp";
  3608. //获取当前用户下面在2.0中的下级所有PV
  3609. $t_pv = $this->getteampv($result_big_team_arr);
  3610. $get_teams_comm_pv =$t_pv['totalPv'];
  3611. // if($user_id == 593){
  3612. // $get_teams_comm_pv = 7000;
  3613. // }
  3614. //var_dump($get_teams_comm_pv);
  3615. //获取当前用户下面在2.0中的下级所有人数
  3616. $get_teams_comm_num = count($result_big_team_arr);
  3617. //用户伞下小部门所有在2.0系统下面的业绩和人数 end
  3618. }else{
  3619. //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
  3620. $child_nums = $this->getChildren($user_id);
  3621. //获取父级子级下面的个人
  3622. $num_teams = $this->getTeamSize($child_nums);
  3623. foreach($child_nums as $v){
  3624. $get_teams_comm_datas[] = $this->getTeamPv11($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
  3625. }
  3626. if( count($get_teams_comm_datas) ==1 ){
  3627. $get_teams_comm_pv =$get_teams_comm_datas[0];
  3628. $get_teams_comm_num = $num_teams[0]['total_count'];
  3629. }else if(count($get_teams_comm_datas) >1){
  3630. // $getss = $this->processArray($get_teams_comm_datas);
  3631. // $team_datas = $num_teams[$getss['max_index']];
  3632. // var_dump( $get_teams_comm_datas);
  3633. //获取一个最大值,设为大部门,其他的加载一块是小部门
  3634. $getss = $this->processArray($get_teams_comm_datas);
  3635. $max_value_count = $num_teams[$getss['max_index']]['total_count'];
  3636. unset($num_teams[$getss['max_index']]);
  3637. //获取小部门的人数
  3638. $per_num = 0;
  3639. foreach($num_teams as $k=>$v){
  3640. $per_num +=$v['total_count'];
  3641. }
  3642. //找到最大值的(大部门)
  3643. $get_teams_comm_num = $max_value_count;
  3644. //小部门的数量
  3645. $get_teams_per_num = $per_num;
  3646. //var_dump($getss['max_value']);
  3647. $person_amount = $getss['remaining_sum'];
  3648. $get_teams_comm_pv = $getss['max_value'];
  3649. }
  3650. }
  3651. //合并业绩和人数
  3652. $team_amount += $get_teams_comm_pv;
  3653. //var_dump($team_amount);
  3654. //1.0获取小区业绩
  3655. $person_nums = $this->getPersonageNums($user_id);
  3656. //var_dump($person_nums);
  3657. $result_small_team_arr = [];
  3658. //1.0系统中有下级,需要在2.0中再加下级数据
  3659. //用户三峡所有在2.0系统下面的业绩和人数 start
  3660. $child_nums_mix = [];
  3661. //再加上当前用户直属的子级
  3662. $common_ns1 = $person_nums;
  3663. $common_ns1[] = $user_id;
  3664. //获取当前用户
  3665. foreach($person_nums as $v){
  3666. $child_nums_mix[] = $this->getRecursiveChildren($v);
  3667. }
  3668. //去除空数组,并重新组合有数据的数组
  3669. $filteredData_1 = array_filter($child_nums_mix, function($array) {
  3670. return !empty($array); // 如果数组不为空,则保留
  3671. });
  3672. // 合并所有非空数组
  3673. $result_small_team_arr = [];
  3674. foreach ($filteredData_1 as $array) {
  3675. $result_small_team_arr = array_merge($result_small_team_arr, $array);
  3676. }
  3677. //获取当前用户下面在2.0中的下级所有PV
  3678. // $get_teams_per_pv = $this->getteampv($result_small_team_arr);
  3679. $t_pv = $this->getteampv($result_small_team_arr);
  3680. $get_teams_per_pv =$t_pv['totalPv'];
  3681. //获取当前用户下面在2.0中的下级所有人数
  3682. $get_teams_per_num += count($result_small_team_arr);
  3683. //合并业绩和人数
  3684. $person_amount += $get_teams_per_pv;
  3685. // if($user_id == 593){
  3686. // $person_amount = 2800;
  3687. // }
  3688. //var_dump($person_amount);
  3689. //用户小部门所有在2.0系统下面的业绩和人数 end
  3690. // $common_nums[] = $user_id;
  3691. foreach ($common_nums as $key => $value) {
  3692. # code...
  3693. $amount = $this->getPerformance1($value);
  3694. $team_amount += $amount;
  3695. }
  3696. foreach ($person_nums as $key => $value) {
  3697. # code...
  3698. $amount = $this->getPerformance1($value);
  3699. $person_amount += $amount;
  3700. }
  3701. //var_dump($team_amount);
  3702. if($user_id < 611){
  3703. //获取当前用户直属下级(查询在2.0中直接推荐人和伞下的业绩。并比对大小部门)
  3704. //例子:17所有下面uid是speard_uid都是17的,和所有伞下的业绩。分出大小部门,加到1.0的大小部门中
  3705. $b_s = $this->getparents_child_pv($user_id);
  3706. //var_dump( $b_s);echo "yyyyyyyyyyyyy";
  3707. $team_amount += $b_s['team_pv'];
  3708. $get_teams_comm_num += $b_s['team_num'];
  3709. $person_amount += $b_s['per_pv'];
  3710. $get_teams_per_num += $b_s['per_num'];//小部门人数
  3711. //var_dump($team_amount,$person_amount );
  3712. }
  3713. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  3714. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  3715. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  3716. $money1180Sum = 0;
  3717. foreach ($user_team_amount as $record) {
  3718. $money1180Sum += $record['money'] - 300 - 180;
  3719. }
  3720. if($user_id == 593){
  3721. $money1180Sum -= 700;
  3722. }
  3723. // 获取 status 为 1 且 money 为 11800 的记录集合
  3724. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  3725. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3726. $money11800Sum = 0;
  3727. foreach ($money11800Records as $record) {
  3728. $money11800Sum += $record['money'] - 3000 - 1800;
  3729. }
  3730. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  3731. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3732. $money10620Sum = 0;
  3733. foreach ($money10620Records as $record) {
  3734. $money10620Sum += $record['money'] - 2700 - 1620;
  3735. }
  3736. // 计算除去特定值后的总和
  3737. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  3738. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3739. $otherMoneySum = 0;
  3740. foreach ($otherMoneyRecords as $record) {
  3741. $otherMoneySum += $record['money'];
  3742. }
  3743. // 分别处理特定值的情况并加上其他值的总和
  3744. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  3745. // var_dump($all_record_nums);
  3746. $team_amount += $all_record_nums;
  3747. // var_dump($user_team_amount);
  3748. //计算自己的个人联盟总流水
  3749. // // //计算自己的个人联盟总流水
  3750. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  3751. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  3752. // $person_amount += $user_person_amount;
  3753. //计算个人的1180单价的业绩 集合
  3754. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  3755. $money1180Sum = 0;
  3756. foreach ($money1180Records as $record) {
  3757. $money1180Sum += $record['money'] - 300 - 180;
  3758. }
  3759. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  3760. //var_dump($person_nums);
  3761. //计算个人的11800单价的业绩 集合
  3762. $money11800Sum = 0;
  3763. foreach ($money11800Records as $record) {
  3764. $money11800Sum += $record['money'] - 3000 - 1800;
  3765. }
  3766. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  3767. //var_dump($person_nums);
  3768. //计算个人的10620单价的业绩 集合
  3769. $money10620Sum = 0;
  3770. foreach ($money10620Records as $record) {
  3771. $money10620Sum += $record['money'] - 2700 - 1620;
  3772. }
  3773. // 计算除去特定值后的总和
  3774. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3775. $otherMoneySum = 0;
  3776. foreach ($otherMoneyRecords as $record) {
  3777. $otherMoneySum += $record['money'];
  3778. }
  3779. // 分别处理特定值的情况并加上其他值的总和
  3780. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  3781. $person_amount += $user_person_amount;
  3782. //级别信息
  3783. $userInfo = Db::name("user")->find($user_id);//
  3784. $zk_level = 4;
  3785. $is_zk = false;
  3786. if($userInfo['user_level_id_old'] == $zk_level) {
  3787. $is_zk = true;
  3788. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  3789. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  3790. } else{
  3791. $sales_incentive = 0;
  3792. }
  3793. $return_data = [
  3794. 'common_nums'=>count($common_nums) + $get_teams_comm_num,
  3795. 'person_nums'=>count($person_nums) + $get_teams_per_num,
  3796. 'common_nums_pv'=> $team_amount,
  3797. 'person_nums_pv'=> $person_amount,
  3798. 'sum_nums_pv' =>$team_amount + $person_amount,
  3799. 'sales_incentive' => $sales_incentive,
  3800. "is_zk"=>$is_zk
  3801. ];
  3802. return $return_data;
  3803. }
  3804. /**
  3805. * 获取当前用户业绩
  3806. */
  3807. public function getPerformance_copy($user_id) {
  3808. // $user_id = $this->request->post("user_id");
  3809. //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  3810. $common_nums = $this->getCommonNums($user_id);
  3811. //1.0获取小区业绩
  3812. $person_nums = $this->getPersonageNums($user_id);
  3813. //return $person_nums;
  3814. // var_dump( $common_nums);
  3815. $team_amount = 0;
  3816. $person_amount = 0;
  3817. // $common_nums[] = $user_id;
  3818. foreach ($common_nums as $key => $value) {
  3819. # code...
  3820. $amount = $this->getPerformance1($value);
  3821. $team_amount += $amount;
  3822. }
  3823. foreach ($person_nums as $key => $value) {
  3824. # code...
  3825. $amount = $this->getPerformance1($value);
  3826. $person_amount += $amount;
  3827. }
  3828. //var_dump($team_amount);
  3829. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  3830. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  3831. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  3832. $money1180Sum = 0;
  3833. foreach ($user_team_amount as $record) {
  3834. $money1180Sum += $record['money'] - 300 - 180;
  3835. }
  3836. // 获取 status 为 1 且 money 为 11800 的记录集合
  3837. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  3838. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3839. $money11800Sum = 0;
  3840. foreach ($money11800Records as $record) {
  3841. $money11800Sum += $record['money'] - 3000 - 1800;
  3842. }
  3843. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  3844. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  3845. $money10620Sum = 0;
  3846. foreach ($money10620Records as $record) {
  3847. $money10620Sum += $record['money'] - 2700 - 1620;
  3848. }
  3849. // 计算除去特定值后的总和
  3850. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  3851. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3852. $otherMoneySum = 0;
  3853. foreach ($otherMoneyRecords as $record) {
  3854. $otherMoneySum += $record['money'];
  3855. }
  3856. // 分别处理特定值的情况并加上其他值的总和
  3857. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  3858. // var_dump($all_record_nums);
  3859. $team_amount += $all_record_nums;
  3860. //计算自己的个人联盟总流水
  3861. // // //计算自己的个人联盟总流水
  3862. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  3863. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  3864. // $person_amount += $user_person_amount;
  3865. //计算个人的1180单价的业绩 集合
  3866. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  3867. $money1180Sum = 0;
  3868. foreach ($money1180Records as $record) {
  3869. $money1180Sum += $record['money'] - 300 - 180;
  3870. }
  3871. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  3872. //var_dump($person_nums);
  3873. //计算个人的11800单价的业绩 集合
  3874. $money11800Sum = 0;
  3875. foreach ($money11800Records as $record) {
  3876. $money11800Sum += $record['money'] - 3000 - 1800;
  3877. }
  3878. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  3879. //var_dump($person_nums);
  3880. //计算个人的10620单价的业绩 集合
  3881. $money10620Sum = 0;
  3882. foreach ($money10620Records as $record) {
  3883. $money10620Sum += $record['money'] - 2700 - 1620;
  3884. }
  3885. // 计算除去特定值后的总和
  3886. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  3887. $otherMoneySum = 0;
  3888. foreach ($otherMoneyRecords as $record) {
  3889. $otherMoneySum += $record['money'];
  3890. }
  3891. // 分别处理特定值的情况并加上其他值的总和
  3892. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  3893. $person_amount += $user_person_amount;
  3894. //级别信息
  3895. $userInfo = Db::name("user")->find($user_id);//
  3896. $zk_level = 4;
  3897. $is_zk = false;
  3898. if($userInfo['user_level_id_old'] == $zk_level) {
  3899. $is_zk = true;
  3900. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  3901. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  3902. } else{
  3903. $sales_incentive = 0;
  3904. }
  3905. $return_data = [
  3906. 'common_nums'=>count($common_nums),
  3907. 'person_nums'=>count($person_nums),
  3908. 'common_nums_pv'=> $team_amount,
  3909. 'person_nums_pv'=> $person_amount,
  3910. 'sum_nums_pv' =>$team_amount + $person_amount,
  3911. 'sales_incentive' => $sales_incentive,
  3912. "is_zk"=>$is_zk
  3913. ];
  3914. return $return_data;
  3915. }
  3916. /**
  3917. * 获取指定用户业绩
  3918. */
  3919. public function getPerformanceOf($user_id) {
  3920. //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  3921. $common_nums = $this->getCommonNums($user_id);
  3922. $person_nums = $this->getPersonageNums($user_id);
  3923. $team_amount = 0;
  3924. $person_amount = 0;
  3925. // $common_nums[] = $user_id;
  3926. foreach ($common_nums as $key => $value) {
  3927. # code...
  3928. $amount = $this->getPerformance1($value);
  3929. $team_amount += $amount;
  3930. }
  3931. foreach ($person_nums as $key => $value) {
  3932. # code...
  3933. $amount = $this->getPerformance1($value);
  3934. $person_amount += $amount;
  3935. }
  3936. // return $person_nums;
  3937. //添加自己共建联盟的流水
  3938. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("spread_id",$user_id)->sum("money");
  3939. $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  3940. $team_amount += $user_team_amount;
  3941. // //计算自己的个人联盟总流水
  3942. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("spread_id",$user_id)->sum("money");
  3943. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  3944. $person_amount += $user_person_amount;
  3945. $sum_nums_pv = $team_amount + $person_amount;
  3946. $sum_nums_pv = isset($sum_nums_pv) ? $sum_nums_pv :0;
  3947. return $sum_nums_pv;
  3948. }
  3949. /**
  3950. * 获取用户星级
  3951. */
  3952. public function getStarLevel($user_id,$team_money=0,$person_money=0) {
  3953. if(empty($team_money)) {
  3954. $common_nums = $this->getCommonNums($user_id);
  3955. $team_money = 0;
  3956. foreach ($common_nums as $key => $value) {
  3957. # code...
  3958. $amount = $this->getPerformance1($value);
  3959. $team_money += $amount;
  3960. }
  3961. //计算自己的共建联盟流水
  3962. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->sum("money");
  3963. $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  3964. $team_money += $user_team_amount;
  3965. }else{
  3966. $common_nums = $this->getCommonNums($user_id);
  3967. }
  3968. if(empty($person_money)) {
  3969. $person_nums = $this->getPersonageNums($user_id);
  3970. $person_amount = 0;
  3971. foreach ($person_nums as $key => $value) {
  3972. # code...
  3973. $amount = $this->getPerformance1($value);
  3974. $person_amount += $amount;
  3975. }
  3976. $person_money = $person_amount;
  3977. //计算自己的个人联盟总流水
  3978. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->sum("money");
  3979. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  3980. $person_money += $user_person_amount;
  3981. }else{
  3982. $person_nums = $this->getPersonageNums($user_id);
  3983. }
  3984. $slow = $person_money;
  3985. if($team_money < $person_money) {
  3986. $slow = $team_money;
  3987. }
  3988. $sum_money = $team_money + $person_money;
  3989. // $data = ['sum_money'=>$sum_money,"team_money"=>$team_money,"person_money"=>$person_money];
  3990. // $this->error(0,$data);
  3991. $star_list = Db::name("old_user_star")->order("statement_all_num desc")->select();
  3992. $start_level = "";
  3993. foreach ($star_list as $key => $value) {
  3994. # code...
  3995. if( $sum_money>=$value['statement_all_num'] && $slow >= $value['person_statement']) {
  3996. return $value;
  3997. }
  3998. }
  3999. return $start_level;
  4000. }
  4001. /**
  4002. * 获取流水信息
  4003. */
  4004. public function getPerformance1($user_id) {
  4005. // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
  4006. // $amount = isset($amount) ? round($amount*0.7,2) : 0;
  4007. // return $amount;
  4008. $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
  4009. $money1180Sum = 0;
  4010. foreach ($money1180Records as $record) {
  4011. $money1180Sum += $record['money'] - 300 - 180;
  4012. }
  4013. // var_dump($money1180Sum);
  4014. $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
  4015. //var_dump($person_nums);
  4016. //计算个人的11800单价的业绩 集合
  4017. $money11800Sum = 0;
  4018. foreach ($money11800Records as $record) {
  4019. $money11800Sum += $record['money'] - 3000 - 1800;
  4020. }
  4021. $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
  4022. //var_dump($person_nums);
  4023. //计算个人的11800单价的业绩 集合
  4024. $money10620Sum = 0;
  4025. foreach ($money10620Records as $record) {
  4026. $money10620Sum += $record['money'] - 2700 - 1620;
  4027. }
  4028. // 计算除去特定值后的总和
  4029. $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
  4030. $otherMoneySum = 0;
  4031. foreach ($otherMoneyRecords as $record) {
  4032. $otherMoneySum += $record['money'];
  4033. }
  4034. // 分别处理特定值的情况并加上其他值的总和
  4035. $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4036. return $user_person_amount;
  4037. }
  4038. /**
  4039. * 获取个人业绩统计信息
  4040. */
  4041. public function getPerformanceOfId($user_id)
  4042. {
  4043. //var_dump($user_id);
  4044. //联盟总人数 共建联盟人数 个人联盟人数 总流水 共建联盟流水 个人联盟流水 所属星级(钻卡专属)
  4045. $common_nums = $this->getCommonNums($user_id);
  4046. $person_nums = $this->getPersonageNums($user_id);
  4047. //联盟业绩 查询 共建联盟业绩 个人联盟业绩
  4048. $team_amount = 0;
  4049. $person_amount = 0;
  4050. // $common_nums[] = $user_id;
  4051. foreach ($common_nums as $key => $value) {
  4052. # code...
  4053. $amount = $this->getPerformance1($value);
  4054. $team_amount += $amount;
  4055. }
  4056. //计算自己的共建联盟流水
  4057. //$user_team_amount = Db::name("user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
  4058. // $this->error(0,$team_amount);
  4059. //$user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  4060. $money1180Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 1180)->select();
  4061. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  4062. $money1180Sum = 0;
  4063. foreach ($money1180Records as $record) {
  4064. $money1180Sum += $record['money'] - 300 - 180;
  4065. }
  4066. // 获取 status 为 1 且 money 为 11800 的记录集合
  4067. $money11800Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 11800)->select();
  4068. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4069. $money11800Sum = 0;
  4070. foreach ($money11800Records as $record) {
  4071. $money11800Sum += $record['money'] - 3000 - 1800;
  4072. }
  4073. // 获取 status 为 1 且 money 为 11800 的记录集合
  4074. $money10620Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 10620)->select();
  4075. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  4076. $money10620Sum = 0;
  4077. foreach ($money10620Records as $record) {
  4078. $money10620Sum += $record['money'] - 2700 - 1620;
  4079. }
  4080. // 计算除去特定值后的总和
  4081. $otherMoneyRecords = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->whereNotIn('money', [1180, 11800,10620])->select();
  4082. $otherMoneySum = 0;
  4083. foreach ($otherMoneyRecords as $record) {
  4084. $otherMoneySum += $record['money'];
  4085. }
  4086. // 分别处理特定值的情况并加上其他值的总和
  4087. $user_team_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  4088. $team_amount += $user_team_amount;
  4089. foreach ($person_nums as $key => $value) {
  4090. # code...
  4091. $amount = $this->getPerformance1($value);
  4092. $person_amount += $amount;
  4093. }
  4094. // //计算自己的个人联盟总流水
  4095. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
  4096. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  4097. $person_amount += $user_person_amount;
  4098. // $this->error(0,$common_nums);
  4099. return $team_amount + $person_amount;
  4100. }
  4101. /**
  4102. * 获取该用户共建联盟
  4103. */
  4104. public function getCommonNums($user_id){
  4105. //先获取共建联盟下用户的id
  4106. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
  4107. $new_array_ids =[];
  4108. foreach ($son_ids as $key => $value) {
  4109. # code...
  4110. $son_id = $value['id'];
  4111. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  4112. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  4113. if(count($son_value_ids) > 0) {
  4114. $son_value_ids = array_column($son_value_ids,"id");
  4115. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  4116. }
  4117. }
  4118. return $new_array_ids;
  4119. }
  4120. /**
  4121. * 获取该用户个人联盟
  4122. */
  4123. public function getPersonageNums($user_id){
  4124. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
  4125. $new_array_ids =[];
  4126. // return 3343;
  4127. foreach ($son_ids as $key => $value) {
  4128. # code...
  4129. $son_id = $value['id'];
  4130. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  4131. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  4132. if(count($son_value_ids) > 0) {
  4133. $son_value_ids = array_column($son_value_ids,"id");
  4134. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  4135. }
  4136. }
  4137. return $new_array_ids;
  4138. }
  4139. //获取团队递归聚宝盆1
  4140. public function teamPeople( $user_id,$type){
  4141. //var_dump($type);
  4142. //$ftype = 1:大部门,0:小部门
  4143. //业绩小是小部门,业绩大是大部门
  4144. if($type == 1) {
  4145. $list = Db::name("old_user_jbp")
  4146. ->where("spread", $user_id)
  4147. ->where("is_team", 1)
  4148. ->field("user_name, id")
  4149. ->select()
  4150. ->toArray();
  4151. $list = $this->get_yj_amount($list,1);
  4152. $list1 = Db::name("old_user_jbp")
  4153. ->where("spread", $user_id)
  4154. ->where("is_team", 0)
  4155. ->field("user_name, id")
  4156. ->select()
  4157. ->toArray();
  4158. $list1 = $this->get_yj_amount($list1, 0);
  4159. // 检查数组和字段是否存在
  4160. if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
  4161. // 如果$list的值小于或等于$list1的值,选择$list
  4162. if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
  4163. return $list1;
  4164. } else {
  4165. return $list;
  4166. }
  4167. } elseif (isset($list[0]['performance']['common_nums_pv'])) {
  4168. // 如果只有$list有值,返回$list
  4169. return $list;
  4170. } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
  4171. // 如果只有$list1有值,返回$list1
  4172. return $list1;
  4173. } else {
  4174. // 如果两个数组都没有该字段,返回空数组
  4175. return [];
  4176. }
  4177. }else if($type == 0) {
  4178. $list = Db::name("old_user_jbp")
  4179. ->where("spread", $user_id)
  4180. ->where("is_team", 1)
  4181. ->field("user_name, id")
  4182. ->select()
  4183. ->toArray();
  4184. $list = $this->get_yj_amount($list,1);
  4185. $list1 = Db::name("old_user_jbp")
  4186. ->where("spread", $user_id)
  4187. ->where("is_team", 0)
  4188. ->field("user_name, id")
  4189. ->select()
  4190. ->toArray();
  4191. $list1 = $this->get_yj_amount($list1, 0);
  4192. // 检查数组和字段是否存在
  4193. if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
  4194. // 如果$list的值小于或等于$list1的值,选择$list
  4195. if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
  4196. return $list;
  4197. } else {
  4198. return $list1;
  4199. }
  4200. } elseif (isset($list[0]['performance']['common_nums_pv'])) {
  4201. // 如果只有$list有值,返回$list
  4202. return $list;
  4203. } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
  4204. // 如果只有$list1有值,返回$list1
  4205. return $list1;
  4206. } else {
  4207. // 如果两个数组都没有该字段,返回空数组
  4208. return [];
  4209. }
  4210. }else if($type == 2){
  4211. $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid,avatar")->select()->toArray();
  4212. return $list;
  4213. }
  4214. // foreach ($list as $key => $value) {
  4215. // $list[$key]['user_name'] = $value['user_name'] . "业绩";
  4216. // $list[$key]['performance'] = $this->getPerformance($value['id']);
  4217. // //辨别当前是大部门还是小部门。用于显示大小业绩展示
  4218. // $list[$key]['curr_type'] = '';
  4219. // if($type == 1){
  4220. // $list[$key]['curr_type'] = 1;
  4221. // }else if($type == 0){
  4222. // $list[$key]['curr_type'] = 0;
  4223. // }else{
  4224. // $list[$key]['curr_type'] = '';
  4225. // }
  4226. // }
  4227. return $list;
  4228. }
  4229. public function get_yj_amount($list,$type){
  4230. foreach ($list as $key => $value) {
  4231. # code...
  4232. // $amount = $this->getPerformanceOfId($value['id']);
  4233. $list[$key]['user_name'] = $value['user_name'] . "业绩";
  4234. //$list[$key]['total_performance'] = $amount;
  4235. //$performance = $this->getPerformanceOfId($search_name['id']);
  4236. $list[$key]['performance'] = $this->getPerformance($value['id']);
  4237. //辨别当前是大部门还是小部门。用于显示大小业绩展示
  4238. $list[$key]['curr_type'] = '';
  4239. if($type == 1){
  4240. $list[$key]['curr_type'] = 1;
  4241. }else if($type == 0){
  4242. $list[$key]['curr_type'] = 0;
  4243. }else{
  4244. $list[$key]['curr_type'] = '';
  4245. }
  4246. }
  4247. return $list;
  4248. }
  4249. //获取团队递归聚宝盆1
  4250. public function teamPeople_copy( $user_id,$type){
  4251. //var_dump($type);
  4252. //$ftype = 1:大部门,0:小部门
  4253. //$user_id = $this->request->post("user_id");
  4254. //$type = $this->request->post("type",0);
  4255. //查找当前用户id下节点
  4256. if($type == 1) {
  4257. // echo 33;
  4258. $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
  4259. }else if($type == 0) {
  4260. // echo 44;
  4261. $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
  4262. }else if($type == 2){
  4263. $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid")->select()->toArray();
  4264. return $list;
  4265. }else {
  4266. // echo 55;
  4267. $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
  4268. }
  4269. foreach ($list as $key => $value) {
  4270. # code...
  4271. // $amount = $this->getPerformanceOfId($value['id']);
  4272. $list[$key]['user_name'] = $value['user_name'] . "业绩";
  4273. //$list[$key]['total_performance'] = $amount;
  4274. //$performance = $this->getPerformanceOfId($search_name['id']);
  4275. $list[$key]['performance'] = $this->getPerformance($value['id']);
  4276. //辨别当前是大部门还是小部门。用于显示大小业绩展示
  4277. $list[$key]['curr_type'] = '';
  4278. if($type == 1){
  4279. $list[$key]['curr_type'] = 1;
  4280. }else if($type == 0){
  4281. $list[$key]['curr_type'] = 0;
  4282. }else{
  4283. $list[$key]['curr_type'] = '';
  4284. }
  4285. }
  4286. return $list;
  4287. }
  4288. // //获取团队递归聚宝盆1
  4289. // public function teamPeople( $user_id,$type){
  4290. // //$user_id = $this->request->post("user_id");
  4291. // //$type = $this->request->post("type",0);
  4292. // //查找当前用户id下节点
  4293. // if($type == 1) {
  4294. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
  4295. // }else if($type == 2) {
  4296. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
  4297. // }else {
  4298. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
  4299. // }
  4300. // foreach ($list as $key => $value) {
  4301. // # code...
  4302. // $amount = $this->getPerformanceOfId($value['id']);
  4303. // $list[$key]['user_name'] = $value['user_name'] . "-----业绩" . $amount;
  4304. // }
  4305. // return $list;
  4306. // }
  4307. }