User.php 151 KB

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