User.php 153 KB

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