mirror of
https://github.com/v2board/v2board.git
synced 2025-08-02 05:18:46 +08:00
Compare commits
926 Commits
1.4.2
...
532dfbf4b8
Author | SHA1 | Date | |
---|---|---|---|
532dfbf4b8 | |||
7f2f9d1f16 | |||
c67d015c94 | |||
fa761f5d9a | |||
fb338aeb96 | |||
4f04eab073 | |||
69c85983d1 | |||
fa6670597a | |||
e980a6bbe0 | |||
80b96e730a | |||
3c372bd268 | |||
4434b13361 | |||
3f24ba9917 | |||
31c5cf1c2b | |||
07de70d8ab | |||
e6b6d1022e | |||
c1097ad48f | |||
4c865d0262 | |||
1a30aa30ad | |||
6f8e395681 | |||
757e605921 | |||
61f1d8a623 | |||
98bee6fa87 | |||
5ee58f32ca | |||
4c97d7e429 | |||
32eaf301fe | |||
948177f22e | |||
b39299be23 | |||
228355a520 | |||
68db4f51b5 | |||
f33eb0b4bb | |||
2285a7c92f | |||
3884cf96ed | |||
1b8ec77bcc | |||
fa50194055 | |||
b16ef8a7f3 | |||
de75063e0b | |||
3752bed0d6 | |||
74c025e719 | |||
4dc6d29076 | |||
45fd04137b | |||
b20504a431 | |||
3f986992e5 | |||
d6f35d0250 | |||
6c327f9a63 | |||
e5f5e1b693 | |||
2f04505562 | |||
4ba6edc328 | |||
c42097e92f | |||
9db5d3d483 | |||
7964bee769 | |||
76f4a1764b | |||
d9bd54cbc5 | |||
3b1159187f | |||
c6fbb89452 | |||
ae0fd63929 | |||
eee5152f52 | |||
8b3ea1f8ea | |||
6bf60eb4ec | |||
1e6210290b | |||
d8aace8647 | |||
24b4c174c1 | |||
7be6553396 | |||
6dd509d73e | |||
bc5fb4956c | |||
de478db2c7 | |||
61ae86be6f | |||
df6d567962 | |||
a7275e005b | |||
3be96ff99c | |||
f874da19f0 | |||
2f153acd51 | |||
f9e79018d8 | |||
d4ac203805 | |||
82aa63b2e8 | |||
f3699ce421 | |||
aa474f02b9 | |||
921b3fce4e | |||
fae83ab0e5 | |||
969e8ec1e1 | |||
d6cc451a45 | |||
6626c734c3 | |||
529a72dda5 | |||
4c06c0cd51 | |||
9f2c83a21e | |||
feb673cab3 | |||
e745c2a5be | |||
23b6364cc0 | |||
9a28d27082 | |||
5114611f4b | |||
c89faf172a | |||
01a6723e3e | |||
57943b85b0 | |||
2afa05a312 | |||
986acf67d0 | |||
7c7f7288d4 | |||
c40314ed96 | |||
891c84eaae | |||
0cbb44cdea | |||
f062e57a81 | |||
5e582292a8 | |||
1ffe78541d | |||
2429ff6d58 | |||
10861856b5 | |||
1957dab114 | |||
7f25fb674f | |||
2c9f45a193 | |||
7c4f206819 | |||
4034fd4d97 | |||
9f574a6208 | |||
ad619b6a3a | |||
db563062e5 | |||
72a1359cb2 | |||
2bc3c9c7aa | |||
4bb3e46308 | |||
398ab4d005 | |||
973d90572f | |||
0c935c5e3e | |||
63566fbd2c | |||
6b235e592d | |||
908696a54d | |||
731a2b247a | |||
e5fcec6a2a | |||
89d5a7fb42 | |||
0992dde314 | |||
8aef19ac4c | |||
2fed7652fa | |||
c8f3684312 | |||
c946a247ae | |||
044e8f6c30 | |||
2e251872b7 | |||
f621619cc4 | |||
ed2a3b034e | |||
f6c6b5fb1c | |||
0d3aef4fd5 | |||
020f0680e5 | |||
b6baf6485d | |||
b88bbbc4ba | |||
3bfc08f4b4 | |||
0490e38239 | |||
99311e12a5 | |||
358d036e33 | |||
5fc49dc840 | |||
08653fb2cd | |||
f8bf23fae3 | |||
858e68399a | |||
44e8588d3d | |||
9c47d4d09a | |||
48056cf03f | |||
f56a943c35 | |||
f91a1df749 | |||
8eab09440b | |||
3ba1e87222 | |||
cc43ae5d38 | |||
57ef51f5d1 | |||
4880bd97fa | |||
1a3618499f | |||
286ba79a67 | |||
2f50a0e90f | |||
3d9416bf26 | |||
d646a3b27f | |||
df9c8977c4 | |||
28677f45be | |||
933ccf3e4f | |||
3f7ecb23df | |||
c2f43a5258 | |||
0dfbadf715 | |||
0a8fe5267f | |||
ac47a879fa | |||
b9f3838e3b | |||
b6f0508858 | |||
c3a47fddb5 | |||
3e91a7b57a | |||
957fe95449 | |||
0768392b24 | |||
e57c09438a | |||
d0d3c6629b | |||
63a2ffe165 | |||
4d8bb0d8e9 | |||
a77523c3b5 | |||
837701f20a | |||
125a882a7e | |||
c36a54dae2 | |||
4398f05b91 | |||
5976bcc65a | |||
70bde7b742 | |||
87e61e1b9a | |||
e82a145d5e | |||
f864d7249e | |||
f781f22cde | |||
40e6400b9b | |||
153721be55 | |||
69dd10f205 | |||
849b98e876 | |||
16693b94bf | |||
f9e2afe9d1 | |||
e86ac44b2a | |||
2930f1957c | |||
56a6025ef9 | |||
d62307b112 | |||
2999648435 | |||
7810db0b47 | |||
bb900d59b0 | |||
d1194ef310 | |||
c5d714d64d | |||
fc85fd0606 | |||
5c4e863560 | |||
964376fa3c | |||
7872516037 | |||
3e0abe93ab | |||
a82b78d770 | |||
3f7100f351 | |||
6d3927cf2a | |||
99077b68f9 | |||
3f8382aab2 | |||
37f1f64442 | |||
44b2d56db9 | |||
1a79a7e7f6 | |||
30f0166ed1 | |||
dc72c6dced | |||
d34c909bb0 | |||
1a0b09edd2 | |||
ef8483a50f | |||
0f8641f2a3 | |||
9accd71732 | |||
ce120bad63 | |||
6503664fcc | |||
3d1d4ac9d0 | |||
38e25e9039 | |||
7907f455ce | |||
bc9cf36b2b | |||
1ecf7120fe | |||
b65fa65e75 | |||
4a9e1a14af | |||
4136f365a6 | |||
56ea13ea3b | |||
1d304d608b | |||
b6ce8314cd | |||
59b0cb4ed9 | |||
8e23e74e53 | |||
82a20ff72c | |||
b6085fd34d | |||
e1a523b363 | |||
4d2e358784 | |||
eebdf79b68 | |||
08ab004dd1 | |||
10bf65a5f9 | |||
550e628972 | |||
28c5844777 | |||
c6317abba5 | |||
36cb5f0bb5 | |||
446d16c7da | |||
724abdd49f | |||
234faeebba | |||
ef366d8d8b | |||
1fd86aab63 | |||
a456ecaa81 | |||
bd1ec0fe89 | |||
1c644e8c5f | |||
b0687b9dfd | |||
9250d7b19c | |||
604cb807f1 | |||
ef96fca97b | |||
1d62f87efc | |||
3fdd6ac30c | |||
763efef9df | |||
1f88f74155 | |||
5ccf508040 | |||
3362287195 | |||
e18590c2f9 | |||
5f573f5306 | |||
df8ea58456 | |||
adf465696a | |||
49d9c453d8 | |||
8702a3489b | |||
dc27410c12 | |||
2073727a0a | |||
346d0222f5 | |||
838fc7bdba | |||
2823f1bd47 | |||
e6e7cbf48d | |||
7713489945 | |||
90b5364039 | |||
ed8d4a3917 | |||
e086586e8e | |||
aa65440556 | |||
8a8c6dd116 | |||
cc6b07d7b8 | |||
bdb10bed32 | |||
2b4e8f4b88 | |||
d18904b631 | |||
fb48e1a721 | |||
0e75b83507 | |||
a0b14029cd | |||
cb631920a1 | |||
0f7d787622 | |||
7a64038133 | |||
12767350ef | |||
c992e0bde6 | |||
ecef0315a0 | |||
4863e7577a | |||
dec00ebe54 | |||
5bb5cbe751 | |||
cdadbf6509 | |||
3fb600a3b0 | |||
3840df1203 | |||
b24041cc23 | |||
da2f942a28 | |||
4a9e0ba94c | |||
cdd55eae4c | |||
fe1ab11bbd | |||
1d1ac37d4d | |||
25dc7294f2 | |||
4ad44c5f45 | |||
7dc626650f | |||
6b978c421a | |||
304e67a632 | |||
9d3ba5dd62 | |||
1dba8e3f0d | |||
2426d88339 | |||
5e7f782583 | |||
f81f6e0716 | |||
25cae43430 | |||
84f8089604 | |||
6d6ab5543a | |||
1ddc05652d | |||
7d92714fa9 | |||
649c03c214 | |||
fae48e2c81 | |||
bd0834bd3f | |||
c09ab693bb | |||
709929a5a3 | |||
ca9847cc45 | |||
512c48adeb | |||
9d9c977ff1 | |||
ed749f85ae | |||
d74ab728fe | |||
e72d28e2b3 | |||
2f977c937f | |||
531a3a5dc4 | |||
74265a5b59 | |||
db06001254 | |||
8311722fda | |||
5bd811e217 | |||
20e365e771 | |||
a0ebcb948b | |||
32bb9fccb5 | |||
a4a70525df | |||
3f32fadc85 | |||
fae1e1f945 | |||
12caada8dd | |||
7ec4b06536 | |||
b5a614d901 | |||
f40480c918 | |||
c8e2d54d2b | |||
ecb085343e | |||
e0404a6b49 | |||
58731faf23 | |||
472a692b3c | |||
b49ffcbfb4 | |||
22ddb0086a | |||
aa9bbf8009 | |||
82584cb18d | |||
a1a95ea9c8 | |||
4ef5a4ca81 | |||
f046a396d6 | |||
d20dce7f69 | |||
0bcaf2889a | |||
5466e4dbba | |||
7b2fa79cdf | |||
e2597b4ac3 | |||
7faa56a4fd | |||
66815f4b91 | |||
84ce0cc0c9 | |||
f439040375 | |||
27271e3ffb | |||
e82f28b670 | |||
447ff0f554 | |||
9dfe44bf82 | |||
6b1f3a73c4 | |||
8fdd755107 | |||
077c8ba0e8 | |||
92d236f5c0 | |||
24e896d301 | |||
5b293f4cb0 | |||
e3ffdb7bce | |||
7c473d6325 | |||
d4183d2c7f | |||
9d45b71731 | |||
c6cc307147 | |||
b1fc316e3d | |||
983b752f20 | |||
af2f6a31da | |||
20b60d553c | |||
f97d9fcc81 | |||
4d657823f6 | |||
791ba463c3 | |||
6a2125794b | |||
8f3281c60e | |||
88187f5a6c | |||
a5ea79493c | |||
1111c6f13d | |||
fc2b4bd422 | |||
d76c2b3bca | |||
82730acdac | |||
d184225b2b | |||
bdf65247e0 | |||
1e9c16543d | |||
d42c271942 | |||
d5504354bc | |||
2eb428fc3c | |||
8832fde4fa | |||
7f848ccb13 | |||
dd0b60071e | |||
fe80d5e89b | |||
93eaf0ae36 | |||
9f6683592c | |||
e46217e085 | |||
5d051994be | |||
c399c7a6dd | |||
e40d9231e7 | |||
daece8dac3 | |||
6ac0538513 | |||
f1598d1c74 | |||
01b7c3b2b0 | |||
0f95918df3 | |||
8283dd7fc1 | |||
63fe749cf4 | |||
828a4ffe39 | |||
85e6dd7210 | |||
5c5500bb2d | |||
d3e81a1b00 | |||
c60cd0a34a | |||
e9c79c1c08 | |||
9ff76dedd7 | |||
535cf0df12 | |||
5aef3f20d5 | |||
4c9a38f722 | |||
5b5293bfab | |||
98b12205f7 | |||
d0cab99ae4 | |||
b85eb72d1a | |||
5345823b63 | |||
3795557bc5 | |||
632205fb6c | |||
ebfba1b178 | |||
8645002d54 | |||
1813fdca5d | |||
33b59d126e | |||
313ac9d27f | |||
5fde09344c | |||
e9cd4a1b27 | |||
40d757dda3 | |||
980f1e3093 | |||
92caf3fc20 | |||
4eb3e23ddc | |||
1c569a2d45 | |||
2ceb910812 | |||
0309befb47 | |||
dcb45ab6ed | |||
c270f3ab5a | |||
23f98d7abc | |||
60b6a6177d | |||
0697d1cd7a | |||
766d1193c7 | |||
a1ada9183c | |||
c8c96365ea | |||
57a746d52b | |||
8d2d1b25a3 | |||
659cc987fa | |||
8cd29641c6 | |||
0efd0d5e99 | |||
391ad04447 | |||
04e9109d90 | |||
e990468d18 | |||
6508b289e0 | |||
ad50e77422 | |||
7fa3d1e58f | |||
659fa85b1d | |||
21a9074b3f | |||
13327d004d | |||
adc9e9e241 | |||
4305e3a246 | |||
1d5a493ef1 | |||
9dc44c0e1d | |||
8a18bdf9c3 | |||
03846022ef | |||
8a7297d7cd | |||
7435e9f9cc | |||
78a87125c8 | |||
e363666b89 | |||
ca9d7df3b5 | |||
5bf1dd3426 | |||
2d348cb078 | |||
1790de63f6 | |||
94a7ab412c | |||
e89c84ad0e | |||
6f849664cc | |||
36f87bd61f | |||
bd73c3f03a | |||
be1f030deb | |||
a5acb86c66 | |||
1f25edaaa4 | |||
90f9c181a0 | |||
e584a95767 | |||
2b698b63e0 | |||
ec946918c9 | |||
3e78ac1625 | |||
da90ea106b | |||
9b21cca314 | |||
3ea8781146 | |||
1bcffc1dd6 | |||
da51d267e2 | |||
1716f2f6ca | |||
b4e657f463 | |||
870e82e155 | |||
77e9e3adeb | |||
c3a74e6610 | |||
9fde0b35eb | |||
85c52f6499 | |||
50768735a8 | |||
ab5fce51a1 | |||
54ea079d4d | |||
bded1a4ee5 | |||
546e53ed2e | |||
339ab3925f | |||
927d575255 | |||
796bcc4ab3 | |||
552a80f5f9 | |||
d78a8a2a9f | |||
3fad649377 | |||
389db6fb97 | |||
080af12f39 | |||
ecbdd12a6d | |||
3ade2bf89c | |||
45a5022d82 | |||
e1a8d6ca35 | |||
5df2504f73 | |||
708a83017b | |||
edb2e7956c | |||
a557aa6d32 | |||
6ed9cc559e | |||
6718a61890 | |||
333611da48 | |||
8ee7839d00 | |||
e29261a87f | |||
ba75d6e993 | |||
ce8b5dde28 | |||
55357a1b0e | |||
0f777f1a77 | |||
8fa73c2d4b | |||
80ae5f17b7 | |||
de4f01f653 | |||
bbfabdb72f | |||
b392fa3345 | |||
ecfb9ce8b0 | |||
a69eb4058b | |||
8d56377c8a | |||
30aec3d8e9 | |||
05769ea591 | |||
fb8bcdcbe0 | |||
39c47a06eb | |||
4c71eb5633 | |||
b8df411ffe | |||
66728f13ea | |||
7b1a8ee5ff | |||
9d96d68f12 | |||
d0947d1aaa | |||
6f67096fe3 | |||
44b369d0e7 | |||
04fcd6758d | |||
99f3004d6b | |||
56c726b173 | |||
37a6f3861c | |||
90211c1018 | |||
cc3e3b3fd1 | |||
10d3feb57c | |||
eb98d706ae | |||
4996c317c9 | |||
f380bd3c0e | |||
8e7f0bbc44 | |||
53011cb95c | |||
037e22aa2d | |||
ffd5eb269d | |||
68def9b4de | |||
a4d617608f | |||
364e259188 | |||
b18c810f7f | |||
239eb2075c | |||
b40272a8fa | |||
a6d5a433b0 | |||
fe0f0afa53 | |||
9ff524fd15 | |||
f6d9e6e7f6 | |||
d911069e18 | |||
32c539d2c0 | |||
52fa1ce6af | |||
82d2d91582 | |||
8085c2ba6a | |||
b60fde5762 | |||
3b51f12ab1 | |||
ab4e66a5b6 | |||
1856e0e87e | |||
e20ae29fb1 | |||
cfd528739a | |||
dd23609658 | |||
c7f3cf9e67 | |||
ddf2f45d6c | |||
ba3de90733 | |||
43f4ecce93 | |||
30b3587771 | |||
6ab9a4d54d | |||
7a4bd468a2 | |||
c97d37a070 | |||
25b3b11efd | |||
edfc4043e8 | |||
ab9abf5b93 | |||
6dd199631b | |||
4b863d681e | |||
5d6010045d | |||
0374a03892 | |||
ec00fc4496 | |||
a365357770 | |||
14579d1eea | |||
9f6d1ada93 | |||
895976b830 | |||
4b011225db | |||
243aed3f55 | |||
d25d7ba69b | |||
c0c84efb7c | |||
91c7dfc0ed | |||
6830e6af38 | |||
cb75579772 | |||
e980c2d8f3 | |||
b6195494d3 | |||
ccf3497241 | |||
c80d93fa25 | |||
c2577e37c4 | |||
c183462ef3 | |||
2a5e9ef079 | |||
decbae1413 | |||
0c14652ff7 | |||
91418caf04 | |||
607aa82f88 | |||
adc2d02c49 | |||
fabb49baea | |||
35e11a6816 | |||
1d87a1b99a | |||
fbced4d09b | |||
52914e354e | |||
d392d29b50 | |||
347a3bb4b0 | |||
7ac1f69a71 | |||
6317c4a4f3 | |||
3da4de02d0 | |||
85686df2e6 | |||
adb5d041e6 | |||
7ba0e9a4e0 | |||
99a64f41e1 | |||
62053bc30f | |||
e5e7a06514 | |||
905e2dacd1 | |||
8189a442bc | |||
b38f7979d6 | |||
5a3b897c57 | |||
2d5fb03937 | |||
982c47d0b4 | |||
4cebeed2d7 | |||
c95d374cc0 | |||
23462e2753 | |||
b26a3e0e70 | |||
3600c9a166 | |||
8a58a1ad88 | |||
968d55e2e3 | |||
98ac5cb680 | |||
0288d2df4b | |||
cb8e34fa2e | |||
b0c818c661 | |||
303d4a1c66 | |||
e6416712f0 | |||
5c6236366c | |||
9b0a487c69 | |||
27a6cc98d1 | |||
e05f6116b6 | |||
a9db11877f | |||
abe1ebccae | |||
c957a4ca83 | |||
c9cd307cc4 | |||
31cdcef3aa | |||
9f75d4cbde | |||
de5f80b5a3 | |||
474df5e18f | |||
dfa75f49bd | |||
f2c7d092ac | |||
2c389ebe8c | |||
25e19446e6 | |||
a8761e9d4d | |||
5f4e9c0301 | |||
b6e9260464 | |||
6aa96fe856 | |||
ab02935fd7 | |||
b275ad469b | |||
e6a7c2c11c | |||
0f0f726269 | |||
00cd3e26be | |||
d95974019a | |||
7a80950ab5 | |||
73a6d3236a | |||
59dd34674e | |||
5dda531c2b | |||
7234ccf4c1 | |||
448b5382b9 | |||
bd2b056fbf | |||
ad8e2b8e80 | |||
8a20a70513 | |||
06adaa2124 | |||
ebf98d42a8 | |||
1adb1bcfa0 | |||
bb8da6e2c5 | |||
c426aabbcf | |||
18bb1bd962 | |||
07e9377417 | |||
c0d3150461 | |||
1a9b8b09bb | |||
cb621a93ae | |||
fb449b490e | |||
e35ec76f81 | |||
5a60380765 | |||
f409d89c4a | |||
de045c79f5 | |||
6a336d4253 | |||
0ce3948c12 | |||
7338c4a294 | |||
9417623fcf | |||
4f29264de9 | |||
34d8f0d5f0 | |||
b585038916 | |||
5abb642277 | |||
01cf486137 | |||
cb811bda5a | |||
2306e38d0c | |||
2798c1df06 | |||
a727745b43 | |||
af901291a5 | |||
42d755c7d9 | |||
56a4ce5fe4 | |||
67ab0d1f22 | |||
230470c037 | |||
77aec7d553 | |||
88948eb8ee | |||
4d38ce3968 | |||
a88121626b | |||
90409b1107 | |||
04615688f7 | |||
f48de9f07d | |||
4722379e79 | |||
9aed2554ee | |||
7eb3d9fed7 | |||
567acdd03b | |||
a0d18d93d3 | |||
1c419283c0 | |||
d25f6bff65 | |||
0b97dd0995 | |||
6f90c6b878 | |||
5b8591fde9 | |||
dfeec044ea | |||
70b47ec4b0 | |||
cd85fba9c7 | |||
e01e951f7f | |||
0284e47155 | |||
a4e1ba4016 | |||
f95deb3f16 | |||
dfef6d2d94 | |||
efc8419eb5 | |||
aecfa85efd | |||
9db5de09f2 | |||
b174403a2a | |||
0f488540f4 | |||
d00ad94c46 | |||
5fa7c534ff | |||
386c1339f5 | |||
6509091e4f | |||
078dfbf339 | |||
de6ff1dca9 | |||
044d1e9b7f | |||
9c711b4ea6 | |||
760d248e4e | |||
1a2e8e2966 | |||
b00b58d73d | |||
43027660be | |||
fe69a5976b | |||
ecebba1d51 | |||
efc43dc45e | |||
c5d88bfbfc | |||
6928fd3fef | |||
e4f178e167 | |||
343c93ad8e | |||
f80af8efdc | |||
e5b998ee8d | |||
d510064732 | |||
c5e2ec1d12 | |||
ee2ca23487 | |||
a5532490ba | |||
2f175323a3 | |||
f896370e64 | |||
0313c35dbe | |||
232cb18a25 | |||
04a05a6ba4 | |||
e2b4df592d | |||
668663f978 | |||
2e7544c71c | |||
1fb3f62cff | |||
02a1728bff | |||
4ea71d85be | |||
afe8bb3171 | |||
ef17be2046 | |||
53dea06a6c | |||
229a3022ac | |||
554dc4c12b | |||
6175e59e6f | |||
9df6e52438 | |||
63acb4c581 | |||
f54c82dcf9 | |||
b92b38a635 | |||
ddab443d75 | |||
8f806e6de7 | |||
f1c62e2732 | |||
3275b96a0a | |||
240555104a | |||
30ff71bd11 | |||
b17bbad745 | |||
a301b8461e | |||
3e354bf5af | |||
b9796f462c | |||
dc6317db97 | |||
b3b0988730 | |||
4070761cd0 | |||
2c408a2f56 | |||
2cfaeb2fb9 | |||
ef1c0b6091 | |||
8e1a313709 | |||
d5cf1bc735 | |||
e1c63bd556 | |||
324e218767 | |||
04b5d16457 | |||
2431ffaba7 | |||
6b31c39e6e | |||
2769a6adf4 | |||
aa78761115 | |||
3e60cbf968 | |||
84583bd384 | |||
0333d62e6f | |||
3bfa2180e6 | |||
22ee741200 | |||
58b27cdd50 | |||
743311f2f7 | |||
9c04f75b85 | |||
c7d7dfda28 | |||
35362689c4 | |||
b740998760 | |||
488eafdd67 | |||
ff30d3dcb2 | |||
cbe5882e01 | |||
4e2e3cd2a0 | |||
326fb5d918 | |||
a49faf3e1f | |||
e4b76a705f | |||
a03125ee6a | |||
58a63ae819 | |||
ab8ebd593f | |||
11b6c8448a | |||
9ce9af4917 | |||
550f0fee37 | |||
ab9c6c85bb | |||
0e6f6358d8 | |||
b0ddf7d45f | |||
f8a851d464 | |||
da8bff5609 | |||
d3150cadac | |||
cdddbae19a | |||
7c40a146a9 | |||
f81426b2c4 | |||
e581d08f95 | |||
2ba924e578 | |||
77f6b3f289 | |||
2979003b6f | |||
2be497b04d | |||
f55fc86547 | |||
bc9b3b6e76 | |||
fcafb65ce9 | |||
34be1b9579 | |||
627ff98882 | |||
007b10d925 | |||
f855ecc758 | |||
af8b2b61d4 | |||
f7a7c21c16 | |||
edee396c9b | |||
54d1226c8b | |||
1ce019cfa5 | |||
fe736df68d | |||
72bf45e4d5 | |||
c5639a9bef | |||
3f1c505922 | |||
ec0fbabd07 | |||
eca105b7d1 | |||
a55647ab7a | |||
633b9ad912 | |||
be146bc98b | |||
79cbe6ce39 | |||
f8185b51b7 | |||
b4d74a016a | |||
dd51daf9d8 | |||
4958c94bf2 | |||
5766ec1951 | |||
faeaa02a84 | |||
66c547d0ac | |||
d1cfc9815b | |||
b8b7033132 | |||
9a465d9bb4 | |||
bcea2e7a54 | |||
7e5e696c70 | |||
1d70382aee | |||
8af862633f | |||
c0e60978ce | |||
f036b46bf0 | |||
a0d1b10614 |
39
.github/ISSUE_TEMPLATE/bug-report----问题反馈.md
vendored
Normal file
39
.github/ISSUE_TEMPLATE/bug-report----问题反馈.md
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
---
|
||||
name: Bug report | 问题反馈
|
||||
about: Tell us what problems you have encountered
|
||||
title: "[BUG]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
🙇♂️🙇♂️🙇♂️注意:XrayR等非V2Board问题请前往项目方提问
|
||||
🙇♂️🙇♂️🙇♂️Note: XrayR and other non-V2Board issues please go to the project side to ask questions
|
||||
|
||||
|
||||
The V2Board version number you are using
|
||||
当前使用的V2Board版本号
|
||||
--------
|
||||
|
||||
|
||||
Briefly describe the problem you are experiencing
|
||||
简单描述你遇到的问题
|
||||
--------
|
||||
|
||||
|
||||
|
||||
Screenshot of the reported error(Please do desensitization)
|
||||
报告错误的截图(请做脱敏处理)
|
||||
--------
|
||||
|
||||
|
||||
|
||||
Screenshot of the reported error(Please do desensitization)
|
||||
报告错误的截图(请做脱敏处理)
|
||||
--------
|
||||
|
||||
|
||||
|
||||
The latest log files in the storage/logs directory report from #1 (Please do desensitization)
|
||||
storage/logs 目录下最新的日志文件从 #1 开始报告(请做脱敏处理)
|
||||
--------
|
11
.github/ISSUE_TEMPLATE/feature-request---功能请求.md
vendored
Normal file
11
.github/ISSUE_TEMPLATE/feature-request---功能请求.md
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
---
|
||||
name: Feature request | 功能请求
|
||||
about: Tell us what you need
|
||||
title: "[Feature request]"
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Please describe in detail the problems or needs you have encountered.
|
||||
请详细描述你遇到的问题或需求。
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,3 +18,4 @@ composer.phar
|
||||
composer.lock
|
||||
yarn.lock
|
||||
docker-compose.yml
|
||||
.DS_Store
|
||||
|
16
.styleci.yml
16
.styleci.yml
@ -1,16 +0,0 @@
|
||||
php:
|
||||
preset: laravel
|
||||
enabled:
|
||||
- alpha_ordered_imports
|
||||
disabled:
|
||||
- length_ordered_imports
|
||||
- unused_use
|
||||
finder:
|
||||
not-name:
|
||||
- index.php
|
||||
- server.php
|
||||
js:
|
||||
finder:
|
||||
not-name:
|
||||
- webpack.mix.js
|
||||
css: true
|
@ -2,9 +2,11 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\CommissionLog;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CheckCommission extends Command
|
||||
{
|
||||
@ -48,7 +50,7 @@ class CheckCommission extends Command
|
||||
if ((int)config('v2board.commission_auto_check_enable', 1)) {
|
||||
Order::where('commission_status', 0)
|
||||
->where('invite_user_id', '!=', NULL)
|
||||
->whereIn('status', [3, 4])
|
||||
->where('status', 3)
|
||||
->where('updated_at', '<=', strtotime('-3 day', time()))
|
||||
->update([
|
||||
'commission_status' => 1
|
||||
@ -58,18 +60,68 @@ class CheckCommission extends Command
|
||||
|
||||
public function autoPayCommission()
|
||||
{
|
||||
$order = Order::where('commission_status', 1)
|
||||
$orders = Order::where('commission_status', 1)
|
||||
->where('invite_user_id', '!=', NULL)
|
||||
->get();
|
||||
foreach ($order as $item) {
|
||||
$inviter = User::find($item->invite_user_id);
|
||||
if (!$inviter) continue;
|
||||
$inviter->commission_balance = $inviter->commission_balance + $item->commission_balance;
|
||||
if ($inviter->save()) {
|
||||
$item->commission_status = 2;
|
||||
$item->save();
|
||||
foreach ($orders as $order) {
|
||||
DB::beginTransaction();
|
||||
if (!$this->payHandle($order->invite_user_id, $order)) {
|
||||
DB::rollBack();
|
||||
continue;
|
||||
}
|
||||
$order->commission_status = 2;
|
||||
if (!$order->save()) {
|
||||
DB::rollBack();
|
||||
continue;
|
||||
}
|
||||
DB::commit();
|
||||
}
|
||||
}
|
||||
|
||||
public function payHandle($inviteUserId, Order $order)
|
||||
{
|
||||
$level = 3;
|
||||
if ((int)config('v2board.commission_distribution_enable', 0)) {
|
||||
$commissionShareLevels = [
|
||||
0 => (int)config('v2board.commission_distribution_l1'),
|
||||
1 => (int)config('v2board.commission_distribution_l2'),
|
||||
2 => (int)config('v2board.commission_distribution_l3')
|
||||
];
|
||||
} else {
|
||||
$commissionShareLevels = [
|
||||
0 => 100
|
||||
];
|
||||
}
|
||||
for ($l = 0; $l < $level; $l++) {
|
||||
$inviter = User::find($inviteUserId);
|
||||
if (!$inviter) continue;
|
||||
if (!isset($commissionShareLevels[$l])) continue;
|
||||
$commissionBalance = $order->commission_balance * ($commissionShareLevels[$l] / 100);
|
||||
if (!$commissionBalance) continue;
|
||||
if ((int)config('v2board.withdraw_close_enable', 0)) {
|
||||
$inviter->balance = $inviter->balance + $commissionBalance;
|
||||
} else {
|
||||
$inviter->commission_balance = $inviter->commission_balance + $commissionBalance;
|
||||
}
|
||||
if (!$inviter->save()) {
|
||||
DB::rollBack();
|
||||
return false;
|
||||
}
|
||||
if (!CommissionLog::create([
|
||||
'invite_user_id' => $inviteUserId,
|
||||
'user_id' => $order->user_id,
|
||||
'trade_no' => $order->trade_no,
|
||||
'order_amount' => $order->total_amount,
|
||||
'get_amount' => $commissionBalance
|
||||
])) {
|
||||
DB::rollBack();
|
||||
return false;
|
||||
}
|
||||
$inviteUserId = $inviter->invite_user_id;
|
||||
// update order actual commission balance
|
||||
$order->actual_commission_balance = $order->actual_commission_balance + $commissionBalance;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\OrderHandleJob;
|
||||
use App\Services\OrderService;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Order;
|
||||
@ -42,21 +43,12 @@ class CheckOrder extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$orders = Order::get();
|
||||
foreach ($orders as $item) {
|
||||
$orderService = new OrderService($item);
|
||||
switch ($item->status) {
|
||||
// cancel
|
||||
case 0:
|
||||
if (strtotime($item->created_at) <= (time() - 1800)) {
|
||||
$orderService->cancel();
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
$orderService->open();
|
||||
break;
|
||||
}
|
||||
|
||||
ini_set('memory_limit', -1);
|
||||
$orders = Order::whereIn('status', [0, 1])
|
||||
->orderBy('created_at', 'ASC')
|
||||
->get();
|
||||
foreach ($orders as $order) {
|
||||
OrderHandleJob::dispatch($order->trade_no);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
65
app/Console/Commands/CheckServer.php
Normal file
65
app/Console/Commands/CheckServer.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\ServerService;
|
||||
use App\Services\TelegramService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class CheckServer extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'check:server';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '节点检查任务';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->checkOffline();
|
||||
}
|
||||
|
||||
private function checkOffline()
|
||||
{
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAllServers();
|
||||
foreach ($servers as $server) {
|
||||
if ($server['parent_id']) continue;
|
||||
if ($server['last_check_at'] && (time() - $server['last_check_at']) > 1800) {
|
||||
$telegramService = new TelegramService();
|
||||
$message = sprintf(
|
||||
"节点掉线通知\r\n----\r\n节点名称:%s\r\n节点地址:%s\r\n",
|
||||
$server['name'],
|
||||
$server['host']
|
||||
);
|
||||
$telegramService->sendMessageWithAdmin($message);
|
||||
Cache::forget(CacheKey::get(sprintf("SERVER_%s_LAST_CHECK_AT", strtoupper($server['type'])), $server->id));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
52
app/Console/Commands/CheckTicket.php
Normal file
52
app/Console/Commands/CheckTicket.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Ticket;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CheckTicket extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'check:ticket';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '工单检查任务';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
$tickets = Ticket::where('status', 0)
|
||||
->where('updated_at', '<=', time() - 24 * 3600)
|
||||
->where('reply_status', 0)
|
||||
->get();
|
||||
foreach ($tickets as $ticket) {
|
||||
if ($ticket->user_id === $ticket->last_reply_user_id) continue;
|
||||
$ticket->status = 1;
|
||||
$ticket->save();
|
||||
}
|
||||
}
|
||||
}
|
@ -2,25 +2,25 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\ServerLog;
|
||||
|
||||
class ResetServerLog extends Command
|
||||
class ClearUser extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'reset:serverLog';
|
||||
protected $signature = 'clear:user';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '节点服务器日志重置';
|
||||
protected $description = '清理用户';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
@ -39,6 +39,13 @@ class ResetServerLog extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
ServerLog::truncate();
|
||||
$builder = User::where('plan_id', NULL)
|
||||
->where('transfer_enable', 0)
|
||||
->where('expired_at', 0)
|
||||
->where('last_login_at', NULL);
|
||||
$count = $builder->count();
|
||||
if ($builder->delete()) {
|
||||
$this->info("已删除${count}位没有任何数据的用户");
|
||||
}
|
||||
}
|
||||
}
|
52
app/Console/Commands/ResetLog.php
Normal file
52
app/Console/Commands/ResetLog.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Log;
|
||||
use App\Models\Plan;
|
||||
use App\Models\StatServer;
|
||||
use App\Models\StatUser;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ResetLog extends Command
|
||||
{
|
||||
protected $builder;
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'reset:log';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '清空日志';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
StatUser::where('record_at', '<', strtotime('-2 month', time()))->delete();
|
||||
StatServer::where('record_at', '<', strtotime('-2 month', time()))->delete();
|
||||
Log::where('created_at', '<', strtotime('-1 month', time()))->delete();
|
||||
}
|
||||
}
|
54
app/Console/Commands/ResetPassword.php
Normal file
54
app/Console/Commands/ResetPassword.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ResetPassword extends Command
|
||||
{
|
||||
protected $builder;
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'reset:password {email}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '重置用户密码';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$user = User::where('email', $this->argument('email'))->first();
|
||||
if (!$user) abort(500, '邮箱不存在');
|
||||
$password = Helper::guid(false);
|
||||
$user->password = password_hash($password, PASSWORD_DEFAULT);
|
||||
$user->password_algo = null;
|
||||
if (!$user->save()) abort(500, '重置失败');
|
||||
$this->info("!!!重置成功!!!");
|
||||
$this->info("新密码为:{$password},请尽快修改密码。");
|
||||
}
|
||||
}
|
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Plan;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ResetTraffic extends Command
|
||||
{
|
||||
@ -41,22 +43,96 @@ class ResetTraffic extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$resetTrafficMethod = config('v2board.reset_traffic_method', 0);
|
||||
switch ((int)$resetTrafficMethod) {
|
||||
// 1 a month
|
||||
case 0:
|
||||
$this->resetByMonthFirstDay();
|
||||
break;
|
||||
// expire day
|
||||
case 1:
|
||||
$this->resetByExpireDay();
|
||||
break;
|
||||
ini_set('memory_limit', -1);
|
||||
$resetMethods = Plan::select(
|
||||
DB::raw("GROUP_CONCAT(`id`) as plan_ids"),
|
||||
DB::raw("reset_traffic_method as method")
|
||||
)
|
||||
->groupBy('reset_traffic_method')
|
||||
->get()
|
||||
->toArray();
|
||||
foreach ($resetMethods as $resetMethod) {
|
||||
$planIds = explode(',', $resetMethod['plan_ids']);
|
||||
switch (true) {
|
||||
case ($resetMethod['method'] === NULL): {
|
||||
$resetTrafficMethod = config('v2board.reset_traffic_method', 0);
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
switch ((int)$resetTrafficMethod) {
|
||||
// month first day
|
||||
case 0:
|
||||
$this->resetByMonthFirstDay($builder);
|
||||
break;
|
||||
// expire day
|
||||
case 1:
|
||||
$this->resetByExpireDay($builder);
|
||||
break;
|
||||
// no action
|
||||
case 2:
|
||||
break;
|
||||
// year first day
|
||||
case 3:
|
||||
$this->resetByYearFirstDay($builder);
|
||||
// year expire day
|
||||
case 4:
|
||||
$this->resetByExpireYear($builder);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ($resetMethod['method'] === 0): {
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
$this->resetByMonthFirstDay($builder);
|
||||
break;
|
||||
}
|
||||
case ($resetMethod['method'] === 1): {
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
$this->resetByExpireDay($builder);
|
||||
break;
|
||||
}
|
||||
case ($resetMethod['method'] === 2): {
|
||||
break;
|
||||
}
|
||||
case ($resetMethod['method'] === 3): {
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
$this->resetByYearFirstDay($builder);
|
||||
break;
|
||||
}
|
||||
case ($resetMethod['method'] === 4): {
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
$this->resetByExpireYear($builder);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function resetByMonthFirstDay():void
|
||||
private function resetByExpireYear($builder):void
|
||||
{
|
||||
$users = [];
|
||||
foreach ($builder->get() as $item) {
|
||||
$expireDay = date('m-d', $item->expired_at);
|
||||
$today = date('m-d');
|
||||
if ($expireDay === $today) {
|
||||
array_push($users, $item->id);
|
||||
}
|
||||
}
|
||||
User::whereIn('id', $users)->update([
|
||||
'u' => 0,
|
||||
'd' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
private function resetByYearFirstDay($builder):void
|
||||
{
|
||||
if ((string)date('md') === '0101') {
|
||||
$builder->update([
|
||||
'u' => 0,
|
||||
'd' => 0
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
private function resetByMonthFirstDay($builder):void
|
||||
{
|
||||
$builder = $this->builder;
|
||||
if ((string)date('d') === '01') {
|
||||
$builder->update([
|
||||
'u' => 0,
|
||||
@ -65,9 +141,8 @@ class ResetTraffic extends Command
|
||||
}
|
||||
}
|
||||
|
||||
private function resetByExpireDay():void
|
||||
private function resetByExpireDay($builder):void
|
||||
{
|
||||
$builder = $this->builder;
|
||||
$lastDay = date('d', strtotime('last day of +0 months'));
|
||||
$users = [];
|
||||
foreach ($builder->get() as $item) {
|
||||
|
58
app/Console/Commands/ResetUser.php
Normal file
58
app/Console/Commands/ResetUser.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ResetUser extends Command
|
||||
{
|
||||
protected $builder;
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'reset:user';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '重置所有用户信息';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (!$this->confirm("确定要重置所有用户安全信息吗?")) {
|
||||
return;
|
||||
}
|
||||
ini_set('memory_limit', -1);
|
||||
$users = User::all();
|
||||
foreach ($users as $user)
|
||||
{
|
||||
$user->token = Helper::guid();
|
||||
$user->uuid = Helper::guid(true);
|
||||
$user->save();
|
||||
$this->info("已重置用户{$user->email}的安全信息");
|
||||
}
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\MailService;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\User;
|
||||
use App\Models\MailLog;
|
||||
@ -41,23 +42,10 @@ class SendRemindMail extends Command
|
||||
public function handle()
|
||||
{
|
||||
$users = User::all();
|
||||
$mailService = new MailService();
|
||||
foreach ($users as $user) {
|
||||
if ($user->remind_expire) $this->remindExpire($user);
|
||||
}
|
||||
}
|
||||
|
||||
private function remindExpire($user)
|
||||
{
|
||||
if ($user->expired_at !== NULL && ($user->expired_at - 86400) < time() && $user->expired_at > time()) {
|
||||
SendEmailJob::dispatch([
|
||||
'email' => $user->email,
|
||||
'subject' => '在' . config('v2board.app_name', 'V2board') . '的服务即将到期',
|
||||
'template_name' => 'remindExpire',
|
||||
'template_value' => [
|
||||
'name' => config('v2board.app_name', 'V2Board'),
|
||||
'url' => config('v2board.app_url')
|
||||
]
|
||||
]);
|
||||
if ($user->remind_expire) $mailService->remindExpire($user);
|
||||
if ($user->remind_traffic) $mailService->remindTraffic($user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\ServerLog;
|
||||
use App\Models\ServerStat;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class V2boardCache extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'v2board:cache';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '缓存任务';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
}
|
||||
|
||||
private function cacheServerStat()
|
||||
{
|
||||
$serverLogs = ServerLog::select(
|
||||
'server_id',
|
||||
DB::raw("sum(u) as u"),
|
||||
DB::raw("sum(d) as d"),
|
||||
DB::raw("count(*) as online")
|
||||
)
|
||||
->where('updated_at', '>=', time() - 3600)
|
||||
->groupBy('server_id')
|
||||
->get();
|
||||
foreach ($serverLogs as $serverLog) {
|
||||
$data = [
|
||||
'server_id' => $serverLog->server_id,
|
||||
'u' => $serverLog->u,
|
||||
'd' => $serverLog->d,
|
||||
'online' => $serverLog->online
|
||||
];
|
||||
// ServerStat::create($data);
|
||||
}
|
||||
}
|
||||
}
|
@ -47,13 +47,14 @@ class V2boardInstall extends Command
|
||||
$this->info(" \ \ / / __) | _ \ / _ \ / _` | '__/ _` | ");
|
||||
$this->info(" \ V / / __/| |_) | (_) | (_| | | | (_| | ");
|
||||
$this->info(" \_/ |_____|____/ \___/ \__,_|_| \__,_| ");
|
||||
if (\File::exists(base_path() . '/.lock')) {
|
||||
abort(500, 'V2board 已安装,如需重新安装请删除目录下.lock文件');
|
||||
if (\File::exists(base_path() . '/.env')) {
|
||||
$securePath = config('v2board.secure_path', config('v2board.frontend_admin_path', hash('crc32b', config('app.key'))));
|
||||
$this->info("访问 http(s)://你的站点/{$securePath} 进入管理面板,你可以在用户中心修改你的密码。");
|
||||
abort(500, '如需重新安装请删除目录下.env文件');
|
||||
}
|
||||
if (!\File::exists(base_path() . '/.env')) {
|
||||
if (!copy(base_path() . '/.env.example', base_path() . '/.env')) {
|
||||
abort(500, '复制环境文件失败,请检查目录权限');
|
||||
}
|
||||
|
||||
if (!copy(base_path() . '/.env.example', base_path() . '/.env')) {
|
||||
abort(500, '复制环境文件失败,请检查目录权限');
|
||||
}
|
||||
$this->saveToEnv([
|
||||
'APP_KEY' => 'base64:' . base64_encode(Encrypter::generateKey('AES-256-CBC')),
|
||||
@ -90,17 +91,17 @@ class V2boardInstall extends Command
|
||||
while (!$email) {
|
||||
$email = $this->ask('请输入管理员邮箱?');
|
||||
}
|
||||
$password = '';
|
||||
while (!$password) {
|
||||
$password = $this->ask('请输入管理员密码?');
|
||||
}
|
||||
$password = Helper::guid(false);
|
||||
if (!$this->registerAdmin($email, $password)) {
|
||||
abort(500, '管理员账号注册失败,请重试');
|
||||
}
|
||||
|
||||
$this->info('一切就绪');
|
||||
$this->info('访问 http(s)://你的站点/admin 进入管理面板');
|
||||
\File::put(base_path() . '/.lock', time());
|
||||
$this->info("管理员邮箱:{$email}");
|
||||
$this->info("管理员密码:{$password}");
|
||||
|
||||
$defaultSecurePath = hash('crc32b', config('app.key'));
|
||||
$this->info("访问 http(s)://你的站点/{$defaultSecurePath} 进入管理面板,你可以在用户中心修改你的密码。");
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
140
app/Console/Commands/V2boardStatistics.php
Normal file
140
app/Console/Commands/V2boardStatistics.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\StatServer;
|
||||
use App\Models\StatUser;
|
||||
use App\Services\StatisticalService;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Stat;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class V2boardStatistics extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'v2board:statistics';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '统计任务';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$startAt = microtime(true);
|
||||
ini_set('memory_limit', -1);
|
||||
$this->statUser();
|
||||
$this->statServer();
|
||||
$this->stat();
|
||||
info('统计任务执行完毕。耗时:' . (microtime(true) - $startAt) / 1000);
|
||||
}
|
||||
|
||||
private function statServer()
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$createdAt = time();
|
||||
$recordAt = strtotime('-1 day', strtotime(date('Y-m-d')));
|
||||
$statService = new StatisticalService();
|
||||
$statService->setStartAt($recordAt);
|
||||
$statService->setServerStats();
|
||||
$stats = $statService->getStatServer();
|
||||
foreach ($stats as $stat) {
|
||||
if (!StatServer::insert([
|
||||
'server_id' => $stat['server_id'],
|
||||
'server_type' => $stat['server_type'],
|
||||
'u' => $stat['u'],
|
||||
'd' => $stat['d'],
|
||||
'created_at' => $createdAt,
|
||||
'updated_at' => $createdAt,
|
||||
'record_type' => 'd',
|
||||
'record_at' => $recordAt
|
||||
])) {
|
||||
throw new \Exception('stat server fail');
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
$statService->clearStatServer();
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
\Log::error($e->getMessage(), ['exception' => $e]);
|
||||
}
|
||||
}
|
||||
|
||||
private function statUser()
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
$createdAt = time();
|
||||
$recordAt = strtotime('-1 day', strtotime(date('Y-m-d')));
|
||||
$statService = new StatisticalService();
|
||||
$statService->setStartAt($recordAt);
|
||||
$statService->setUserStats();
|
||||
$stats = $statService->getStatUser();
|
||||
foreach ($stats as $stat) {
|
||||
if (!StatUser::insert([
|
||||
'user_id' => $stat['user_id'],
|
||||
'u' => $stat['u'],
|
||||
'd' => $stat['d'],
|
||||
'server_rate' => $stat['server_rate'],
|
||||
'created_at' => $createdAt,
|
||||
'updated_at' => $createdAt,
|
||||
'record_type' => 'd',
|
||||
'record_at' => $recordAt
|
||||
])) {
|
||||
throw new \Exception('stat user fail');
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
$statService->clearStatUser();
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
\Log::error($e->getMessage(), ['exception' => $e]);
|
||||
}
|
||||
}
|
||||
|
||||
private function stat()
|
||||
{
|
||||
try {
|
||||
$endAt = strtotime(date('Y-m-d'));
|
||||
$startAt = strtotime('-1 day', $endAt);
|
||||
$statisticalService = new StatisticalService();
|
||||
$statisticalService->setStartAt($startAt);
|
||||
$statisticalService->setEndAt($endAt);
|
||||
$data = $statisticalService->generateStatData();
|
||||
$data['record_at'] = $startAt;
|
||||
$data['record_type'] = 'd';
|
||||
$statistic = Stat::where('record_at', $startAt)
|
||||
->where('record_type', 'd')
|
||||
->first();
|
||||
if ($statistic) {
|
||||
$statistic->update($data);
|
||||
return;
|
||||
}
|
||||
Stat::create($data);
|
||||
} catch (\Exception $e) {
|
||||
\Log::error($e->getMessage(), ['exception' => $e]);
|
||||
}
|
||||
}
|
||||
}
|
@ -51,11 +51,13 @@ class V2boardUpdate extends Command
|
||||
}
|
||||
$this->info('正在导入数据库请稍等...');
|
||||
foreach ($sql as $item) {
|
||||
if (!$item) continue;
|
||||
try {
|
||||
DB::select(DB::raw($item));
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
$this->info('更新完毕');
|
||||
\Artisan::call('horizon:terminate');
|
||||
$this->info('更新完毕,队列服务已重启,你无需进行任何操作。');
|
||||
}
|
||||
}
|
||||
|
10
app/Console/Kernel.php
Executable file → Normal file
10
app/Console/Kernel.php
Executable file → Normal file
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
@ -24,16 +26,20 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
Cache::put(CacheKey::get('SCHEDULE_LAST_CHECK_AT', null), time());
|
||||
// v2board
|
||||
$schedule->command('v2board:cache')->hourly();
|
||||
$schedule->command('v2board:statistics')->dailyAt('0:10');
|
||||
// check
|
||||
$schedule->command('check:order')->everyMinute();
|
||||
$schedule->command('check:commission')->everyMinute();
|
||||
$schedule->command('check:ticket')->everyMinute();
|
||||
// reset
|
||||
$schedule->command('reset:traffic')->daily();
|
||||
$schedule->command('reset:serverLog')->quarterly();
|
||||
$schedule->command('reset:log')->daily();
|
||||
// send
|
||||
$schedule->command('send:remindMail')->dailyAt('11:30');
|
||||
// horizon metrics
|
||||
$schedule->command('horizon:snapshot')->everyFiveMinutes();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,8 +2,11 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Support\Arr;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Throwable;
|
||||
use Facade\Ignition\Exceptions\ViewException;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
@ -29,10 +32,12 @@ class Handler extends ExceptionHandler
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* @param \Exception $exception
|
||||
* @param \Throwable $exception
|
||||
* @return void
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function report(Exception $exception)
|
||||
public function report(Throwable $exception)
|
||||
{
|
||||
parent::report($exception);
|
||||
}
|
||||
@ -40,16 +45,33 @@ class Handler extends ExceptionHandler
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Exception $exception
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Throwable $exception
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function render($request, Exception $exception)
|
||||
public function render($request, Throwable $exception)
|
||||
{
|
||||
if($exception instanceof \Illuminate\Http\Exceptions\ThrottleRequestsException) {
|
||||
abort(429, '请求频繁,请稍后再试');
|
||||
if ($exception instanceof ViewException) {
|
||||
abort(500, "主题渲染失败。如更新主题,参数可能发生变化请重新配置主题后再试。");
|
||||
}
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
|
||||
|
||||
protected function convertExceptionToArray(Throwable $e)
|
||||
{
|
||||
return config('app.debug') ? [
|
||||
'message' => $e->getMessage(),
|
||||
'exception' => get_class($e),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
'trace' => collect($e->getTrace())->map(function ($trace) {
|
||||
return Arr::except($trace, ['args']);
|
||||
})->all(),
|
||||
] : [
|
||||
'message' => $this->isHttpException($e) ? $e->getMessage() : __("Uh-oh, we've had some problems, we're working on it."),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,172 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\ConfigSave;
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Utils\Dict;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class ConfigController extends Controller
|
||||
{
|
||||
public function getEmailTemplate()
|
||||
{
|
||||
$path = resource_path('views/mail/');
|
||||
$files = array_map(function ($item) use ($path) {
|
||||
return str_replace($path, '', $item);
|
||||
}, glob($path . '*'));
|
||||
return response([
|
||||
'data' => $files
|
||||
]);
|
||||
}
|
||||
|
||||
public function setTelegramWebhook(Request $request)
|
||||
{
|
||||
$telegramService = new TelegramService($request->input('telegram_bot_token'));
|
||||
$telegramService->getMe();
|
||||
$telegramService->setWebhook(
|
||||
url(
|
||||
'/api/v1/guest/telegram/webhook?access_token=' . md5(config('v2board.telegram_bot_token', $request->input('telegram_bot_token')))
|
||||
)
|
||||
);
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetch()
|
||||
{
|
||||
// TODO: default should be in Dict
|
||||
return response([
|
||||
'data' => [
|
||||
'invite' => [
|
||||
'invite_force' => (int)config('v2board.invite_force', 0),
|
||||
'invite_commission' => config('v2board.invite_commission', 10),
|
||||
'invite_gen_limit' => config('v2board.invite_gen_limit', 5),
|
||||
'invite_never_expire' => config('v2board.invite_never_expire', 0),
|
||||
'commission_first_time_enable' => config('v2board.commission_first_time_enable', 1),
|
||||
'commission_auto_check_enable' => config('v2board.commission_auto_check_enable', 1),
|
||||
'commission_withdraw_limit' => config('v2board.commission_withdraw_limit', 100)
|
||||
],
|
||||
'site' => [
|
||||
'safe_mode_enable' => (int)config('v2board.safe_mode_enable', 0),
|
||||
'stop_register' => (int)config('v2board.stop_register', 0),
|
||||
'email_verify' => (int)config('v2board.email_verify', 0),
|
||||
'app_name' => config('v2board.app_name', 'V2Board'),
|
||||
'app_description' => config('v2board.app_description', 'V2Board is best!'),
|
||||
'app_url' => config('v2board.app_url'),
|
||||
'subscribe_url' => config('v2board.subscribe_url'),
|
||||
'try_out_plan_id' => (int)config('v2board.try_out_plan_id', 0),
|
||||
'try_out_hour' => (int)config('v2board.try_out_hour', 1),
|
||||
'email_whitelist_enable' => (int)config('v2board.email_whitelist_enable', 0),
|
||||
'email_whitelist_suffix' => config('v2board.email_whitelist_suffix', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT),
|
||||
'email_gmail_limit_enable' => config('v2board.email_gmail_limit_enable', 0),
|
||||
'recaptcha_enable' => (int)config('v2board.recaptcha_enable', 0),
|
||||
'recaptcha_key' => config('v2board.recaptcha_key'),
|
||||
'recaptcha_site_key' => config('v2board.recaptcha_site_key')
|
||||
],
|
||||
'subscribe' => [
|
||||
'plan_change_enable' => (int)config('v2board.plan_change_enable', 1),
|
||||
'reset_traffic_method' => (int)config('v2board.reset_traffic_method', 0),
|
||||
'renew_reset_traffic_enable' => (int)config('v2board.renew_reset_traffic_enable', 0),
|
||||
'surplus_enable' => (int)config('v2board.surplus_enable', 1)
|
||||
],
|
||||
'pay' => [
|
||||
// alipay
|
||||
'alipay_enable' => (int)config('v2board.alipay_enable'),
|
||||
'alipay_appid' => config('v2board.alipay_appid'),
|
||||
'alipay_pubkey' => config('v2board.alipay_pubkey'),
|
||||
'alipay_privkey' => config('v2board.alipay_privkey'),
|
||||
// stripe
|
||||
'stripe_alipay_enable' => (int)config('v2board.stripe_alipay_enable', 0),
|
||||
'stripe_wepay_enable' => (int)config('v2board.stripe_wepay_enable', 0),
|
||||
'stripe_card_enable' => (int)config('v2board.stripe_card_enable', 0),
|
||||
'stripe_sk_live' => config('v2board.stripe_sk_live'),
|
||||
'stripe_pk_live' => config('v2board.stripe_pk_live'),
|
||||
'stripe_webhook_key' => config('v2board.stripe_webhook_key'),
|
||||
'stripe_currency' => config('v2board.stripe_currency', 'hkd'),
|
||||
// bitpayx
|
||||
'bitpayx_name' => config('v2board.bitpayx_name', '在线支付'),
|
||||
'bitpayx_enable' => (int)config('v2board.bitpayx_enable', 0),
|
||||
'bitpayx_appsecret' => config('v2board.bitpayx_appsecret'),
|
||||
// mGate
|
||||
'mgate_name' => config('v2board.mgate_name', '在线支付'),
|
||||
'mgate_enable' => (int)config('v2board.mgate_enable', 0),
|
||||
'mgate_url' => config('v2board.mgate_url'),
|
||||
'mgate_app_id' => config('v2board.mgate_app_id'),
|
||||
'mgate_app_secret' => config('v2board.mgate_app_secret'),
|
||||
// Epay
|
||||
'epay_name' => config('v2board.epay_name', '在线支付'),
|
||||
'epay_enable' => (int)config('v2board.epay_enable', 0),
|
||||
'epay_url' => config('v2board.epay_url'),
|
||||
'epay_pid' => config('v2board.epay_pid'),
|
||||
'epay_key' => config('v2board.epay_key'),
|
||||
],
|
||||
'frontend' => [
|
||||
'frontend_theme_sidebar' => config('v2board.frontend_theme_sidebar', 'light'),
|
||||
'frontend_theme_header' => config('v2board.frontend_theme_header', 'dark'),
|
||||
'frontend_theme_color' => config('v2board.frontend_theme_color', 'default'),
|
||||
'frontend_background_url' => config('v2board.frontend_background_url'),
|
||||
'frontend_admin_path' => config('v2board.frontend_admin_path', 'admin')
|
||||
],
|
||||
'server' => [
|
||||
'server_token' => config('v2board.server_token'),
|
||||
'server_license' => config('v2board.server_license'),
|
||||
'server_log_enable' => config('v2board.server_log_enable', 0),
|
||||
'server_v2ray_domain' => config('v2board.server_v2ray_domain'),
|
||||
'server_v2ray_protocol' => config('v2board.server_v2ray_protocol'),
|
||||
],
|
||||
'tutorial' => [
|
||||
'apple_id' => config('v2board.apple_id')
|
||||
],
|
||||
'email' => [
|
||||
'email_template' => config('v2board.email_template', 'default'),
|
||||
'email_host' => config('v2board.email_host'),
|
||||
'email_port' => config('v2board.email_port'),
|
||||
'email_username' => config('v2board.email_username'),
|
||||
'email_password' => config('v2board.email_password'),
|
||||
'email_encryption' => config('v2board.email_encryption'),
|
||||
'email_from_address' => config('v2board.email_from_address')
|
||||
],
|
||||
'telegram' => [
|
||||
'telegram_bot_enable' => config('v2board.telegram_bot_enable', 0),
|
||||
'telegram_bot_token' => config('v2board.telegram_bot_token')
|
||||
],
|
||||
'app' => [
|
||||
'windows_version' => config('v2board.windows_version'),
|
||||
'windows_download_url' => config('v2board.windows_download_url'),
|
||||
'macos_version' => config('v2board.macos_version'),
|
||||
'macos_download_url' => config('v2board.macos_download_url'),
|
||||
'android_version' => config('v2board.android_version'),
|
||||
'android_download_url' => config('v2board.android_download_url')
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(ConfigSave $request)
|
||||
{
|
||||
$data = $request->input();
|
||||
$array = \Config::get('v2board');
|
||||
foreach ($data as $k => $v) {
|
||||
if (!in_array($k, array_keys($request->validated()))) {
|
||||
abort(500, '参数' . $k . '不在规则内,禁止修改');
|
||||
}
|
||||
$array[$k] = $v;
|
||||
}
|
||||
$data = var_export($array, 1);
|
||||
if (!\File::put(base_path() . '/config/v2board.php', "<?php\n return $data ;")) {
|
||||
abort(500, '修改失败');
|
||||
}
|
||||
if (function_exists('opcache_reset')) {
|
||||
if (opcache_reset() === false) {
|
||||
abort(500, '缓存清除失败,请卸载或检查opcache配置状态');
|
||||
}
|
||||
}
|
||||
\Artisan::call('config:cache');
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
|
||||
use App\Http\Requests\Admin\ServerTrojanSort;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerGroup;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Models\ServerTrojan;
|
||||
use App\Models\User;
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ManageController extends Controller
|
||||
{
|
||||
public function getNodes(Request $request)
|
||||
{
|
||||
$serverService = new ServerService();
|
||||
$servers = array_merge(
|
||||
$serverService->getShadowsocksServers(),
|
||||
$serverService->getV2rayServers(),
|
||||
$serverService->getTrojanServers()
|
||||
);
|
||||
$tmp = array_column($servers, 'sort');
|
||||
array_multisort($tmp, SORT_ASC, $servers);
|
||||
return response([
|
||||
'data' => $servers
|
||||
]);
|
||||
}
|
||||
|
||||
public function sort(Request $request)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
foreach ($request->input('sorts') as $k => $v) {
|
||||
switch ($v['key']) {
|
||||
case 'shadowsocks':
|
||||
if (!ServerShadowsocks::find($v['value'])->update(['sort' => $k + 1])) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
break;
|
||||
case 'v2ray':
|
||||
if (!Server::find($v['value'])->update(['sort' => $k + 1])) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
break;
|
||||
case 'trojan':
|
||||
if (!ServerTrojan::find($v['value'])->update(['sort' => $k + 1])) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
|
||||
use App\Http\Requests\Admin\ServerV2raySave;
|
||||
use App\Http\Requests\Admin\ServerV2raySort;
|
||||
use App\Http\Requests\Admin\ServerV2rayUpdate;
|
||||
use App\Services\ServerService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class V2rayController extends Controller
|
||||
{
|
||||
public function save(ServerV2raySave $request)
|
||||
{
|
||||
$params = $request->validated();
|
||||
$params['group_id'] = json_encode($params['group_id']);
|
||||
if (isset($params['tags'])) {
|
||||
$params['tags'] = json_encode($params['tags']);
|
||||
}
|
||||
|
||||
if (isset($params['dnsSettings'])) {
|
||||
if (!is_object(json_decode($params['dnsSettings']))) {
|
||||
abort(500, 'DNS规则配置格式不正确');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($params['ruleSettings'])) {
|
||||
if (!is_object(json_decode($params['ruleSettings']))) {
|
||||
abort(500, '审计规则配置格式不正确');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($params['networkSettings'])) {
|
||||
if (!is_object(json_decode($params['networkSettings']))) {
|
||||
abort(500, '传输协议配置格式不正确');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($params['tlsSettings'])) {
|
||||
if (!is_object(json_decode($params['tlsSettings']))) {
|
||||
abort(500, 'TLS配置格式不正确');
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->input('id')) {
|
||||
$server = Server::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
if (!Server::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$server = Server::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $server->delete()
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(ServerV2rayUpdate $request)
|
||||
{
|
||||
$params = $request->only([
|
||||
'show',
|
||||
]);
|
||||
|
||||
$server = Server::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function copy(Request $request)
|
||||
{
|
||||
$server = Server::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
if (!Server::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function viewConfig(Request $request)
|
||||
{
|
||||
$serverService = new ServerService();
|
||||
$config = $serverService->getVmessConfig($request->input('node_id'), 23333);
|
||||
return response([
|
||||
'data' => $config
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerGroup;
|
||||
use App\Models\Server;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class StatController extends Controller
|
||||
{
|
||||
public function getOverride(Request $request)
|
||||
{
|
||||
return response([
|
||||
'data' => [
|
||||
'month_income' => Order::where('created_at', '>=', strtotime(date('Y-m-1')))
|
||||
->where('created_at', '<', time())
|
||||
->whereIn('status', [3, 4])
|
||||
->sum('total_amount'),
|
||||
'month_register_total' => User::where('created_at', '>=', strtotime(date('Y-m-1')))
|
||||
->where('created_at', '<', time())
|
||||
->count(),
|
||||
'ticket_pendding_total' => Ticket::where('status', 0)
|
||||
->count(),
|
||||
'commission_pendding_total' => Order::where('commission_status', 0)
|
||||
->where('invite_user_id', '!=', NULL)
|
||||
->where('status', [3, 4])
|
||||
->where('commission_balance', '>', 0)
|
||||
->count(),
|
||||
'day_income' => Order::where('created_at', '>=', strtotime(date('Y-m-d')))
|
||||
->where('created_at', '<', time())
|
||||
->whereIn('status', [3, 4])
|
||||
->sum('total_amount'),
|
||||
'last_month_income' => Order::where('created_at', '>=', strtotime('-1 month', strtotime(date('Y-m-1'))))
|
||||
->where('created_at', '<', strtotime(date('Y-m-1')))
|
||||
->whereIn('status', [3, 4])
|
||||
->sum('total_amount')
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\Clash;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Server;
|
||||
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 = [];
|
||||
$user = $request->user;
|
||||
$userService = new UserService();
|
||||
if ($userService->isAvailable($user)) {
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAvailableServers($user);
|
||||
}
|
||||
$config = Yaml::parseFile(base_path() . '/resources/rules/app.clash.yaml');
|
||||
$proxy = [];
|
||||
$proxies = [];
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
array_push($proxy, Clash::buildShadowsocks($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'v2ray') {
|
||||
array_push($proxy, Clash::buildVmess($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
array_push($proxy, Clash::buildTrojan($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
}
|
||||
|
||||
$config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy);
|
||||
foreach ($config['proxy-groups'] as $k => $v) {
|
||||
$config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies);
|
||||
}
|
||||
die(Yaml::dump($config));
|
||||
}
|
||||
|
||||
public function getVersion(Request $request)
|
||||
{
|
||||
if (strpos($request->header('user-agent'), 'tidalab/4.0.0') !== false
|
||||
|| strpos($request->header('user-agent'), 'tunnelab/4.0.0') !== false
|
||||
) {
|
||||
if (strpos($request->header('user-agent'), 'Win64') !== false) {
|
||||
return response([
|
||||
'data' => [
|
||||
'version' => config('v2board.windows_version'),
|
||||
'download_url' => config('v2board.windows_download_url')
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
return response([
|
||||
'data' => [
|
||||
'version' => config('v2board.macos_version'),
|
||||
'download_url' => config('v2board.macos_download_url')
|
||||
]
|
||||
]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
return response([
|
||||
'data' => [
|
||||
'windows_version' => config('v2board.windows_version'),
|
||||
'windows_download_url' => config('v2board.windows_download_url'),
|
||||
'macos_version' => config('v2board.macos_version'),
|
||||
'macos_download_url' => config('v2board.macos_download_url'),
|
||||
'android_version' => config('v2board.android_version'),
|
||||
'android_download_url' => config('v2board.android_download_url')
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function config(Request $request)
|
||||
{
|
||||
if (empty($request->input('server_id'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$user = $request->user;
|
||||
if ($user->expired_at < time() && $user->expired_at !== NULL) {
|
||||
abort(500, '订阅计划已过期');
|
||||
}
|
||||
$server = Server::where('show', 1)
|
||||
->where('id', $request->input('server_id'))
|
||||
->first();
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
$json = json_decode(self::CLIENT_CONFIG);
|
||||
//socks
|
||||
$json->inbound->port = (int)self::SOCKS_PORT;
|
||||
//http
|
||||
$json->inboundDetour[0]->port = (int)self::HTTP_PORT;
|
||||
//other
|
||||
$json->outbound->settings->vnext[0]->address = (string)$server->host;
|
||||
$json->outbound->settings->vnext[0]->port = (int)$server->port;
|
||||
$json->outbound->settings->vnext[0]->users[0]->id = (string)$user->uuid;
|
||||
$json->outbound->settings->vnext[0]->users[0]->alterId = (int)$server->alter_id;
|
||||
$json->outbound->settings->vnext[0]->remark = (string)$server->name;
|
||||
$json->outbound->streamSettings->network = $server->network;
|
||||
if ($server->networkSettings) {
|
||||
switch ($server->network) {
|
||||
case 'tcp':
|
||||
$json->outbound->streamSettings->tcpSettings = json_decode($server->networkSettings);
|
||||
break;
|
||||
case 'kcp':
|
||||
$json->outbound->streamSettings->kcpSettings = json_decode($server->networkSettings);
|
||||
break;
|
||||
case 'ws':
|
||||
$json->outbound->streamSettings->wsSettings = json_decode($server->networkSettings);
|
||||
break;
|
||||
case 'http':
|
||||
$json->outbound->streamSettings->httpSettings = json_decode($server->networkSettings);
|
||||
break;
|
||||
case 'domainsocket':
|
||||
$json->outbound->streamSettings->dsSettings = json_decode($server->networkSettings);
|
||||
break;
|
||||
case 'quic':
|
||||
$json->outbound->streamSettings->quicSettings = json_decode($server->networkSettings);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($request->input('is_global')) {
|
||||
$json->routing->settings->rules[0]->outboundTag = 'proxy';
|
||||
}
|
||||
if ($server->tls) {
|
||||
$json->outbound->streamSettings->security = "tls";
|
||||
}
|
||||
die(json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
@ -1,276 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ServerService;
|
||||
use App\Utils\Clash;
|
||||
use App\Utils\QuantumultX;
|
||||
use App\Utils\Shadowrocket;
|
||||
use App\Utils\Surge;
|
||||
use App\Utils\Surfboard;
|
||||
use App\Utils\URLSchemes;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Server;
|
||||
use App\Utils\Helper;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use App\Services\UserService;
|
||||
|
||||
class ClientController extends Controller
|
||||
{
|
||||
public function subscribe(Request $request)
|
||||
{
|
||||
$flag = $request->input('flag')
|
||||
?? (isset($_SERVER['HTTP_USER_AGENT'])
|
||||
? $_SERVER['HTTP_USER_AGENT']
|
||||
: '');
|
||||
$flag = strtolower($flag);
|
||||
$user = $request->user;
|
||||
// account not expired and is not banned.
|
||||
$userService = new UserService();
|
||||
if ($userService->isAvailable($user)) {
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAvailableServers($user);
|
||||
if ($flag) {
|
||||
if (strpos($flag, 'quantumult%20x') !== false) {
|
||||
die($this->quantumultX($user, $servers));
|
||||
}
|
||||
if (strpos($flag, 'quantumult') !== false) {
|
||||
die($this->quantumult($user, $servers));
|
||||
}
|
||||
if (strpos($flag, 'clash') !== false) {
|
||||
die($this->clash($user, $servers));
|
||||
}
|
||||
if (strpos($flag, 'surfboard') !== false) {
|
||||
die($this->surfboard($user, $servers));
|
||||
}
|
||||
if (strpos($flag, 'surge') !== false) {
|
||||
die($this->surge($user, $servers));
|
||||
}
|
||||
if (strpos($flag, 'shadowrocket') !== false) {
|
||||
die($this->shadowrocket($user, $servers));
|
||||
}
|
||||
if (strpos($flag, 'shadowsocks') !== false) {
|
||||
die($this->shaodowsocksSIP008($user, $servers));
|
||||
}
|
||||
}
|
||||
die($this->origin($user, $servers));
|
||||
}
|
||||
}
|
||||
// TODO: Ready to stop support
|
||||
private function quantumult($user, $servers = [])
|
||||
{
|
||||
$uri = '';
|
||||
header('subscription-userinfo: upload=' . $user->u . '; download=' . $user->d . ';total=' . $user->transfer_enable);
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'v2ray') {
|
||||
$str = '';
|
||||
$str .= $item['name'] . '= vmess, ' . $item['host'] . ', ' . $item['port'] . ', chacha20-ietf-poly1305, "' . $user['uuid'] . '", over-tls=' . ($item['tls'] ? "true" : "false") . ', certificate=0, group=' . config('v2board.app_name', 'V2Board');
|
||||
if ($item['network'] === 'ws') {
|
||||
$str .= ', obfs=ws';
|
||||
if ($item['networkSettings']) {
|
||||
$wsSettings = json_decode($item['networkSettings'], true);
|
||||
if (isset($wsSettings['path'])) $str .= ', obfs-path="' . $wsSettings['path'] . '"';
|
||||
if (isset($wsSettings['headers']['Host'])) $str .= ', obfs-header="Host:' . $wsSettings['headers']['Host'] . '"';
|
||||
}
|
||||
}
|
||||
$uri .= "vmess://" . base64_encode($str) . "\r\n";
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
private function shadowrocket($user, $servers = [])
|
||||
{
|
||||
$uri = '';
|
||||
//display remaining traffic and expire date
|
||||
$upload = round($user->u / (1024*1024*1024), 2);
|
||||
$download = round($user->d / (1024*1024*1024), 2);
|
||||
$totalTraffic = round($user->transfer_enable / (1024*1024*1024), 2);
|
||||
$expiredDate = date('Y-m-d', $user->expired_at);
|
||||
$uri .= "STATUS=🚀↑:{$upload}GB,↓:{$download}GB,TOT:{$totalTraffic}GB💡Expires:{$expiredDate}\r\n";
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
$uri .= Shadowrocket::buildShadowsocks($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'v2ray') {
|
||||
$uri .= Shadowrocket::buildVmess($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
$uri .= Shadowrocket::buildTrojan($user['uuid'], $item);
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
private function quantumultX($user, $servers = [])
|
||||
{
|
||||
$uri = '';
|
||||
header("subscription-userinfo: upload={$user->u}; download={$user->d}; total={$user->transfer_enable}; expire={$user->expired_at}");
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
$uri .= QuantumultX::buildShadowsocks($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'v2ray') {
|
||||
$uri .= QuantumultX::buildVmess($user['uuid'], $item);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
$uri .= QuantumultX::buildTrojan($user['uuid'], $item);
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
private function origin($user, $servers = [])
|
||||
{
|
||||
$uri = '';
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
$uri .= URLSchemes::buildShadowsocks($item, $user);
|
||||
}
|
||||
if ($item['type'] === 'v2ray') {
|
||||
$uri .= URLSchemes::buildVmess($item, $user);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
$uri .= URLSchemes::buildTrojan($item, $user);
|
||||
}
|
||||
}
|
||||
return base64_encode($uri);
|
||||
}
|
||||
|
||||
private function shaodowsocksSIP008($user, $servers = [])
|
||||
{
|
||||
$configs = [];
|
||||
$subs = [];
|
||||
$subs['servers'] = [];
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
array_push($configs, URLSchemes::buildShadowsocksSIP008($item, $user));
|
||||
}
|
||||
}
|
||||
|
||||
$subs['version'] = 1;
|
||||
$subs['remark'] = config('v2board.app_name', 'V2Board');
|
||||
$subs['servers'] = array_merge($subs['servers'] ? $subs['servers'] : [], $configs);
|
||||
|
||||
return json_encode($subs, JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
private function surge($user, $servers = [])
|
||||
{
|
||||
$proxies = '';
|
||||
$proxyGroup = '';
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
// [Proxy]
|
||||
$proxies .= Surge::buildShadowsocks($user['uuid'], $item);
|
||||
// [Proxy Group]
|
||||
$proxyGroup .= $item['name'] . ', ';
|
||||
}
|
||||
if ($item['type'] === 'v2ray') {
|
||||
// [Proxy]
|
||||
$proxies .= Surge::buildVmess($user['uuid'], $item);
|
||||
// [Proxy Group]
|
||||
$proxyGroup .= $item['name'] . ', ';
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
// [Proxy]
|
||||
$proxies .= Surge::buildTrojan($user['uuid'], $item);
|
||||
// [Proxy Group]
|
||||
$proxyGroup .= $item['name'] . ', ';
|
||||
}
|
||||
}
|
||||
|
||||
$defaultConfig = base_path() . '/resources/rules/default.surge.conf';
|
||||
$customConfig = base_path() . '/resources/rules/custom.surge.conf';
|
||||
if (\File::exists($customConfig)) {
|
||||
$config = file_get_contents("$customConfig");
|
||||
} else {
|
||||
$config = file_get_contents("$defaultConfig");
|
||||
}
|
||||
|
||||
// Subscription link
|
||||
$subsURL = config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $user['token'];
|
||||
|
||||
$config = str_replace('$subs_link', $subsURL, $config);
|
||||
$config = str_replace('$proxies', $proxies, $config);
|
||||
$config = str_replace('$proxy_group', rtrim($proxyGroup, ', '), $config);
|
||||
return $config;
|
||||
}
|
||||
|
||||
private function surfboard($user, $servers = [])
|
||||
{
|
||||
$proxies = '';
|
||||
$proxyGroup = '';
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
// [Proxy]
|
||||
$proxies .= Surfboard::buildShadowsocks($user['uuid'], $item);
|
||||
// [Proxy Group]
|
||||
$proxyGroup .= $item['name'] . ', ';
|
||||
}
|
||||
if ($item['type'] === 'v2ray') {
|
||||
// [Proxy]
|
||||
$proxies .= Surfboard::buildVmess($user['uuid'], $item);
|
||||
// [Proxy Group]
|
||||
$proxyGroup .= $item['name'] . ', ';
|
||||
}
|
||||
}
|
||||
|
||||
$defaultConfig = base_path() . '/resources/rules/default.surfboard.conf';
|
||||
$customConfig = base_path() . '/resources/rules/custom.surfboard.conf';
|
||||
if (\File::exists($customConfig)) {
|
||||
$config = file_get_contents("$customConfig");
|
||||
} else {
|
||||
$config = file_get_contents("$defaultConfig");
|
||||
}
|
||||
|
||||
// Subscription link
|
||||
$subsURL = config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $user['token'];
|
||||
|
||||
$config = str_replace('$subs_link', $subsURL, $config);
|
||||
$config = str_replace('$proxies', $proxies, $config);
|
||||
$config = str_replace('$proxy_group', rtrim($proxyGroup, ', '), $config);
|
||||
return $config;
|
||||
}
|
||||
|
||||
private function clash($user, $servers = [])
|
||||
{
|
||||
$defaultConfig = base_path() . '/resources/rules/default.clash.yaml';
|
||||
$customConfig = base_path() . '/resources/rules/custom.clash.yaml';
|
||||
if (\File::exists($customConfig)) {
|
||||
$config = Yaml::parseFile($customConfig);
|
||||
} else {
|
||||
$config = Yaml::parseFile($defaultConfig);
|
||||
}
|
||||
$proxy = [];
|
||||
$proxies = [];
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks') {
|
||||
array_push($proxy, Clash::buildShadowsocks($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'v2ray') {
|
||||
array_push($proxy, Clash::buildVmess($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
array_push($proxy, Clash::buildTrojan($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
}
|
||||
|
||||
$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;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies);
|
||||
}
|
||||
$yaml = Yaml::dump($config);
|
||||
$yaml = str_replace('$app_name', config('v2board.app_name', 'V2Board'), $yaml);
|
||||
return $yaml;
|
||||
}
|
||||
}
|
@ -1,177 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Guest;
|
||||
|
||||
use App\Services\OrderService;
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use Library\Epay;
|
||||
use Omnipay\Omnipay;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Library\BitpayX;
|
||||
use Library\MGate;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function alipayNotify(Request $request)
|
||||
{
|
||||
// Log::info('alipayNotifyData: ' . json_encode($_POST));
|
||||
$gateway = Omnipay::create('Alipay_AopF2F');
|
||||
$gateway->setSignType('RSA2'); //RSA/RSA2
|
||||
$gateway->setAppId(config('v2board.alipay_appid'));
|
||||
$gateway->setPrivateKey(config('v2board.alipay_privkey')); // 可以是路径,也可以是密钥内容
|
||||
$gateway->setAlipayPublicKey(config('v2board.alipay_pubkey')); // 可以是路径,也可以是密钥内容
|
||||
$request = $gateway->completePurchase();
|
||||
$request->setParams($_POST); //Optional
|
||||
try {
|
||||
/** @var \Omnipay\Alipay\Responses\AopCompletePurchaseResponse $response */
|
||||
$response = $request->send();
|
||||
|
||||
if ($response->isPaid()) {
|
||||
/**
|
||||
* Payment is successful
|
||||
*/
|
||||
if (!$this->handle($_POST['out_trade_no'], $_POST['trade_no'])) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
|
||||
die('success'); //The response should be 'success' only
|
||||
} else {
|
||||
/**
|
||||
* Payment is not successful
|
||||
*/
|
||||
die('fail');
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/**
|
||||
* Payment is not successful
|
||||
*/
|
||||
die('fail');
|
||||
}
|
||||
}
|
||||
|
||||
public function stripeNotify(Request $request)
|
||||
{
|
||||
// Log::info('stripeNotifyData: ' . json_encode($request->input()));
|
||||
|
||||
\Stripe\Stripe::setApiKey(config('v2board.stripe_sk_live'));
|
||||
try {
|
||||
$event = \Stripe\Webhook::constructEvent(
|
||||
file_get_contents('php://input'),
|
||||
$_SERVER['HTTP_STRIPE_SIGNATURE'],
|
||||
config('v2board.stripe_webhook_key')
|
||||
);
|
||||
} catch (\Stripe\Error\SignatureVerification $e) {
|
||||
abort(400);
|
||||
}
|
||||
switch ($event->type) {
|
||||
case 'source.chargeable':
|
||||
$object = $event->data->object;
|
||||
\Stripe\Charge::create([
|
||||
'amount' => $object->amount,
|
||||
'currency' => $object->currency,
|
||||
'source' => $object->id,
|
||||
'metadata' => json_decode($object->metadata, true)
|
||||
]);
|
||||
die('success');
|
||||
break;
|
||||
case 'charge.succeeded':
|
||||
$object = $event->data->object;
|
||||
if ($object->status === 'succeeded') {
|
||||
$metaData = isset($object->metadata->out_trade_no) ? $object->metadata : $object->source->metadata;
|
||||
$tradeNo = $metaData->out_trade_no;
|
||||
if (!$tradeNo) {
|
||||
abort(500, 'trade no is not found in metadata');
|
||||
}
|
||||
if (!$this->handle($tradeNo, $object->balance_transaction)) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
die('success');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
abort(500, 'event is not support');
|
||||
}
|
||||
}
|
||||
|
||||
public function bitpayXNotify(Request $request)
|
||||
{
|
||||
$inputString = file_get_contents('php://input', 'r');
|
||||
// Log::info('bitpayXNotifyData: ' . $inputString);
|
||||
$inputStripped = str_replace(array("\r", "\n", "\t", "\v"), '', $inputString);
|
||||
$inputJSON = json_decode($inputStripped, true); //convert JSON into array
|
||||
|
||||
$bitpayX = new BitpayX(config('v2board.bitpayx_appsecret'));
|
||||
$params = [
|
||||
'status' => $inputJSON['status'],
|
||||
'order_id' => $inputJSON['order_id'],
|
||||
'merchant_order_id' => $inputJSON['merchant_order_id'],
|
||||
'price_amount' => $inputJSON['price_amount'],
|
||||
'price_currency' => $inputJSON['price_currency'],
|
||||
'pay_amount' => $inputJSON['pay_amount'],
|
||||
'pay_currency' => $inputJSON['pay_currency'],
|
||||
'created_at_t' => $inputJSON['created_at_t']
|
||||
];
|
||||
$strToSign = $bitpayX->prepareSignId($inputJSON['merchant_order_id']);
|
||||
if (!$bitpayX->verify($strToSign, $inputJSON['token'])) {
|
||||
abort(500, 'sign error');
|
||||
}
|
||||
if ($params['status'] !== 'PAID') {
|
||||
abort(500, 'order is not paid');
|
||||
}
|
||||
if (!$this->handle($params['merchant_order_id'], $params['order_id'])) {
|
||||
abort(500, 'order process fail');
|
||||
}
|
||||
die(json_encode([
|
||||
'status' => 200
|
||||
]));
|
||||
}
|
||||
|
||||
public function mgateNotify(Request $request)
|
||||
{
|
||||
$mgate = new MGate(config('v2board.mgate_url'), config('v2board.mgate_app_id'), config('v2board.mgate_app_secret'));
|
||||
if (!$mgate->verify($request->input())) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
if (!$this->handle($request->input('out_trade_no'), $request->input('trade_no'))) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
die('success');
|
||||
}
|
||||
|
||||
public function epayNotify(Request $request)
|
||||
{
|
||||
$epay = new Epay(config('v2board.epay_url'), config('v2board.epay_pid'), config('v2board.epay_key'));
|
||||
if (!$epay->verify($request->input())) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
if (!$this->handle($request->input('out_trade_no'), $request->input('trade_no'))) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
die('success');
|
||||
}
|
||||
|
||||
private function handle($tradeNo, $callbackNo)
|
||||
{
|
||||
$order = Order::where('trade_no', $tradeNo)->first();
|
||||
if ($order->status === 1) return true;
|
||||
if (!$order) {
|
||||
abort(500, 'order is not found');
|
||||
}
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->success($callbackNo)) {
|
||||
return false;
|
||||
}
|
||||
$telegramService = new TelegramService();
|
||||
$message = sprintf(
|
||||
"💰成功收款%s元\n———————————————\n订单号:%s",
|
||||
$order->total_amount / 100,
|
||||
$order->trade_no
|
||||
);
|
||||
$telegramService->sendMessageWithAdmin($message);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Guest;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$plan = Plan::where('show', 1)->get();
|
||||
return response([
|
||||
'data' => $plan
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,199 +0,0 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
if ($request->input('access_token') !== md5(config('v2board.telegram_bot_token'))) {
|
||||
abort(500, 'authentication failed');
|
||||
}
|
||||
}
|
||||
|
||||
public function webhook(Request $request)
|
||||
{
|
||||
$this->msg = $this->getMessage($request->input());
|
||||
if (!$this->msg) return;
|
||||
try {
|
||||
switch($this->msg->message_type) {
|
||||
case 'send':
|
||||
$this->fromSend();
|
||||
break;
|
||||
case 'reply':
|
||||
$this->fromReply();
|
||||
break;
|
||||
}
|
||||
} 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]);
|
||||
}
|
||||
}
|
||||
|
||||
private function getMessage(array $data)
|
||||
{
|
||||
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->text = $data['message']['text'];
|
||||
if ($obj->message_type === 'reply') {
|
||||
$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');
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Server;
|
||||
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerLog;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/*
|
||||
* V2ray Aurora
|
||||
* Github: https://github.com/tokumeikoi/aurora
|
||||
*/
|
||||
class DeepbworkController extends Controller
|
||||
{
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
abort(500, 'token is null');
|
||||
}
|
||||
if ($token !== config('v2board.server_token')) {
|
||||
abort(500, 'token is error');
|
||||
}
|
||||
}
|
||||
|
||||
// 后端获取用户
|
||||
public function user(Request $request)
|
||||
{
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = Server::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_V2RAY_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
$users = $serverService->getAvailableUsers(json_decode($server->group_id));
|
||||
$result = [];
|
||||
foreach ($users as $user) {
|
||||
$user->v2ray_user = [
|
||||
"uuid" => $user->uuid,
|
||||
"email" => sprintf("%s@v2board.user", $user->uuid),
|
||||
"alter_id" => $server->alter_id,
|
||||
"level" => 0,
|
||||
];
|
||||
unset($user['uuid']);
|
||||
unset($user['email']);
|
||||
array_push($result, $user);
|
||||
}
|
||||
return response([
|
||||
'msg' => 'ok',
|
||||
'data' => $result,
|
||||
]);
|
||||
}
|
||||
|
||||
// 后端提交数据
|
||||
public function submit(Request $request)
|
||||
{
|
||||
// Log::info('serverSubmitData:' . $request->input('node_id') . ':' . file_get_contents('php://input'));
|
||||
$server = Server::find($request->input('node_id'));
|
||||
if (!$server) {
|
||||
return response([
|
||||
'ret' => 0,
|
||||
'msg' => 'server is not found'
|
||||
]);
|
||||
}
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
Cache::put(CacheKey::get('SERVER_V2RAY_ONLINE_USER', $server->id), count($data), 3600);
|
||||
$userService = new UserService();
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
foreach ($data as $item) {
|
||||
$u = $item['u'] * $server->rate;
|
||||
$d = $item['d'] * $server->rate;
|
||||
if (!$userService->trafficFetch($u, $d, $item['user_id'], $server, 'vmess')) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response([
|
||||
'ret' => 0,
|
||||
'msg' => 'user fetch fail'
|
||||
]);
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
return response([
|
||||
'ret' => 1,
|
||||
'msg' => 'ok'
|
||||
]);
|
||||
}
|
||||
|
||||
// 后端获取配置
|
||||
public function config(Request $request)
|
||||
{
|
||||
$nodeId = $request->input('node_id');
|
||||
$localPort = $request->input('local_port');
|
||||
if (empty($nodeId) || empty($localPort)) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$serverService = new ServerService();
|
||||
try {
|
||||
$json = $serverService->getVmessConfig($nodeId, $localPort);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
|
||||
die(json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
@ -1,157 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Server;
|
||||
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerLog;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/*
|
||||
* V2ray Poseidon
|
||||
* Github: https://github.com/ColetteContreras/trojan-poseidon
|
||||
*/
|
||||
class PoseidonController extends Controller
|
||||
{
|
||||
public $poseidonVersion;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->poseidonVersion = $request->input('poseidon_version');
|
||||
}
|
||||
|
||||
// 后端获取用户
|
||||
public function user(Request $request)
|
||||
{
|
||||
if ($r = $this->verifyToken($request)) { return $r; }
|
||||
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = Server::find($nodeId);
|
||||
if (!$server) {
|
||||
return $this->error("server could not be found", 404);
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_V2RAY_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
$users = $serverService->getAvailableUsers(json_decode($server->group_id));
|
||||
$result = [];
|
||||
foreach ($users as $user) {
|
||||
$user->v2ray_user = [
|
||||
"uuid" => $user->uuid,
|
||||
"email" => sprintf("%s@v2board.user", $user->uuid),
|
||||
"alter_id" => $server->alter_id,
|
||||
"level" => 0,
|
||||
];
|
||||
unset($user['uuid']);
|
||||
unset($user['email']);
|
||||
array_push($result, $user);
|
||||
}
|
||||
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
// 后端提交数据
|
||||
public function submit(Request $request)
|
||||
{
|
||||
if ($r = $this->verifyToken($request)) { return $r; }
|
||||
$server = Server::find($request->input('node_id'));
|
||||
if (!$server) {
|
||||
return $this->error("server could not be found", 404);
|
||||
}
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
Cache::put(CacheKey::get('SERVER_V2RAY_ONLINE_USER', $server->id), count($data), 3600);
|
||||
$userService = new UserService();
|
||||
foreach ($data as $item) {
|
||||
$u = $item['u'] * $server->rate;
|
||||
$d = $item['d'] * $server->rate;
|
||||
if (!$userService->trafficFetch($u, $d, $item['user_id'], $server, 'vmess')) {
|
||||
return $this->error("user fetch fail", 500);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success('');
|
||||
}
|
||||
|
||||
// 后端获取配置
|
||||
public function config(Request $request)
|
||||
{
|
||||
if ($r = $this->verifyToken($request)) { return $r; }
|
||||
|
||||
$nodeId = $request->input('node_id');
|
||||
$localPort = $request->input('local_port');
|
||||
if (empty($nodeId) || empty($localPort)) {
|
||||
return $this->error('invalid parameters', 400);
|
||||
}
|
||||
|
||||
$serverService = new ServerService();
|
||||
try {
|
||||
$json = $serverService->getVmessConfig($nodeId, $localPort);
|
||||
$json->poseidon = [
|
||||
'license_key' => (string)config('v2board.server_license'),
|
||||
];
|
||||
if ($this->poseidonVersion >= 'v1.5.0') {
|
||||
// don't need it after v1.5.0
|
||||
unset($json->inboundDetour);
|
||||
unset($json->stats);
|
||||
unset($json->api);
|
||||
array_shift($json->routing->rules);
|
||||
}
|
||||
|
||||
foreach($json->policy->levels as &$level) {
|
||||
$level->handshake = 2;
|
||||
$level->uplinkOnly = 2;
|
||||
$level->downlinkOnly = 2;
|
||||
$level->connIdle = 60;
|
||||
}
|
||||
|
||||
return $this->success($json);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage(), 500);
|
||||
}
|
||||
}
|
||||
|
||||
protected function verifyToken(Request $request)
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
return $this->error("token must be set");
|
||||
}
|
||||
if ($token !== config('v2board.server_token')) {
|
||||
return $this->error("invalid token");
|
||||
}
|
||||
}
|
||||
|
||||
protected function error($msg, int $status = 400) {
|
||||
return response([
|
||||
'msg' => $msg,
|
||||
], $status);
|
||||
}
|
||||
|
||||
protected function success($data) {
|
||||
$req = request();
|
||||
// Only for "GET" method
|
||||
if (!$req->isMethod('GET') || !$data) {
|
||||
return response([
|
||||
'msg' => 'ok',
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
$etag = sha1(json_encode($data));
|
||||
if ($etag == $req->header("IF-NONE-MATCH")) {
|
||||
return response(null, 304);
|
||||
}
|
||||
|
||||
return response([
|
||||
'msg' => 'ok',
|
||||
'data' => $data,
|
||||
])->header('ETAG', $etag);
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
class CommController extends Controller
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return response([
|
||||
'data' => [
|
||||
'isTelegram' => (int)config('v2board.telegram_bot_enable', 0),
|
||||
'stripePk' => config('v2board.stripe_pk_live')
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Coupon;
|
||||
|
||||
class CouponController extends Controller
|
||||
{
|
||||
public function check(Request $request)
|
||||
{
|
||||
if (empty($request->input('code'))) {
|
||||
abort(500, '优惠券码不能为空');
|
||||
}
|
||||
$coupon = Coupon::where('code', $request->input('code'))->first();
|
||||
if (!$coupon) {
|
||||
abort(500, '优惠券无效');
|
||||
}
|
||||
if ($coupon->limit_use <= 0 && $coupon->limit_use !== NULL) {
|
||||
abort(500, '优惠券已无可用次数');
|
||||
}
|
||||
if (time() < $coupon->started_at) {
|
||||
abort(500, '优惠券还未到可用时间');
|
||||
}
|
||||
if (time() > $coupon->ended_at) {
|
||||
abort(500, '优惠券已过期');
|
||||
}
|
||||
if ($coupon->limit_plan_ids) {
|
||||
$limitPlanIds = json_decode($coupon->limit_plan_ids);
|
||||
if (!in_array($request->input('plan_id'), $limitPlanIds)) {
|
||||
abort(500, '这个计划无法使用该优惠码');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $coupon
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\Order;
|
||||
use App\Models\InviteCode;
|
||||
use App\Utils\Helper;
|
||||
|
||||
class InviteController extends Controller
|
||||
{
|
||||
public function save(Request $request)
|
||||
{
|
||||
if (InviteCode::where('user_id', $request->session()->get('id'))->where('status', 0)->count() >= config('v2board.invite_gen_limit', 5)) {
|
||||
abort(500, '已达到创建数量上限');
|
||||
}
|
||||
$inviteCode = new InviteCode();
|
||||
$inviteCode->user_id = $request->session()->get('id');
|
||||
$inviteCode->code = Helper::randomChar(8);
|
||||
return response([
|
||||
'data' => $inviteCode->save()
|
||||
]);
|
||||
}
|
||||
|
||||
public function details(Request $request)
|
||||
{
|
||||
return response([
|
||||
'data' => Order::where('invite_user_id', $request->session()->get('id'))
|
||||
->where('commission_balance', '>', 0)
|
||||
->where('status', 3)
|
||||
->select([
|
||||
'id',
|
||||
'commission_status',
|
||||
'commission_balance',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
])
|
||||
->get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$codes = InviteCode::where('user_id', $request->session()->get('id'))
|
||||
->where('status', 0)
|
||||
->get();
|
||||
$commission_rate = config('v2board.invite_commission', 10);
|
||||
$user = User::find($request->session()->get('id'));
|
||||
if ($user->commission_rate) {
|
||||
$commission_rate = $user->commission_rate;
|
||||
}
|
||||
$stat = [
|
||||
//已注册用户数
|
||||
(int)User::where('invite_user_id', $request->session()->get('id'))->count(),
|
||||
//有效的佣金
|
||||
(int)Order::where('status', 3)
|
||||
->where('commission_status', 2)
|
||||
->where('invite_user_id', $request->session()->get('id'))
|
||||
->sum('commission_balance'),
|
||||
//确认中的佣金
|
||||
(int)Order::where('status', 3)
|
||||
->where('commission_status', 0)
|
||||
->where('invite_user_id', $request->session()->get('id'))
|
||||
->sum('commission_balance'),
|
||||
//佣金比例
|
||||
(int)$commission_rate,
|
||||
//可用佣金
|
||||
(int)$user->commission_balance
|
||||
];
|
||||
return response([
|
||||
'data' => [
|
||||
'codes' => $codes,
|
||||
'stat' => $stat
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Knowledge;
|
||||
|
||||
class KnowledgeController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$knowledge = Knowledge::where('id', $request->input('id'))
|
||||
->where('show', 1)
|
||||
->first()
|
||||
->toArray();
|
||||
if (!$knowledge) abort(500, '知识不存在');
|
||||
$user = User::find($request->session()->get('id'));
|
||||
$userService = new UserService();
|
||||
$appleId = $userService->isAvailable($user) ? config('v2board.apple_id') : '没有有效订阅无法使用本站提供的AppleID';
|
||||
$appleIdPassword = $userService->isAvailable($user) ? config('v2board.apple_id_password') : '没有有效订阅无法使用本站提供的AppleID';
|
||||
$subscribeUrl = config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $user['token'];
|
||||
$knowledge['body'] = str_replace('{{siteName}}', config('v2board.app_name', 'V2Board'), $knowledge['body']);
|
||||
$knowledge['body'] = str_replace('{{appleId}}', $appleId, $knowledge['body']);
|
||||
$knowledge['body'] = str_replace('{{appleIdPassword}}', $appleIdPassword, $knowledge['body']);
|
||||
$knowledge['body'] = str_replace('{{subscribeUrl}}', $subscribeUrl, $knowledge['body']);
|
||||
$knowledge['body'] = str_replace('{{urlEncodeSubscribeUrl}}', urlencode($subscribeUrl), $knowledge['body']);
|
||||
$knowledge['body'] = str_replace(
|
||||
'{{safeBase64SubscribeUrl}}',
|
||||
str_replace(
|
||||
array('+', '/', '='),
|
||||
array('-', '_', ''),
|
||||
base64_encode($subscribeUrl)
|
||||
),
|
||||
$knowledge['body']
|
||||
);
|
||||
return response([
|
||||
'data' => $knowledge
|
||||
]);
|
||||
}
|
||||
$knowledges = Knowledge::select(['id', 'category', 'title', 'updated_at'])
|
||||
->where('language', $request->input('language'))
|
||||
->where('show', 1)
|
||||
->orderBy('sort', 'ASC')
|
||||
->get()
|
||||
->groupBy('category');
|
||||
return response([
|
||||
'data' => $knowledges
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,498 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\OrderSave;
|
||||
use App\Services\CouponService;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Order;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Utils\Helper;
|
||||
use Omnipay\Omnipay;
|
||||
use Stripe\Stripe;
|
||||
use Stripe\Source;
|
||||
use Library\BitpayX;
|
||||
use Library\MGate;
|
||||
use Library\Epay;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$model = Order::where('user_id', $request->session()->get('id'))
|
||||
->orderBy('created_at', 'DESC');
|
||||
if ($request->input('status') !== null) {
|
||||
$model->where('status', $request->input('status'));
|
||||
}
|
||||
$order = $model->get();
|
||||
$plan = Plan::get();
|
||||
for ($i = 0; $i < count($order); $i++) {
|
||||
for ($x = 0; $x < count($plan); $x++) {
|
||||
if ($order[$i]['plan_id'] === $plan[$x]['id']) {
|
||||
$order[$i]['plan'] = $plan[$x];
|
||||
}
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $order
|
||||
]);
|
||||
}
|
||||
|
||||
public function details(Request $request)
|
||||
{
|
||||
$order = Order::where('user_id', $request->session()->get('id'))
|
||||
->where('trade_no', $request->input('trade_no'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在');
|
||||
}
|
||||
$order['plan'] = Plan::find($order->plan_id);
|
||||
$order['try_out_plan_id'] = (int)config('v2board.try_out_plan_id');
|
||||
if (!$order['plan']) {
|
||||
abort(500, '订阅不存在');
|
||||
}
|
||||
return response([
|
||||
'data' => $order
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(OrderSave $request)
|
||||
{
|
||||
$userService = new UserService();
|
||||
if ($userService->isNotCompleteOrderByUserId($request->session()->get('id'))) {
|
||||
abort(500, '您有未付款或开通中的订单,请稍后或取消再试');
|
||||
}
|
||||
|
||||
$plan = Plan::find($request->input('plan_id'));
|
||||
$user = User::find($request->session()->get('id'));
|
||||
|
||||
if (!$plan) {
|
||||
abort(500, '该订阅不存在');
|
||||
}
|
||||
|
||||
if ((!$plan->show && !$plan->renew) || (!$plan->show && $user->plan_id !== $plan->id)) {
|
||||
if ($request->input('cycle') !== 'reset_price') {
|
||||
abort(500, '该订阅已售罄,请更换其他订阅');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$plan->renew && $user->plan_id == $plan->id && $request->input('cycle') !== 'reset_price') {
|
||||
abort(500, '该订阅无法续费,请更换其他订阅');
|
||||
}
|
||||
|
||||
if ($plan[$request->input('cycle')] === NULL) {
|
||||
abort(500, '该订阅周期无法进行购买,请选择其他周期');
|
||||
}
|
||||
|
||||
if ($request->input('cycle') === 'reset_price') {
|
||||
if ($user->expired_at <= time() || !$user->plan_id) {
|
||||
abort(500, '订阅已过期或无有效订阅,无法购买重置包');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$plan->show && $plan->renew && !$userService->isAvailable($user)) {
|
||||
abort(500, '订阅已过期,请更换其他订阅');
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
$order = new Order();
|
||||
$orderService = new OrderService($order);
|
||||
$order->user_id = $request->session()->get('id');
|
||||
$order->plan_id = $plan->id;
|
||||
$order->cycle = $request->input('cycle');
|
||||
$order->trade_no = Helper::guid();
|
||||
$order->total_amount = $plan[$request->input('cycle')];
|
||||
|
||||
if ($request->input('coupon_code')) {
|
||||
$couponService = new CouponService($request->input('coupon_code'));
|
||||
if (!$couponService->use($order)) {
|
||||
DB::rollBack();
|
||||
abort(500, '优惠券使用失败');
|
||||
}
|
||||
$order->coupon_id = $couponService->getId();
|
||||
}
|
||||
|
||||
$orderService->setVipDiscount($user);
|
||||
$orderService->setOrderType($user);
|
||||
$orderService->setInvite($user);
|
||||
|
||||
if ($user->balance && $order->total_amount > 0) {
|
||||
$remainingBalance = $user->balance - $order->total_amount;
|
||||
$userService = new UserService();
|
||||
if ($remainingBalance > 0) {
|
||||
if (!$userService->addBalance($order->user_id, - $order->total_amount)) {
|
||||
DB::rollBack();
|
||||
abort(500, '余额不足');
|
||||
}
|
||||
$order->balance_amount = $order->total_amount;
|
||||
$order->total_amount = 0;
|
||||
} else {
|
||||
if (!$userService->addBalance($order->user_id, - $user->balance)) {
|
||||
DB::rollBack();
|
||||
abort(500, '余额不足');
|
||||
}
|
||||
$order->balance_amount = $user->balance;
|
||||
$order->total_amount = $order->total_amount - $user->balance;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$order->save()) {
|
||||
DB::rollback();
|
||||
abort(500, '订单创建失败');
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response([
|
||||
'data' => $order->trade_no
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkout(Request $request)
|
||||
{
|
||||
$tradeNo = $request->input('trade_no');
|
||||
$method = $request->input('method');
|
||||
$order = Order::where('trade_no', $tradeNo)
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->where('status', 0)
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在或已支付');
|
||||
}
|
||||
// free process
|
||||
if ($order->total_amount <= 0) {
|
||||
$order->total_amount = 0;
|
||||
$order->status = 1;
|
||||
$order->save();
|
||||
return response([
|
||||
'type' => -1,
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
switch ($method) {
|
||||
// return type => 0: QRCode / 1: URL / 2: No action
|
||||
case 0:
|
||||
// alipayF2F
|
||||
if (!(int)config('v2board.alipay_enable')) {
|
||||
abort(500, '支付方式不可用');
|
||||
}
|
||||
return response([
|
||||
'type' => 0,
|
||||
'data' => $this->alipayF2F($tradeNo, $order->total_amount)
|
||||
]);
|
||||
case 2:
|
||||
// stripeAlipay
|
||||
if (!(int)config('v2board.stripe_alipay_enable')) {
|
||||
abort(500, '支付方式不可用');
|
||||
}
|
||||
return response([
|
||||
'type' => 1,
|
||||
'data' => $this->stripeAlipay($order)
|
||||
]);
|
||||
case 3:
|
||||
// stripeWepay
|
||||
if (!(int)config('v2board.stripe_wepay_enable')) {
|
||||
abort(500, '支付方式不可用');
|
||||
}
|
||||
return response([
|
||||
'type' => 0,
|
||||
'data' => $this->stripeWepay($order)
|
||||
]);
|
||||
case 4:
|
||||
// bitpayX
|
||||
if (!(int)config('v2board.bitpayx_enable')) {
|
||||
abort(500, '支付方式不可用');
|
||||
}
|
||||
return response([
|
||||
'type' => 1,
|
||||
'data' => $this->bitpayX($order)
|
||||
]);
|
||||
case 5:
|
||||
if (!(int)config('v2board.mgate_enable')) {
|
||||
abort(500, '支付方式不可用');
|
||||
}
|
||||
return response([
|
||||
'type' => 1,
|
||||
'data' => $this->mgate($order)
|
||||
]);
|
||||
case 6:
|
||||
if (!(int)config('v2board.stripe_card_enable')) {
|
||||
abort(500, '支付方式不可用');
|
||||
}
|
||||
return response([
|
||||
'type' => 2,
|
||||
'data' => $this->stripeCard($order, $request->input('token'))
|
||||
]);
|
||||
case 7:
|
||||
if (!(int)config('v2board.epay_enable')) {
|
||||
abort(500, '支付方式不可用');
|
||||
}
|
||||
return response([
|
||||
'type' => 1,
|
||||
'data' => $this->epay($order)
|
||||
]);
|
||||
default:
|
||||
abort(500, '支付方式不存在');
|
||||
}
|
||||
}
|
||||
|
||||
public function check(Request $request)
|
||||
{
|
||||
$tradeNo = $request->input('trade_no');
|
||||
$order = Order::where('trade_no', $tradeNo)
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在');
|
||||
}
|
||||
return response([
|
||||
'data' => $order->status
|
||||
]);
|
||||
}
|
||||
|
||||
public function getPaymentMethod()
|
||||
{
|
||||
$data = [];
|
||||
if ((int)config('v2board.alipay_enable')) {
|
||||
$alipayF2F = new \StdClass();
|
||||
$alipayF2F->name = '支付宝';
|
||||
$alipayF2F->method = 0;
|
||||
$alipayF2F->icon = 'alipay';
|
||||
array_push($data, $alipayF2F);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.stripe_alipay_enable')) {
|
||||
$stripeAlipay = new \StdClass();
|
||||
$stripeAlipay->name = '支付宝';
|
||||
$stripeAlipay->method = 2;
|
||||
$stripeAlipay->icon = 'alipay';
|
||||
array_push($data, $stripeAlipay);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.stripe_wepay_enable')) {
|
||||
$stripeWepay = new \StdClass();
|
||||
$stripeWepay->name = '微信';
|
||||
$stripeWepay->method = 3;
|
||||
$stripeWepay->icon = 'wechat';
|
||||
array_push($data, $stripeWepay);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.bitpayx_enable')) {
|
||||
$bitpayX = new \StdClass();
|
||||
$bitpayX->name = config('v2board.bitpayx_name', '在线支付');
|
||||
$bitpayX->method = 4;
|
||||
$bitpayX->icon = 'wallet';
|
||||
array_push($data, $bitpayX);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.mgate_enable')) {
|
||||
$obj = new \StdClass();
|
||||
$obj->name = config('v2board.mgate_name', '在线支付');
|
||||
$obj->method = 5;
|
||||
$obj->icon = 'wallet';
|
||||
array_push($data, $obj);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.stripe_card_enable')) {
|
||||
$obj = new \StdClass();
|
||||
$obj->name = '信用卡';
|
||||
$obj->method = 6;
|
||||
$obj->icon = 'card';
|
||||
array_push($data, $obj);
|
||||
}
|
||||
|
||||
if ((int)config('v2board.epay_enable')) {
|
||||
$obj = new \StdClass();
|
||||
$obj->name = config('v2board.epay_name', '在线支付');
|
||||
$obj->method = 7;
|
||||
$obj->icon = 'wallet';
|
||||
array_push($data, $obj);
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public function cancel(Request $request)
|
||||
{
|
||||
if (empty($request->input('trade_no'))) {
|
||||
abort(500, '参数有误');
|
||||
}
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在');
|
||||
}
|
||||
if ($order->status !== 0) {
|
||||
abort(500, '只可以取消待支付订单');
|
||||
}
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->cancel()) {
|
||||
abort(500, '取消失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
private function alipayF2F($tradeNo, $totalAmount)
|
||||
{
|
||||
$gateway = Omnipay::create('Alipay_AopF2F');
|
||||
$gateway->setSignType('RSA2'); //RSA/RSA2
|
||||
$gateway->setAppId(config('v2board.alipay_appid'));
|
||||
$gateway->setPrivateKey(config('v2board.alipay_privkey')); // 可以是路径,也可以是密钥内容
|
||||
$gateway->setAlipayPublicKey(config('v2board.alipay_pubkey')); // 可以是路径,也可以是密钥内容
|
||||
$gateway->setNotifyUrl(url('/api/v1/guest/order/alipayNotify'));
|
||||
$request = $gateway->purchase();
|
||||
$request->setBizContent([
|
||||
'subject' => config('v2board.app_name', 'V2Board') . ' - 订阅',
|
||||
'out_trade_no' => $tradeNo,
|
||||
'total_amount' => $totalAmount / 100
|
||||
]);
|
||||
/** @var \Omnipay\Alipay\Responses\AopTradePreCreateResponse $response */
|
||||
$response = $request->send();
|
||||
$result = $response->getAlipayResponse();
|
||||
if ($result['code'] !== '10000') {
|
||||
abort(500, $result['sub_msg']);
|
||||
}
|
||||
// 获取收款二维码内容
|
||||
return $response->getQrCode();
|
||||
}
|
||||
|
||||
private function stripeAlipay($order)
|
||||
{
|
||||
$currency = config('v2board.stripe_currency', 'hkd');
|
||||
$exchange = Helper::exchange('CNY', strtoupper($currency));
|
||||
if (!$exchange) {
|
||||
abort(500, '货币转换超时,请稍后再试');
|
||||
}
|
||||
Stripe::setApiKey(config('v2board.stripe_sk_live'));
|
||||
$source = Source::create([
|
||||
'amount' => floor($order->total_amount * $exchange),
|
||||
'currency' => $currency,
|
||||
'type' => 'alipay',
|
||||
'statement_descriptor' => $order->trade_no,
|
||||
'metadata' => [
|
||||
'user_id' => $order->user_id,
|
||||
'out_trade_no' => $order->trade_no,
|
||||
'identifier' => ''
|
||||
],
|
||||
'redirect' => [
|
||||
'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order'
|
||||
]
|
||||
]);
|
||||
if (!$source['redirect']['url']) {
|
||||
abort(500, '支付网关请求失败');
|
||||
}
|
||||
return $source['redirect']['url'];
|
||||
}
|
||||
|
||||
private function stripeWepay($order)
|
||||
{
|
||||
$currency = config('v2board.stripe_currency', 'hkd');
|
||||
$exchange = Helper::exchange('CNY', strtoupper($currency));
|
||||
if (!$exchange) {
|
||||
abort(500, '货币转换超时,请稍后再试');
|
||||
}
|
||||
Stripe::setApiKey(config('v2board.stripe_sk_live'));
|
||||
$source = Source::create([
|
||||
'amount' => floor($order->total_amount * $exchange),
|
||||
'currency' => $currency,
|
||||
'type' => 'wechat',
|
||||
'metadata' => [
|
||||
'user_id' => $order->user_id,
|
||||
'out_trade_no' => $order->trade_no,
|
||||
'identifier' => ''
|
||||
],
|
||||
'redirect' => [
|
||||
'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order'
|
||||
]
|
||||
]);
|
||||
if (!$source['wechat']['qr_code_url']) {
|
||||
abort(500, '支付网关请求失败');
|
||||
}
|
||||
return $source['wechat']['qr_code_url'];
|
||||
}
|
||||
|
||||
private function stripeCard($order, string $token)
|
||||
{
|
||||
$currency = config('v2board.stripe_currency', 'hkd');
|
||||
$exchange = Helper::exchange('CNY', strtoupper($currency));
|
||||
if (!$exchange) {
|
||||
abort(500, '货币转换超时,请稍后再试');
|
||||
}
|
||||
Stripe::setApiKey(config('v2board.stripe_sk_live'));
|
||||
try {
|
||||
$charge = \Stripe\Charge::create([
|
||||
'amount' => floor($order->total_amount * $exchange),
|
||||
'currency' => $currency,
|
||||
'source' => $token,
|
||||
'metadata' => [
|
||||
'user_id' => $order->user_id,
|
||||
'out_trade_no' => $order->trade_no,
|
||||
'identifier' => ''
|
||||
]
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '遇到了点问题,请刷新页面稍后再试');
|
||||
}
|
||||
info($charge);
|
||||
if (!$charge->paid) {
|
||||
abort(500, '扣款失败,请检查信用卡信息');
|
||||
}
|
||||
return $charge->paid;
|
||||
}
|
||||
|
||||
private function bitpayX($order)
|
||||
{
|
||||
$bitpayX = new BitpayX(config('v2board.bitpayx_appsecret'));
|
||||
$params = [
|
||||
'merchant_order_id' => $order->trade_no,
|
||||
'price_amount' => $order->total_amount / 100,
|
||||
'price_currency' => 'CNY',
|
||||
'title' => '支付单号:' . $order->trade_no,
|
||||
'description' => '充值:' . $order->total_amount / 100 . ' 元',
|
||||
'callback_url' => url('/api/v1/guest/order/bitpayXNotify'),
|
||||
'success_url' => config('v2board.app_url', env('APP_URL')) . '/#/order',
|
||||
'cancel_url' => config('v2board.app_url', env('APP_URL')) . '/#/order'
|
||||
];
|
||||
$strToSign = $bitpayX->prepareSignId($params['merchant_order_id']);
|
||||
$params['token'] = $bitpayX->sign($strToSign);
|
||||
$result = $bitpayX->mprequest($params);
|
||||
// Log::info('bitpayXSubmit: ' . json_encode($result));
|
||||
return isset($result['payment_url']) ? $result['payment_url'] : false;
|
||||
}
|
||||
|
||||
private function mgate($order)
|
||||
{
|
||||
$mgate = new MGate(config('v2board.mgate_url'), config('v2board.mgate_app_id'), config('v2board.mgate_app_secret'));
|
||||
$result = $mgate->pay([
|
||||
'app_id' => config('v2board.mgate_app_id'),
|
||||
'out_trade_no' => $order->trade_no,
|
||||
'total_amount' => $order->total_amount,
|
||||
'notify_url' => url('/api/v1/guest/order/mgateNotify'),
|
||||
'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order'
|
||||
]);
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function epay($order)
|
||||
{
|
||||
$epay = new Epay(config('v2board.epay_url'), config('v2board.epay_pid'), config('v2board.epay_key'));
|
||||
return $epay->pay([
|
||||
'money' => $order->total_amount / 100,
|
||||
'name' => $order->trade_no,
|
||||
'notify_url' => url('/api/v1/guest/order/epayNotify'),
|
||||
'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order',
|
||||
'out_trade_no' => $order->trade_no
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Plan;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$plan = Plan::where('id', $request->input('id'))
|
||||
->first();
|
||||
if (!$plan) {
|
||||
abort(500, '该订阅不存在');
|
||||
}
|
||||
return response([
|
||||
'data' => $plan
|
||||
]);
|
||||
}
|
||||
$plan = Plan::where('show', 1)
|
||||
->orderBy('sort', 'ASC')
|
||||
->get();
|
||||
return response([
|
||||
'data' => $plan
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerLog;
|
||||
use App\Models\User;
|
||||
|
||||
use App\Utils\Helper;
|
||||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$user = User::find($request->session()->get('id'));
|
||||
$servers = [];
|
||||
$userService = new UserService();
|
||||
if ($userService->isAvailable($user)) {
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAvailableServers($user);
|
||||
}
|
||||
return response([
|
||||
'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('created_at', 'DESC');
|
||||
switch ($type) {
|
||||
case 0:
|
||||
$serverLogModel->where('created_at', '>=', strtotime(date('Y-m-d')));
|
||||
break;
|
||||
case 1:
|
||||
$serverLogModel->where('created_at', '>=', strtotime(date('Y-m-d')) - 604800);
|
||||
break;
|
||||
case 2:
|
||||
$serverLogModel->where('created_at', '>=', strtotime(date('Y-m-1')));
|
||||
}
|
||||
$total = $serverLogModel->count();
|
||||
$res = $serverLogModel->forPage($current, $pageSize)
|
||||
->get();
|
||||
return response([
|
||||
'data' => $res,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\UserUpdate;
|
||||
use App\Http\Requests\User\UserChangePassword;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Server;
|
||||
use App\Models\Ticket;
|
||||
use App\Utils\Helper;
|
||||
use App\Models\Order;
|
||||
use App\Models\ServerLog;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function logout(Request $request)
|
||||
{
|
||||
$request->session()->flush();
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function changePassword(UserChangePassword $request)
|
||||
{
|
||||
$user = User::find($request->session()->get('id'));
|
||||
if (!Helper::multiPasswordVerify(
|
||||
$user->password_algo,
|
||||
$request->input('old_password'),
|
||||
$user->password)
|
||||
) {
|
||||
abort(500, '旧密码有误');
|
||||
}
|
||||
$user->password = password_hash($request->input('new_password'), PASSWORD_DEFAULT);
|
||||
$user->password_algo = NULL;
|
||||
if (!$user->save()) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
$request->session()->flush();
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function info(Request $request)
|
||||
{
|
||||
$user = User::where('id', $request->session()->get('id'))
|
||||
->select([
|
||||
'email',
|
||||
'transfer_enable',
|
||||
'last_login_at',
|
||||
'created_at',
|
||||
'banned',
|
||||
'remind_expire',
|
||||
'remind_traffic',
|
||||
'expired_at',
|
||||
'balance',
|
||||
'commission_balance',
|
||||
'plan_id',
|
||||
'discount',
|
||||
'commission_rate',
|
||||
'telegram_id'
|
||||
])
|
||||
->first();
|
||||
$user['avatar_url'] = 'https://cdn.v2ex.com/gravatar/' . md5($user->email) . '?s=64&d=identicon';
|
||||
return response([
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
public function getStat(Request $request)
|
||||
{
|
||||
$stat = [
|
||||
Order::where('status', 0)
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->count(),
|
||||
Ticket::where('status', 0)
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->count(),
|
||||
User::where('invite_user_id', $request->session()->get('id'))
|
||||
->count()
|
||||
];
|
||||
return response([
|
||||
'data' => $stat
|
||||
]);
|
||||
}
|
||||
|
||||
public function getSubscribe(Request $request)
|
||||
{
|
||||
$user = User::find($request->session()->get('id'));
|
||||
if ($user->plan_id) {
|
||||
$user['plan'] = Plan::find($user->plan_id);
|
||||
if (!$user['plan']) {
|
||||
abort(500, '订阅计划不存在');
|
||||
}
|
||||
}
|
||||
$user['subscribe_url'] = config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $user['token'];
|
||||
$user['reset_day'] = $this->getResetDay($user);
|
||||
return response([
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
public function resetSecurity(Request $request)
|
||||
{
|
||||
$user = User::find($request->session()->get('id'));
|
||||
$user->uuid = Helper::guid(true);
|
||||
$user->token = Helper::guid();
|
||||
if (!$user->save()) {
|
||||
abort(500, '重置失败');
|
||||
}
|
||||
return response([
|
||||
'data' => config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $user->token
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UserUpdate $request)
|
||||
{
|
||||
$updateData = $request->only([
|
||||
'remind_expire',
|
||||
'remind_traffic'
|
||||
]);
|
||||
|
||||
$user = User::find($request->session()->get('id'));
|
||||
if (!$user) {
|
||||
abort(500, '该用户不存在');
|
||||
}
|
||||
try {
|
||||
$user->update($updateData);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function transfer(Request $request)
|
||||
{
|
||||
$user = User::find($request->session()->get('id'));
|
||||
if (!$user) {
|
||||
abort(500, '该用户不存在');
|
||||
}
|
||||
if ($request->input('transfer_amount') <= 0) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
if ($request->input('transfer_amount') > $user->commission_balance) {
|
||||
abort(500, '推广佣金余额不足');
|
||||
}
|
||||
$user->commission_balance = $user->commission_balance - $request->input('transfer_amount');
|
||||
$user->balance = $user->balance + $request->input('transfer_amount');
|
||||
if (!$user->save()) {
|
||||
abort(500, '划转失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
private function getResetDay(User $user)
|
||||
{
|
||||
if ($user->expired_at <= time() || $user->expired_at === NULL) return null;
|
||||
$day = date('d', $user->expired_at);
|
||||
$today = date('d');
|
||||
$lastDay = date('d', strtotime('last day of +0 months'));
|
||||
|
||||
if ((int)config('v2board.reset_traffic_method') === 0) {
|
||||
return $lastDay - $today;
|
||||
}
|
||||
if ((int)config('v2board.reset_traffic_method') === 1) {
|
||||
if ((int)$day >= (int)$today) {
|
||||
return $day - $today;
|
||||
} else {
|
||||
return $lastDay - $today + $day;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
113
app/Http/Controllers/V1/Admin/ConfigController.php
Executable file
113
app/Http/Controllers/V1/Admin/ConfigController.php
Executable file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\ConfigSave;
|
||||
use App\Jobs\SendEmailJob;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\TelegramService;
|
||||
use App\Utils\Dict;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class ConfigController extends Controller
|
||||
{
|
||||
public function getEmailTemplate()
|
||||
{
|
||||
$path = resource_path('views/mail/');
|
||||
$files = array_map(function ($item) use ($path) {
|
||||
return str_replace($path, '', $item);
|
||||
}, glob($path . '*'));
|
||||
return response([
|
||||
'data' => $files
|
||||
]);
|
||||
}
|
||||
|
||||
public function getThemeTemplate()
|
||||
{
|
||||
$path = public_path('theme/');
|
||||
$files = array_map(function ($item) use ($path) {
|
||||
return str_replace($path, '', $item);
|
||||
}, glob($path . '*'));
|
||||
return response([
|
||||
'data' => $files
|
||||
]);
|
||||
}
|
||||
|
||||
public function testSendMail(Request $request)
|
||||
{
|
||||
$obj = new SendEmailJob([
|
||||
'email' => $request->user['email'],
|
||||
'subject' => 'This is v2board test email',
|
||||
'template_name' => 'notify',
|
||||
'template_value' => [
|
||||
'name' => config('v2board.app_name', 'V2Board'),
|
||||
'content' => 'This is v2board test email',
|
||||
'url' => config('v2board.app_url')
|
||||
]
|
||||
]);
|
||||
return response([
|
||||
'data' => true,
|
||||
'log' => $obj->handle()
|
||||
]);
|
||||
}
|
||||
|
||||
public function setTelegramWebhook(Request $request)
|
||||
{
|
||||
$hookUrl = url('/api/v1/guest/telegram/webhook?access_token=' . md5(config('v2board.telegram_bot_token', $request->input('telegram_bot_token'))));
|
||||
$telegramService = new TelegramService($request->input('telegram_bot_token'));
|
||||
$telegramService->getMe();
|
||||
$telegramService->setWebhook($hookUrl);
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$key = $request->input('key');
|
||||
$data = (new ConfigService)->getDefaultConfig();
|
||||
if ($key && isset($data[$key])) {
|
||||
return response([
|
||||
'data' => [
|
||||
$key => $data[$key]
|
||||
]
|
||||
]);
|
||||
};
|
||||
// TODO: default should be in Dict
|
||||
return response([
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(ConfigSave $request)
|
||||
{
|
||||
$data = $request->validated();
|
||||
$config = config('v2board');
|
||||
foreach (ConfigSave::RULES as $k => $v) {
|
||||
if (!in_array($k, array_keys(ConfigSave::RULES))) {
|
||||
unset($config[$k]);
|
||||
continue;
|
||||
}
|
||||
if (array_key_exists($k, $data)) {
|
||||
$config[$k] = $data[$k];
|
||||
}
|
||||
}
|
||||
$data = var_export($config, 1);
|
||||
if (!File::put(base_path() . '/config/v2board.php', "<?php\n return $data ;")) {
|
||||
abort(500, '修改失败');
|
||||
}
|
||||
if (function_exists('opcache_reset')) {
|
||||
if (opcache_reset() === false) {
|
||||
abort(500, '缓存清除失败,请卸载或检查opcache配置状态');
|
||||
}
|
||||
}
|
||||
Artisan::call('config:cache');
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\CouponSave;
|
||||
use App\Http\Requests\Admin\CouponGenerate;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\CouponGenerate;
|
||||
use App\Http\Requests\Admin\CouponSave;
|
||||
use App\Models\Coupon;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CouponController extends Controller
|
||||
@ -19,40 +17,29 @@ class CouponController extends Controller
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$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';
|
||||
$sort = $request->input('sort') ? $request->input('sort') : 'id';
|
||||
$builder = Coupon::orderBy($sort, $sortType);
|
||||
$total = $builder->count();
|
||||
$coupons = $builder->forPage($current, $pageSize)
|
||||
->get();
|
||||
|
||||
foreach ($coupons as $k => $v) {
|
||||
if ($coupons[$k]['limit_plan_ids']) $coupons[$k]['limit_plan_ids'] = json_decode($coupons[$k]['limit_plan_ids']);
|
||||
}
|
||||
return response([
|
||||
'data' => $coupons,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(CouponSave $request)
|
||||
public function show(Request $request)
|
||||
{
|
||||
$params = $request->validated();
|
||||
if (isset($params['limit_plan_ids'])) {
|
||||
$params['limit_plan_ids'] = json_encode($params['limit_plan_ids']);
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
}
|
||||
if (!$request->input('id')) {
|
||||
if (!isset($params['code'])) {
|
||||
$params['code'] = Helper::randomChar(8);
|
||||
}
|
||||
if (!Coupon::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Coupon::find($request->input('id'))->update($params);
|
||||
} catch (\Exception $e) {
|
||||
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([
|
||||
@ -68,9 +55,6 @@ class CouponController extends Controller
|
||||
}
|
||||
|
||||
$params = $request->validated();
|
||||
if (isset($params['limit_plan_ids'])) {
|
||||
$params['limit_plan_ids'] = json_encode($params['limit_plan_ids']);
|
||||
}
|
||||
if (!$request->input('id')) {
|
||||
if (!isset($params['code'])) {
|
||||
$params['code'] = Helper::randomChar(8);
|
||||
@ -95,15 +79,24 @@ class CouponController extends Controller
|
||||
{
|
||||
$coupons = [];
|
||||
$coupon = $request->validated();
|
||||
$coupon['limit_plan_ids'] = json_encode($coupon['limit_plan_ids']);
|
||||
$coupon['created_at'] = $coupon['updated_at'] = time();
|
||||
$coupon['show'] = 1;
|
||||
unset($coupon['generate_count']);
|
||||
for ($i = 0;$i < $request->input('generate_count');$i++) {
|
||||
$coupon['code'] = Helper::randomChar(8);
|
||||
array_push($coupons, $coupon);
|
||||
}
|
||||
DB::beginTransaction();
|
||||
if (!Coupon::insert($coupons)) {
|
||||
if (!Coupon::insert(array_map(function ($item) use ($coupon) {
|
||||
// format data
|
||||
if (isset($item['limit_plan_ids']) && is_array($item['limit_plan_ids'])) {
|
||||
$item['limit_plan_ids'] = json_encode($coupon['limit_plan_ids']);
|
||||
}
|
||||
if (isset($item['limit_period']) && is_array($item['limit_period'])) {
|
||||
$item['limit_period'] = json_encode($coupon['limit_period']);
|
||||
}
|
||||
return $item;
|
||||
}, $coupons))) {
|
||||
DB::rollBack();
|
||||
abort(500, '生成失败');
|
||||
}
|
||||
@ -116,7 +109,8 @@ 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']);
|
||||
$data .= "{$coupon['name']},{$type},{$value},{$startTime},{$endTime},{$limitUse},{$coupon['limit_plan_ids']},{$coupon['code']},{$createTime}\r\n";
|
||||
$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;
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\KnowledgeSave;
|
||||
use App\Http\Requests\Admin\KnowledgeSort;
|
||||
use App\Models\Knowledge;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class KnowledgeController extends Controller
|
||||
@ -77,11 +77,15 @@ class KnowledgeController extends Controller
|
||||
public function sort(KnowledgeSort $request)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
foreach ($request->input('knowledge_ids') as $k => $v) {
|
||||
if (!Knowledge::find($v)->update(['sort' => $k + 1])) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
try {
|
||||
foreach ($request->input('knowledge_ids') as $k => $v) {
|
||||
$knowledge = Knowledge::find($v);
|
||||
$knowledge->timestamps = false;
|
||||
$knowledge->update(['sort' => $k + 1]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
DB::commit();
|
||||
return response([
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Staff;
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\NoticeSave;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\NoticeSave;
|
||||
use App\Models\Notice;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class NoticeController extends Controller
|
||||
@ -22,7 +22,8 @@ class NoticeController extends Controller
|
||||
$data = $request->only([
|
||||
'title',
|
||||
'content',
|
||||
'img_url'
|
||||
'img_url',
|
||||
'tags'
|
||||
]);
|
||||
if (!$request->input('id')) {
|
||||
if (!Notice::create($data)) {
|
||||
@ -40,6 +41,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'))) {
|
@ -1,39 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\OrderAssign;
|
||||
use App\Http\Requests\Admin\OrderFetch;
|
||||
use App\Http\Requests\Admin\OrderUpdate;
|
||||
use App\Models\CommissionLog;
|
||||
use App\Models\Order;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
private function filter(Request $request, &$builder)
|
||||
{
|
||||
if ($request->input('filter')) {
|
||||
foreach ($request->input('filter') as $filter) {
|
||||
if ($filter['key'] === 'email') {
|
||||
$user = User::where('email', "%{$filter['value']}%")->first();
|
||||
if (!$user) continue;
|
||||
$builder->where('user_id', $user->id);
|
||||
continue;
|
||||
}
|
||||
if ($filter['condition'] === '模糊') {
|
||||
$filter['condition'] = 'like';
|
||||
$filter['value'] = "%{$filter['value']}%";
|
||||
}
|
||||
$builder->where($filter['key'], $filter['condition'], $filter['value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
||||
$orderModel = Order::orderBy('created_at', 'DESC');
|
||||
if ($request->input('trade_no')) {
|
||||
$orderModel->where('trade_no', $request->input('trade_no'));
|
||||
}
|
||||
if ($request->input('is_commission')) {
|
||||
$orderModel->where('invite_user_id', '!=', NULL);
|
||||
$orderModel->whereIn('status', [3, 4]);
|
||||
$orderModel->whereNotIn('status', [0, 2]);
|
||||
$orderModel->where('commission_balance', '>', 0);
|
||||
}
|
||||
if ($request->input('id')) {
|
||||
$orderModel->where('id', $request->input('id'));
|
||||
}
|
||||
if ($request->input('user_id')) {
|
||||
$orderModel->where('user_id', $request->input('user_id'));
|
||||
}
|
||||
$this->filter($request, $orderModel);
|
||||
$total = $orderModel->count();
|
||||
$res = $orderModel->forPage($current, $pageSize)
|
||||
->get();
|
||||
@ -51,10 +78,45 @@ class OrderController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function paid(Request $request)
|
||||
{
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在');
|
||||
}
|
||||
if ($order->status !== 0) abort(500, '只能对待支付的订单进行操作');
|
||||
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->paid('manual_operation')) {
|
||||
abort(500, '更新失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function cancel(Request $request)
|
||||
{
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在');
|
||||
}
|
||||
if ($order->status !== 0) abort(500, '只能对待支付的订单进行操作');
|
||||
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->cancel()) {
|
||||
abort(500, '更新失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(OrderUpdate $request)
|
||||
{
|
||||
$params = $request->only([
|
||||
'status',
|
||||
'commission_status'
|
||||
]);
|
||||
|
||||
@ -64,16 +126,6 @@ class OrderController extends Controller
|
||||
abort(500, '订单不存在');
|
||||
}
|
||||
|
||||
if (isset($params['status']) && (int)$params['status'] === 2) {
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->cancel()) {
|
||||
abort(500, '更新失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
$order->update($params);
|
||||
} catch (\Exception $e) {
|
||||
@ -85,26 +137,6 @@ class OrderController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function repair(Request $request)
|
||||
{
|
||||
if (empty($request->input('trade_no'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->where('status', 0)
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, '订单不存在或订单已支付');
|
||||
}
|
||||
$order->status = 1;
|
||||
if (!$order->save()) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function assign(OrderAssign $request)
|
||||
{
|
||||
$plan = Plan::find($request->input('plan_id'));
|
||||
@ -118,16 +150,21 @@ class OrderController extends Controller
|
||||
abort(500, '该订阅不存在');
|
||||
}
|
||||
|
||||
$userService = new UserService();
|
||||
if ($userService->isNotCompleteOrderByUserId($user->id)) {
|
||||
abort(500, '该用户还有待支付的订单,无法分配');
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
$order = new Order();
|
||||
$orderService = new OrderService($order);
|
||||
$order->user_id = $user->id;
|
||||
$order->plan_id = $plan->id;
|
||||
$order->cycle = $request->input('cycle');
|
||||
$order->period = $request->input('period');
|
||||
$order->trade_no = Helper::guid();
|
||||
$order->total_amount = $request->input('total_amount');
|
||||
|
||||
if ($order->cycle === 'reset_price') {
|
||||
if ($order->period === 'reset_price') {
|
||||
$order->type = 4;
|
||||
} else if ($user->plan_id !== NULL && $order->plan_id !== $user->plan_id) {
|
||||
$order->type = 3;
|
133
app/Http/Controllers/V1/Admin/PaymentController.php
Normal file
133
app/Http/Controllers/V1/Admin/PaymentController.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\PaymentSave;
|
||||
use App\Models\Payment;
|
||||
use App\Services\PaymentService;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
public function getPaymentMethods()
|
||||
{
|
||||
$methods = [];
|
||||
foreach (glob(base_path('app//Payments') . '/*.php') as $file) {
|
||||
array_push($methods, pathinfo($file)['filename']);
|
||||
}
|
||||
return response([
|
||||
'data' => $methods
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetch()
|
||||
{
|
||||
$payments = Payment::orderBy('sort', 'ASC')->get();
|
||||
foreach ($payments as $k => $v) {
|
||||
$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
|
||||
]);
|
||||
}
|
||||
|
||||
public function getPaymentForm(Request $request)
|
||||
{
|
||||
$paymentService = new PaymentService($request->input('payment'), $request->input('id'));
|
||||
return response([
|
||||
'data' => $paymentService->form()
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
$payment = Payment::find($request->input('id'));
|
||||
if (!$payment) abort(500, '支付方式不存在');
|
||||
$payment->enable = !$payment->enable;
|
||||
if (!$payment->save()) abort(500, '保存失败');
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
if (!config('v2board.app_url')) {
|
||||
abort(500, '请在站点配置中配置站点地址');
|
||||
}
|
||||
$params = $request->validate([
|
||||
'name' => 'required',
|
||||
'icon' => 'nullable',
|
||||
'payment' => 'required',
|
||||
'config' => 'required',
|
||||
'notify_domain' => 'nullable|url',
|
||||
'handling_fee_fixed' => 'nullable|integer',
|
||||
'handling_fee_percent' => 'nullable|numeric|between:0.1,100'
|
||||
], [
|
||||
'name.required' => '显示名称不能为空',
|
||||
'payment.required' => '网关参数不能为空',
|
||||
'config.required' => '配置参数不能为空',
|
||||
'notify_domain.url' => '自定义通知域名格式有误',
|
||||
'handling_fee_fixed.integer' => '固定手续费格式有误',
|
||||
'handling_fee_percent.between' => '百分比手续费范围须在0.1-100之间'
|
||||
]);
|
||||
if ($request->input('id')) {
|
||||
$payment = Payment::find($request->input('id'));
|
||||
if (!$payment) abort(500, '支付方式不存在');
|
||||
try {
|
||||
$payment->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
$params['uuid'] = Helper::randomChar(8);
|
||||
if (!Payment::create($params)) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
$payment = Payment::find($request->input('id'));
|
||||
if (!$payment) abort(500, '支付方式不存在');
|
||||
return response([
|
||||
'data' => $payment->delete()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function sort(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'ids' => 'required|array'
|
||||
], [
|
||||
'ids.required' => '参数有误',
|
||||
'ids.array' => '参数有误'
|
||||
]);
|
||||
DB::beginTransaction();
|
||||
foreach ($request->input('ids') as $k => $v) {
|
||||
if (!Payment::find($v)->update(['sort' => $k + 1])) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,33 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\PlanSave;
|
||||
use App\Http\Requests\Admin\PlanSort;
|
||||
use App\Http\Requests\Admin\PlanUpdate;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Order;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Services\PlanService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
|
||||
$counts = User::select(
|
||||
DB::raw("plan_id"),
|
||||
DB::raw("count(*) as count")
|
||||
)
|
||||
->where('plan_id', '!=', NULL)
|
||||
->where(function ($query) {
|
||||
$query->where('expired_at', '>=', time())
|
||||
->orWhere('expired_at', NULL);
|
||||
})
|
||||
->groupBy("plan_id")
|
||||
->get();
|
||||
$counts = PlanService::countActiveUsers();
|
||||
$plans = Plan::orderBy('sort', 'ASC')->get();
|
||||
foreach ($plans as $k => $v) {
|
||||
$plans[$k]->count = 0;
|
||||
@ -51,10 +41,13 @@ class PlanController extends Controller
|
||||
DB::beginTransaction();
|
||||
// update user group id and transfer
|
||||
try {
|
||||
User::where('plan_id', $plan->id)->update([
|
||||
'group_id' => $plan->group_id,
|
||||
'transfer_enable' => $plan->transfer_enable * 1073741824
|
||||
]);
|
||||
if ($request->input('force_update')) {
|
||||
User::where('plan_id', $plan->id)->update([
|
||||
'group_id' => $params['group_id'],
|
||||
'transfer_enable' => $params['transfer_enable'] * 1073741824,
|
||||
'speed_limit' => $params['speed_limit']
|
||||
]);
|
||||
}
|
||||
$plan->update($params);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\Models\Server;
|
||||
use App\Models\ServerGroup;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
use App\Models\ServerGroup;
|
||||
use App\Models\ServerVmess;
|
||||
use App\Models\User;
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GroupController extends Controller
|
||||
{
|
||||
@ -18,8 +19,20 @@ class GroupController extends Controller
|
||||
'data' => [ServerGroup::find($request->input('group_id'))]
|
||||
]);
|
||||
}
|
||||
$serverGroups = ServerGroup::get();
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAllServers();
|
||||
foreach ($serverGroups as $k => $v) {
|
||||
$serverGroups[$k]['user_count'] = User::where('group_id', $v['id'])->count();
|
||||
$serverGroups[$k]['server_count'] = 0;
|
||||
foreach ($servers as $server) {
|
||||
if (in_array($v['id'], $server['group_id'])) {
|
||||
$serverGroups[$k]['server_count'] = $serverGroups[$k]['server_count']+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => ServerGroup::get()
|
||||
'data' => $serverGroups
|
||||
]);
|
||||
}
|
||||
|
||||
@ -50,10 +63,9 @@ class GroupController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$servers = Server::all();
|
||||
$servers = ServerVmess::all();
|
||||
foreach ($servers as $server) {
|
||||
$groupId = json_decode($server->group_id);
|
||||
if (in_array($request->input('id'), $groupId)) {
|
||||
if (in_array($request->input('id'), $server->group_id)) {
|
||||
abort(500, '该组已被节点所使用,无法删除');
|
||||
}
|
||||
}
|
111
app/Http/Controllers/V1/Admin/Server/HysteriaController.php
Normal file
111
app/Http/Controllers/V1/Admin/Server/HysteriaController.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerHysteria;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HysteriaController extends Controller
|
||||
{
|
||||
public function save(Request $request)
|
||||
{
|
||||
$params = $request->validate([
|
||||
'show' => '',
|
||||
'name' => 'required',
|
||||
'group_id' => 'required|array',
|
||||
'route_id' => 'nullable|array',
|
||||
'parent_id' => 'nullable|integer',
|
||||
'host' => 'required',
|
||||
'port' => 'required',
|
||||
'server_port' => 'required',
|
||||
'tags' => 'nullable|array',
|
||||
'rate' => 'required|numeric',
|
||||
'up_mbps' => 'required|numeric|min:1',
|
||||
'down_mbps' => 'required|numeric|min:1',
|
||||
'server_name' => 'nullable',
|
||||
'insecure' => 'required|in:0,1',
|
||||
'obfs_type' => 'nullable|in:salamander',
|
||||
'ignore_client_bandwidth' => 'required|in:0,1'
|
||||
]);
|
||||
|
||||
if ($request->input('id')) {
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
if (!ServerHysteria::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $server->delete()
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'show' => 'in:0,1'
|
||||
], [
|
||||
'show.in' => '显示状态格式不正确'
|
||||
]);
|
||||
$params = $request->only([
|
||||
'show',
|
||||
]);
|
||||
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function copy(Request $request)
|
||||
{
|
||||
$server = ServerHysteria::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerHysteria::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
44
app/Http/Controllers/V1/Admin/Server/ManageController.php
Normal file
44
app/Http/Controllers/V1/Admin/Server/ManageController.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ManageController extends Controller
|
||||
{
|
||||
public function getNodes(Request $request)
|
||||
{
|
||||
$serverService = new ServerService();
|
||||
return response([
|
||||
'data' => $serverService->getAllServers()
|
||||
]);
|
||||
}
|
||||
|
||||
public function sort(Request $request)
|
||||
{
|
||||
ini_set('post_max_size', '1m');
|
||||
$params = $request->only(
|
||||
'shadowsocks',
|
||||
'vmess',
|
||||
'trojan',
|
||||
'hysteria'
|
||||
) ?? [];
|
||||
DB::beginTransaction();
|
||||
foreach ($params as $k => $v) {
|
||||
$model = 'App\\Models\\Server' . ucfirst($k);
|
||||
foreach($v as $id => $sort) {
|
||||
if (!$model::find($id)->update(['sort' => $sort])) {
|
||||
DB::rollBack();
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
68
app/Http/Controllers/V1/Admin/Server/RouteController.php
Normal file
68
app/Http/Controllers/V1/Admin/Server/RouteController.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerRoute;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RouteController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$routes = ServerRoute::get();
|
||||
// TODO: remove on 1.8.0
|
||||
foreach ($routes as $k => $route) {
|
||||
$array = json_decode($route->match, true);
|
||||
if (is_array($array)) $routes[$k]['match'] = $array;
|
||||
}
|
||||
// TODO: remove on 1.8.0
|
||||
return [
|
||||
'data' => $routes
|
||||
];
|
||||
}
|
||||
|
||||
public function save(Request $request)
|
||||
{
|
||||
$params = $request->validate([
|
||||
'remarks' => 'required',
|
||||
'match' => 'required|array',
|
||||
'action' => 'required|in:block,dns',
|
||||
'action_value' => 'nullable'
|
||||
], [
|
||||
'remarks.required' => '备注不能为空',
|
||||
'match.required' => '匹配值不能为空',
|
||||
'action.required' => '动作类型不能为空',
|
||||
'action.in' => '动作类型参数有误'
|
||||
]);
|
||||
$params['match'] = array_filter($params['match']);
|
||||
// TODO: remove on 1.8.0
|
||||
$params['match'] = json_encode($params['match']);
|
||||
// TODO: remove on 1.8.0
|
||||
if ($request->input('id')) {
|
||||
try {
|
||||
$route = ServerRoute::find($request->input('id'));
|
||||
$route->update($params);
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
}
|
||||
if (!ServerRoute::create($params)) abort(500, '创建失败');
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
$route = ServerRoute::find($request->input('id'));
|
||||
if (!$route) abort(500, '路由不存在');
|
||||
if (!$route->delete()) abort(500, '删除失败');
|
||||
return [
|
||||
'data' => true
|
||||
];
|
||||
}
|
||||
}
|
@ -1,28 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\ServerShadowsocksSave;
|
||||
use App\Http\Requests\Admin\ServerShadowsocksSort;
|
||||
use App\Http\Requests\Admin\ServerShadowsocksUpdate;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ShadowsocksController extends Controller
|
||||
{
|
||||
public function save(ServerShadowsocksSave $request)
|
||||
{
|
||||
$params = $request->validated();
|
||||
$params['group_id'] = json_encode($params['group_id']);
|
||||
if (isset($params['tags'])) {
|
||||
$params['tags'] = json_encode($params['tags']);
|
||||
}
|
||||
|
||||
if ($request->input('id')) {
|
||||
$server = ServerShadowsocks::find($request->input('id'));
|
||||
if (!$server) {
|
@ -1,28 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Server;
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Http\Requests\Admin\ServerTrojanSave;
|
||||
use App\Http\Requests\Admin\ServerTrojanSort;
|
||||
use App\Http\Requests\Admin\ServerTrojanUpdate;
|
||||
use App\Services\ServerService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\ServerTrojanSave;
|
||||
use App\Http\Requests\Admin\ServerTrojanUpdate;
|
||||
use App\Models\ServerTrojan;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrojanController extends Controller
|
||||
{
|
||||
public function save(ServerTrojanSave $request)
|
||||
{
|
||||
$params = $request->validated();
|
||||
$params['group_id'] = json_encode($params['group_id']);
|
||||
if (isset($params['tags'])) {
|
||||
$params['tags'] = json_encode($params['tags']);
|
||||
}
|
||||
|
||||
if ($request->input('id')) {
|
||||
$server = ServerTrojan::find($request->input('id'));
|
||||
if (!$server) {
|
119
app/Http/Controllers/V1/Admin/Server/VlessController.php
Normal file
119
app/Http/Controllers/V1/Admin/Server/VlessController.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerVless;
|
||||
use Illuminate\Http\Request;
|
||||
use ParagonIE_Sodium_Compat as SodiumCompat;
|
||||
use App\Utils\Helper;
|
||||
|
||||
class VlessController extends Controller
|
||||
{
|
||||
public function save(Request $request)
|
||||
{
|
||||
$params = $request->validate([
|
||||
'group_id' => 'required',
|
||||
'route_id' => 'nullable|array',
|
||||
'name' => 'required',
|
||||
'parent_id' => 'nullable|integer',
|
||||
'host' => 'required',
|
||||
'port' => 'required',
|
||||
'server_port' => 'required',
|
||||
'tls' => 'required|in:0,1,2',
|
||||
'tls_settings' => 'nullable|array',
|
||||
'flow' => 'nullable|in:xtls-rprx-vision',
|
||||
'network' => 'required',
|
||||
'network_settings' => 'nullable|array',
|
||||
'tags' => 'nullable|array',
|
||||
'rate' => 'required',
|
||||
'show' => 'nullable|in:0,1',
|
||||
'sort' => 'nullable'
|
||||
]);
|
||||
|
||||
if (isset($params['tls']) && (int)$params['tls'] === 2) {
|
||||
$keyPair = SodiumCompat::crypto_box_keypair();
|
||||
$params['tls_settings'] = $params['tls_settings'] ?? [];
|
||||
if (!isset($params['tls_settings']['public_key'])) {
|
||||
$params['tls_settings']['public_key'] = Helper::base64EncodeUrlSafe(SodiumCompat::crypto_box_publickey($keyPair));
|
||||
}
|
||||
if (!isset($params['tls_settings']['private_key'])) {
|
||||
$params['tls_settings']['private_key'] = Helper::base64EncodeUrlSafe(SodiumCompat::crypto_box_secretkey($keyPair));
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->input('id')) {
|
||||
$server = ServerVless::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
if (!ServerVless::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$server = ServerVless::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $server->delete()
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request)
|
||||
{
|
||||
$params = $request->validate([
|
||||
'show' => 'nullable|in:0,1',
|
||||
]);
|
||||
|
||||
$server = ServerVless::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function copy(Request $request)
|
||||
{
|
||||
$server = ServerVless::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerVless::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
91
app/Http/Controllers/V1/Admin/Server/VmessController.php
Normal file
91
app/Http/Controllers/V1/Admin/Server/VmessController.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin\Server;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\ServerVmessSave;
|
||||
use App\Http\Requests\Admin\ServerVmessUpdate;
|
||||
use App\Models\ServerVmess;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class VmessController extends Controller
|
||||
{
|
||||
public function save(ServerVmessSave $request)
|
||||
{
|
||||
$params = $request->validated();
|
||||
|
||||
if ($request->input('id')) {
|
||||
$server = ServerVmess::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
if (!ServerVmess::create($params)) {
|
||||
abort(500, '创建失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$server = ServerVmess::find($request->input('id'));
|
||||
if (!$server) {
|
||||
abort(500, '节点ID不存在');
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $server->delete()
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(ServerVmessUpdate $request)
|
||||
{
|
||||
$params = $request->only([
|
||||
'show',
|
||||
]);
|
||||
|
||||
$server = ServerVmess::find($request->input('id'));
|
||||
|
||||
if (!$server) {
|
||||
abort(500, '该服务器不存在');
|
||||
}
|
||||
try {
|
||||
$server->update($params);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function copy(Request $request)
|
||||
{
|
||||
$server = ServerVmess::find($request->input('id'));
|
||||
$server->show = 0;
|
||||
if (!$server) {
|
||||
abort(500, '服务器不存在');
|
||||
}
|
||||
if (!ServerVmess::create($server->toArray())) {
|
||||
abort(500, '复制失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
153
app/Http/Controllers/V1/Admin/StatController.php
Normal file
153
app/Http/Controllers/V1/Admin/StatController.php
Normal file
@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CommissionLog;
|
||||
use App\Models\Order;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Models\ServerTrojan;
|
||||
use App\Models\ServerVmess;
|
||||
use App\Models\Stat;
|
||||
use App\Models\StatServer;
|
||||
use App\Models\StatUser;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use App\Services\StatisticalService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StatController extends Controller
|
||||
{
|
||||
public function getOverride(Request $request)
|
||||
{
|
||||
return [
|
||||
'data' => [
|
||||
'month_income' => Order::where('created_at', '>=', strtotime(date('Y-m-1')))
|
||||
->where('created_at', '<', time())
|
||||
->whereNotIn('status', [0, 2])
|
||||
->sum('total_amount'),
|
||||
'month_register_total' => User::where('created_at', '>=', strtotime(date('Y-m-1')))
|
||||
->where('created_at', '<', time())
|
||||
->count(),
|
||||
'ticket_pending_total' => Ticket::where('status', 0)
|
||||
->count(),
|
||||
'commission_pending_total' => Order::where('commission_status', 0)
|
||||
->where('invite_user_id', '!=', NULL)
|
||||
->whereNotIn('status', [0, 2])
|
||||
->where('commission_balance', '>', 0)
|
||||
->count(),
|
||||
'day_income' => Order::where('created_at', '>=', strtotime(date('Y-m-d')))
|
||||
->where('created_at', '<', time())
|
||||
->whereNotIn('status', [0, 2])
|
||||
->sum('total_amount'),
|
||||
'last_month_income' => Order::where('created_at', '>=', strtotime('-1 month', strtotime(date('Y-m-1'))))
|
||||
->where('created_at', '<', strtotime(date('Y-m-1')))
|
||||
->whereNotIn('status', [0, 2])
|
||||
->sum('total_amount'),
|
||||
'commission_month_payout' => CommissionLog::where('created_at', '>=', strtotime(date('Y-m-1')))
|
||||
->where('created_at', '<', time())
|
||||
->sum('get_amount'),
|
||||
'commission_last_month_payout' => CommissionLog::where('created_at', '>=', strtotime('-1 month', strtotime(date('Y-m-1'))))
|
||||
->where('created_at', '<', strtotime(date('Y-m-1')))
|
||||
->sum('get_amount'),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getOrder(Request $request)
|
||||
{
|
||||
$statistics = Stat::where('record_type', 'd')
|
||||
->limit(31)
|
||||
->orderBy('record_at', 'DESC')
|
||||
->get()
|
||||
->toArray();
|
||||
$result = [];
|
||||
foreach ($statistics as $statistic) {
|
||||
$date = date('m-d', $statistic['record_at']);
|
||||
$result[] = [
|
||||
'type' => '收款金额',
|
||||
'date' => $date,
|
||||
'value' => $statistic['paid_total'] / 100
|
||||
];
|
||||
$result[] = [
|
||||
'type' => '收款笔数',
|
||||
'date' => $date,
|
||||
'value' => $statistic['paid_count']
|
||||
];
|
||||
$result[] = [
|
||||
'type' => '佣金金额(已发放)',
|
||||
'date' => $date,
|
||||
'value' => $statistic['commission_total'] / 100
|
||||
];
|
||||
$result[] = [
|
||||
'type' => '佣金笔数(已发放)',
|
||||
'date' => $date,
|
||||
'value' => $statistic['commission_count']
|
||||
];
|
||||
}
|
||||
$result = array_reverse($result);
|
||||
return [
|
||||
'data' => $result
|
||||
];
|
||||
}
|
||||
|
||||
public function getServerLastRank()
|
||||
{
|
||||
$servers = [
|
||||
'shadowsocks' => ServerShadowsocks::where('parent_id', null)->get()->toArray(),
|
||||
'v2ray' => ServerVmess::where('parent_id', null)->get()->toArray(),
|
||||
'trojan' => ServerTrojan::where('parent_id', null)->get()->toArray(),
|
||||
'vmess' => ServerVmess::where('parent_id', null)->get()->toArray()
|
||||
];
|
||||
$startAt = strtotime('-1 day', strtotime(date('Y-m-d')));
|
||||
$endAt = strtotime(date('Y-m-d'));
|
||||
$statistics = StatServer::select([
|
||||
'server_id',
|
||||
'server_type',
|
||||
'u',
|
||||
'd',
|
||||
DB::raw('(u+d) as total')
|
||||
])
|
||||
->where('record_at', '>=', $startAt)
|
||||
->where('record_at', '<', $endAt)
|
||||
->where('record_type', 'd')
|
||||
->limit(10)
|
||||
->orderBy('total', 'DESC')
|
||||
->get()
|
||||
->toArray();
|
||||
foreach ($statistics as $k => $v) {
|
||||
foreach ($servers[$v['server_type']] as $server) {
|
||||
if ($server['id'] === $v['server_id']) {
|
||||
$statistics[$k]['server_name'] = $server['name'];
|
||||
}
|
||||
}
|
||||
$statistics[$k]['total'] = $statistics[$k]['total'] / 1073741824;
|
||||
}
|
||||
array_multisort(array_column($statistics, 'total'), SORT_DESC, $statistics);
|
||||
return [
|
||||
'data' => $statistics
|
||||
];
|
||||
}
|
||||
|
||||
public function getStatUser(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'user_id' => 'required|integer'
|
||||
]);
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
||||
$builder = StatUser::orderBy('record_at', 'DESC')->where('user_id', $request->input('user_id'));
|
||||
|
||||
$total = $builder->count();
|
||||
$records = $builder->forPage($current, $pageSize)
|
||||
->get();
|
||||
return [
|
||||
'data' => $records,
|
||||
'total' => $total
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
119
app/Http/Controllers/V1/Admin/SystemController.php
Normal file
119
app/Http/Controllers/V1/Admin/SystemController.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Log as LogModel;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Laravel\Horizon\Contracts\JobRepository;
|
||||
use Laravel\Horizon\Contracts\MasterSupervisorRepository;
|
||||
use Laravel\Horizon\Contracts\MetricsRepository;
|
||||
use Laravel\Horizon\Contracts\SupervisorRepository;
|
||||
use Laravel\Horizon\Contracts\WorkloadRepository;
|
||||
use Laravel\Horizon\WaitTimeCalculator;
|
||||
|
||||
class SystemController extends Controller
|
||||
{
|
||||
public function getSystemStatus()
|
||||
{
|
||||
return response([
|
||||
'data' => [
|
||||
'schedule' => $this->getScheduleStatus(),
|
||||
'horizon' => $this->getHorizonStatus(),
|
||||
'schedule_last_runtime' => Cache::get(CacheKey::get('SCHEDULE_LAST_CHECK_AT', null))
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function getQueueWorkload(WorkloadRepository $workload)
|
||||
{
|
||||
return response([
|
||||
'data' => collect($workload->get())->sortBy('name')->values()->toArray()
|
||||
]);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function getQueueStats()
|
||||
{
|
||||
return response([
|
||||
'data' => [
|
||||
'failedJobs' => app(JobRepository::class)->countRecentlyFailed(),
|
||||
'jobsPerMinute' => app(MetricsRepository::class)->jobsProcessedPerMinute(),
|
||||
'pausedMasters' => $this->totalPausedMasters(),
|
||||
'periods' => [
|
||||
'failedJobs' => config('horizon.trim.recent_failed', config('horizon.trim.failed')),
|
||||
'recentJobs' => config('horizon.trim.recent'),
|
||||
],
|
||||
'processes' => $this->totalProcessCount(),
|
||||
'queueWithMaxRuntime' => app(MetricsRepository::class)->queueWithMaximumRuntime(),
|
||||
'queueWithMaxThroughput' => app(MetricsRepository::class)->queueWithMaximumThroughput(),
|
||||
'recentJobs' => app(JobRepository::class)->countRecent(),
|
||||
'status' => $this->getHorizonStatus(),
|
||||
'wait' => collect(app(WaitTimeCalculator::class)->calculate())->take(1),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the total process count across all supervisors.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function totalProcessCount()
|
||||
{
|
||||
$supervisors = app(SupervisorRepository::class)->all();
|
||||
|
||||
return collect($supervisors)->reduce(function ($carry, $supervisor) {
|
||||
return $carry + collect($supervisor->processes)->sum();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of master supervisors that are currently paused.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function totalPausedMasters()
|
||||
{
|
||||
if (! $masters = app(MasterSupervisorRepository::class)->all()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return collect($masters)->filter(function ($master) {
|
||||
return $master->status === 'paused';
|
||||
})->count();
|
||||
}
|
||||
|
||||
public function getSystemLog(Request $request) {
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('page_size') >= 10 ? $request->input('page_size') : 10;
|
||||
$builder = LogModel::orderBy('created_at', 'DESC')
|
||||
->setFilterAllowKeys('level');
|
||||
$total = $builder->count();
|
||||
$res = $builder->forPage($current, $pageSize)
|
||||
->get();
|
||||
return response([
|
||||
'data' => $res,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
}
|
91
app/Http/Controllers/V1/Admin/ThemeController.php
Normal file
91
app/Http/Controllers/V1/Admin/ThemeController.php
Normal file
@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ThemeService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class ThemeController extends Controller
|
||||
{
|
||||
private $themes;
|
||||
private $path;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->path = $path = public_path('theme/');
|
||||
$this->themes = array_map(function ($item) use ($path) {
|
||||
return str_replace($path, '', $item);
|
||||
}, glob($path . '*'));
|
||||
}
|
||||
|
||||
public function getThemes()
|
||||
{
|
||||
$themeConfigs = [];
|
||||
foreach ($this->themes as $theme) {
|
||||
$themeConfigFile = $this->path . "{$theme}/config.json";
|
||||
if (!File::exists($themeConfigFile)) continue;
|
||||
$themeConfig = json_decode(File::get($themeConfigFile), true);
|
||||
if (!isset($themeConfig['configs']) || !is_array($themeConfig)) continue;
|
||||
$themeConfigs[$theme] = $themeConfig;
|
||||
if (config("theme.{$theme}")) continue;
|
||||
$themeService = new ThemeService($theme);
|
||||
$themeService->init();
|
||||
}
|
||||
return response([
|
||||
'data' => [
|
||||
'themes' => $themeConfigs,
|
||||
'active' => config('v2board.frontend_theme', 'v2board')
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function getThemeConfig(Request $request)
|
||||
{
|
||||
$payload = $request->validate([
|
||||
'name' => 'required|in:' . join(',', $this->themes)
|
||||
]);
|
||||
return response([
|
||||
'data' => config("theme.{$payload['name']}")
|
||||
]);
|
||||
}
|
||||
|
||||
public function saveThemeConfig(Request $request)
|
||||
{
|
||||
$payload = $request->validate([
|
||||
'name' => 'required|in:' . join(',', $this->themes),
|
||||
'config' => 'required'
|
||||
]);
|
||||
$payload['config'] = json_decode(base64_decode($payload['config']), true);
|
||||
if (!$payload['config'] || !is_array($payload['config'])) abort(500, '参数有误');
|
||||
$themeConfigFile = public_path("theme/{$payload['name']}/config.json");
|
||||
if (!File::exists($themeConfigFile)) abort(500, '主题不存在');
|
||||
$themeConfig = json_decode(File::get($themeConfigFile), true);
|
||||
if (!isset($themeConfig['configs']) || !is_array($themeConfig)) abort(500, '主题配置文件有误');
|
||||
$validateFields = array_column($themeConfig['configs'], 'field_name');
|
||||
$config = [];
|
||||
foreach ($validateFields as $validateField) {
|
||||
$config[$validateField] = isset($payload['config'][$validateField]) ? $payload['config'][$validateField] : '';
|
||||
}
|
||||
|
||||
File::ensureDirectoryExists(base_path() . '/config/theme/');
|
||||
|
||||
$data = var_export($config, 1);
|
||||
if (!File::put(base_path() . "/config/theme/{$payload['name']}.php", "<?php\n return $data ;")) {
|
||||
abort(500, '修改失败');
|
||||
}
|
||||
|
||||
try {
|
||||
Artisan::call('config:cache');
|
||||
// sleep(2);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => $config
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,14 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Jobs\SendEmailJob;
|
||||
use App\Services\TicketService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use App\Models\TicketMessage;
|
||||
use App\Models\User;
|
||||
use App\Services\TicketService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
@ -36,20 +35,20 @@ class TicketController extends Controller
|
||||
}
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
||||
$model = Ticket::orderBy('created_at', 'DESC');
|
||||
$model = Ticket::orderBy('updated_at', 'DESC');
|
||||
if ($request->input('status') !== NULL) {
|
||||
$model->where('status', $request->input('status'));
|
||||
}
|
||||
if ($request->input('reply_status') !== NULL) {
|
||||
$model->whereIn('reply_status', $request->input('reply_status'));
|
||||
}
|
||||
if ($request->input('email') !== NULL) {
|
||||
$user = User::where('email', $request->input('email'))->first();
|
||||
if ($user) $model->where('user_id', $user->id);
|
||||
}
|
||||
$total = $model->count();
|
||||
$res = $model->forPage($current, $pageSize)
|
||||
->get();
|
||||
for ($i = 0; $i < count($res); $i++) {
|
||||
if ($res[$i]['last_reply_user_id'] == $request->session()->get('id')) {
|
||||
$res[$i]['reply_status'] = 0;
|
||||
} else {
|
||||
$res[$i]['reply_status'] = 1;
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $res,
|
||||
'total' => $total
|
||||
@ -68,7 +67,7 @@ class TicketController extends Controller
|
||||
$ticketService->replyByAdmin(
|
||||
$request->input('id'),
|
||||
$request->input('message'),
|
||||
$request->session()->get('id')
|
||||
$request->user['id']
|
||||
);
|
||||
return response([
|
||||
'data' => true
|
@ -1,39 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
namespace App\Http\Controllers\V1\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\UserFetch;
|
||||
use App\Http\Requests\Admin\UserGenerate;
|
||||
use App\Http\Requests\Admin\UserSendMail;
|
||||
use App\Http\Requests\Admin\UserUpdate;
|
||||
use App\Jobs\SendEmailJob;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Services\AuthService;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function resetSecret(Request $request)
|
||||
{
|
||||
$user = User::find($request->input('id'));
|
||||
if (!$user) abort(500, '用户不存在');
|
||||
$user->token = Helper::guid();
|
||||
$user->uuid = Helper::guid(true);
|
||||
return response([
|
||||
'data' => $user->save()
|
||||
]);
|
||||
}
|
||||
|
||||
private function filter(Request $request, $builder)
|
||||
{
|
||||
if ($request->input('filter')) {
|
||||
foreach ($request->input('filter') as $filter) {
|
||||
if ($filter['key'] === 'invite_by_email') {
|
||||
$user = User::where('email', $filter['value'])->first();
|
||||
if (!$user) continue;
|
||||
$builder->where('invite_user_id', $user->id);
|
||||
continue;
|
||||
$filters = $request->input('filter');
|
||||
if ($filters) {
|
||||
foreach ($filters as $k => $filter) {
|
||||
if ($filter['condition'] === '模糊') {
|
||||
$filter['condition'] = 'like';
|
||||
$filter['value'] = "%{$filter['value']}%";
|
||||
}
|
||||
if ($filter['key'] === 'd' || $filter['key'] === 'transfer_enable') {
|
||||
$filter['value'] = $filter['value'] * 1073741824;
|
||||
}
|
||||
if ($filter['condition'] === '模糊') {
|
||||
$filter['condition'] = 'like';
|
||||
$filter['value'] = "%{$filter['value']}%";
|
||||
if ($filter['key'] === 'invite_by_email') {
|
||||
$user = User::where('email', $filter['condition'], $filter['value'])->first();
|
||||
$inviteUserId = isset($user->id) ? $user->id : 0;
|
||||
$builder->where('invite_user_id', $inviteUserId);
|
||||
unset($filters[$k]);
|
||||
continue;
|
||||
}
|
||||
$builder->where($filter['key'], $filter['condition'], $filter['value']);
|
||||
}
|
||||
@ -46,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)
|
||||
@ -58,7 +74,7 @@ class UserController extends Controller
|
||||
$res[$i]['plan_name'] = $plan[$k]['name'];
|
||||
}
|
||||
}
|
||||
$res[$i]['subscribe_url'] = config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $res[$i]['token'];
|
||||
$res[$i]['subscribe_url'] = Helper::getSubscribeUrl($res[$i]['token']);
|
||||
}
|
||||
return response([
|
||||
'data' => $res,
|
||||
@ -71,8 +87,12 @@ class UserController extends Controller
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$user = User::find($request->input('id'));
|
||||
if ($user->invite_user_id) {
|
||||
$user['invite_user'] = User::find($user->invite_user_id);
|
||||
}
|
||||
return response([
|
||||
'data' => User::find($request->input('id'))
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
@ -99,6 +119,19 @@ class UserController extends Controller
|
||||
}
|
||||
$params['group_id'] = $plan->group_id;
|
||||
}
|
||||
if ($request->input('invite_user_email')) {
|
||||
$inviteUser = User::where('email', $request->input('invite_user_email'))->first();
|
||||
if ($inviteUser) {
|
||||
$params['invite_user_id'] = $inviteUser->id;
|
||||
}
|
||||
} else {
|
||||
$params['invite_user_id'] = null;
|
||||
}
|
||||
|
||||
if (isset($params['banned']) && (int)$params['banned'] === 1) {
|
||||
$authService = new AuthService($user);
|
||||
$authService->removeAllSession();
|
||||
}
|
||||
|
||||
try {
|
||||
$user->update($params);
|
||||
@ -125,7 +158,6 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
$data = "邮箱,余额,推广佣金,总流量,剩余流量,套餐到期时间,订阅计划,订阅地址\r\n";
|
||||
$baseUrl = config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL')));
|
||||
foreach($res as $user) {
|
||||
$expireDate = $user['expired_at'] === NULL ? '长期有效' : date('Y-m-d H:i:s', $user['expired_at']);
|
||||
$balance = $user['balance'] / 100;
|
||||
@ -133,7 +165,7 @@ class UserController extends Controller
|
||||
$transferEnable = $user['transfer_enable'] ? $user['transfer_enable'] / 1073741824 : 0;
|
||||
$notUseFlow = (($user['transfer_enable'] - ($user['u'] + $user['d'])) / 1073741824) ?? 0;
|
||||
$planName = $user['plan_name'] ?? '无订阅';
|
||||
$subscribeUrl = $baseUrl . '/api/v1/client/subscribe?token=' . $user['token'];
|
||||
$subscribeUrl = Helper::getSubscribeUrl($user['token']);
|
||||
$data .= "{$user['email']},{$balance},{$commissionBalance},{$transferEnable},{$notUseFlow},{$expireDate},{$planName},{$subscribeUrl}\r\n";
|
||||
}
|
||||
echo "\xEF\xBB\xBF" . $data;
|
||||
@ -157,6 +189,9 @@ class UserController extends Controller
|
||||
'uuid' => Helper::guid(true),
|
||||
'token' => Helper::guid()
|
||||
];
|
||||
if (User::where('email', $user['email'])->first()) {
|
||||
abort(500, '邮箱已存在于系统中');
|
||||
}
|
||||
$user['password'] = password_hash($request->input('password') ?? $user['email'], PASSWORD_DEFAULT);
|
||||
if (!User::create($user)) {
|
||||
abort(500, '生成失败');
|
||||
@ -201,12 +236,11 @@ class UserController extends Controller
|
||||
}
|
||||
DB::commit();
|
||||
$data = "账号,密码,过期时间,UUID,创建时间,订阅地址\r\n";
|
||||
$baseUrl = config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL')));
|
||||
foreach($users as $user) {
|
||||
$expireDate = $user['expired_at'] === NULL ? '长期有效' : date('Y-m-d H:i:s', $user['expired_at']);
|
||||
$createDate = date('Y-m-d H:i:s', $user['created_at']);
|
||||
$password = $request->input('password') ?? $user['email'];
|
||||
$subscribeUrl = $baseUrl . '/api/v1/client/subscribe?token=' . $user['token'];
|
||||
$subscribeUrl = Helper::getSubscribeUrl($user['token']);
|
||||
$data .= "{$user['email']},{$password},{$expireDate},{$user['uuid']},{$createDate},{$subscribeUrl}\r\n";
|
||||
}
|
||||
echo $data;
|
||||
@ -229,7 +263,8 @@ class UserController extends Controller
|
||||
'url' => config('v2board.app_url'),
|
||||
'content' => $request->input('content')
|
||||
]
|
||||
]);
|
||||
],
|
||||
'send_email_mass');
|
||||
}
|
||||
|
||||
return response([
|
95
app/Http/Controllers/V1/Client/AppController.php
Normal file
95
app/Http/Controllers/V1/Client/AppController.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class AppController extends Controller
|
||||
{
|
||||
public function getConfig(Request $request)
|
||||
{
|
||||
$servers = [];
|
||||
$user = $request->user;
|
||||
$userService = new UserService();
|
||||
if ($userService->isAvailable($user)) {
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAvailableServers($user);
|
||||
}
|
||||
$defaultConfig = base_path() . '/resources/rules/app.clash.yaml';
|
||||
$customConfig = base_path() . '/resources/rules/custom.app.clash.yaml';
|
||||
if (File::exists($customConfig)) {
|
||||
$config = Yaml::parseFile($customConfig);
|
||||
} else {
|
||||
$config = Yaml::parseFile($defaultConfig);
|
||||
}
|
||||
$proxy = [];
|
||||
$proxies = [];
|
||||
|
||||
foreach ($servers as $item) {
|
||||
if ($item['type'] === 'shadowsocks'
|
||||
&& in_array($item['cipher'], [
|
||||
'aes-128-gcm',
|
||||
'aes-192-gcm',
|
||||
'aes-256-gcm',
|
||||
'chacha20-ietf-poly1305'
|
||||
])
|
||||
) {
|
||||
array_push($proxy, \App\Protocols\Clash::buildShadowsocks($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'vmess') {
|
||||
array_push($proxy, \App\Protocols\Clash::buildVmess($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
if ($item['type'] === 'trojan') {
|
||||
array_push($proxy, \App\Protocols\Clash::buildTrojan($user['uuid'], $item));
|
||||
array_push($proxies, $item['name']);
|
||||
}
|
||||
}
|
||||
|
||||
$config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy);
|
||||
foreach ($config['proxy-groups'] as $k => $v) {
|
||||
$config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies);
|
||||
}
|
||||
die(Yaml::dump($config));
|
||||
}
|
||||
|
||||
public function getVersion(Request $request)
|
||||
{
|
||||
if (strpos($request->header('user-agent'), 'tidalab/4.0.0') !== false
|
||||
|| strpos($request->header('user-agent'), 'tunnelab/4.0.0') !== false
|
||||
) {
|
||||
if (strpos($request->header('user-agent'), 'Win64') !== false) {
|
||||
return response([
|
||||
'data' => [
|
||||
'version' => config('v2board.windows_version'),
|
||||
'download_url' => config('v2board.windows_download_url')
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
return response([
|
||||
'data' => [
|
||||
'version' => config('v2board.macos_version'),
|
||||
'download_url' => config('v2board.macos_download_url')
|
||||
]
|
||||
]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
return response([
|
||||
'data' => [
|
||||
'windows_version' => config('v2board.windows_version'),
|
||||
'windows_download_url' => config('v2board.windows_download_url'),
|
||||
'macos_version' => config('v2board.macos_version'),
|
||||
'macos_download_url' => config('v2board.macos_download_url'),
|
||||
'android_version' => config('v2board.android_version'),
|
||||
'android_download_url' => config('v2board.android_download_url')
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
62
app/Http/Controllers/V1/Client/ClientController.php
Normal file
62
app/Http/Controllers/V1/Client/ClientController.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Protocols\General;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ClientController extends Controller
|
||||
{
|
||||
public function subscribe(Request $request)
|
||||
{
|
||||
$flag = $request->input('flag')
|
||||
?? ($_SERVER['HTTP_USER_AGENT'] ?? '');
|
||||
$flag = strtolower($flag);
|
||||
$user = $request->user;
|
||||
// account not expired and is not banned.
|
||||
$userService = new UserService();
|
||||
if ($userService->isAvailable($user)) {
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAvailableServers($user);
|
||||
$this->setSubscribeInfoToServers($servers, $user);
|
||||
if ($flag) {
|
||||
foreach (array_reverse(glob(app_path('Protocols') . '/*.php')) as $file) {
|
||||
$file = 'App\\Protocols\\' . basename($file, '.php');
|
||||
$class = new $file($user, $servers);
|
||||
if (strpos($flag, $class->flag) !== false) {
|
||||
die($class->handle());
|
||||
}
|
||||
}
|
||||
}
|
||||
$class = new General($user, $servers);
|
||||
die($class->handle());
|
||||
}
|
||||
}
|
||||
|
||||
private function setSubscribeInfoToServers(&$servers, $user)
|
||||
{
|
||||
if (!isset($servers[0])) return;
|
||||
if (!(int)config('v2board.show_info_to_server_enable', 0)) return;
|
||||
$useTraffic = $user['u'] + $user['d'];
|
||||
$totalTraffic = $user['transfer_enable'];
|
||||
$remainingTraffic = Helper::trafficConvert($totalTraffic - $useTraffic);
|
||||
$expiredDate = $user['expired_at'] ? date('Y-m-d', $user['expired_at']) : '长期有效';
|
||||
$userService = new UserService();
|
||||
$resetDay = $userService->getResetDay($user);
|
||||
array_unshift($servers, array_merge($servers[0], [
|
||||
'name' => "套餐到期:{$expiredDate}",
|
||||
]));
|
||||
if ($resetDay) {
|
||||
array_unshift($servers, array_merge($servers[0], [
|
||||
'name' => "距离下次重置剩余:{$resetDay} 天",
|
||||
]));
|
||||
}
|
||||
array_unshift($servers, array_merge($servers[0], [
|
||||
'name' => "剩余流量:{$remainingTraffic}",
|
||||
]));
|
||||
}
|
||||
}
|
38
app/Http/Controllers/V1/Guest/CommController.php
Normal file
38
app/Http/Controllers/V1/Guest/CommController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Guest;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Utils\Dict;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class CommController extends Controller
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return response([
|
||||
'data' => [
|
||||
'tos_url' => config('v2board.tos_url'),
|
||||
'is_email_verify' => (int)config('v2board.email_verify', 0) ? 1 : 0,
|
||||
'is_invite_force' => (int)config('v2board.invite_force', 0) ? 1 : 0,
|
||||
'email_whitelist_suffix' => (int)config('v2board.email_whitelist_enable', 0)
|
||||
? $this->getEmailSuffix()
|
||||
: 0,
|
||||
'is_recaptcha' => (int)config('v2board.recaptcha_enable', 0) ? 1 : 0,
|
||||
'recaptcha_site_key' => config('v2board.recaptcha_site_key'),
|
||||
'app_description' => config('v2board.app_description'),
|
||||
'app_url' => config('v2board.app_url'),
|
||||
'logo' => config('v2board.logo'),
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
private function getEmailSuffix()
|
||||
{
|
||||
$suffix = config('v2board.email_whitelist_suffix', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT);
|
||||
if (!is_array($suffix)) {
|
||||
return preg_split('/,/', $suffix);
|
||||
}
|
||||
return $suffix;
|
||||
}
|
||||
}
|
49
app/Http/Controllers/V1/Guest/PaymentController.php
Normal file
49
app/Http/Controllers/V1/Guest/PaymentController.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Guest;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\PaymentService;
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PaymentController extends Controller
|
||||
{
|
||||
public function notify($method, $uuid, Request $request)
|
||||
{
|
||||
try {
|
||||
$paymentService = new PaymentService($method, null, $uuid);
|
||||
$verify = $paymentService->notify($request->input());
|
||||
if (!$verify) abort(500, 'verify error');
|
||||
if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {
|
||||
abort(500, 'handle error');
|
||||
}
|
||||
die(isset($verify['custom_result']) ? $verify['custom_result'] : 'success');
|
||||
} catch (\Exception $e) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
}
|
||||
|
||||
private function handle($tradeNo, $callbackNo)
|
||||
{
|
||||
$order = Order::where('trade_no', $tradeNo)->first();
|
||||
if (!$order) {
|
||||
abort(500, 'order is not found');
|
||||
}
|
||||
if ($order->status !== 0) return true;
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->paid($callbackNo)) {
|
||||
return false;
|
||||
}
|
||||
$telegramService = new TelegramService();
|
||||
$message = sprintf(
|
||||
"💰成功收款%s元\n———————————————\n订单号:%s",
|
||||
$order->total_amount / 100,
|
||||
$order->trade_no
|
||||
);
|
||||
$telegramService->sendMessageWithAdmin($message);
|
||||
return true;
|
||||
}
|
||||
}
|
123
app/Http/Controllers/V1/Guest/TelegramController.php
Normal file
123
app/Http/Controllers/V1/Guest/TelegramController.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Guest;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TelegramController extends Controller
|
||||
{
|
||||
protected $msg;
|
||||
protected $commands = [];
|
||||
protected $telegramService;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
if ($request->input('access_token') !== md5(config('v2board.telegram_bot_token'))) {
|
||||
abort(401);
|
||||
}
|
||||
|
||||
$this->telegramService = new TelegramService();
|
||||
}
|
||||
|
||||
public function webhook(Request $request)
|
||||
{
|
||||
$this->formatMessage($request->input());
|
||||
$this->formatChatJoinRequest($request->input());
|
||||
$this->handle();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
if (!$this->msg) return;
|
||||
$msg = $this->msg;
|
||||
$commandName = explode('@', $msg->command);
|
||||
|
||||
// To reduce request, only commands contains @ will get the bot name
|
||||
if (count($commandName) == 2) {
|
||||
$botName = $this->getBotName();
|
||||
if ($commandName[1] === $botName){
|
||||
$msg->command = $commandName[0];
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
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) {
|
||||
$this->telegramService->sendMessage($msg->chat_id, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getBotName()
|
||||
{
|
||||
$response = $this->telegramService->getMe();
|
||||
return $response->result->username;
|
||||
}
|
||||
|
||||
private function formatMessage(array $data)
|
||||
{
|
||||
if (!isset($data['message'])) return;
|
||||
if (!isset($data['message']['text'])) return;
|
||||
$obj = new \StdClass();
|
||||
$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 = 'message';
|
||||
$obj->text = $data['message']['text'];
|
||||
$obj->is_private = $data['message']['chat']['type'] === 'private';
|
||||
if (isset($data['message']['reply_to_message']['text'])) {
|
||||
$obj->message_type = 'reply_message';
|
||||
$obj->reply_text = $data['message']['reply_to_message']['text'];
|
||||
}
|
||||
$this->msg = $obj;
|
||||
}
|
||||
|
||||
private function formatChatJoinRequest(array $data)
|
||||
{
|
||||
if (!isset($data['chat_join_request'])) return;
|
||||
if (!isset($data['chat_join_request']['from']['id'])) return;
|
||||
if (!isset($data['chat_join_request']['chat']['id'])) return;
|
||||
$user = \App\Models\User::where('telegram_id', $data['chat_join_request']['from']['id'])
|
||||
->first();
|
||||
if (!$user) {
|
||||
$this->telegramService->declineChatJoinRequest(
|
||||
$data['chat_join_request']['chat']['id'],
|
||||
$data['chat_join_request']['from']['id']
|
||||
);
|
||||
return;
|
||||
}
|
||||
$userService = new \App\Services\UserService();
|
||||
if (!$userService->isAvailable($user)) {
|
||||
$this->telegramService->declineChatJoinRequest(
|
||||
$data['chat_join_request']['chat']['id'],
|
||||
$data['chat_join_request']['from']['id']
|
||||
);
|
||||
return;
|
||||
}
|
||||
$userService = new \App\Services\UserService();
|
||||
$this->telegramService->approveChatJoinRequest(
|
||||
$data['chat_join_request']['chat']['id'],
|
||||
$data['chat_join_request']['from']['id']
|
||||
);
|
||||
}
|
||||
}
|
@ -1,30 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Passport;
|
||||
namespace App\Http\Controllers\V1\Passport;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Passport\AuthRegister;
|
||||
use App\Http\Requests\Passport\AuthForget;
|
||||
use App\Http\Requests\Passport\AuthLogin;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Http\Requests\Passport\AuthRegister;
|
||||
use App\Jobs\SendEmailJob;
|
||||
use App\Models\InviteCode;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Models\InviteCode;
|
||||
use App\Utils\Helper;
|
||||
use App\Utils\Dict;
|
||||
use App\Services\AuthService;
|
||||
use App\Utils\CacheKey;
|
||||
use App\Utils\Dict;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use ReCaptcha\ReCaptcha;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function loginWithMailLink(Request $request)
|
||||
{
|
||||
if (!(int)config('v2board.login_with_mail_link_enable')) {
|
||||
abort(404);
|
||||
}
|
||||
$params = $request->validate([
|
||||
'email' => 'required|email:strict',
|
||||
'redirect' => 'nullable'
|
||||
]);
|
||||
|
||||
if (Cache::get(CacheKey::get('LAST_SEND_LOGIN_WITH_MAIL_LINK_TIMESTAMP', $params['email']))) {
|
||||
abort(500, __('Sending frequently, please try again later'));
|
||||
}
|
||||
|
||||
$user = User::where('email', $params['email'])->first();
|
||||
if (!$user) {
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
$code = Helper::guid();
|
||||
$key = CacheKey::get('TEMP_TOKEN', $code);
|
||||
Cache::put($key, $user->id, 300);
|
||||
Cache::put(CacheKey::get('LAST_SEND_LOGIN_WITH_MAIL_LINK_TIMESTAMP', $params['email']), time(), 60);
|
||||
|
||||
|
||||
$redirect = '/#/login?verify=' . $code . '&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard');
|
||||
if (config('v2board.app_url')) {
|
||||
$link = config('v2board.app_url') . $redirect;
|
||||
} else {
|
||||
$link = url($redirect);
|
||||
}
|
||||
|
||||
SendEmailJob::dispatch([
|
||||
'email' => $user->email,
|
||||
'subject' => __('Login to :name', [
|
||||
'name' => config('v2board.app_name', 'V2Board')
|
||||
]),
|
||||
'template_name' => 'login',
|
||||
'template_value' => [
|
||||
'name' => config('v2board.app_name', 'V2Board'),
|
||||
'link' => $link,
|
||||
'url' => config('v2board.app_url')
|
||||
]
|
||||
]);
|
||||
|
||||
return response([
|
||||
'data' => $link
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
public function register(AuthRegister $request)
|
||||
{
|
||||
if ((int)config('v2board.register_limit_by_ip_enable', 0)) {
|
||||
$registerCountByIP = Cache::get(CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip())) ?? 0;
|
||||
if ((int)$registerCountByIP >= (int)config('v2board.register_limit_count', 3)) {
|
||||
abort(500, __('Register frequently, please try again after :minute minute', [
|
||||
'minute' => config('v2board.register_limit_expire', 60)
|
||||
]));
|
||||
}
|
||||
}
|
||||
if ((int)config('v2board.recaptcha_enable', 0)) {
|
||||
$recaptcha = new ReCaptcha(config('v2board.recaptcha_key'));
|
||||
$recaptchaResp = $recaptcha->verify($request->input('recaptcha_data'));
|
||||
if (!$recaptchaResp->isSuccess()) {
|
||||
abort(500, '验证码有误');
|
||||
abort(500, __('Invalid code is incorrect'));
|
||||
}
|
||||
}
|
||||
if ((int)config('v2board.email_whitelist_enable', 0)) {
|
||||
@ -32,36 +95,36 @@ class AuthController extends Controller
|
||||
$request->input('email'),
|
||||
config('v2board.email_whitelist_suffix', Dict::EMAIL_WHITELIST_SUFFIX_DEFAULT))
|
||||
) {
|
||||
abort(500, '邮箱后缀不处于白名单中');
|
||||
abort(500, __('Email suffix is not in the Whitelist'));
|
||||
}
|
||||
}
|
||||
if ((int)config('v2board.email_gmail_limit_enable', 0)) {
|
||||
$prefix = explode('@', $request->input('email'))[0];
|
||||
if (strpos($prefix, '.') !== false || strpos($prefix, '+') !== false) {
|
||||
abort(500, '不支持Gmail别名邮箱');
|
||||
abort(500, __('Gmail alias is not supported'));
|
||||
}
|
||||
}
|
||||
if ((int)config('v2board.stop_register', 0)) {
|
||||
abort(500, '本站已关闭注册');
|
||||
abort(500, __('Registration has closed'));
|
||||
}
|
||||
if ((int)config('v2board.invite_force', 0)) {
|
||||
if (empty($request->input('invite_code'))) {
|
||||
abort(500, '必须使用邀请码才可以注册');
|
||||
abort(500, __('You must use the invitation code to register'));
|
||||
}
|
||||
}
|
||||
if ((int)config('v2board.email_verify', 0)) {
|
||||
if (empty($request->input('email_code'))) {
|
||||
abort(500, '邮箱验证码不能为空');
|
||||
abort(500, __('Email verification code cannot be empty'));
|
||||
}
|
||||
if (Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email'))) !== $request->input('email_code')) {
|
||||
abort(500, '邮箱验证码有误');
|
||||
if ((string)Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email'))) !== (string)$request->input('email_code')) {
|
||||
abort(500, __('Incorrect email verification code'));
|
||||
}
|
||||
}
|
||||
$email = $request->input('email');
|
||||
$password = $request->input('password');
|
||||
$exist = User::where('email', $email)->first();
|
||||
if ($exist) {
|
||||
abort(500, '邮箱已存在系统中');
|
||||
abort(500, __('Email already exists'));
|
||||
}
|
||||
$user = new User();
|
||||
$user->email = $email;
|
||||
@ -74,7 +137,7 @@ class AuthController extends Controller
|
||||
->first();
|
||||
if (!$inviteCode) {
|
||||
if ((int)config('v2board.invite_force', 0)) {
|
||||
abort(500, '邀请码无效');
|
||||
abort(500, __('Invalid invitation code'));
|
||||
}
|
||||
} else {
|
||||
$user->invite_user_id = $inviteCode->user_id ? $inviteCode->user_id : null;
|
||||
@ -93,19 +156,32 @@ class AuthController extends Controller
|
||||
$user->plan_id = $plan->id;
|
||||
$user->group_id = $plan->group_id;
|
||||
$user->expired_at = time() + (config('v2board.try_out_hour', 1) * 3600);
|
||||
$user->speed_limit = $plan->speed_limit;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$user->save()) {
|
||||
abort(500, '注册失败');
|
||||
abort(500, __('Register failed'));
|
||||
}
|
||||
if ((int)config('v2board.email_verify', 0)) {
|
||||
Cache::forget(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email')));
|
||||
}
|
||||
$request->session()->put('email', $user->email);
|
||||
$request->session()->put('id', $user->id);
|
||||
|
||||
$user->last_login_at = time();
|
||||
$user->save();
|
||||
|
||||
if ((int)config('v2board.register_limit_by_ip_enable', 0)) {
|
||||
Cache::put(
|
||||
CacheKey::get('REGISTER_IP_RATE_LIMIT', $request->ip()),
|
||||
(int)$registerCountByIP + 1,
|
||||
(int)config('v2board.register_limit_expire', 60) * 60
|
||||
);
|
||||
}
|
||||
|
||||
$authService = new AuthService($user);
|
||||
|
||||
return response()->json([
|
||||
'data' => true
|
||||
'data' => $authService->generateAuthData($request)
|
||||
]);
|
||||
}
|
||||
|
||||
@ -114,37 +190,42 @@ class AuthController extends Controller
|
||||
$email = $request->input('email');
|
||||
$password = $request->input('password');
|
||||
|
||||
if ((int)config('v2board.password_limit_enable', 1)) {
|
||||
$passwordErrorCount = (int)Cache::get(CacheKey::get('PASSWORD_ERROR_LIMIT', $email), 0);
|
||||
if ($passwordErrorCount >= (int)config('v2board.password_limit_count', 5)) {
|
||||
abort(500, __('There are too many password errors, please try again after :minute minutes.', [
|
||||
'minute' => config('v2board.password_limit_expire', 60)
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
$user = User::where('email', $email)->first();
|
||||
if (!$user) {
|
||||
abort(500, '用户名或密码错误');
|
||||
abort(500, __('Incorrect email or password'));
|
||||
}
|
||||
if (!Helper::multiPasswordVerify(
|
||||
$user->password_algo,
|
||||
$user->password_salt,
|
||||
$password,
|
||||
$user->password)
|
||||
) {
|
||||
abort(500, '用户名或密码错误');
|
||||
if ((int)config('v2board.password_limit_enable')) {
|
||||
Cache::put(
|
||||
CacheKey::get('PASSWORD_ERROR_LIMIT', $email),
|
||||
(int)$passwordErrorCount + 1,
|
||||
60 * (int)config('v2board.password_limit_expire', 60)
|
||||
);
|
||||
}
|
||||
abort(500, __('Incorrect email or password'));
|
||||
}
|
||||
|
||||
if ($user->banned) {
|
||||
abort(500, '该账户已被停止使用');
|
||||
abort(500, __('Your account has been suspended'));
|
||||
}
|
||||
|
||||
$data = [
|
||||
'token' => $user->token
|
||||
];
|
||||
$request->session()->put('email', $user->email);
|
||||
$request->session()->put('id', $user->id);
|
||||
if ($user->is_admin) {
|
||||
$request->session()->put('is_admin', true);
|
||||
$data['is_admin'] = true;
|
||||
}
|
||||
if ($user->is_staff) {
|
||||
$request->session()->put('is_staff', true);
|
||||
$data['is_staff'] = true;
|
||||
}
|
||||
$authService = new AuthService($user);
|
||||
return response([
|
||||
'data' => $data
|
||||
'data' => $authService->generateAuthData($request)
|
||||
]);
|
||||
}
|
||||
|
||||
@ -164,52 +245,34 @@ class AuthController extends Controller
|
||||
$key = CacheKey::get('TEMP_TOKEN', $request->input('verify'));
|
||||
$userId = Cache::get($key);
|
||||
if (!$userId) {
|
||||
abort(500, '令牌有误');
|
||||
abort(500, __('Token error'));
|
||||
}
|
||||
$user = User::find($userId);
|
||||
if (!$user) {
|
||||
abort(500, '用户不存在');
|
||||
abort(500, __('The user does not '));
|
||||
}
|
||||
if ($user->banned) {
|
||||
abort(500, '该账户已被停止使用');
|
||||
}
|
||||
$request->session()->put('email', $user->email);
|
||||
$request->session()->put('id', $user->id);
|
||||
if ($user->is_admin) {
|
||||
$request->session()->put('is_admin', true);
|
||||
abort(500, __('Your account has been suspended'));
|
||||
}
|
||||
Cache::forget($key);
|
||||
$authService = new AuthService($user);
|
||||
return response([
|
||||
'data' => true
|
||||
'data' => $authService->generateAuthData($request)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getTempToken(Request $request)
|
||||
{
|
||||
$user = User::where('token', $request->input('token'))->first();
|
||||
if (!$user) {
|
||||
abort(500, '令牌有误');
|
||||
}
|
||||
|
||||
$code = Helper::guid();
|
||||
$key = CacheKey::get('TEMP_TOKEN', $code);
|
||||
Cache::put($key, $user->id, 60);
|
||||
return response([
|
||||
'data' => $code
|
||||
]);
|
||||
}
|
||||
|
||||
public function getQuickLoginUrl(Request $request)
|
||||
{
|
||||
$user = User::where('token', $request->input('token'))->first();
|
||||
if (!$user) {
|
||||
abort(500, '令牌有误');
|
||||
}
|
||||
$authorization = $request->input('auth_data') ?? $request->header('authorization');
|
||||
if (!$authorization) abort(403, '未登录或登陆已过期');
|
||||
|
||||
$user = AuthService::decryptAuthData($authorization);
|
||||
if (!$user) abort(403, '未登录或登陆已过期');
|
||||
|
||||
$code = Helper::guid();
|
||||
$key = CacheKey::get('TEMP_TOKEN', $code);
|
||||
Cache::put($key, $user->id, 60);
|
||||
Cache::put($key, $user['id'], 60);
|
||||
$redirect = '/#/login?verify=' . $code . '&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard');
|
||||
if (config('v2board.app_url')) {
|
||||
$url = config('v2board.app_url') . $redirect;
|
||||
@ -221,37 +284,28 @@ class AuthController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function check(Request $request)
|
||||
{
|
||||
$data = [
|
||||
'is_login' => $request->session()->get('id') ? true : false
|
||||
];
|
||||
if ($request->session()->get('is_admin')) {
|
||||
$data['is_admin'] = true;
|
||||
}
|
||||
return response([
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public function forget(AuthForget $request)
|
||||
{
|
||||
if (Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email'))) !== $request->input('email_code')) {
|
||||
abort(500, '邮箱验证码有误');
|
||||
$forgetRequestLimitKey = CacheKey::get('FORGET_REQUEST_LIMIT', $request->input('email'));
|
||||
$forgetRequestLimit = (int)Cache::get($forgetRequestLimitKey);
|
||||
if ($forgetRequestLimit >= 3) abort(500, __('Reset failed, Please try again later'));
|
||||
if ((string)Cache::get(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email'))) !== (string)$request->input('email_code')) {
|
||||
Cache::put($forgetRequestLimitKey, $forgetRequestLimit ? $forgetRequestLimit + 1 : 1, 300);
|
||||
abort(500, __('Incorrect email verification code'));
|
||||
}
|
||||
$user = User::where('email', $request->input('email'))->first();
|
||||
if (!$user) {
|
||||
abort(500, '该邮箱不存在系统中');
|
||||
abort(500, __('This email is not registered in the system'));
|
||||
}
|
||||
$user->password = password_hash($request->input('password'), PASSWORD_DEFAULT);
|
||||
$user->password_algo = NULL;
|
||||
$user->password_salt = NULL;
|
||||
if (!$user->save()) {
|
||||
abort(500, '重置失败');
|
||||
abort(500, __('Reset failed'));
|
||||
}
|
||||
Cache::forget(CacheKey::get('EMAIL_VERIFY_CODE', $request->input('email')));
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Passport;
|
||||
namespace App\Http\Controllers\V1\Passport;
|
||||
|
||||
use App\Http\Requests\Passport\CommSendEmailVerify;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use App\Http\Requests\Passport\CommSendEmailVerify;
|
||||
use App\Jobs\SendEmailJob;
|
||||
use App\Models\InviteCode;
|
||||
use App\Utils\Dict;
|
||||
use App\Models\User;
|
||||
use App\Utils\CacheKey;
|
||||
use App\Utils\Dict;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use ReCaptcha\ReCaptcha;
|
||||
|
||||
class CommController extends Controller
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return response([
|
||||
'data' => [
|
||||
'isEmailVerify' => (int)config('v2board.email_verify', 0) ? 1 : 0,
|
||||
'isInviteForce' => (int)config('v2board.invite_force', 0) ? 1 : 0,
|
||||
'emailWhitelistSuffix' => (int)config('v2board.email_whitelist_enable', 0)
|
||||
? $this->getEmailSuffix()
|
||||
: 0,
|
||||
'isRecaptcha' => (int)config('v2board.recaptcha_enable', 0) ? 1 : 0,
|
||||
'recaptchaSiteKey' => config('v2board.recaptcha_site_key'),
|
||||
'appDescription' => config('v2board.app_description'),
|
||||
'appUrl' => config('v2board.app_url')
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
private function isEmailVerify()
|
||||
{
|
||||
return response([
|
||||
@ -47,15 +30,15 @@ class CommController extends Controller
|
||||
$recaptcha = new ReCaptcha(config('v2board.recaptcha_key'));
|
||||
$recaptchaResp = $recaptcha->verify($request->input('recaptcha_data'));
|
||||
if (!$recaptchaResp->isSuccess()) {
|
||||
abort(500, '验证码有误');
|
||||
abort(500, __('Invalid code is incorrect'));
|
||||
}
|
||||
}
|
||||
$email = $request->input('email');
|
||||
if (Cache::get(CacheKey::get('LAST_SEND_EMAIL_VERIFY_TIMESTAMP', $email))) {
|
||||
abort(500, '验证码已发送,请过一会再请求');
|
||||
abort(500, __('Email verification code has been sent, please request again later'));
|
||||
}
|
||||
$code = rand(100000, 999999);
|
||||
$subject = config('v2board.app_name', 'V2Board') . '邮箱验证码';
|
||||
$subject = config('v2board.app_name', 'V2Board') . __('Email verification code');
|
||||
|
||||
SendEmailJob::dispatch([
|
||||
'email' => $email,
|
232
app/Http/Controllers/V1/Server/DeepbworkController.php
Normal file
232
app/Http/Controllers/V1/Server/DeepbworkController.php
Normal file
@ -0,0 +1,232 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Server;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerVmess;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/*
|
||||
* V2ray Aurora
|
||||
* Github: https://github.com/tokumeikoi/aurora
|
||||
*/
|
||||
class DeepbworkController extends Controller
|
||||
{
|
||||
CONST V2RAY_CONFIG = '{"log":{"loglevel":"debug","access":"access.log","error":"error.log"},"api":{"services":["HandlerService","StatsService"],"tag":"api"},"dns":{},"stats":{},"inbounds":[{"port":443,"protocol":"vmess","settings":{"clients":[]},"sniffing":{"enabled":true,"destOverride":["http","tls"]},"streamSettings":{"network":"tcp"},"tag":"proxy"},{"listen":"127.0.0.1","port":23333,"protocol":"dokodemo-door","settings":{"address":"0.0.0.0"},"tag":"api"}],"outbounds":[{"protocol":"freedom","settings":{}},{"protocol":"blackhole","settings":{},"tag":"block"}],"routing":{"rules":[{"type":"field","inboundTag":"api","outboundTag":"api"}]},"policy":{"levels":{"0":{"handshake":4,"connIdle":300,"uplinkOnly":5,"downlinkOnly":30,"statsUserUplink":true,"statsUserDownlink":true}}}}';
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
abort(500, 'token is null');
|
||||
}
|
||||
if ($token !== config('v2board.server_token')) {
|
||||
abort(500, 'token is error');
|
||||
}
|
||||
}
|
||||
|
||||
// 后端获取用户
|
||||
public function user(Request $request)
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = ServerVmess::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_VMESS_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
$users = $serverService->getAvailableUsers($server->group_id);
|
||||
$result = [];
|
||||
foreach ($users as $user) {
|
||||
$user->v2ray_user = [
|
||||
"uuid" => $user->uuid,
|
||||
"email" => sprintf("%s@v2board.user", $user->uuid),
|
||||
"alter_id" => 0,
|
||||
"level" => 0,
|
||||
];
|
||||
unset($user['uuid']);
|
||||
array_push($result, $user);
|
||||
}
|
||||
$eTag = sha1(json_encode($result));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
}
|
||||
return response([
|
||||
'msg' => 'ok',
|
||||
'data' => $result,
|
||||
])->header('ETag', "\"{$eTag}\"");
|
||||
}
|
||||
|
||||
// 后端提交数据
|
||||
public function submit(Request $request)
|
||||
{
|
||||
// Log::info('serverSubmitData:' . $request->input('node_id') . ':' . file_get_contents('php://input'));
|
||||
$server = ServerVmess::find($request->input('node_id'));
|
||||
if (!$server) {
|
||||
return response([
|
||||
'ret' => 0,
|
||||
'msg' => 'server is not found'
|
||||
]);
|
||||
}
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
Cache::put(CacheKey::get('SERVER_VMESS_ONLINE_USER', $server->id), count($data), 3600);
|
||||
Cache::put(CacheKey::get('SERVER_VMESS_LAST_PUSH_AT', $server->id), time(), 3600);
|
||||
$userService = new UserService();
|
||||
$formatData = [];
|
||||
|
||||
foreach ($data as $item) {
|
||||
$formatData[$item['user_id']] = [$item['u'], $item['d']];
|
||||
}
|
||||
$userService->trafficFetch($server->toArray(), 'vmess', $formatData);
|
||||
|
||||
return response([
|
||||
'ret' => 1,
|
||||
'msg' => 'ok'
|
||||
]);
|
||||
}
|
||||
|
||||
// 后端获取配置
|
||||
public function config(Request $request)
|
||||
{
|
||||
$nodeId = $request->input('node_id');
|
||||
$localPort = $request->input('local_port');
|
||||
if (empty($nodeId) || empty($localPort)) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
try {
|
||||
$json = $this->getV2RayConfig($nodeId, $localPort);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
|
||||
die(json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
private function getV2RayConfig(int $nodeId, int $localPort)
|
||||
{
|
||||
$server = ServerVmess::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, '节点不存在');
|
||||
}
|
||||
$json = json_decode(self::V2RAY_CONFIG);
|
||||
$json->log->loglevel = (int)config('v2board.server_log_enable') ? 'debug' : 'none';
|
||||
$json->inbounds[1]->port = (int)$localPort;
|
||||
$json->inbounds[0]->port = (int)$server->server_port;
|
||||
$json->inbounds[0]->streamSettings->network = $server->network;
|
||||
$this->setDns($server, $json);
|
||||
$this->setNetwork($server, $json);
|
||||
$this->setRule($server, $json);
|
||||
$this->setTls($server, $json);
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
private function setDns(ServerVmess $server, object $json)
|
||||
{
|
||||
if ($server->dnsSettings) {
|
||||
$dns = $server->dnsSettings;
|
||||
if (isset($dns->servers)) {
|
||||
array_push($dns->servers, '1.1.1.1');
|
||||
array_push($dns->servers, 'localhost');
|
||||
}
|
||||
$json->dns = $dns;
|
||||
$json->outbounds[0]->settings->domainStrategy = 'UseIP';
|
||||
}
|
||||
}
|
||||
|
||||
private function setNetwork(ServerVmess $server, object $json)
|
||||
{
|
||||
if ($server->networkSettings) {
|
||||
switch ($server->network) {
|
||||
case 'tcp':
|
||||
$json->inbounds[0]->streamSettings->tcpSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'kcp':
|
||||
$json->inbounds[0]->streamSettings->kcpSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'ws':
|
||||
$json->inbounds[0]->streamSettings->wsSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'http':
|
||||
$json->inbounds[0]->streamSettings->httpSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'domainsocket':
|
||||
$json->inbounds[0]->streamSettings->dsSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'quic':
|
||||
$json->inbounds[0]->streamSettings->quicSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'grpc':
|
||||
$json->inbounds[0]->streamSettings->grpcSettings = $server->networkSettings;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function setRule(ServerVmess $server, object $json)
|
||||
{
|
||||
$domainRules = array_filter(explode(PHP_EOL, config('v2board.server_v2ray_domain')));
|
||||
$protocolRules = array_filter(explode(PHP_EOL, config('v2board.server_v2ray_protocol')));
|
||||
if ($server->ruleSettings) {
|
||||
$ruleSettings = $server->ruleSettings;
|
||||
// domain
|
||||
if (isset($ruleSettings->domain)) {
|
||||
$ruleSettings->domain = array_filter($ruleSettings->domain);
|
||||
if (!empty($ruleSettings->domain)) {
|
||||
$domainRules = array_merge($domainRules, $ruleSettings->domain);
|
||||
}
|
||||
}
|
||||
// protocol
|
||||
if (isset($ruleSettings->protocol)) {
|
||||
$ruleSettings->protocol = array_filter($ruleSettings->protocol);
|
||||
if (!empty($ruleSettings->protocol)) {
|
||||
$protocolRules = array_merge($protocolRules, $ruleSettings->protocol);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($domainRules)) {
|
||||
$domainObj = new \StdClass();
|
||||
$domainObj->type = 'field';
|
||||
$domainObj->domain = $domainRules;
|
||||
$domainObj->outboundTag = 'block';
|
||||
array_push($json->routing->rules, $domainObj);
|
||||
}
|
||||
if (!empty($protocolRules)) {
|
||||
$protocolObj = new \StdClass();
|
||||
$protocolObj->type = 'field';
|
||||
$protocolObj->protocol = $protocolRules;
|
||||
$protocolObj->outboundTag = 'block';
|
||||
array_push($json->routing->rules, $protocolObj);
|
||||
}
|
||||
if (empty($domainRules) && empty($protocolRules)) {
|
||||
$json->inbounds[0]->sniffing->enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private function setTls(ServerVMess $server, object $json)
|
||||
{
|
||||
if ((int)$server->tls) {
|
||||
$tlsSettings = $server->tlsSettings;
|
||||
$json->inbounds[0]->streamSettings->security = 'tls';
|
||||
$tls = (object)[
|
||||
'certificateFile' => '/root/.cert/server.crt',
|
||||
'keyFile' => '/root/.cert/server.key'
|
||||
];
|
||||
$json->inbounds[0]->streamSettings->tlsSettings = new \StdClass();
|
||||
if (isset($tlsSettings->serverName)) {
|
||||
$json->inbounds[0]->streamSettings->tlsSettings->serverName = (string)$tlsSettings->serverName;
|
||||
}
|
||||
if (isset($tlsSettings->allowInsecure)) {
|
||||
$json->inbounds[0]->streamSettings->tlsSettings->allowInsecure = (int)$tlsSettings->allowInsecure ? true : false;
|
||||
}
|
||||
$json->inbounds[0]->streamSettings->tlsSettings->certificates[0] = $tls;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Server;
|
||||
namespace App\Http\Controllers\V1\Server;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\ServerLog;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/*
|
||||
@ -34,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) {
|
||||
@ -41,7 +38,7 @@ class ShadowsocksTidalabController extends Controller
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_SHADOWSOCKS_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
$users = $serverService->getAvailableUsers(json_decode($server->group_id));
|
||||
$users = $serverService->getAvailableUsers($server->group_id);
|
||||
$result = [];
|
||||
foreach ($users as $user) {
|
||||
array_push($result, [
|
||||
@ -51,9 +48,13 @@ class ShadowsocksTidalabController extends Controller
|
||||
'secret' => $user->uuid
|
||||
]);
|
||||
}
|
||||
$eTag = sha1(json_encode($result));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
}
|
||||
return response([
|
||||
'data' => $result
|
||||
]);
|
||||
])->header('ETag', "\"{$eTag}\"");
|
||||
}
|
||||
|
||||
// 后端提交数据
|
||||
@ -70,24 +71,14 @@ class ShadowsocksTidalabController extends Controller
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
Cache::put(CacheKey::get('SERVER_SHADOWSOCKS_ONLINE_USER', $server->id), count($data), 3600);
|
||||
Cache::put(CacheKey::get('SERVER_SHADOWSOCKS_LAST_PUSH_AT', $server->id), time(), 3600);
|
||||
$userService = new UserService();
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
foreach ($data as $item) {
|
||||
$u = $item['u'] * $server->rate;
|
||||
$d = $item['d'] * $server->rate;
|
||||
if (!$userService->trafficFetch((float)$u, (float)$d, (int)$item['user_id'], $server, 'shadowsocks')) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response([
|
||||
'ret' => 0,
|
||||
'msg' => 'user fetch fail'
|
||||
]);
|
||||
$formatData = [];
|
||||
|
||||
foreach ($data as $item) {
|
||||
$formatData[$item['user_id']] = [$item['u'], $item['d']];
|
||||
}
|
||||
DB::commit();
|
||||
$userService->trafficFetch($server->toArray(), 'shadowsocks', $formatData);
|
||||
|
||||
return response([
|
||||
'ret' => 1,
|
@ -1,18 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Server;
|
||||
namespace App\Http\Controllers\V1\Server;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerTrojan;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\ServerTrojan;
|
||||
use App\Models\ServerLog;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/*
|
||||
* Tidal Lab Trojan
|
||||
@ -20,6 +18,7 @@ use Illuminate\Support\Facades\Cache;
|
||||
*/
|
||||
class TrojanTidalabController extends Controller
|
||||
{
|
||||
CONST TROJAN_CONFIG = '{"run_type":"server","local_addr":"0.0.0.0","local_port":443,"remote_addr":"www.taobao.com","remote_port":80,"password":[],"ssl":{"cert":"server.crt","key":"server.key","sni":"domain.com"},"api":{"enabled":true,"api_addr":"127.0.0.1","api_port":10000}}';
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$token = $request->input('token');
|
||||
@ -34,6 +33,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) {
|
||||
@ -41,20 +41,23 @@ class TrojanTidalabController extends Controller
|
||||
}
|
||||
Cache::put(CacheKey::get('SERVER_TROJAN_LAST_CHECK_AT', $server->id), time(), 3600);
|
||||
$serverService = new ServerService();
|
||||
$users = $serverService->getAvailableUsers(json_decode($server->group_id));
|
||||
$users = $serverService->getAvailableUsers($server->group_id);
|
||||
$result = [];
|
||||
foreach ($users as $user) {
|
||||
$user->trojan_user = [
|
||||
"password" => $user->uuid,
|
||||
];
|
||||
unset($user['uuid']);
|
||||
unset($user['email']);
|
||||
array_push($result, $user);
|
||||
}
|
||||
$eTag = sha1(json_encode($result));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
}
|
||||
return response([
|
||||
'msg' => 'ok',
|
||||
'data' => $result,
|
||||
]);
|
||||
])->header('ETag', "\"{$eTag}\"");
|
||||
}
|
||||
|
||||
// 后端提交数据
|
||||
@ -71,24 +74,13 @@ class TrojanTidalabController extends Controller
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
Cache::put(CacheKey::get('SERVER_TROJAN_ONLINE_USER', $server->id), count($data), 3600);
|
||||
Cache::put(CacheKey::get('SERVER_TROJAN_LAST_PUSH_AT', $server->id), time(), 3600);
|
||||
$userService = new UserService();
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
foreach ($data as $item) {
|
||||
$u = $item['u'] * $server->rate;
|
||||
$d = $item['d'] * $server->rate;
|
||||
if (!$userService->trafficFetch($u, $d, $item['user_id'], $server, 'trojan')) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response([
|
||||
'ret' => 0,
|
||||
'msg' => 'user fetch fail'
|
||||
]);
|
||||
$formatData = [];
|
||||
foreach ($data as $item) {
|
||||
$formatData[$item['user_id']] = [$item['u'], $item['d']];
|
||||
}
|
||||
DB::commit();
|
||||
$userService->trafficFetch($server->toArray(), 'trojan', $formatData);
|
||||
|
||||
return response([
|
||||
'ret' => 1,
|
||||
@ -104,13 +96,28 @@ class TrojanTidalabController extends Controller
|
||||
if (empty($nodeId) || empty($localPort)) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$serverService = new ServerService();
|
||||
try {
|
||||
$json = $serverService->getTrojanConfig($nodeId, $localPort);
|
||||
$json = $this->getTrojanConfig($nodeId, $localPort);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
|
||||
die(json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
|
||||
private function getTrojanConfig(int $nodeId, int $localPort)
|
||||
{
|
||||
$server = ServerTrojan::find($nodeId);
|
||||
if (!$server) {
|
||||
abort(500, '节点不存在');
|
||||
}
|
||||
|
||||
$json = json_decode(self::TROJAN_CONFIG);
|
||||
$json->local_port = $server->server_port;
|
||||
$json->ssl->sni = $server->server_name ? $server->server_name : $server->host;
|
||||
$json->ssl->cert = "/root/.cert/server.crt";
|
||||
$json->ssl->key = "/root/.cert/server.key";
|
||||
$json->api->api_port = $localPort;
|
||||
return $json;
|
||||
}
|
||||
}
|
141
app/Http/Controllers/V1/Server/UniProxyController.php
Normal file
141
app/Http/Controllers/V1/Server/UniProxyController.php
Normal file
@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\Server;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class UniProxyController extends Controller
|
||||
{
|
||||
private $nodeType;
|
||||
private $nodeInfo;
|
||||
private $nodeId;
|
||||
private $serverService;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$token = $request->input('token');
|
||||
if (empty($token)) {
|
||||
abort(500, 'token is null');
|
||||
}
|
||||
if ($token !== config('v2board.server_token')) {
|
||||
abort(500, 'token is error');
|
||||
}
|
||||
$this->nodeType = $request->input('node_type');
|
||||
if ($this->nodeType === 'v2ray') $this->nodeType = 'vmess';
|
||||
$this->nodeId = $request->input('node_id');
|
||||
$this->serverService = new ServerService();
|
||||
$this->nodeInfo = $this->serverService->getServer($this->nodeId, $this->nodeType);
|
||||
if (!$this->nodeInfo) abort(500, 'server is not exist');
|
||||
}
|
||||
|
||||
// 后端获取用户
|
||||
public function user(Request $request)
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
Cache::put(CacheKey::get('SERVER_' . strtoupper($this->nodeType) . '_LAST_CHECK_AT', $this->nodeInfo->id), time(), 3600);
|
||||
$users = $this->serverService->getAvailableUsers($this->nodeInfo->group_id);
|
||||
$users = $users->toArray();
|
||||
|
||||
$response['users'] = $users;
|
||||
|
||||
$eTag = sha1(json_encode($response));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
}
|
||||
|
||||
return response($response)->header('ETag', "\"{$eTag}\"");
|
||||
}
|
||||
|
||||
// 后端提交数据
|
||||
public function push(Request $request)
|
||||
{
|
||||
$data = file_get_contents('php://input');
|
||||
$data = json_decode($data, true);
|
||||
Cache::put(CacheKey::get('SERVER_' . strtoupper($this->nodeType) . '_ONLINE_USER', $this->nodeInfo->id), count($data), 3600);
|
||||
Cache::put(CacheKey::get('SERVER_' . strtoupper($this->nodeType) . '_LAST_PUSH_AT', $this->nodeInfo->id), time(), 3600);
|
||||
$userService = new UserService();
|
||||
$userService->trafficFetch($this->nodeInfo->toArray(), $this->nodeType, $data);
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
// 后端获取配置
|
||||
public function config(Request $request)
|
||||
{
|
||||
switch ($this->nodeType) {
|
||||
case 'shadowsocks':
|
||||
$response = [
|
||||
'server_port' => $this->nodeInfo->server_port,
|
||||
'cipher' => $this->nodeInfo->cipher,
|
||||
'obfs' => $this->nodeInfo->obfs,
|
||||
'obfs_settings' => $this->nodeInfo->obfs_settings
|
||||
];
|
||||
|
||||
if ($this->nodeInfo->cipher === '2022-blake3-aes-128-gcm') {
|
||||
$response['server_key'] = Helper::getServerKey($this->nodeInfo->created_at, 16);
|
||||
}
|
||||
if ($this->nodeInfo->cipher === '2022-blake3-aes-256-gcm') {
|
||||
$response['server_key'] = Helper::getServerKey($this->nodeInfo->created_at, 32);
|
||||
}
|
||||
break;
|
||||
case 'vmess':
|
||||
$response = [
|
||||
'server_port' => $this->nodeInfo->server_port,
|
||||
'network' => $this->nodeInfo->network,
|
||||
'networkSettings' => $this->nodeInfo->networkSettings,
|
||||
'tls' => $this->nodeInfo->tls
|
||||
];
|
||||
break;
|
||||
case 'trojan':
|
||||
$response = [
|
||||
'host' => $this->nodeInfo->host,
|
||||
'server_port' => $this->nodeInfo->server_port,
|
||||
'server_name' => $this->nodeInfo->server_name,
|
||||
];
|
||||
break;
|
||||
case 'hysteria':
|
||||
$response = [
|
||||
'host' => $this->nodeInfo->host,
|
||||
'server_port' => $this->nodeInfo->server_port,
|
||||
'server_name' => $this->nodeInfo->server_name,
|
||||
'up_mbps' => $this->nodeInfo->up_mbps,
|
||||
'down_mbps' => $this->nodeInfo->down_mbps,
|
||||
'obfs' => Helper::getServerKey($this->nodeInfo->created_at, 16),
|
||||
'obfs_type' => $this->nodeInfo->obfs_type,
|
||||
'ignore_client_bandwidth' => !!$this->nodeInfo->ignore_client_bandwidth
|
||||
];
|
||||
break;
|
||||
case "vless":
|
||||
$response = [
|
||||
'server_port' => $this->nodeInfo->server_port,
|
||||
'network' => $this->nodeInfo->network,
|
||||
'network_settings' => $this->nodeInfo->network_settings,
|
||||
'tls' => $this->nodeInfo->tls,
|
||||
'flow' => $this->nodeInfo->flow,
|
||||
'tls_settings' => $this->nodeInfo->tls_settings
|
||||
];
|
||||
break;
|
||||
}
|
||||
$response['base_config'] = [
|
||||
'push_interval' => (int)config('v2board.server_push_interval', 60),
|
||||
'pull_interval' => (int)config('v2board.server_pull_interval', 60)
|
||||
];
|
||||
if ($this->nodeInfo['route_id']) {
|
||||
$response['routes'] = $this->serverService->getRoutes($this->nodeInfo['route_id']);
|
||||
}
|
||||
$eTag = sha1(json_encode($response));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
}
|
||||
|
||||
return response($response)->header('ETag', "\"{$eTag}\"");
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
namespace App\Http\Controllers\V1\Staff;
|
||||
|
||||
use App\Http\Requests\Admin\NoticeSave;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\NoticeSave;
|
||||
use App\Models\Notice;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class NoticeController extends Controller
|
@ -1,15 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Staff;
|
||||
namespace App\Http\Controllers\V1\Staff;
|
||||
|
||||
use App\Http\Requests\Admin\PlanSave;
|
||||
use App\Http\Requests\Admin\PlanSort;
|
||||
use App\Http\Requests\Admin\PlanUpdate;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PlanController extends Controller
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Staff;
|
||||
namespace App\Http\Controllers\V1\Staff;
|
||||
|
||||
use App\Services\TicketService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketMessage;
|
||||
use App\Services\TicketService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TicketController extends Controller
|
||||
{
|
||||
@ -39,13 +39,6 @@ class TicketController extends Controller
|
||||
$total = $model->count();
|
||||
$res = $model->forPage($current, $pageSize)
|
||||
->get();
|
||||
for ($i = 0; $i < count($res); $i++) {
|
||||
if ($res[$i]['last_reply_user_id'] == $request->session()->get('id')) {
|
||||
$res[$i]['reply_status'] = 0;
|
||||
} else {
|
||||
$res[$i]['reply_status'] = 1;
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $res,
|
||||
'total' => $total
|
||||
@ -64,7 +57,7 @@ class TicketController extends Controller
|
||||
$ticketService->replyByAdmin(
|
||||
$request->input('id'),
|
||||
$request->input('message'),
|
||||
$request->session()->get('id')
|
||||
$request->user['id']
|
||||
);
|
||||
return response([
|
||||
'data' => true
|
@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Staff;
|
||||
namespace App\Http\Controllers\V1\Staff;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\UserSendMail;
|
||||
use App\Http\Requests\Staff\UserUpdate;
|
||||
use App\Jobs\SendEmailJob;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
@ -17,8 +17,13 @@ class UserController extends Controller
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
}
|
||||
$user = User::where('is_admin', 0)
|
||||
->where('id', $request->input('id'))
|
||||
->where('is_staff', 0)
|
||||
->first();
|
||||
if (!$user) abort(500, '用户不存在');
|
||||
return response([
|
||||
'data' => User::find($request->input('id'))
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
41
app/Http/Controllers/V1/User/CommController.php
Normal file
41
app/Http/Controllers/V1/User/CommController.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Payment;
|
||||
use App\Utils\Dict;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CommController extends Controller
|
||||
{
|
||||
public function config()
|
||||
{
|
||||
return response([
|
||||
'data' => [
|
||||
'is_telegram' => (int)config('v2board.telegram_bot_enable', 0),
|
||||
'telegram_discuss_link' => config('v2board.telegram_discuss_link'),
|
||||
'stripe_pk' => config('v2board.stripe_pk_live'),
|
||||
'withdraw_methods' => config('v2board.commission_withdraw_method', Dict::WITHDRAW_METHOD_WHITELIST_DEFAULT),
|
||||
'withdraw_close' => (int)config('v2board.withdraw_close_enable', 0),
|
||||
'currency' => config('v2board.currency', 'CNY'),
|
||||
'currency_symbol' => config('v2board.currency_symbol', '¥'),
|
||||
'commission_distribution_enable' => (int)config('v2board.commission_distribution_enable', 0),
|
||||
'commission_distribution_l1' => config('v2board.commission_distribution_l1'),
|
||||
'commission_distribution_l2' => config('v2board.commission_distribution_l2'),
|
||||
'commission_distribution_l3' => config('v2board.commission_distribution_l3')
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function getStripePublicKey(Request $request)
|
||||
{
|
||||
$payment = Payment::where('id', $request->input('id'))
|
||||
->where('payment', 'StripeCredit')
|
||||
->first();
|
||||
if (!$payment) abort(500, 'payment is not found');
|
||||
return response([
|
||||
'data' => $payment->config['stripe_pk_live']
|
||||
]);
|
||||
}
|
||||
}
|
24
app/Http/Controllers/V1/User/CouponController.php
Normal file
24
app/Http/Controllers/V1/User/CouponController.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\CouponService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CouponController extends Controller
|
||||
{
|
||||
public function check(Request $request)
|
||||
{
|
||||
if (empty($request->input('code'))) {
|
||||
abort(500, __('Coupon cannot be empty'));
|
||||
}
|
||||
$couponService = new CouponService($request->input('code'));
|
||||
$couponService->setPlanId($request->input('plan_id'));
|
||||
$couponService->setUserId($request->user['id']);
|
||||
$couponService->check();
|
||||
return response([
|
||||
'data' => $couponService->getCoupon()
|
||||
]);
|
||||
}
|
||||
}
|
88
app/Http/Controllers/V1/User/InviteController.php
Normal file
88
app/Http/Controllers/V1/User/InviteController.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CommissionLog;
|
||||
use App\Models\InviteCode;
|
||||
use App\Models\Order;
|
||||
use App\Models\User;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class InviteController extends Controller
|
||||
{
|
||||
public function save(Request $request)
|
||||
{
|
||||
if (InviteCode::where('user_id', $request->user['id'])->where('status', 0)->count() >= config('v2board.invite_gen_limit', 5)) {
|
||||
abort(500, __('The maximum number of creations has been reached'));
|
||||
}
|
||||
$inviteCode = new InviteCode();
|
||||
$inviteCode->user_id = $request->user['id'];
|
||||
$inviteCode->code = Helper::randomChar(8);
|
||||
return response([
|
||||
'data' => $inviteCode->save()
|
||||
]);
|
||||
}
|
||||
|
||||
public function details(Request $request)
|
||||
{
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('page_size') >= 10 ? $request->input('page_size') : 10;
|
||||
$builder = CommissionLog::where('invite_user_id', $request->user['id'])
|
||||
->where('get_amount', '>', 0)
|
||||
->select([
|
||||
'id',
|
||||
'trade_no',
|
||||
'order_amount',
|
||||
'get_amount',
|
||||
'created_at'
|
||||
])
|
||||
->orderBy('created_at', 'DESC');
|
||||
$total = $builder->count();
|
||||
$details = $builder->forPage($current, $pageSize)
|
||||
->get();
|
||||
return response([
|
||||
'data' => $details,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$codes = InviteCode::where('user_id', $request->user['id'])
|
||||
->where('status', 0)
|
||||
->get();
|
||||
$commission_rate = config('v2board.invite_commission', 10);
|
||||
$user = User::find($request->user['id']);
|
||||
if ($user->commission_rate) {
|
||||
$commission_rate = $user->commission_rate;
|
||||
}
|
||||
$uncheck_commission_balance = (int)Order::where('status', 3)
|
||||
->where('commission_status', 0)
|
||||
->where('invite_user_id', $request->user['id'])
|
||||
->sum('commission_balance');
|
||||
if (config('v2board.commission_distribution_enable', 0)) {
|
||||
$uncheck_commission_balance = $uncheck_commission_balance * (config('v2board.commission_distribution_l1') / 100);
|
||||
}
|
||||
$stat = [
|
||||
//已注册用户数
|
||||
(int)User::where('invite_user_id', $request->user['id'])->count(),
|
||||
//有效的佣金
|
||||
(int)CommissionLog::where('invite_user_id', $request->user['id'])
|
||||
->sum('get_amount'),
|
||||
//确认中的佣金
|
||||
$uncheck_commission_balance,
|
||||
//佣金比例
|
||||
(int)$commission_rate,
|
||||
//可用佣金
|
||||
(int)$user->commission_balance
|
||||
];
|
||||
return response([
|
||||
'data' => [
|
||||
'codes' => $codes,
|
||||
'stat' => $stat
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
73
app/Http/Controllers/V1/User/KnowledgeController.php
Normal file
73
app/Http/Controllers/V1/User/KnowledgeController.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Knowledge;
|
||||
use App\Models\User;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class KnowledgeController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$knowledge = Knowledge::where('id', $request->input('id'))
|
||||
->where('show', 1)
|
||||
->first()
|
||||
->toArray();
|
||||
if (!$knowledge) abort(500, __('Article does not exist'));
|
||||
$user = User::find($request->user['id']);
|
||||
$userService = new UserService();
|
||||
if (!$userService->isAvailable($user)) {
|
||||
$this->formatAccessData($knowledge['body']);
|
||||
}
|
||||
$subscribeUrl = Helper::getSubscribeUrl($user['token']);
|
||||
$knowledge['body'] = str_replace('{{siteName}}', config('v2board.app_name', 'V2Board'), $knowledge['body']);
|
||||
$knowledge['body'] = str_replace('{{subscribeUrl}}', $subscribeUrl, $knowledge['body']);
|
||||
$knowledge['body'] = str_replace('{{urlEncodeSubscribeUrl}}', urlencode($subscribeUrl), $knowledge['body']);
|
||||
$knowledge['body'] = str_replace(
|
||||
'{{safeBase64SubscribeUrl}}',
|
||||
str_replace(
|
||||
array('+', '/', '='),
|
||||
array('-', '_', ''),
|
||||
base64_encode($subscribeUrl)
|
||||
),
|
||||
$knowledge['body']
|
||||
);
|
||||
return response([
|
||||
'data' => $knowledge
|
||||
]);
|
||||
}
|
||||
$builder = Knowledge::select(['id', 'category', 'title', 'updated_at'])
|
||||
->where('language', $request->input('language'))
|
||||
->where('show', 1)
|
||||
->orderBy('sort', 'ASC');
|
||||
$keyword = $request->input('keyword');
|
||||
if ($keyword) {
|
||||
$builder = $builder->where(function ($query) use ($keyword) {
|
||||
$query->where('title', 'LIKE', "%{$keyword}%")
|
||||
->orWhere('body', 'LIKE', "%{$keyword}%");
|
||||
});
|
||||
}
|
||||
|
||||
$knowledges = $builder->get()
|
||||
->groupBy('category');
|
||||
return response([
|
||||
'data' => $knowledges
|
||||
]);
|
||||
}
|
||||
|
||||
private function formatAccessData(&$body)
|
||||
{
|
||||
function getBetween($input, $start, $end){$substr = substr($input, strlen($start)+strpos($input, $start),(strlen($input) - strpos($input, $end))*(-1));return $start . $substr . $end;}
|
||||
while (strpos($body, '<!--access start-->') !== false) {
|
||||
$accessData = getBetween($body, '<!--access start-->', '<!--access end-->');
|
||||
if ($accessData) {
|
||||
$body = str_replace($accessData, '<div class="v2board-no-access">'. __('You must have a valid subscription to view content in this area') .'</div>', $body);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Notice;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class NoticeController extends Controller
|
||||
{
|
||||
@ -13,7 +12,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();
|
266
app/Http/Controllers/V1/User/OrderController.php
Executable file
266
app/Http/Controllers/V1/User/OrderController.php
Executable file
@ -0,0 +1,266 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\OrderSave;
|
||||
use App\Models\Order;
|
||||
use App\Models\Payment;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Services\CouponService;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\PaymentService;
|
||||
use App\Services\PlanService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Library\BitpayX;
|
||||
use Library\Epay;
|
||||
use Library\MGate;
|
||||
use Omnipay\Omnipay;
|
||||
use Stripe\Source;
|
||||
use Stripe\Stripe;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$model = Order::where('user_id', $request->user['id'])
|
||||
->orderBy('created_at', 'DESC');
|
||||
if ($request->input('status') !== null) {
|
||||
$model->where('status', $request->input('status'));
|
||||
}
|
||||
$order = $model->get();
|
||||
$plan = Plan::get();
|
||||
for ($i = 0; $i < count($order); $i++) {
|
||||
for ($x = 0; $x < count($plan); $x++) {
|
||||
if ($order[$i]['plan_id'] === $plan[$x]['id']) {
|
||||
$order[$i]['plan'] = $plan[$x];
|
||||
}
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $order->makeHidden(['id', 'user_id'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function detail(Request $request)
|
||||
{
|
||||
$order = Order::where('user_id', $request->user['id'])
|
||||
->where('trade_no', $request->input('trade_no'))
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, __('Order does not exist or has been paid'));
|
||||
}
|
||||
$order['plan'] = Plan::find($order->plan_id);
|
||||
$order['try_out_plan_id'] = (int)config('v2board.try_out_plan_id');
|
||||
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
|
||||
]);
|
||||
}
|
||||
|
||||
public function save(OrderSave $request)
|
||||
{
|
||||
$userService = new UserService();
|
||||
if ($userService->isNotCompleteOrderByUserId($request->user['id'])) {
|
||||
abort(500, __('You have an unpaid or pending order, please try again later or cancel it'));
|
||||
}
|
||||
|
||||
$planService = new PlanService($request->input('plan_id'));
|
||||
|
||||
$plan = $planService->plan;
|
||||
$user = User::find($request->user['id']);
|
||||
|
||||
if (!$plan) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
|
||||
if ($user->plan_id !== $plan->id && !$planService->haveCapacity() && $request->input('period') !== 'reset_price') {
|
||||
abort(500, __('Current product is sold out'));
|
||||
}
|
||||
|
||||
if ($plan[$request->input('period')] === NULL) {
|
||||
abort(500, __('This payment period cannot be purchased, please choose another period'));
|
||||
}
|
||||
|
||||
if ($request->input('period') === 'reset_price') {
|
||||
if (!$userService->isAvailable($user) || $plan->id !== $user->plan_id) {
|
||||
abort(500, __('Subscription has expired or no active subscription, unable to purchase Data Reset Package'));
|
||||
}
|
||||
}
|
||||
|
||||
if ((!$plan->show && !$plan->renew) || (!$plan->show && $user->plan_id !== $plan->id)) {
|
||||
if ($request->input('period') !== 'reset_price') {
|
||||
abort(500, __('This subscription has been sold out, please choose another subscription'));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$plan->renew && $user->plan_id == $plan->id && $request->input('period') !== 'reset_price') {
|
||||
abort(500, __('This subscription cannot be renewed, please change to another subscription'));
|
||||
}
|
||||
|
||||
|
||||
if (!$plan->show && $plan->renew && !$userService->isAvailable($user)) {
|
||||
abort(500, __('This subscription has expired, please change to another subscription'));
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
$order = new Order();
|
||||
$orderService = new OrderService($order);
|
||||
$order->user_id = $request->user['id'];
|
||||
$order->plan_id = $plan->id;
|
||||
$order->period = $request->input('period');
|
||||
$order->trade_no = Helper::generateOrderNo();
|
||||
$order->total_amount = $plan[$request->input('period')];
|
||||
|
||||
if ($request->input('coupon_code')) {
|
||||
$couponService = new CouponService($request->input('coupon_code'));
|
||||
if (!$couponService->use($order)) {
|
||||
DB::rollBack();
|
||||
abort(500, __('Coupon failed'));
|
||||
}
|
||||
$order->coupon_id = $couponService->getId();
|
||||
}
|
||||
|
||||
$orderService->setVipDiscount($user);
|
||||
$orderService->setOrderType($user);
|
||||
$orderService->setInvite($user);
|
||||
|
||||
if ($user->balance && $order->total_amount > 0) {
|
||||
$remainingBalance = $user->balance - $order->total_amount;
|
||||
$userService = new UserService();
|
||||
if ($remainingBalance > 0) {
|
||||
if (!$userService->addBalance($order->user_id, - $order->total_amount)) {
|
||||
DB::rollBack();
|
||||
abort(500, __('Insufficient balance'));
|
||||
}
|
||||
$order->balance_amount = $order->total_amount;
|
||||
$order->total_amount = 0;
|
||||
} else {
|
||||
if (!$userService->addBalance($order->user_id, - $user->balance)) {
|
||||
DB::rollBack();
|
||||
abort(500, __('Insufficient balance'));
|
||||
}
|
||||
$order->balance_amount = $user->balance;
|
||||
$order->total_amount = $order->total_amount - $user->balance;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$order->save()) {
|
||||
DB::rollback();
|
||||
abort(500, __('Failed to create order'));
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response([
|
||||
'data' => $order->trade_no
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkout(Request $request)
|
||||
{
|
||||
$tradeNo = $request->input('trade_no');
|
||||
$method = $request->input('method');
|
||||
$order = Order::where('trade_no', $tradeNo)
|
||||
->where('user_id', $request->user['id'])
|
||||
->where('status', 0)
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, __('Order does not exist or has been paid'));
|
||||
}
|
||||
// free process
|
||||
if ($order->total_amount <= 0) {
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->paid($order->trade_no)) abort(500, '');
|
||||
return response([
|
||||
'type' => -1,
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
$payment = Payment::find($method);
|
||||
if (!$payment || $payment->enable !== 1) abort(500, __('Payment method is not available'));
|
||||
$paymentService = new PaymentService($payment->payment, $payment->id);
|
||||
$order->handling_amount = NULL;
|
||||
if ($payment->handling_fee_fixed || $payment->handling_fee_percent) {
|
||||
$order->handling_amount = round(($order->total_amount * ($payment->handling_fee_percent / 100)) + $payment->handling_fee_fixed);
|
||||
}
|
||||
$order->payment_id = $method;
|
||||
if (!$order->save()) abort(500, __('Request failed, please try again later'));
|
||||
$result = $paymentService->pay([
|
||||
'trade_no' => $tradeNo,
|
||||
'total_amount' => isset($order->handling_amount) ? ($order->total_amount + $order->handling_amount) : $order->total_amount,
|
||||
'user_id' => $order->user_id,
|
||||
'stripe_token' => $request->input('token')
|
||||
]);
|
||||
return response([
|
||||
'type' => $result['type'],
|
||||
'data' => $result['data']
|
||||
]);
|
||||
}
|
||||
|
||||
public function check(Request $request)
|
||||
{
|
||||
$tradeNo = $request->input('trade_no');
|
||||
$order = Order::where('trade_no', $tradeNo)
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, __('Order does not exist'));
|
||||
}
|
||||
return response([
|
||||
'data' => $order->status
|
||||
]);
|
||||
}
|
||||
|
||||
public function getPaymentMethod()
|
||||
{
|
||||
$methods = Payment::select([
|
||||
'id',
|
||||
'name',
|
||||
'payment',
|
||||
'icon',
|
||||
'handling_fee_fixed',
|
||||
'handling_fee_percent'
|
||||
])
|
||||
->where('enable', 1)
|
||||
->orderBy('sort', 'ASC')
|
||||
->get();
|
||||
|
||||
return response([
|
||||
'data' => $methods
|
||||
]);
|
||||
}
|
||||
|
||||
public function cancel(Request $request)
|
||||
{
|
||||
if (empty($request->input('trade_no'))) {
|
||||
abort(500, __('Invalid parameter'));
|
||||
}
|
||||
$order = Order::where('trade_no', $request->input('trade_no'))
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$order) {
|
||||
abort(500, __('Order does not exist'));
|
||||
}
|
||||
if ($order->status !== 0) {
|
||||
abort(500, __('You can only cancel pending orders'));
|
||||
}
|
||||
$orderService = new OrderService($order);
|
||||
if (!$orderService->cancel()) {
|
||||
abort(500, __('Cancel failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
}
|
43
app/Http/Controllers/V1/User/PlanController.php
Executable file
43
app/Http/Controllers/V1/User/PlanController.php
Executable file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Services\PlanService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if ($request->input('id')) {
|
||||
$plan = Plan::where('id', $request->input('id'))->first();
|
||||
if (!$plan) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
if ((!$plan->show && !$plan->renew) || (!$plan->show && $user->plan_id !== $plan->id)) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
return response([
|
||||
'data' => $plan
|
||||
]);
|
||||
}
|
||||
|
||||
$counts = PlanService::countActiveUsers();
|
||||
$plans = Plan::where('show', 1)
|
||||
->orderBy('sort', 'ASC')
|
||||
->get();
|
||||
foreach ($plans as $k => $v) {
|
||||
if ($plans[$k]->capacity_limit === NULL) continue;
|
||||
if (!isset($counts[$plans[$k]->id])) continue;
|
||||
$plans[$k]->capacity_limit = $plans[$k]->capacity_limit - $counts[$plans[$k]->id]->count;
|
||||
}
|
||||
return response([
|
||||
'data' => $plans
|
||||
]);
|
||||
}
|
||||
}
|
33
app/Http/Controllers/V1/User/ServerController.php
Normal file
33
app/Http/Controllers/V1/User/ServerController.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Services\ServerService;
|
||||
use App\Services\UserService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
public function fetch(Request $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
$servers = [];
|
||||
$userService = new UserService();
|
||||
if ($userService->isAvailable($user)) {
|
||||
$serverService = new ServerService();
|
||||
$servers = $serverService->getAvailableServers($user);
|
||||
}
|
||||
$eTag = sha1(json_encode(array_column($servers, 'cache_key')));
|
||||
if (strpos($request->header('If-None-Match'), $eTag) !== false ) {
|
||||
abort(304);
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => $servers
|
||||
])->header('ETag', "\"{$eTag}\"");
|
||||
}
|
||||
}
|
28
app/Http/Controllers/V1/User/StatController.php
Normal file
28
app/Http/Controllers/V1/User/StatController.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\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([
|
||||
'u',
|
||||
'd',
|
||||
'record_at',
|
||||
'user_id',
|
||||
'server_rate'
|
||||
])
|
||||
->where('user_id', $request->user['id'])
|
||||
->where('record_at', '>=', strtotime(date('Y-m-1')))
|
||||
->orderBy('record_at', 'DESC');
|
||||
return response([
|
||||
'data' => $builder->get()
|
||||
]);
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TelegramController extends Controller
|
||||
{
|
||||
@ -17,4 +19,9 @@ class TelegramController extends Controller
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function unbind(Request $request)
|
||||
{
|
||||
$user = User::where('user_id', $request->user['id'])->first();
|
||||
}
|
||||
}
|
@ -1,16 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\TicketSave;
|
||||
use App\Http\Requests\User\TicketWithdraw;
|
||||
use App\Jobs\SendTelegramJob;
|
||||
use App\Models\User;
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketMessage;
|
||||
use App\Models\User;
|
||||
use App\Services\TelegramService;
|
||||
use App\Services\TicketService;
|
||||
use App\Utils\Dict;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TicketController extends Controller
|
||||
@ -19,10 +20,10 @@ class TicketController extends Controller
|
||||
{
|
||||
if ($request->input('id')) {
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, '工单不存在');
|
||||
abort(500, __('Ticket does not exist'));
|
||||
}
|
||||
$ticket['message'] = TicketMessage::where('ticket_id', $ticket->id)->get();
|
||||
for ($i = 0; $i < count($ticket['message']); $i++) {
|
||||
@ -36,16 +37,9 @@ class TicketController extends Controller
|
||||
'data' => $ticket
|
||||
]);
|
||||
}
|
||||
$ticket = Ticket::where('user_id', $request->session()->get('id'))
|
||||
$ticket = Ticket::where('user_id', $request->user['id'])
|
||||
->orderBy('created_at', 'DESC')
|
||||
->get();
|
||||
for ($i = 0; $i < count($ticket); $i++) {
|
||||
if ($ticket[$i]['last_reply_user_id'] == $request->session()->get('id')) {
|
||||
$ticket[$i]['reply_status'] = 0;
|
||||
} else {
|
||||
$ticket[$i]['reply_status'] = 1;
|
||||
}
|
||||
}
|
||||
return response([
|
||||
'data' => $ticket
|
||||
]);
|
||||
@ -54,31 +48,30 @@ class TicketController extends Controller
|
||||
public function save(TicketSave $request)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
if ((int)Ticket::where('status', 0)->where('user_id', $request->session()->get('id'))->count()) {
|
||||
abort(500, '存在其他工单尚未处理');
|
||||
if ((int)Ticket::where('status', 0)->where('user_id', $request->user['id'])->lockForUpdate()->count()) {
|
||||
abort(500, __('There are other unresolved tickets'));
|
||||
}
|
||||
$ticket = Ticket::create(array_merge($request->only([
|
||||
'subject',
|
||||
'level'
|
||||
]), [
|
||||
'user_id' => $request->session()->get('id'),
|
||||
'last_reply_user_id' => $request->session()->get('id')
|
||||
'user_id' => $request->user['id']
|
||||
]));
|
||||
if (!$ticket) {
|
||||
DB::rollback();
|
||||
abort(500, '工单创建失败');
|
||||
abort(500, __('Failed to open ticket'));
|
||||
}
|
||||
$ticketMessage = TicketMessage::create([
|
||||
'user_id' => $request->session()->get('id'),
|
||||
'user_id' => $request->user['id'],
|
||||
'ticket_id' => $ticket->id,
|
||||
'message' => $request->input('message')
|
||||
]);
|
||||
if (!$ticketMessage) {
|
||||
DB::rollback();
|
||||
abort(500, '工单创建失败');
|
||||
abort(500, __('Failed to open ticket'));
|
||||
}
|
||||
DB::commit();
|
||||
$this->sendNotify($ticket, $ticketMessage);
|
||||
$this->sendNotify($ticket, $request->input('message'));
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
@ -87,36 +80,32 @@ class TicketController extends Controller
|
||||
public function reply(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
abort(500, __('Invalid parameter'));
|
||||
}
|
||||
if (empty($request->input('message'))) {
|
||||
abort(500, '消息不能为空');
|
||||
abort(500, __('Message cannot be empty'));
|
||||
}
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, '工单不存在');
|
||||
abort(500, __('Ticket does not exist'));
|
||||
}
|
||||
if ($ticket->status) {
|
||||
abort(500, '工单已关闭,无法回复');
|
||||
abort(500, __('The ticket is closed and cannot be replied'));
|
||||
}
|
||||
if ($request->session()->get('id') == $this->getLastMessage($ticket->id)->user_id) {
|
||||
abort(500, '请等待技术支持回复');
|
||||
if ($request->user['id'] == $this->getLastMessage($ticket->id)->user_id) {
|
||||
abort(500, __('Please wait for the technical enginneer to reply'));
|
||||
}
|
||||
DB::beginTransaction();
|
||||
$ticketMessage = TicketMessage::create([
|
||||
'user_id' => $request->session()->get('id'),
|
||||
'ticket_id' => $ticket->id,
|
||||
'message' => $request->input('message')
|
||||
]);
|
||||
$ticket->last_reply_user_id = $request->session()->get('id');
|
||||
if (!$ticketMessage || !$ticket->save()) {
|
||||
DB::rollback();
|
||||
abort(500, '工单回复失败');
|
||||
$ticketService = new TicketService();
|
||||
if (!$ticketService->reply(
|
||||
$ticket,
|
||||
$request->input('message'),
|
||||
$request->user['id']
|
||||
)) {
|
||||
abort(500, __('Ticket reply failed'));
|
||||
}
|
||||
DB::commit();
|
||||
$this->sendNotify($ticket, $ticketMessage);
|
||||
$this->sendNotify($ticket, $request->input('message'));
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
@ -126,17 +115,17 @@ class TicketController extends Controller
|
||||
public function close(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数错误');
|
||||
abort(500, __('Invalid parameter'));
|
||||
}
|
||||
$ticket = Ticket::where('id', $request->input('id'))
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->where('user_id', $request->user['id'])
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, '工单不存在');
|
||||
abort(500, __('Ticket does not exist'));
|
||||
}
|
||||
$ticket->status = 1;
|
||||
if (!$ticket->save()) {
|
||||
abort(500, '关闭失败');
|
||||
abort(500, __('Close failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
@ -152,49 +141,57 @@ class TicketController extends Controller
|
||||
|
||||
public function withdraw(TicketWithdraw $request)
|
||||
{
|
||||
$user = User::find($request->session()->get('id'));
|
||||
if ((int)config('v2board.withdraw_close_enable', 0)) {
|
||||
abort(500, 'user.ticket.withdraw.not_support_withdraw');
|
||||
}
|
||||
if (!in_array(
|
||||
$request->input('withdraw_method'),
|
||||
config(
|
||||
'v2board.commission_withdraw_method',
|
||||
Dict::WITHDRAW_METHOD_WHITELIST_DEFAULT
|
||||
)
|
||||
)) {
|
||||
abort(500, __('Unsupported withdrawal method'));
|
||||
}
|
||||
$user = User::find($request->user['id']);
|
||||
$limit = config('v2board.commission_withdraw_limit', 100);
|
||||
if ($limit > ($user->commission_balance / 100)) {
|
||||
abort(500, "当前系统要求的提现门槛佣金需为{$limit}CNY");
|
||||
abort(500, __('The current required minimum withdrawal commission is :limit', ['limit' => $limit]));
|
||||
}
|
||||
DB::beginTransaction();
|
||||
$subject = '[提现申请]本工单由系统发出';
|
||||
$subject = __('[Commission Withdrawal Request] This ticket is opened by the system');
|
||||
$ticket = Ticket::create([
|
||||
'subject' => $subject,
|
||||
'level' => 2,
|
||||
'user_id' => $request->session()->get('id'),
|
||||
'last_reply_user_id' => $request->session()->get('id')
|
||||
'user_id' => $request->user['id']
|
||||
]);
|
||||
if (!$ticket) {
|
||||
DB::rollback();
|
||||
abort(500, '工单创建失败');
|
||||
abort(500, __('Failed to open ticket'));
|
||||
}
|
||||
$methodText = [
|
||||
'alipay' => '支付宝',
|
||||
'paypal' => '贝宝(Paypal)',
|
||||
'usdt' => 'USDT',
|
||||
'btc' => '比特币'
|
||||
];
|
||||
$message = "提现方式:{$methodText[$request->input('withdraw_method')]}\r\n提现账号:{$request->input('withdraw_account')}\r\n";
|
||||
$message = sprintf("%s\r\n%s",
|
||||
__('Withdrawal method') . ":" . $request->input('withdraw_method'),
|
||||
__('Withdrawal account') . ":" . $request->input('withdraw_account')
|
||||
);
|
||||
$ticketMessage = TicketMessage::create([
|
||||
'user_id' => $request->session()->get('id'),
|
||||
'user_id' => $request->user['id'],
|
||||
'ticket_id' => $ticket->id,
|
||||
'message' => $message
|
||||
]);
|
||||
if (!$ticketMessage) {
|
||||
DB::rollback();
|
||||
abort(500, '工单创建失败');
|
||||
abort(500, __('Failed to open ticket'));
|
||||
}
|
||||
DB::commit();
|
||||
$this->sendNotify($ticket, $ticketMessage);
|
||||
$this->sendNotify($ticket, $message);
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
private function sendNotify(Ticket $ticket, TicketMessage $ticketMessage)
|
||||
private function sendNotify(Ticket $ticket, string $message)
|
||||
{
|
||||
$telegramService = new TelegramService();
|
||||
$telegramService->sendMessageWithAdmin("📮工单提醒 #{$ticket->id}\n———————————————\n主题:\n`{$ticket->subject}`\n内容:\n`{$ticketMessage->message}`", true);
|
||||
$telegramService->sendMessageWithAdmin("📮工单提醒 #{$ticket->id}\n———————————————\n主题:\n`{$ticket->subject}`\n内容:\n`{$message}`", true);
|
||||
}
|
||||
}
|
239
app/Http/Controllers/V1/User/UserController.php
Executable file
239
app/Http/Controllers/V1/User/UserController.php
Executable file
@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V1\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\UserChangePassword;
|
||||
use App\Http\Requests\User\UserTransfer;
|
||||
use App\Http\Requests\User\UserUpdate;
|
||||
use App\Models\Order;
|
||||
use App\Models\Plan;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use App\Services\AuthService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\CacheKey;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function getActiveSession(Request $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
$authService = new AuthService($user);
|
||||
return response([
|
||||
'data' => $authService->getSessions()
|
||||
]);
|
||||
}
|
||||
|
||||
public function removeActiveSession(Request $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
$authService = new AuthService($user);
|
||||
return response([
|
||||
'data' => $authService->removeSession($request->input('session_id'))
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkLogin(Request $request)
|
||||
{
|
||||
$data = [
|
||||
'is_login' => $request->user['id'] ? true : false
|
||||
];
|
||||
if ($request->user['is_admin']) {
|
||||
$data['is_admin'] = true;
|
||||
}
|
||||
return response([
|
||||
'data' => $data
|
||||
]);
|
||||
}
|
||||
|
||||
public function changePassword(UserChangePassword $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
if (!Helper::multiPasswordVerify(
|
||||
$user->password_algo,
|
||||
$user->password_salt,
|
||||
$request->input('old_password'),
|
||||
$user->password)
|
||||
) {
|
||||
abort(500, __('The old password is wrong'));
|
||||
}
|
||||
$user->password = password_hash($request->input('new_password'), PASSWORD_DEFAULT);
|
||||
$user->password_algo = NULL;
|
||||
$user->password_salt = NULL;
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Save failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function info(Request $request)
|
||||
{
|
||||
$user = User::where('id', $request->user['id'])
|
||||
->select([
|
||||
'email',
|
||||
'transfer_enable',
|
||||
'last_login_at',
|
||||
'created_at',
|
||||
'banned',
|
||||
'remind_expire',
|
||||
'remind_traffic',
|
||||
'expired_at',
|
||||
'balance',
|
||||
'commission_balance',
|
||||
'plan_id',
|
||||
'discount',
|
||||
'commission_rate',
|
||||
'telegram_id',
|
||||
'uuid'
|
||||
])
|
||||
->first();
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
$user['avatar_url'] = 'https://cdn.v2ex.com/gravatar/' . md5($user->email) . '?s=64&d=identicon';
|
||||
return response([
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
public function getStat(Request $request)
|
||||
{
|
||||
$stat = [
|
||||
Order::where('status', 0)
|
||||
->where('user_id', $request->user['id'])
|
||||
->count(),
|
||||
Ticket::where('status', 0)
|
||||
->where('user_id', $request->user['id'])
|
||||
->count(),
|
||||
User::where('invite_user_id', $request->user['id'])
|
||||
->count()
|
||||
];
|
||||
return response([
|
||||
'data' => $stat
|
||||
]);
|
||||
}
|
||||
|
||||
public function getSubscribe(Request $request)
|
||||
{
|
||||
$user = User::where('id', $request->user['id'])
|
||||
->select([
|
||||
'plan_id',
|
||||
'token',
|
||||
'expired_at',
|
||||
'u',
|
||||
'd',
|
||||
'transfer_enable',
|
||||
'email',
|
||||
'uuid'
|
||||
])
|
||||
->first();
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
if ($user->plan_id) {
|
||||
$user['plan'] = Plan::find($user->plan_id);
|
||||
if (!$user['plan']) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
}
|
||||
$user['subscribe_url'] = Helper::getSubscribeUrl($user['token']);
|
||||
$userService = new UserService();
|
||||
$user['reset_day'] = $userService->getResetDay($user);
|
||||
return response([
|
||||
'data' => $user
|
||||
]);
|
||||
}
|
||||
|
||||
public function resetSecurity(Request $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
$user->uuid = Helper::guid(true);
|
||||
$user->token = Helper::guid();
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Reset failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => Helper::getSubscribeUrl($user['token'])
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UserUpdate $request)
|
||||
{
|
||||
$updateData = $request->only([
|
||||
'remind_expire',
|
||||
'remind_traffic'
|
||||
]);
|
||||
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
try {
|
||||
$user->update($updateData);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, __('Save failed'));
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function transfer(UserTransfer $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
if ($request->input('transfer_amount') > $user->commission_balance) {
|
||||
abort(500, __('Insufficient commission balance'));
|
||||
}
|
||||
$user->commission_balance = $user->commission_balance - $request->input('transfer_amount');
|
||||
$user->balance = $user->balance + $request->input('transfer_amount');
|
||||
if (!$user->save()) {
|
||||
abort(500, __('Transfer failed'));
|
||||
}
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function getQuickLoginUrl(Request $request)
|
||||
{
|
||||
$user = User::find($request->user['id']);
|
||||
if (!$user) {
|
||||
abort(500, __('The user does not exist'));
|
||||
}
|
||||
|
||||
$code = Helper::guid();
|
||||
$key = CacheKey::get('TEMP_TOKEN', $code);
|
||||
Cache::put($key, $user->id, 60);
|
||||
$redirect = '/#/login?verify=' . $code . '&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard');
|
||||
if (config('v2board.app_url')) {
|
||||
$url = config('v2board.app_url') . $redirect;
|
||||
} else {
|
||||
$url = url($redirect);
|
||||
}
|
||||
return response([
|
||||
'data' => $url
|
||||
]);
|
||||
}
|
||||
}
|
92
app/Http/Controllers/V2/Admin/StatController.php
Normal file
92
app/Http/Controllers/V2/Admin/StatController.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\V2\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CommissionLog;
|
||||
use App\Models\Order;
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Models\ServerTrojan;
|
||||
use App\Models\ServerVmess;
|
||||
use App\Models\Stat;
|
||||
use App\Models\StatServer;
|
||||
use App\Models\StatUser;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use App\Services\StatisticalService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StatController extends Controller
|
||||
{
|
||||
public function override(Request $request)
|
||||
{
|
||||
$params = $request->validate([
|
||||
'start_at' => '',
|
||||
'end_at' => ''
|
||||
]);
|
||||
|
||||
if (isset($params['start_at']) && isset($params['end_at'])) {
|
||||
$stats = Stat::where('record_at', '>=', $params['start_at'])
|
||||
->where('record_at', '<', $params['end_at'])
|
||||
->get()
|
||||
->makeHidden(['record_at', 'created_at', 'updated_at', 'id', 'record_type'])
|
||||
->toArray();
|
||||
} else {
|
||||
$statisticalService = new StatisticalService();
|
||||
return [
|
||||
'data' => $statisticalService->generateStatData()
|
||||
];
|
||||
}
|
||||
|
||||
$stats = array_reduce($stats, function($carry, $item) {
|
||||
foreach($item as $key => $value) {
|
||||
if(isset($carry[$key]) && $carry[$key]) {
|
||||
$carry[$key] += $value;
|
||||
} else {
|
||||
$carry[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $carry;
|
||||
}, []);
|
||||
|
||||
return [
|
||||
'data' => $stats
|
||||
];
|
||||
}
|
||||
|
||||
public function record(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'type' => 'required|in:paid_total,commission_total,register_count',
|
||||
'start_at' => '',
|
||||
'end_at' => ''
|
||||
]);
|
||||
|
||||
$statisticalService = new StatisticalService();
|
||||
$statisticalService->setStartAt($request->input('start_at'));
|
||||
$statisticalService->setEndAt($request->input('end_at'));
|
||||
return [
|
||||
'data' => $statisticalService->getStatRecord($request->input('type'))
|
||||
];
|
||||
}
|
||||
|
||||
public function ranking(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'type' => 'required|in:server_traffic_rank,user_consumption_rank,invite_rank',
|
||||
'start_at' => '',
|
||||
'end_at' => '',
|
||||
'limit' => 'nullable|integer'
|
||||
]);
|
||||
|
||||
$statisticalService = new StatisticalService();
|
||||
$statisticalService->setStartAt($request->input('start_at'));
|
||||
$statisticalService->setEndAt($request->input('end_at'));
|
||||
return [
|
||||
'data' => $statisticalService->getRanking($request->input('type'), $request->input('limit') ?? 20)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http;
|
||||
|
||||
use Fruitcake\Cors\HandleCors;
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
@ -14,6 +15,7 @@ class Kernel extends HttpKernel
|
||||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
\App\Http\Middleware\CORS::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\App\Http\Middleware\CheckForMaintenanceMode::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
|
||||
@ -28,21 +30,21 @@ class Kernel extends HttpKernel
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \App\Http\Middleware\EncryptCookies::class,
|
||||
// \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
// \Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
// \Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
// \App\Http\Middleware\VerifyCsrfToken::class,
|
||||
// \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
],
|
||||
|
||||
'api' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \App\Http\Middleware\EncryptCookies::class,
|
||||
// \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
// \Illuminate\Session\Middleware\StartSession::class,
|
||||
\App\Http\Middleware\ForceJson::class,
|
||||
\App\Http\Middleware\CORS::class,
|
||||
\App\Http\Middleware\Language::class,
|
||||
'bindings',
|
||||
],
|
||||
];
|
||||
@ -68,6 +70,7 @@ class Kernel extends HttpKernel
|
||||
'admin' => \App\Http\Middleware\Admin::class,
|
||||
'client' => \App\Http\Middleware\Client::class,
|
||||
'staff' => \App\Http\Middleware\Staff::class,
|
||||
'log' => \App\Http\Middleware\RequestLog::class
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Services\AuthService;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Admin
|
||||
{
|
||||
@ -15,9 +17,14 @@ class Admin
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (!$request->session()->get('is_admin')) {
|
||||
abort(403, '权限不足');
|
||||
}
|
||||
$authorization = $request->input('auth_data') ?? $request->header('authorization');
|
||||
if (!$authorization) abort(403, '未登录或登陆已过期');
|
||||
|
||||
$user = AuthService::decryptAuthData($authorization);
|
||||
if (!$user || !$user['is_admin']) abort(403, '未登录或登陆已过期');
|
||||
$request->merge([
|
||||
'user' => $user
|
||||
]);
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ class CORS
|
||||
}
|
||||
$response = $next($request);
|
||||
$response->header('Access-Control-Allow-Origin', trim($origin, '/'));
|
||||
$response->header('Access-Control-Allow-Methods', 'GET,POST,OPTIONS');
|
||||
$response->header('Access-Control-Allow-Headers', 'Content-Type,X-Requested-With');
|
||||
$response->header('Access-Control-Allow-Methods', 'GET,POST,OPTIONS,HEAD');
|
||||
$response->header('Access-Control-Allow-Headers', 'Origin,Content-Type,Accept,Authorization,X-Request-With');
|
||||
$response->header('Access-Control-Allow-Credentials', 'true');
|
||||
$response->header('Access-Control-Max-Age', 10080);
|
||||
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Utils\CacheKey;
|
||||
use Closure;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Client
|
||||
{
|
||||
@ -24,7 +26,9 @@ class Client
|
||||
if (!$user) {
|
||||
abort(403, 'token is error');
|
||||
}
|
||||
$request->user = $user;
|
||||
$request->merge([
|
||||
'user' => $user
|
||||
]);
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
17
app/Http/Middleware/Language.php
Executable file
17
app/Http/Middleware/Language.php
Executable file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class Language
|
||||
{
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if ($request->header('content-language')) {
|
||||
App::setLocale($request->header('content-language'));
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
24
app/Http/Middleware/RequestLog.php
Executable file
24
app/Http/Middleware/RequestLog.php
Executable file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class RequestLog
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if ($request->method() === 'POST') {
|
||||
$path = $request->path();
|
||||
info("POST {$path}");
|
||||
};
|
||||
return $next($request);
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Services\AuthService;
|
||||
use Closure;
|
||||
|
||||
class Staff
|
||||
@ -15,9 +16,14 @@ class Staff
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if (!$request->session()->get('is_staff')) {
|
||||
abort(403, '权限不足');
|
||||
}
|
||||
$authorization = $request->input('auth_data') ?? $request->header('authorization');
|
||||
if (!$authorization) abort(403, '未登录或登陆已过期');
|
||||
|
||||
$user = AuthService::decryptAuthData($authorization);
|
||||
if (!$user || !$user['is_staff']) abort(403, '未登录或登陆已过期');
|
||||
$request->merge([
|
||||
'user' => $user
|
||||
]);
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Services\AuthService;
|
||||
use Closure;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class User
|
||||
{
|
||||
@ -15,16 +17,14 @@ class User
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
if ($request->input('access_token')) {
|
||||
$user = \App\Models\User::where('token', $request->input('access_token'))->first();
|
||||
if ($user) {
|
||||
$request->session()->put('email', $user->email);
|
||||
$request->session()->put('id', $user->id);
|
||||
}
|
||||
}
|
||||
if (!$request->session()->get('id')) {
|
||||
abort(403, '未登录或登陆已过期');
|
||||
}
|
||||
$authorization = $request->input('auth_data') ?? $request->header('authorization');
|
||||
if (!$authorization) abort(403, '未登录或登陆已过期');
|
||||
|
||||
$user = AuthService::decryptAuthData($authorization);
|
||||
if (!$user) abort(403, '未登录或登陆已过期');
|
||||
$request->merge([
|
||||
'user' => $user
|
||||
]);
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,91 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ConfigSave extends FormRequest
|
||||
{
|
||||
const RULES = [
|
||||
// invite & commission
|
||||
'invite_force' => 'in:0,1',
|
||||
'invite_commission' => 'integer',
|
||||
'invite_gen_limit' => 'integer',
|
||||
'invite_never_expire' => 'in:0,1',
|
||||
'commission_first_time_enable' => 'in:0,1',
|
||||
'commission_auto_check_enable' => 'in:0,1',
|
||||
'commission_withdraw_limit' => 'nullable|numeric',
|
||||
'commission_withdraw_method' => 'nullable|array',
|
||||
'withdraw_close_enable' => 'in:0,1',
|
||||
'commission_distribution_enable' => 'in:0,1',
|
||||
'commission_distribution_l1' => 'nullable|numeric',
|
||||
'commission_distribution_l2' => 'nullable|numeric',
|
||||
'commission_distribution_l3' => 'nullable|numeric',
|
||||
// site
|
||||
'logo' => 'nullable|url',
|
||||
'force_https' => 'in:0,1',
|
||||
'stop_register' => 'in:0,1',
|
||||
'app_name' => '',
|
||||
'app_description' => '',
|
||||
'app_url' => 'nullable|url',
|
||||
'subscribe_url' => 'nullable',
|
||||
'subscribe_path' => 'nullable',
|
||||
'try_out_enable' => 'in:0,1',
|
||||
'try_out_plan_id' => 'integer',
|
||||
'try_out_hour' => 'numeric',
|
||||
'tos_url' => 'nullable|url',
|
||||
'currency' => '',
|
||||
'currency_symbol' => '',
|
||||
// subscribe
|
||||
'plan_change_enable' => 'in:0,1',
|
||||
'reset_traffic_method' => 'in:0,1,2,3,4',
|
||||
'new_order_event_id' => 'in:0,1',
|
||||
'renew_order_event_id' => 'in:0,1',
|
||||
'change_order_event_id' => 'in:0,1',
|
||||
'show_info_to_server_enable' => 'in:0,1',
|
||||
// server
|
||||
'server_token' => 'nullable|min:16',
|
||||
'server_pull_interval' => 'integer',
|
||||
'server_push_interval' => 'integer',
|
||||
// frontend
|
||||
'frontend_theme' => '',
|
||||
'frontend_theme_sidebar' => 'nullable|in:dark,light',
|
||||
'frontend_theme_header' => 'nullable|in:dark,light',
|
||||
'frontend_theme_color' => 'nullable|in:default,darkblue,black,green',
|
||||
'frontend_background_url' => 'nullable|url',
|
||||
// email
|
||||
'email_template' => '',
|
||||
'email_host' => '',
|
||||
'email_port' => '',
|
||||
'email_username' => '',
|
||||
'email_password' => '',
|
||||
'email_encryption' => '',
|
||||
'email_from_address' => '',
|
||||
// telegram
|
||||
'telegram_bot_enable' => 'in:0,1',
|
||||
'telegram_bot_token' => '',
|
||||
'telegram_discuss_id' => '',
|
||||
'telegram_channel_id' => '',
|
||||
'telegram_discuss_link' => 'nullable|url',
|
||||
// app
|
||||
'windows_version' => '',
|
||||
'windows_download_url' => '',
|
||||
'macos_version' => '',
|
||||
'macos_download_url' => '',
|
||||
'android_version' => '',
|
||||
'android_download_url' => '',
|
||||
// safe
|
||||
'email_whitelist_enable' => 'in:0,1',
|
||||
'email_whitelist_suffix' => 'nullable|array',
|
||||
'email_gmail_limit_enable' => 'in:0,1',
|
||||
'recaptcha_enable' => 'in:0,1',
|
||||
'recaptcha_key' => '',
|
||||
'recaptcha_site_key' => '',
|
||||
'email_verify' => 'in:0,1',
|
||||
'safe_mode_enable' => 'in:0,1',
|
||||
'register_limit_by_ip_enable' => 'in:0,1',
|
||||
'register_limit_count' => 'integer',
|
||||
'register_limit_expire' => 'integer',
|
||||
'secure_path' => 'min:8|regex:/^[\w-]*$/',
|
||||
'password_limit_enable' => 'in:0,1',
|
||||
'password_limit_count' => 'integer',
|
||||
'password_limit_expire' => 'integer',
|
||||
];
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
@ -13,102 +98,7 @@ class ConfigSave extends FormRequest
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
// invite & commission
|
||||
'safe_mode_enable' => 'in:0,1',
|
||||
'invite_force' => 'in:0,1',
|
||||
'invite_commission' => 'integer',
|
||||
'invite_gen_limit' => 'integer',
|
||||
'invite_never_expire' => 'in:0,1',
|
||||
'commission_first_time_enable' => 'in:0,1',
|
||||
'commission_auto_check_enable' => 'in:0,1',
|
||||
'commission_withdraw_limit' => 'nullable|numeric',
|
||||
// site
|
||||
'stop_register' => 'in:0,1',
|
||||
'email_verify' => 'in:0,1',
|
||||
'app_name' => '',
|
||||
'app_description' => '',
|
||||
'app_url' => 'nullable|url',
|
||||
'subscribe_url' => 'nullable|url',
|
||||
'try_out_enable' => 'in:0,1',
|
||||
'try_out_plan_id' => 'integer',
|
||||
'try_out_hour' => 'numeric',
|
||||
'email_whitelist_enable' => 'in:0,1',
|
||||
'email_whitelist_suffix' => '',
|
||||
'email_gmail_limit_enable' => 'in:0,1',
|
||||
'recaptcha_enable' => 'in:0,1',
|
||||
'recaptcha_key' => '',
|
||||
'recaptcha_site_key' => '',
|
||||
// subscribe
|
||||
'plan_change_enable' => 'in:0,1',
|
||||
'reset_traffic_method' => 'in:0,1',
|
||||
'renew_reset_traffic_enable' => 'in:0,1',
|
||||
'surplus_enable' => 'in:0,1',
|
||||
// server
|
||||
'server_token' => 'nullable|min:16',
|
||||
'server_license' => 'nullable',
|
||||
'server_log_enable' => 'in:0,1',
|
||||
'server_v2ray_domain' => '',
|
||||
'server_v2ray_protocol' => '',
|
||||
// alipay
|
||||
'alipay_enable' => 'in:0,1',
|
||||
'alipay_appid' => 'nullable|integer|min:16',
|
||||
'alipay_pubkey' => 'max:2048',
|
||||
'alipay_privkey' => 'max:2048',
|
||||
// stripe
|
||||
'stripe_alipay_enable' => 'in:0,1',
|
||||
'stripe_wepay_enable' => 'in:0,1',
|
||||
'stripe_card_enable' => 'in:0,1',
|
||||
'stripe_sk_live' => '',
|
||||
'stripe_pk_live' => '',
|
||||
'stripe_webhook_key' => '',
|
||||
'stripe_currency' => 'in:hkd,usd,sgd,eur,gbp,jpy,cad',
|
||||
// bitpayx
|
||||
'bitpayx_name' => '',
|
||||
'bitpayx_enable' => 'in:0,1',
|
||||
'bitpayx_appsecret' => '',
|
||||
// mGate
|
||||
'mgate_name' => '',
|
||||
'mgate_enable' => 'in:0,1',
|
||||
'mgate_url' => 'nullable|url',
|
||||
'mgate_app_id' => '',
|
||||
'mgate_app_secret' => '',
|
||||
// Epay
|
||||
'epay_name' => '',
|
||||
'epay_enable' => 'in:0,1',
|
||||
'epay_url' => 'nullable|url',
|
||||
'epay_pid' => '',
|
||||
'epay_key' => '',
|
||||
// frontend
|
||||
'frontend_theme_sidebar' => 'in:dark,light',
|
||||
'frontend_theme_header' => 'in:dark,light',
|
||||
'frontend_theme_color' => 'in:default,darkblue,black',
|
||||
'frontend_background_url' => 'nullable|url',
|
||||
'frontend_admin_path' => '',
|
||||
// tutorial
|
||||
'apple_id' => 'nullable|email',
|
||||
'apple_id_password' => '',
|
||||
// email
|
||||
'email_template' => '',
|
||||
'email_host' => '',
|
||||
'email_port' => '',
|
||||
'email_username' => '',
|
||||
'email_password' => '',
|
||||
'email_encryption' => '',
|
||||
'email_from_address' => '',
|
||||
// telegram
|
||||
'telegram_bot_enable' => 'in:0,1',
|
||||
'telegram_bot_token' => '',
|
||||
'telegram_discuss_id' => '',
|
||||
'telegram_channel_id' => '',
|
||||
// app
|
||||
'windows_version' => '',
|
||||
'windows_download_url' => '',
|
||||
'macos_version' => '',
|
||||
'macos_download_url' => '',
|
||||
'android_version' => '',
|
||||
'android_download_url' => ''
|
||||
];
|
||||
return self::RULES;
|
||||
}
|
||||
|
||||
public function messages()
|
||||
@ -116,7 +106,13 @@ class ConfigSave extends FormRequest
|
||||
// illiteracy prompt
|
||||
return [
|
||||
'app_url.url' => '站点URL格式不正确,必须携带http(s)://',
|
||||
'subscribe_url.url' => '订阅URL格式不正确,必须携带http(s)://'
|
||||
'subscribe_url.url' => '订阅URL格式不正确,必须携带http(s)://',
|
||||
'server_token.min' => '通讯密钥长度必须大于16位',
|
||||
'tos_url.url' => '服务条款URL格式不正确,必须携带http(s)://',
|
||||
'telegram_discuss_link.url' => 'Telegram群组地址必须为URL格式,必须携带http(s)://',
|
||||
'logo.url' => 'LOGO URL格式不正确,必须携带https(s)://',
|
||||
'secure_path.min' => '后台路径长度最小为8位',
|
||||
'secure_path.regex' => '后台路径只能为字母或数字'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,9 @@ class CouponGenerate extends FormRequest
|
||||
'started_at' => 'required|integer',
|
||||
'ended_at' => 'required|integer',
|
||||
'limit_use' => 'nullable|integer',
|
||||
'limit_use_with_user' => 'nullable|integer',
|
||||
'limit_plan_ids' => 'nullable|array',
|
||||
'limit_period' => 'nullable|array',
|
||||
'code' => ''
|
||||
];
|
||||
}
|
||||
@ -40,8 +42,10 @@ class CouponGenerate extends FormRequest
|
||||
'started_at.integer' => '开始时间格式有误',
|
||||
'ended_at.required' => '结束时间不能为空',
|
||||
'ended_at.integer' => '结束时间格式有误',
|
||||
'limit_use.integer' => '使用次数格式有误',
|
||||
'limit_plan_ids.array' => '指定订阅格式有误'
|
||||
'limit_use.integer' => '最大使用次数格式有误',
|
||||
'limit_use_with_user.integer' => '限制用户使用次数格式有误',
|
||||
'limit_plan_ids.array' => '指定订阅格式有误',
|
||||
'limit_period.array' => '指定周期格式有误'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CouponSave extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
'type' => 'required|in:1,2',
|
||||
'value' => 'required|integer',
|
||||
'started_at' => 'required|integer',
|
||||
'ended_at' => 'required|integer',
|
||||
'limit_use' => 'nullable|integer',
|
||||
'limit_plan_ids' => 'nullable|array',
|
||||
'code' => ''
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'name.required' => '名称不能为空',
|
||||
'type.required' => '类型不能为空',
|
||||
'type.in' => '类型格式有误',
|
||||
'value.required' => '金额或比例不能为空',
|
||||
'value.integer' => '金额或比例格式有误',
|
||||
'started_at.required' => '开始时间不能为空',
|
||||
'started_at.integer' => '开始时间格式有误',
|
||||
'ended_at.required' => '结束时间不能为空',
|
||||
'ended_at.integer' => '结束时间格式有误',
|
||||
'limit_use.integer' => '使用次数格式有误',
|
||||
'limit_plan_ids.array' => '指定订阅格式有误'
|
||||
];
|
||||
}
|
||||
}
|
@ -16,7 +16,8 @@ class NoticeSave extends FormRequest
|
||||
return [
|
||||
'title' => 'required',
|
||||
'content' => 'required',
|
||||
'img_url' => 'nullable|url'
|
||||
'img_url' => 'nullable|url',
|
||||
'tags' => 'nullable|array'
|
||||
];
|
||||
}
|
||||
|
||||
@ -25,7 +26,8 @@ class NoticeSave extends FormRequest
|
||||
return [
|
||||
'title.required' => '标题不能为空',
|
||||
'content.required' => '内容不能为空',
|
||||
'img_url.url' => '图片URL格式不正确'
|
||||
'img_url.url' => '图片URL格式不正确',
|
||||
'tags.array' => '标签格式不正确'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ class OrderAssign extends FormRequest
|
||||
'plan_id' => 'required',
|
||||
'email' => 'required',
|
||||
'total_amount' => 'required',
|
||||
'cycle' => 'required|in:month_price,quarter_price,half_year_price,year_price,two_year_price,three_year_price,onetime_price,reset_price'
|
||||
'period' => 'required|in:month_price,quarter_price,half_year_price,year_price,two_year_price,three_year_price,onetime_price,reset_price'
|
||||
];
|
||||
}
|
||||
|
||||
@ -27,8 +27,8 @@ class OrderAssign extends FormRequest
|
||||
'plan_id.required' => '订阅不能为空',
|
||||
'email.required' => '邮箱不能为空',
|
||||
'total_amount.required' => '支付金额不能为空',
|
||||
'cycle.required' => '订阅周期不能为空',
|
||||
'cycle.in' => '订阅周期格式有误'
|
||||
'period.required' => '订阅周期不能为空',
|
||||
'period.in' => '订阅周期格式有误'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user