User.php 151 KB

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