|
@@ -44,60 +44,80 @@ use Validator;
|
|
|
*
|
|
|
* @package App\Http\Controllers
|
|
|
*/
|
|
|
-class UserController extends Controller
|
|
|
-{
|
|
|
+class UserController extends Controller {
|
|
|
protected static $systemConfig;
|
|
|
|
|
|
- function __construct()
|
|
|
- {
|
|
|
+ function __construct() {
|
|
|
self::$systemConfig = Helpers::systemConfig();
|
|
|
}
|
|
|
|
|
|
- public function index()
|
|
|
- {
|
|
|
+ public function index() {
|
|
|
$totalTransfer = Auth::user()->transfer_enable;
|
|
|
- $usedTransfer = Auth::user()->u+Auth::user()->d;
|
|
|
- $unusedTransfer = $totalTransfer-$usedTransfer > 0? $totalTransfer-$usedTransfer : 0;
|
|
|
+ $usedTransfer = Auth::user()->u + Auth::user()->d;
|
|
|
+ $unusedTransfer = $totalTransfer - $usedTransfer > 0? $totalTransfer - $usedTransfer : 0;
|
|
|
$expireTime = Auth::user()->expire_time;
|
|
|
- $view['remainDays'] = $expireTime < date('Y-m-d')? -1 : (strtotime($expireTime)-strtotime(date('Y-m-d')))/86400;
|
|
|
- $view['resetDays'] = Auth::user()->reset_time? round((strtotime(Auth::user()->reset_time)-strtotime(date('Y-m-d')))/86400) : 0;
|
|
|
+ $view['remainDays'] = $expireTime < date('Y-m-d')? -1 : (strtotime($expireTime) - strtotime(date('Y-m-d'))) / 86400;
|
|
|
+ $view['resetDays'] = Auth::user()->reset_time? round((strtotime(Auth::user()->reset_time) - strtotime(date('Y-m-d'))) / 86400) : 0;
|
|
|
$view['unusedTransfer'] = $unusedTransfer;
|
|
|
$view['expireTime'] = $expireTime;
|
|
|
$view['banedTime'] = Auth::user()->ban_time? date('Y-m-d H:i:s', Auth::user()->ban_time) : 0;
|
|
|
- $view['unusedPercent'] = $totalTransfer > 0? round($unusedTransfer/$totalTransfer, 2) : 0;
|
|
|
+ $view['unusedPercent'] = $totalTransfer > 0? round($unusedTransfer / $totalTransfer, 2) : 0;
|
|
|
$view['noticeList'] = Article::type(2)->orderBy('id', 'desc')->Paginate(1); // 公告
|
|
|
//流量异常判断
|
|
|
- $hourlyTraffic = UserTrafficHourly::query()->whereUserId(Auth::user()->id)->whereNodeId(0)->where('created_at', '>=', date('Y-m-d H:i:s', time()-3900))->sum('total');
|
|
|
- $view['isTrafficWarning'] = $hourlyTraffic >= (self::$systemConfig['traffic_ban_value']*1073741824)? : 0;
|
|
|
+ $hourlyTraffic = UserTrafficHourly::query()
|
|
|
+ ->whereUserId(Auth::user()->id)
|
|
|
+ ->whereNodeId(0)
|
|
|
+ ->where('created_at', '>=', date('Y-m-d H:i:s', time() - 3900))
|
|
|
+ ->sum('total');
|
|
|
+ $view['isTrafficWarning'] = $hourlyTraffic >= (self::$systemConfig['traffic_ban_value'] * 1073741824)?: 0;
|
|
|
//付费用户判断
|
|
|
- $view['not_paying_user'] = Order::uid()->whereStatus(2)->whereIsExpire(0)->where('origin_amount', '>', 0)->doesntExist();
|
|
|
- $view['userLoginLog'] = UserLoginLog::query()->whereUserId(Auth::user()->id)->orderBy('id', 'desc')->first(); // 近期登录日志
|
|
|
+ $view['not_paying_user'] = Order::uid()
|
|
|
+ ->whereStatus(2)
|
|
|
+ ->whereIsExpire(0)
|
|
|
+ ->where('origin_amount', '>', 0)
|
|
|
+ ->doesntExist();
|
|
|
+ $view['userLoginLog'] = UserLoginLog::query()
|
|
|
+ ->whereUserId(Auth::user()->id)
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
+ ->first(); // 近期登录日志
|
|
|
|
|
|
$dailyData = [];
|
|
|
$hourlyData = [];
|
|
|
|
|
|
// 节点一个月内的流量
|
|
|
// TODO:有bug
|
|
|
- $userTrafficDaily = UserTrafficDaily::query()->whereUserId(Auth::user()->id)->whereNodeId(0)->where('created_at', '<=', date('Y-m-d', time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
|
|
|
-
|
|
|
- $dailyTotal = date('d', time())-1; // 今天不算,减一
|
|
|
+ $userTrafficDaily = UserTrafficDaily::query()
|
|
|
+ ->whereUserId(Auth::user()->id)
|
|
|
+ ->whereNodeId(0)
|
|
|
+ ->where('created_at', '<=', date('Y-m-d', time()))
|
|
|
+ ->orderBy('created_at', 'asc')
|
|
|
+ ->pluck('total')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $dailyTotal = date('d', time()) - 1; // 今天不算,减一
|
|
|
$dailyCount = count($userTrafficDaily);
|
|
|
- for($x = 0; $x < $dailyTotal-$dailyCount; $x++){
|
|
|
+ for($x = 0; $x < $dailyTotal - $dailyCount; $x++){
|
|
|
$dailyData[$x] = 0;
|
|
|
}
|
|
|
- for($x = $dailyTotal-$dailyCount; $x < $dailyTotal; $x++){
|
|
|
- $dailyData[$x] = round($userTrafficDaily[$x-($dailyTotal-$dailyCount)]/(1024*1024*1024), 3);
|
|
|
+ for($x = $dailyTotal - $dailyCount; $x < $dailyTotal; $x++){
|
|
|
+ $dailyData[$x] = round($userTrafficDaily[$x - ($dailyTotal - $dailyCount)] / (1024 * 1024 * 1024), 3);
|
|
|
}
|
|
|
|
|
|
// 节点一天内的流量
|
|
|
- $userTrafficHourly = UserTrafficHourly::query()->whereUserId(Auth::user()->id)->whereNodeId(0)->where('created_at', '>=', date('Y-m-d', time()))->orderBy('created_at', 'asc')->pluck('total')->toArray();
|
|
|
+ $userTrafficHourly = UserTrafficHourly::query()
|
|
|
+ ->whereUserId(Auth::user()->id)
|
|
|
+ ->whereNodeId(0)
|
|
|
+ ->where('created_at', '>=', date('Y-m-d', time()))
|
|
|
+ ->orderBy('created_at', 'asc')
|
|
|
+ ->pluck('total')
|
|
|
+ ->toArray();
|
|
|
$hourlyTotal = date('H');
|
|
|
$hourlyCount = count($userTrafficHourly);
|
|
|
- for($x = 0; $x < $hourlyTotal-$hourlyCount; $x++){
|
|
|
+ for($x = 0; $x < $hourlyTotal - $hourlyCount; $x++){
|
|
|
$hourlyData[$x] = 0;
|
|
|
}
|
|
|
- for($x = ($hourlyTotal-$hourlyCount); $x < $hourlyTotal; $x++){
|
|
|
- $hourlyData[$x] = round($userTrafficHourly[$x-($hourlyTotal-$hourlyCount)]/(1024*1024*1024), 3);
|
|
|
+ for($x = ($hourlyTotal - $hourlyCount); $x < $hourlyTotal; $x++){
|
|
|
+ $hourlyData[$x] = round($userTrafficHourly[$x - ($hourlyTotal - $hourlyCount)] / (1024 * 1024 * 1024), 3);
|
|
|
}
|
|
|
|
|
|
// 本月天数数据
|
|
@@ -120,8 +140,7 @@ class UserController extends Controller
|
|
|
}
|
|
|
|
|
|
// 签到
|
|
|
- public function checkIn()
|
|
|
- {
|
|
|
+ public function checkIn() {
|
|
|
// 系统开启登录加积分功能才可以签到
|
|
|
if(!self::$systemConfig['is_checkin']){
|
|
|
return Response::json(['status' => 'fail', 'message' => '系统未开启签到功能']);
|
|
@@ -132,25 +151,26 @@ class UserController extends Controller
|
|
|
return Response::json(['status' => 'fail', 'message' => '已经签到过了,明天再来吧']);
|
|
|
}
|
|
|
|
|
|
- $traffic = mt_rand((int)self::$systemConfig['min_rand_traffic'], (int)self::$systemConfig['max_rand_traffic'])*1048576;
|
|
|
+ $traffic = mt_rand((int) self::$systemConfig['min_rand_traffic'],
|
|
|
+ (int) self::$systemConfig['max_rand_traffic']) * 1048576;
|
|
|
$ret = User::uid()->increment('transfer_enable', $traffic);
|
|
|
if(!$ret){
|
|
|
return Response::json(['status' => 'fail', 'message' => '签到失败,系统异常']);
|
|
|
}
|
|
|
|
|
|
// 写入用户流量变动记录
|
|
|
- Helpers::addUserTrafficModifyLog(Auth::user()->id, 0, Auth::user()->transfer_enable, Auth::user()->transfer_enable+$traffic, '[签到]');
|
|
|
+ Helpers::addUserTrafficModifyLog(Auth::user()->id, 0, Auth::user()->transfer_enable,
|
|
|
+ Auth::user()->transfer_enable + $traffic, '[签到]');
|
|
|
|
|
|
// 多久后可以再签到
|
|
|
- $ttl = self::$systemConfig['traffic_limit_time']? self::$systemConfig['traffic_limit_time']*60 : 86400;
|
|
|
+ $ttl = self::$systemConfig['traffic_limit_time']? self::$systemConfig['traffic_limit_time'] * 60 : 86400;
|
|
|
Cache::put('userCheckIn_'.Auth::user()->id, '1', $ttl);
|
|
|
|
|
|
return Response::json(['status' => 'success', 'message' => '签到成功,系统送您 '.flowAutoShow($traffic).'流量']);
|
|
|
}
|
|
|
|
|
|
// 节点列表
|
|
|
- public function nodeList(Request $request)
|
|
|
- {
|
|
|
+ public function nodeList(Request $request) {
|
|
|
if($request->isMethod('POST')){
|
|
|
$node_id = $request->input('id');
|
|
|
$infoType = $request->input('type');
|
|
@@ -165,20 +185,36 @@ class UserController extends Controller
|
|
|
// 获取当前用户标签
|
|
|
$userLabelIds = UserLabel::uid()->pluck('label_id');
|
|
|
// 获取当前用户可用节点
|
|
|
- $nodeList = SsNode::query()->selectRaw('ss_node.*')->leftJoin('ss_node_label', 'ss_node.id', '=', 'ss_node_label.node_id')->whereIn('ss_node_label.label_id', $userLabelIds)->where('ss_node.status', 1)->groupBy('ss_node.id')->orderBy('ss_node.sort', 'desc')->orderBy('ss_node.id', 'asc')->get();
|
|
|
+ $nodeList = SsNode::query()
|
|
|
+ ->selectRaw('ss_node.*')
|
|
|
+ ->leftJoin('ss_node_label', 'ss_node.id', '=', 'ss_node_label.node_id')
|
|
|
+ ->whereIn('ss_node_label.label_id', $userLabelIds)
|
|
|
+ ->where('ss_node.status', 1)
|
|
|
+ ->groupBy('ss_node.id')
|
|
|
+ ->orderBy('ss_node.sort', 'desc')
|
|
|
+ ->orderBy('ss_node.id', 'asc')
|
|
|
+ ->get();
|
|
|
|
|
|
foreach($nodeList as $node){
|
|
|
- $node->ct = number_format(SsNodePing::query()->whereNodeId($node->id)->where('ct', '>', '0')->avg('ct'), 1, '.', '');
|
|
|
- $node->cu = number_format(SsNodePing::query()->whereNodeId($node->id)->where('cu', '>', '0')->avg('cu'), 1, '.', '');
|
|
|
- $node->cm = number_format(SsNodePing::query()->whereNodeId($node->id)->where('cm', '>', '0')->avg('cm'), 1, '.', '');
|
|
|
- $node->hk = number_format(SsNodePing::query()->whereNodeId($node->id)->where('hk', '>', '0')->avg('hk'), 1, '.', '');
|
|
|
+ $node->ct = number_format(SsNodePing::query()->whereNodeId($node->id)->where('ct', '>', '0')->avg('ct'),
|
|
|
+ 1, '.', '');
|
|
|
+ $node->cu = number_format(SsNodePing::query()->whereNodeId($node->id)->where('cu', '>', '0')->avg('cu'),
|
|
|
+ 1, '.', '');
|
|
|
+ $node->cm = number_format(SsNodePing::query()->whereNodeId($node->id)->where('cm', '>', '0')->avg('cm'),
|
|
|
+ 1, '.', '');
|
|
|
+ $node->hk = number_format(SsNodePing::query()->whereNodeId($node->id)->where('hk', '>', '0')->avg('hk'),
|
|
|
+ 1, '.', '');
|
|
|
|
|
|
// 节点在线状态
|
|
|
- $node->offline = SsNodeInfo::query()->whereNodeId($node->id)->where('log_time', '>=', strtotime("-10 minutes"))->orderBy('id', 'desc')->doesntExist();
|
|
|
+ $node->offline = SsNodeInfo::query()
|
|
|
+ ->whereNodeId($node->id)
|
|
|
+ ->where('log_time', '>=', strtotime("-10 minutes"))
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
+ ->doesntExist();
|
|
|
// 节点标签
|
|
|
$node->labels = SsNodeLabel::query()->whereNodeId($node->id)->first();
|
|
|
}
|
|
|
- $view['nodeList'] = $nodeList? : [];
|
|
|
+ $view['nodeList'] = $nodeList?: [];
|
|
|
}
|
|
|
|
|
|
|
|
@@ -186,16 +222,14 @@ class UserController extends Controller
|
|
|
}
|
|
|
|
|
|
// 公告详情
|
|
|
- public function article(Request $request)
|
|
|
- {
|
|
|
+ public function article(Request $request) {
|
|
|
$view['info'] = Article::query()->findOrFail($request->input('id'));
|
|
|
|
|
|
return Response::view('user.article', $view);
|
|
|
}
|
|
|
|
|
|
// 修改个人资料
|
|
|
- public function profile(Request $request)
|
|
|
- {
|
|
|
+ public function profile(Request $request) {
|
|
|
if($request->isMethod('POST')){
|
|
|
$old_password = trim($request->input('old_password'));
|
|
|
$new_password = trim($request->input('new_password'));
|
|
@@ -250,26 +284,45 @@ class UserController extends Controller
|
|
|
}
|
|
|
|
|
|
// 商品列表
|
|
|
- public function services(Request $request)
|
|
|
- {
|
|
|
+ public function services(Request $request) {
|
|
|
// 余额充值商品,只取10个
|
|
|
- $view['chargeGoodsList'] = Goods::type(3)->whereStatus(1)->orderBy('price', 'asc')->orderBy('price', 'asc')->limit(10)->get();
|
|
|
- $view['goodsList'] = Goods::query()->whereStatus(1)->where('type', '<=', '2')->orderBy('type', 'desc')->orderBy('sort', 'desc')->paginate(10)->appends($request->except('page'));
|
|
|
- $renewOrder = Order::query()->with(['goods'])->whereUserId(Auth::user()->id)->whereStatus(2)->whereIsExpire(0)->whereHas('goods', function($q){ $q->whereType(2); })->first();
|
|
|
+ $view['chargeGoodsList'] = Goods::type(3)
|
|
|
+ ->whereStatus(1)
|
|
|
+ ->orderBy('price', 'asc')
|
|
|
+ ->orderBy('price', 'asc')
|
|
|
+ ->limit(10)
|
|
|
+ ->get();
|
|
|
+ $view['goodsList'] = Goods::query()
|
|
|
+ ->whereStatus(1)
|
|
|
+ ->where('type', '<=', '2')
|
|
|
+ ->orderBy('type', 'desc')
|
|
|
+ ->orderBy('sort', 'desc')
|
|
|
+ ->paginate(10)
|
|
|
+ ->appends($request->except('page'));
|
|
|
+ $renewOrder = Order::query()
|
|
|
+ ->with(['goods'])
|
|
|
+ ->whereUserId(Auth::user()->id)
|
|
|
+ ->whereStatus(2)
|
|
|
+ ->whereIsExpire(0)
|
|
|
+ ->whereHas('goods', function($q) {
|
|
|
+ $q->whereType(2);
|
|
|
+ })
|
|
|
+ ->first();
|
|
|
$renewPrice = $renewOrder? Goods::query()->whereId($renewOrder->goods_id)->first() : 0;
|
|
|
$view['renewTraffic'] = $renewPrice? $renewPrice->renew : 0;
|
|
|
// 有重置日时按照重置日为标准,否者就以过期日为标准
|
|
|
$dataPlusDays = Auth::user()->reset_time? Auth::user()->reset_time : Auth::user()->expire_time;
|
|
|
- $view['dataPlusDays'] = $dataPlusDays > date('Y-m-d')? round((strtotime($dataPlusDays)-strtotime(date('Y-m-d')))/86400) : 0;
|
|
|
+ $view['dataPlusDays'] = $dataPlusDays > date('Y-m-d')? round((strtotime($dataPlusDays) - strtotime(date('Y-m-d'))) / 86400) : 0;
|
|
|
$view['purchaseHTML'] = PaymentController::purchaseHTML();
|
|
|
|
|
|
return Response::view('user.services', $view);
|
|
|
}
|
|
|
|
|
|
//重置流量
|
|
|
- public function resetUserTraffic()
|
|
|
- {
|
|
|
- $temp = Order::uid()->whereStatus(2)->whereIsExpire(0)->with(['goods'])->whereHas('goods', function($q){ $q->whereType(2); })->first();
|
|
|
+ public function resetUserTraffic() {
|
|
|
+ $temp = Order::uid()->whereStatus(2)->whereIsExpire(0)->with(['goods'])->whereHas('goods', function($q) {
|
|
|
+ $q->whereType(2);
|
|
|
+ })->first();
|
|
|
$renewCost = Goods::query()->whereId($temp->goods_id)->first()->renew;
|
|
|
if(Auth::user()->balance < $renewCost){
|
|
|
return Response::json(['status' => 'fail', 'data' => '', 'message' => '余额不足,请充值余额']);
|
|
@@ -277,33 +330,35 @@ class UserController extends Controller
|
|
|
User::uid()->update(['u' => 0, 'd' => 0]);
|
|
|
|
|
|
// 扣余额
|
|
|
- User::query()->whereId(Auth::user()->id)->decrement('balance', $renewCost*100);
|
|
|
+ User::query()->whereId(Auth::user()->id)->decrement('balance', $renewCost * 100);
|
|
|
|
|
|
// 记录余额操作日志
|
|
|
- Helpers::addUserBalanceLog(Auth::user()->id, '', Auth::user()->balance, Auth::user()->balance-$renewCost, -1*$renewCost, '用户自行重置流量');
|
|
|
+ Helpers::addUserBalanceLog(Auth::user()->id, '', Auth::user()->balance, Auth::user()->balance - $renewCost,
|
|
|
+ -1 * $renewCost, '用户自行重置流量');
|
|
|
|
|
|
return Response::json(['status' => 'success', 'data' => '', 'message' => '重置成功']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 工单
|
|
|
- public function ticketList(Request $request)
|
|
|
- {
|
|
|
+ public function ticketList(Request $request) {
|
|
|
$view['ticketList'] = Ticket::uid()->orderBy('id', 'desc')->paginate(10)->appends($request->except('page'));
|
|
|
|
|
|
return Response::view('user.ticketList', $view);
|
|
|
}
|
|
|
|
|
|
// 订单
|
|
|
- public function invoices(Request $request)
|
|
|
- {
|
|
|
- $view['orderList'] = Order::uid()->with(['user', 'goods', 'coupon', 'payment'])->orderBy('oid', 'desc')->paginate(10)->appends($request->except('page'));
|
|
|
+ public function invoices(Request $request) {
|
|
|
+ $view['orderList'] = Order::uid()
|
|
|
+ ->with(['user', 'goods', 'coupon', 'payment'])
|
|
|
+ ->orderBy('oid', 'desc')
|
|
|
+ ->paginate(10)
|
|
|
+ ->appends($request->except('page'));
|
|
|
|
|
|
return Response::view('user.invoices', $view);
|
|
|
}
|
|
|
|
|
|
- public function activeOrder(Request $request)
|
|
|
- {
|
|
|
+ public function activeOrder(Request $request) {
|
|
|
$oid = $request->input('oid');
|
|
|
$prepaidOrder = Order::query()->whereOid($oid)->first();
|
|
|
if(!$prepaidOrder){
|
|
@@ -318,16 +373,14 @@ class UserController extends Controller
|
|
|
}
|
|
|
|
|
|
// 订单明细
|
|
|
- public function invoiceDetail($sn)
|
|
|
- {
|
|
|
+ public function invoiceDetail($sn) {
|
|
|
$view['order'] = Order::uid()->with(['goods', 'coupon', 'payment'])->whereOrderSn($sn)->firstOrFail();
|
|
|
|
|
|
return Response::view('user.invoiceDetail', $view);
|
|
|
}
|
|
|
|
|
|
// 添加工单
|
|
|
- public function addTicket(Request $request)
|
|
|
- {
|
|
|
+ public function addTicket(Request $request) {
|
|
|
$title = $request->input('title');
|
|
|
$content = clean($request->input('content'));
|
|
|
$content = str_replace("eval", "", str_replace("atob", "", $content));
|
|
@@ -362,8 +415,7 @@ class UserController extends Controller
|
|
|
}
|
|
|
|
|
|
// 回复工单
|
|
|
- public function replyTicket(Request $request)
|
|
|
- {
|
|
|
+ public function replyTicket(Request $request) {
|
|
|
$id = $request->input('id');
|
|
|
|
|
|
$ticket = Ticket::uid()->with('user')->whereId($id)->firstOrFail();
|
|
@@ -416,8 +468,7 @@ class UserController extends Controller
|
|
|
}
|
|
|
|
|
|
// 关闭工单
|
|
|
- public function closeTicket(Request $request)
|
|
|
- {
|
|
|
+ public function closeTicket(Request $request) {
|
|
|
$id = $request->input('id');
|
|
|
|
|
|
$ret = Ticket::uid()->whereId($id)->update(['status' => 2]);
|
|
@@ -431,23 +482,22 @@ class UserController extends Controller
|
|
|
}
|
|
|
|
|
|
// 邀请码
|
|
|
- public function invite()
|
|
|
- {
|
|
|
+ public function invite() {
|
|
|
if(Order::uid()->whereStatus(2)->whereIsExpire(0)->where('origin_amount', '>', 0)->doesntExist()){
|
|
|
- return Response::view('auth.error', ['message' => '本功能对非付费用户禁用!请 <a class="btn btn-sm btn-danger" href="/">返 回</a>']);
|
|
|
+ return Response::view('auth.error',
|
|
|
+ ['message' => '本功能对非付费用户禁用!请 <a class="btn btn-sm btn-danger" href="/">返 回</a>']);
|
|
|
}
|
|
|
|
|
|
$view['num'] = Auth::user()->invite_num; // 还可以生成的邀请码数量
|
|
|
$view['inviteList'] = Invite::uid()->with(['generator', 'user'])->paginate(10); // 邀请码列表
|
|
|
- $view['referral_traffic'] = flowAutoShow(self::$systemConfig['referral_traffic']*1048576);
|
|
|
+ $view['referral_traffic'] = flowAutoShow(self::$systemConfig['referral_traffic'] * 1048576);
|
|
|
$view['referral_percent'] = self::$systemConfig['referral_percent'];
|
|
|
|
|
|
return Response::view('user.invite', $view);
|
|
|
}
|
|
|
|
|
|
// 生成邀请码
|
|
|
- public function makeInvite()
|
|
|
- {
|
|
|
+ public function makeInvite() {
|
|
|
if(Auth::user()->invite_num <= 0){
|
|
|
return Response::json(['status' => 'fail', 'data' => '', 'message' => '生成失败:已无邀请码生成名额']);
|
|
|
}
|
|
@@ -466,8 +516,7 @@ class UserController extends Controller
|
|
|
}
|
|
|
|
|
|
// 使用优惠券
|
|
|
- public function redeemCoupon(Request $request)
|
|
|
- {
|
|
|
+ public function redeemCoupon(Request $request) {
|
|
|
$coupon_sn = $request->input('coupon_sn');
|
|
|
$good_price = $request->input('price');
|
|
|
|
|
@@ -493,22 +542,33 @@ class UserController extends Controller
|
|
|
return Response::json(['status' => 'fail', 'title' => '使用条件未满足', 'message' => '请购买价格更高的套餐']);
|
|
|
}
|
|
|
|
|
|
- $data = ['name' => $coupon->name, 'type' => $coupon->type, 'amount' => $coupon->amount, 'discount' => $coupon->discount];
|
|
|
+ $data = [
|
|
|
+ 'name' => $coupon->name,
|
|
|
+ 'type' => $coupon->type,
|
|
|
+ 'amount' => $coupon->amount,
|
|
|
+ 'discount' => $coupon->discount
|
|
|
+ ];
|
|
|
|
|
|
return Response::json(['status' => 'success', 'data' => $data, 'message' => '优惠券有效']);
|
|
|
}
|
|
|
|
|
|
// 购买服务
|
|
|
- public function buy($goods_id)
|
|
|
- {
|
|
|
+ public function buy($goods_id) {
|
|
|
$goods = Goods::query()->whereId($goods_id)->whereStatus(1)->first();
|
|
|
if(empty($goods)){
|
|
|
return Redirect::to('services');
|
|
|
}
|
|
|
// 有重置日时按照重置日为标准,否者就以过期日为标准
|
|
|
$dataPlusDays = Auth::user()->reset_time? Auth::user()->reset_time : Auth::user()->expire_time;
|
|
|
- $view['dataPlusDays'] = $dataPlusDays > date('Y-m-d')? round((strtotime($dataPlusDays)-strtotime(date('Y-m-d')))/86400) : 0;
|
|
|
- $view['activePlan'] = Order::uid()->with(['goods'])->whereIsExpire(0)->whereStatus(2)->whereHas('goods', function($q){ $q->whereType(2); })->exists();
|
|
|
+ $view['dataPlusDays'] = $dataPlusDays > date('Y-m-d')? round((strtotime($dataPlusDays) - strtotime(date('Y-m-d'))) / 86400) : 0;
|
|
|
+ $view['activePlan'] = Order::uid()
|
|
|
+ ->with(['goods'])
|
|
|
+ ->whereIsExpire(0)
|
|
|
+ ->whereStatus(2)
|
|
|
+ ->whereHas('goods', function($q) {
|
|
|
+ $q->whereType(2);
|
|
|
+ })
|
|
|
+ ->exists();
|
|
|
$view['purchaseHTML'] = PaymentController::purchaseHTML();
|
|
|
$view['goods'] = $goods;
|
|
|
|
|
@@ -516,12 +576,15 @@ class UserController extends Controller
|
|
|
}
|
|
|
|
|
|
// 帮助中心
|
|
|
- public function help()
|
|
|
- {
|
|
|
+ public function help() {
|
|
|
$view['articleList'] = Article::type(1)->orderBy('sort', 'desc')->orderBy('id', 'desc')->limit(10)->paginate(5);
|
|
|
|
|
|
//付费用户判断
|
|
|
- $view['not_paying_user'] = Order::uid()->whereStatus(2)->whereIsExpire(0)->where('origin_amount', '>', 0)->doesntExist();
|
|
|
+ $view['not_paying_user'] = Order::uid()
|
|
|
+ ->whereStatus(2)
|
|
|
+ ->whereIsExpire(0)
|
|
|
+ ->where('origin_amount', '>', 0)
|
|
|
+ ->doesntExist();
|
|
|
//客户端安装
|
|
|
$view['Shadowrocket_install'] = 'itms-services://?action=download-manifest&url='.self::$systemConfig['website_url'].'/clients/Shadowrocket.plist';
|
|
|
$view['Quantumult_install'] = 'itms-services://?action=download-manifest&url='.self::$systemConfig['website_url'].'/clients/Quantumult.plist';
|
|
@@ -540,8 +603,7 @@ class UserController extends Controller
|
|
|
}
|
|
|
|
|
|
// 更换订阅地址
|
|
|
- public function exchangeSubscribe()
|
|
|
- {
|
|
|
+ public function exchangeSubscribe() {
|
|
|
DB::beginTransaction();
|
|
|
try{
|
|
|
// 更换订阅码
|
|
@@ -563,8 +625,7 @@ class UserController extends Controller
|
|
|
}
|
|
|
|
|
|
// 转换成管理员的身份
|
|
|
- public function switchToAdmin()
|
|
|
- {
|
|
|
+ public function switchToAdmin() {
|
|
|
if(!Session::has('admin')){
|
|
|
return Response::json(['status' => 'fail', 'data' => '', 'message' => '非法请求']);
|
|
|
}
|
|
@@ -577,14 +638,22 @@ class UserController extends Controller
|
|
|
}
|
|
|
|
|
|
// 卡券余额充值
|
|
|
- public function charge(Request $request)
|
|
|
- {
|
|
|
- $validator = Validator::make($request->all(), ['coupon_sn' => ['required', Rule::exists('coupon', 'sn')->where(function($query){
|
|
|
- $query->whereType(3)->whereStatus(0);
|
|
|
- }),]], ['coupon_sn.required' => '券码不能为空', 'coupon_sn.exists' => '该券不可用']);
|
|
|
+ public function charge(Request $request) {
|
|
|
+ $validator = Validator::make($request->all(), [
|
|
|
+ 'coupon_sn' => [
|
|
|
+ 'required',
|
|
|
+ Rule::exists('coupon', 'sn')->where(function($query) {
|
|
|
+ $query->whereType(3)->whereStatus(0);
|
|
|
+ }),
|
|
|
+ ]
|
|
|
+ ], ['coupon_sn.required' => '券码不能为空', 'coupon_sn.exists' => '该券不可用']);
|
|
|
|
|
|
if($validator->fails()){
|
|
|
- return Response::json(['status' => 'fail', 'data' => '', 'message' => $validator->getMessageBag()->first()]);
|
|
|
+ return Response::json([
|
|
|
+ 'status' => 'fail',
|
|
|
+ 'data' => '',
|
|
|
+ 'message' => $validator->getMessageBag()->first()
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
$coupon = Coupon::query()->whereSn($request->input('coupon_sn'))->first();
|
|
@@ -592,10 +661,12 @@ class UserController extends Controller
|
|
|
try{
|
|
|
DB::beginTransaction();
|
|
|
// 写入日志
|
|
|
- Helpers::addUserBalanceLog(Auth::user()->id, 0, Auth::user()->balance, Auth::user()->balance+$coupon->amount, $coupon->amount, '用户手动充值 - [充值券:'.$request->input('coupon_sn').']');
|
|
|
+ Helpers::addUserBalanceLog(Auth::user()->id, 0, Auth::user()->balance,
|
|
|
+ Auth::user()->balance + $coupon->amount, $coupon->amount,
|
|
|
+ '用户手动充值 - [充值券:'.$request->input('coupon_sn').']');
|
|
|
|
|
|
// 余额充值
|
|
|
- User::uid()->increment('balance', $coupon->amount*100);
|
|
|
+ User::uid()->increment('balance', $coupon->amount * 100);
|
|
|
|
|
|
// 更改卡券状态
|
|
|
$coupon->status = 1;
|