User.php 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035
  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. $uid = $this->request->uid();
  989. //$foteam = $this->request->param('foteam', 0);
  990. $teamid = $this->request->param('teamid');//测试ID
  991. $type = $this->request->param('type',2);//1:大部门,0:小部门
  992. // if($type == null){
  993. // $type == 2;
  994. // }
  995. //getPerformance
  996. $team_userinfo_old_jbp1= $this->getPerformance($teamid);
  997. $tes = $this->teamPeople($teamid,$type);//1:团队,2:个人
  998. $data1= [
  999. "total"=>100,
  1000. "per_page"=> 10,
  1001. "current_page"=> 1,
  1002. "last_page"=> 1,
  1003. ];
  1004. // if(!empty($teamid)){
  1005. foreach($tes as $k=>$v){
  1006. $data1['data'][$k] = [
  1007. "uid"=>$v["id"],
  1008. "nickname"=> $v['user_name'],
  1009. "phone"=> "137****3315",
  1010. "avatar"=>"https://cdn.bjtdba.com/vod/image/2025-01-20/20250120125206881.png",
  1011. "create_time"=>"2025-01-25 11:00:18",
  1012. "identity"=>"11",
  1013. "level"=> "40002",
  1014. "partnership"=>"22",
  1015. "total_performance"=>$v['total_performance'],//$v["performance"]['sum_nums_pv'],//总业绩
  1016. "new_performance"=> 0,//新增业绩
  1017. "team_count"=> $v["performance"]['common_nums'] + $v["performance"]['person_nums'],//团购人数
  1018. ];
  1019. }
  1020. $data['team_list'] = $data1;
  1021. $data['fans_num'] = $team_userinfo_old_jbp1['person_nums'] + $team_userinfo_old_jbp1['common_nums'] ;//粉丝数
  1022. $data['new_performance'] = 0;//新增业绩
  1023. $data['total_performance']= $team_userinfo_old_jbp1['sum_nums_pv'];//总业绩
  1024. $data['person_nums'] = $team_userinfo_old_jbp1['person_nums'];//个人联盟
  1025. $data['common_nums'] = $team_userinfo_old_jbp1['common_nums'];//共建联盟
  1026. $data['common_nums_pv'] = $team_userinfo_old_jbp1['common_nums_pv'];//公共联盟PV
  1027. $data['person_nums_pv'] = $team_userinfo_old_jbp1['person_nums_pv'];//个人联盟PV
  1028. // $data['effective_fans_num'] = DB::name('enterprise_user')
  1029. // }else{
  1030. // $data['fans_num'] =0 ;//粉丝数
  1031. // $data['new_performance'] = 0;//新增业绩
  1032. // $data['total_performance']= 0;//总业绩
  1033. // }
  1034. return app("json")->success($data);
  1035. }
  1036. /**
  1037. * 一壶茶-团队列表
  1038. */
  1039. public function team_list_copy()
  1040. {
  1041. $uid = $this->request->uid();
  1042. $where['puid'] = $uid;
  1043. $where['mer_id'] = $this->merId;
  1044. $data['direct_fans_num'] = Db::name('enterprise_user')->where($where)->count();//直属粉丝数量
  1045. //var_dump($uid);
  1046. $arr = $this->jisuan_fans($uid);
  1047. $data['fans_num'] = count($arr);//粉丝总数
  1048. $data['total_performance'] = 12555;//总业绩
  1049. $data['new_performance'] = 15;//新增业绩
  1050. [$page, $limit] = $this->getPage();
  1051. $where2['eu.mer_id'] = $this->merId;
  1052. $type = $this->request->param('type', 0);//1:大部门,0:小部门
  1053. // var_dump($where2);
  1054. $enterprise_user_team = DB::name('enterprise_user')
  1055. ->alias('eu')
  1056. ->join('user u', 'eu.uid=u.uid')
  1057. ->where($where2)
  1058. ->when($type < 1 || $type == 2, function ($q) use ($arr) {
  1059. $q->whereIn('eu.uid', $arr);
  1060. })
  1061. ->when($type == 1, function ($q) use ($uid) {
  1062. $q->whereIn('eu.puid', $uid);
  1063. })
  1064. ->when($type == 2, function ($q) use ($uid) {
  1065. $q->whereIn('eu.identity', [100, 101, 102, 103, 104, 105]);
  1066. })
  1067. ->field('eu.uid,u.nickname,u.phone,eu.avatar,eu.create_time,eu.identity,eu.level,eu.partnership')
  1068. ->order('eu.enterprise_user_id desc')
  1069. ->paginate($limit)
  1070. ->each(function ($item) {
  1071. $item['phone'] = substr_replace($item['phone'], '****', 3, 4);
  1072. return $item;
  1073. });
  1074. //var_dump($enterprise_user_team);
  1075. $data['team_list'] = $enterprise_user_team;
  1076. $data['effective_fans_num'] = DB::name('enterprise_user')
  1077. ->alias('eu')
  1078. ->join('user u', 'eu.uid=u.uid')
  1079. ->where($where2)
  1080. ->whereIn('eu.uid', $arr)
  1081. ->whereIn('eu.identity', [100, 101, 102, 103, 104, 105])
  1082. ->count();//有效粉丝数量
  1083. return app("json")->success($data);
  1084. }
  1085. public function team_details()
  1086. {
  1087. $uid = $this->request->param('uid', 0);
  1088. $where2['eu.uid'] = $uid;
  1089. $where2['eu.mer_id'] = $this->merId;
  1090. $enterprise_user_team = DB::name('enterprise_user')
  1091. ->alias('eu')
  1092. ->join('user u', 'eu.uid=u.uid')
  1093. ->where($where2)
  1094. ->field('eu.uid,u.nickname,u.phone,u.avatar,eu.create_time,eu.identity,eu.level,eu.partnership,eu.puid')
  1095. ->find();;
  1096. if ($enterprise_user_team) {
  1097. $enterprise_user_team['phone'] = substr_replace($enterprise_user_team['phone'], '****', 3, 4);
  1098. $enterprise_user_team['p_nickname'] = '';
  1099. $enterprise_user_team['p_phone'] = '';
  1100. $yanglao = 0;
  1101. $offLinewhere = ['mer_id' => $this->merId, 'uid' => $uid, 'commission_type' => '5', 'type_shop' => 0];
  1102. $offLine1 = Db::name('user_bill')->where($offLinewhere)->where('source', 1)->where('status', 1)->sum('number');
  1103. $yanglao += $offLine1;
  1104. $offLine2 = Db::name('user_bill')->where($offLinewhere)->where('source', 0)->whereIn('status', [0, 1])->sum('number');
  1105. $yanglao += $offLine2;
  1106. $enterprise_user_team['ylj'] = set_price_rtrim($yanglao);
  1107. if ($enterprise_user_team['puid'] > 0) {
  1108. $user = Db::name('user')->where('uid', $enterprise_user_team['puid'])->find();
  1109. if ($user) {
  1110. $enterprise_user_team['p_nickname'] = $user['nickname'];
  1111. $enterprise_user_team['p_phone'] = substr_replace($user['phone'], '****', 3, 4);
  1112. }
  1113. }
  1114. }
  1115. return app("json")->success($enterprise_user_team);
  1116. }
  1117. /**
  1118. * 率积分明细
  1119. */
  1120. public function green_integral_list()
  1121. {
  1122. $pm = $this->request->param('pm');
  1123. $status = $this->request->param('status');
  1124. [$page, $limit] = $this->getPage();
  1125. $uid = $this->request->uid();
  1126. log::info("green_integral_list==={$uid}");
  1127. $where['uid'] = $uid;
  1128. // $where['mer_id'] = $this->merId;
  1129. // if ($pm == 1) {
  1130. // $pm_arr = [1, 3];
  1131. // } else {
  1132. // $pm_arr = [2, 4];
  1133. // }
  1134. if ($pm==0){
  1135. $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();
  1136. }
  1137. if($pm==1){
  1138. $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();
  1139. }
  1140. if($pm==2){
  1141. $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();
  1142. }
  1143. log::info("=======date==={$data}");
  1144. return app("json")->success($data);
  1145. }
  1146. public function user_invite_profit_list()
  1147. {
  1148. $uid = $this->request->uid();
  1149. [$page, $limit] = $this->getPage();
  1150. $commission_type = $this->request->param('commission_type', 0);
  1151. if ($commission_type) {
  1152. $where['commission_type'] = $commission_type;
  1153. }
  1154. $month = $this->request->param('month', '') ?: date('Y-m');
  1155. $startMonth = date('Y-m-01 00:00:00', strtotime($month));
  1156. $endMonth = date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month)));
  1157. $data['yanglao_clear_all'] = Db::name('user_bill')
  1158. ->where('uid', $uid)
  1159. ->whereBetween('create_time', [$startMonth, $endMonth])
  1160. ->where('commission_type', 5)
  1161. ->where('pm', 1)
  1162. ->where('status', 1)
  1163. ->sum('number');
  1164. $data['yanglao_nclear_all'] = Db::name('user_bill')
  1165. ->where('uid', $uid)
  1166. ->whereBetween('create_time', [$startMonth, $endMonth])
  1167. ->where('commission_type', 5)
  1168. ->where('pm', 1)
  1169. ->where('status', 0)
  1170. ->sum('number');
  1171. $data['yanglao_yugu_all'] = $data['yanglao_clear_all'] + $data['yanglao_nclear_all'];
  1172. $where['uid'] = $uid;
  1173. $data['totel_money'] = Db::name('user_bill')->where($where)
  1174. ->whereNotIn('commission_type', [5, 7, 17, 19])
  1175. ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
  1176. $query->whereBetween('create_time', [$startMonth, $endMonth]);
  1177. }, function ($query) use ($where, $month, $startMonth, $endMonth) {
  1178. $query->where('commission_type', '<>', 5)
  1179. ->whereBetween('create_time', [$startMonth, $endMonth]);
  1180. })
  1181. ->sum('number');
  1182. $pageInfo = Db::name('user_bill')
  1183. ->where($where)
  1184. ->whereNotIn('commission_type', [5, 7, 17, 19])
  1185. ->when($commission_type == 5, function ($query) use ($where, $startMonth, $endMonth) {
  1186. $query->whereBetween('create_time', [$startMonth, $endMonth]);
  1187. }, function ($query) use ($where, $month, $startMonth, $endMonth) {
  1188. $query->where('commission_type', '<>', 5)
  1189. ->whereBetween('create_time', [$startMonth, $endMonth]);
  1190. })
  1191. ->order('bill_id desc')
  1192. ->paginate($limit);
  1193. $data_arr = [];
  1194. foreach ($pageInfo->items() as $k => $v) {
  1195. $v['money'] = set_price_rtrim($v['number']);
  1196. $v['order_money'] = set_price_rtrim(0);
  1197. $v['commission_rate'] = set_price_rtrim(0);
  1198. $order = Db::name('store_order')->where('order_sn', $v['order_sn'])->find();
  1199. if (!empty($order)) {
  1200. $v['order_money'] = set_price_rtrim($order['total_price']);
  1201. $v['commission_rate'] = set_price_rtrim(bcdiv($v['money'], $v['order_money'], 2));
  1202. }
  1203. if ($v['status'] == 0) {
  1204. // $v['create_time'] = '--';
  1205. }
  1206. if ($v['status'] == 1) {
  1207. // $v['create_time'] = $v['take_time'];
  1208. }
  1209. $data_arr[] = $v;
  1210. }
  1211. $data['pageInfo']['current_page'] = $pageInfo->currentPage();
  1212. $data['pageInfo']['data'] = $data_arr;
  1213. $data['pageInfo']['last_page'] = $pageInfo->lastPage();
  1214. return app("json")->success($data);
  1215. }
  1216. /*导航转链-用于用户下单绑定*/
  1217. public function changeLink()
  1218. {
  1219. $uid = $this->request->uid();
  1220. if (!$uid) {
  1221. return app("json")->error("请登录");
  1222. }
  1223. $data = $data = $this->request->params([
  1224. 'url',
  1225. 'name'
  1226. ]);
  1227. $data['url'] = urldecode($data['url']);
  1228. $data['name'] = urldecode($data['name']);
  1229. if (in_array($data['name'], ['京东', '苏宁易购', '饿了么', '唯品会', '拼多多'])) {
  1230. if ($data['name'] == '京东') {
  1231. $url = app()->make(Jd::class)->linkChange($data['url'], $uid);
  1232. }
  1233. if ($data['name'] == '拼多多') {
  1234. $url = app()->make(TaoKe::class)->changeLink($data['url'], $uid);
  1235. }
  1236. if ($data['name'] == '唯品会') {
  1237. $url = app()->make(Vip::class)->changeLink($data['url'], $uid);
  1238. }
  1239. if ($data['name'] == '苏宁易购') {
  1240. $url = $data['url'];
  1241. //$url = app()->make(Su::class)->changeLink($data['url'],$uid);
  1242. }
  1243. if ($data['name'] == '饿了么') {//获取饿了么官方活动链接
  1244. //如果用户没有拉取relation_id,
  1245. $where = ['uid' => $uid, 'type' => 5];
  1246. $isRelation = UserThirdModel::where($where)->find();
  1247. if ($isRelation) {
  1248. $result = DaTaoKe::activityChangeLink('20150318020002597', $uid);
  1249. if ($result['code'] == 0) {
  1250. return \app('json')->fail("获取饿了么链接出错", $result['raw']);
  1251. }
  1252. $url = $result['link'];
  1253. } else {//如果还没有获取用户的relation_id还需要拉淘宝授权
  1254. $state = "{$uid}_h5";
  1255. $url = \app()->make(TaoBao::class)->getAuthUrl($state);
  1256. }
  1257. }
  1258. }
  1259. return app("json")->success($url);
  1260. }
  1261. /*获取协议*/
  1262. public function xieyi()
  1263. {
  1264. $data = $this->request->params([
  1265. 'type'
  1266. ]);
  1267. $data = app()->make(\app\common\repositories\agreement\AgreementRepository::class)->getTypeDetail($data['type']);
  1268. return app("json")->success($data);
  1269. }
  1270. /**
  1271. * 支付宝获取授权
  1272. * @return mixed
  1273. * @author php迷途小书童
  1274. * @created 2021/1/16 17:03
  1275. */
  1276. public function alipayAuthorization(UserRepository $userRepository)
  1277. {
  1278. $authorization_code = $this->request->param('code');
  1279. $type = $this->request->param('type', 'h5');
  1280. $paramStr = $userRepository->getTokenByCode($authorization_code, false, $type);
  1281. return app("json")->success($paramStr);
  1282. }
  1283. /**
  1284. * 微信获取授权
  1285. * @return mixed
  1286. * @author php迷途小书童
  1287. * @created 2021/1/16 19:08
  1288. */
  1289. public function wechatAuthorization()
  1290. {
  1291. $request = $this->request;
  1292. $wxConfig = [
  1293. "appid" => "wx66f5f8def2b755da",
  1294. "appsecret" => "891572d83222105a635cf9f502363ff8"
  1295. ];
  1296. $oauth = WechatService::create()->getApplication()->oauth;
  1297. // dump($oauth);
  1298. $oauth->setRequest(new Request($request->get(), $request->post(), [], [], [], $request->server(), $request->getContent()));
  1299. try {
  1300. $wechatInfo = $oauth->user()->getOriginal();
  1301. } catch (\Exception $e) {
  1302. return app('json')->fail('授权失败[001]', ['message' => $e->getMessage()]);
  1303. }
  1304. if (!isset($wechatInfo['nickname'])) {
  1305. return app('json')->fail('授权失败[002]');
  1306. }
  1307. return app("json")->success($wechatInfo);
  1308. }
  1309. /**
  1310. * 更新绑定微信支付宝账号
  1311. * type=1 微信 2 支付宝
  1312. * openid openid
  1313. */
  1314. public function updateAccount(UserRepository $userRepository)
  1315. {
  1316. $type = $this->request->param('type');
  1317. $openid = $this->request->param('openid');//前端传的是unionid
  1318. $nickname = $this->request->param('nickname');
  1319. $avater = $this->request->param('avater');
  1320. $alinfo = $this->request->param('alinfo');
  1321. $uid = $this->request->uid();
  1322. $user = $this->request->userInfo();
  1323. if (!$type) {
  1324. return app("json")->fail("失败");
  1325. }
  1326. makeLock()->lock();
  1327. try {
  1328. if ($type == 1) {
  1329. $data = ["wechat_user_id" => $openid];
  1330. $unionId = $openid;
  1331. $check = Db::name('user_extract_openid')->where('uid',$uid)->value('openid');
  1332. if ($check) throw new \Exception("此微信号已被绑定");
  1333. } else {
  1334. $alinfo = json_decode($alinfo, true);
  1335. if (!$alinfo) throw new \Exception("参数异常");
  1336. $data = ["ali_user_id" => $alinfo["userId"]];
  1337. $unionId = $alinfo["userId"];
  1338. $check = Db::name("user")->where("ali_user_id", $unionId)->find();
  1339. if ($check) throw new \Exception("此支付宝号已被绑定");
  1340. $paramStr = $userRepository->getTokenByCode($alinfo["authCode"], true);
  1341. // \think\facade\Db::name('log')->insert(['data'=>'支付宝授权信息'.json_encode($paramStr)]);
  1342. $nickname = empty($paramStr["nick_name"]) ? "al" . $alinfo["userId"] : $paramStr["nick_name"];
  1343. $avater = empty($paramStr["avatar"]) ? "http://app.bjtdba.com/uploads/def/20201118/5984361a2e00f5407776bcd6eaaae1ce.png" : $paramStr["avatar"];
  1344. }
  1345. $data2 = [
  1346. "type" => $type,
  1347. "uid" => $uid,
  1348. "nickname" => $nickname,
  1349. "avater" => $avater,
  1350. ];
  1351. $result = $this->repository->updateUser($uid, $data, $data2);
  1352. if (!$result) throw new \Exception("修改失败");
  1353. $userRepository = app()->make(UserRepository::class);
  1354. $userInfo = $userRepository->getOne(['uid' => $uid]);
  1355. //绑定线下充值金额
  1356. $unionUsersRepository = app()->make(UnionUsersRepository::class);
  1357. $orderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1358. $notBind = $unionUsersRepository->getAllNotBind($unionId);
  1359. if ($notBind) {
  1360. $orderMerchantRepository->doBindUser($userInfo, $type);
  1361. }
  1362. } catch (\Throwable $e) {
  1363. makeLock()->unlock();
  1364. return app("json")->fail("失败" . $e->getMessage());
  1365. }
  1366. makeLock()->unlock();
  1367. return app("json")->success("修改成功", $data);
  1368. }
  1369. /**
  1370. * 获取账号绑定信息
  1371. * @return mixed
  1372. */
  1373. public function getAccount()
  1374. {
  1375. $uid = $this->request->uid();
  1376. // $data = $this->repository->getUser($uid, "wechat_user_id,ali_user_id");
  1377. $data = $this->repository->getAccount($uid);
  1378. if ($data) {
  1379. return app("json")->success("查询成功", $data);
  1380. }
  1381. return app("json")->fail("未绑定");
  1382. }
  1383. // /*
  1384. // * 养老金统计
  1385. // * */
  1386. // public function get_yanglao_statistics()
  1387. // {
  1388. // $uid = $this->request->uid();
  1389. // //线下数量
  1390. // // 查询未结算
  1391. //
  1392. // $gzc_order_list = Db::name('gzc_logs')->where('uid', $uid)->column('out_trade_no');
  1393. //
  1394. // $onlineYanglaoUserBill = Db::name('user_bill')->where('commission_type', 5)->whereNotIn('order_sn',$gzc_order_list)->where('status', 0)->where('uid', $uid)->sum('number');
  1395. // $onlineYanglaoGzc = Db::name('gzc_logs')->where('success', 0)->where('uid', $uid)->sum('pension');
  1396. // $clearYanglao = Db::name('gzc_logs')->where('success', 1)->where('uid', $uid)->sum('pension');
  1397. //
  1398. // $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
  1399. // $res = GzcApiRequest::checkAmount($userInfo);
  1400. // $gzc = $res['extendData']['amount'] * 0.01;
  1401. // // PCPC-中信公证处
  1402. // $data['all_gzc'] = set_price_rtrim(sprintf("%01.2f", $gzc));
  1403. // // 总养老金
  1404. // $data['all_yanglao'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao + $gzc);
  1405. // // 平台养老金
  1406. // $data['all_yanglao_yhc'] = set_price_rtrim($onlineYanglaoUserBill + $onlineYanglaoGzc + $clearYanglao);
  1407. // // 未结算养老金=预估养老金,不能包含进入公证处未成功的记录(这部分是已结算的)
  1408. // $data['all_yanglao_yugu'] = set_price_rtrim(round($onlineYanglaoUserBill, 2));
  1409. // // 已结算养老金 已入账
  1410. // $data['all_yanglao_clear'] = set_price_rtrim(round($onlineYanglaoGzc+$clearYanglao, 2));
  1411. // // 已入账养老金
  1412. // $data['all_yanglao_in'] = set_price_rtrim(round($clearYanglao, 2));
  1413. // // 平台未入账养老金
  1414. // $data['all_yanglao_nclear'] = set_price_rtrim(round($onlineYanglaoGzc + $onlineYanglaoUserBill, 2));
  1415. // // 待发起
  1416. // $data['all_yanglao_wait'] = set_price_rtrim(round($onlineYanglaoGzc, 2));
  1417. //
  1418. // return app("json")->success("查询成功", $data);
  1419. // }
  1420. /*
  1421. * 养老金统计
  1422. * */
  1423. public function get_yanglao_statistics()
  1424. {
  1425. $uid = $this->request->uid();
  1426. //线下数量
  1427. $offLine = \think\facade\Db::name('order_merchant')->where('uid', $uid)->where('status', 1)->field('pension yanglao')->select()->toArray();
  1428. $data['offLine'] = array(
  1429. 'num' => count($offLine),
  1430. 'yanglao' => round($this->num($offLine, 'yanglao'), 2)
  1431. );
  1432. $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>1,'type_shop'=>0];
  1433. if($this->source=='yhc' && $this->merId){
  1434. $offLinewhere['mer_id']=$this->merId;
  1435. }
  1436. $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
  1437. $data['offLine'] = array(
  1438. 'num' => count($offLine),
  1439. 'yanglao' => round($this->num($offLine, 'number'), 2)
  1440. );
  1441. // $offLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
  1442. // $offLine= \think\facade\Db::name('user_bill')->where($offLinewhere)->select()->toArray();
  1443. // $data['offLine'] = array(
  1444. // 'num' => count($offLine),
  1445. // 'yanglao' => round($this->num($offLine, 'number'), 2)
  1446. // );
  1447. //线上已确认收货
  1448. // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '2,3')->select()
  1449. // ->each(function ($item) {
  1450. // //查询养老金金额
  1451. // $UserBillRepository = app()->make(UserBillRepository::class);
  1452. // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
  1453. // $pension = $bill->number ?? 0;
  1454. // $item['yanglao'] = $pension;
  1455. // return $item;
  1456. // })
  1457. // ->toArray();
  1458. $onLinewhere=['uid'=>$uid,'status'=>'1','commission_type' => '5','source'=>0,'type_shop'=>0];
  1459. if($this->source=='yhc' && $this->merId){
  1460. $onLinewhere['mer_id']=$this->merId;
  1461. }
  1462. $onLine= \think\facade\Db::name('user_bill')->where($onLinewhere)->select()->toArray();
  1463. $data['onLine'] = array(
  1464. 'num' => count($onLine),
  1465. 'yanglao' => round($this->num($onLine, 'number'), 2)
  1466. );
  1467. //线上未确认收货
  1468. // $onLine = \think\facade\Db::name('store_order')->where('uid', $uid)->where('paid', 1)->where('status', 'in', '0,1')->select()
  1469. // ->each(function ($item) {
  1470. // //查询养老金金额
  1471. // $UserBillRepository = app()->make(UserBillRepository::class);
  1472. // $bill = $UserBillRepository->getWhere(['uid' => $item['uid'], 'link_id' => $item['order_id'], 'order_sn' => $item['order_sn'], 'title' => '养老金']);
  1473. // $pension = $bill->number ?? 0;
  1474. // $item['yanglao'] = $pension;
  1475. // return $item;
  1476. // })
  1477. // ->toArray();
  1478. $onLine_take_nowhere=['uid'=>$uid,'status'=>'0','commission_type' => '5','source'=>0,'type_shop'=>0];
  1479. if($this->source=='yhc' && $this->merId){
  1480. $onLine_take_nowhere['mer_id']=$this->merId;
  1481. }
  1482. $onLine_take_no=\think\facade\Db::name('user_bill')->where($onLine_take_nowhere)->select()->toArray();
  1483. $data['onLine_take_no'] = array(
  1484. 'num' => count($onLine_take_no),
  1485. 'yanglao' => round($this->num($onLine_take_no, 'number'), 2)
  1486. );
  1487. if($this->source=='yhc' && $this->merId){
  1488. $data['all_num'] = $data['offLine']['num'] +$data['onLine_take_no']['num'] + $data['onLine']['num'];
  1489. $data['all_yanglao_yhc'] = set_price_rtrim(round($data['offLine']['yanglao']+$data['onLine']['yanglao'] + $data['onLine_take_no']['yanglao'] , 2));//总养老金
  1490. $data['all_yanglao_a'] = set_price_rtrim(round($data['offLine']['yanglao'] + $data['onLine']['yanglao'], 2));//已结算养老金
  1491. $data['all_yanglao_yugu'] = set_price_rtrim(round($data['all_yanglao_yhc']-$data['all_yanglao_a'],2));//预估养老金
  1492. $userInfo = Db::name('UserCertification') -> where('uid',$uid) -> field('user_name,user_card') -> find();
  1493. $res = GzcApiRequest::checkAmount($userInfo);
  1494. $data['all_gzc']=set_price_rtrim(sprintf("%01.2f", $res['extendData']['amount'] * 0.01));
  1495. $data['all_yanglao']=set_price_rtrim( $data['all_yanglao_yhc'] + $data['all_gzc']);
  1496. return app("json")->success("查询成功", $data);
  1497. }
  1498. //淘宝
  1499. $tb_a = 0;
  1500. $tb_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>5];
  1501. $tb = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($tb_where)->where('status','<>','-1')->select()->each(function ($value) use (&$tb_a) {
  1502. $value['yanglao'] = 0;
  1503. $value['yanglao'] = $value['number'];
  1504. $value['yanglao_a'] = 0;
  1505. if ($value['status'] == 1) {
  1506. $value['yanglao_a'] = $value['yanglao'];
  1507. $tb_a++;
  1508. }
  1509. return $value;
  1510. })->toArray();
  1511. $data['tb'] = array(
  1512. 'num' => count($tb),
  1513. 'num_a' => $tb_a,
  1514. 'yanglao' => round($this->num($tb, 'yanglao'), 2),
  1515. 'yanglao_a' => round($this->num($tb, 'yanglao_a'), 2),
  1516. );
  1517. //京东
  1518. $jd_a = 0;
  1519. $jd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>6];
  1520. $jd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($jd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$jd_a) {
  1521. $value['yanglao'] = 0;
  1522. $value['yanglao'] = $value['number'];
  1523. $value['yanglao_a'] = 0;
  1524. if ($value['status'] == 1) {
  1525. $value['yanglao_a'] = $value['yanglao'];
  1526. $jd_a++;
  1527. }
  1528. return $value;
  1529. })->toArray();
  1530. $data['jd'] = array(
  1531. 'num' => count($jd),
  1532. 'num_a' => $jd_a,
  1533. 'yanglao' => round($this->num($jd, 'yanglao'), 2),
  1534. 'yanglao_a' => round($this->num($jd, 'yanglao_a'), 2),
  1535. );
  1536. //苏宁
  1537. $su_a = 0;
  1538. $su_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>3];
  1539. $su = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($su_where)->where('status','<>','-1')->select()->each(function ($value) use (&$su_a) {
  1540. $value['yanglao'] = 0;
  1541. $value['yanglao'] = $value['number'];
  1542. $value['yanglao_a'] = 0;
  1543. if ($value['status'] == 1) {
  1544. $value['yanglao_a'] = $value['yanglao'];
  1545. $su_a++;
  1546. }
  1547. return $value;
  1548. })->toArray();
  1549. $data['su'] = array(
  1550. 'num' => count($su),
  1551. 'num_a' => $su_a,
  1552. 'yanglao' => round($this->num($su, 'yanglao'), 2),
  1553. 'yanglao_a' => round($this->num($su, 'yanglao_a'), 2),
  1554. );
  1555. //拼多多
  1556. $pdd_a = 0;
  1557. $pdd_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>1];
  1558. $pdd = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($pdd_where)->where('status','<>','-1')->select()->each(function ($value) use (&$pdd_a) {
  1559. $value['yanglao'] = 0;
  1560. $value['yanglao'] = $value['number'];
  1561. $value['yanglao_a'] = 0;
  1562. if ($value['status'] == 1) {
  1563. $value['yanglao_a'] = $value['yanglao'];
  1564. $pdd_a++;
  1565. }
  1566. return $value;
  1567. })->toArray();
  1568. $data['pdd'] = array(
  1569. 'num' => count($pdd),
  1570. 'num_a' => $pdd_a,
  1571. 'yanglao' => round($this->num($pdd, 'yanglao'), 2),
  1572. 'yanglao_a' => round($this->num($pdd, 'yanglao_a'), 2),
  1573. );
  1574. //唯品会
  1575. $vip_a = 0;
  1576. $vip_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>2];
  1577. $vip = \think\facade\Db::name('user_bill')->where($vip_where)->where('uid', $uid)->where('status','<>','-1')->select()->each(function ($value) use (&$vip_a) {
  1578. $value['yanglao'] = 0;
  1579. $value['yanglao'] = $value['number'];
  1580. $value['yanglao_a'] = 0;
  1581. if ($value['status'] == 1) {
  1582. $value['yanglao_a'] = $value['yanglao'];
  1583. $vip_a++;
  1584. }
  1585. return $value;
  1586. })->toArray();
  1587. $data['vip'] = array(
  1588. 'num' => count($vip),
  1589. 'num_a' => $vip_a,
  1590. 'yanglao' => round($this->num($vip, 'yanglao'), 2),
  1591. 'yanglao_a' => round($this->num($vip, 'yanglao_a'), 2),
  1592. );
  1593. // 抖音
  1594. $dy_a = 0;
  1595. $dy_where=['uid'=>$uid,'commission_type' => '5','source'=>0,'type_shop'=>9];
  1596. $dy = \think\facade\Db::name('user_bill')->where('uid', $uid)->where($dy_where)->where('status','<>','-1')->select()->each(function ($value) use (&$dy_a) {
  1597. $value['yanglao'] = 0;
  1598. $value['yanglao'] = $value['number'];
  1599. $value['yanglao_a'] = 0;
  1600. if ($value['status'] == 1) {
  1601. $value['yanglao_a'] = $value['yanglao'];
  1602. $dy_a++;
  1603. }
  1604. return $value;
  1605. })->toArray();
  1606. $data['dy'] = array(
  1607. 'num' => count($dy),
  1608. 'num_a' => $dy_a,
  1609. 'yanglao' => round($this->num($dy, 'yanglao'), 2),
  1610. 'yanglao_a' => round($this->num($dy, 'yanglao_a'), 2),
  1611. );
  1612. $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'];
  1613. $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);
  1614. $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);
  1615. $data['third_party_num']=['all_num'=>$data['tb']['num']+$data['jd']['num']+$data['su']['num']+ $data['pdd']['num'] + $data['vip']['num']+ $data['dy']['num']];
  1616. $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']];
  1617. $data['third_party_num_n']=['all_num_n'=>$data['third_party_num']['all_num']-$data['third_party_num_a']['all_num_a']];
  1618. return app("json")->success("查询成功", $data);
  1619. }
  1620. public function num($data, $field)
  1621. {
  1622. $sum = 0;
  1623. foreach ($data as $item) {
  1624. $sum += $item[$field];
  1625. }
  1626. return $sum;
  1627. }
  1628. //志愿者升级
  1629. public function changeVolunteer()
  1630. {
  1631. $uid = $this->request->uid();
  1632. //志愿者条件
  1633. $volunteer_achievement = systemConfig("volunteer_achievement");//volunteer_achievement:用户本人满足养老金要求可升级为志愿者
  1634. $volunteer_class = new Volunteer();
  1635. $volunteer = $volunteer_class->volunteer($uid);
  1636. if ($volunteer['self_yanglao'] < $volunteer_achievement) {
  1637. $data['grade'] = 0;
  1638. $data['self_yanglao'] = $volunteer['self_yanglao'];
  1639. $data['condition_one'] = systemConfig("volunteer_achievement");//用户本人满足养老金要求可升级为志愿者
  1640. return app('json')->success($data);
  1641. }
  1642. $volunteer_class->grade($uid, 1, $volunteer);
  1643. return app('json')->success('申请成功');
  1644. }
  1645. public function GZC($uid)
  1646. {
  1647. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1648. $orderId = $OrderMerchantRepository->getNewOrderId('IN10');
  1649. $OrderGzcRepository = app()->make(OrderGzcRepository::class);
  1650. $where = [
  1651. 'uid' => $uid,
  1652. 'pm' => 1,
  1653. 'status' => 1,
  1654. 'type' => 'commission'
  1655. ];
  1656. $user_data = \think\facade\Db::name('user')->where('uid', $uid)->find();
  1657. $certification = ['user_name' => $user_data['real_name'], 'mobile' => $user_data['account'], 'user_card' => $user_data['card_id']];
  1658. $user_data['real_name'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_name');
  1659. $user_data['account'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('mobile');
  1660. $user_data['card_id'] = Db::name('user_certification')->where('status', 1)->where('uid', $user_data['uid'])->value('user_card');
  1661. Db::name('user_bill')->where($where)->select()->each(function ($item) use ($uid, $orderId, $OrderGzcRepository, $user_data, $certification) {
  1662. $is_implement = 1;
  1663. if ($item['source'] == 0) {
  1664. $order_data = \think\facade\Db::name('store_order')->where('order_sn', $item['order_sn'])->value('uid');
  1665. if ($order_data['uid'] == $item['uid']) {
  1666. $is_implement = 0;
  1667. } else {
  1668. $is_implement = 1;
  1669. }
  1670. } else {
  1671. $order_data = \think\facade\Db::name('order_merchant')->where('out_trade_no', $item['order_sn'])->value('uid');
  1672. if ($order_data['uid'] == $item['uid']) {
  1673. $is_implement = 0;
  1674. } else {
  1675. $is_implement = 1;
  1676. }
  1677. }
  1678. if ($is_implement == 1) {
  1679. $online = ['uid' => $uid, 'pay_type' => '1', 'order_sn' => $item['order_sn'], 'order_id' => $item['link_id']];
  1680. $create = [
  1681. 'uid' => $online['uid'],
  1682. 'platform_no' => $orderId,
  1683. 'account_type' => $online['pay_type'] == 1 ? 3 : 2,
  1684. 'user_name' => $certification['user_name'],
  1685. 'mobile' => $certification['mobile'],
  1686. 'user_card' => $certification['user_card'],
  1687. 'pension' => $item['number'],
  1688. 'order_type' => 2,
  1689. 'out_trade_no' => $online['order_sn']
  1690. ];
  1691. $OrderGzcRepository->create($create);
  1692. }
  1693. });
  1694. }
  1695. //20220712版签到
  1696. public function new_sign()
  1697. {
  1698. // return app('json')->fail('不允许签到');
  1699. $uid = $this->request->uid();//签到用户
  1700. $user = Db::name('user')->where('uid', $uid)->field("spread_uid,first_sign")->find();//上级用户
  1701. //前6天积分
  1702. $score = [
  1703. 2,//1
  1704. 4,//2
  1705. 6,//3
  1706. 10,//4
  1707. 14,//5
  1708. 20//6
  1709. ];
  1710. //7-30天积分
  1711. $scoreS = 3;
  1712. //额外积分
  1713. $scoreExtra = [
  1714. 7 => 38,
  1715. 14 => 68,
  1716. 21 => 128,
  1717. 30 => 188
  1718. ];
  1719. $today_signintime = strtotime(date('Y-m-d', time()));
  1720. $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
  1721. if (!empty($today_signin_info)) {
  1722. return app('json')->fail('今天已经签到过了');
  1723. } else {
  1724. //查询昨天是否已经签到了
  1725. $yes_signintime = strtotime(date('Y-m-d')) - 86400;
  1726. $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
  1727. $has_qian = 1;
  1728. if (!empty($yes_signin_info)) {
  1729. $has_qian = $yes_signin_info['continuity_day'] + 1;
  1730. $has_qian = $has_qian > 30 ? 1 : $has_qian;
  1731. }
  1732. if ($has_qian <= 6) {
  1733. $get_score = $score[$has_qian - 1];
  1734. } else {
  1735. $get_score = $scoreS;
  1736. if (isset($scoreExtra[$has_qian])) {
  1737. $get_score = $scoreS + $scoreExtra[$has_qian];
  1738. }
  1739. }
  1740. $userRepository = app()->make(UserRepository::class);
  1741. $userRepository->sign_add($uid, $get_score, 1, '签到赠送积分', $has_qian, $today_signintime, '');
  1742. //首次签到
  1743. if ($user['first_sign'] == 0) {
  1744. Db::name('user')->where('uid', $uid)->update(['first_sign' => 1]);
  1745. } elseif ($user['first_sign'] == 1 && $has_qian == 1) {
  1746. Db::name('user')->where('uid', $uid)->update(['first_sign' => 2]);
  1747. }
  1748. //非首次签到,第一天,断签
  1749. //好友连续签到3天 奖励50
  1750. //好友连续签到14天 奖励100
  1751. //好友联系签到30天 奖励300
  1752. if ($user['first_sign'] < 2) {
  1753. if ($has_qian == 3) {
  1754. $userRepository->sign_add($user['spread_uid'], 50, 1, '好友签到赠送积分', '', $today_signintime, '');
  1755. } elseif ($has_qian == 14) {
  1756. $userRepository->sign_add($user['spread_uid'], 100, 1, '好友签到赠送积分', '', $today_signintime, '');
  1757. } elseif ($has_qian == 30) {
  1758. $userRepository->sign_add($user['spread_uid'], 300, 1, '好友签到赠送积分', '', $today_signintime, '');
  1759. Db::name('user')->where('uid', $uid)->update(['first_sign' => 3]);
  1760. }
  1761. }
  1762. return app('json')->success('签到成功', ['score' => $get_score]);
  1763. }
  1764. }
  1765. public function new_sign_info()
  1766. {
  1767. $uid = $this->request->uid();
  1768. //查询今天是否已经签到
  1769. $today_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid))->whereDay('signin_time')->find();
  1770. //查询昨天是否已经签到了
  1771. $yes_signintime = strtotime(date('Y-m-d')) - 86400;
  1772. $yes_signin_info = Db::name('user_sign_score')->where(array('uid' => $uid, 'signin_time' => $yes_signintime))->find();
  1773. $data = [
  1774. 'today' => 0,
  1775. 'day' => 0
  1776. ];
  1777. if ($yes_signin_info) $data['day'] = (int)$yes_signin_info['continuity_day'];
  1778. if ($yes_signin_info['continuity_day'] >= 30) $data['day'] = 0;
  1779. if ($today_signin_info) {
  1780. $data['today'] = 1;
  1781. $data['day'] = $data['day'] + 1;
  1782. }
  1783. return app('json')->success($data);
  1784. }
  1785. /**
  1786. * 积分列表
  1787. * @return mixed
  1788. * @throws \think\db\exception\DataNotFoundException
  1789. * @throws \think\db\exception\DbException
  1790. * @throws \think\db\exception\ModelNotFoundException
  1791. */
  1792. public function sign_list()
  1793. {
  1794. [$page, $limit] = $this->getPage();
  1795. $uid = $this->request->uid();
  1796. $month = $this->request->param('month', '') ?: date('Y-m');
  1797. $status = $this->request->param('status');
  1798. $pm = $this->request->param('pm');
  1799. $startMonth = strtotime(date('Y-m-01 00:00:00', strtotime($month)));
  1800. $endMonth = strtotime(date("Y-m-d 00:00:00", strtotime("first day of next month", strtotime($month))));
  1801. $count = Db::name('user_sign_score')
  1802. ->whereBetween('addtime', [$startMonth, $endMonth])
  1803. ->when(isset($status) && $status !== '', function ($query) use ($status) {
  1804. $query->where('status', $status);
  1805. })
  1806. ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
  1807. $query->where('pm', $pm);
  1808. })
  1809. ->where('uid', $uid)->count();
  1810. $list = Db::name('user_sign_score')
  1811. ->whereBetween('addtime', [$startMonth, $endMonth])
  1812. ->where('uid', $uid)
  1813. ->when(isset($status) && $status !== '', function ($query) use ($status) {
  1814. $query->where('status', $status);
  1815. })
  1816. ->when(isset($pm) && $pm !== '', function ($query) use ($pm) {
  1817. $query->where('pm', $pm);
  1818. })
  1819. ->page($page, $limit)->order('id DESC')->select()->each(function ($item) {
  1820. $item['signin_time'] = date('Y-m-d', $item['signin_time']);
  1821. $item['addtime'] = date('Y-m-d H:i:s', $item['addtime']);
  1822. if (!empty($item['order_id'])) {
  1823. //线上订单
  1824. if ($item['order_type'] == 'store_order' || $item['order_type'] == 'store_order_beishengtang') {
  1825. $item['order_sn'] = Db::name("store_order")->where("order_id", $item['order_id'])->value("order_sn");
  1826. } elseif ($item['order_type'] == 'order_merchant') {
  1827. $item['order_sn'] = Db::name("order_merchant")->where("id", $item['order_id'])->value("out_trade_no");
  1828. } elseif ($item['order_type'] == 'extract') {
  1829. $item['order_sn'] = Db::name("user_extract")->where("extract_id", $item['order_id'])->value("order_sn");
  1830. } else {
  1831. $item['order_sn'] = '';
  1832. }
  1833. } else {
  1834. $item['order_sn'] = '';
  1835. }
  1836. return $item;
  1837. });
  1838. $data['list'] = $list;
  1839. $data['count'] = $count;
  1840. return app('json')->success($data);
  1841. }
  1842. public function getAmountFromGzc()
  1843. {
  1844. $uid = $this->request->uid();
  1845. $userInfo = Db::name('UserCertification')->where('uid', $uid)->field('user_name,user_card')->find();
  1846. $res = GzcApiRequest::checkAmount($userInfo);
  1847. return app('json')->success(['amount' => sprintf("%01.2f", $res['extendData']['amount'] * 0.01)]);
  1848. }
  1849. public function check_user_annual_fee()
  1850. {
  1851. //INSERT INTO rrx_user_pension_account (uid) SELECT uid FROM rrx_user;
  1852. //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;
  1853. $uid = $this->request->uid();
  1854. $check = Db::name("user_pension_account")->where("uid", $uid)->find();
  1855. $data = [
  1856. "status" => 3,//0:未交年费,1:年费到期。2:未实名认证,3:正常
  1857. ];
  1858. // //未交年费
  1859. // if (!$check || $check["status"] == 0) {
  1860. // $data["status"] = 0;
  1861. // return app('json')->success($data);
  1862. // }
  1863. // //到期时间小于当前时间。年费到期
  1864. // if (strtotime($check['end_time']) < time()){
  1865. // $data["status"] = 1;
  1866. // return app('json')->success($data);
  1867. // }
  1868. // $data["start_time"] = $check['start_time'];
  1869. // $data["end_time"] = $check['end_time'];
  1870. //
  1871. // //检查实名认证
  1872. // $checkCertification = Db::name("user_certification") -> where("uid",$uid) -> find();
  1873. // if (!$checkCertification){
  1874. // $data["status"] = 2;
  1875. // return app('json')->success($data);
  1876. // }
  1877. return app('json')->success($data);
  1878. }
  1879. /**
  1880. *
  1881. * @remarks 创建年费订单
  1882. * @author 小菜菜
  1883. * @created 2023/04/10 14:37
  1884. */
  1885. public function create_annual_order()
  1886. {
  1887. $uid = $this->request->uid();
  1888. $type = $this->request->param('type', 1);
  1889. $OrderMerchantRepository = app()->make(OrderMerchantRepository::class);
  1890. if ($type == 1) $price = "12.00";
  1891. elseif ($type == 2) $price = systemConfig('offline_a');
  1892. elseif ($type == 3) $price = systemConfig('offline_b');
  1893. elseif ($type == 4) $price = systemConfig('offline_c');
  1894. else return app('json')->fail("参数错误");
  1895. $check = Db::name("user_pension_account")->where("uid", $uid)->find();
  1896. //到期时间小于当前时间。年费到期
  1897. if (strtotime($check['end_time']) > time() && $check['status'] == 1) {
  1898. return app('json')->fail("账户已开通,不可重复开通账户");
  1899. }
  1900. $insertData = [
  1901. 'pay_price' => $price,
  1902. 'status' => 0,
  1903. 'order_no' => $OrderMerchantRepository->getNewOrderId("mt"),
  1904. 'uid' => $uid,
  1905. 'type' => $type,
  1906. ];
  1907. $order_id = Db::name('user_pension_account_order')->insertGetId($insertData);
  1908. try {
  1909. return app('json')->success(['order_id' => $order_id]);
  1910. } catch (\Exception $e) {
  1911. return app('json')->status('error', $e->getMessage(), ['order_id' => $order_id]);
  1912. }
  1913. }
  1914. /**
  1915. * @remarks 会员支付
  1916. * @author Tang
  1917. * @created 2021/8/27 9:18
  1918. */
  1919. public function pay_user_annual()
  1920. {
  1921. try {
  1922. $oid = r::param('oid', '');
  1923. $code = r::param('code', '');
  1924. $payType = r::param('type', '');//wx.ALI
  1925. if ($oid == '') return app('json')->fail("请检查参数是否正确");
  1926. $groupOrder = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
  1927. if (!$groupOrder) return app('json')->fail('订单不存在或已支付');
  1928. $access = new Access();
  1929. $res = $access->pay_huifu($payType, $code, $groupOrder, "年费", env('APP_URL') . "/api/hf_notify/pay_user_annual");
  1930. Db::name('log')->insert(['data' => '汇付用户年费支付---' . json_encode($res)]);
  1931. Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
  1932. return app('json')->success($res);
  1933. } catch (\Exception $exception) {
  1934. return app('json')->fail();
  1935. }
  1936. }
  1937. /**
  1938. * @remarks 会员支付 线下
  1939. * @author Tang
  1940. * @created 2021/8/27 9:18
  1941. */
  1942. public function pay_user_annual_offline()
  1943. {
  1944. try {
  1945. $oid = r::param('oid', '');
  1946. $payType = r::param('type', '');//WX.ALI
  1947. $pay_user_id = r::param('pay_user_id', '');//如果是微信。传open_id 如果是支付宝。传user_id
  1948. if ($oid == '') return app('json')->fail("请检查参数是否正确");
  1949. if ($pay_user_id == '') return app('json')->fail("请检查参数是否正确");
  1950. $order = Db::name('user_pension_account_order')->where('id', $oid)->where('status', 0)->find();
  1951. if (!$order) return app('json')->fail('订单不存在或已支付');
  1952. if ($order['type'] == 1) {
  1953. $title = "开通账户";
  1954. } elseif ($order['type'] == 2) {
  1955. $title = "大礼包1";
  1956. } elseif ($order['type'] == 3) {
  1957. $title = "大礼包2";
  1958. } elseif ($order['type'] == 4) {
  1959. $title = "大礼包3";
  1960. } else {
  1961. return app('json')->fail('订单异常');
  1962. }
  1963. if ($order['type'] > 1) {
  1964. //本人给养老金10%
  1965. $ylj = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));//10%的养老金
  1966. $commission = 0;
  1967. //上级给佣金10%
  1968. $order_user = Db::name("user")->where("uid", $order["uid"])->field("spread_uid")->find();
  1969. //推广员id
  1970. $spread_uid = $order_user["spread_uid"];
  1971. if (!empty($spread_uid)) {
  1972. $commission = sprintf("%01.2f", bcmul($order['pay_price'], '0.1', 5));//10%的佣金
  1973. }
  1974. $pt = sprintf("%01.2f", 12 + $ylj + $commission);
  1975. $merchant_money = sprintf("%01.2f", $order['pay_price'] - $pt);
  1976. } else {
  1977. $pt = "12.00";
  1978. $merchant_money = "0.00";
  1979. }
  1980. if ($payType == 'WX') {
  1981. $pay_wx = systemConfig('pay_wx');
  1982. //微信
  1983. if ($pay_wx == 3) {
  1984. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 3)->value('member_id');
  1985. $key = 'api_live_b0a687ec-5450-4ada-a0e4-65bac0f46871';
  1986. $app_id = 'app_383a75dd-c03d-44ab-8f58-92c60fe9b9d0';
  1987. } else {
  1988. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 2)->value('member_id');
  1989. $key = 'api_live_90ef02e4-54ac-41ee-adf1-e4927d23d58f';
  1990. $app_id = 'app_0827b960-b932-45ec-b800-4e850091b419';
  1991. }
  1992. $type = '2';
  1993. $pay_channel = 'wx_pub';
  1994. $expend = [
  1995. 'open_id' => $pay_user_id
  1996. ];
  1997. } elseif ($payType == 'ALI') {
  1998. $member_id = Db::name('merchant_member')->where('mer_id', 429)->where("type", 1)->value('member_id');
  1999. $app_id = 'app_44108546-d27a-48ee-88c1-84b45b75114f';
  2000. $type = '1';
  2001. $pay_channel = 'alipay_pub';
  2002. $expend = [
  2003. 'buyer_id' => $pay_user_id
  2004. ];
  2005. $key = 'api_live_b23537ed-64b8-45d6-832e-fb228aa9e0a9';
  2006. }
  2007. if ($merchant_money == '0.00') {
  2008. $div_members = [
  2009. [
  2010. 'member_id' => 0,
  2011. 'amount' => $pt,
  2012. 'fee_flag' => 'Y'
  2013. ]
  2014. ];
  2015. } else {
  2016. $div_members = [
  2017. [
  2018. 'member_id' => $member_id,
  2019. 'amount' => $merchant_money,
  2020. 'fee_flag' => 'Y'
  2021. ],
  2022. [
  2023. 'member_id' => 0,
  2024. 'amount' => $pt,
  2025. 'fee_flag' => 'N'
  2026. ]
  2027. ];
  2028. }
  2029. $params = [
  2030. 'order_no' => $order['order_no'] . '_' . rand(000, 999),
  2031. 'app_id' => $app_id,
  2032. 'pay_channel' => $pay_channel,
  2033. 'pay_amt' => (string)$order['pay_price'],
  2034. 'goods_title' => "储蓄保",
  2035. 'goods_desc' => $title,
  2036. 'device_info' => [
  2037. 'device_ip' => app('request')->ip()
  2038. // 'device_ip'=>'115.171.134.68'
  2039. ],
  2040. 'expend' => json_encode($expend),
  2041. 'div_members' => json_encode($div_members),
  2042. 'fee_mode' => 'I',
  2043. 'notify_url' => env('APP_URL') . "/api/jsapiPay/notify/HF_pay_user_annual"
  2044. ];
  2045. $res = $this->Payment_create_traits($params, $type, $key);
  2046. if (!empty($res['error_code'])) {
  2047. return app('json')->fail($res['return_msg']);
  2048. } else {
  2049. Db::name('user_pension_account_order')->where('id', $oid)->update(['hf_pay_id' => $res['id']]);
  2050. return app('json')->success($res);
  2051. }
  2052. } catch (\Exception $exception) {
  2053. Db::name('log')->insert(['data' => '大礼包支付error:' . $exception->getFile() . ':' . $exception->getLine() . '【' . $exception->getMessage() . '】']);
  2054. return app('json')->fail();
  2055. }
  2056. }
  2057. public function red_log()
  2058. {
  2059. $uid = $this->request->uid();
  2060. [$page, $limit] = $this->getPage();
  2061. $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) {
  2062. $item['create_time'] = date('Y-m-d H:i:s', $item['time']);
  2063. $item['red'] = set_price_rtrim($item['red']);
  2064. return $item;
  2065. });
  2066. return app('json')->success($user_rich_log);
  2067. }
  2068. public function apply_bang_fu()
  2069. {
  2070. $uid = $this->request->uid();
  2071. $check = Db::name('user_rich')->where('uid', $uid)->find();
  2072. if ($check['type'] < 3) {
  2073. return app('json')->fail("不满足申请条件");
  2074. }
  2075. $check = Db::name('user_bangfu')->where('uid', $uid)->value('status');
  2076. if ($check == 0) {
  2077. return app('json')->fail("审核中");
  2078. }
  2079. if ($check == 1) {
  2080. return app('json')->fail("已是帮扶中心");
  2081. }
  2082. if ($check == 2) {
  2083. return app('json')->fail("审核被拒绝");
  2084. }
  2085. $bang_fu_number = systemConfig("bang_fu_number");
  2086. //检测用户是否满足条件
  2087. $number = $this->getNumber($uid, $bang_fu_number) - 1;//满足条件人数 减去自己
  2088. //条件
  2089. if ($number >= $bang_fu_number) {
  2090. // echo '满足';
  2091. Db::name('user_bangfu')->insert([
  2092. 'uid' => $uid,
  2093. 'time' => time(),
  2094. 'status' => 0
  2095. ]);
  2096. return app('json')->success("提交申请成功");
  2097. }
  2098. return app('json')->fail("不满足申请条件");
  2099. // echo '不满足';
  2100. }
  2101. //获得满足 1+5 的下级数量
  2102. public function getNumber($uid, $bang_fu_number): int
  2103. {
  2104. $number = 0;
  2105. $getUid = Db::name('user')->where('level_id', $uid)->field('uid')->select();
  2106. $count = count($getUid);
  2107. if ($count >= 5) {
  2108. $number = 1;
  2109. foreach ($getUid as $value) {
  2110. $number += $this->getNumber($value['uid'], $bang_fu_number);
  2111. if ($number >= $bang_fu_number) {
  2112. break;
  2113. }
  2114. }
  2115. }
  2116. return $number;
  2117. }
  2118. /**
  2119. * 积分明细
  2120. * @return mixed
  2121. */
  2122. public function score_info()
  2123. {
  2124. $uid = $this->request->uid();;
  2125. $data['score'] = decimal2(Db::name('user_sign_score')
  2126. ->where('uid', $uid)
  2127. ->where('status', 1)
  2128. ->where('pm', 1)
  2129. ->sum('reward_socre'));;
  2130. $data['no_clear_score'] = decimal2(Db::name('user_sign_score')
  2131. ->where('uid', $uid)
  2132. ->where('status', -1)
  2133. ->where('pm', 1)
  2134. ->sum('reward_socre'));
  2135. $data['lose_score'] = decimal2(Db::name('user_sign_score')
  2136. ->where('uid', $uid)
  2137. ->where('pm', 2)
  2138. ->sum('reward_socre'));
  2139. $data['clear_score'] = $score = decimal2($data['score'] - $data['lose_score']);
  2140. $data['score'] = $data['clear_score'] + $data['no_clear_score'] + $data['lose_score'];
  2141. $data['score'] = decimal2($data['score']);
  2142. Db::name('user')->where('uid', $uid)->update([
  2143. 'score' => $score
  2144. ]);
  2145. //clear_score 可用积分,score 积分总数 lose_score 已使用积分 no_clear_score 未结算积分
  2146. return app('json')->success($data);
  2147. }
  2148. /**
  2149. * 新版我的团队
  2150. */
  2151. public function get_team_list()
  2152. {
  2153. $data = [];
  2154. [$page, $limit] = $this->getPage();
  2155. $uid = $this->request->uid();
  2156. $type = intval($this->request->param('type'));
  2157. //查询团队列表
  2158. $userRepository = app()->make(UserRepository::class);
  2159. $chilid_userids = $userRepository->getSpreadUidBreak($uid);
  2160. $data['fans_count'] = count($chilid_userids);
  2161. $direct_uid_list = Db::name('user')->where('spread_uid', $uid)->where('is_del', 0)->column('uid');
  2162. $data['direct_count'] = count($direct_uid_list);
  2163. $valid_uid_list = Db::name('store_order')
  2164. ->whereIn('uid', $chilid_userids)
  2165. ->where('paid', 1)
  2166. ->group('uid')
  2167. ->column('uid');
  2168. $data['valid_count'] = count($valid_uid_list);
  2169. $data['count'] = Db::name('user')
  2170. ->whereIn('uid', $chilid_userids)
  2171. ->count();
  2172. $data['list'] = Db::name('user')
  2173. ->field('uid,phone,nickname,user_group,create_time,avatar as picture')
  2174. ->page($page, $limit)
  2175. ->whereIn('uid', $chilid_userids)
  2176. ->when($type == 1, function ($query) use ($direct_uid_list) {
  2177. return $query->whereIn('uid', $direct_uid_list);
  2178. })
  2179. ->when($type == 2, function ($query) use ($valid_uid_list) {
  2180. return $query->whereIn('uid', $valid_uid_list);
  2181. })
  2182. ->order('uid DESC')
  2183. ->select()
  2184. ->toArray();
  2185. foreach ($data['list'] as &$user) {
  2186. $user ['phone'] = substr_replace($user['phone'], '****', 3, 4);
  2187. }
  2188. return app('json')->success($data);
  2189. }
  2190. /**
  2191. * 我的粉丝详情
  2192. */
  2193. public function get_team_info()
  2194. {
  2195. $uid = $this->request->param('uid', '');
  2196. if (!$uid)
  2197. return app('json')->fail("uid不正确");
  2198. $userRepository = app()->make(UserRepository::class);
  2199. $chilid_userids = $userRepository->getSpreadUidBreak($this->request->uid());
  2200. if (!in_array($uid, $chilid_userids))
  2201. return app('json')->fail("该用户不在所属团队内");
  2202. $data = Db::name('user')
  2203. ->field('uid,phone,nickname,spread_uid,user_group,create_time,manage_address')
  2204. ->where('uid', $uid)
  2205. ->find();
  2206. $data['regimental_commander_count'] = Db::name('user')
  2207. ->where('spread_uid', $uid)
  2208. ->where('user_group', 2)
  2209. ->count();
  2210. $data['clear_order_amount'] = Db::name('store_order')
  2211. ->where('uid', $uid)
  2212. ->where('is_settlement', 1)
  2213. ->sum('pay_price');
  2214. $data['mybuy_order_amount'] = Db::name('store_order')
  2215. ->where('uid', $uid)
  2216. ->where('paid', 1)
  2217. ->sum('pay_price');
  2218. $spread_user = Db::name('user')
  2219. ->field('nickname as spread_nickname,phone as spread_phone')
  2220. ->where('uid', $data['spread_uid'])
  2221. ->find();
  2222. $spread_user ['spread_phone'] = substr_replace($spread_user['spread_phone'], '****', 3, 4);
  2223. $spread_user ['spread_nick_name'] = $spread_user['spread_nickname'] ?? '';
  2224. $data ['phone'] = substr_replace($data['phone'], '****', 3, 4);
  2225. $data = array_merge($data, $spread_user);
  2226. if (in_array($data['user_group'], [5, 6])) {
  2227. $data['area_name'] = Db::name('regions')->field('type,code_list')->where('id', 'in', $data['manage_address'])->cache('code:' . $data['manage_address'], 7200)->column('name');
  2228. $data['area_name'] = join($data['area_name']);
  2229. $data['area_bonus_money'] = Db::name('user_bill')
  2230. ->where('uid', $uid)
  2231. ->sum('number');
  2232. }
  2233. unset($data['manage_address']);
  2234. if (in_array($data['user_group'], [4])) {
  2235. $merchant = Db::name('merchant')->where('uid', $uid)->field('mer_id,mer_name')->find();
  2236. $data['mer_id'] = $merchant['mer_id'] ?? 0;
  2237. $data['mer_name'] = $merchant['mer_name'] ?? '';
  2238. }
  2239. return app('json')->success($data);
  2240. }
  2241. /**
  2242. * 我的佣金
  2243. */
  2244. public function get_brokerage_info()
  2245. {
  2246. $uid = $this->request->uid();
  2247. $data['brokerage_price'] = Db::name('user')->where('uid', $uid)->value('brokerage_price');
  2248. $data['sum_amount'] = Db::name('user_bill')
  2249. ->where('uid', $uid)
  2250. ->where('commission_type', '<>', 5)
  2251. ->where('pm', 1)
  2252. ->sum('number');
  2253. $data['no_clear_amount'] = Db::name('user_bill')
  2254. ->where('uid', $uid)
  2255. ->where('commission_type', '<>', 5)
  2256. ->where('pm', 1)
  2257. ->where('status', 0)
  2258. ->sum('number');
  2259. $data['withdraw_amount'] = Db::name('user_extract')
  2260. ->where('uid', $uid)
  2261. ->whereIn('status', [0, 1])
  2262. ->sum('extract_price');
  2263. return app('json')->success($data);
  2264. }
  2265. public function get_token_by_phone(UserRepository $repository){
  2266. $user = $repository->accountByUser($this->request->param('phone'));
  2267. $tokenInfo = $repository->createToken($user);
  2268. return app('json')->success($repository->returnToken($user, $tokenInfo));
  2269. }
  2270. /**
  2271. * 获取当前用户业绩
  2272. */
  2273. public function getPerformance($user_id) {
  2274. // $user_id = $this->request->post("user_id");
  2275. //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  2276. $common_nums = $this->getCommonNums($user_id);
  2277. $person_nums = $this->getPersonageNums($user_id);
  2278. //return $person_nums;
  2279. // var_dump( $common_nums);
  2280. $team_amount = 0;
  2281. $person_amount = 0;
  2282. // $common_nums[] = $user_id;
  2283. foreach ($common_nums as $key => $value) {
  2284. # code...
  2285. $amount = $this->getPerformance1($value);
  2286. $team_amount += $amount;
  2287. }
  2288. foreach ($person_nums as $key => $value) {
  2289. # code...
  2290. $amount = $this->getPerformance1($value);
  2291. $person_amount += $amount;
  2292. }
  2293. //var_dump($team_amount);
  2294. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 1180)->select();
  2295. //$money1180Records = $this->old_user_of_goods->where('status', 1)->where('money', 1180)->select();
  2296. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  2297. $money1180Sum = 0;
  2298. foreach ($user_team_amount as $record) {
  2299. $money1180Sum += $record['money'] - 300 - 180;
  2300. }
  2301. // 获取 status 为 1 且 money 为 11800 的记录集合
  2302. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 11800)->select();
  2303. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  2304. $money11800Sum = 0;
  2305. foreach ($money11800Records as $record) {
  2306. $money11800Sum += $record['money'] - 3000 - 1800;
  2307. }
  2308. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where('money', 10620)->select();
  2309. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  2310. $money10620Sum = 0;
  2311. foreach ($money10620Records as $record) {
  2312. $money10620Sum += $record['money'] - 2700 - 1620;
  2313. }
  2314. // 计算除去特定值后的总和
  2315. //$otherMoneyRecords = $this->old_user_of_goods->where('status', 1)->whereNotIn('money', [1180, 11800])->select();
  2316. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  2317. $otherMoneySum = 0;
  2318. foreach ($otherMoneyRecords as $record) {
  2319. $otherMoneySum += $record['money'];
  2320. }
  2321. // 分别处理特定值的情况并加上其他值的总和
  2322. $all_record_nums = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  2323. // var_dump($all_record_nums);
  2324. $team_amount += $all_record_nums;
  2325. //计算自己的个人联盟总流水
  2326. // // //计算自己的个人联盟总流水
  2327. // $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where('status',1)->sum("money");
  2328. // $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  2329. // $person_amount += $user_person_amount;
  2330. //计算个人的1180单价的业绩 集合
  2331. $money1180Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",1180)->select();
  2332. $money1180Sum = 0;
  2333. foreach ($money1180Records as $record) {
  2334. $money1180Sum += $record['money'] - 300 - 180;
  2335. }
  2336. $money11800Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",11800)->select();
  2337. //var_dump($person_nums);
  2338. //计算个人的11800单价的业绩 集合
  2339. $money11800Sum = 0;
  2340. foreach ($money11800Records as $record) {
  2341. $money11800Sum += $record['money'] - 3000 - 1800;
  2342. }
  2343. $money10620Records = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("money",10620)->select();
  2344. //var_dump($person_nums);
  2345. //计算个人的10620单价的业绩 集合
  2346. $money10620Sum = 0;
  2347. foreach ($money10620Records as $record) {
  2348. $money10620Sum += $record['money'] - 2700 - 1620;
  2349. }
  2350. // 计算除去特定值后的总和
  2351. $otherMoneyRecords = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->whereNotIn('money', [1180, 11800 ,10620])->select();
  2352. $otherMoneySum = 0;
  2353. foreach ($otherMoneyRecords as $record) {
  2354. $otherMoneySum += $record['money'];
  2355. }
  2356. // 分别处理特定值的情况并加上其他值的总和
  2357. $user_person_amount = $money1180Sum + $money11800Sum +$money10620Sum + round($otherMoneySum * 0.7,2);
  2358. $person_amount += $user_person_amount;
  2359. //级别信息
  2360. $userInfo = Db::name("user")->find($user_id);//
  2361. $zk_level = 4;
  2362. $is_zk = false;
  2363. if($userInfo['user_level_id_old'] == $zk_level) {
  2364. $is_zk = true;
  2365. $sales_incentive_info = $this->getStarLevel($user_id,$team_amount,$person_amount);
  2366. $sales_incentive = isset($sales_incentive_info['title']) ? $sales_incentive_info['title'] : '';
  2367. } else{
  2368. $sales_incentive = 0;
  2369. }
  2370. $return_data = [
  2371. 'common_nums'=>count($common_nums),
  2372. 'person_nums'=>count($person_nums),
  2373. 'common_nums_pv'=> $team_amount,
  2374. 'person_nums_pv'=> $person_amount,
  2375. 'sum_nums_pv' =>$team_amount + $person_amount,
  2376. 'sales_incentive' => $sales_incentive,
  2377. "is_zk"=>$is_zk
  2378. ];
  2379. return $return_data;
  2380. }
  2381. /**
  2382. * 获取指定用户业绩
  2383. */
  2384. public function getPerformanceOf($user_id) {
  2385. //共建联盟业绩 个人联盟业绩 共建联盟总pv 个人联盟业绩pv
  2386. $common_nums = $this->getCommonNums($user_id);
  2387. $person_nums = $this->getPersonageNums($user_id);
  2388. $team_amount = 0;
  2389. $person_amount = 0;
  2390. // $common_nums[] = $user_id;
  2391. foreach ($common_nums as $key => $value) {
  2392. # code...
  2393. $amount = $this->getPerformance1($value);
  2394. $team_amount += $amount;
  2395. }
  2396. foreach ($person_nums as $key => $value) {
  2397. # code...
  2398. $amount = $this->getPerformance1($value);
  2399. $person_amount += $amount;
  2400. }
  2401. // return $person_nums;
  2402. //添加自己共建联盟的流水
  2403. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("spread_id",$user_id)->sum("money");
  2404. $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  2405. $team_amount += $user_team_amount;
  2406. // //计算自己的个人联盟总流水
  2407. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("spread_id",$user_id)->sum("money");
  2408. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  2409. $person_amount += $user_person_amount;
  2410. $sum_nums_pv = $team_amount + $person_amount;
  2411. $sum_nums_pv = isset($sum_nums_pv) ? $sum_nums_pv :0;
  2412. return $sum_nums_pv;
  2413. }
  2414. /**
  2415. * 获取用户星级
  2416. */
  2417. public function getStarLevel($user_id,$team_money=0,$person_money=0) {
  2418. if(empty($team_money)) {
  2419. $common_nums = $this->getCommonNums($user_id);
  2420. $team_money = 0;
  2421. foreach ($common_nums as $key => $value) {
  2422. # code...
  2423. $amount = $this->getPerformance1($value);
  2424. $team_money += $amount;
  2425. }
  2426. //计算自己的共建联盟流水
  2427. $user_team_amount = Db::name("old_user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->sum("money");
  2428. $user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  2429. $team_money += $user_team_amount;
  2430. }else{
  2431. $common_nums = $this->getCommonNums($user_id);
  2432. }
  2433. if(empty($person_money)) {
  2434. $person_nums = $this->getPersonageNums($user_id);
  2435. $person_amount = 0;
  2436. foreach ($person_nums as $key => $value) {
  2437. # code...
  2438. $amount = $this->getPerformance1($value);
  2439. $person_amount += $amount;
  2440. }
  2441. $person_money = $person_amount;
  2442. //计算自己的个人联盟总流水
  2443. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->sum("money");
  2444. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  2445. $person_money += $user_person_amount;
  2446. }else{
  2447. $person_nums = $this->getPersonageNums($user_id);
  2448. }
  2449. $slow = $person_money;
  2450. if($team_money < $person_money) {
  2451. $slow = $team_money;
  2452. }
  2453. $sum_money = $team_money + $person_money;
  2454. // $data = ['sum_money'=>$sum_money,"team_money"=>$team_money,"person_money"=>$person_money];
  2455. // $this->error(0,$data);
  2456. $star_list = Db::name("old_user_star")->order("statement_all_num desc")->select();
  2457. $start_level = "";
  2458. foreach ($star_list as $key => $value) {
  2459. # code...
  2460. if( $sum_money>=$value['statement_all_num'] && $slow >= $value['person_statement']) {
  2461. return $value;
  2462. }
  2463. }
  2464. return $start_level;
  2465. }
  2466. /**
  2467. * 获取流水信息
  2468. */
  2469. public function getPerformance1($user_id) {
  2470. // $amount = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("status",1)->sum("money");
  2471. // $amount = isset($amount) ? round($amount*0.7,2) : 0;
  2472. // return $amount;
  2473. $money1180Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",1180)->where("status",1)->select();
  2474. $money1180Sum = 0;
  2475. foreach ($money1180Records as $record) {
  2476. $money1180Sum += $record['money'] - 300 - 180;
  2477. }
  2478. // var_dump($money1180Sum);
  2479. $money11800Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",11800)->where("status",1)->select();
  2480. //var_dump($person_nums);
  2481. //计算个人的11800单价的业绩 集合
  2482. $money11800Sum = 0;
  2483. foreach ($money11800Records as $record) {
  2484. $money11800Sum += $record['money'] - 3000 - 1800;
  2485. }
  2486. $money10620Records = Db::name("old_user_of_goods")->where("node_id",$user_id)->where("money",10620)->where("status",1)->select();
  2487. //var_dump($person_nums);
  2488. //计算个人的11800单价的业绩 集合
  2489. $money10620Sum = 0;
  2490. foreach ($money10620Records as $record) {
  2491. $money10620Sum += $record['money'] - 2700 - 1620;
  2492. }
  2493. // 计算除去特定值后的总和
  2494. $otherMoneyRecords = Db::name("old_user_of_goods")->where("node_id",$user_id)->where('status', 1)->whereNotIn('money', [1180, 11800 ,10620])->select();
  2495. $otherMoneySum = 0;
  2496. foreach ($otherMoneyRecords as $record) {
  2497. $otherMoneySum += $record['money'];
  2498. }
  2499. // 分别处理特定值的情况并加上其他值的总和
  2500. $user_person_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  2501. return $user_person_amount;
  2502. }
  2503. /**
  2504. * 获取个人业绩统计信息
  2505. */
  2506. public function getPerformanceOfId($user_id)
  2507. {
  2508. //var_dump($user_id);
  2509. //联盟总人数 共建联盟人数 个人联盟人数 总流水 共建联盟流水 个人联盟流水 所属星级(钻卡专属)
  2510. $common_nums = $this->getCommonNums($user_id);
  2511. $person_nums = $this->getPersonageNums($user_id);
  2512. //联盟业绩 查询 共建联盟业绩 个人联盟业绩
  2513. $team_amount = 0;
  2514. $person_amount = 0;
  2515. // $common_nums[] = $user_id;
  2516. foreach ($common_nums as $key => $value) {
  2517. # code...
  2518. $amount = $this->getPerformance1($value);
  2519. $team_amount += $amount;
  2520. }
  2521. //计算自己的共建联盟流水
  2522. //$user_team_amount = Db::name("user_of_goods")->whereIn("user_id",$common_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
  2523. // $this->error(0,$team_amount);
  2524. //$user_team_amount = empty($user_team_amount) ? 0 : round($user_team_amount * 0.7,2);
  2525. $money1180Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 1180)->select();
  2526. // 计算 status 为 1 且 money 为 1180 的记录总和(减去相应值后)
  2527. $money1180Sum = 0;
  2528. foreach ($money1180Records as $record) {
  2529. $money1180Sum += $record['money'] - 300 - 180;
  2530. }
  2531. // 获取 status 为 1 且 money 为 11800 的记录集合
  2532. $money11800Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->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. // 获取 status 为 1 且 money 为 11800 的记录集合
  2539. $money10620Records = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->where('money', 10620)->select();
  2540. // 计算 status 为 1 且 money 为 11800 的记录总和(减去相应值后)
  2541. $money10620Sum = 0;
  2542. foreach ($money10620Records as $record) {
  2543. $money10620Sum += $record['money'] - 2700 - 1620;
  2544. }
  2545. // 计算除去特定值后的总和
  2546. $otherMoneyRecords = Db::name("old_user_of_goods")->where('status', 1)->whereIn("user_id",$common_nums)->whereNotIn('money', [1180, 11800,10620])->select();
  2547. $otherMoneySum = 0;
  2548. foreach ($otherMoneyRecords as $record) {
  2549. $otherMoneySum += $record['money'];
  2550. }
  2551. // 分别处理特定值的情况并加上其他值的总和
  2552. $user_team_amount = $money1180Sum + $money11800Sum + $money10620Sum + round($otherMoneySum * 0.7,2);
  2553. $team_amount += $user_team_amount;
  2554. foreach ($person_nums as $key => $value) {
  2555. # code...
  2556. $amount = $this->getPerformance1($value);
  2557. $person_amount += $amount;
  2558. }
  2559. // //计算自己的个人联盟总流水
  2560. $user_person_amount = Db::name("old_user_of_goods")->whereIn("user_id",$person_nums)->where("node_id",$user_id)->where("status",1)->sum("money");
  2561. $user_person_amount = empty($user_person_amount) ? 0 : round($user_person_amount * 0.7,2);
  2562. $person_amount += $user_person_amount;
  2563. // $this->error(0,$common_nums);
  2564. return $team_amount + $person_amount;
  2565. }
  2566. /**
  2567. * 获取该用户共建联盟
  2568. */
  2569. public function getCommonNums($user_id){
  2570. //先获取共建联盟下用户的id
  2571. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->select()->toArray();
  2572. $new_array_ids =[];
  2573. foreach ($son_ids as $key => $value) {
  2574. # code...
  2575. $son_id = $value['id'];
  2576. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  2577. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  2578. if(count($son_value_ids) > 0) {
  2579. $son_value_ids = array_column($son_value_ids,"id");
  2580. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  2581. }
  2582. }
  2583. return $new_array_ids;
  2584. }
  2585. /**
  2586. * 获取该用户个人联盟
  2587. */
  2588. public function getPersonageNums($user_id){
  2589. $son_ids = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("id")->select();
  2590. $new_array_ids =[];
  2591. // return 3343;
  2592. foreach ($son_ids as $key => $value) {
  2593. # code...
  2594. $son_id = $value['id'];
  2595. $new_array_ids = array_merge($new_array_ids,[$son_id]);
  2596. $son_value_ids = Db::name("old_user_jbp")->whereRaw("FIND_IN_SET('$son_id',parent_ids)")->field("id")->select()->toArray();
  2597. if(count($son_value_ids) > 0) {
  2598. $son_value_ids = array_column($son_value_ids,"id");
  2599. $new_array_ids = array_merge($new_array_ids,$son_value_ids);
  2600. }
  2601. }
  2602. return $new_array_ids;
  2603. }
  2604. //获取团队递归聚宝盆1
  2605. public function teamPeople( $user_id,$type){
  2606. //var_dump($type);
  2607. //$ftype = 1:大部门,0:小部门
  2608. //$user_id = $this->request->post("user_id");
  2609. //$type = $this->request->post("type",0);
  2610. //查找当前用户id下节点
  2611. if($type == 1) {
  2612. // echo 33;
  2613. $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
  2614. }else if($type == 0) {
  2615. // echo 44;
  2616. $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
  2617. }else {
  2618. // echo 55;
  2619. $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
  2620. }
  2621. foreach ($list as $key => $value) {
  2622. # code...
  2623. $amount = $this->getPerformanceOfId($value['id']);
  2624. $list[$key]['user_name'] = $value['user_name'] . "业绩" . $amount;
  2625. $list[$key]['total_performance'] = $amount;
  2626. //$performance = $this->getPerformanceOfId($search_name['id']);
  2627. $list[$key]['performance'] = $this->getPerformance($value['id']);
  2628. }
  2629. return $list;
  2630. }
  2631. // //获取团队递归聚宝盆1
  2632. // public function teamPeople( $user_id,$type){
  2633. // //$user_id = $this->request->post("user_id");
  2634. // //$type = $this->request->post("type",0);
  2635. // //查找当前用户id下节点
  2636. // if($type == 1) {
  2637. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",1)->field("user_name,id")->select()->toArray();
  2638. // }else if($type == 2) {
  2639. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->where("is_team",0)->field("user_name,id")->select()->toArray();
  2640. // }else {
  2641. // $list = Db::name("old_user_jbp")->where("spread",$user_id)->field("user_name,id")->select()->toArray();
  2642. // }
  2643. // foreach ($list as $key => $value) {
  2644. // # code...
  2645. // $amount = $this->getPerformanceOfId($value['id']);
  2646. // $list[$key]['user_name'] = $value['user_name'] . "-----业绩" . $amount;
  2647. // }
  2648. // return $list;
  2649. // }
  2650. }