User.php 149 KB

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