uid(); $lastDayCount = UserBill::yesterdayCommissionSum($uid);//昨天的佣金 $extractCount = UserExtract::extractSum($uid);//累计提现金额 $commissionCount = UserBill::getBrokerage($uid);//获取总佣金 if ($commissionCount > 0) { $rechargeCount = UserBill::getRecharge($uid);//累计充值 $orderYuePrice = StoreOrder::getOrderStatusYueSum($uid);//余额累计消费 $systemAdd = UserBill::getSystemAdd($uid);//后台添加余额 $yueCount = bcadd($rechargeCount, $systemAdd, 2);// 后台添加余额 + 累计充值 = 非佣金的总金额 $orderYuePrice = $yueCount > $orderYuePrice ? 0 : bcsub($orderYuePrice, $yueCount, 2);// 余额累计消费(使用佣金消费的金额) $commissionCount = bcsub($commissionCount, $extractCount, 2);//减去已提现金额 $extractPriceCount = UserExtract::userExtractTotalPrice($uid, 0); $commissionCount = $extractPriceCount < $commissionCount ? bcsub($commissionCount, $extractPriceCount, 2) : 0;//减去审核中的提现金额 $commissionCount = $commissionCount > $orderYuePrice ? bcsub($commissionCount, $orderYuePrice, 2) : 0;//减掉余额支付 } $data['lastDayCount'] = $lastDayCount; $data['extractCount'] = $extractCount; $data['commissionCount'] = $commissionCount; return app('json')->successful($data); } /** * 推荐用户 * @param Request $request * @return mixed * * grade == 0 获取一级推荐人 * grade == 1 获取二级推荐人 * * keyword 会员名称查询 * * sort childCount ASC/DESC 团队排序 numberCount ASC/DESC 金额排序 orderCount ASC/DESC 订单排序 */ public function spread_people(Request $request) { $spreadInfo = UtilService::postMore([ ['page', 1], ['limit', 20], ['grade', 0], ['keyword', ''], ['sort', ''], ], $request); $uid = $request->uid(); $data['list'] = User::getUserSpreadGrade($uid, $spreadInfo['grade'], $spreadInfo['sort'], $spreadInfo['keyword'], $spreadInfo['page'], $spreadInfo['limit']); $data['total'] = User::getSpreadCount($uid); $data['totalLevel'] = User::getSpreadLevelCount($uid); return app('json')->successful($data); } /** * 推广订单 * @param Request $request * @return mixed */ public function spread_order(Request $request) { $orderInfo = UtilService::postMore([ ['page', 1], ['limit', 20], ['category', 'now_money'], ['type', 'brokerage'], ], $request); $data['list'] = []; $data['count'] = 0; $uid = $request->uid(); $data['list'] = UserBill::getRecordList($uid, $orderInfo['page'], $orderInfo['limit'], $orderInfo['category'], $orderInfo['type']); $count = UserBill::getRecordOrderCount($uid, $orderInfo['category'], $orderInfo['type']); $data['count'] = $count ? $count : 0; if (!count($data['list'])) return app('json')->successful($data); foreach ($data['list'] as $key => &$value) { $value['child'] = UserBill::getRecordOrderListDraw($uid, $value['time'], $orderInfo['category'], $orderInfo['type']); $value['count'] = count($value['child']); } return app('json')->successful($data); } /** * 推广佣金明细 * @param Request $request * @param $type 0 全部 1 消费 2 充值 3 返佣 4 提现 * @return mixed */ public function spread_commission(Request $request, $type) { list($page, $limit) = UtilService::getMore([ ['page', 0], ['limit', 0], ], $request, true); return app('json')->successful(UserBill::getUserBillList($request->uid(), $page, $limit, $type)); } /** * 推广 佣金/提现 总和 * @param Request $request * @param $type 3 佣金 4 提现 * @return mixed */ public function spread_count(Request $request, $type) { $count = 0; if ($type == 3) { $count1 = UserBill::getRecordCount($request->uid(), 'now_money', 'brokerage'); $count2 = UserBill::getRecordCount($request->uid(), 'now_money', 'brokerage', '', true); $count = $count1 - $count2; } else if ($type == 4) { $count = UserExtract::userExtractTotalPrice($request->uid());//累计提现 } $count = $count ? $count : 0; return app('json')->successful(['count' => $count]); } /** * 分销二维码海报生成 * @param Request $request * @return mixed */ public function spread_banner(Request $request) { list($type) = UtilService::getMore([ ['type', 2], ], $request, true); $user = $request->user(); $rootPath = app()->getRootPath(); try { $resRoutine = true;//小程序 $resWap = true;//公众号 $siteUrl = sys_config('site_url'); $routineSpreadBanner = sys_data('routine_spread_banner'); if (!count($routineSpreadBanner)) return app('json')->fail('暂无海报'); if ($type == 1) { //小程序 $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_routine.jpg'; $imageInfo = SystemAttachment::getInfo($name, 'name'); //检测远程文件是否存在 if (isset($imageInfo['att_dir']) && strstr($imageInfo['att_dir'], 'http') !== false && curl_file_exist($imageInfo['att_dir']) === false) { $imageInfo = null; SystemAttachment::where(['name' => $name])->delete(); } if (!$imageInfo) { $res = RoutineCode::getShareCode($user['uid'], 'spread', '', ''); if (!$res) return app('json')->fail('二维码生成失败'); $uploadType = (int)sys_config('upload_type', 1); $upload = new Upload($uploadType, [ 'accessKey' => sys_config('accessKey'), 'secretKey' => sys_config('secretKey'), 'uploadUrl' => sys_config('uploadUrl'), 'storageName' => sys_config('storage_name'), 'storageRegion' => sys_config('storage_region'), ]); $uploadRes = $upload->to('routine/spread/code')->validate()->stream($res['res'], $name); if ($uploadRes === false) { return app('json')->fail($upload->getError()); } $imageInfo = $upload->getUploadInfo(); $imageInfo['image_type'] = $uploadType; SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2); RoutineQrcode::setRoutineQrcodeFind($res['id'], ['status' => 1, 'url_time' => time(), 'qrcode_url' => $imageInfo['dir']]); $urlCode = $imageInfo['dir']; } else $urlCode = $imageInfo['att_dir']; if ($imageInfo['image_type'] == 1) $urlCode = $siteUrl . $urlCode; $siteUrlHttps = set_http_type($siteUrl, 0); $filelink = [ 'Bold' => 'static' . DS . 'font' . DS . 'Alibaba-PuHuiTi-Regular.otf', 'Normal' => 'static' . DS . 'font' . DS . 'Alibaba-PuHuiTi-Regular.otf', ]; if (!file_exists($filelink['Bold'])) return app('json')->fail('缺少字体文件Bold'); if (!file_exists($filelink['Normal'])) return app('json')->fail('缺少字体文件Normal'); foreach ($routineSpreadBanner as $key => &$item) { $posterInfo = '海报生成失败:('; $config = array( 'image' => array( array( 'url' => $urlCode, //二维码资源 'stream' => 0, 'left' => 114, 'top' => 790, 'right' => 0, 'bottom' => 0, 'width' => 120, 'height' => 120, 'opacity' => 100 ) ), 'text' => array( array( 'text' => $user['nickname'], 'left' => 250, 'top' => 840, 'fontPath' => $rootPath . 'public' . DS . $filelink['Bold'], //字体文件 'fontSize' => 16, //字号 'fontColor' => '40,40,40', //字体颜色 'angle' => 0, ), array( 'text' => '邀请您加入' . sys_config('site_name'), 'left' => 250, 'top' => 880, 'fontPath' => $rootPath . 'public' . DS . $filelink['Normal'], //字体文件 'fontSize' => 16, //字号 'fontColor' => '40,40,40', //字体颜色 'angle' => 0, ) ), 'background' => $item['pic'] ); $resRoutine = $resRoutine && $posterInfo = UtilService::setSharePoster($config, 'routine/spread/poster'); if (!is_array($posterInfo)) return app('json')->fail($posterInfo); SystemAttachment::attachmentAdd($posterInfo['name'], $posterInfo['size'], $posterInfo['type'], $posterInfo['dir'], $posterInfo['thumb_path'], 1, $posterInfo['image_type'], $posterInfo['time'], 2); if ($resRoutine) { if ($posterInfo['image_type'] == 1) $item['poster'] = $siteUrlHttps . $posterInfo['dir']; else $item['poster'] = set_http_type($posterInfo['dir'], 0); $item['poster'] = str_replace('\\', '/', $item['poster']); } } } else if ($type == 2 || $type == 3) { //公众号 $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_app.jpg'; if ($type == 3) $name = $user['uid'] . '_' . $user['is_promoter'] . '_user_wap.jpg'; $imageInfo = SystemAttachment::getInfo($name, 'name'); //检测远程文件是否存在 if (isset($imageInfo['att_dir']) && strstr($imageInfo['att_dir'], 'http') !== false && curl_file_exist($imageInfo['att_dir']) === false) { $imageInfo = null; SystemAttachment::where(['name' => $name])->delete(); } if (!$imageInfo) { if ($type == 3) { $qr_code = QrcodeService::getForeverQrcode('spread', $user['uid']); if (isset($qr_code['url'])) { $urlCode = $qr_code['url']; } else return app('json')->fail('二维码生成失败'); } else { $codeUrl = set_http_type($siteUrl . '/register?spread=' . $user['account'], 1);//二维码链接 // if ($type == 3) $codeUrl = set_http_type($siteUrl . '/index?spread=' . $user['account'], 1);//二维码链接 $imageInfo = UtilService::getQRCodePath($codeUrl, $name); if (is_string($imageInfo)) return app('json')->fail('二维码生成失败', ['error' => $imageInfo]); SystemAttachment::attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2); $urlCode = $imageInfo['dir']; } } else $urlCode = $imageInfo['att_dir']; if ($imageInfo['image_type'] == 1) $urlCode = $siteUrl . $urlCode; $siteUrl = set_http_type($siteUrl, 1); $filelink = [ 'Bold' => 'static' . DS . 'font' . DS . 'Alibaba-PuHuiTi-Regular.otf', 'Normal' => 'static' . DS . 'font' . DS . 'Alibaba-PuHuiTi-Regular.otf', ]; if (!file_exists($filelink['Bold'])) return app('json')->fail('缺少字体文件Bold'); if (!file_exists($filelink['Normal'])) return app('json')->fail('缺少字体文件Normal'); foreach ($routineSpreadBanner as $key => &$item) { $posterInfo = '海报生成失败:('; $config = array( 'image' => array( array( 'url' => $urlCode, //二维码资源 'stream' => 0, 'left' => 244, 'top' => 880, 'right' => 0, 'bottom' => 0, 'width' => 260, 'height' => 260, 'opacity' => 100 ) ), 'text' => array( array( 'text' => '邀请码', 'left' => 330, 'top' => 1180, 'fontPath' => $rootPath . 'public' . DS . $filelink['Bold'], //字体文件 'fontSize' => 20, //字号 'fontColor' => '0,0,0', //字体颜色 'angle' => 0, ), array( 'text' => $user['account'], 'left' => 290, 'top' => 1210, 'fontPath' => $rootPath . 'public' . DS . $filelink['Normal'], //字体文件 'fontSize' => 20, //字号 'fontColor' => '0,0,0', //字体颜色 'angle' => 0, ) ), 'background' => $item['pic'] ); $resWap = $resWap && $posterInfo = UtilService::setSharePoster($config, 'wap/spread/poster'); if (!is_array($posterInfo)) return app('json')->fail($posterInfo); SystemAttachment::attachmentAdd($posterInfo['name'], $posterInfo['size'], $posterInfo['type'], $posterInfo['dir'], $posterInfo['thumb_path'], 1, $posterInfo['image_type'], $posterInfo['time'], 2); if ($resWap) { if ($posterInfo['image_type'] == 1) $item['wap_poster'] = $siteUrl . $posterInfo['thumb_path']; else $item['wap_poster'] = UtilService::setHttpType($posterInfo['thumb_path'], 1); } } } if ($resRoutine && $resWap) return app('json')->successful($routineSpreadBanner); else return app('json')->fail('生成图片失败'); } catch (\Exception $e) { return app('json')->fail('生成图片时,系统错误', ['line' => $e->getLine(), 'message' => $e->getMessage(), 'file' => $e->getFile()]); } } /** * 积分记录 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function integral_list(Request $request) { list($page, $limit) = UtilService::getMore([ ['page', 0], ['limit', 0] ], $request, true); return app('json')->successful(UserBill::userBillList($request->uid(), $page, $limit)); } public function setReturnUper($uid, Request $request) { $user = User::getUserInfo($uid); if (!$user || $user['spread_uid'] != $request->uid()) { return app('json')->fail('用户不合法'); } $ratio = $request->post('ratio', 0); $mid = $request->post('mid', 0); if (!$mid || !MiningMachine::get($mid)) return app('json')->fail('矿机不合法'); $self = UserMiningRatio::where('mid', $mid)->where('uid', $request->uid())->find(); if (!isset($self['ratio']) || $ratio > $self['ratio']) { return app('json')->fail('佣金比例不能超过自己'); } $uids = User::where('spread_uid', $user['uid'])->column('uid'); $user2 = UserMiningRatio::where('mid', $mid)->where('uid', 'in', $uids)->max('ratio'); if ($ratio < $user2) { return app('json')->fail('佣金比例不能低于目标下级'); } if (UserMiningRatio::where('mid', $mid)->where('uid', $uid)->find()) { $res = UserMiningRatio::where('mid', $mid)->where('uid', $uid) ->update(['ratio' => $ratio, 'update_time' => time(), 'update_uid' => $request->uid()]); } else { $res = UserMiningRatio::create([ 'uid' => $uid, 'mid' => $mid, 'ratio' => $ratio, 'add_time' => time(), 'update_time' => time(), 'update_uid' => $request->uid(), ]); } if ($res) { return app('json')->success('修改成功'); } else { return app('json')->fail('修改失败或者您没有修改什么'); } } public function setService($uid, Request $request) { $user = User::getUserInfo($uid); if (!$user || $user['spread_uid'] != $request->uid()) { return app('json')->fail('用户不合法'); } $ratio = $request->post('ratio', 0); $mid = $request->post('mid', 0); if (!$mid || !MiningMachine::get($mid)) return app('json')->fail('矿机不合法'); $self = UserMiningService::where('mid', $mid)->where('uid', $request->uid())->find(); if (!isset($self['ratio']) || $ratio < $self['ratio']) { return app('json')->fail('服务费比例不能低于自己'); } $uids = User::where('spread_uid', $user['uid'])->column('uid'); $user2 = UserMiningService::where('mid', $mid)->where('uid', 'in', $uids)->min('ratio'); if ($user2 > 0 && $ratio > $user2) { return app('json')->fail('服务费比例不能高于目标下级'); } if ($ratio > MiningMachine::where('id', $mid)->value('service_ratio')) { return app('json')->fail('服务费比例不能高于系统设置'); } if (UserMiningService::where('mid', $mid)->where('uid', $uid)->find()) { $res = UserMiningService::where('mid', $mid)->where('uid', $uid) ->update(['ratio' => $ratio, 'update_time' => time(), 'update_uid' => $request->uid()]); } else { $res = UserMiningService::create([ 'uid' => $uid, 'mid' => $mid, 'ratio' => $ratio, 'add_time' => time(), 'update_time' => time(), 'update_uid' => $request->uid(), ]); } if ($res) { return app('json')->success('修改成功'); } else { return app('json')->fail('修改失败或者您没有修改什么'); } } public static function userBillInfo(Request $request) { $achievement = function ($uid) { $uids = [$uid]; $all = []; while ($uids) { $uids = User::where('spread_uid', 'in', $uids)->column('uid'); $all = array_merge($all, $uids); } //var_dump($all); return LalaPinkJoin::where('paid', 1)->where('status', 'in', [1, 2])->where('uid', '<>', 0)->where('uid', 'in', $all)->where('cost_money_type', 'USDT')->sum('cost'); }; $small_achivement = function ($uid) { $sub_uids = User::where('spread_uid', $uid)->column('uid'); $max = 0; $all = 0; foreach ($sub_uids as $v) { $uids = [$v]; $all_uids = [$v]; while ($uids) { $uids = \app\admin\model\user\User::where('spread_uid', 'in', $uids)->column('uid'); $all_uids = array_merge($all_uids, $uids); } $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'); if ($achievement > $max) $max = $achievement; $all += $achievement; } return $all - $max; }; $achievement_month = function ($uid) { $uids = [$uid]; $all = []; while ($uids) { $uids = User::where('spread_uid', 'in', $uids)->column('uid'); $all = array_merge($all, $uids); } //var_dump($all); 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'); }; $small_achivement_month = function ($uid) { $sub_uids = User::where('spread_uid', $uid)->column('uid'); $max = 0; $all = 0; foreach ($sub_uids as $v) { $uids = [$v]; $all_uids = [$v]; while ($uids) { $uids = \app\admin\model\user\User::where('spread_uid', 'in', $uids)->column('uid'); $all_uids = array_merge($all_uids, $uids); } $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'); if ($achievement > $max) $max = $achievement; $all += $achievement; } return $all - $max; }; $group_num = function ($uid) { $uids = [$uid]; $all = []; while ($uids) { $uids = User::where('spread_uid', 'in', $uids)->column('uid'); $all = array_merge($all, $uids); } return count($all); }; $res['achievement'] = $achievement($request->uid()); $res['achievement_month'] = $achievement_month($request->uid()); $res['group_num'] = $group_num($request->uid()); $res['small_achivement'] = $small_achivement($request->uid()); $res['small_achivement_month'] = $small_achivement_month($request->uid()); $res['recommend_num'] = User::where('spread_uid', $request->uid())->count(); $res['yesterday'] = [ '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)'), '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)'), '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)'), ]; $res['today'] = [ '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)'), '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)'), '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)'), ]; $res['all'] = [ 'pink' => UserBill::where('uid', $request->uid())->where('category', 'USDT')->where('type', 'in', ['join_award'])->where('pm', 1)->where('status', 1)->value('SUM(number)'), 'recommend' => UserBill::where('uid', $request->uid())->where('category', 'USDT')->where('type', 'in', ['lala_recommend_award'])->where('pm', 1)->where('status', 1)->value('SUM(number)'), '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)'), ]; return app('json')->success('ok', $res); } }