| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641 |
- <?php
- /**
- * @package merchant
- *
- * @author xaboy
- * @day 2020/6/18
- *
- *
- */
- namespace app\controller\api\user;
- use app\common\repositories\article\AgreementRepository;
- use app\common\repositories\merchant\order\OrderGzcRepository;
- use app\common\repositories\merchant\order\OrderMerchantRepository;
- use app\common\repositories\store\product\ProductRepository;
- use app\common\repositories\user\UnionUsersRepository;
- use app\controller\api\merchant\sxy\Access;
- use app\controller\api\store\product\DaTaoKe;
- use app\controller\api\store\product\Jd;
- use app\controller\api\store\product\TaoBao;
- use app\controller\api\store\product\TaoKe;
- use app\controller\api\store\product\Vip;
- use app\model\common\UserThirdModel;
- use app\traits\GzcApiRequest;
- use app\traits\HuiPay;
- use crmeb\basic\BaseController;
- use app\common\repositories\user\UserBillRepository;
- use app\common\repositories\user\UserRepository;
- use app\common\repositories\user\UserVisitRepository;
- use crmeb\services\QrcodeService;
- use crmeb\services\WechatService;
- use Symfony\Component\HttpFoundation\Request;
- use think\App;
- use think\facade\Db;
- use think\Exception;
- use think\exception\ValidateException;
- use think\facade\Cache;
- use BaiduAi\controller\Ocr;
- use think\facade\Log;
- use think\facade\Request as r;
- class User extends BaseController
- {
- use HuiPay;
- public $repository;
- private $merId;
- private $source;
- public function __construct(App $app, UserRepository $repository)
- {
- parent::__construct($app);
- $this->repository = $repository;
- $this->source = $this->request->header('source');
- $this->merId = $this->request->header('merId');
- }
- /**
- * 创建环信账户
- * @return mixed
- */
- public function hxim_create()
- {
- $uid = $this->request->uid();
- try {
- $im = new Im();
- $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();
- if (isset($user['im_uuid']) && $user['im_user_id']) {
- return app('json')->success($user);
- }
- $im_user_id = 'user' . $user['uid'];
- $data = [];
- $data['im_pass'] = mt_rand(100000, 999999);
- $data['im_user_id'] = $im_user_id;
- // 获取用户是否存在
- $imUser = $im->getImUser('user' . $uid);
- if (isset($imUser['activated']) && $imUser['activated'] == true) {
- $data['im_uuid'] = $imUser['uuid'];
- } else {
- $data['im_uuid'] = $im->createImUser($im_user_id, $user['nickname'], $data['im_pass']);
- }
- Db::name('User')->where(['uid' => $uid])->update([
- 'im' => 1,
- 'im_uuid' => $data['im_uuid'],
- 'im_userid' => $im_user_id,
- 'im_password' => $data['im_pass']
- ]);
- return app('json')->success($data);
- } catch (\Exception $e) {
- Db::name('log')->insert(['data' => '注册异常' . $e->getFile() . $e->getMessage() . $e->getLine()]);
- }
- return app('json')->fail('注册失败');
- }
- /**
- * @return mixed
- * @author xaboy
- * @day 2020/6/22
- */
- public function we_com()
- {
- $where2['mer_id'] = $this->merId;
- $user = Db::name('enterprise')->field('we_com,we_com_url')->where($where2)->find();
- return app('json')->success($user);
- }
- public function spread_image()
- {
- $type = $this->request->param('type');
- $res = $type == 'routine'
- ? $this->repository->routineSpreadImage($this->request->userInfo())
- : $this->repository->wxSpreadImage($this->request->userInfo());
- return app('json')->success($res);
- }
- /**
- * @return mixed
- * 分享每日海报
- */
- public function share_day()
- {
- /**
- * 1242
- * 2208
- */
- $user = $this->request->userInfo();
- $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_wap.jpg';
- $siteUrl = systemConfig('site_url');
- $codeUrl = set_http_type($siteUrl . '/share?spread=' . $user['uid'], request()->isSsl() ? 0 : 1);//二维码链接
- $imageInfo = app()->make(QrcodeService::class)->getQRCodePath($codeUrl, $name, $user['avatar']);
- if (is_string($imageInfo)) throw new ValidateException('二维码生成失败');
- $filename = 'https://88yx.xyz/qqh/uploads/20211101074257444.jpg';
- $qrcode = $imageInfo['dir'];
- dump($qrcode);
- $config = array(
- 'image' => array(
- array(
- 'url' => $qrcode,//二维码资源
- 'stream' => 0,
- 'left' => 533,
- 'top' => 1941,
- 'right' => 0,
- 'bottom' => 0,
- 'width' => 184,
- 'height' => 182,
- 'opacity' => 100
- )
- ),
- 'background' => $filename
- );
- $data = setSharePoster($config, 'routine/spread/poster');
- dump($data);
- return app('json')->success($data);
- }
- public function spread_info()
- {
- $user = $this->request->userInfo();
- $user->append(['one_level_count', 'lock_brokerage', 'two_level_count', 'spread_total', 'yesterday_brokerage', 'total_extract', 'total_brokerage']);
- $data = [
- 'lock_brokerage' => $user->lock_brokerage,
- 'one_level_count' => $user->one_level_count,
- 'two_level_count' => $user->two_level_count,
- 'spread_total' => $user->spread_total,
- 'yesterday_brokerage' => $user->yesterday_brokerage,
- 'total_extract' => $user->total_extract,
- 'total_brokerage' => $user->total_brokerage,
- 'brokerage_price' => $user->brokerage_price,
- 'member_brokerage_price' => $user->member_brokerage_price,
- 'now_money' => $user->now_money,
- 'broken_day' => (int)systemConfig('lock_brokerage_timer')
- ];
- return app('json')->success($data);
- }
- //红包
- public function hongbao_info(){
- log::info("============hongbao");
- $user = $this->request->userInfo();
- if($user->uid>0){
- //已经入账红包
- $data['total_source']=$user->hongbao;
- //为生效红包
- $data['no_total_source']=Db::name('user_sign_hongbao')->where('status', -1)->where('uid', $user->uid)->sum('number');;
- log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
- return app('json')->success($data);
- }
- }
- public function vr_name()
- {
- $uid = $this->request->uid();
- $data = [
- "name"=>"VR转账",
- "url"=>'https://show.gdjbp.com/?uid=' .$uid,
- ];
- return app('json')->success($data);
- }
- public function hongbao_list(){
- $pm = $this->request->param('pm');
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- log::info("hongbao_list==={$uid}");
- $where['uid'] = $uid;
- if ($pm==0){
- $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();
- }
- if($pm==1){
- $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();
- }
- if($pm==2){
- $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();
- }
- log::info("=======date==={$data}");
- return app("json")->success($data);
- }
- //贡献值
- public function gongxian_info(){
- log::info("============gongxianinfo");
- $user = $this->request->userInfo();
- if($user->uid>0){
- // $dateObj=DB::name('user_sign_hongbao')->where('uid', $user->uid)->select();
- //已经入账贡献值
- $data['total_source']=$user->contribute;
- //我的团队贡献值
- $data['team_gongxian_num']=$user->contribute;
- //为生贡献值
- $data['no_total_source']=Db::name('user_sign_gongxian')->where('status', -1)->where('uid', $user->uid)->sum('number');;
- log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
- return app('json')->success($data);
- }
- }
- public function gongxian_list(){
- $pm = $this->request->param('pm');
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- log::info("green_integral_list==={$uid}");
- $where['uid'] = $uid;
- if ($pm==0){
- $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();
- }
- // if($pm==1){
- // $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();
- //
- // }
- if($pm==2){
- $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();
- }
- log::info("=======date==={$data}");
- return app("json")->success($data);
- }
- //京豆
- public function jingdou_info(){
- log::info("============hongbao");
- $user = $this->request->userInfo();
- if($user->uid>0){
- //已经入账京豆
- //$data['total_source']=$user->vr;//原件
- $data['total_source'] = 0;//临时使用
- //为生效京豆
- $data['no_total_source']=Db::name('user_sign_jingdou')->where('status', -1)->where('uid', $user->uid)->sum('number');;
- log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
- return app('json')->success($data);
- }
- }
- public function jingdou_list(){
- return;
- $pm = $this->request->param('pm');
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- log::info("jingdou_list==={$uid}");
- $where['uid'] = $uid;
- if ($pm==0){
- $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();
- }
- if($pm==1){
- $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();
- }
- // if($pm==2){
- // $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();
- // }
- // $data['total'] =111;
- log::info("=======date==={$data}");
- return app("json")->success($data);
- }
- //复购金
- public function fugou_info(){
- log::info("============fugou");
- $user = $this->request->userInfo();
- if($user->uid>0){
- //已经入账京豆
- $data['total_source']=$user->fugou;
- //为生效京豆
- $data['no_total_source']=Db::name('user_sign_fugou')->where('status', -1)->where('uid', $user->uid)->sum('number');;
- log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
- return app('json')->success($data);
- }
- }
- public function fugou_list(){
- $pm = $this->request->param('pm');
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- log::info("fugou_list==={$uid}");
- $where['uid'] = $uid;
- if ($pm==0){
- $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();
- }
- if($pm==1){
- $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();
- }
- if($pm==2){
- $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();
- }
- log::info("=======date==={$data}");
- return app("json")->success($data);
- }
- //VR 购物金
- public function vr_info(){
- log::info("============vr");
- $user = $this->request->userInfo();
- if($user->uid>0){
- //已经入账京豆
- $data['total_source'] = $user->vr;
- //为生效京豆
- $data['no_total_source']=0;
- //$data['no_total_source']=Db::name('user_sign_vr')->where('status', -1)->where('uid', $user->uid)->sum('number');;
- log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
- return app('json')->success($data);
- }
- }
- public function vr_list(){
- $pm = $this->request->param('pm');
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- log::info("vr_list==={$uid}");
- $where['uid'] = $uid;
- $data = DB::name('user_sign_vr')->page($page, $limit)->order("id desc")->select();
- if ($pm==0){
- $data = DB::name('user_sign_vr')->where($where)->where('type', 1)->page($page, $limit)->order("id desc")->select();
- }
- if($pm==2){
- $data = DB::name('user_sign_vr')->where($where)->where('type', 2)->page($page, $limit)->order("id desc")->select();
- }
- // if($pm==2){
- // $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();
- //
- // }
- log::info("=======date==={$data}");
- return app("json")->success($data);
- }
- public function spread_info_yhc()
- {
- log::info("============ddddddddd");
- $user = $this->request->userInfo();
- if($user->uid>0){
- //已经入账积分
- $data['total_source']=$user->score;
- //为生效积分
- $data['no_total_source']=Db::name('user_sign_score')->where('status', -1)->where('uid', $user->uid)->sum('reward_socre');;
- log::info("====spread_info_yhc=={$data['total_source']}======={$data['no_total_source']}");
- return app('json')->success($data);
- }
- // if ($this->source == 'yhc' && $this->merId) {
- // $where['mer_id'] = $this->merId;
- // $where['uid'] = $user->uid;
- // $enterprise_user = Db::name('enterprise_user')->where($where)->find();
- // if ($enterprise_user) {
- // $data['current_balance'] = set_price_rtrim($enterprise_user['commission']);//收益余额
- // $data['unsettled_balance'] = 0;//未结算
- // $extract_price = Db::name('user_extract')->where($where)->whereIn('status', [0, 1])->sum('extract_price');
- // $data['withdrawn_balance'] = set_price_rtrim($extract_price); //已提现
- // $data['total_balance'] = set_price_rtrim($enterprise_user['commission'] + $data['withdrawn_balance']);//总收益=收益余额+已提现
- // $data['identity'] = $enterprise_user['identity'];
- // $data['level'] = $enterprise_user['level'];
- // $data['partnership'] = $enterprise_user['partnership'];
- // $data['green_integral'] = $enterprise_user['green_integral'];
- // $data['green_integral_is'] = $enterprise_user['green_integral_is'];
- // $data['operate'] = $enterprise_user['operate'];
- // $data['operate_icon'] = '';
- // $data['operate_text'] = '';
- // $member_settings = merchantConfig($this->merId, 'member_settings');
- // if ($data['operate'] == 101) {
- // $data['operate_icon'] = $member_settings['yy_one_img'];
- // $data['operate_text'] = $member_settings['yy_one_text'];
- // }
- // if ($data['operate'] == 102) {
- // $data['operate_icon'] = $member_settings['yy_two_img'];
- // $data['operate_text'] = $member_settings['yy_two_text'];
- // }
- //
- //
- // $data['nickname'] = $user->nickname;
- // $data['avatar'] = $enterprise_user['avatar'];
- //
- // $arr = $this->jisuan_fans($user->uid);
- // $data['fans_num'] = count($arr);//粉丝总数
- //
- // $yanglao = 0;
- // $offLinewhere = ['mer_id' => $this->merId, 'uid' => $user->uid, 'commission_type' => '5', 'type_shop' => 0];
- // $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
- // $yanglao += $offLine1;
- // $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
- // $yanglao += $offLine2;
- //
- //
- // $data['ylj'] = set_price_rtrim($yanglao);
- //
- // $data['yhc_withdrawal_money'] = merchantConfig($this->merId, 'yhc_withdrawal_money');
- //
- //
- // $data['uid'] = $enterprise_user['uid'];
- // if ($enterprise_user['identity'] > 100) {
- // $data['identity_data'] = Db::name('enterprise_performance_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['identity'])->find();
- // if (!$data['identity_data']) {
- // $data['identity_data'] = null;
- // $data['identity'] = '100';
- // }
- // } else {
- // $data['identity_data'] = null;
- // }
- //
- // $data['level_data'] = Db::name('enterprise_agent_divvy')->field('name,img,content')->where('state', 1)->where('id', $enterprise_user['level'])->find();
- //
- //
- // return app('json')->success($data);
- // }
- // }
- return app('json')->fail('用户不存在');
- }
- /**
- * @param UserBillRepository $billRepository
- * @return mixed
- * @author xaboy
- * @day 2020/6/22
- */
- public function bill(UserBillRepository $billRepository)
- {
- [$page, $limit] = $this->getPage();
- $where = [
- // 'now_money' => $this->request->param('type', 0),
- 'status' => $this->request->param('status'),
- ];
- if ($this->request->param('is_red') == true) {
- $where['is_red_brokerage'] = 1;
- }
- return app('json')->success($billRepository->userList($where, $this->request->uid(), $page, $limit));
- }
- /**
- * @param UserBillRepository $billRepository
- * @return mixed
- * @author xaboy
- * @day 2020/6/22
- */
- public function brokerage_list(UserBillRepository $billRepository)
- {
- [$page, $limit] = $this->getPage();
- return app('json')->success($billRepository->userList([
- 'category' => 'brokerage',
- ], $this->request->uid(), $page, $limit));
- }
- /**
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author xaboy
- * @day 2020/6/22
- */
- public function spread_order()
- {
- [$page, $limit] = $this->getPage();
- return app('json')->success($this->repository->subOrder($this->request->uid(), $page, $limit));
- }
- /**
- * TODO
- * @return mixed
- * @author Qinii
- * @day 2020-06-18
- */
- public function binding()
- {
- $data = $this->request->params(['phone', 'sms_code']);
- if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
- $user = $this->repository->accountByUser($data['phone']);
- if ($user) {
- $data = ['phone' => $data['phone']];
- } else {
- $data = ['account' => $data['phone'], 'phone' => $data['phone']];
- }
- $this->repository->update($this->request->uid(), $data);
- return app('json')->success('绑定成功');
- }
- /**
- * TODO
- * @return mixed
- * @author Qinii
- * @day 2020-06-18
- */
- public function binding_verify()
- {
- $data = $this->request->params(['user_id', 'captcha']);
- $data['phone'] = \think\facade\Db::name("user")->where(["uid" => $data['user_id']])->value("phone");
- $data['sms_code'] = $data['captcha'];
- if (!$data['sms_code'] || !$this->checkSmsCode($data['phone'], $data['sms_code'])) return app('json')->fail('验证码不正确');
- return app('json')->success('验证成功');
- }
- public function checkSmsCode($phone, $code)
- {
- $sms_key = 'api.auth.sms.' . $phone;
- if (!$cache_code = Cache::get($sms_key)) return false;
- if ($code != $cache_code) return false;
- Cache::delete($sms_key);
- return true;
- }
- /**
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- * @author xaboy
- * @day 2020/6/22
- */
- public function spread_list()
- {
- [$level, $sort, $nickname] = $this->request->params(['level', 'sort', 'keyword'], true);
- $uid = $this->request->uid();
- [$page, $limit] = $this->getPage();
- return app('json')->success($level == 2
- ? $this->repository->getTwoLevelList($uid, $nickname, $sort, $page, $limit)
- : $this->repository->getOneLevelList($uid, $nickname, $sort, $page, $limit));
- }
- /**
- * @return mixed
- * @author xaboy
- * @day 2020/6/22
- */
- public function spread_top()
- {
- [$page, $limit] = $this->getPage();
- $type = $this->request->param('type', 0);
- return app('json')->success($type == 1
- ? $this->repository->spreadMonthTop($page, $limit)
- : $this->repository->spreadWeekTop($page, $limit));
- }
- /**
- * @return mixed
- * @author xaboy
- * @day 2020/6/22
- */
- public function brokerage_top()
- {
- [$page, $limit] = $this->getPage();
- $type = $this->request->param('type', 0);
- return app('json')->success($type == 1
- ? $this->repository->brokerageMonthTop($page, $limit)
- : $this->repository->brokerageWeekTop($page, $limit));
- }
- public function history(UserVisitRepository $repository)
- {
- $uid = $this->request->uid();
- [$page, $limit] = $this->getPage();
- return app('json')->success($repository->getHistory($uid, $page, $limit));
- }
- public function deleteHistory($id, UserVisitRepository $repository)
- {
- $uid = $this->request->uid();
- if (!$repository->getWhereCount(['user_visit_id' => $id, 'uid' => $uid]))
- return app('json')->fail('数据不存在');
- $repository->delete($id);
- return app('json')->success('删除成功');
- }
- public function account()
- {
- $user = $this->request->userInfo();
- if (!$user->phone) return app('json')->fail('请绑定手机号');
- return app('json')->success($this->repository->selfUserList($user->phone));
- }
- public function switchUser()
- {
- $uid = (int)$this->request->param('uid');
- if (!$uid) return app('json')->fail('用户不存在');
- $userInfo = $this->request->userInfo();
- if (!$userInfo->phone) return app('json')->fail('请绑定手机号');
- $user = $this->repository->switchUser($userInfo, $uid);
- $tokenInfo = $this->repository->createToken($user);
- $this->repository->loginAfter($user);
- return app('json')->success($this->repository->returnToken($user, $tokenInfo));
- }
- /**
- * 签到 获取积分
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function sub_signin()
- {
- $member_id = $this->request->uid();
- if (!$member_id) return app('json')->fail('用户不存在');
- $res = $this->repository->sub_signin($member_id);
- return app('json')->success($res);
- }
- /**
- * 获取用户签到记录
- * data1 开始时间
- * data2 结束时间
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function get_signin()
- {
- $member_id = $this->request->uid();
- if (!$member_id) return app('json')->fail('用户不存在');
- $where = [];
- $data1 = input('data1');
- $data2 = input('data2');
- if ($data1 && $data2) {
- $where["data1"] = $data1;
- $where["data2"] = $data2;
- }
- $res = $this->repository->get_signin($member_id, $where);
- return app('json')->success($res);
- }
- /**
- * 提交实名认证
- *
- * @return void
- */
- public function add_certification()
- {
- $member_id = $this->request->uid();
- $type = input("type", 0);
- if ($type == 1) {
- $data = $this->repository->get_cer(["uid" => $member_id]);
- return app('json')->success($data);
- }
- if (!$member_id) return app('json')->fail('用户不存在');
- $params = $this->request->params([
- 'user_name',
- 'mobile',
- 'user_card',
- 'card_positive',
- 'card_reverse',
- ]);
- $params['create_time'] = time();
- $params['uid'] = $member_id;
- $baidu = new Ocr();
- $image = file_get_contents($params['card_positive']);
- $idCardSide = "front";
- $result = $baidu->idcard($image, $idCardSide);
- $real_user_name = $result['words_result']['姓名']['words'] ?? '';
- $real_user_card = $result['words_result']['公民身份号码']['words'] ?? '';
- if ($real_user_name != $params['user_name']) {
- return app('json')->fail('姓名或身份证号输入有误~');
- }
- if ($real_user_card != $params['user_card']) {
- return app('json')->fail('姓名或身份证号输入有误~');
- }
- if ($result['image_status'] == "normal" && $result['idcard_number_type'] == 1) {
- $params['status'] = 1;
- $res = $this->repository->add_cer($params, $member_id);
- if ($res) {
- $userRepository = app()->make(UserRepository::class);
- //赠送积分 完善实名送90个积分,同时送邀请人50个积分
- $userRepository->sign_add($member_id, 90,1,'完善实名系统赠送90个积分','','', '', 1, '', 1);
- $member_info = Db::name('user')->where( array('uid' => $member_id) )->find();
- if($member_info['spread_uid']){
- //好友完善实名系统赠送50个积分
- $spreadUid = $member_info['spread_uid'];
- $userRepository->sign_add($spreadUid, 50,1,'好友完善实名系统赠送50个积分','','', '', 1, '', 1);
- }
- return app('json')->success($res);
- } else {
- return app('json')->fail('认证失败');
- }
- } else {
- return app('json')->fail('认证失败,请重新认证');
- }
- }
- /**
- * 申请代理
- * name:公司名称
- * identity:身份
- * license:营业执照
- */
- public function apply_agent()
- {
- $name = input("name", "");
- $identity = input("identity", 1);
- $license = input("license", "");
- $province_id = input("province_id", "");
- $city_id = input("city_id", "");
- $area_id = input("area_id", "");
- $street_id = input("street_id", "");
- $spread_account = input("spread_account", "");
- $member_id = $this->request->uid();
- if ($identity != 6 && (!$name || !$identity || !$license)) {
- return app('json')->fail('请检查参数');
- }
- if ($identity == 6 && (!$name || !$identity)) {
- return app('json')->fail('请检查参数');
- }
- $data = [
- "name" => $name,
- "identity" => $identity,
- "license" => $license,
- "user_id" => $member_id,
- "province_id" => $province_id,
- "city_id" => $city_id,
- "area_id" => $area_id,
- "street_id" => $street_id,
- 'spread_account' => $spread_account,
- "add_time" => time(),
- "update_time" => time()
- ];
- $res = $this->repository->agent($data);
- if ($res['code'] == 400) {
- return app('json')->fail($res['msg']);
- }
- return app('json')->success("申请成功", $res);
- }
- /*查询是否有已申请或者审核中的代理信息*/
- public function isAgent()
- {
- $uid = $this->request->uid();
- $data = $this->repository->isAgent($uid);
- return app("json")->success($data);
- }
- /*查询是否有审核成功的未支付或支付失败的订单*/
- public function AgentPayDetail()
- {
- $uid = $this->request->uid();
- if (!$uid) {
- return app('json')->fail('请检查参数');
- }
- $where = ['status' => 1, 'pay_status' => ['0', '2'], 'user_id' => $uid];
- $data = $this->repository->getAgentPayDetail($where);
- return app('json')->success("成功", $data);
- }
- /**
- * 获取信息 全民营销首页
- * @return mixed
- */
- public function get_agent_info()
- {
- $member_id = $this->request->uid();
- $res = $this->repository->get_agent_info($member_id);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /**
- * 推广统计
- * search 搜索
- * @return mixed
- */
- public function get_extension_info()
- {
- $search = input("search", "");
- $where = $this->request->params(["identity"]);
- $member_id = $this->request->uid();
- $res = $this->repository->get_extension_info($member_id, $search, $where);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /**
- * 收益统计
- * type 搜索
- * @return mixed
- */
- public function get_profit_info()
- {
- $where = $this->request->params([
- 'commission_type',
- 'date_on',
- 'date_off',
- 'order'
- ]);
- $member_id = $this->request->uid();
- $res = $this->repository->get_profit_info($member_id, $where);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /**
- * 订单统计
- * search 搜索
- * @return mixed
- */
- public function get_tuiguang_order()
- {
- $member_id = $this->request->uid();
- $res = $this->repository->get_tuiguang_order($member_id);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /*
- * 攒金明细统计
- * */
- public function get_commission_all()
- {
- $uid = $this->request->uid();
- $where['date_on'] = 1;
- $where['date_off'] = 0;
- // $where['commission_type'] = '';
- $date = $this->request->params(['date']);//"today","yesterday","week","month","year"
- $where['order'] = $date['date'];
- $res = $this->repository->get_profit_info($uid, $where);
- return app('json')->success($res);
- }
- /*
- * 攒金明细列表
- * */
- public function get_commission_list()
- {
- $uid = $this->request->uid();
- [$where['page'], $where['limit']] = $this->getPage();
- $data = $this->request->params(['type', 'date']);//"today","yesterday","week","month","year"
- $where['type'] = $data['type'];//0线上;1线下
- $where['order'] = $data['date'];//"today","yesterday","week","month","year"
- $res = $this->repository->get_tuiguang_list($uid, $where);
- return app('json')->success($res);
- }
- /*
- * 越攒越多佣金
- * */
- public function get_com_list()
- {
- $uid = $this->request->uid();
- [$where['page'], $where['limit']] = $this->getPage();
- $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
- $where['order'] = $data['date'];//"today","yesterday","week","month","year"
- $res = $this->repository->get_com_list($uid, $where);
- return app('json')->success($res);
- }
- /*
- * 越攒越多统计
- * */
- public function get_com_all()
- {
- $uid = $this->request->uid();
- $data = $this->request->params(['date']);//"today","yesterday","week","month","year"
- $where['order'] = $data['date'];//"today","yesterday","week","month","year"
- $res = $this->repository->get_com_all($uid, $where);
- return app('json')->success($res);
- }
- /**
- * 养老金详情
- * @return mixed
- */
- public function get_yanglao()
- {
- $member_id = $this->request->uid();
- $res = $this->repository->get_yanglao($member_id);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /**
- * 养老金明细
- */
- public function yanglaolog()
- {
- $member_id = $this->request->uid();
- [$page, $limit] = $this->getPage();
- $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "type_shop" => 0];
- if ($this->source == 'yhc' && $this->merId) {
- $where['mer_id'] = $this->merId;
- }
- $month = $this->request->param('month', '');//年月搜索
- $status = $this->request->param('status', 1);
- //1-全部 2-已结算 3-未结算 4-已取消
- if ($status == 2) {
- $where['status'] = 1;
- } else if ($status == 3) {
- // $where['gzc']=0;
- $where['status'] = 0;
- } else if ($status == 4) {
- $where['status'] = -1;
- }
- $source = $this->request->param('source', -1);
- if ($source > -1) {
- $where['source'] = $source;
- }
- $res = $this->repository->yanglaolog($where, $page, $limit, $month);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /*养老金详情*/
- public function YangLaoDetail($id)
- {
- $member_id = $this->request->uid();
- $data = $this->request->params([
- 'type',
- ]);
- $where = ["uid" => $member_id, "type" => "commission", "commission_type" => $data['type'], 'bill_id' => $id];
- $res = $this->repository->yanglaoDetail($where);
- return app('json')->success($res);
- }
- /**
- * 消费明细
- * @return mixed
- */
- public function tripartite()
- {
- $member_id = $this->request->uid();
- $where = ["uid" => $member_id, "type" => "commission", "commission_type" => 5, "tripartite" => ["<>", 0]];
- $res = $this->repository->yanglaolog($where);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /**
- * 提现明细
- * @return mixed
- */
- public function withdrawal()
- {
- $member_id = $this->request->uid();
- $data = $this->request->params([
- 'type',
- ]);
- $where = ["uid" => $member_id, "type" => $data['type'] ? $data['type'] : 2];
- if ($this->source == 'yhc') {
- $where['mer_id'] = $this->merId;
- }
- $res = $this->repository->withdrawal_user($where);
- if ($res) {
- return app('json')->success($res);
- } else {
- return app('json')->fail('获取失败');
- }
- }
- /**
- * 提现详情
- * @return mixed
- * @author cabbage
- * @day 2020/10/31
- */
- public function withdrawalDetail()
- {
- $member_id = $this->request->uid();
- $extract_id = input("extract_id", 0);
- return app('json')->success($this->repository->withdrawalDetail($extract_id, $member_id));
- }
- /*
- * 修改个人信息*/
- public function updateUser()
- {
- $data = $this->request->params([
- 'nickname',
- 'avatar',
- 'sex',
- 'birthday',
- 'addres',
- 'mark'
- ]);
- $uid = $this->request->uid();
- $res = '';
- if ($this->source == 'yhc') {
- $res = Db::name('enterprise_user')->where('mer_id', $this->merId)->where('uid', $uid)->update(['avatar' => $data['avatar']]);
- unset($data['avatar']);
- }
- $data = $this->repository->updateUser($uid, $data);
- if ($data || $res) {
- return app("json")->success("修改成功", $data);
- }
- return app("json")->fail("未做任何修改");
- }
- /*积分记录*/
- public function socreList()
- {
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- $data = $this->repository->socreList($uid, $page, $limit);
- return app("json")->success($data);
- }
- function jisuan_fans($uid)
- {
- $where22['node_uid'] = $uid;
- $where22['mer_id'] = $this->merId;
- $arr = $this->jisuantuandui($where22);
- $where['puid'] = $uid;
- $where['mer_id'] = $this->merId;
- $direct_fans = Db::name('enterprise_user')->where($where)->column('uid');//直属粉丝数量
- $result = array_unique(array_merge($arr, $direct_fans));
- return $result;
- }
- function jisuantuandui($where, $data = [])
- {
- $enterprise_user_team = DB::name('enterprise_user')->where($where)->column('uid');
- $arr = array_merge($data, $enterprise_user_team);
- foreach ($enterprise_user_team as $v) {
- $where['node_uid'] = $v;
- $arr = $this->jisuantuandui($where, $arr);
- }
- return $arr;
- }
- /**
- * 一壶茶-团队列表
- */
- public function team_list_1()
- {
- $teamid = $this->request->uid();
- //$teamid = $this->request->param('teamid');//测试ID
- $teamid = 17;
- $datas_jbp = Db::name('old_user_jbp')->where("id",$teamid)->find();//查询旧系统是否有当前会员
- $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推
- if(!empty($datas_jbp)){
- $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
- //判断大小团队(业绩多的是大部门,业绩小的是小部门)
- $tes = $this->teamPeople($teamid,$type);//1:团队,2:个人
- // 获取分页参数
- $data1= [
- "total"=>100,
- "per_page"=> 10,
- "current_page"=> 1,
- "last_page"=> 1,
- ];
- if($type != 2){
- //小部门和大部门列表数据
- foreach($tes as $k=>$v){
- $curr_pv = '';
- if($v['curr_type']==0){
- $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
- }else if($v['curr_type']==1){
- $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
- }else{
- $curr_pv = 0;
- }
- $data1['data'][$k] = [
- "uid"=>$v["id"],
- "nickname"=> $v['user_name'] . $curr_pv,
- "phone"=> "137****3315",
- "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
- "create_time"=>"2025-01-25 11:00:18",
- "identity"=>"11",
- "level"=> "40002",
- "partnership"=>"22",
- "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩
- "new_performance"=> 0,//新增业绩
- "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,//团购人数(加的这个1 是当前用户的数)
- ];
- }
- }else{
- //直推列表
- foreach($tes as $k=>$v){
- $data1['data'][$k] = [
- "uid"=>$v["uid"],
- "nickname"=> $v['nickname'],
- "avatar"=>$v['avatar'],
- "create_time"=>"2025-01-25 11:00:18",
- ];
- }
- }
- $data['team_list'] = $data1;
- $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;//粉丝数
- $data['new_performance'] = 0;//新增业绩
- $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];//总业绩
- $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];//个人联盟
- $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];//共建联盟
- $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//公共联盟PV
- $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//个人联盟PV
- // $data['effective_fans_num'] = DB::name('enterprise_user')
- }
- //var_dump($data);
- //把新表中的新增邀请用户加到数组中
- //$spread_usersdata = Db::name('user')->where("spread_uid",$teamid)->select();//查询旗下会员
- // 查询当前会员旗下的会员数据
- // 获取分页参数
- [$page, $limit] = $this->getPage();
- // 查询当前会员旗下的会员数据(分页)
- $subordinate_members = Db::name('user')
- ->alias('u')
- ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- ->where("u.spread_uid", $teamid) // 查询旗下会员
- ->where("so.mer_id", 496)
- // ->where("so.douhuomall", 1)
- // ->where("so.douhuomall_status", 9)
- // ->where("so.status", 0)
- ->group('u.uid') // 确保每个用户只出现一次
- ->page($page, $limit) // 分页查询
- ->select(); // 获取分页数据
- //计算团队总业绩
- // $total_amount=0;
- // foreach($subordinate_members as $k=>$v){
- // }
- // 获取总会员数
- $total_members = Db::name('user') ->alias('u')
- ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- ->where("u.spread_uid", $teamid) // 查询旗下会员
- ->where("so.mer_id", 496)
- // ->where("so.douhuomall", 1)
- // ->where("so.douhuomall_status", 9)
- // ->where("so.status", 0)
- ->group('u.uid') // 确保每个用户只出现一次
- ->page($page, $limit) // 分页查询
- ->count(); // 获取分页数据
- // 构造分页信息
- $data1 = [
- "total" => $total_members,
- "per_page" => $limit,
- "current_page" => $page,
- "last_page" => ceil($total_members / $limit),
- "data" => []
- ];
- $total_amount_pv_team = 0;//计算总业绩
- //获取团队总数量
- $team_count_total = 0;
- $small_count = 0;//小部门人数
- //var_dump($this->calculatePerformance($subordinate_members));
- //获取大小部门数据(新表)
- $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);//下标0是大部门
- //var_dump( $get_big_small_datas);
- //判断大小部门的人数(根据业绩多的就是大部门,业绩小的就是小部门来计算展示的部门人数);
- $big_team_count = $get_big_small_datas[0]['team_count'];
- $smallteam_count = $get_big_small_datas[1]['team_count'];
- //end
- // 遍历分页数据,构造每个会员的详细信息
- foreach ($subordinate_members as $k => $v) {
- //计算自己和旗下的业绩
- $t_teams_pv = $this->calculatePerformance($v['uid']);
- $total_amount_pv_team += $t_teams_pv['total_performance'];
- $data1['data'][$k] = [
- "uid" => $v["uid"],
- "nickname" => $v['nickname'], // 假设昵称字段为 nickname
- "phone" => substr_replace($v['phone'], '****', 3, 4), // 隐藏手机号中间四位
- "avatar" => $v['avatar'], // 假设头像字段为 avatar
- "create_time" => $v['create_time'], // 假设创建时间为 create_time
- "total_performance" => $t_teams_pv['total_performance'], // 假设总业绩字段需要额外计算
- "new_performance" => $t_teams_pv['total_performance'], // 假设新增业绩字段需要额外计算
- "team_count" => $t_teams_pv['team_count'], // 假设团购人数需要额外计算
- ];
- }
- // 根据 type 参数处理数据
- if ($type == 1) {
- // 大部门:取 total_performance 最大的一个数组
- usort($data1['data'], function ($a, $b) {
- return $b['total_performance'] <=> $a['total_performance'];
- });
- $data1['data'] = array_slice($data1['data'], 0, 1); // 只保留最大的一个
- } elseif ($type == 0) {
- // 小部门:去掉 total_performance 最大的一个数组
- usort($data1['data'], function ($a, $b) {
- return $b['total_performance'] <=> $a['total_performance'];
- });
- $data1['data'] = array_slice($data1['data'], 1); // 去掉第一个
- } elseif ($type == 2) {
- // 直推:不做任何处理
- }
- // 构造最终返回的数据
- $data = [
- 'team_list' => $data1,
- 'fans_num' => $get_big_small_datas[0]['team_count'] + $get_big_small_datas[1]['team_count'], // 粉丝数
- 'new_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 新增业绩
- 'total_performance' => $get_big_small_datas[0]['total_performance'] + $get_big_small_datas[1]['total_performance'], // 总业绩
- 'person_nums' => $big_team_count, // 大部门人数
- 'common_nums' => $smallteam_count, // 小部门人数
- 'common_nums_pv' => $get_big_small_datas[0]['total_performance'], // 公共联盟PV
- 'person_nums_pv' => $get_big_small_datas[1]['total_performance'], // 个人联盟PV
- ];
- return app("json")->success($data);
- }
- /**
- * 一壶茶-团队列表
- */
- public function team_list()
- {
- $teamid = $this->request->uid();
- //$teamid = $this->request->param('teamid');//测试ID
- //$teamid = 17;
- if($teamid == 592){
- $teamid = 360;//593
- $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
- return;
- //var_dump($team_userinfo_old_jbp1);return;
- }
- //根据用户找jbp1.0的节点人数组 end
- $datas_jbp = Db::name('old_user_jbp')->where("id",$teamid)->find();//查询旧系统是否有当前会员
- $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推
- // 初始化最终返回的数据
- $data = [
- 'team_list' => [],
- 'fans_num' => 0, // 粉丝数
- 'new_performance' => 0, // 新增业绩
- 'total_performance' => 0, // 总业绩
- 'person_nums' => 0, // 个人联盟人数
- 'common_nums' => 0, // 公共联盟人数
- 'common_nums_pv' => 0, // 公共联盟PV
- 'person_nums_pv' => 0, // 个人联盟PV
- ];
- // 如果在旧系统中有数据
- //if (!empty($datas_jbp)) {
- $team_userinfo_old_jbp1 = $this->getPerformance($teamid);
- $tes = $this->teamPeople($teamid, $type); // 1:团队, 2:个人
- $data1 = [
- "total" => 100,
- "per_page" => 10,
- "current_page" => 1,
- "last_page" => 1,
- "data" => []
- ];
- if ($type != 2) {
- foreach ($tes as $k => $v) {
- $curr_pv = '';
- if ($v['curr_type'] == 0) {
- $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
- } elseif ($v['curr_type'] == 1) {
- $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
- } else {
- $curr_pv = 0;
- }
- $data1['data'][$k] = [
- "uid" => $v["id"],
- "nickname" => $v['user_name'] . $curr_pv,
- "phone" => "137****3315",
- "avatar" => "https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
- "create_time" => "2025-01-25 11:00:18",
- "identity" => "11",
- "level" => "40002",
- "partnership" => "22",
- "total_performance" => $curr_pv,
- "new_performance" => 0,
- "team_count" => $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,
- ];
- }
- } else {
- foreach ($tes as $k => $v) {
- $data1['data'][$k] = [
- "uid" => $v["uid"],
- "nickname" => $v['nickname'],
- "avatar" => $v['avatar'],
- "create_time" => "2025-01-25 11:00:18",
- ];
- }
- }
- // 旧系统中的公共部分数据
- $data['team_list'] = $data1;
- $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'];
- $data['new_performance'] = 0;
- $data['total_performance'] = $team_userinfo_old_jbp1['sum_nums_pv'];
- $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];
- $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];
- $data['common_nums_pv'] = max($team_userinfo_old_jbp1['common_nums_pv'], $team_userinfo_old_jbp1['person_nums_pv']);
- $data['person_nums_pv'] = min($team_userinfo_old_jbp1['common_nums_pv'], $team_userinfo_old_jbp1['person_nums_pv']);
- // }
- return app("json")->success($data);
- // // 查询当前会员旗下的会员数据(分页)
- // [$page, $limit] = $this->getPage();
- // $subordinate_members = Db::name('user')
- // // ->alias('u')
- // // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- // ->where("spread_uid", $teamid)
- // // ->where("so.mer_id", 496)
- // // ->group('u.uid')
- // ->page($page, $limit)
- // ->select();
- // $total_members = Db::name('user')
- // // ->alias('u')
- // // ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- // ->where("spread_uid", $teamid)
- // // ->where("so.mer_id", 496)
- // // ->group('u.uid')
- // ->count();
- // $data1 = [
- // "total" => $total_members,
- // "per_page" => $limit,
- // "current_page" => $page,
- // "last_page" => ceil($total_members / $limit),
- // "data" => []
- // ];
- // $total_amount_pv_team = 0;
- // $team_count_total = 0;
- // foreach ($subordinate_members as $k => $v) {
- // $t_teams_pv = $this->calculatePerformance($v['uid']);
- // $total_amount_pv_team += $t_teams_pv['total_performance'];
- // $team_count_total += $t_teams_pv['team_count'];
- // $data1['data'][$k] = [
- // "uid" => $v["uid"],
- // "nickname" => $v['nickname'],
- // "phone" => substr_replace($v['phone'], '****', 3, 4),
- // "avatar" => $v['avatar'],
- // "create_time" => $v['create_time'],
- // "total_performance" => $t_teams_pv['total_performance'],
- // "new_performance" => $t_teams_pv['total_performance'],
- // "team_count" => $t_teams_pv['team_count'],
- // ];
- // }
- // // 获取大小部门数据
- // $get_big_small_datas = $this->getbig_samll_datas($subordinate_members);
- // // 判断大小部门的人数
- // $big_team_count = $get_big_small_datas[0]['team_count'];
- // $small_team_count = $get_big_small_datas[1]['team_count'];
- // // 根据 type 参数处理数据
- // if ($type == 1) {
- // usort($data1['data'], function ($a, $b) {
- // return $b['total_performance'] <=> $a['total_performance'];
- // });
- // $data1['data'] = array_slice($data1['data'], 0, 1);
- // } elseif ($type == 0) {
- // usort($data1['data'], function ($a, $b) {
- // return $b['total_performance'] <=> $a['total_performance'];
- // });
- // $data1['data'] = array_slice($data1['data'], 1);
- // }
- // // 合并数据
- // if (!empty($datas_jbp)) {
- // // 如果旧系统中有数据,合并新旧数据
- // $data['team_list']['data'] = array_merge($data['team_list']['data'], $data1['data']);
- // $data['fans_num'] += $team_count_total;
- // $data['new_performance'] += $total_amount_pv_team;
- // $data['total_performance'] += $total_amount_pv_team;
- // $data['person_nums'] += $big_team_count;
- // $data['common_nums'] += $small_team_count;
- // $data['common_nums_pv'] += $get_big_small_datas[0]['total_performance'];
- // $data['person_nums_pv'] += $get_big_small_datas[1]['total_performance'];
- // } else {
- // // 如果旧系统中没有数据,直接使用新数据
- // $data['team_list'] = $data1;
- // $data['fans_num'] = $team_count_total;
- // $data['new_performance'] = $total_amount_pv_team;
- // $data['total_performance'] = $total_amount_pv_team;
- // $data['person_nums'] = $big_team_count;
- // $data['common_nums'] = $small_team_count;
- // $data['common_nums_pv'] = $get_big_small_datas[0]['total_performance'];
- // $data['person_nums_pv'] = $get_big_small_datas[1]['total_performance'];
- // }
- // return app("json")->success($data);
- }
- //计算自己和自己团队下面的业绩。新表
- //计算自己和自己团队下面的业绩。新表
- public function calculatePerformance($uid)
- {
- // 初始化业绩数组
- $performance = [
- 'personal_performance' => 0, // 个人业绩
- 'team_performance' => 0, // 团队业绩
- 'total_performance' => 0, // 总业绩
- 'team_count' => 0, // 加上自己的团队数量
- ];
- // 定义业绩换算规则
- $performanceMapping = [
- 1180 => 700,
- 10620 => 6300,
- 11800 => 7000
- ];
- // 计算个人业绩
- $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
- if ($personalOrder) {
- // 将浮点数转换为整数
- $totalPrice = (int)$personalOrder['total_price'];
- if (isset($performanceMapping[$totalPrice])) {
- $performance['personal_performance'] = $performanceMapping[$totalPrice];
- }
- }
- // 计算旗下团队成员的业绩
- $teamOrders = Db::name('user')
- ->alias('u')
- ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- ->where("u.spread_uid", $uid) // 查询旗下会员
- ->where("so.mer_id", 496)
- // ->where("so.douhuomall", 1)
- // ->where("so.douhuomall_status", 9)
- // ->where("so.status", 0)
- ->select();
- $teamOrders_count = Db::name('user')
- ->alias('u')
- ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- ->where("u.spread_uid", $uid) // 查询旗下会员
- ->where("so.mer_id", 496)
- // ->where("so.douhuomall", 1)
- // ->where("so.douhuomall_status", 9)
- // ->where("so.status", 0)
- ->count();
- $performance['team_count'] = $teamOrders_count + 1; // 赋值团队数量
- foreach ($teamOrders as $order) {
- if ($order['total_price']) {
- // 将浮点数转换为整数
- $totalPrice = (int)$order['total_price'];
- if (isset($performanceMapping[$totalPrice])) {
- $performance['team_performance'] += $performanceMapping[$totalPrice];
- }
- }
- }
- // 计算总业绩
- $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
- // 假设总业绩最大值需要通过后续逻辑判断,这里暂时设置为 false
- return $performance;
- }
- //获取大小部门业绩(新表)
- public function getbig_samll_datas($subordinate_members){
- //单独写一个方法获取大小部门的数据
- $arr_team = [];
- foreach ($subordinate_members as $k => $v) {
- //计算自己和旗下的业绩
- $arr_team[] = $this->calculatePerformance($v['uid']);
- }
- // 初始化变量
- $maxPerformance = 0;
- $maxIndex = -1;
- // 找出 total_performance 最高的记录
- foreach ($arr_team as $index => $item) {
- if ($item['total_performance'] > $maxPerformance) {
- $maxPerformance = $item['total_performance'];
- $maxIndex = $index;
- }
- }
- // 如果找到了最高记录
- if ($maxIndex !== -1) {
- // 提取最高记录
- $maxRecord = $arr_team[$maxIndex];
- // 从原数组中移除该记录
- unset($arr_team[$maxIndex]);
- // 重新索引数组
- $arr_team = array_values($arr_team);
- } else {
- // 如果没有找到记录,可以设置一个默认值
- $maxRecord = null;
- }
- // 计算大部门和小部门的汇总信息
- $majorDepartmentSummary = [
- "total_person_performance" => $maxRecord ? $maxRecord['personal_performance'] : 0,
- "total_team_performance" => $maxRecord ? $maxRecord['team_performance'] : 0,
- "total_performance" => $maxRecord ? $maxRecord['total_performance'] : 0,
- "team_count" => $maxRecord ? $maxRecord['team_count'] : 0,
- "data" => $maxRecord ? [$maxRecord] : []
- ];
- $minorDepartmentSummary = [
- "total_person_performance" => array_sum(array_column($arr_team, 'personal_performance')),
- "total_team_performance" => array_sum(array_column($arr_team, 'team_performance')),
- "total_performance" => array_sum(array_column($arr_team, 'total_performance')),
- "team_count" => array_sum(array_column($arr_team, 'team_count')),
- "data" => $arr_team
- ];
- // 输出结果
- // echo "大部门汇总信息:\n";
- // print_r($majorDepartmentSummary);
- // echo "小部门汇总信息:\n";
- // print_r($minorDepartmentSummary);
- return array($majorDepartmentSummary,$minorDepartmentSummary);
- }
- //计算自己和自己团队下面的业绩。新表
- public function calculatePerformance_copy($uid)
- {
- // 初始化业绩数组
- $performance = [
- 'personal_performance' => 0, // 个人业绩
- 'team_performance' => 0, // 团队业绩
- 'total_performance' => 0, // 总业绩
- 'team_count' =>0, //加上自己的团队数量
- //'team_count_pr'=>0,//实际团队数量(没有加上自己)
- ];
- // 定义业绩换算规则
- $performanceMapping = [
- 1180 => 700,
- 10620 => 6300,
- 11800 => 7000
- ];
- // 计算个人业绩
- $personalOrder = Db::name('store_order')->where("uid", $uid)->find();
- if ($personalOrder) {
- // 将浮点数转换为整数
- $totalPrice = (int)$personalOrder['total_price'];
- if (isset($performanceMapping[$totalPrice])) {
- $performance['personal_performance'] = $performanceMapping[$totalPrice];
- }
- }
- // 计算旗下团队成员的业绩
- $teamOrders = Db::name('user')
- ->alias('u')
- ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- ->where("u.spread_uid", $uid) // 查询旗下会员
- ->where("so.mer_id", 496)
- // ->where("so.douhuomall", 1)
- // ->where("so.douhuomall_status", 9)
- // ->where("so.status", 0)
- ->select();
- $teamOrders_count = Db::name('user')
- ->alias('u')
- ->join('store_order so', 'u.uid = so.uid', 'LEFT')
- ->where("u.spread_uid", $uid) // 查询旗下会员
- ->where("so.mer_id", 496)
- // ->where("so.douhuomall", 1)
- // ->where("so.douhuomall_status", 9)
- // ->where("so.status", 0)
- ->count();
- $performance['team_count'] = $teamOrders_count+1;//赋值团队数量
- //$performance['team_count_pr'] = $teamOrders_count;//没有加上父级赋值团队数量
- foreach ($teamOrders as $order) {
- if ($order['total_price']) {
- // 将浮点数转换为整数
- $totalPrice = (int)$order['total_price'];
- if (isset($performanceMapping[$totalPrice])) {
- $performance['team_performance'] += $performanceMapping[$totalPrice];
- }
- }
- }
- // 计算总业绩
- $performance['total_performance'] = $performance['personal_performance'] + $performance['team_performance'];
- return $performance;
- }
- public function team_list_copy旧表使用()
- {
- $teamid = $this->request->uid();
- //$teamid = $this->request->param('teamid');//测试ID
- $teamid = 17;
- $type = $this->request->param('type',0);//1:大部门,0:小部门,2:直推
- $team_userinfo_old_jbp1= $this->getPerformance($teamid);
- //判断大小团队(业绩多的是大部门,业绩小的是小部门)
- $tes = $this->teamPeople($teamid,$type);//1:团队,2:个人
- $data1= [
- "total"=>100,
- "per_page"=> 10,
- "current_page"=> 1,
- "last_page"=> 1,
- ];
- if($type != 2){
- //小部门和大部门列表数据
- foreach($tes as $k=>$v){
- $curr_pv = '';
- if($v['curr_type']==0){
- $curr_pv = $team_userinfo_old_jbp1['person_nums_pv'];
- }else if($v['curr_type']==1){
- $curr_pv = $team_userinfo_old_jbp1['common_nums_pv'];
- }else{
- $curr_pv = 0;
- }
- $data1['data'][$k] = [
- "uid"=>$v["id"],
- "nickname"=> $v['user_name'] . $curr_pv,
- "phone"=> "137****3315",
- "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
- "create_time"=>"2025-01-25 11:00:18",
- "identity"=>"11",
- "level"=> "40002",
- "partnership"=>"22",
- "total_performance"=> $curr_pv,//$v["performance"]['sum_nums_pv'],//总业绩
- "new_performance"=> 0,//新增业绩
- "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'] + 1,//团购人数(加的这个1 是当前用户的数)
- ];
- }
- }else{
- //直推列表
- foreach($tes as $k=>$v){
- $data1['data'][$k] = [
- "uid"=>$v["uid"],
- "nickname"=> $v['nickname'],
- "avatar"=>$v['avatar'],
- "create_time"=>"2025-01-25 11:00:18",
- ];
- }
- }
- $data['team_list'] = $data1;
- $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;//粉丝数
- $data['new_performance'] = 0;//新增业绩
- $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];//总业绩
- $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];//个人联盟
- $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];//共建联盟
- $data['common_nums_pv'] =max( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//公共联盟PV
- $data['person_nums_pv'] = min( $team_userinfo_old_jbp1['common_nums_pv'],$team_userinfo_old_jbp1['person_nums_pv']);//个人联盟PV
- // $data['effective_fans_num'] = DB::name('enterprise_user')
- //把新表中的新增邀请用户加到数组中
- return app("json")->success($data);
- }
- /**
- * 一壶茶-团队列表
- */
- public function team_list_copy()
- {
- $uid = $this->request->uid();
- $where['puid'] = $uid;
- $where['mer_id'] = $this->merId;
- $data['direct_fans_num'] = Db::name('enterprise_user')->where($where)->count();//直属粉丝数量
- //var_dump($uid);
- $arr = $this->jisuan_fans($uid);
- $data['fans_num'] = count($arr);//粉丝总数
- $data['total_performance'] = 12555;//总业绩
- $data['new_performance'] = 15;//新增业绩
- [$page, $limit] = $this->getPage();
- $where2['eu.mer_id'] = $this->merId;
- $type = $this->request->param('type', 0);//1:大部门,0:小部门
- // var_dump($where2);
- $enterprise_user_team = DB::name('enterprise_user')
- ->alias('eu')
- ->join('user u', 'eu.uid=u.uid')
- ->where($where2)
- ->when($type < 1 || $type == 2, function ($q) use ($arr) {
- $q->whereIn('eu.uid', $arr);
- })
- ->when($type == 1, function ($q) use ($uid) {
- $q->whereIn('eu.puid', $uid);
- })
- ->when($type == 2, function ($q) use ($uid) {
- $q->whereIn('eu.identity', [100, 101, 102, 103, 104, 105]);
- })
- ->field('eu.uid,u.nickname,u.phone,eu.avatar,eu.create_time,eu.identity,eu.level,eu.partnership')
- ->order('eu.enterprise_user_id desc')
- ->paginate($limit)
- ->each(function ($item) {
- $item['phone'] = substr_replace($item['phone'], '****', 3, 4);
- return $item;
- });
- //var_dump($enterprise_user_team);
- $data['team_list'] = $enterprise_user_team;
- $data['effective_fans_num'] = DB::name('enterprise_user')
- ->alias('eu')
- ->join('user u', 'eu.uid=u.uid')
- ->where($where2)
- ->whereIn('eu.uid', $arr)
- ->whereIn('eu.identity', [100, 101, 102, 103, 104, 105])
- ->count();//有效粉丝数量
- return app("json")->success($data);
- }
- public function team_details()
- {
- $uid = $this->request->param('uid', 0);
- $where2['eu.uid'] = $uid;
- $where2['eu.mer_id'] = $this->merId;
- $enterprise_user_team = DB::name('enterprise_user')
- ->alias('eu')
- ->join('user u', 'eu.uid=u.uid')
- ->where($where2)
- ->field('eu.uid,u.nickname,u.phone,u.avatar,eu.create_time,eu.identity,eu.level,eu.partnership,eu.puid')
- ->find();;
- if ($enterprise_user_team) {
- $enterprise_user_team['phone'] = substr_replace($enterprise_user_team['phone'], '****', 3, 4);
- $enterprise_user_team['p_nickname'] = '';
- $enterprise_user_team['p_phone'] = '';
- $yanglao = 0;
- $offLinewhere = ['mer_id' => $this->merId, 'uid' => $uid, 'commission_type' => '5', 'type_shop' => 0];
- $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
- $yanglao += $offLine1;
- $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
- $yanglao += $offLine2;
- $enterprise_user_team['ylj'] = set_price_rtrim($yanglao);
- if ($enterprise_user_team['puid'] > 0) {
- $user = Db::name('user')->where('uid', $enterprise_user_team['puid'])->find();
- if ($user) {
- $enterprise_user_team['p_nickname'] = $user['nickname'];
- $enterprise_user_team['p_phone'] = substr_replace($user['phone'], '****', 3, 4);
- }
- }
- }
- return app("json")->success($enterprise_user_team);
- }
- /**
- * 率积分明细
- */
- public function green_integral_list()
- {
- $pm = $this->request->param('pm');
- $status = $this->request->param('status');
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- log::info("green_integral_list==={$uid}");
- $where['uid'] = $uid;
- // $where['mer_id'] = $this->merId;
- // if ($pm == 1) {
- // $pm_arr = [1, 3];
- // } else {
- // $pm_arr = [2, 4];
- // }
- if ($pm==0){
- $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();
- }
- if($pm==1){
- $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();
- }
- if($pm==2){
- $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();
- }
- log::info("=======date==={$data}");
- return app("json")->success($data);
- }
- public function user_invite_profit_list()
- {
- $uid = $this->request->uid();
- [$page, $limit] = $this->getPage();
- $commission_type = $this->request->param('commission_type', 0);
- if ($commission_type) {
- $where['commission_type'] = $commission_type;
- }
- $month = $this->request->param('month', '') ?: date('Y-m');
- $startMonth = date('Y-m-01 00:00:00', strtotime($month));
- $endMonth = date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month)));
- $data['yanglao_clear_all'] = Db::name('user_bill')
- ->where('uid', $uid)
- ->whereBetween('create_time', [$startMonth, $endMonth])
- ->where('commission_type', 5)
- ->where('pm', 1)
- ->where('status', 1)
- ->sum('number');
- $data['yanglao_nclear_all'] = Db::name('user_bill')
- ->where('uid', $uid)
- ->whereBetween('create_time', [$startMonth, $endMonth])
- ->where('commission_type', 5)
- ->where('pm', 1)
- ->where('status', 0)
- ->sum('number');
- $data['yanglao_yugu_all'] = $data['yanglao_clear_all'] + $data['yanglao_nclear_all'];
- $where['uid'] = $uid;
- $data['totel_money'] = Db::name('user_bill')->where($where)
- ->whereNotIn('commission_type', [5, 7, 17, 19])
- ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
- $query->whereBetween('create_time', [$startMonth, $endMonth]);
- }, function ($query) use ($where, $month, $startMonth, $endMonth) {
- $query->where('commission_type', '<>', 5)
- ->whereBetween('create_time', [$startMonth, $endMonth]);
- })
- ->sum('number');
- $pageInfo = Db::name('user_bill')
- ->where($where)
- ->whereNotIn('commission_type', [5, 7, 17, 19])
- ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
- $query->whereBetween('create_time', [$startMonth, $endMonth]);
- }, function ($query) use ($where, $month, $startMonth, $endMonth) {
- $query->where('commission_type', '<>', 5)
- ->whereBetween('create_time', [$startMonth, $endMonth]);
- })
- ->order('bill_id desc')
- ->paginate($limit);
- $data_arr = [];
- foreach ($pageInfo->items() as $k => $v) {
- $v['money'] = set_price_rtrim($v['number']);
- $v['order_money'] = set_price_rtrim(0);
- $v['commission_rate'] = set_price_rtrim(0);
- $order = Db::name('store_order')->where('order_sn', $v['order_sn'])->find();
- if (!empty($order)) {
- $v['order_money'] = set_price_rtrim($order['total_price']);
- $v['commission_rate'] = set_price_rtrim(bcdiv($v['money'], $v['order_money'], 2));
- }
- if ($v['status'] == 0) {
- // $v['create_time'] = '--';
- }
- if ($v['status'] == 1) {
- // $v['create_time'] = $v['take_time'];
- }
- $data_arr[] = $v;
- }
- $data['pageInfo']['current_page'] = $pageInfo->currentPage();
- $data['pageInfo']['data'] = $data_arr;
- $data['pageInfo']['last_page'] = $pageInfo->lastPage();
- return app("json")->success($data);
- }
- /*导航转链-用于用户下单绑定*/
- public function changeLink()
- {
- $uid = $this->request->uid();
- if (!$uid) {
- return app("json")->error("请登录");
- }
- $data = $data = $this->request->params([
- 'url',
- 'name'
- ]);
- $data['url'] = urldecode($data['url']);
- $data['name'] = urldecode($data['name']);
- if (in_array($data['name'], ['京东', '苏宁易购', '饿了么', '唯品会', '拼多多'])) {
- if ($data['name'] == '京东') {
- $url = app()->make(Jd::class)->linkChange($data['url'], $uid);
- }
- if ($data['name'] == '拼多多') {
- $url = app()->make(TaoKe::class)->changeLink($data['url'], $uid);
- }
- if ($data['name'] == '唯品会') {
- $url = app()->make(Vip::class)->changeLink($data['url'], $uid);
- }
- if ($data['name'] == '苏宁易购') {
- $url = $data['url'];
- //$url = app()->make(Su::class)->changeLink($data['url'],$uid);
- }
- if ($data['name'] == '饿了么') {//获取饿了么官方活动链接
- //如果用户没有拉取relation_id,
- $where = ['uid' => $uid, 'type' => 5];
- $isRelation = UserThirdModel::where($where)->find();
- if ($isRelation) {
- $result = DaTaoKe::activityChangeLink('20150318020002597', $uid);
- if ($result['code'] == 0) {
- return \app('json')->fail("获取饿了么链接出错", $result['raw']);
- }
- $url = $result['link'];
- } else {//如果还没有获取用户的relation_id还需要拉淘宝授权
- $state = "{$uid}_h5";
- $url = \app()->make(TaoBao::class)->getAuthUrl($state);
- }
- }
- }
- return app("json")->success($url);
- }
- /*获取协议*/
- public function xieyi()
- {
- $data = $this->request->params([
- 'type'
- ]);
- $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($data['type']);
- return app("json")->success($data);
- }
- /*获取规则文章*/
- public function guize()
- {
- $id = $this->request->param('id');
- $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($id);
- if(!$data){
- $data['title']='';
- $data['content']='';
- }
- $html='<!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>'.$data['title'].'</title>
- <style>
- body {
- font-family: Arial, sans-serif;
- margin: 0;
- padding: 0;
- }
- .container {
- margin: 0 auto;
- padding: 20px;
- }
- </style>
- </head>
- <body>
- <div class="container">
- '.$data['content'].'
- </div>
- </body>
- </html';
- return $html;
- }
- /**
- * 支付宝获取授权
- * @return mixed
- * @author php迷途小书童
- * @created 2021/1/16 17:03
- */
- public function alipayAuthorization(UserRepository $userRepository)
- {
- $authorization_code = $this->request->param('code');
- $type = $this->request->param('type', 'h5');
- $paramStr = $userRepository->getTokenByCode($authorization_code, false, $type);
- return app("json")->success($paramStr);
- }
- /**
- * 微信获取授权
- * @return mixed
- * @author php迷途小书童
- * @created 2021/1/16 19:08
- */
- public function wechatAuthorization()
- {
- $request = $this->request;
- $wxConfig = [
- "appid" => "wx66f5f8def2b755da",
- "appsecret" => "891572d83222105a635cf9f502363ff8"
- ];
- $oauth = WechatService::create()->getApplication()->oauth;
- // dump($oauth);
- $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
- try {
- $wechatInfo = $oauth->user()->getOriginal();
- } catch (\Exception $e) {
- return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]);
- }
- if (!isset($wechatInfo['nickname'])) {
- return app('json')->fail('授权失败[002]');
- }
- return app("json")->success($wechatInfo);
- }
- /**
- * 更新绑定微信支付宝账号
- * type=1 微信 2 支付宝
- * openid openid
- */
- public function updateAccount(UserRepository $userRepository)
- {
- $type = $this->request->param('type');
- $openid = $this->request->param('openid');//前端传的是unionid
- $nickname = $this->request->param('nickname');
- $avater = $this->request->param('avater');
- $alinfo = $this->request->param('alinfo');
- $uid = $this->request->uid();
- $user = $this->request->userInfo();
- if (!$type) {
- return app("json")->fail("失败");
- }
- makeLock()->lock();
- try {
- if ($type == 1) {
- $data = ["wechat_user_id" => $openid];
- $unionId = $openid;
- $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
- if ($check) throw new \Exception("此微信号已被绑定");
- } else {
- $alinfo = json_decode($alinfo, true);
- if (!$alinfo) throw new \Exception("参数异常");
- $data = ["ali_user_id" => $alinfo["userId"]];
- $unionId = $alinfo["userId"];
- $check = Db::name("user")->where("ali_user_id", $unionId)->find();
- if ($check) throw new \Exception("此支付宝号已被绑定");
- $paramStr = $userRepository->getTokenByCode($alinfo["authCode"], true);
- // \think\facade\Db::name('log')->insert(['data'=>'支付宝授权信息'.json_encode($paramStr)]);
- $nickname = empty($paramStr["nick_name"]) ? "al" . $alinfo["userId"] : $paramStr["nick_name"];
- $avater = empty($paramStr["avatar"]) ? "http://app.bjtdba.com/uploads/def/20201118/5984361a2e00f5407776bcd6eaaae1ce.png" : $paramStr["avatar"];
- }
- $data2 = [
- "type" => $type,
- "uid" => $uid,
- "nickname" => $nickname,
- "avater" => $avater,
- ];
- $result = $this->repository->updateUser($uid, $data, $data2);
- if (!$result) throw new \Exception("修改失败");
- $userRepository = app()->make(UserRepository::class);
- $userInfo = $userRepository->getOne(['uid' => $uid]);
- //绑定线下充值金额
- $unionUsersRepository = app()->make(UnionUsersRepository::class);
- $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
- $notBind = $unionUsersRepository->getAllNotBind($unionId);
- if ($notBind) {
- $orderMerchantRepository->doBindUser($userInfo, $type);
- }
- } catch (\Throwable $e) {
- makeLock()->unlock();
- return app("json")->fail("失败" . $e->getMessage());
- }
- makeLock()->unlock();
- return app("json")->success("修改成功", $data);
- }
- /**
- * 获取账号绑定信息
- * @return mixed
- */
- public function getAccount()
- {
- $uid = $this->request->uid();
- // $data = $this->repository->getUser($uid, "wechat_user_id,ali_user_id");
- $data = $this->repository->getAccount($uid);
- if ($data) {
- return app("json")->success("查询成功", $data);
- }
- return app("json")->fail("未绑定");
- }
- // /*
- // * 养老金统计
- // * */
- // public function get_yanglao_statistics()
- // {
- // $uid = $this->request->uid();
- // //线下数量
- // // 查询未结算
- //
- // $gzc_order_list = Db::name('gzc_logs')->where('uid', $uid)->column('out_trade_no');
- //
- // $onlineYanglaoUserBill = Db::name('user_bill')->where('commission_type', 5)->whereNotIn('order_sn',$gzc_order_list)->where('status', 0)->where('uid', $uid)->sum('number');
- // $onlineYanglaoGzc = Db::name('gzc_logs')->where('success', 0)->where('uid', $uid)->sum('pension');
- // $clearYanglao = Db::name('gzc_logs')->where('success', 1)->where('uid', $uid)->sum('pension');
- //
- // $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
- // $res = GzcApiRequest::checkAmount($userInfo);
- // $gzc = $res['extendData']['amount'] * 0.01;
- // // PCPC-中信公证处
- // $data['all_gzc'] = set_price_rtrim(sprintf("%01.2f", $gzc));
- // // 总养老金
- // $data['all_yanglao'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao + $gzc);
- // // 平台养老金
- // $data['all_yanglao_yhc'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao);
- // // 未结算养老金=预估养老金,不能包含进入公证处未成功的记录(这部分是已结算的)
- // $data['all_yanglao_yugu'] = set_price_rtrim(round($onlineYanglaoUserBill, 2));
- // // 已结算养老金 已入账
- // $data['all_yanglao_clear'] = set_price_rtrim(round($onlineYanglaoGzc+$clearYanglao, 2));
- // // 已入账养老金
- // $data['all_yanglao_in'] = set_price_rtrim(round($clearYanglao, 2));
- // // 平台未入账养老金
- // $data['all_yanglao_nclear'] = set_price_rtrim(round($onlineYanglaoGzc + $onlineYanglaoUserBill, 2));
- // // 待发起
- // $data['all_yanglao_wait'] = set_price_rtrim(round($onlineYanglaoGzc, 2));
- //
- // return app("json")->success("查询成功", $data);
- // }
- /*
- * 养老金统计
- * */
- public function get_yanglao_statistics()
- {
- $uid = $this->request->uid();
- //线下数量
- $offLine = \think\facade\Db::name('order_merchant')->where('uid', $uid)->where('status', 1)->field('pension yanglao')->select()->toArray();
- $data['offLine'] = array(
- 'num' => count($offLine),
- 'yanglao' => round($this->num($offLine, 'yanglao'), 2)
- );
- $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>1,'type_shop'=>0];
- if($this->source=='yhc' && $this->merId){
- $offLinewhere['mer_id']=$this->merId;
- }
- $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
- $data['offLine'] = array(
- 'num' => count($offLine),
- 'yanglao' => round($this->num($offLine, 'number'), 2)
- );
- // $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
- // $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
- // $data['offLine'] = array(
- // 'num' => count($offLine),
- // 'yanglao' => round($this->num($offLine, 'number'), 2)
- // );
- //线上已确认收货
- // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '2,3')->select()
- // ->each(function ($item) {
- // //查询养老金金额
- // $UserBillRepository = app()->make(UserBillRepository::class);
- // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
- // $pension = $bill->number ?? 0;
- // $item['yanglao'] = $pension;
- // return $item;
- // })
- // ->toArray();
- $onLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
- if($this->source=='yhc' && $this->merId){
- $onLinewhere['mer_id']=$this->merId;
- }
- $onLine= \think\facade\Db::name('user_bill')->where($onLinewhere)->select()->toArray();
- $data['onLine'] = array(
- 'num' => count($onLine),
- 'yanglao' => round($this->num($onLine, 'number'), 2)
- );
- //线上未确认收货
- // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '0,1')->select()
- // ->each(function ($item) {
- // //查询养老金金额
- // $UserBillRepository = app()->make(UserBillRepository::class);
- // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
- // $pension = $bill->number ?? 0;
- // $item['yanglao'] = $pension;
- // return $item;
- // })
- // ->toArray();
- $onLine_take_nowhere=['uid'=>$uid,'status'=>'0','commission_type' => '5','source'=>0,'type_shop'=>0];
- if($this->source=='yhc' && $this->merId){
- $onLine_take_nowhere['mer_id']=$this->merId;
- }
- $onLine_take_no=\think\facade\Db::name('user_bill')->where($onLine_take_nowhere)->select()->toArray();
- $data['onLine_take_no'] = array(
- 'num' => count($onLine_take_no),
- 'yanglao' => round($this->num($onLine_take_no, 'number'), 2)
- );
- if($this->source=='yhc' && $this->merId){
- $data['all_num'] = $data['offLine']['num'] +$data['onLine_take_no']['num'] + $data['onLine']['num'];
- $data['all_yanglao_yhc'] = set_price_rtrim(round($data['offLine']['yanglao']+$data['onLine']['yanglao'] + $data['onLine_take_no']['yanglao'] , 2));//总养老金
- $data['all_yanglao_a'] = set_price_rtrim(round($data['offLine']['yanglao'] + $data['onLine']['yanglao'], 2));//已结算养老金
- $data['all_yanglao_yugu'] = set_price_rtrim(round($data['all_yanglao_yhc']-$data['all_yanglao_a'],2));//预估养老金
- $userInfo = Db::name('UserCertification') -> where('uid',$uid) -> field('user_name,user_card') -> find();
- $res = GzcApiRequest::checkAmount($userInfo);
- $data['all_gzc']=set_price_rtrim(sprintf("%01.2f", $res['extendData']['amount'] * 0.01));
- $data['all_yanglao']=set_price_rtrim( $data['all_yanglao_yhc'] + $data['all_gzc']);
- return app("json")->success("查询成功", $data);
- }
- //淘宝
- $tb_a = 0;
- $tb_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>5];
- $tb = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($tb_where)->where('status','<>','-1')->select()->each(function ($value) use (&$tb_a) {
- $value['yanglao'] = 0;
- $value['yanglao'] = $value['number'];
- $value['yanglao_a'] = 0;
- if ($value['status'] == 1) {
- $value['yanglao_a'] = $value['yanglao'];
- $tb_a++;
- }
- return $value;
- })->toArray();
- $data['tb'] = array(
- 'num' => count($tb),
- 'num_a' => $tb_a,
- 'yanglao' => round($this->num($tb, 'yanglao'), 2),
- 'yanglao_a' => round($this->num($tb, 'yanglao_a'), 2),
- );
- //京东
- $jd_a = 0;
- $jd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>6];
- $jd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($jd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$jd_a) {
- $value['yanglao'] = 0;
- $value['yanglao'] = $value['number'];
- $value['yanglao_a'] = 0;
- if ($value['status'] == 1) {
- $value['yanglao_a'] = $value['yanglao'];
- $jd_a++;
- }
- return $value;
- })->toArray();
- $data['jd'] = array(
- 'num' => count($jd),
- 'num_a' => $jd_a,
- 'yanglao' => round($this->num($jd, 'yanglao'), 2),
- 'yanglao_a' => round($this->num($jd, 'yanglao_a'), 2),
- );
- //苏宁
- $su_a = 0;
- $su_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>3];
- $su = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($su_where)->where('status','<>','-1')->select()->each(function ($value) use (&$su_a) {
- $value['yanglao'] = 0;
- $value['yanglao'] = $value['number'];
- $value['yanglao_a'] = 0;
- if ($value['status'] == 1) {
- $value['yanglao_a'] = $value['yanglao'];
- $su_a++;
- }
- return $value;
- })->toArray();
- $data['su'] = array(
- 'num' => count($su),
- 'num_a' => $su_a,
- 'yanglao' => round($this->num($su, 'yanglao'), 2),
- 'yanglao_a' => round($this->num($su, 'yanglao_a'), 2),
- );
- //拼多多
- $pdd_a = 0;
- $pdd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>1];
- $pdd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($pdd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$pdd_a) {
- $value['yanglao'] = 0;
- $value['yanglao'] = $value['number'];
- $value['yanglao_a'] = 0;
- if ($value['status'] == 1) {
- $value['yanglao_a'] = $value['yanglao'];
- $pdd_a++;
- }
- return $value;
- })->toArray();
- $data['pdd'] = array(
- 'num' => count($pdd),
- 'num_a' => $pdd_a,
- 'yanglao' => round($this->num($pdd, 'yanglao'), 2),
- 'yanglao_a' => round($this->num($pdd, 'yanglao_a'), 2),
- );
- //唯品会
- $vip_a = 0;
- $vip_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>2];
- $vip = \think\facade\Db::name('user_bill')->where($vip_where)->where('uid', $uid)->where('status','<>','-1')->select()->each(function ($value) use (&$vip_a) {
- $value['yanglao'] = 0;
- $value['yanglao'] = $value['number'];
- $value['yanglao_a'] = 0;
- if ($value['status'] == 1) {
- $value['yanglao_a'] = $value['yanglao'];
- $vip_a++;
- }
- return $value;
- })->toArray();
- $data['vip'] = array(
- 'num' => count($vip),
- 'num_a' => $vip_a,
- 'yanglao' => round($this->num($vip, 'yanglao'), 2),
- 'yanglao_a' => round($this->num($vip, 'yanglao_a'), 2),
- );
- // 抖音
- $dy_a = 0;
- $dy_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>9];
- $dy = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($dy_where)->where('status','<>','-1')->select()->each(function ($value) use (&$dy_a) {
- $value['yanglao'] = 0;
- $value['yanglao'] = $value['number'];
- $value['yanglao_a'] = 0;
- if ($value['status'] == 1) {
- $value['yanglao_a'] = $value['yanglao'];
- $dy_a++;
- }
- return $value;
- })->toArray();
- $data['dy'] = array(
- 'num' => count($dy),
- 'num_a' => $dy_a,
- 'yanglao' => round($this->num($dy, 'yanglao'), 2),
- 'yanglao_a' => round($this->num($dy, 'yanglao_a'), 2),
- );
- $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'];
- $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);
- $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);
- $data['third_party_num']=['all_num'=>$data['tb']['num']+$data['jd']['num']+$data['su']['num']+ $data['pdd']['num'] + $data['vip']['num']+ $data['dy']['num']];
- $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']];
- $data['third_party_num_n']=['all_num_n'=>$data['third_party_num']['all_num']-$data['third_party_num_a']['all_num_a']];
- return app("json")->success("查询成功", $data);
- }
- public function num($data, $field)
- {
- $sum = 0;
- foreach ($data as $item) {
- $sum += $item[$field];
- }
- return $sum;
- }
- //志愿者升级
- public function changeVolunteer()
- {
- $uid = $this->request->uid();
- //志愿者条件
- $volunteer_achievement = systemConfig("volunteer_achievement");//volunteer_achievement:用户本人满足养老金要求可升级为志愿者
- $volunteer_class = new Volunteer();
- $volunteer = $volunteer_class->volunteer($uid);
- if ($volunteer['self_yanglao'] < $volunteer_achievement) {
- $data['grade'] = 0;
- $data['self_yanglao'] = $volunteer['self_yanglao'];
- $data['condition_one'] = systemConfig("volunteer_achievement");//用户本人满足养老金要求可升级为志愿者
- return app('json')->success($data);
- }
- $volunteer_class->grade($uid, 1, $volunteer);
- return app('json')->success('申请成功');
- }
- public function GZC($uid)
- {
- $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
- $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
- $OrderGzcRepository = app()->make(OrderGzcRepository::class);
- $where = [
- 'uid' => $uid,
- 'pm' => 1,
- 'status' => 1,
- 'type' => 'commission'
- ];
- $user_data = \think\facade\Db::name('user')->where('uid', $uid)->find();
- $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']];
- $user_data['real_name'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_name');
- $user_data['account'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('mobile');
- $user_data['card_id'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_card');
- Db::name('user_bill')->where($where)->select()->each(function ($item) use ($uid, $orderId, $OrderGzcRepository, $user_data, $certification) {
- $is_implement = 1;
- if ($item['source'] == 0) {
- $order_data = \think\facade\Db::name('store_order')->where('order_sn', $item['order_sn'])->value('uid');
- if ($order_data['uid'] == $item['uid']) {
- $is_implement = 0;
- } else {
- $is_implement = 1;
- }
- } else {
- $order_data = \think\facade\Db::name('order_merchant')->where('out_trade_no', $item['order_sn'])->value('uid');
- if ($order_data['uid'] == $item['uid']) {
- $is_implement = 0;
- } else {
- $is_implement = 1;
- }
- }
- if ($is_implement == 1) {
- $online = ['uid' => $uid, 'pay_type' => '1', 'order_sn' => $item['order_sn'], 'order_id' => $item['link_id']];
- $create = [
- 'uid' => $online['uid'],
- 'platform_no' => $orderId,
- 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
- 'user_name' => $certification['user_name'],
- 'mobile' => $certification['mobile'],
- 'user_card' => $certification['user_card'],
- 'pension' => $item['number'],
- 'order_type' => 2,
- 'out_trade_no' => $online['order_sn']
- ];
- $OrderGzcRepository->create($create);
- }
- });
- }
- //20220712版签到
- public function new_sign()
- {
- // return app('json')->fail('不允许签到');
- $uid = $this->request->uid();//签到用户
- $user = Db::name('user')->where('uid', $uid)->field("spread_uid,first_sign")->find();//上级用户
- //第一天签到获得2积分,第二天获得4积分,第三天获得6积分,第四天获得 10 积分,第五天获得 14积分第六天获得 20积分,
- //连续签到从第七天开始,每日签到获得3积分,第七天连续签到额外奖励 38积分,第 14 天连续签到额外奖励 68 积分,第 21天连续签到额外奖励 128 积分第 30 天连续签到额外奖励 188 积分
- //前6天积分
- $score = [
- 2,//1
- 4,//2
- 6,//3
- 10,//4
- 14,//5
- 20//6
- ];
- //7-30天积分
- $scoreS = 3;
- //额外积分
- $scoreExtra = [
- 7 => 38,
- 14 => 68,
- 21 => 128,
- 30 => 188
- ];
- $today_signintime = strtotime(date('Y-m-d', time()));
- $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
- if (!empty($today_signin_info)) {
- return app('json')->fail('今天已经签到过了');
- } else {
- //查询昨天是否已经签到了
- $yes_signintime = strtotime(date('Y-m-d')) - 86400;
- $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
- $has_qian = 1;
- if (!empty($yes_signin_info)) {
- $has_qian = $yes_signin_info['continuity_day'] + 1;
- $has_qian = $has_qian > 30 ? 1 : $has_qian;
- }
- $get_score = 0;
- $get_gw_score = 0;
- if ($has_qian <= 6) {
- $get_score = $score[$has_qian - 1];
- } else {
- $get_score = $scoreS;
- if (isset($scoreExtra[$has_qian])) {
- $get_gw_score = $scoreExtra[$has_qian];
- }
- }
- $userRepository = app()->make(UserRepository::class);
- $userRepository->sign_add($uid, $get_score, 1, '签到赠送积分', $has_qian, $today_signintime, '', 1, '', 1);
- if($get_gw_score > 0){
- $userRepository->sign_add($uid, $get_gw_score,1,'连续签到赠送额外奖励积分', $has_qian, $today_signintime, '', 1, '', 1);
- }
- //首次签到
- if ($user['first_sign'] == 0) {
- //首次签到送30积分,同时赠送邀请人30积分
- $userRepository->sign_add($uid, 30,1,'首次签到送30积分','','', '', 1, '', 1);
- $member_info = Db::name('user')->where( array('uid' => $uid) )->find();
- if($member_info['spread_uid']){
- $spreadUid = $member_info['spread_uid'];
- $userRepository->sign_add($spreadUid, 30,1,'邀请人首次签到送30积分','','', '', 1, '', 1);
- }
- Db::name('user')->where('uid', $uid)->update(['first_sign' => 1]);
- } elseif ($user['first_sign'] == 1 && $has_qian == 1) {
- Db::name('user')->where('uid', $uid)->update(['first_sign' => 2]);
- }
- // //非首次签到,第一天,断签
- // //好友连续签到3天 奖励50
- // //好友连续签到14天 奖励100
- // //好友联系签到30天 奖励300
- // if ($user['first_sign'] < 2) {
- // if ($has_qian == 3) {
- // $userRepository->sign_add($user['spread_uid'], 50, 1, '好友签到赠送积分', '', $today_signintime, '');
- // } elseif ($has_qian == 14) {
- // $userRepository->sign_add($user['spread_uid'], 100, 1, '好友签到赠送积分', '', $today_signintime, '');
- // } elseif ($has_qian == 30) {
- // $userRepository->sign_add($user['spread_uid'], 300, 1, '好友签到赠送积分', '', $today_signintime, '');
- // Db::name('user')->where('uid', $uid)->update(['first_sign' => 3]);
- // }
- // }
- return app('json')->success('签到成功', ['score' => $get_score]);
- }
- }
- public function new_sign_info()
- {
- $uid = $this->request->uid();
- //查询今天是否已经签到
- $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
- //查询昨天是否已经签到了
- $yes_signintime = strtotime(date('Y-m-d')) - 86400;
- $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
- $data = [
- 'today' => 0,
- 'day' => 0
- ];
- if ($yes_signin_info) $data['day'] = (int)$yes_signin_info['continuity_day'];
- if ($yes_signin_info['continuity_day'] >= 30) $data['day'] = 0;
- if ($today_signin_info) {
- $data['today'] = 1;
- $data['day'] = $data['day'] + 1;
- }
- return app('json')->success($data);
- }
- /**
- * 积分列表
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function sign_list()
- {
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- $month = $this->request->param('month', '') ?: date('Y-m');
- $status = $this->request->param('status');
- $pm = $this->request->param('pm');
- $startMonth = strtotime(date('Y-m-01 00:00:00', strtotime($month)));
- $endMonth = strtotime(date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month))));
- $count = Db::name('user_sign_score')
- ->whereBetween('addtime', [$startMonth, $endMonth])
- ->when(isset($status) && $status !== '', function ($query) use ($status) {
- $query->where('status', $status);
- })
- ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
- $query->where('pm', $pm);
- })
- ->where('uid', $uid)->count();
- $list = Db::name('user_sign_score')
- ->whereBetween('addtime', [$startMonth, $endMonth])
- ->where('uid', $uid)
- ->when(isset($status) && $status !== '', function ($query) use ($status) {
- $query->where('status', $status);
- })
- ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
- $query->where('pm', $pm);
- })
- ->page($page, $limit)->order('id DESC')->select()->each(function ($item) {
- $item['signin_time'] = date('Y-m-d', $item['signin_time']);
- $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']);
- if (!empty($item['order_id'])) {
- //线上订单
- if ($item['order_type'] == 'store_order' || $item['order_type'] == 'store_order_beishengtang') {
- $item['order_sn'] = Db::name("store_order")->where("order_id", $item['order_id'])->value("order_sn");
- } elseif ($item['order_type'] == 'order_merchant') {
- $item['order_sn'] = Db::name("order_merchant")->where("id", $item['order_id'])->value("out_trade_no");
- } elseif ($item['order_type'] == 'extract') {
- $item['order_sn'] = Db::name("user_extract")->where("extract_id", $item['order_id'])->value("order_sn");
- } else {
- $item['order_sn'] = '';
- }
- } else {
- $item['order_sn'] = '';
- }
- return $item;
- });
- $data['list'] = $list;
- $data['count'] = $count;
- return app('json')->success($data);
- }
- public function getAmountFromGzc()
- {
- $uid = $this->request->uid();
- $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
- $res = GzcApiRequest::checkAmount($userInfo);
- return app('json')->success(['amount' => sprintf("%01.2f", $res['extendData']['amount'] * 0.01)]);
- }
- public function check_user_annual_fee()
- {
- //INSERT INTO rrx_user_pension_account (uid) SELECT uid FROM rrx_user;
- //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;
- $uid = $this->request->uid();
- $check = Db::name("user_pension_account")->where("uid", $uid)->find();
- $data = [
- "status" => 3,//0:未交年费,1:年费到期。2:未实名认证,3:正常
- ];
- // //未交年费
- // if (!$check || $check["status"] == 0) {
- // $data["status"] = 0;
- // return app('json')->success($data);
- // }
- // //到期时间小于当前时间。年费到期
- // if (strtotime($check['end_time']) < time()){
- // $data["status"] = 1;
- // return app('json')->success($data);
- // }
- // $data["start_time"] = $check['start_time'];
- // $data["end_time"] = $check['end_time'];
- //
- // //检查实名认证
- // $checkCertification = Db::name("user_certification") -> where("uid",$uid) -> find();
- // if (!$checkCertification){
- // $data["status"] = 2;
- // return app('json')->success($data);
- // }
- return app('json')->success($data);
- }
- /**
- *
- * @remarks 创建年费订单
- * @author 小菜菜
- * @created 2023/04/10 14:37
- */
- public function create_annual_order()
- {
- $uid = $this->request->uid();
- $type = $this->request->param('type', 1);
- $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
- if ($type == 1) $price = "12.00";
- elseif ($type == 2) $price = systemConfig('offline_a');
- elseif ($type == 3) $price = systemConfig('offline_b');
- elseif ($type == 4) $price = systemConfig('offline_c');
- else return app('json')->fail("参数错误");
- $check = Db::name("user_pension_account")->where("uid", $uid)->find();
- //到期时间小于当前时间。年费到期
- if (strtotime($check['end_time']) > time() && $check['status'] == 1) {
- return app('json')->fail("账户已开通,不可重复开通账户");
- }
-
- $insertData = [
- 'pay_price' => $price,
- 'status' => 0,
- 'order_no' => $OrderMerchantRepository->getNewOrderId("mt"),
- 'uid' => $uid,
- 'type' => $type,
- ];
- $order_id = Db::name('user_pension_account_order')->insertGetId($insertData);
- try {
- return app('json')->success(['order_id' => $order_id]);
- } catch (\Exception $e) {
- return app('json')->status('error', $e->getMessage(), ['order_id' => $order_id]);
- }
- }
- /**
- * @remarks 会员支付
- * @author Tang
- * @created 2021/8/27 9:18
- */
- public function pay_user_annual()
- {
- try {
- $oid = r::param('oid', '');
- $code = r::param('code', '');
- $payType = r::param('type', '');//wx.ALI
- if ($oid == '') return app('json')->fail("请检查参数是否正确");
- $groupOrder = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
- if (!$groupOrder) return app('json')->fail('订单不存在或已支付');
- $access = new Access();
- $res = $access->pay_huifu($payType, $code, $groupOrder, "年费", env('APP_URL') . "/api/hf_notify/pay_user_annual");
- Db::name('log')->insert(['data' => '汇付用户年费支付---' . json_encode($res)]);
- Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
- return app('json')->success($res);
- } catch (\Exception $exception) {
- return app('json')->fail();
- }
- }
- /**
- * @remarks 会员支付 线下
- * @author Tang
- * @created 2021/8/27 9:18
- */
- public function pay_user_annual_offline()
- {
- try {
- $oid = r::param('oid', '');
- $payType = r::param('type', '');//WX.ALI
- $pay_user_id = r::param('pay_user_id', '');//如果是微信。传open_id 如果是支付宝。传user_id
- if ($oid == '') return app('json')->fail("请检查参数是否正确");
- if ($pay_user_id == '') return app('json')->fail("请检查参数是否正确");
- $order = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
- if (!$order) return app('json')->fail('订单不存在或已支付');
- if ($order['type'] == 1) {
- $title = "开通账户";
- } elseif ($order['type'] == 2) {
- $title = "大礼包1";
- } elseif ($order['type'] == 3) {
- $title = "大礼包2";
- } elseif ($order['type'] == 4) {
- $title = "大礼包3";
- } else {
- return app('json')->fail('订单异常');
- }
- if ($order['type'] > 1) {
- //本人给养老金10%
- $ylj = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));//10%的养老金
- $commission = 0;
- //上级给佣金10%
- $order_user = Db::name("user")->where("uid", $order["uid"])->field("spread_uid")->find();
- //推广员id
- $spread_uid = $order_user["spread_uid"];
- if (!empty($spread_uid)) {
- $commission = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));//10%的佣金
- }
- $pt = sprintf("%01.2f", 12 + $ylj + $commission);
- $merchant_money = sprintf("%01.2f", $order['pay_price'] - $pt);
- } else {
- $pt = "12.00";
- $merchant_money = "0.00";
- }
- if ($payType == 'WX') {
- $pay_wx = systemConfig('pay_wx');
- //微信
- if ($pay_wx == 3) {
- $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 3)->value('member_id');
- $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
- $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
- } else {
- $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 2)->value('member_id');
- $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
- $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
- }
- $type = '2';
- $pay_channel = 'wx_pub';
- $expend = [
- 'open_id' => $pay_user_id
- ];
- } elseif ($payType == 'ALI') {
- $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 1)->value('member_id');
- $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';
- $type = '1';
- $pay_channel = 'alipay_pub';
- $expend = [
- 'buyer_id' => $pay_user_id
- ];
- $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
- }
- if ($merchant_money == '0.00') {
- $div_members = [
- [
- 'member_id' => 0,
- 'amount' => $pt,
- 'fee_flag' => 'Y'
- ]
- ];
- } else {
- $div_members = [
- [
- 'member_id' => $member_id,
- 'amount' => $merchant_money,
- 'fee_flag' => 'Y'
- ],
- [
- 'member_id' => 0,
- 'amount' => $pt,
- 'fee_flag' => 'N'
- ]
- ];
- }
- $params = [
- 'order_no' => $order['order_no'] . '_' . rand(000, 999),
- 'app_id' => $app_id,
- 'pay_channel' => $pay_channel,
- 'pay_amt' => (string)$order['pay_price'],
- 'goods_title' => "储蓄保",
- 'goods_desc' => $title,
- 'device_info' => [
- 'device_ip' => app('request')->ip()
- // 'device_ip'=>'115.171.134.68'
- ],
- 'expend' => json_encode($expend),
- 'div_members' => json_encode($div_members),
- 'fee_mode' => 'I',
- 'notify_url' => env('APP_URL') . "/api/jsapiPay/notify/HF_pay_user_annual"
- ];
- $res = $this->Payment_create_traits($params, $type, $key);
- if (!empty($res['error_code'])) {
- return app('json')->fail($res['return_msg']);
- } else {
- Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
- return app('json')->success($res);
- }
- } catch (\Exception $exception) {
- Db::name('log')->insert(['data' => '大礼包支付error:' . $exception->getFile() . ':' . $exception->getLine() . '【' . $exception->getMessage() . '】']);
- return app('json')->fail();
- }
- }
- public function red_log()
- {
- $uid = $this->request->uid();
- [$page, $limit] = $this->getPage();
- $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) {
- $item['create_time'] = date('Y-m-d H:i:s', $item['time']);
- $item['red'] = set_price_rtrim($item['red']);
- return $item;
- });
- return app('json')->success($user_rich_log);
- }
- public function apply_bang_fu()
- {
- $uid = $this->request->uid();
- $check = Db::name('user_rich')->where('uid', $uid)->find();
- if ($check['type'] < 3) {
- return app('json')->fail("不满足申请条件");
- }
- $check = Db::name('user_bangfu')->where('uid', $uid)->value('status');
- if ($check == 0) {
- return app('json')->fail("审核中");
- }
- if ($check == 1) {
- return app('json')->fail("已是帮扶中心");
- }
- if ($check == 2) {
- return app('json')->fail("审核被拒绝");
- }
- $bang_fu_number = systemConfig("bang_fu_number");
- //检测用户是否满足条件
- $number = $this->getNumber($uid, $bang_fu_number) - 1;//满足条件人数 减去自己
- //条件
- if ($number >= $bang_fu_number) {
- // echo '满足';
- Db::name('user_bangfu')->insert([
- 'uid' => $uid,
- 'time' => time(),
- 'status' => 0
- ]);
- return app('json')->success("提交申请成功");
- }
- return app('json')->fail("不满足申请条件");
- // echo '不满足';
- }
- //获得满足 1+5 的下级数量
- public function getNumber($uid, $bang_fu_number): int
- {
- $number = 0;
- $getUid = Db::name('user')->where('level_id', $uid)->field('uid')->select();
- $count = count($getUid);
- if ($count >= 5) {
- $number = 1;
- foreach ($getUid as $value) {
- $number += $this->getNumber($value['uid'], $bang_fu_number);
- if ($number >= $bang_fu_number) {
- break;
- }
- }
- }
- return $number;
- }
- /**
- * 积分明细
- * @return mixed
- */
- public function score_info()
- {
- $uid = $this->request->uid();;
- $data['score'] = decimal2(Db::name('user_sign_score')
- ->where('uid', $uid)
- ->where('status', 1)
- ->where('pm', 1)
- ->sum('reward_socre'));;
- $data['no_clear_score'] = decimal2(Db::name('user_sign_score')
- ->where('uid', $uid)
- ->where('status', -1)
- ->where('pm', 1)
- ->sum('reward_socre'));
- $data['lose_score'] = decimal2(Db::name('user_sign_score')
- ->where('uid', $uid)
- ->where('pm', 2)
- ->sum('reward_socre'));
- $data['clear_score'] = $score = decimal2($data['score'] - $data['lose_score']);
- $data['score'] = $data['clear_score'] + $data['no_clear_score'] + $data['lose_score'];
- $data['score'] = decimal2($data['score']);
- Db::name('user')->where('uid', $uid)->update([
- 'score' => $score
- ]);
- //clear_score 可用积分,score 积分总数 lose_score 已使用积分 no_clear_score 未结算积分
- return app('json')->success($data);
- }
- /**
- * 新版我的团队
- */
- public function get_team_list()
- {
- $data = [];
- [$page, $limit] = $this->getPage();
- $uid = $this->request->uid();
- $type = intval($this->request->param('type'));
- //查询团队列表
- $userRepository = app()->make(UserRepository::class);
- $chilid_userids = $userRepository->getSpreadUidBreak($uid);
- $data['fans_count'] = count($chilid_userids);
- $direct_uid_list = Db::name('user')->where('spread_uid', $uid)->where('is_del', 0)->column('uid');
- $data['direct_count'] = count($direct_uid_list);
- $valid_uid_list = Db::name('store_order')
- ->whereIn('uid', $chilid_userids)
- ->where('paid', 1)
- ->group('uid')
- ->column('uid');
- $data['valid_count'] = count($valid_uid_list);
- $data['count'] = Db::name('user')
- ->whereIn('uid', $chilid_userids)
- ->count();
- $data['list'] = Db::name('user')
- ->field('uid,phone,nickname,user_group,create_time,avatar as picture')
- ->page($page, $limit)
- ->whereIn('uid', $chilid_userids)
- ->when($type == 1, function ($query) use ($direct_uid_list) {
- return $query->whereIn('uid', $direct_uid_list);
- })
- ->when($type == 2, function ($query) use ($valid_uid_list) {
- return $query->whereIn('uid', $valid_uid_list);
- })
- ->order('uid DESC')
- ->select()
- ->toArray();
- foreach ($data['list'] as &$user) {
- $user ['phone'] = substr_replace($user['phone'], '****', 3, 4);
- }
- return app('json')->success($data);
- }
- /**
- * 我的粉丝详情
- */
- public function get_team_info()
- {
- $uid = $this->request->param('uid', '');
- if (!$uid)
- return app('json')->fail("uid不正确");
- $userRepository = app()->make(UserRepository::class);
- $chilid_userids = $userRepository->getSpreadUidBreak($this->request->uid());
- if (!in_array($uid, $chilid_userids))
- return app('json')->fail("该用户不在所属团队内");
- $data = Db::name('user')
- ->field('uid,phone,nickname,spread_uid,user_group,create_time,manage_address')
- ->where('uid', $uid)
- ->find();
- $data['regimental_commander_count'] = Db::name('user')
- ->where('spread_uid', $uid)
- ->where('user_group', 2)
- ->count();
- $data['clear_order_amount'] = Db::name('store_order')
- ->where('uid', $uid)
- ->where('is_settlement', 1)
- ->sum('pay_price');
- $data['mybuy_order_amount'] = Db::name('store_order')
- ->where('uid', $uid)
- ->where('paid', 1)
- ->sum('pay_price');
- $spread_user = Db::name('user')
- ->field('nickname as spread_nickname,phone as spread_phone')
- ->where('uid', $data['spread_uid'])
- ->find();
- $spread_user ['spread_phone'] = substr_replace($spread_user['spread_phone'], '****', 3, 4);
- $spread_user ['spread_nick_name'] = $spread_user['spread_nickname'] ?? '';
- $data ['phone'] = substr_replace($data['phone'], '****', 3, 4);
- $data = array_merge($data, $spread_user);
- if (in_array($data['user_group'], [5, 6])) {
- $data['area_name'] = Db::name('regions')->field('type,code_list')->where('id', 'in', $data['manage_address'])->cache('code:' . $data['manage_address'], 7200)->column('name');
- $data['area_name'] = join($data['area_name']);
- $data['area_bonus_money'] = Db::name('user_bill')
- ->where('uid', $uid)
- ->sum('number');
- }
- unset($data['manage_address']);
- if (in_array($data['user_group'], [4])) {
- $merchant = Db::name('merchant')->where('uid', $uid)->field('mer_id,mer_name')->find();
- $data['mer_id'] = $merchant['mer_id'] ?? 0;
- $data['mer_name'] = $merchant['mer_name'] ?? '';
- }
- return app('json')->success($data);
- }
- /**
- * 我的佣金
- */
- public function get_brokerage_info()
- {
- $uid = $this->request->uid();
- //佣金余额
- $data['brokerage_price'] = Db::name('user')->where('uid', $uid)->value('brokerage_price');
- //总收益
- $data['sum_amount'] = Db::name('user_bill')
- ->where('uid', $uid)
- ->where('commission_type', '<>', 5)
- ->where('pm', 1)
- ->sum('number');
- //未结算
- $data['no_clear_amount'] = Db::name('user_bill')
- ->where('uid', $uid)
- ->where('commission_type', '<>', 5)
- ->where('pm', 1)
- ->where('status', 0)
- ->sum('number');
- //已提现
- $data['withdraw_amount'] = Db::name('user_extract')
- ->where('uid', $uid)
- ->whereIn('status', [0, 1])
- ->sum('extract_price');
- //转VR
- $data['transition_vr_amount'] = Db::name('user_transition_vr')
- ->where('uid', $uid)
- ->where('type', 1)
- ->sum('number');
- //最终 总收益是 = 佣金余额 + 已提现 + 已转VR
- $data['sum_amount'] = $data['sum_amount'] + $data['transition_vr_amount'];
- return app('json')->success($data);
- }
- public function get_token_by_phone(UserRepository $repository){
- $user = $repository->accountByUser($this->request->param('phone'));
- $tokenInfo = $repository->createToken($user);
- return app('json')->success($repository->returnToken($user, $tokenInfo));
- }
- /**
- * 转VR
- */
- public function transition_vr()
- {
- $uid = $this->request->uid();
- $user = $this->request->userInfo();
- $type = $this->request->param('type', 'brokerage');
- $extract_amount = $this->request->param('extract_amount', 0);
- if ($type == 'brokerage') {
- $brokerage_price = Db::name('user')->where('uid', $uid)->value('brokerage_price');
- $no_clear_amount = Db::name('user_bill')
- ->where('uid', $uid)
- ->where('commission_type', '<>', 5)
- ->where('pm', 1)
- ->where('status', 0)
- ->sum('number');
- $clear_amount = $brokerage_price - $no_clear_amount;
- if ($user['brokerage_price'] < (systemConfig('withdrawal_money'))){
- return app('json')->fail('未到达提现最低额度');
- }
- if($extract_amount > $clear_amount){
- return app('json')->fail("可用金额不足提现");
- }
- $brokerage_price = bcsub($user['brokerage_price'], $extract_amount,2);
- $user->brokerage_price = $brokerage_price;
- $vr = bcadd($user['vr'], $extract_amount, 2);
- $user->vr = $vr;
- $res = $user->save();
- if ($res){
- //加入转VR记录
- $insertdata = [
- 'uid'=> $uid,
- 'number' => $extract_amount,
- 'surplus' => $vr,
- 'mark' => '佣金转VR',
- 'type' => 1,
- 'create_time' => time(),
- ];
- Db::name('user_transition_vr')->insertGetId($insertdata);
- //VR入账
- $insertdata = [
- 'uid'=> $uid,
- 'number' => $extract_amount,
- 'surplus' => $vr,
- 'mark' => '佣金转VR',
- 'order_id'=> 0,
- 'type' => 1,
- 'addtime' => time(),
- 'settlement_time'=> date('Y-m-d H:i:s', time())
- ];
- Db::name('user_sign_vr')->insertGetId($insertdata);
- return app('json')->success('转VR成功');
- }else{
- return app('json')->fail('转VR失败');
- }
- }
- if ($type == 'hongbao') {
- $hongbao = Db::name('user')->where('uid', $uid)->value('hongbao');
- $no_clear_amount = Db::name('user_sign_hongbao')
- ->where('uid', $uid)
- ->where('type', 1)
- ->where('status', -1)
- ->sum('number');
- $clear_amount = $hongbao - $no_clear_amount;
- if ($user['hongbao'] < (systemConfig('withdrawal_money'))){
- return app('json')->fail('未到达提现最低额度');
- }
- if($extract_amount > $clear_amount){
- return app('json')->fail("可用金额不足提现");
- }
- $hongbao = bcsub($user['hongbao'], $extract_amount,2);
- $user->hongbao = $hongbao;
- $vr = bcadd($user['vr'], $extract_amount, 2);
- $user->vr = $vr;
- $res = $user->save();
- if ($res){
- //加入转VR记录
- $insertdata = [
- 'uid'=> $uid,
- 'number' => $extract_amount,
- 'surplus' => $vr,
- 'mark' => '红包转VR',
- 'type' => 2,
- 'status' => -1,
- 'addtime' => time(),
- ];
- Db::name('user_sign_hongbao')->insertGetId($insertdata);
- //VR入账
- $insertdata = [
- 'uid'=> $uid,
- 'number' => $extract_amount,
- 'surplus' => $vr,
- 'mark' => '红包转VR',
- 'order_id'=> 0,
- 'type' => 1,
- 'addtime' => time(),
- 'settlement_time'=> date('Y-m-d H:i:s', time())
- ];
- Db::name('user_sign_vr')->insertGetId($insertdata);
- return app('json')->success('转VR成功');
- }else{
- return app('json')->fail('转VR失败');
- }
- }
- return app('json')->fail('转VR失败');
- }
- /**
- * 转VR记录
- */
- public function transition_vr_log()
- {
- $uid = $this->request->uid();
- $type = $this->request->param('type', 1);
- [$page, $limit] = $this->getPage();
- $where = [];
- $where[] = ['uid', '=', $uid];
- $where[] = ['type', '=', $type];
- $query = Db::name("user_transition_vr");
- $count = $query->where($where)->count();
- $list = $query->page($page, $limit)->where($where)->select()->each(function ($item){
- $item['create_time'] = date("Y-m-d H:i:s", $item['create_time']);
- return $item;
- });
- return app('json')->success('获取转VR记录成功', ['list'=>$list, 'count'=>$count]);
- }
-
-
- // 根据父级uid,递归获取所有子级UID数组
- function getRecursiveChildren($parentUid) {
- $result = []; // 用于存储所有子级的 uid
- // 定义递归函数
- $recursion = function ($parentUid) use (&$result, &$recursion) {
- // 查询当前父级的所有直接子级
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid"); // 获取子级的 uid 列表
- // 如果没有子级,直接返回
- if (empty($children)) {
- return;
- }
- // 遍历每个子级
- foreach ($children as $childUid) {
- $result[] = $childUid; // 将子级的 uid 添加到结果数组
- $recursion($childUid); // 递归查询子级的子级
- }
- };
- // 从初始父级开始递归查询
- $recursion($parentUid);
- return array_unique($result); // 返回结果数组,并去重
- }
- // 2.0 根据父级uid,找到当前用户下面的UID
- function getChildren($parentUid) {
- $result = []; // 用于存储所有子级的 uid
-
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid"); // 获取子级的 uid 列表
-
- return $children; // 返回结果数组,并去重
- }
- public function getNewTeamPv($common_nums) {
- // 初始化结果数组
- $result = [
- 'max_value' => null,
- 'max_uid' => null,
- 'remaining_values' => 0, // 剩余值的总和
- 'remaining_uids' => [] // 剩余值对应的 UID
- ];
- // 递归获取所有子级 UID 的函数
- $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid");
- $allChildren = [];
- foreach ($children as $childUid) {
- $allChildren[] = $childUid;
- $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
- }
- return $allChildren;
- };
- // 获取每个用户的总业绩,包括子级的业绩
- $userTotalPv = [];
- foreach ($common_nums as $uid) {
- // 获取当前用户及其所有子级的 UID
- $allUids = array_merge([$uid], $getRecursiveChildren($uid));
- // 查询当前用户及其子级的所有订单
- $orders = Db::name("store_order")
- ->whereIn('status', [0, 1, 2, 3])
- ->whereIn("uid", $allUids)
- ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
- ->select();
- // 计算总业绩
- $totalPv = 0;
- foreach ($orders as $order) {
- if ($order['total_price'] == 1180) {
- $totalPv += 700;
- } else if ($order['total_price'] == 11800) {
- $totalPv += 7000;
- } else if ($order['total_price'] == 10620) {
- $totalPv += 6300;
- } else if ($order['total_price'] == 2360) {
- $totalPv += 1400;
- } else if ($order['total_price'] == 9440) {
- $totalPv += 5600;
- }
- }
- // 将当前用户的总业绩和 UID 存入数组
- $userTotalPv[] = ['uid' => $uid, 'totalPv' => $totalPv];
- }
- // 如果没有符合条件的订单,直接返回空数组
- if (empty($userTotalPv)) {
- return [];
- }
- // 找到最大值及其对应的 UID
- usort($userTotalPv, function($a, $b) {
- return $b['totalPv'] <=> $a['totalPv']; // 按 totalPv 降序排序
- });
- // 获取最大值及其 UID
- $result['max_value'] = $userTotalPv[0]['totalPv'];
- $result['max_uid'] = $userTotalPv[0]['uid'];
- // 计算剩余值的总和和对应的 UID
- foreach ($userTotalPv as $index => $user) {
- if ($index > 0) { // 跳过第一个(最大值)
- $result['remaining_values'] += $user['totalPv'];
- $result['remaining_uids'][] = $user['uid'];
- }
- }
- return $result;
- }
- //只获取数组中的业绩
- public function getteampv($common_nums) {
- // 查询当前用户及其子级的所有订单
- $orders = Db::name("store_order")
- ->whereIn('status', [0, 1, 2, 3])
- ->whereIn("uid", $common_nums)
- ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
- ->select();
- // 计算总业绩
- $totalPv = 0;
- foreach ($orders as $order) {
-
- // var_dump($order['uid']."订单:".$order['total_price']);
- if ($order['total_price'] == 1180) {
- $totalPv += 700;
- } else if ($order['total_price'] == 11800) {
- $totalPv += 7000;
- } else if ($order['total_price'] == 10620) {
- $totalPv += 6300;
- } else if ($order['total_price'] == 2360) {
- $totalPv += 1400;
- } else if ($order['total_price'] == 9440) {
- $totalPv += 5600;
- }
- }
-
- return $totalPv;
- }
- // 递归获取所有子级 UID 的业绩
- public function getTeamPv11($parentUid) {
-
- $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid");
- $allChildren = [];
- foreach ($children as $childUid) {
- $allChildren[] = $childUid;
- $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
- }
- return $allChildren;
- };
- // 获取当前用户及其所有子级的 UID
- $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
- // 查询当前用户及其子级的所有订单
- $orders = Db::name("store_order")
- ->whereIn('status', [0, 1, 2, 3])
- ->whereIn("uid", $allUids)
- ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
- ->select();
- // 计算总业绩
- $totalPv = 0;
- foreach ($orders as $order) {
- switch ($order['total_price']) {
- case 1180:
- $totalPv += 700;
- break;
- case 11800:
- $totalPv += 7000;
- break;
- case 10620:
- $totalPv += 6300;
- break;
- case 2360:
- $totalPv += 1400;
- break;
- case 9440:
- $totalPv += 5600;
- break;
- }
- }
- return $totalPv;
- }
- //根据传递的父级数组,返回他的对应子级的个数
- public function getTeamSize($parentUids) {
- // 初始化结果数组
- $result = [];
- // 遍历每个父级ID
- foreach ($parentUids as $parentUid) {
- // 递归获取所有子级 UID
- $getRecursiveChildren = function ($parentUid) use (&$getRecursiveChildren) {
- $children = Db::name("user")
- ->where("spread_uid", $parentUid)
- ->column("uid");
- // 确保返回的是数组
- if (!is_array($children)) {
- return [];
- }
- $allChildren = [];
- foreach ($children as $childUid) {
- $allChildren[] = $childUid;
- $allChildren = array_merge($allChildren, $getRecursiveChildren($childUid));
- }
- return $allChildren;
- };
- // 获取当前父级及其所有子级的 UID
- $allUids = array_merge([$parentUid], $getRecursiveChildren($parentUid));
- // 计算总个数(包括父级自身)
- $totalUids = count($allUids);
- // 将结果存入数组
- $result[] = [
- 'parent_uid' => $parentUid,
- 'total_count' => $totalUids
- ];
- }
- return $result;
- }
- public function processArray($array) {
- // 初始化结果数组
- $result = [
- 'max_value' => null, // 最大值
- 'max_index' => null, // 最大值的下标
- 'remaining_sum' => 0 // 剩余值的总和
- ];
- // 检查数组是否为空
- if (empty($array)) {
- return $result;
- }
- // 找出最大值及其下标
- $maxValue = $array[0];
- $maxIndex = 0;
- for ($i = 1; $i < count($array); $i++) {
- if ($array[$i] > $maxValue) {
- $maxValue = $array[$i];
- $maxIndex = $i;
- }
- }
- // 计算剩余值的总和
- $remainingSum = 0;
- for ($i = 0; $i < count($array); $i++) {
- if ($i != $maxIndex) {
- $remainingSum += $array[$i];
- }
- }
- // 将结果存入数组
- $result['max_value'] = $maxValue;
- $result['max_index'] = $maxIndex;
- $result['remaining_sum'] = $remainingSum;
- return $result;
- }
- /**
- * 获取当前用户业绩
- */
- public function getPerformance($user_id) {
- $team_amount = 0;
- $person_amount = 0;
-
-
- $result_big_team_arr = [];
- $get_teams_comm_datas = [];//在2.0中获取父级下面的所有团队数据
- //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
- $common_nums = $this->getCommonNums($user_id);
-
- //var_dump($user_id);
- $get_teams_comm_num = 0;
- $get_teams_comm_pv = 0;
- //1.0系统中有下级,需要在2.0中再加下级数据
- if($user_id < 611){
- //梅红在2.0中的ID是780
- if($user_id == 593){
- $common_nums[] = 780;
- unset($common_nums[0]);
- }
- //var_dump($common_nums);
- //用户三峡所有在2.0系统下面的业绩和人数 start
- $child_nums = [];
- //再加上当前用户直属的子级
- $common_ns = $common_nums;
- $common_ns[] = $user_id;
- //var_dump($common_ns);return;
- //获取当前用户
- foreach($common_ns as $v){
- $child_nums[] = $this->getRecursiveChildren($v);
- }
-
- //梅红在2.0中的ID是780
- if($user_id == 593){
- $child_nums[0][] = 780;
-
- }
-
- //去除空数组,并重新组合有数据的数组
- $filteredData = array_filter($child_nums, function($array) {
- return !empty($array); // 如果数组不为空,则保留
- });
-
-
- // 合并所有非空数组
-
- foreach ($filteredData as $array) {
- $result_big_team_arr = array_merge($result_big_team_arr, $array);
- }
-
- //var_dump($result_big_team_arr);echo "ppppppppppppppppp";
- //获取当前用户下面在2.0中的下级所有PV
- $get_teams_comm_pv = $this->getteampv($result_big_team_arr);
-
- //获取当前用户下面在2.0中的下级所有人数
- $get_teams_comm_num = count($result_big_team_arr);
- //var_dump($get_teams_comm_num);
- // var_dump( $get_teams_comm_pv);
- //用户伞下小部门所有在2.0系统下面的业绩和人数 end
- }else{
-
- //当前用户在1.0没有下级,那直接在新系统2.0找下级获取数据,并区分大小部门
- $child_nums = $this->getChildren($user_id);
- //获取父级子级下面的个人
- $num_teams = $this->getTeamSize($child_nums);
- //var_dump($num_teams);
- //= $child_nums;
- // $getss = $this->processArray($get_teams_comm_datas);
- // var_dump($getss);
- // var_dump($num_teams[$getss['max_index']]);
-
- foreach($child_nums as $v){
-
- $get_teams_comm_datas[] = $this->getTeamPv11($v);//如果有多个父级ID,需要获取他们伞下的子级,所有的业绩进行
- }
-
- if( count($get_teams_comm_datas) ==1 ){
-
- $get_teams_comm_pv =$get_teams_comm_datas[0];
- $get_teams_comm_num = $num_teams[0]['total_count'];
-
- }else if(count($get_teams_comm_datas) >1){
- $getss = $this->processArray($get_teams_comm_datas);
- //var_dump($getss);
- $team_datas = $num_teams[$getss['max_index']];
- }
-
-
- }
-
- // var_dump($result_big_team_arr);
-
-
- //var_dump(count($get_teams_comm_num));
- //合并业绩和人数
- $team_amount += $get_teams_comm_pv;
-
- // var_dump($team_amount);
- //1.0获取小区业绩
- $person_nums = $this->getPersonageNums($user_id);
- //var_dump($person_nums);
- $result_small_team_arr = [];
- //1.0系统中有下级,需要在2.0中再加下级数据
-
-
-
- //用户三峡所有在2.0系统下面的业绩和人数 start
- $child_nums_mix = [];
- //再加上当前用户直属的子级
- $common_ns1 = $person_nums;
- $common_ns1[] = $user_id;
- //获取当前用户
- foreach($common_ns1 as $v){
- $child_nums_mix[] = $this->getRecursiveChildren($v);
- }
-
- //去除空数组,并重新组合有数据的数组
- $filteredData_1 = array_filter($child_nums_mix, function($array) {
- return !empty($array); // 如果数组不为空,则保留
- });
-
- // 合并所有非空数组
- $result_small_team_arr = [];
- foreach ($filteredData_1 as $array) {
- $result_small_team_arr = array_merge($result_small_team_arr, $array);
- }
-
- //获取当前用户下面在2.0中的下级所有PV
- $get_teams_per_pv = $this->getteampv($result_small_team_arr);
-
-
-
-
-
- //获取当前用户下面在2.0中的下级所有人数
- $get_teams_per_num = count($result_small_team_arr);
- //合并业绩和人数
- $person_amount += $get_teams_per_pv;
- // var_dump($person_amount);
- //用户小部门所有在2.0系统下面的业绩和人数 end
-
- // $common_nums[] = $user_id;
- foreach ($common_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $team_amount += $amount;
- }
- foreach ($person_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $person_amount += $amount;
- }
- //var_dump($team_amount);
- $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
- //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
- // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
- $money1180Sum = 0;
- foreach ($user_team_amount as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- // 获取 status 为 1 且 money 为 11800 的记录集合
- $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
- $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
- // var_dump($all_record_nums);
- $team_amount += $all_record_nums;
- // var_dump($user_team_amount);
- //计算自己的个人联盟总流水
- // // //计算自己的个人联盟总流水
- // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
- // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
- // $person_amount += $user_person_amount;
- //计算个人的1180单价的业绩 集合
- $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
- $money1180Sum = 0;
- foreach ($money1180Records as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
- //var_dump($person_nums);
- //计算个人的11800单价的业绩 集合
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
- //var_dump($person_nums);
- //计算个人的10620单价的业绩 集合
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
- $person_amount += $user_person_amount;
- //级别信息
- $userInfo = Db::name("user")->find($user_id);//
- $zk_level = 4;
- $is_zk = false;
- if($userInfo['user_level_id_old'] == $zk_level) {
- $is_zk = true;
- $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
- $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
- } else{
- $sales_incentive = 0;
- }
- $return_data = [
- 'common_nums'=>count($common_nums) + $get_teams_comm_num,
- 'person_nums'=>count($person_nums) + $get_teams_per_num,
- 'common_nums_pv'=> $team_amount,
- 'person_nums_pv'=> $person_amount,
- 'sum_nums_pv' =>$team_amount + $person_amount,
- 'sales_incentive' => $sales_incentive,
- "is_zk"=>$is_zk
- ];
- return $return_data;
- }
- /**
- * 获取当前用户业绩
- */
- public function getPerformance_copy($user_id) {
- // $user_id = $this->request->post("user_id");
- //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
- $common_nums = $this->getCommonNums($user_id);
-
-
-
- //1.0获取小区业绩
- $person_nums = $this->getPersonageNums($user_id);
- //return $person_nums;
- // var_dump( $common_nums);
- $team_amount = 0;
- $person_amount = 0;
- // $common_nums[] = $user_id;
- foreach ($common_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $team_amount += $amount;
- }
- foreach ($person_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $person_amount += $amount;
- }
- //var_dump($team_amount);
- $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
- //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
- // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
- $money1180Sum = 0;
- foreach ($user_team_amount as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- // 获取 status 为 1 且 money 为 11800 的记录集合
- $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
- $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
- // var_dump($all_record_nums);
- $team_amount += $all_record_nums;
- //计算自己的个人联盟总流水
- // // //计算自己的个人联盟总流水
- // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
- // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
- // $person_amount += $user_person_amount;
- //计算个人的1180单价的业绩 集合
- $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
- $money1180Sum = 0;
- foreach ($money1180Records as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
- //var_dump($person_nums);
- //计算个人的11800单价的业绩 集合
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
- //var_dump($person_nums);
- //计算个人的10620单价的业绩 集合
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
- $person_amount += $user_person_amount;
- //级别信息
- $userInfo = Db::name("user")->find($user_id);//
- $zk_level = 4;
- $is_zk = false;
- if($userInfo['user_level_id_old'] == $zk_level) {
- $is_zk = true;
- $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
- $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
- } else{
- $sales_incentive = 0;
- }
- $return_data = [
- 'common_nums'=>count($common_nums),
- 'person_nums'=>count($person_nums),
- 'common_nums_pv'=> $team_amount,
- 'person_nums_pv'=> $person_amount,
- 'sum_nums_pv' =>$team_amount + $person_amount,
- 'sales_incentive' => $sales_incentive,
- "is_zk"=>$is_zk
- ];
- return $return_data;
- }
- /**
- * 获取指定用户业绩
- */
- public function getPerformanceOf($user_id) {
- //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
- $common_nums = $this->getCommonNums($user_id);
- $person_nums = $this->getPersonageNums($user_id);
- $team_amount = 0;
- $person_amount = 0;
- // $common_nums[] = $user_id;
- foreach ($common_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $team_amount += $amount;
- }
- foreach ($person_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $person_amount += $amount;
- }
- // return $person_nums;
- //添加自己共建联盟的流水
- $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("spread_id",$user_id)->sum("money");
- $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
- $team_amount += $user_team_amount;
- // //计算自己的个人联盟总流水
- $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("spread_id",$user_id)->sum("money");
- $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
- $person_amount += $user_person_amount;
- $sum_nums_pv = $team_amount + $person_amount;
- $sum_nums_pv = isset($sum_nums_pv) ? $sum_nums_pv :0;
- return $sum_nums_pv;
- }
- /**
- * 获取用户星级
- */
- public function getStarLevel($user_id,$team_money=0,$person_money=0) {
- if(empty($team_money)) {
- $common_nums = $this->getCommonNums($user_id);
- $team_money = 0;
- foreach ($common_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $team_money += $amount;
- }
- //计算自己的共建联盟流水
- $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->sum("money");
- $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
- $team_money += $user_team_amount;
- }else{
- $common_nums = $this->getCommonNums($user_id);
- }
- if(empty($person_money)) {
- $person_nums = $this->getPersonageNums($user_id);
- $person_amount = 0;
- foreach ($person_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $person_amount += $amount;
- }
- $person_money = $person_amount;
- //计算自己的个人联盟总流水
- $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->sum("money");
- $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
- $person_money += $user_person_amount;
- }else{
- $person_nums = $this->getPersonageNums($user_id);
- }
- $slow = $person_money;
- if($team_money < $person_money) {
- $slow = $team_money;
- }
- $sum_money = $team_money + $person_money;
- // $data = ['sum_money'=>$sum_money,"team_money"=>$team_money,"person_money"=>$person_money];
- // $this->error(0,$data);
- $star_list = Db::name("old_user_star")->order("statement_all_num desc")->select();
- $start_level = "";
- foreach ($star_list as $key => $value) {
- # code...
- if( $sum_money>=$value['statement_all_num'] && $slow >= $value['person_statement']) {
- return $value;
- }
- }
- return $start_level;
- }
- /**
- * 获取流水信息
- */
- public function getPerformance1($user_id) {
- // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
- // $amount = isset($amount) ? round($amount*0.7,2) : 0;
- // return $amount;
- $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
- $money1180Sum = 0;
- foreach ($money1180Records as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- // var_dump($money1180Sum);
- $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
- //var_dump($person_nums);
- //计算个人的11800单价的业绩 集合
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
- //var_dump($person_nums);
- //计算个人的11800单价的业绩 集合
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
- return $user_person_amount;
- }
- /**
- * 获取个人业绩统计信息
- */
- public function getPerformanceOfId($user_id)
- {
- //var_dump($user_id);
- //联盟总人数 共建联盟人数 个人联盟人数 总流水 共建联盟流水 个人联盟流水 所属星级(钻卡专属)
- $common_nums = $this->getCommonNums($user_id);
- $person_nums = $this->getPersonageNums($user_id);
- //联盟业绩 查询 共建联盟业绩 个人联盟业绩
- $team_amount = 0;
- $person_amount = 0;
- // $common_nums[] = $user_id;
- foreach ($common_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $team_amount += $amount;
- }
- //计算自己的共建联盟流水
- //$user_team_amount = Db::name("user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
- // $this->error(0,$team_amount);
- //$user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
- $money1180Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 1180)->select();
- // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
- $money1180Sum = 0;
- foreach ($money1180Records as $record) {
- $money1180Sum += $record['money'] - 300 - 180;
- }
- // 获取 status 为 1 且 money 为 11800 的记录集合
- $money11800Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 11800)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money11800Sum = 0;
- foreach ($money11800Records as $record) {
- $money11800Sum += $record['money'] - 3000 - 1800;
- }
- // 获取 status 为 1 且 money 为 11800 的记录集合
- $money10620Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 10620)->select();
- // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
- $money10620Sum = 0;
- foreach ($money10620Records as $record) {
- $money10620Sum += $record['money'] - 2700 - 1620;
- }
- // 计算除去特定值后的总和
- $otherMoneyRecords = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->whereNotIn('money', [1180, 11800,10620])->select();
- $otherMoneySum = 0;
- foreach ($otherMoneyRecords as $record) {
- $otherMoneySum += $record['money'];
- }
- // 分别处理特定值的情况并加上其他值的总和
- $user_team_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
- $team_amount += $user_team_amount;
- foreach ($person_nums as $key => $value) {
- # code...
- $amount = $this->getPerformance1($value);
- $person_amount += $amount;
- }
- // //计算自己的个人联盟总流水
- $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
- $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
- $person_amount += $user_person_amount;
- // $this->error(0,$common_nums);
- return $team_amount + $person_amount;
- }
- /**
- * 获取该用户共建联盟
- */
- public function getCommonNums($user_id){
- //先获取共建联盟下用户的id
- $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
- $new_array_ids =[];
- foreach ($son_ids as $key => $value) {
- # code...
- $son_id = $value['id'];
- $new_array_ids = array_merge($new_array_ids,[$son_id]);
- $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
- if(count($son_value_ids) > 0) {
- $son_value_ids = array_column($son_value_ids,"id");
- $new_array_ids = array_merge($new_array_ids,$son_value_ids);
- }
- }
- return $new_array_ids;
- }
- /**
- * 获取该用户个人联盟
- */
- public function getPersonageNums($user_id){
- $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
- $new_array_ids =[];
- // return 3343;
- foreach ($son_ids as $key => $value) {
- # code...
- $son_id = $value['id'];
- $new_array_ids = array_merge($new_array_ids,[$son_id]);
- $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
- if(count($son_value_ids) > 0) {
- $son_value_ids = array_column($son_value_ids,"id");
- $new_array_ids = array_merge($new_array_ids,$son_value_ids);
- }
- }
- return $new_array_ids;
- }
- //获取团队递归聚宝盆1
- public function teamPeople( $user_id,$type){
- //var_dump($type);
- //$ftype = 1:大部门,0:小部门
- //业绩小是小部门,业绩大是大部门
- if($type == 1) {
- $list = Db::name("old_user_jbp")
- ->where("spread", $user_id)
- ->where("is_team", 1)
- ->field("user_name, id")
- ->select()
- ->toArray();
- $list = $this->get_yj_amount($list,1);
- $list1 = Db::name("old_user_jbp")
- ->where("spread", $user_id)
- ->where("is_team", 0)
- ->field("user_name, id")
- ->select()
- ->toArray();
- $list1 = $this->get_yj_amount($list1, 0);
- // 检查数组和字段是否存在
- if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
- // 如果$list的值小于或等于$list1的值,选择$list
- if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
- return $list1;
- } else {
- return $list;
- }
- } elseif (isset($list[0]['performance']['common_nums_pv'])) {
- // 如果只有$list有值,返回$list
- return $list;
- } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
- // 如果只有$list1有值,返回$list1
- return $list1;
- } else {
- // 如果两个数组都没有该字段,返回空数组
- return [];
- }
- }else if($type == 0) {
- $list = Db::name("old_user_jbp")
- ->where("spread", $user_id)
- ->where("is_team", 1)
- ->field("user_name, id")
- ->select()
- ->toArray();
- $list = $this->get_yj_amount($list,1);
- $list1 = Db::name("old_user_jbp")
- ->where("spread", $user_id)
- ->where("is_team", 0)
- ->field("user_name, id")
- ->select()
- ->toArray();
- $list1 = $this->get_yj_amount($list1, 0);
- // 检查数组和字段是否存在
- if (isset($list[0]['performance']['common_nums_pv']) && isset($list1[0]['performance']['common_nums_pv'])) {
- // 如果$list的值小于或等于$list1的值,选择$list
- if ($list[0]['performance']['common_nums_pv'] <= $list1[0]['performance']['common_nums_pv']) {
- return $list;
- } else {
- return $list1;
- }
- } elseif (isset($list[0]['performance']['common_nums_pv'])) {
- // 如果只有$list有值,返回$list
- return $list;
- } elseif (isset($list1[0]['performance']['common_nums_pv'])) {
- // 如果只有$list1有值,返回$list1
- return $list1;
- } else {
- // 如果两个数组都没有该字段,返回空数组
- return [];
- }
- }else if($type == 2){
- $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid,avatar")->select()->toArray();
- return $list;
- }
- // foreach ($list as $key => $value) {
- // $list[$key]['user_name'] = $value['user_name'] . "业绩";
- // $list[$key]['performance'] = $this->getPerformance($value['id']);
- // //辨别当前是大部门还是小部门。用于显示大小业绩展示
- // $list[$key]['curr_type'] = '';
- // if($type == 1){
- // $list[$key]['curr_type'] = 1;
- // }else if($type == 0){
- // $list[$key]['curr_type'] = 0;
- // }else{
- // $list[$key]['curr_type'] = '';
- // }
- // }
- return $list;
- }
- public function get_yj_amount($list,$type){
- foreach ($list as $key => $value) {
- # code...
- // $amount = $this->getPerformanceOfId($value['id']);
- $list[$key]['user_name'] = $value['user_name'] . "业绩";
- //$list[$key]['total_performance'] = $amount;
- //$performance = $this->getPerformanceOfId($search_name['id']);
- $list[$key]['performance'] = $this->getPerformance($value['id']);
- //辨别当前是大部门还是小部门。用于显示大小业绩展示
- $list[$key]['curr_type'] = '';
- if($type == 1){
- $list[$key]['curr_type'] = 1;
- }else if($type == 0){
- $list[$key]['curr_type'] = 0;
- }else{
- $list[$key]['curr_type'] = '';
- }
- }
- return $list;
- }
- //获取团队递归聚宝盆1
- public function teamPeople_copy( $user_id,$type){
- //var_dump($type);
- //$ftype = 1:大部门,0:小部门
- //$user_id = $this->request->post("user_id");
- //$type = $this->request->post("type",0);
- //查找当前用户id下节点
- if($type == 1) {
- // echo 33;
- $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
- }else if($type == 0) {
- // echo 44;
- $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
- }else if($type == 2){
- $list = Db::name("user")->where("spread_uid",$user_id)->field("nickname,uid")->select()->toArray();
- return $list;
- }else {
- // echo 55;
- $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
- }
- foreach ($list as $key => $value) {
- # code...
- // $amount = $this->getPerformanceOfId($value['id']);
- $list[$key]['user_name'] = $value['user_name'] . "业绩";
- //$list[$key]['total_performance'] = $amount;
- //$performance = $this->getPerformanceOfId($search_name['id']);
- $list[$key]['performance'] = $this->getPerformance($value['id']);
- //辨别当前是大部门还是小部门。用于显示大小业绩展示
- $list[$key]['curr_type'] = '';
- if($type == 1){
- $list[$key]['curr_type'] = 1;
- }else if($type == 0){
- $list[$key]['curr_type'] = 0;
- }else{
- $list[$key]['curr_type'] = '';
- }
- }
- return $list;
- }
- // //获取团队递归聚宝盆1
- // public function teamPeople( $user_id,$type){
- // //$user_id = $this->request->post("user_id");
- // //$type = $this->request->post("type",0);
- // //查找当前用户id下节点
- // if($type == 1) {
- // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
- // }else if($type == 2) {
- // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
- // }else {
- // $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
- // }
- // foreach ($list as $key => $value) {
- // # code...
- // $amount = $this->getPerformanceOfId($value['id']);
- // $list[$key]['user_name'] = $value['user_name'] . "-----业绩" . $amount;
- // }
- // return $list;
- // }
- }
|