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