User.php 152 KB

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