User.php 132 KB

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