User.php 152 KB

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