User.php 151 KB

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