<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Member\Util; use Illuminate\Database\Eloquent\Model; use ModStart\Core\Exception\BizException; use ModStart\Core\Util\FileUtil; use ModStart\Module\ModuleManager; use Module\Member\Model\MemberDataStatistic; use Module\Member\Model\MemberUpload; class MemberDataStatisticUtil { public static function checkQuota($shbIl) { goto Hw6ON; l8dv3: BizException::throwsIfEmpty('获取用户数据统计失败', $lLaeU); goto QhDqN; qGegK: if ($lLaeU['sizeUsed'] >= $GdEuu) { BizException::throws('您的上传空间已满，最多可以上传' . FileUtil::formatByte($GdEuu)); } goto xjqEH; Hw6ON: if (!$shbIl) { BizException::throws('请先登录'); } goto HNHkJ; QhDqN: $GdEuu = $lLaeU['sizeLimit'] * 1024 * 1024; goto qGegK; yM_TU: $lLaeU = MemberDataStatistic::getCreateMemberUser($shbIl); goto l8dv3; HNHkJ: if (!ModuleManager::getModuleConfig('Member', 'dataStatisticEnable', false) || !modstart_config('Member_DataStatisticEnable', false)) { return; } goto yM_TU; xjqEH: } public static function getCreateMemberUser($gZ39D) { goto ylXLX; ylXLX: $rBX9E = MemberDataStatistic::where('id', $gZ39D)->first(); goto n1YOD; e226o: return $rBX9E->toArray(); goto OG8dV; n1YOD: if (empty($rBX9E)) { goto enahn; w634u: self::updateMemberUserUsedSize($gZ39D); goto ua0qw; mzMA8: $QjHVP->sizeLimit = modstart_config('Member_DataStatisticDefaultLimit', 1024); goto nsRcE; nsRcE: $QjHVP->save(); goto w634u; ua0qw: return self::getCreateMemberUser($gZ39D); goto Yxywu; enahn: $QjHVP = new MemberDataStatistic(); goto uUrt2; uUrt2: $QjHVP->id = $gZ39D; goto mzMA8; Yxywu: } goto e226o; OG8dV: } public static function updateMemberUser($gZ39D, $avcnU) { goto nVJrP; zJeFJ: $ZjBZH = false; goto ucQsR; ucQsR: if (empty($QjHVP)) { goto rh2E5; iQ4RU: $QjHVP->id = $gZ39D; goto Vzbvp; rh2E5: $QjHVP = new MemberDataStatistic(); goto iQ4RU; Vzbvp: $ZjBZH = true; goto BkhIe; BkhIe: } goto d_O33; urAxL: $QjHVP->save(); goto PaafC; d_O33: foreach ($avcnU as $KAKiA => $Iim2u) { $QjHVP->{$KAKiA} = $Iim2u; } goto urAxL; nVJrP: $QjHVP = MemberDataStatistic::where('id', $gZ39D)->first(); goto zJeFJ; PaafC: if ($ZjBZH) { self::updateMemberUserUsedSize($gZ39D); } goto MkXU9; MkXU9: } public static function calcMemberUserUsedSize($gZ39D) { $mAmuv = MemberUpload::where(array('userId' => $gZ39D))->leftJoin('data', 'data.id', '=', 'member_upload.dataId')->sum('data.size'); return intval($mAmuv); } public static function updateMemberUserUsedSize($gZ39D) { $Gszjy = array('sizeUsed' => self::calcMemberUserUsedSize($gZ39D)); MemberDataStatistic::where('id', $gZ39D)->update($Gszjy); } }