mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 17:31:49 +08:00 
			
		
		
		
	| @@ -30,6 +30,25 @@ class CouponController extends Controller | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function show(Request $request) | ||||
|     { | ||||
|         if (empty($request->input('id'))) { | ||||
|             abort(500, '参数有误'); | ||||
|         } | ||||
|         $coupon = Coupon::find($request->input('id')); | ||||
|         if (!$coupon) { | ||||
|             abort(500, '优惠券不存在'); | ||||
|         } | ||||
|         $coupon->show = $coupon->show ? 0 : 1; | ||||
|         if (!$coupon->save()) { | ||||
|             abort(500, '保存失败'); | ||||
|         } | ||||
|  | ||||
|         return response([ | ||||
|             'data' => true | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function generate(CouponGenerate $request) | ||||
|     { | ||||
|         if ($request->input('generate_count')) { | ||||
| @@ -63,8 +82,6 @@ class CouponController extends Controller | ||||
|         $coupons = []; | ||||
|         $coupon = $request->validated(); | ||||
|         $coupon['created_at'] = $coupon['updated_at'] = time(); | ||||
|         $coupon['limit_plan_ids'] = json_encode($coupon['limit_plan_ids']); | ||||
|         $coupon['limit_period'] = json_encode($coupon['limit_period']); | ||||
|         unset($coupon['generate_count']); | ||||
|         for ($i = 0;$i < $request->input('generate_count');$i++) { | ||||
|             $coupon['code'] = Helper::randomChar(8); | ||||
| @@ -84,7 +101,7 @@ class CouponController extends Controller | ||||
|             $endTime = date('Y-m-d H:i:s', $coupon['ended_at']); | ||||
|             $limitUse = $coupon['limit_use'] ?? '不限制'; | ||||
|             $createTime = date('Y-m-d H:i:s', $coupon['created_at']); | ||||
|             $limitPlanIds = implode("/", json_decode($coupon['limit_plan_ids'], true)) ?? '不限制'; | ||||
|             $limitPlanIds = isset($coupon['limit_plan_ids']) ? implode("/", $coupon['limit_plan_ids']) : '不限制'; | ||||
|             $data .= "{$coupon['name']},{$type},{$value},{$startTime},{$endTime},{$limitUse},{$limitPlanIds},{$coupon['code']},{$createTime}\r\n"; | ||||
|         } | ||||
|         echo $data; | ||||
|   | ||||
| @@ -40,6 +40,27 @@ class NoticeController extends Controller | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|     public function show(Request $request) | ||||
|     { | ||||
|         if (empty($request->input('id'))) { | ||||
|             abort(500, '参数有误'); | ||||
|         } | ||||
|         $notice = Notice::find($request->input('id')); | ||||
|         if (!$notice) { | ||||
|             abort(500, '公告不存在'); | ||||
|         } | ||||
|         $notice->show = $notice->show ? 0 : 1; | ||||
|         if (!$notice->save()) { | ||||
|             abort(500, '保存失败'); | ||||
|         } | ||||
|  | ||||
|         return response([ | ||||
|             'data' => true | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function drop(Request $request) | ||||
|     { | ||||
|         if (empty($request->input('id'))) { | ||||
|   | ||||
| @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin; | ||||
| use App\Http\Requests\Admin\OrderAssign; | ||||
| use App\Http\Requests\Admin\OrderUpdate; | ||||
| use App\Http\Requests\Admin\OrderFetch; | ||||
| use App\Models\CommissionLog; | ||||
| use App\Services\OrderService; | ||||
| use App\Services\UserService; | ||||
| use App\Utils\Helper; | ||||
| @@ -36,6 +37,19 @@ class OrderController extends Controller | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public function detail(Request $request) | ||||
|     { | ||||
|         $order = Order::find($request->input('id')); | ||||
|         if (!$order) abort(500, '订单不存在'); | ||||
|         $order['commission_log'] = CommissionLog::where('trade_no', $order->trade_no)->get(); | ||||
|         if ($order->surplus_order_ids) { | ||||
|             $order['surplus_orders'] = Order::whereIn('id', $order->surplus_order_ids)->get(); | ||||
|         } | ||||
|         return response([ | ||||
|             'data' => $order | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function fetch(OrderFetch $request) | ||||
|     { | ||||
|         $current = $request->input('current') ? $request->input('current') : 1; | ||||
|   | ||||
| @@ -26,7 +26,12 @@ class PaymentController extends Controller | ||||
|     { | ||||
|         $payments = Payment::all(); | ||||
|         foreach ($payments as $k => $v) { | ||||
|             $payments[$k]['notify_url'] = url("/api/v1/guest/payment/notify/{$v->payment}/{$v->uuid}"); | ||||
|             $notifyUrl = url("/api/v1/guest/payment/notify/{$v->payment}/{$v->uuid}"); | ||||
|             if ($v->notify_domain) { | ||||
|                 $parseUrl = parse_url($notifyUrl); | ||||
|                 $notifyUrl = $v->notify_domain . $parseUrl['path']; | ||||
|             } | ||||
|             $payments[$k]['notify_url'] = $notifyUrl; | ||||
|         } | ||||
|         return response([ | ||||
|             'data' => $payments | ||||
| @@ -58,22 +63,20 @@ class PaymentController extends Controller | ||||
|                 'data' => true | ||||
|             ]); | ||||
|         } | ||||
|         $request->validate([ | ||||
|         $params = $request->validate([ | ||||
|             'name' => 'required', | ||||
|             'icon' => 'nullable', | ||||
|             'payment' => 'required', | ||||
|             'config' => 'required' | ||||
|             'config' => 'required', | ||||
|             'notify_domain' => 'nullable|url' | ||||
|         ], [ | ||||
|             'name.required' => '显示名称不能为空', | ||||
|             'payment.required' => '网关参数不能为空', | ||||
|             'config.required' => '配置参数不能为空' | ||||
|             'config.required' => '配置参数不能为空', | ||||
|             'notify_domain.url' => '自定义通知域名格式有误' | ||||
|         ]); | ||||
|         if (!Payment::create([ | ||||
|             'name' => $request->input('name'), | ||||
|             'icon' => $request->input('icon'), | ||||
|             'payment' => $request->input('payment'), | ||||
|             'config' => $request->input('config'), | ||||
|             'uuid' => Helper::randomChar(8) | ||||
|         ])) { | ||||
|         $params['uuid'] = Helper::randomChar(8); | ||||
|         if (!Payment::create($params)) { | ||||
|             abort(500, '保存失败'); | ||||
|         } | ||||
|         return response([ | ||||
|   | ||||
| @@ -31,9 +31,9 @@ class StatController extends Controller | ||||
|                 'month_register_total' => User::where('created_at', '>=', strtotime(date('Y-m-1'))) | ||||
|                     ->where('created_at', '<', time()) | ||||
|                     ->count(), | ||||
|                 'ticket_pendding_total' => Ticket::where('status', 0) | ||||
|                 'ticket_pending_total' => Ticket::where('status', 0) | ||||
|                     ->count(), | ||||
|                 'commission_pendding_total' => Order::where('commission_status', 0) | ||||
|                 'commission_pending_total' => Order::where('commission_status', 0) | ||||
|                     ->where('invite_user_id', '!=', NULL) | ||||
|                     ->whereNotIn('status', [0, 2]) | ||||
|                     ->where('commission_balance', '>', 0) | ||||
|   | ||||
							
								
								
									
										52
									
								
								app/Http/Controllers/Admin/SystemController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								app/Http/Controllers/Admin/SystemController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Http\Controllers\Admin; | ||||
|  | ||||
| use App\Models\ServerShadowsocks; | ||||
| use App\Models\ServerTrojan; | ||||
| use App\Services\ServerService; | ||||
| use App\Utils\CacheKey; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Http\Controllers\Controller; | ||||
| use App\Models\ServerGroup; | ||||
| use App\Models\ServerV2ray; | ||||
| use App\Models\Plan; | ||||
| use App\Models\User; | ||||
| use App\Models\Ticket; | ||||
| use App\Models\Order; | ||||
| use App\Models\StatOrder; | ||||
| use App\Models\StatServer; | ||||
| use Illuminate\Support\Facades\Cache; | ||||
| use Illuminate\Support\Facades\DB; | ||||
| use Illuminate\Support\Facades\Http; | ||||
| use Laravel\Horizon\Contracts\MasterSupervisorRepository; | ||||
|  | ||||
| class SystemController extends Controller | ||||
| { | ||||
|     public function getStatus() | ||||
|     { | ||||
|         return response([ | ||||
|             'data' => [ | ||||
|                 'schedule' => $this->getScheduleStatus(), | ||||
|                 'horizon' => $this->getHorizonStatus() | ||||
|             ] | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     protected function getScheduleStatus():bool | ||||
|     { | ||||
|         return (time() - 120) < Cache::get(CacheKey::get('SCHEDULE_LAST_CHECK_AT', null)); | ||||
|     } | ||||
|  | ||||
|     protected function getHorizonStatus():bool | ||||
|     { | ||||
|         if (! $masters = app(MasterSupervisorRepository::class)->all()) { | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
|         return collect($masters)->contains(function ($master) { | ||||
|             return $master->status === 'paused'; | ||||
|         }) ? false : true; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @@ -58,7 +58,11 @@ class UserController extends Controller | ||||
|         $pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10; | ||||
|         $sortType = in_array($request->input('sort_type'), ['ASC', 'DESC']) ? $request->input('sort_type') : 'DESC'; | ||||
|         $sort = $request->input('sort') ? $request->input('sort') : 'created_at'; | ||||
|         $userModel = User::orderBy($sort, $sortType); | ||||
|         $userModel = User::select( | ||||
|             DB::raw('*'), | ||||
|             DB::raw('(u+d) as total_used') | ||||
|         ) | ||||
|             ->orderBy($sort, $sortType); | ||||
|         $this->filter($request, $userModel); | ||||
|         $total = $userModel->count(); | ||||
|         $res = $userModel->forPage($current, $pageSize) | ||||
|   | ||||
| @@ -13,10 +13,6 @@ use Symfony\Component\Yaml\Yaml; | ||||
|  | ||||
| class AppController extends Controller | ||||
| { | ||||
|     CONST CLIENT_CONFIG = '{"policy":{"levels":{"0":{"uplinkOnly":0}}},"dns":{"servers":["114.114.114.114","8.8.8.8"]},"outboundDetour":[{"protocol":"freedom","tag":"direct","settings":{}}],"inbound":{"listen":"0.0.0.0","port":31211,"protocol":"socks","settings":{"auth":"noauth","udp":true,"ip":"127.0.0.1"}},"inboundDetour":[{"listen":"0.0.0.0","allocate":{"strategy":"always","refresh":5,"concurrency":3},"port":31210,"protocol":"http","tag":"httpDetour","domainOverride":["http","tls"],"streamSettings":{},"settings":{"timeout":0}}],"routing":{"strategy":"rules","settings":{"domainStrategy":"IPIfNonMatch","rules":[{"type":"field","ip":["geoip:cn"],"outboundTag":"direct"},{"type":"field","ip":["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.2.0/24","192.168.0.0/16","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","::1/128","fc00::/7","fe80::/10"],"outboundTag":"direct"}]}},"outbound":{"tag":"proxy","sendThrough":"0.0.0.0","mux":{"enabled":false,"concurrency":8},"protocol":"vmess","settings":{"vnext":[{"address":"server","port":443,"users":[{"id":"uuid","alterId":2,"security":"auto","level":0}],"remark":"remark"}]},"streamSettings":{"network":"tcp","tcpSettings":{"header":{"type":"none"}},"security":"none","tlsSettings":{"allowInsecure":true,"allowInsecureCiphers":true},"kcpSettings":{"header":{"type":"none"},"mtu":1350,"congestion":false,"tti":20,"uplinkCapacity":5,"writeBufferSize":1,"readBufferSize":1,"downlinkCapacity":20},"wsSettings":{"path":"","headers":{"Host":"server.cc"}}}}}'; | ||||
|     CONST SOCKS_PORT = 10010; | ||||
|     CONST HTTP_PORT = 10011; | ||||
|  | ||||
|     public function getConfig(Request $request) | ||||
|     { | ||||
|         $servers = []; | ||||
|   | ||||
| @@ -23,7 +23,7 @@ class Clash | ||||
|         $appName = config('v2board.app_name', 'V2Board'); | ||||
|         header("subscription-userinfo: upload={$user['u']}; download={$user['d']}; total={$user['transfer_enable']}; expire={$user['expired_at']}"); | ||||
|         header('profile-update-interval: 24'); | ||||
|         header("content-disposition: filename={$appName}"); | ||||
|         header("content-disposition:attachment;filename={$appName}"); | ||||
|         $defaultConfig = base_path() . '/resources/rules/default.clash.yaml'; | ||||
|         $customConfig = base_path() . '/resources/rules/custom.clash.yaml'; | ||||
|         if (\File::exists($customConfig)) { | ||||
| @@ -51,20 +51,21 @@ class Clash | ||||
|  | ||||
|         $config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy); | ||||
|         foreach ($config['proxy-groups'] as $k => $v) { | ||||
|             if (!is_array($config['proxy-groups'][$k]['proxies'])) continue; | ||||
|             if (!is_array($config['proxy-groups'][$k]['proxies'])) $config['proxy-groups'][$k]['proxies'] = []; | ||||
|             $isFilter = false; | ||||
|             foreach ($config['proxy-groups'][$k]['proxies'] as $src) { | ||||
|                 foreach ($proxies as $dst) { | ||||
|                     if (!$this->isRegex($src)) continue; | ||||
|                     $isFilter = true; | ||||
|                     $config['proxy-groups'][$k]['proxies'] = array_values(array_diff($config['proxy-groups'][$k]['proxies'], [$src])); | ||||
|                     if ($this->isMatch($src, $dst)) { | ||||
|                         $isFilter = true; | ||||
|                         $config['proxy-groups'][$k]['proxies'] = array_diff($config['proxy-groups'][$k]['proxies'], [$src]); | ||||
|                         array_push($config['proxy-groups'][$k]['proxies'], $dst); | ||||
|                     } | ||||
|                 } | ||||
|                 if ($isFilter) continue; | ||||
|             } | ||||
|             if (!$isFilter) { | ||||
|                 $config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies); | ||||
|             } | ||||
|             if ($isFilter) continue; | ||||
|             $config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies); | ||||
|         } | ||||
|         // Force the current subscription domain to be a direct rule | ||||
|         $subsDomain = $_SERVER['SERVER_NAME']; | ||||
| @@ -97,7 +98,7 @@ class Clash | ||||
|         $array['server'] = $server['host']; | ||||
|         $array['port'] = $server['port']; | ||||
|         $array['uuid'] = $uuid; | ||||
|         $array['alterId'] = $server['alter_id']; | ||||
|         $array['alterId'] = 0; | ||||
|         $array['cipher'] = 'auto'; | ||||
|         $array['udp'] = true; | ||||
|  | ||||
| @@ -115,6 +116,12 @@ class Clash | ||||
|             $array['network'] = 'ws'; | ||||
|             if ($server['networkSettings']) { | ||||
|                 $wsSettings = $server['networkSettings']; | ||||
|                 $array['ws-opts'] = []; | ||||
|                 if (isset($wsSettings['path']) && !empty($wsSettings['path'])) | ||||
|                     $array['ws-opts']['path'] = $wsSettings['path']; | ||||
|                 if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host'])) | ||||
|                     $array['ws-opts']['headers'] = ['Host' => $wsSettings['headers']['Host']]; | ||||
|                 // TODO: 2022.06.01 remove it | ||||
|                 if (isset($wsSettings['path']) && !empty($wsSettings['path'])) | ||||
|                     $array['ws-path'] = $wsSettings['path']; | ||||
|                 if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host'])) | ||||
| @@ -124,9 +131,9 @@ class Clash | ||||
|         if ($server['network'] === 'grpc') { | ||||
|             $array['network'] = 'grpc'; | ||||
|             if ($server['networkSettings']) { | ||||
|                 $grpcObject = $server['networkSettings']; | ||||
|                 $grpcSettings = $server['networkSettings']; | ||||
|                 $array['grpc-opts'] = []; | ||||
|                 $array['grpc-opts']['grpc-service-name'] = $grpcObject['serviceName']; | ||||
|                 $array['grpc-opts']['grpc-service-name'] = $grpcSettings['serviceName']; | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @@ -149,10 +156,11 @@ class Clash | ||||
|  | ||||
|     private function isMatch($exp, $str) | ||||
|     { | ||||
|         try { | ||||
|             return preg_match($exp, $str); | ||||
|         } catch (\Exception $e) { | ||||
|             return false; | ||||
|         } | ||||
|         return @preg_match($exp, $str); | ||||
|     } | ||||
|  | ||||
|     private function isRegex($exp) | ||||
|     { | ||||
|         return @preg_match($exp, null) !== false; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -54,7 +54,7 @@ class Passwall | ||||
|             "add" => $server['host'], | ||||
|             "port" => (string)$server['port'], | ||||
|             "id" => $uuid, | ||||
|             "aid" => (string)$server['alter_id'], | ||||
|             "aid" => '0', | ||||
|             "net" => $server['network'], | ||||
|             "type" => "none", | ||||
|             "host" => "", | ||||
|   | ||||
| @@ -54,7 +54,7 @@ class SSRPlus | ||||
|             "add" => $server['host'], | ||||
|             "port" => (string)$server['port'], | ||||
|             "id" => $uuid, | ||||
|             "aid" => (string)$server['alter_id'], | ||||
|             "aid" => '0', | ||||
|             "net" => $server['network'], | ||||
|             "type" => "none", | ||||
|             "host" => "", | ||||
|   | ||||
| @@ -58,7 +58,7 @@ class Shadowrocket | ||||
|         $config = [ | ||||
|             'tfo' => 1, | ||||
|             'remark' => $server['name'], | ||||
|             'alterId' => $server['alter_id'] | ||||
|             'alterId' => 0 | ||||
|         ]; | ||||
|         if ($server['tls']) { | ||||
|             $config['tls'] = 1; | ||||
|   | ||||
| @@ -56,16 +56,17 @@ class Stash | ||||
|             $isFilter = false; | ||||
|             foreach ($config['proxy-groups'][$k]['proxies'] as $src) { | ||||
|                 foreach ($proxies as $dst) { | ||||
|                     if (!$this->isRegex($src)) continue; | ||||
|                     $isFilter = true; | ||||
|                     $config['proxy-groups'][$k]['proxies'] = array_values(array_diff($config['proxy-groups'][$k]['proxies'], [$src])); | ||||
|                     if ($this->isMatch($src, $dst)) { | ||||
|                         $isFilter = true; | ||||
|                         $config['proxy-groups'][$k]['proxies'] = array_diff($config['proxy-groups'][$k]['proxies'], [$src]); | ||||
|                         array_push($config['proxy-groups'][$k]['proxies'], $dst); | ||||
|                     } | ||||
|                 } | ||||
|                 if ($isFilter) continue; | ||||
|             } | ||||
|             if (!$isFilter) { | ||||
|                 $config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies); | ||||
|             } | ||||
|             if ($isFilter) continue; | ||||
|             $config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies); | ||||
|         } | ||||
|         // Force the current subscription domain to be a direct rule | ||||
|         $subsDomain = $_SERVER['SERVER_NAME']; | ||||
| @@ -98,7 +99,7 @@ class Stash | ||||
|         $array['server'] = $server['host']; | ||||
|         $array['port'] = $server['port']; | ||||
|         $array['uuid'] = $uuid; | ||||
|         $array['alterId'] = $server['alter_id']; | ||||
|         $array['alterId'] = 0; | ||||
|         $array['cipher'] = 'auto'; | ||||
|         $array['udp'] = true; | ||||
|  | ||||
| @@ -116,6 +117,12 @@ class Stash | ||||
|             $array['network'] = 'ws'; | ||||
|             if ($server['networkSettings']) { | ||||
|                 $wsSettings = $server['networkSettings']; | ||||
|                 $array['ws-opts'] = []; | ||||
|                 if (isset($wsSettings['path']) && !empty($wsSettings['path'])) | ||||
|                     $array['ws-opts']['path'] = $wsSettings['path']; | ||||
|                 if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host'])) | ||||
|                     $array['ws-opts']['headers'] = ['Host' => $wsSettings['headers']['Host']]; | ||||
|                 // TODO: 2022.06.01 remove it | ||||
|                 if (isset($wsSettings['path']) && !empty($wsSettings['path'])) | ||||
|                     $array['ws-path'] = $wsSettings['path']; | ||||
|                 if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host'])) | ||||
| @@ -125,9 +132,9 @@ class Stash | ||||
|         if ($server['network'] === 'grpc') { | ||||
|             $array['network'] = 'grpc'; | ||||
|             if ($server['networkSettings']) { | ||||
|                 $grpcObject = $server['networkSettings']; | ||||
|                 $grpcSettings = $server['networkSettings']; | ||||
|                 $array['grpc-opts'] = []; | ||||
|                 $array['grpc-opts']['grpc-service-name'] = $grpcObject['serviceName']; | ||||
|                 $array['grpc-opts']['grpc-service-name'] = $grpcSettings['serviceName']; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -88,6 +88,7 @@ class Surfboard | ||||
|             "{$server['host']}", | ||||
|             "{$server['port']}", | ||||
|             "username={$uuid}", | ||||
|             "vmess-aead=true", | ||||
|             'tfo=true', | ||||
|             'udp-relay=true' | ||||
|         ]; | ||||
|   | ||||
| @@ -87,6 +87,7 @@ class Surge | ||||
|             "{$server['host']}", | ||||
|             "{$server['port']}", | ||||
|             "username={$uuid}", | ||||
|             "vmess-aead=true", | ||||
|             'tfo=true', | ||||
|             'udp-relay=true' | ||||
|         ]; | ||||
|   | ||||
| @@ -54,7 +54,7 @@ class V2rayN | ||||
|             "add" => $server['host'], | ||||
|             "port" => (string)$server['port'], | ||||
|             "id" => $uuid, | ||||
|             "aid" => (string)$server['alter_id'], | ||||
|             "aid" => '0', | ||||
|             "net" => $server['network'], | ||||
|             "type" => "none", | ||||
|             "host" => "", | ||||
|   | ||||
| @@ -54,7 +54,7 @@ class V2rayNG | ||||
|             "add" => $server['host'], | ||||
|             "port" => (string)$server['port'], | ||||
|             "id" => $uuid, | ||||
|             "aid" => (string)$server['alter_id'], | ||||
|             "aid" => '0', | ||||
|             "net" => $server['network'], | ||||
|             "type" => "none", | ||||
|             "host" => "", | ||||
|   | ||||
| @@ -4,6 +4,7 @@ namespace App\Http\Controllers\Guest; | ||||
|  | ||||
| use App\Utils\Dict; | ||||
| use App\Http\Controllers\Controller; | ||||
| use Illuminate\Support\Facades\Http; | ||||
|  | ||||
| class CommController extends Controller | ||||
| { | ||||
| @@ -33,4 +34,11 @@ class CommController extends Controller | ||||
|         } | ||||
|         return $suffix; | ||||
|     } | ||||
|  | ||||
|     public function getHitokoto() | ||||
|     { | ||||
|         return response([ | ||||
|             'data' => Http::get('https://v1.hitokoto.cn/')->json() | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -20,7 +20,7 @@ class PaymentController extends Controller | ||||
|             if (!$this->handle($verify['trade_no'], $verify['callback_no'])) { | ||||
|                 abort(500, 'handle error'); | ||||
|             } | ||||
|             die(isset($paymentService->customResult) ? $paymentService->customResult : 'success'); | ||||
|             die(isset($verify['custom_result']) ? $verify['custom_result'] : 'success'); | ||||
|         } catch (\Exception $e) { | ||||
|             abort(500, 'fail'); | ||||
|         } | ||||
|   | ||||
| @@ -5,18 +5,16 @@ namespace App\Http\Controllers\Guest; | ||||
| use App\Services\TelegramService; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Http\Controllers\Controller; | ||||
| use App\Models\User; | ||||
| use App\Utils\Helper; | ||||
| use App\Services\TicketService; | ||||
|  | ||||
| class TelegramController extends Controller | ||||
| { | ||||
|     protected $msg; | ||||
|     protected $commands = []; | ||||
|  | ||||
|     public function __construct(Request $request) | ||||
|     { | ||||
|         if ($request->input('access_token') !== md5(config('v2board.telegram_bot_token'))) { | ||||
|             abort(500, 'authentication failed'); | ||||
|             abort(401); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -24,41 +22,34 @@ class TelegramController extends Controller | ||||
|     { | ||||
|         $this->msg = $this->getMessage($request->input()); | ||||
|         if (!$this->msg) return; | ||||
|         $this->handle(); | ||||
|     } | ||||
|  | ||||
|     public function handle() | ||||
|     { | ||||
|         $msg = $this->msg; | ||||
|         try { | ||||
|             switch($this->msg->message_type) { | ||||
|                 case 'send': | ||||
|                     $this->fromSend(); | ||||
|                     break; | ||||
|                 case 'reply': | ||||
|                     $this->fromReply(); | ||||
|                     break; | ||||
|             foreach (glob(base_path('app//Plugins//Telegram//Commands') . '/*.php') as $file) { | ||||
|                 $command = basename($file, '.php'); | ||||
|                 $class = '\\App\\Plugins\\Telegram\\Commands\\' . $command; | ||||
|                 if (!class_exists($class)) continue; | ||||
|                 $instance = new $class(); | ||||
|                 if ($msg->message_type === 'message') { | ||||
|                     if (!isset($instance->command)) continue; | ||||
|                     if ($msg->command !== $instance->command) continue; | ||||
|                     $instance->handle($msg); | ||||
|                     return; | ||||
|                 } | ||||
|                 if ($msg->message_type === 'reply_message') { | ||||
|                     if (!isset($instance->regex)) continue; | ||||
|                     if (!preg_match($instance->regex, $msg->reply_text, $match)) continue; | ||||
|                     $instance->handle($msg, $match); | ||||
|                     return; | ||||
|                 } | ||||
|             } | ||||
|         } catch (\Exception $e) { | ||||
|             $telegramService = new TelegramService(); | ||||
|             $telegramService->sendMessage($this->msg->chat_id, $e->getMessage()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private function fromSend() | ||||
|     { | ||||
|         switch($this->msg->command) { | ||||
|             case '/bind': $this->bind(); | ||||
|                 break; | ||||
|             case '/traffic': $this->traffic(); | ||||
|                 break; | ||||
|             case '/getlatesturl': $this->getLatestUrl(); | ||||
|                 break; | ||||
|             case '/unbind': $this->unbind(); | ||||
|                 break; | ||||
|             default: $this->help(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private function fromReply() | ||||
|     { | ||||
|         // ticket | ||||
|         if (preg_match("/[#](.*)/", $this->msg->reply_text, $match)) { | ||||
|             $this->replayTicket($match[1]); | ||||
|             $telegramService->sendMessage($msg->chat_id, $e->getMessage()); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -66,135 +57,18 @@ class TelegramController extends Controller | ||||
|     { | ||||
|         if (!isset($data['message'])) return false; | ||||
|         $obj = new \StdClass(); | ||||
|         $obj->is_private = $data['message']['chat']['type'] === 'private' ? true : false; | ||||
|         if (!isset($data['message']['text'])) return false; | ||||
|         $text = explode(' ', $data['message']['text']); | ||||
|         $obj->command = $text[0]; | ||||
|         $obj->args = array_slice($text, 1); | ||||
|         $obj->chat_id = $data['message']['chat']['id']; | ||||
|         $obj->message_id = $data['message']['message_id']; | ||||
|         $obj->message_type = !isset($data['message']['reply_to_message']['text']) ? 'send' : 'reply'; | ||||
|         $obj->message_type = !isset($data['message']['reply_to_message']['text']) ? 'message' : 'reply_message'; | ||||
|         $obj->text = $data['message']['text']; | ||||
|         if ($obj->message_type === 'reply') { | ||||
|         $obj->is_private = $data['message']['chat']['type'] === 'private'; | ||||
|         if ($obj->message_type === 'reply_message') { | ||||
|             $obj->reply_text = $data['message']['reply_to_message']['text']; | ||||
|         } | ||||
|         return $obj; | ||||
|     } | ||||
|  | ||||
|     private function bind() | ||||
|     { | ||||
|         $msg = $this->msg; | ||||
|         if (!$msg->is_private) return; | ||||
|         if (!isset($msg->args[0])) { | ||||
|             abort(500, '参数有误,请携带订阅地址发送'); | ||||
|         } | ||||
|         $subscribeUrl = $msg->args[0]; | ||||
|         $subscribeUrl = parse_url($subscribeUrl); | ||||
|         parse_str($subscribeUrl['query'], $query); | ||||
|         $token = $query['token']; | ||||
|         if (!$token) { | ||||
|             abort(500, '订阅地址无效'); | ||||
|         } | ||||
|         $user = User::where('token', $token)->first(); | ||||
|         if (!$user) { | ||||
|             abort(500, '用户不存在'); | ||||
|         } | ||||
|         if ($user->telegram_id) { | ||||
|             abort(500, '该账号已经绑定了Telegram账号'); | ||||
|         } | ||||
|         $user->telegram_id = $msg->chat_id; | ||||
|         if (!$user->save()) { | ||||
|             abort(500, '设置失败'); | ||||
|         } | ||||
|         $telegramService = new TelegramService(); | ||||
|         $telegramService->sendMessage($msg->chat_id, '绑定成功'); | ||||
|     } | ||||
|  | ||||
|     private function unbind() | ||||
|     { | ||||
|         $msg = $this->msg; | ||||
|         if (!$msg->is_private) return; | ||||
|         $user = User::where('telegram_id', $msg->chat_id)->first(); | ||||
|         $telegramService = new TelegramService(); | ||||
|         if (!$user) { | ||||
|             $this->help(); | ||||
|             $telegramService->sendMessage($msg->chat_id, '没有查询到您的用户信息,请先绑定账号', 'markdown'); | ||||
|             return; | ||||
|         } | ||||
|         $user->telegram_id = NULL; | ||||
|         if (!$user->save()) { | ||||
|             abort(500, '解绑失败'); | ||||
|         } | ||||
|         $telegramService->sendMessage($msg->chat_id, '解绑成功', 'markdown'); | ||||
|     } | ||||
|  | ||||
|     private function help() | ||||
|     { | ||||
|         $msg = $this->msg; | ||||
|         if (!$msg->is_private) return; | ||||
|         $telegramService = new TelegramService(); | ||||
|         $commands = [ | ||||
|             '/bind 订阅地址 - 绑定你的' . config('v2board.app_name', 'V2Board') . '账号', | ||||
|             '/traffic - 查询流量信息', | ||||
|             '/getlatesturl - 获取最新的' . config('v2board.app_name', 'V2Board') . '网址', | ||||
|             '/unbind - 解除绑定' | ||||
|         ]; | ||||
|         $text = implode(PHP_EOL, $commands); | ||||
|         $telegramService->sendMessage($msg->chat_id, "你可以使用以下命令进行操作:\n\n$text", 'markdown'); | ||||
|     } | ||||
|  | ||||
|     private function traffic() | ||||
|     { | ||||
|         $msg = $this->msg; | ||||
|         if (!$msg->is_private) return; | ||||
|         $user = User::where('telegram_id', $msg->chat_id)->first(); | ||||
|         $telegramService = new TelegramService(); | ||||
|         if (!$user) { | ||||
|             $this->help(); | ||||
|             $telegramService->sendMessage($msg->chat_id, '没有查询到您的用户信息,请先绑定账号', 'markdown'); | ||||
|             return; | ||||
|         } | ||||
|         $transferEnable = Helper::trafficConvert($user->transfer_enable); | ||||
|         $up = Helper::trafficConvert($user->u); | ||||
|         $down = Helper::trafficConvert($user->d); | ||||
|         $remaining = Helper::trafficConvert($user->transfer_enable - ($user->u + $user->d)); | ||||
|         $text = "🚥流量查询\n———————————————\n计划流量:`{$transferEnable}`\n已用上行:`{$up}`\n已用下行:`{$down}`\n剩余流量:`{$remaining}`"; | ||||
|         $telegramService->sendMessage($msg->chat_id, $text, 'markdown'); | ||||
|     } | ||||
|  | ||||
|     private function getLatestUrl() | ||||
|     { | ||||
|         $msg = $this->msg; | ||||
|         $user = User::where('telegram_id', $msg->chat_id)->first(); | ||||
|         $telegramService = new TelegramService(); | ||||
|         $text = sprintf( | ||||
|             "%s的最新网址是:%s", | ||||
|             config('v2board.app_name', 'V2Board'), | ||||
|             config('v2board.app_url') | ||||
|         ); | ||||
|         $telegramService->sendMessage($msg->chat_id, $text, 'markdown'); | ||||
|     } | ||||
|  | ||||
|     private function replayTicket($ticketId) | ||||
|     { | ||||
|         $msg = $this->msg; | ||||
|         if (!$msg->is_private) return; | ||||
|         $user = User::where('telegram_id', $msg->chat_id)->first(); | ||||
|         if (!$user) { | ||||
|             abort(500, '用户不存在'); | ||||
|         } | ||||
|         $ticketService = new TicketService(); | ||||
|         if ($user->is_admin || $user->is_staff) { | ||||
|             $ticketService->replyByAdmin( | ||||
|                 $ticketId, | ||||
|                 $msg->text, | ||||
|                 $user->id | ||||
|             ); | ||||
|         } | ||||
|         $telegramService = new TelegramService(); | ||||
|         $telegramService->sendMessage($msg->chat_id, "#`{$ticketId}` 的工单已回复成功", 'markdown'); | ||||
|         $telegramService->sendMessageWithAdmin("#`{$ticketId}` 的工单已由 {$user->email} 进行回复", true); | ||||
|     } | ||||
|  | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -34,6 +34,7 @@ class DeepbworkController extends Controller | ||||
|     // 后端获取用户 | ||||
|     public function user(Request $request) | ||||
|     { | ||||
|         ini_set('memory_limit', -1); | ||||
|         $nodeId = $request->input('node_id'); | ||||
|         $server = ServerV2ray::find($nodeId); | ||||
|         if (!$server) { | ||||
| @@ -47,7 +48,7 @@ class DeepbworkController extends Controller | ||||
|             $user->v2ray_user = [ | ||||
|                 "uuid" => $user->uuid, | ||||
|                 "email" => sprintf("%s@v2board.user", $user->uuid), | ||||
|                 "alter_id" => $server->alter_id, | ||||
|                 "alter_id" => 0, | ||||
|                 "level" => 0, | ||||
|             ]; | ||||
|             unset($user['uuid']); | ||||
|   | ||||
| @@ -30,6 +30,7 @@ class ShadowsocksTidalabController extends Controller | ||||
|     // 后端获取用户 | ||||
|     public function user(Request $request) | ||||
|     { | ||||
|         ini_set('memory_limit', -1); | ||||
|         $nodeId = $request->input('node_id'); | ||||
|         $server = ServerShadowsocks::find($nodeId); | ||||
|         if (!$server) { | ||||
|   | ||||
| @@ -34,6 +34,7 @@ class TrojanTidalabController extends Controller | ||||
|     // 后端获取用户 | ||||
|     public function user(Request $request) | ||||
|     { | ||||
|         ini_set('memory_limit', -1); | ||||
|         $nodeId = $request->input('node_id'); | ||||
|         $server = ServerTrojan::find($nodeId); | ||||
|         if (!$server) { | ||||
|   | ||||
| @@ -3,6 +3,7 @@ | ||||
| namespace App\Http\Controllers\User; | ||||
|  | ||||
| use App\Http\Controllers\Controller; | ||||
| use App\Models\CommissionLog; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Models\User; | ||||
| use App\Models\Order; | ||||
| @@ -27,15 +28,13 @@ class InviteController extends Controller | ||||
|     public function details(Request $request) | ||||
|     { | ||||
|         return response([ | ||||
|             'data' => Order::where('invite_user_id', $request->session()->get('id')) | ||||
|                 ->where('commission_balance', '>', 0) | ||||
|                 ->whereIn('status', [3, 4]) | ||||
|             'data' => CommissionLog::where('invite_user_id', $request->session()->get('id')) | ||||
|                 ->select([ | ||||
|                     'id', | ||||
|                     'commission_status', | ||||
|                     'commission_balance', | ||||
|                     'created_at', | ||||
|                     'updated_at' | ||||
|                     'trade_no', | ||||
|                     'order_amount', | ||||
|                     'get_amount', | ||||
|                     'created_at' | ||||
|                 ]) | ||||
|                 ->get() | ||||
|         ]); | ||||
|   | ||||
| @@ -13,7 +13,8 @@ class NoticeController extends Controller | ||||
|     { | ||||
|         $current = $request->input('current') ? $request->input('current') : 1; | ||||
|         $pageSize = 5; | ||||
|         $model = Notice::orderBy('created_at', 'DESC'); | ||||
|         $model = Notice::orderBy('created_at', 'DESC') | ||||
|             ->where('show', 1); | ||||
|         $total = $model->count(); | ||||
|         $res = $model->forPage($current, $pageSize) | ||||
|             ->get(); | ||||
|   | ||||
| @@ -4,6 +4,7 @@ namespace App\Http\Controllers\User; | ||||
|  | ||||
| use App\Http\Controllers\Controller; | ||||
| use App\Http\Requests\User\OrderSave; | ||||
| use App\Models\CommissionLog; | ||||
| use App\Models\Payment; | ||||
| use App\Services\CouponService; | ||||
| use App\Services\OrderService; | ||||
| @@ -46,7 +47,7 @@ class OrderController extends Controller | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function details(Request $request) | ||||
|     public function detail(Request $request) | ||||
|     { | ||||
|         $order = Order::where('user_id', $request->session()->get('id')) | ||||
|             ->where('trade_no', $request->input('trade_no')) | ||||
| @@ -59,6 +60,9 @@ class OrderController extends Controller | ||||
|         if (!$order['plan']) { | ||||
|             abort(500, __('Subscription plan does not exist')); | ||||
|         } | ||||
|         if ($order->surplus_order_ids) { | ||||
|             $order['surplus_orders'] = Order::whereIn('id', $order->surplus_order_ids)->get(); | ||||
|         } | ||||
|         return response([ | ||||
|             'data' => $order | ||||
|         ]); | ||||
|   | ||||
| @@ -13,6 +13,7 @@ use App\Models\ServerLog; | ||||
| use App\Models\User; | ||||
|  | ||||
| use App\Utils\Helper; | ||||
| use Illuminate\Support\Facades\DB; | ||||
|  | ||||
| class ServerController extends Controller | ||||
| { | ||||
| @@ -29,30 +30,4 @@ class ServerController extends Controller | ||||
|             'data' => $servers | ||||
|         ]); | ||||
|     } | ||||
|  | ||||
|     public function logFetch(Request $request) | ||||
|     { | ||||
|         $type = $request->input('type') ? $request->input('type') : 0; | ||||
|         $current = $request->input('current') ? $request->input('current') : 1; | ||||
|         $pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10; | ||||
|         $serverLogModel = ServerLog::where('user_id', $request->session()->get('id')) | ||||
|             ->orderBy('log_at', 'DESC'); | ||||
|         switch ($type) { | ||||
|             case 0: | ||||
|                 $serverLogModel->where('log_at', '>=', strtotime(date('Y-m-d'))); | ||||
|                 break; | ||||
|             case 1: | ||||
|                 $serverLogModel->where('log_at', '>=', strtotime(date('Y-m-d')) - 604800); | ||||
|                 break; | ||||
|             case 2: | ||||
|                 $serverLogModel->where('log_at', '>=', strtotime(date('Y-m-1'))); | ||||
|         } | ||||
|         $total = $serverLogModel->count(); | ||||
|         $res = $serverLogModel->forPage($current, $pageSize) | ||||
|             ->get(); | ||||
|         return response([ | ||||
|             'data' => $res, | ||||
|             'total' => $total | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										29
									
								
								app/Http/Controllers/User/StatController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								app/Http/Controllers/User/StatController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Http\Controllers\User; | ||||
|  | ||||
| use App\Http\Controllers\Controller; | ||||
| use App\Models\StatUser; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Support\Facades\DB; | ||||
|  | ||||
| class StatController extends Controller | ||||
| { | ||||
|     public function getTrafficLog(Request $request) | ||||
|     { | ||||
|         $builder = StatUser::select([ | ||||
|             DB::raw('sum(u) as u'), | ||||
|             DB::raw('sum(d) as d'), | ||||
|             'record_at', | ||||
|             'user_id', | ||||
|             'server_rate' | ||||
|         ]) | ||||
|             ->where('user_id', $request->session()->get('id')) | ||||
|             ->where('record_at', '>=', strtotime(date('Y-m-1'))) | ||||
|             ->groupBy('record_at', 'user_id', 'server_rate') | ||||
|             ->orderBy('record_at', 'DESC'); | ||||
|         return response([ | ||||
|             'data' => $builder->get() | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
| @@ -10,11 +10,9 @@ use App\Utils\CacheKey; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Models\User; | ||||
| use App\Models\Plan; | ||||
| use App\Models\ServerV2ray; | ||||
| use App\Models\Ticket; | ||||
| use App\Utils\Helper; | ||||
| use App\Models\Order; | ||||
| use App\Models\ServerLog; | ||||
| use Illuminate\Support\Facades\Cache; | ||||
|  | ||||
| class UserController extends Controller | ||||
| @@ -195,10 +193,14 @@ class UserController extends Controller | ||||
|         $today = date('d'); | ||||
|         $lastDay = date('d', strtotime('last day of +0 months')); | ||||
|  | ||||
|         if ((int)config('v2board.reset_traffic_method') === 0) { | ||||
|         if ((int)config('v2board.reset_traffic_method') === 0 || | ||||
|             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 0)) | ||||
|         { | ||||
|             return $lastDay - $today; | ||||
|         } | ||||
|         if ((int)config('v2board.reset_traffic_method') === 1) { | ||||
|         if ((int)config('v2board.reset_traffic_method') === 1 || | ||||
|             (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 1)) | ||||
|         { | ||||
|             if ((int)$day >= (int)$today && (int)$day >= (int)$lastDay) { | ||||
|                 return $lastDay - $today; | ||||
|             } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user