User.php 151 KB

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