UserBillController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\admin\model\system\SystemAttachment;
  4. use app\models\lala\LalaPinkJoin;
  5. use app\models\mining\MiningMachine;
  6. use app\models\mining\UserMiningRatio;
  7. use app\models\mining\UserMiningService;
  8. use app\models\routine\RoutineCode;
  9. use app\models\routine\RoutineQrcode;
  10. use app\models\store\StoreOrder;
  11. use app\models\user\User;
  12. use app\models\user\UserBill;
  13. use app\models\user\UserExtract;
  14. use app\Request;
  15. use crmeb\services\GroupDataService;
  16. use crmeb\services\QrcodeService;
  17. use crmeb\services\SystemConfigService;
  18. use crmeb\services\UtilService;
  19. use crmeb\services\upload\Upload;
  20. /**
  21. * 账单类
  22. * Class UserBillController
  23. * @package app\api\controller\user
  24. */
  25. class UserBillController
  26. {
  27. /**
  28. * 推广数据 昨天的佣金 累计提现金额 当前佣金
  29. * @param Request $request
  30. * @return mixed
  31. */
  32. public function commission(Request $request)
  33. {
  34. $uid = $request->uid();
  35. $lastDayCount = UserBill::yesterdayCommissionSum($uid);//昨天的佣金
  36. $extractCount = UserExtract::extractSum($uid);//累计提现金额
  37. $commissionCount = UserBill::getBrokerage($uid);//获取总佣金
  38. if ($commissionCount > 0) {
  39. $rechargeCount = UserBill::getRecharge($uid);//累计充值
  40. $orderYuePrice = StoreOrder::getOrderStatusYueSum($uid);//余额累计消费
  41. $systemAdd = UserBill::getSystemAdd($uid);//后台添加余额
  42. $yueCount = bcadd($rechargeCount, $systemAdd, 2);// 后台添加余额 + 累计充值 = 非佣金的总金额
  43. $orderYuePrice = $yueCount > $orderYuePrice ? 0 : bcsub($orderYuePrice, $yueCount, 2);// 余额累计消费(使用佣金消费的金额)
  44. $commissionCount = bcsub($commissionCount, $extractCount, 2);//减去已提现金额
  45. $extractPriceCount = UserExtract::userExtractTotalPrice($uid, 0);
  46. $commissionCount = $extractPriceCount < $commissionCount ? bcsub($commissionCount, $extractPriceCount, 2) : 0;//减去审核中的提现金额
  47. $commissionCount = $commissionCount > $orderYuePrice ? bcsub($commissionCount, $orderYuePrice, 2) : 0;//减掉余额支付
  48. }
  49. $data['lastDayCount'] = $lastDayCount;
  50. $data['extractCount'] = $extractCount;
  51. $data['commissionCount'] = $commissionCount;
  52. return app('json')->successful($data);
  53. }
  54. /**
  55. * 推荐用户
  56. * @param Request $request
  57. * @return mixed
  58. *
  59. * grade == 0 获取一级推荐人
  60. * grade == 1 获取二级推荐人
  61. *
  62. * keyword 会员名称查询
  63. *
  64. * sort childCount ASC/DESC 团队排序 numberCount ASC/DESC 金额排序 orderCount ASC/DESC 订单排序
  65. */
  66. public function spread_people(Request $request)
  67. {
  68. $spreadInfo = UtilService::postMore([
  69. ['page', 1],
  70. ['limit', 20],
  71. ['grade', 0],
  72. ['keyword', ''],
  73. ['sort', ''],
  74. ], $request);
  75. $uid = $request->uid();
  76. $data['list'] = User::getUserSpreadGrade($uid, $spreadInfo['grade'], $spreadInfo['sort'], $spreadInfo['keyword'], $spreadInfo['page'], $spreadInfo['limit']);
  77. $data['total'] = User::getSpreadCount($uid);
  78. $data['totalLevel'] = User::getSpreadLevelCount($uid);
  79. return app('json')->successful($data);
  80. }
  81. /**
  82. * 推广订单
  83. * @param Request $request
  84. * @return mixed
  85. */
  86. public function spread_order(Request $request)
  87. {
  88. $orderInfo = UtilService::postMore([
  89. ['page', 1],
  90. ['limit', 20],
  91. ['category', 'now_money'],
  92. ['type', 'brokerage'],
  93. ], $request);
  94. $data['list'] = [];
  95. $data['count'] = 0;
  96. $uid = $request->uid();
  97. $data['list'] = UserBill::getRecordList($uid, $orderInfo['page'], $orderInfo['limit'], $orderInfo['category'], $orderInfo['type']);
  98. $count = UserBill::getRecordOrderCount($uid, $orderInfo['category'], $orderInfo['type']);
  99. $data['count'] = $count ? $count : 0;
  100. if (!count($data['list'])) return app('json')->successful($data);
  101. foreach ($data['list'] as $key => &$value) {
  102. $value['child'] = UserBill::getRecordOrderListDraw($uid, $value['time'], $orderInfo['category'], $orderInfo['type']);
  103. $value['count'] = count($value['child']);
  104. }
  105. return app('json')->successful($data);
  106. }
  107. /**
  108. * 推广佣金明细
  109. * @param Request $request
  110. * @param $type 0 全部 1 消费 2 充值 3 返佣 4 提现
  111. * @return mixed
  112. */
  113. public function spread_commission(Request $request, $type)
  114. {
  115. list($page, $limit) = UtilService::getMore([
  116. ['page', 0],
  117. ['limit', 0],
  118. ], $request, true);
  119. return app('json')->successful(UserBill::getUserBillList($request->uid(), $page, $limit, $type));
  120. }
  121. /**
  122. * 推广 佣金/提现 总和
  123. * @param Request $request
  124. * @param $type 3 佣金 4 提现
  125. * @return mixed
  126. */
  127. public function spread_count(Request $request, $type)
  128. {
  129. $count = 0;
  130. if ($type == 3) {
  131. $count1 = UserBill::getRecordCount($request->uid(), 'now_money', 'brokerage');
  132. $count2 = UserBill::getRecordCount($request->uid(), 'now_money', 'brokerage', '', true);
  133. $count = $count1 - $count2;
  134. } else if ($type == 4) {
  135. $count = UserExtract::userExtractTotalPrice($request->uid());//累计提现
  136. }
  137. $count = $count ? $count : 0;
  138. return app('json')->successful(['count' => $count]);
  139. }
  140. /**
  141. * 分销二维码海报生成
  142. * @param Request $request
  143. * @return mixed
  144. */
  145. public function spread_banner(Request $request)
  146. {
  147. list($type) = UtilService::getMore([
  148. ['type', 2],
  149. ], $request, true);
  150. $user = $request->user();
  151. $rootPath = app()->getRootPath();
  152. try {
  153. $resRoutine = true;//小程序
  154. $resWap = true;//公众号
  155. $siteUrl = sys_config('site_url');
  156. $routineSpreadBanner = sys_data('routine_spread_banner');
  157. if (!count($routineSpreadBanner)) return app('json')->fail('暂无海报');
  158. if ($type == 1) {
  159. //小程序
  160. $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_routine.jpg';
  161. $imageInfo = SystemAttachment::getInfo($name, 'name');
  162. //检测远程文件是否存在
  163. if (isset($imageInfo['att_dir']) && strstr($imageInfo['att_dir'], 'http') !== false && curl_file_exist($imageInfo['att_dir']) === false) {
  164. $imageInfo = null;
  165. SystemAttachment::where(['name' => $name])->delete();
  166. }
  167. if (!$imageInfo) {
  168. $res = RoutineCode::getShareCode($user['uid'], 'spread', '', '');
  169. if (!$res) return app('json')->fail('二维码生成失败');
  170. $uploadType = (int)sys_config('upload_type', 1);
  171. $upload = new Upload($uploadType, [
  172. 'accessKey' => sys_config('accessKey'),
  173. 'secretKey' => sys_config('secretKey'),
  174. 'uploadUrl' => sys_config('uploadUrl'),
  175. 'storageName' => sys_config('storage_name'),
  176. 'storageRegion' => sys_config('storage_region'),
  177. ]);
  178. $uploadRes = $upload->to('routine/spread/code')->validate()->stream($res['res'], $name);
  179. if ($uploadRes === false) {
  180. return app('json')->fail($upload->getError());
  181. }
  182. $imageInfo = $upload->getUploadInfo();
  183. $imageInfo['image_type'] = $uploadType;
  184. SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
  185. RoutineQrcode::setRoutineQrcodeFind($res['id'], ['status' => 1, 'url_time' => time(), 'qrcode_url' => $imageInfo['dir']]);
  186. $urlCode = $imageInfo['dir'];
  187. } else $urlCode = $imageInfo['att_dir'];
  188. if ($imageInfo['image_type'] == 1) $urlCode = $siteUrl . $urlCode;
  189. $siteUrlHttps = set_http_type($siteUrl, 0);
  190. $filelink = [
  191. 'Bold' => 'static' . DS . 'font' . DS . 'Alibaba-PuHuiTi-Regular.otf',
  192. 'Normal' => 'static' . DS . 'font' . DS . 'Alibaba-PuHuiTi-Regular.otf',
  193. ];
  194. if (!file_exists($filelink['Bold'])) return app('json')->fail('缺少字体文件Bold');
  195. if (!file_exists($filelink['Normal'])) return app('json')->fail('缺少字体文件Normal');
  196. foreach ($routineSpreadBanner as $key => &$item) {
  197. $posterInfo = '海报生成失败:(';
  198. $config = array(
  199. 'image' => array(
  200. array(
  201. 'url' => $urlCode, //二维码资源
  202. 'stream' => 0,
  203. 'left' => 114,
  204. 'top' => 790,
  205. 'right' => 0,
  206. 'bottom' => 0,
  207. 'width' => 120,
  208. 'height' => 120,
  209. 'opacity' => 100
  210. )
  211. ),
  212. 'text' => array(
  213. array(
  214. 'text' => $user['nickname'],
  215. 'left' => 250,
  216. 'top' => 840,
  217. 'fontPath' => $rootPath . 'public' . DS . $filelink['Bold'], //字体文件
  218. 'fontSize' => 16, //字号
  219. 'fontColor' => '40,40,40', //字体颜色
  220. 'angle' => 0,
  221. ),
  222. array(
  223. 'text' => '邀请您加入' . sys_config('site_name'),
  224. 'left' => 250,
  225. 'top' => 880,
  226. 'fontPath' => $rootPath . 'public' . DS . $filelink['Normal'], //字体文件
  227. 'fontSize' => 16, //字号
  228. 'fontColor' => '40,40,40', //字体颜色
  229. 'angle' => 0,
  230. )
  231. ),
  232. 'background' => $item['pic']
  233. );
  234. $resRoutine = $resRoutine && $posterInfo = UtilService::setSharePoster($config, 'routine/spread/poster');
  235. if (!is_array($posterInfo)) return app('json')->fail($posterInfo);
  236. SystemAttachment::attachmentAdd($posterInfo['name'], $posterInfo['size'], $posterInfo['type'], $posterInfo['dir'], $posterInfo['thumb_path'], 1, $posterInfo['image_type'], $posterInfo['time'], 2);
  237. if ($resRoutine) {
  238. if ($posterInfo['image_type'] == 1)
  239. $item['poster'] = $siteUrlHttps . $posterInfo['dir'];
  240. else
  241. $item['poster'] = set_http_type($posterInfo['dir'], 0);
  242. $item['poster'] = str_replace('\\', '/', $item['poster']);
  243. }
  244. }
  245. } else if ($type == 2 || $type == 3) {
  246. //公众号
  247. $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_app.jpg';
  248. if ($type == 3) $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_wap.jpg';
  249. $imageInfo = SystemAttachment::getInfo($name, 'name');
  250. //检测远程文件是否存在
  251. if (isset($imageInfo['att_dir']) && strstr($imageInfo['att_dir'], 'http') !== false && curl_file_exist($imageInfo['att_dir']) === false) {
  252. $imageInfo = null;
  253. SystemAttachment::where(['name' => $name])->delete();
  254. }
  255. if (!$imageInfo) {
  256. if ($type == 3) {
  257. $qr_code = QrcodeService::getForeverQrcode('spread', $user['uid']);
  258. if (isset($qr_code['url'])) {
  259. $urlCode = $qr_code['url'];
  260. } else
  261. return app('json')->fail('二维码生成失败');
  262. } else {
  263. $codeUrl = set_http_type($siteUrl . '/register?spread=' . $user['account'], 1);//二维码链接
  264. // if ($type == 3) $codeUrl = set_http_type($siteUrl . '/index?spread=' . $user['account'], 1);//二维码链接
  265. $imageInfo = UtilService::getQRCodePath($codeUrl, $name);
  266. if (is_string($imageInfo)) return app('json')->fail('二维码生成失败', ['error' => $imageInfo]);
  267. SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
  268. $urlCode = $imageInfo['dir'];
  269. }
  270. } else $urlCode = $imageInfo['att_dir'];
  271. if ($imageInfo['image_type'] == 1) $urlCode = $siteUrl . $urlCode;
  272. $siteUrl = set_http_type($siteUrl, 1);
  273. $filelink = [
  274. 'Bold' => 'static' . DS . 'font' . DS . 'Alibaba-PuHuiTi-Regular.otf',
  275. 'Normal' => 'static' . DS . 'font' . DS . 'Alibaba-PuHuiTi-Regular.otf',
  276. ];
  277. if (!file_exists($filelink['Bold'])) return app('json')->fail('缺少字体文件Bold');
  278. if (!file_exists($filelink['Normal'])) return app('json')->fail('缺少字体文件Normal');
  279. foreach ($routineSpreadBanner as $key => &$item) {
  280. $posterInfo = '海报生成失败:(';
  281. $config = array(
  282. 'image' => array(
  283. array(
  284. 'url' => $urlCode, //二维码资源
  285. 'stream' => 0,
  286. 'left' => 244,
  287. 'top' => 880,
  288. 'right' => 0,
  289. 'bottom' => 0,
  290. 'width' => 260,
  291. 'height' => 260,
  292. 'opacity' => 100
  293. )
  294. ),
  295. 'text' => array(
  296. array(
  297. 'text' => '邀请码',
  298. 'left' => 330,
  299. 'top' => 1180,
  300. 'fontPath' => $rootPath . 'public' . DS . $filelink['Bold'], //字体文件
  301. 'fontSize' => 20, //字号
  302. 'fontColor' => '0,0,0', //字体颜色
  303. 'angle' => 0,
  304. ),
  305. array(
  306. 'text' => $user['account'],
  307. 'left' => 290,
  308. 'top' => 1210,
  309. 'fontPath' => $rootPath . 'public' . DS . $filelink['Normal'], //字体文件
  310. 'fontSize' => 20, //字号
  311. 'fontColor' => '0,0,0', //字体颜色
  312. 'angle' => 0,
  313. )
  314. ),
  315. 'background' => $item['pic']
  316. );
  317. $resWap = $resWap && $posterInfo = UtilService::setSharePoster($config, 'wap/spread/poster');
  318. if (!is_array($posterInfo)) return app('json')->fail($posterInfo);
  319. SystemAttachment::attachmentAdd($posterInfo['name'], $posterInfo['size'], $posterInfo['type'], $posterInfo['dir'], $posterInfo['thumb_path'], 1, $posterInfo['image_type'], $posterInfo['time'], 2);
  320. if ($resWap) {
  321. if ($posterInfo['image_type'] == 1)
  322. $item['wap_poster'] = $siteUrl . $posterInfo['thumb_path'];
  323. else
  324. $item['wap_poster'] = UtilService::setHttpType($posterInfo['thumb_path'], 1);
  325. }
  326. }
  327. }
  328. if ($resRoutine && $resWap) return app('json')->successful($routineSpreadBanner);
  329. else return app('json')->fail('生成图片失败');
  330. } catch (\Exception $e) {
  331. return app('json')->fail('生成图片时,系统错误', ['line' => $e->getLine(), 'message' => $e->getMessage(), 'file' => $e->getFile()]);
  332. }
  333. }
  334. /**
  335. * 积分记录
  336. * @param Request $request
  337. * @return mixed
  338. * @throws \think\db\exception\DataNotFoundException
  339. * @throws \think\db\exception\ModelNotFoundException
  340. * @throws \think\exception\DbException
  341. */
  342. public function integral_list(Request $request)
  343. {
  344. list($page, $limit) = UtilService::getMore([
  345. ['page', 0], ['limit', 0]
  346. ], $request, true);
  347. return app('json')->successful(UserBill::userBillList($request->uid(), $page, $limit));
  348. }
  349. public function setReturnUper($uid, Request $request)
  350. {
  351. $user = User::getUserInfo($uid);
  352. if (!$user || $user['spread_uid'] != $request->uid()) {
  353. return app('json')->fail('用户不合法');
  354. }
  355. $ratio = $request->post('ratio', 0);
  356. $mid = $request->post('mid', 0);
  357. if (!$mid || !MiningMachine::get($mid)) return app('json')->fail('矿机不合法');
  358. $self = UserMiningRatio::where('mid', $mid)->where('uid', $request->uid())->find();
  359. if (!isset($self['ratio']) || $ratio > $self['ratio']) {
  360. return app('json')->fail('佣金比例不能超过自己');
  361. }
  362. $uids = User::where('spread_uid', $user['uid'])->column('uid');
  363. $user2 = UserMiningRatio::where('mid', $mid)->where('uid', 'in', $uids)->max('ratio');
  364. if ($ratio < $user2) {
  365. return app('json')->fail('佣金比例不能低于目标下级');
  366. }
  367. if (UserMiningRatio::where('mid', $mid)->where('uid', $uid)->find()) {
  368. $res = UserMiningRatio::where('mid', $mid)->where('uid', $uid)
  369. ->update(['ratio' => $ratio, 'update_time' => time(), 'update_uid' => $request->uid()]);
  370. } else {
  371. $res = UserMiningRatio::create([
  372. 'uid' => $uid,
  373. 'mid' => $mid,
  374. 'ratio' => $ratio,
  375. 'add_time' => time(),
  376. 'update_time' => time(),
  377. 'update_uid' => $request->uid(),
  378. ]);
  379. }
  380. if ($res) {
  381. return app('json')->success('修改成功');
  382. } else {
  383. return app('json')->fail('修改失败或者您没有修改什么');
  384. }
  385. }
  386. public function setService($uid, Request $request)
  387. {
  388. $user = User::getUserInfo($uid);
  389. if (!$user || $user['spread_uid'] != $request->uid()) {
  390. return app('json')->fail('用户不合法');
  391. }
  392. $ratio = $request->post('ratio', 0);
  393. $mid = $request->post('mid', 0);
  394. if (!$mid || !MiningMachine::get($mid)) return app('json')->fail('矿机不合法');
  395. $self = UserMiningService::where('mid', $mid)->where('uid', $request->uid())->find();
  396. if (!isset($self['ratio']) || $ratio < $self['ratio']) {
  397. return app('json')->fail('服务费比例不能低于自己');
  398. }
  399. $uids = User::where('spread_uid', $user['uid'])->column('uid');
  400. $user2 = UserMiningService::where('mid', $mid)->where('uid', 'in', $uids)->min('ratio');
  401. if ($user2 > 0 && $ratio > $user2) {
  402. return app('json')->fail('服务费比例不能高于目标下级');
  403. }
  404. if ($ratio > MiningMachine::where('id', $mid)->value('service_ratio')) {
  405. return app('json')->fail('服务费比例不能高于系统设置');
  406. }
  407. if (UserMiningService::where('mid', $mid)->where('uid', $uid)->find()) {
  408. $res = UserMiningService::where('mid', $mid)->where('uid', $uid)
  409. ->update(['ratio' => $ratio, 'update_time' => time(), 'update_uid' => $request->uid()]);
  410. } else {
  411. $res = UserMiningService::create([
  412. 'uid' => $uid,
  413. 'mid' => $mid,
  414. 'ratio' => $ratio,
  415. 'add_time' => time(),
  416. 'update_time' => time(),
  417. 'update_uid' => $request->uid(),
  418. ]);
  419. }
  420. if ($res) {
  421. return app('json')->success('修改成功');
  422. } else {
  423. return app('json')->fail('修改失败或者您没有修改什么');
  424. }
  425. }
  426. public static function userBillInfo(Request $request)
  427. {
  428. $achievement = function ($uid) {
  429. $uids = [$uid];
  430. $all = [];
  431. while ($uids) {
  432. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  433. $all = array_merge($all, $uids);
  434. }
  435. //var_dump($all);
  436. return LalaPinkJoin::where('paid', 1)->where('status', 'in', [1, 2])->where('uid', '<>', 0)->where('uid', 'in', $all)->where('cost_money_type', 'USDT')->sum('cost');
  437. };
  438. $small_achivement = function ($uid) {
  439. $sub_uids = User::where('spread_uid', $uid)->column('uid');
  440. $max = 0;
  441. $all = 0;
  442. foreach ($sub_uids as $v) {
  443. $uids = [$v];
  444. $all_uids = [$v];
  445. while ($uids) {
  446. $uids = \app\admin\model\user\User::where('spread_uid', 'in', $uids)->column('uid');
  447. $all_uids = array_merge($all_uids, $uids);
  448. }
  449. $achievement = LalaPinkJoin::where('paid', 1)->where('uid', '<>', 0)->where('status', 'in', [1, 2])->where('uid', 'in', $all_uids)->where('cost_money_type', 'USDT')->sum('cost');
  450. if ($achievement > $max) $max = $achievement;
  451. $all += $achievement;
  452. }
  453. return $all - $max;
  454. };
  455. $achievement_month = function ($uid) {
  456. $uids = [$uid];
  457. $all = [];
  458. while ($uids) {
  459. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  460. $all = array_merge($all, $uids);
  461. }
  462. //var_dump($all);
  463. return LalaPinkJoin::whereTime('add_time', 'month')->where('paid', 1)->where('status', 'in', [1, 2])->where('uid', '<>', 0)->where('uid', 'in', $all)->where('cost_money_type', 'USDT')->sum('cost');
  464. };
  465. $small_achivement_month = function ($uid) {
  466. $sub_uids = User::where('spread_uid', $uid)->column('uid');
  467. $max = 0;
  468. $all = 0;
  469. foreach ($sub_uids as $v) {
  470. $uids = [$v];
  471. $all_uids = [$v];
  472. while ($uids) {
  473. $uids = \app\admin\model\user\User::where('spread_uid', 'in', $uids)->column('uid');
  474. $all_uids = array_merge($all_uids, $uids);
  475. }
  476. $achievement = LalaPinkJoin::whereTime('add_time', 'month')->where('paid', 1)->where('uid', '<>', 0)->where('status', 'in', [1, 2])->where('uid', 'in', $all_uids)->where('cost_money_type', 'USDT')->sum('cost');
  477. if ($achievement > $max) $max = $achievement;
  478. $all += $achievement;
  479. }
  480. return $all - $max;
  481. };
  482. $group_num = function ($uid) {
  483. $uids = [$uid];
  484. $all = [];
  485. while ($uids) {
  486. $uids = User::where('spread_uid', 'in', $uids)->column('uid');
  487. $all = array_merge($all, $uids);
  488. }
  489. return count($all);
  490. };
  491. $res['achievement'] = $achievement($request->uid());
  492. $res['achievement_month'] = $achievement_month($request->uid());
  493. $res['group_num'] = $group_num($request->uid());
  494. $res['small_achivement'] = $small_achivement($request->uid());
  495. $res['small_achivement_month'] = $small_achivement_month($request->uid());
  496. $res['recommend_num'] = User::where('spread_uid', $request->uid())->count();
  497. $res['yesterday'] = [
  498. 'pink' => UserBill::where('uid', $request->uid())->where('category', 'USDT')->where('type', 'in', ['join_award'])->where('pm', 1)->where('status', 1)->whereTime('add_time', 'today')->value('SUM(number)'),
  499. 'recommend' => UserBill::where('uid', $request->uid())->where('category', 'USDT')->where('type', 'in', ['lala_recommend_award'])->where('pm', 1)->where('status', 1)->whereTime('add_time', 'today')->value('SUM(number)'),
  500. 'group' => UserBill::where('uid', $request->uid())->where('category', 'USDT')->where('type', 'in', ['lala_same_level_award', 'lala_group_award'])->where('pm', 1)->where('status', 1)->whereTime('add_time', 'today')->value('SUM(number)'),
  501. ];
  502. $res['today'] = [
  503. 'pink' => UserBill::where('uid', $request->uid())->where('category', 'USDT')->where('type', 'in', ['join_award'])->where('pm', 1)->where('status', 0)->whereTime('add_time', 'today')->value('SUM(number)'),
  504. 'recommend' => UserBill::where('uid', $request->uid())->where('category', 'USDT')->where('type', 'in', ['lala_recommend_award'])->where('pm', 1)->where('status', 0)->whereTime('add_time', 'today')->value('SUM(number)'),
  505. 'group' => UserBill::where('uid', $request->uid())->where('category', 'USDT')->where('type', 'in', ['lala_same_level_award', 'lala_group_award'])->where('pm', 1)->where('status', 0)->whereTime('add_time', 'today')->value('SUM(number)'),
  506. ];
  507. $res['all'] = [
  508. 'pink' => UserBill::where('uid', $request->uid())->where('category', 'USDT')->where('type', 'in', ['join_award'])->where('pm', 1)->where('status', 1)->value('SUM(number)'),
  509. 'recommend' => UserBill::where('uid', $request->uid())->where('category', 'USDT')->where('type', 'in', ['lala_recommend_award'])->where('pm', 1)->where('status', 1)->value('SUM(number)'),
  510. 'group' => UserBill::where('uid', $request->uid())->where('category', 'USDT')->where('type', 'in', ['lala_same_level_award', 'lala_group_award'])->where('pm', 1)->where('status', 1)->value('SUM(number)'),
  511. ];
  512. return app('json')->success('ok', $res);
  513. }
  514. }