User.php 151 KB

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