User.php 151 KB

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