123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- <?php
- namespace app\api\controller\user;
- use app\admin\model\system\SystemAttachment;
- use app\models\routine\RoutineCode;
- use app\models\routine\RoutineQrcode;
- use app\models\store\StoreOrder;
- use app\models\user\User;
- use app\models\user\UserBill;
- use app\models\user\UserExtract;
- use app\Request;
- use crmeb\services\GroupDataService;
- use crmeb\services\QrcodeService;
- use crmeb\services\SystemConfigService;
- use crmeb\services\UtilService;
- use crmeb\services\upload\Upload;
- class UserBillController
- {
-
- public function commission(Request $request)
- {
- $uid = $request->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);
- }
-
- 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);
- }
-
- 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);
- }
-
- 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));
- }
-
- 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]);
- }
-
- 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) {
-
- $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) {
- try {
- $qr_code = QrcodeService::getForeverQrcode('spread', $user['uid']);
- if (isset($qr_code['url'])) {
- $urlCode = $qr_code['url'];
- } else {
- $codeUrl = set_http_type($siteUrl . '?spread=' . $user['uid'], 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'];
- }
- } catch (\Exception $e) {
- $codeUrl = set_http_type($siteUrl . '?spread=' . $user['uid'], 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' => 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']
- );
- $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()]);
- }
- }
-
- public function integral_list(Request $request)
- {
- list($page, $limit, $status) = UtilService::getMore([
- ['page', 0], ['limit', 0], ['pm', 0]
- ], $request, true);
- return app('json')->successful(UserBill::userBillList($request->uid(), $page, $limit, 'integral', ['pm' => $status]));
- }
- }
|