User.php 174 KB

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