Compare commits
656 Commits
0e376ec1f1
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 32af6abeb2 | |||
| d4082e0edd | |||
| 0402097b59 | |||
| b07f4e971a | |||
| e69bceeb77 | |||
| 00270b3904 | |||
| 61cfc2091c | |||
| af772350c9 | |||
| f0269c7c17 | |||
| 17d1885efc | |||
| c8a9c92b56 | |||
| 62bd92c1c6 | |||
| 0ac12364bb | |||
| 36ac9d090b | |||
| 7fc40eba32 | |||
| aecabde44c | |||
| 4cdcaa537f | |||
| 891e18e83f | |||
| 2e8bfb61c2 | |||
| be0052119f | |||
| 5b6f687db6 | |||
| e53f2f5d9d | |||
| ee4abdff85 | |||
| 925f2498c5 | |||
| 6f779edb91 | |||
| 8d038c698f | |||
| 7966c0f662 | |||
| 1f1c329085 | |||
| 0953e03b73 | |||
| 9ba18315cc | |||
| 8e57ad8a45 | |||
| a5c43383e1 | |||
| 63f6dc7106 | |||
| 48d646d723 | |||
| d5f9cf7371 | |||
| 414dc52a3b | |||
| 3bbde9b4dd | |||
| b622053bc2 | |||
| 66a9e8ad23 | |||
| 585a6fbf5f | |||
| 9f61dcc619 | |||
| dac8adfc5a | |||
| 8a690ac40d | |||
| c7b8ba956b | |||
| e6a686233f | |||
| 55d3dd43ba | |||
| fdd20917a4 | |||
| a6bc6c61c5 | |||
| f8fb849714 | |||
| 43d613bfb1 | |||
| a766f2a9c5 | |||
| 14511b6230 | |||
| 136240e5e1 | |||
| ed2d60a24e | |||
| 1e9f6673cc | |||
| a5c2022422 | |||
| d4a6a799fe | |||
| e3a3f6a596 | |||
| 35ee91530b | |||
| de7c79f0de | |||
| 19e50944d9 | |||
| 4d337a2e8f | |||
| e876e76ec7 | |||
| 35cbfedeb7 | |||
| b7af9330c4 | |||
| cedc787586 | |||
| 7900145ba9 | |||
| c3229f870a | |||
| 4352919889 | |||
| 90d2fcc14a | |||
| a62e7ff41f | |||
| 4815d201f6 | |||
| 4751a5578e | |||
| 85a419fe53 | |||
| d875dd08ec | |||
| 2d4593c597 | |||
| 91ddfbb408 | |||
| ed7ff81321 | |||
| bb401b8940 | |||
| f54757414d | |||
| d46fe85c70 | |||
| 0623120c00 | |||
| ed484c9235 | |||
| 6cb63a98e2 | |||
| c44c8198d2 | |||
| 992615b7be | |||
| a0aaceecc3 | |||
| c7ad87a767 | |||
| 2180fa5ff4 | |||
| 8bf913c568 | |||
| 22981802ca | |||
| 9cc10d56a7 | |||
| 8cdf8492fb | |||
| e9a3310649 | |||
| db545aa32e | |||
| 086a46dda6 | |||
| 5823028276 | |||
| 21a727a693 | |||
| ef434f0703 | |||
| 5938976360 | |||
| 0cfb43183a | |||
| 990b939a3a | |||
| 4f869eb6ea | |||
| 20317f4699 | |||
| 83fff919a5 | |||
| 95484681c5 | |||
| a847dad00a | |||
| e341f2d1a7 | |||
| 318aeba684 | |||
| 4b1d47e96c | |||
| 8886f5c690 | |||
| c8bc81f961 | |||
| 283793bc1c | |||
| 84b3624d59 | |||
| 74602c7a7b | |||
| 31f53ddfbe | |||
| d012b3e73b | |||
| 308e5690fe | |||
| 2f09d5e2ed | |||
| ac8a3b959d | |||
| 518cc86a93 | |||
| 3773cf905b | |||
| 1a750f2fe7 | |||
| 37e4c5d4c5 | |||
| 0526419dbc | |||
| 89f344bd29 | |||
| 247283a282 | |||
| 4df557bb9e | |||
| 54faf8b501 | |||
| be22710424 | |||
| 1db22dc5de | |||
| 0310798675 | |||
| 04ee32e4d5 | |||
| ef471ec68b | |||
| 3e525eaa36 | |||
| ce6f8552c1 | |||
| 1429dee8a6 | |||
| cf42071c29 | |||
| 10e9835530 | |||
| 64a1e5d769 | |||
| ca61dd42f7 | |||
| e9c3fc989c | |||
| c858f6af0c | |||
| 2f246f9112 | |||
| f1d8d20180 | |||
| e3cba255f9 | |||
| 128b52d0aa | |||
| c410897231 | |||
| 855d031b04 | |||
| 4d3f4f7a4b | |||
| f18eefe9bc | |||
| 8bd1dae9e1 | |||
| 5bfcd75442 | |||
| 8b15507f22 | |||
| 97c021dae2 | |||
| 8cf5029711 | |||
| aab609f69b | |||
| a0268b611f | |||
| fc68aaff72 | |||
| 32584f11d2 | |||
| a3b5184470 | |||
| b2b91b9238 | |||
| 9f8b5e7524 | |||
| 5273b4ee4b | |||
| 4486a87326 | |||
| be9fc09d9d | |||
| 34356a26ae | |||
| 0f0bfef2a8 | |||
| d7ec42a025 | |||
| 6c631aa495 | |||
| fb96747352 | |||
| 7c27ba0c48 | |||
| bef797abd5 | |||
| 73c6674fc4 | |||
| b0028c515f | |||
| a066580014 | |||
| 5a6446b832 | |||
| a17a67f533 | |||
| fed51dda18 | |||
| c209221bad | |||
| 590b7d5b35 | |||
| f0769a841e | |||
| 281315d1cf | |||
| cfdbf387af | |||
| cf4006eb8b | |||
| 96a449d94b | |||
| 916f4c5aa6 | |||
| d4a9389fbc | |||
| 900c93c6c7 | |||
| 438241e878 | |||
| ba6406ed68 | |||
| 5ce83a769d | |||
| bd97ed0b73 | |||
| b98ae7f94e | |||
| c710d585da | |||
| 3afe5a4480 | |||
| c7cb826013 | |||
| 0e8a1669b9 | |||
| 0f4de941db | |||
| 4866d25df9 | |||
| dd938ec6e7 | |||
| 1a39ddd725 | |||
| 7255d50966 | |||
| 6927a88dd3 | |||
| fc9a66469a | |||
| 0183de66dd | |||
| b76b6559ea | |||
| a2e51f5668 | |||
| 392f46769c | |||
| df29da7440 | |||
| 762caac938 | |||
| 426d01d99b | |||
| 596c7f357f | |||
| 2eb732642b | |||
| d060e1b797 | |||
| dca43a2d0d | |||
| 353aaaf6ce | |||
| d739fc7028 | |||
| c297b61493 | |||
| ef407a8c6e | |||
| f8d5a3b250 | |||
| a4cc85b558 | |||
| bf856e18e3 | |||
| d60065ff3e | |||
| e837d1fcd0 | |||
| 61541bfe4c | |||
| d6f14868fd | |||
| 4ac3311328 | |||
| e5f0f28978 | |||
| 5755bea748 | |||
| 1559e49d3d | |||
| d52db10863 | |||
| adc89240fd | |||
| 28cbf2b564 | |||
| e7aea014fb | |||
| 87c7a8d786 | |||
| 5b637d2c64 | |||
| 2090250967 | |||
| 705af810a9 | |||
| 77c17f87f9 | |||
| 1e64d2d5e2 | |||
| 70cb170f2c | |||
| 33a3e5d118 | |||
| bc825157c9 | |||
| 9b1f2a2146 | |||
| 0899ff184c | |||
| 82e29753b8 | |||
| 00b9396dea | |||
| d2f08eb2dd | |||
| 8471516fd7 | |||
| dee91bccca | |||
| 9b4b0ab5f3 | |||
| f4a632a9c1 | |||
| e43dceab2c | |||
| dd9a8c5db8 | |||
| ff402be02f | |||
| 0a764a3a86 | |||
| f91772b019 | |||
| abc05de86e | |||
| 37c175289c | |||
| b02a789264 | |||
| 44db0d7853 | |||
| cc1dd017ce | |||
| ca1c7e66c5 | |||
| f6fb5aab78 | |||
| 4eba9dfc12 | |||
| 9fb7710079 | |||
| a21695e326 | |||
| a7fe908c1c | |||
| f1d94b18b2 | |||
| 632c9e5a93 | |||
| 6af789dd83 | |||
| 12fd0558d9 | |||
| c30b518105 | |||
| c2a2b4818e | |||
| 56b24901c6 | |||
| 7087c22259 | |||
| 746116d325 | |||
| db26820544 | |||
| 3488ad0605 | |||
| 659e562208 | |||
| d47f9c5360 | |||
| 540793c152 | |||
| 3aa2402808 | |||
| b0b77640f6 | |||
| fb1e4402dc | |||
| 97e32572cf | |||
| b4d6e0e23b | |||
| caf4742dd8 | |||
| c7142efa99 | |||
| c4edda8b4e | |||
| 63292ab810 | |||
| 2786c8e7bf | |||
| ecfed9bf6b | |||
| a562ecca72 | |||
| fa5e37f003 | |||
| e36b779a4a | |||
| 66451c189e | |||
| 310e8bc07d | |||
| f04512ac3f | |||
| a24c8280c9 | |||
| 9857797b80 | |||
| 870855d99c | |||
| 039c32ecf4 | |||
| 08498c97d0 | |||
| fc57f97c9e | |||
| 8a809e3cc0 | |||
| 0a192c4f33 | |||
| 426695e410 | |||
| 69e41fbbd9 | |||
| 3a460b9ac6 | |||
| f0d92b21be | |||
| a3edb7538a | |||
| 5d4a0dd00f | |||
| a69a20ee1e | |||
| 08c854222e | |||
| 7bb7f1f4fd | |||
| aa760b14a2 | |||
| 2e252eb70e | |||
| d16626d121 | |||
| 3bfc0e358f | |||
| 3814ea5e85 | |||
| c9a569fc42 | |||
| 348f4e0fe0 | |||
| 887fc5c7ef | |||
| e515a1429c | |||
| 7bcb9b126b | |||
| 043be04187 | |||
| e5fca206f0 | |||
| 91b9a6bcef | |||
| 63f9a174ed | |||
| b4f62ca6b9 | |||
| 8f850e651e | |||
| 08df13bfc7 | |||
| 60bafe7bc4 | |||
| f0618aad4b | |||
| 8fcccf72a5 | |||
| a68e82107e | |||
| 532dc20a2d | |||
| 65bd8894c9 | |||
| 4d60893dbe | |||
| c13bb5f35c | |||
| ed04b2d4b9 | |||
| bb505d7508 | |||
| cbc4d3b7d0 | |||
| e42dc5fbfa | |||
| 78a682e0ab | |||
| 60cec0276b | |||
| 7bf9d18b33 | |||
| 5f4abc5152 | |||
| 4139949405 | |||
| 363a0145d9 | |||
| 36cc934f7a | |||
| 72bcb73351 | |||
| c9cab898c2 | |||
| f3579ae9fe | |||
| 42beed5c93 | |||
| afd02b38e3 | |||
| b63b709032 | |||
| 340cbe8784 | |||
| d7a575d8c8 | |||
| 6c4183e175 | |||
| 0ca028f73d | |||
| c7063e02c2 | |||
| 75f25150c3 | |||
| 5b065fdcce | |||
| ca415cceef | |||
| 46fde766e5 | |||
| 630a3a6dde | |||
| 0ce969ef69 | |||
| ad754a704e | |||
| 7d984ebe64 | |||
| c8ebbc750e | |||
| 4927e815b5 | |||
| 7804adc54a | |||
| ef9a8ed0b6 | |||
| 1181162219 | |||
| 35a80279e6 | |||
| bb63cc12c3 | |||
| 91597e6b2c | |||
| 4cf7ef1bd1 | |||
| c2293f96cb | |||
| 51aa3931b9 | |||
| 1328b3d8cb | |||
| aa7a389ab2 | |||
| 6400cb51ca | |||
| 30d0e386fd | |||
| 1b5f185a03 | |||
| 29493b4fee | |||
| cc28a27ab0 | |||
| 6817e8e5cd | |||
| 21111aecf5 | |||
| 32ca130f90 | |||
| daeef0af0b | |||
| 4a759802dc | |||
| a225609cea | |||
| b2e54aafdb | |||
| a8bed5de36 | |||
| d6d246ee63 | |||
| cfd5345e93 | |||
| 02816fbb03 | |||
| 925ac68f20 | |||
| 106dc7f852 | |||
| 5b70ccd51f | |||
| cb3481b269 | |||
| 78564e2a1d | |||
| ec95d69e92 | |||
| 4b6eca953d | |||
| e8b21096a0 | |||
| d36da26c44 | |||
| 16498a4657 | |||
| eab300851a | |||
| 10cd89f9f9 | |||
| a6b80eadc3 | |||
| d827c8a1df | |||
| 909d578547 | |||
| dde080f69b | |||
| 0ab0483603 | |||
| af1d1c5ace | |||
| 4606888b0c | |||
| a14761c498 | |||
| f614e07b8f | |||
| 289b79affe | |||
| a6b0c24b66 | |||
| 9e1e5fb7db | |||
| 246d89fef6 | |||
| b7f2dae847 | |||
| 1c42f05e20 | |||
| b9c703b755 | |||
| f1062b34d2 | |||
| 174ee8241d | |||
| 529a59551c | |||
| 89122773af | |||
| bfb1a3bca4 | |||
| 28d9f9ee96 | |||
| a562564e88 | |||
| ca639ddd37 | |||
| 318eb6f234 | |||
| 6c9db806ae | |||
| 148c91a61c | |||
| 5864478ae0 | |||
| 202b55a489 | |||
| 67bea9375f | |||
| f80b83aee8 | |||
| 500b7c718e | |||
| 79672a38ec | |||
| b13861c869 | |||
| 4114571040 | |||
| a788a0022a | |||
| 27371fe321 | |||
| b30be5c053 | |||
| 040dbdef3c | |||
| 349eb5a338 | |||
| 1c53acbd1b | |||
| 16cbb32f35 | |||
| bcaaa527d4 | |||
| 2b990942c0 | |||
| f867e912e9 | |||
| b62a9f6240 | |||
| f45483bcba | |||
| 602dcd7cf1 | |||
| 40fcce2db3 | |||
| 36fbc9982c | |||
| 8b5fbd7e91 | |||
| 0fd4f51b5e | |||
| 9f5d213d99 | |||
| 03ec3a9fbb | |||
| 783afe0677 | |||
| adb9f157e6 | |||
| b03de378b0 | |||
| 5b51754c58 | |||
| 154d9ca8a2 | |||
| 4324633f82 | |||
| ad91c4420a | |||
| a41e701fed | |||
| fdb500c3dd | |||
| 9b6ebbedb3 | |||
| e21f049643 | |||
| 6fa42b90d5 | |||
| ed195bb5f4 | |||
| 148947781a | |||
| 9359184e38 | |||
| dfa7278184 | |||
| 955aec6b73 | |||
| 04ab62c988 | |||
| 39d36578fd | |||
| 4ffc4abff4 | |||
| 37b1595709 | |||
| ff28775635 | |||
| 8a74bfd639 | |||
| 8c99e1fad7 | |||
| c5fe9faf94 | |||
| a37b04aca0 | |||
| 23fca927d5 | |||
| 392b1b06bb | |||
| 0990a13c2e | |||
| 68c4ca7a96 | |||
| eefdae93fe | |||
| e9a41995be | |||
| e81887034c | |||
| 84a4b42f31 | |||
| 9b55b5558b | |||
| 6b32fe38c8 | |||
| 87d91db1ee | |||
| 1e5d11929e | |||
| 00231e0836 | |||
| a60a2c8173 | |||
| a9f395994b | |||
| 73c78ee6d7 | |||
| d7c6e0e7a8 | |||
| 5bcbf74dfc | |||
| 52c252f525 | |||
| b7ded61523 | |||
| 919f0e30b5 | |||
| 420efbc093 | |||
| b6188ce2c3 | |||
| be2d02cb8f | |||
| 050aec1db4 | |||
| c53cd7784a | |||
| 9ccc0b379d | |||
| 9c4598ab66 | |||
| d703309a34 | |||
| c8c1943f85 | |||
| bf001a6cf6 | |||
| c72309aa16 | |||
| fc4c0c543e | |||
| 759fb6deae | |||
| 0ea6ea206c | |||
| 168bc002f9 | |||
| 303c5e2a60 | |||
| bd1e247fcf | |||
| 03e7f260b2 | |||
| 63679a622f | |||
| e0c15b437e | |||
| 954a078d63 | |||
| 9139108744 | |||
| 5cf87391b6 | |||
| f9312475d0 | |||
| 3132f013b7 | |||
| 4a9730c38d | |||
| 29e43507ac | |||
| 1f33013216 | |||
| e5a35779f8 | |||
| e20f94fe17 | |||
| 877fd1935f | |||
| 37af4ba975 | |||
| 143601c251 | |||
| d2797d5b59 | |||
| 4f49fb7ce8 | |||
| 384cf8e078 | |||
| 2d07b032d9 | |||
| 11dcb03924 | |||
| 73badefcc5 | |||
| 477bba3003 | |||
| f114c6b168 | |||
| 211075b77c | |||
| 632a4240c4 | |||
| fc495ccceb | |||
| 312b92a81d | |||
| 8120058948 | |||
| 4ced484419 | |||
| 48b31e7cff | |||
| 58b63fa8d3 | |||
| dac7750fe1 | |||
| 1d7aa636a0 | |||
| 2947f0f741 | |||
| 0dff79dd51 | |||
| 769632dea8 | |||
| 855f169516 | |||
| f4de31f92b | |||
| 3d7b86f06d | |||
| 2ae3d83349 | |||
| 9da0d83914 | |||
| 5180526821 | |||
| 0d693eef5f | |||
| 4207528043 | |||
| 96c472bfb9 | |||
| 4ba5a88fc2 | |||
| 21cabb08c9 | |||
| 3d30d7e811 | |||
| cc1278ffcb | |||
| 8dcf23d7e4 | |||
| 57f515e2eb | |||
| 89d93c92ed | |||
| baaa7087b0 | |||
| a145c6fc0a | |||
| 41d4acdd72 | |||
| ff57afe388 | |||
| 476499832f | |||
| 5a7d1565e5 | |||
| 7bae5e56ff | |||
| a44a9ce242 | |||
| f951ec428d | |||
| 5c53b8cf2f | |||
| 0f0691d037 | |||
| 7985a9b0d7 | |||
| 779179af01 | |||
| d60a225368 | |||
| 212f7a0096 | |||
| cc16f89bbe | |||
| 3c2038e8fe | |||
| 700ab9def4 | |||
| 8853d08e5a | |||
| 7ec0904c5c | |||
| e2ae4b34b3 | |||
| f0cbcfa949 | |||
| 91b569ffd3 | |||
| 0f5b8a4f52 | |||
| 1caaec5601 | |||
| 94414057e6 | |||
| 76fd17c727 | |||
| 5f30220609 | |||
| a599047cf0 | |||
| 95dd259913 | |||
| ff097cce3c | |||
| aeffb8e4d4 | |||
| 27b52da0e5 | |||
| 5233a485eb | |||
| 7643740eda | |||
| 0662901b1b | |||
| 72d23af335 | |||
| 1eb58ea331 | |||
| 0c5e218aa8 | |||
| 3f5d0e9539 | |||
| ffe35c048d | |||
| 2219d7e26e | |||
| 0ff64d2737 | |||
| 28d402d204 | |||
| 9a98bdfbe6 | |||
| cb2e962116 | |||
| 7bbc4c18d7 | |||
| e7436e7898 | |||
| 4ef95eaa27 | |||
| efc4dfd752 | |||
| 3ad67a1610 | |||
| 4fe3c1eed9 | |||
| b170724f3f | |||
| 8b18c7159f | |||
| aa9a9318f5 | |||
| 2c5d4cedea | |||
| 39d03d30a8 | |||
| e7440e5e84 | |||
| f37530fa0e | |||
| 43956d286e | |||
| 157aee3812 | |||
| 6a8ba4fbc8 | |||
| 1e2c304754 | |||
| 8ac540c65b | |||
| 9c8f7b1a95 | |||
| 7fb86bfe21 | |||
| c52998671b | |||
| 9147dc0d01 | |||
| a5e4c5f46f | |||
| b366c9888f | |||
| 6d73e50bff | |||
| ba4f9113ae |
@@ -144,3 +144,7 @@ class ChatStateService
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 2.5 迁移文件注意事项
|
||||
|
||||
同时新建多个迁移文件时,要注意 是否有关联主键问题,主键所在表要先创建,所以迁移文件名称 要比被调用表文件名的靠前,否则执行迁移时会报错;
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
---
|
||||
name: tailwindcss-development
|
||||
description: "Styles applications using Tailwind CSS v4 utilities. Activates when adding styles, restyling components, working with gradients, spacing, layout, flex, grid, responsive design, dark mode, colors, typography, or borders; or when the user mentions CSS, styling, classes, Tailwind, restyle, hero section, cards, buttons, or any visual/UI changes."
|
||||
license: MIT
|
||||
metadata:
|
||||
author: laravel
|
||||
---
|
||||
|
||||
# Tailwind CSS Development
|
||||
|
||||
## When to Apply
|
||||
|
||||
Activate this skill when:
|
||||
|
||||
- Adding styles to components or pages
|
||||
- Working with responsive design
|
||||
- Implementing dark mode
|
||||
- Extracting repeated patterns into components
|
||||
- Debugging spacing or layout issues
|
||||
|
||||
## Documentation
|
||||
|
||||
Use `search-docs` for detailed Tailwind CSS v4 patterns and documentation.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
- Use Tailwind CSS classes to style HTML. Check and follow existing Tailwind conventions in the project before introducing new patterns.
|
||||
- Offer to extract repeated patterns into components that match the project's conventions (e.g., Blade, JSX, Vue).
|
||||
- Consider class placement, order, priority, and defaults. Remove redundant classes, add classes to parent or child elements carefully to reduce repetition, and group elements logically.
|
||||
|
||||
## Tailwind CSS v4 Specifics
|
||||
|
||||
- Always use Tailwind CSS v4 and avoid deprecated utilities.
|
||||
- `corePlugins` is not supported in Tailwind v4.
|
||||
|
||||
### CSS-First Configuration
|
||||
|
||||
In Tailwind v4, configuration is CSS-first using the `@theme` directive — no separate `tailwind.config.js` file is needed:
|
||||
|
||||
<!-- CSS-First Config -->
|
||||
```css
|
||||
@theme {
|
||||
--color-brand: oklch(0.72 0.11 178);
|
||||
}
|
||||
```
|
||||
|
||||
### Import Syntax
|
||||
|
||||
In Tailwind v4, import Tailwind with a regular CSS `@import` statement instead of the `@tailwind` directives used in v3:
|
||||
|
||||
<!-- v4 Import Syntax -->
|
||||
```diff
|
||||
- @tailwind base;
|
||||
- @tailwind components;
|
||||
- @tailwind utilities;
|
||||
+ @import "tailwindcss";
|
||||
```
|
||||
|
||||
### Replaced Utilities
|
||||
|
||||
Tailwind v4 removed deprecated utilities. Use the replacements shown below. Opacity values remain numeric.
|
||||
|
||||
| Deprecated | Replacement |
|
||||
|------------|-------------|
|
||||
| bg-opacity-* | bg-black/* |
|
||||
| text-opacity-* | text-black/* |
|
||||
| border-opacity-* | border-black/* |
|
||||
| divide-opacity-* | divide-black/* |
|
||||
| ring-opacity-* | ring-black/* |
|
||||
| placeholder-opacity-* | placeholder-black/* |
|
||||
| flex-shrink-* | shrink-* |
|
||||
| flex-grow-* | grow-* |
|
||||
| overflow-ellipsis | text-ellipsis |
|
||||
| decoration-slice | box-decoration-slice |
|
||||
| decoration-clone | box-decoration-clone |
|
||||
|
||||
## Spacing
|
||||
|
||||
Use `gap` utilities instead of margins for spacing between siblings:
|
||||
|
||||
<!-- Gap Utilities -->
|
||||
```html
|
||||
<div class="flex gap-8">
|
||||
<div>Item 1</div>
|
||||
<div>Item 2</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Dark Mode
|
||||
|
||||
If existing pages and components support dark mode, new pages and components must support it the same way, typically using the `dark:` variant:
|
||||
|
||||
<!-- Dark Mode -->
|
||||
```html
|
||||
<div class="bg-white dark:bg-gray-900 text-gray-900 dark:text-white">
|
||||
Content adapts to color scheme
|
||||
</div>
|
||||
```
|
||||
|
||||
## Common Patterns
|
||||
|
||||
### Flexbox Layout
|
||||
|
||||
<!-- Flexbox Layout -->
|
||||
```html
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<div>Left content</div>
|
||||
<div>Right content</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
### Grid Layout
|
||||
|
||||
<!-- Grid Layout -->
|
||||
```html
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
<div>Card 1</div>
|
||||
<div>Card 2</div>
|
||||
<div>Card 3</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Common Pitfalls
|
||||
|
||||
- Using deprecated v3 utilities (bg-opacity-*, flex-shrink-*, etc.)
|
||||
- Using `@tailwind` directives instead of `@import "tailwindcss"`
|
||||
- Trying to use `tailwind.config.js` instead of CSS `@theme` directive
|
||||
- Using margins for spacing between siblings instead of gap utilities
|
||||
- Forgetting to add dark mode variants when the project uses dark mode
|
||||
@@ -0,0 +1,12 @@
|
||||
# THIS IS AUTOGENERATED. DO NOT EDIT MANUALLY
|
||||
version = 1
|
||||
name = "chatroom"
|
||||
|
||||
[setup]
|
||||
script = ""
|
||||
|
||||
[cleanup]
|
||||
script = '''
|
||||
php artisan reverb:start
|
||||
php artisan horizon
|
||||
'''
|
||||
@@ -0,0 +1,14 @@
|
||||
# THIS IS AUTOGENERATED. DO NOT EDIT MANUALLY
|
||||
version = 1
|
||||
name = "chatroom"
|
||||
|
||||
[setup]
|
||||
script = ""
|
||||
|
||||
[[actions]]
|
||||
name = "启动ws"
|
||||
icon = "tool"
|
||||
command = '''
|
||||
php artisan reverb:start
|
||||
php artisan horizon
|
||||
'''
|
||||
@@ -3,6 +3,7 @@ APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
APP_FORCE_HTTPS=false
|
||||
|
||||
APP_LOCALE=en
|
||||
APP_FALLBACK_LOCALE=en
|
||||
@@ -32,6 +33,7 @@ SESSION_LIFETIME=120
|
||||
SESSION_ENCRYPT=false
|
||||
SESSION_PATH=/
|
||||
SESSION_DOMAIN=null
|
||||
TRUSTED_PROXIES=127.0.0.1,::1
|
||||
|
||||
BROADCAST_CONNECTION=log
|
||||
FILESYSTEM_DISK=local
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"mcpServers": {
|
||||
"laravel-boost": {
|
||||
"command": "php",
|
||||
"args": [
|
||||
"artisan",
|
||||
"boost:mcp"
|
||||
]
|
||||
},
|
||||
"herd": {
|
||||
"command": "php",
|
||||
"args": [
|
||||
"/Applications/Herd.app/Contents/Resources/herd-mcp.phar"
|
||||
],
|
||||
"env": {
|
||||
"SITE_PATH": "/Users/pllx/Web/Herd/chatroom"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
---
|
||||
name: tailwindcss-development
|
||||
description: "Styles applications using Tailwind CSS v4 utilities. Activates when adding styles, restyling components, working with gradients, spacing, layout, flex, grid, responsive design, dark mode, colors, typography, or borders; or when the user mentions CSS, styling, classes, Tailwind, restyle, hero section, cards, buttons, or any visual/UI changes."
|
||||
license: MIT
|
||||
metadata:
|
||||
author: laravel
|
||||
---
|
||||
|
||||
# Tailwind CSS Development
|
||||
|
||||
## When to Apply
|
||||
|
||||
Activate this skill when:
|
||||
|
||||
- Adding styles to components or pages
|
||||
- Working with responsive design
|
||||
- Implementing dark mode
|
||||
- Extracting repeated patterns into components
|
||||
- Debugging spacing or layout issues
|
||||
|
||||
## Documentation
|
||||
|
||||
Use `search-docs` for detailed Tailwind CSS v4 patterns and documentation.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
- Use Tailwind CSS classes to style HTML. Check and follow existing Tailwind conventions in the project before introducing new patterns.
|
||||
- Offer to extract repeated patterns into components that match the project's conventions (e.g., Blade, JSX, Vue).
|
||||
- Consider class placement, order, priority, and defaults. Remove redundant classes, add classes to parent or child elements carefully to reduce repetition, and group elements logically.
|
||||
|
||||
## Tailwind CSS v4 Specifics
|
||||
|
||||
- Always use Tailwind CSS v4 and avoid deprecated utilities.
|
||||
- `corePlugins` is not supported in Tailwind v4.
|
||||
|
||||
### CSS-First Configuration
|
||||
|
||||
In Tailwind v4, configuration is CSS-first using the `@theme` directive — no separate `tailwind.config.js` file is needed:
|
||||
|
||||
<!-- CSS-First Config -->
|
||||
```css
|
||||
@theme {
|
||||
--color-brand: oklch(0.72 0.11 178);
|
||||
}
|
||||
```
|
||||
|
||||
### Import Syntax
|
||||
|
||||
In Tailwind v4, import Tailwind with a regular CSS `@import` statement instead of the `@tailwind` directives used in v3:
|
||||
|
||||
<!-- v4 Import Syntax -->
|
||||
```diff
|
||||
- @tailwind base;
|
||||
- @tailwind components;
|
||||
- @tailwind utilities;
|
||||
+ @import "tailwindcss";
|
||||
```
|
||||
|
||||
### Replaced Utilities
|
||||
|
||||
Tailwind v4 removed deprecated utilities. Use the replacements shown below. Opacity values remain numeric.
|
||||
|
||||
| Deprecated | Replacement |
|
||||
|------------|-------------|
|
||||
| bg-opacity-* | bg-black/* |
|
||||
| text-opacity-* | text-black/* |
|
||||
| border-opacity-* | border-black/* |
|
||||
| divide-opacity-* | divide-black/* |
|
||||
| ring-opacity-* | ring-black/* |
|
||||
| placeholder-opacity-* | placeholder-black/* |
|
||||
| flex-shrink-* | shrink-* |
|
||||
| flex-grow-* | grow-* |
|
||||
| overflow-ellipsis | text-ellipsis |
|
||||
| decoration-slice | box-decoration-slice |
|
||||
| decoration-clone | box-decoration-clone |
|
||||
|
||||
## Spacing
|
||||
|
||||
Use `gap` utilities instead of margins for spacing between siblings:
|
||||
|
||||
<!-- Gap Utilities -->
|
||||
```html
|
||||
<div class="flex gap-8">
|
||||
<div>Item 1</div>
|
||||
<div>Item 2</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Dark Mode
|
||||
|
||||
If existing pages and components support dark mode, new pages and components must support it the same way, typically using the `dark:` variant:
|
||||
|
||||
<!-- Dark Mode -->
|
||||
```html
|
||||
<div class="bg-white dark:bg-gray-900 text-gray-900 dark:text-white">
|
||||
Content adapts to color scheme
|
||||
</div>
|
||||
```
|
||||
|
||||
## Common Patterns
|
||||
|
||||
### Flexbox Layout
|
||||
|
||||
<!-- Flexbox Layout -->
|
||||
```html
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<div>Left content</div>
|
||||
<div>Right content</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
### Grid Layout
|
||||
|
||||
<!-- Grid Layout -->
|
||||
```html
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
<div>Card 1</div>
|
||||
<div>Card 2</div>
|
||||
<div>Card 3</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Common Pitfalls
|
||||
|
||||
- Using deprecated v3 utilities (bg-opacity-*, flex-shrink-*, etc.)
|
||||
- Using `@tailwind` directives instead of `@import "tailwindcss"`
|
||||
- Trying to use `tailwind.config.js` instead of CSS `@theme` directive
|
||||
- Using margins for spacing between siblings instead of gap utilities
|
||||
- Forgetting to add dark mode variants when the project uses dark mode
|
||||
@@ -11,6 +11,10 @@
|
||||
/.phpunit.cache
|
||||
/.vscode
|
||||
/.zed
|
||||
/.junie
|
||||
/.github
|
||||
/.gemini
|
||||
/.agents
|
||||
/auth.json
|
||||
/node_modules
|
||||
/public/build
|
||||
@@ -24,3 +28,5 @@ Homestead.yaml
|
||||
Thumbs.db
|
||||
vendor.zip
|
||||
test-captcha.php
|
||||
public/.user.ini
|
||||
dump.rdb
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
<laravel-boost-guidelines>
|
||||
=== foundation rules ===
|
||||
|
||||
# Laravel Boost Guidelines
|
||||
|
||||
The Laravel Boost guidelines are specifically curated by Laravel maintainers for this application. These guidelines should be followed closely to ensure the best experience when building Laravel applications.
|
||||
|
||||
## Foundational Context
|
||||
|
||||
This application is a Laravel application and its main Laravel ecosystems package & versions are below. You are an expert with them all. Ensure you abide by these specific packages & versions.
|
||||
|
||||
- php - 8.4.5
|
||||
- laravel/framework (LARAVEL) - v12
|
||||
- laravel/horizon (HORIZON) - v5
|
||||
- laravel/prompts (PROMPTS) - v0
|
||||
- laravel/reverb (REVERB) - v1
|
||||
- laravel/boost (BOOST) - v2
|
||||
- laravel/mcp (MCP) - v0
|
||||
- laravel/pail (PAIL) - v1
|
||||
- laravel/pint (PINT) - v1
|
||||
- laravel/sail (SAIL) - v1
|
||||
- phpunit/phpunit (PHPUNIT) - v11
|
||||
- laravel-echo (ECHO) - v2
|
||||
- tailwindcss (TAILWINDCSS) - v4
|
||||
|
||||
## Skills Activation
|
||||
|
||||
This project has domain-specific skills available. You MUST activate the relevant skill whenever you work in that domain—don't wait until you're stuck.
|
||||
|
||||
- `tailwindcss-development` — Styles applications using Tailwind CSS v4 utilities. Activates when adding styles, restyling components, working with gradients, spacing, layout, flex, grid, responsive design, dark mode, colors, typography, or borders; or when the user mentions CSS, styling, classes, Tailwind, restyle, hero section, cards, buttons, or any visual/UI changes.
|
||||
|
||||
## Conventions
|
||||
|
||||
- You must follow all existing code conventions used in this application. When creating or editing a file, check sibling files for the correct structure, approach, and naming.
|
||||
- Use descriptive names for variables and methods. For example, `isRegisteredForDiscounts`, not `discount()`.
|
||||
- Check for existing components to reuse before writing a new one.
|
||||
|
||||
## Verification Scripts
|
||||
|
||||
- Do not create verification scripts or tinker when tests cover that functionality and prove they work. Unit and feature tests are more important.
|
||||
|
||||
## Application Structure & Architecture
|
||||
|
||||
- Stick to existing directory structure; don't create new base folders without approval.
|
||||
- Do not change the application's dependencies without approval.
|
||||
|
||||
## Frontend Bundling
|
||||
|
||||
- If the user doesn't see a frontend change reflected in the UI, it could mean they need to run `npm run build`, `npm run dev`, or `composer run dev`. Ask them.
|
||||
|
||||
## Documentation Files
|
||||
|
||||
- You must only create documentation files if explicitly requested by the user.
|
||||
|
||||
## Replies
|
||||
|
||||
- Be concise in your explanations - focus on what's important rather than explaining obvious details.
|
||||
|
||||
=== boost rules ===
|
||||
|
||||
# Laravel Boost
|
||||
|
||||
- Laravel Boost is an MCP server that comes with powerful tools designed specifically for this application. Use them.
|
||||
|
||||
## Artisan
|
||||
|
||||
- Use the `list-artisan-commands` tool when you need to call an Artisan command to double-check the available parameters.
|
||||
|
||||
## URLs
|
||||
|
||||
- Whenever you share a project URL with the user, you should use the `get-absolute-url` tool to ensure you're using the correct scheme, domain/IP, and port.
|
||||
|
||||
## Tinker / Debugging
|
||||
|
||||
- You should use the `tinker` tool when you need to execute PHP to debug code or query Eloquent models directly.
|
||||
- Use the `database-query` tool when you only need to read from the database.
|
||||
- Use the `database-schema` tool to inspect table structure before writing migrations or models.
|
||||
|
||||
## Reading Browser Logs With the `browser-logs` Tool
|
||||
|
||||
- You can read browser logs, errors, and exceptions using the `browser-logs` tool from Boost.
|
||||
- Only recent browser logs will be useful - ignore old logs.
|
||||
|
||||
## Searching Documentation (Critically Important)
|
||||
|
||||
- Boost comes with a powerful `search-docs` tool you should use before trying other approaches when working with Laravel or Laravel ecosystem packages. This tool automatically passes a list of installed packages and their versions to the remote Boost API, so it returns only version-specific documentation for the user's circumstance. You should pass an array of packages to filter on if you know you need docs for particular packages.
|
||||
- Search the documentation before making code changes to ensure we are taking the correct approach.
|
||||
- Use multiple, broad, simple, topic-based queries at once. For example: `['rate limiting', 'routing rate limiting', 'routing']`. The most relevant results will be returned first.
|
||||
- Do not add package names to queries; package information is already shared. For example, use `test resource table`, not `filament 4 test resource table`.
|
||||
|
||||
### Available Search Syntax
|
||||
|
||||
1. Simple Word Searches with auto-stemming - query=authentication - finds 'authenticate' and 'auth'.
|
||||
2. Multiple Words (AND Logic) - query=rate limit - finds knowledge containing both "rate" AND "limit".
|
||||
3. Quoted Phrases (Exact Position) - query="infinite scroll" - words must be adjacent and in that order.
|
||||
4. Mixed Queries - query=middleware "rate limit" - "middleware" AND exact phrase "rate limit".
|
||||
5. Multiple Queries - queries=["authentication", "middleware"] - ANY of these terms.
|
||||
|
||||
=== php rules ===
|
||||
|
||||
# PHP
|
||||
|
||||
- Always use curly braces for control structures, even for single-line bodies.
|
||||
|
||||
## Constructors
|
||||
|
||||
- Use PHP 8 constructor property promotion in `__construct()`.
|
||||
- `public function __construct(public GitHub $github) { }`
|
||||
- Do not allow empty `__construct()` methods with zero parameters unless the constructor is private.
|
||||
|
||||
## Type Declarations
|
||||
|
||||
- Always use explicit return type declarations for methods and functions.
|
||||
- Use appropriate PHP type hints for method parameters.
|
||||
|
||||
<!-- Explicit Return Types and Method Params -->
|
||||
```php
|
||||
protected function isAccessible(User $user, ?string $path = null): bool
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Enums
|
||||
|
||||
- Typically, keys in an Enum should be TitleCase. For example: `FavoritePerson`, `BestLake`, `Monthly`.
|
||||
|
||||
## Comments
|
||||
|
||||
- Prefer PHPDoc blocks over inline comments. Never use comments within the code itself unless the logic is exceptionally complex.
|
||||
|
||||
## PHPDoc Blocks
|
||||
|
||||
- Add useful array shape type definitions when appropriate.
|
||||
|
||||
=== herd rules ===
|
||||
|
||||
# Laravel Herd
|
||||
|
||||
- The application is served by Laravel Herd and will be available at: `https?://[kebab-case-project-dir].test`. Use the `get-absolute-url` tool to generate valid URLs for the user.
|
||||
- You must not run any commands to make the site available via HTTP(S). It is always available through Laravel Herd.
|
||||
|
||||
=== laravel/core rules ===
|
||||
|
||||
# Do Things the Laravel Way
|
||||
|
||||
- Use `php artisan make:` commands to create new files (i.e. migrations, controllers, models, etc.). You can list available Artisan commands using the `list-artisan-commands` tool.
|
||||
- If you're creating a generic PHP class, use `php artisan make:class`.
|
||||
- Pass `--no-interaction` to all Artisan commands to ensure they work without user input. You should also pass the correct `--options` to ensure correct behavior.
|
||||
|
||||
## Database
|
||||
|
||||
- Always use proper Eloquent relationship methods with return type hints. Prefer relationship methods over raw queries or manual joins.
|
||||
- Use Eloquent models and relationships before suggesting raw database queries.
|
||||
- Avoid `DB::`; prefer `Model::query()`. Generate code that leverages Laravel's ORM capabilities rather than bypassing them.
|
||||
- Generate code that prevents N+1 query problems by using eager loading.
|
||||
- Use Laravel's query builder for very complex database operations.
|
||||
|
||||
### Model Creation
|
||||
|
||||
- When creating new models, create useful factories and seeders for them too. Ask the user if they need any other things, using `list-artisan-commands` to check the available options to `php artisan make:model`.
|
||||
|
||||
### APIs & Eloquent Resources
|
||||
|
||||
- For APIs, default to using Eloquent API Resources and API versioning unless existing API routes do not, then you should follow existing application convention.
|
||||
|
||||
## Controllers & Validation
|
||||
|
||||
- Always create Form Request classes for validation rather than inline validation in controllers. Include both validation rules and custom error messages.
|
||||
- Check sibling Form Requests to see if the application uses array or string based validation rules.
|
||||
|
||||
## Authentication & Authorization
|
||||
|
||||
- Use Laravel's built-in authentication and authorization features (gates, policies, Sanctum, etc.).
|
||||
|
||||
## URL Generation
|
||||
|
||||
- When generating links to other pages, prefer named routes and the `route()` function.
|
||||
|
||||
## Queues
|
||||
|
||||
- Use queued jobs for time-consuming operations with the `ShouldQueue` interface.
|
||||
|
||||
## Configuration
|
||||
|
||||
- Use environment variables only in configuration files - never use the `env()` function directly outside of config files. Always use `config('app.name')`, not `env('APP_NAME')`.
|
||||
|
||||
## Testing
|
||||
|
||||
- When creating models for tests, use the factories for the models. Check if the factory has custom states that can be used before manually setting up the model.
|
||||
- Faker: Use methods such as `$this->faker->word()` or `fake()->randomDigit()`. Follow existing conventions whether to use `$this->faker` or `fake()`.
|
||||
- When creating tests, make use of `php artisan make:test [options] {name}` to create a feature test, and pass `--unit` to create a unit test. Most tests should be feature tests.
|
||||
|
||||
## Vite Error
|
||||
|
||||
- If you receive an "Illuminate\Foundation\ViteException: Unable to locate file in Vite manifest" error, you can run `npm run build` or ask the user to run `npm run dev` or `composer run dev`.
|
||||
|
||||
=== laravel/v12 rules ===
|
||||
|
||||
# Laravel 12
|
||||
|
||||
- CRITICAL: ALWAYS use `search-docs` tool for version-specific Laravel documentation and updated code examples.
|
||||
- Since Laravel 11, Laravel has a new streamlined file structure which this project uses.
|
||||
|
||||
## Laravel 12 Structure
|
||||
|
||||
- In Laravel 12, middleware are no longer registered in `app/Http/Kernel.php`.
|
||||
- Middleware are configured declaratively in `bootstrap/app.php` using `Application::configure()->withMiddleware()`.
|
||||
- `bootstrap/app.php` is the file to register middleware, exceptions, and routing files.
|
||||
- `bootstrap/providers.php` contains application specific service providers.
|
||||
- The `app\Console\Kernel.php` file no longer exists; use `bootstrap/app.php` or `routes/console.php` for console configuration.
|
||||
- Console commands in `app/Console/Commands/` are automatically available and do not require manual registration.
|
||||
|
||||
## Database
|
||||
|
||||
- When modifying a column, the migration must include all of the attributes that were previously defined on the column. Otherwise, they will be dropped and lost.
|
||||
- Laravel 12 allows limiting eagerly loaded records natively, without external packages: `$query->latest()->limit(10);`.
|
||||
|
||||
### Models
|
||||
|
||||
- Casts can and likely should be set in a `casts()` method on a model rather than the `$casts` property. Follow existing conventions from other models.
|
||||
|
||||
=== pint/core rules ===
|
||||
|
||||
# Laravel Pint Code Formatter
|
||||
|
||||
- If you have modified any PHP files, you must run `vendor/bin/pint --dirty --format agent` before finalizing changes to ensure your code matches the project's expected style.
|
||||
- Do not run `vendor/bin/pint --test --format agent`, simply run `vendor/bin/pint --format agent` to fix any formatting issues.
|
||||
|
||||
=== phpunit/core rules ===
|
||||
|
||||
# PHPUnit
|
||||
|
||||
- This application uses PHPUnit for testing. All tests must be written as PHPUnit classes. Use `php artisan make:test --phpunit {name}` to create a new test.
|
||||
- If you see a test using "Pest", convert it to PHPUnit.
|
||||
- Every time a test has been updated, run that singular test.
|
||||
- When the tests relating to your feature are passing, ask the user if they would like to also run the entire test suite to make sure everything is still passing.
|
||||
- Tests should cover all happy paths, failure paths, and edge cases.
|
||||
- You must not remove any tests or test files from the tests directory without approval. These are not temporary or helper files; these are core to the application.
|
||||
|
||||
## Running Tests
|
||||
|
||||
- Run the minimal number of tests, using an appropriate filter, before finalizing.
|
||||
- To run all tests: `php artisan test --compact`.
|
||||
- To run all tests in a file: `php artisan test --compact tests/Feature/ExampleTest.php`.
|
||||
- To filter on a particular test name: `php artisan test --compact --filter=testName` (recommended after making a change to a related file).
|
||||
|
||||
=== tailwindcss/core rules ===
|
||||
|
||||
# Tailwind CSS
|
||||
|
||||
- Always use existing Tailwind conventions; check project patterns before adding new ones.
|
||||
- IMPORTANT: Always use `search-docs` tool for version-specific Tailwind CSS documentation and updated code examples. Never rely on training data.
|
||||
- IMPORTANT: Activate `tailwindcss-development` every time you're working with a Tailwind CSS or styling-related task.
|
||||
|
||||
</laravel-boost-guidelines>
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"mcpServers": {
|
||||
"laravel-boost": {
|
||||
"command": "/opt/homebrew/Cellar/php/8.4.5_1/bin/php",
|
||||
"args": [
|
||||
"/Users/pllx/Web/Herd/chatroom/artisan",
|
||||
"boost:mcp"
|
||||
]
|
||||
},
|
||||
"herd": {
|
||||
"command": "/opt/homebrew/Cellar/php/8.4.5_1/bin/php",
|
||||
"args": [
|
||||
"/Applications/Herd.app/Contents/Resources/herd-mcp.phar"
|
||||
],
|
||||
"env": {
|
||||
"SITE_PATH": "/Users/pllx/Web/Herd/chatroom"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
---
|
||||
name: tailwindcss-development
|
||||
description: "Styles applications using Tailwind CSS v4 utilities. Activates when adding styles, restyling components, working with gradients, spacing, layout, flex, grid, responsive design, dark mode, colors, typography, or borders; or when the user mentions CSS, styling, classes, Tailwind, restyle, hero section, cards, buttons, or any visual/UI changes."
|
||||
license: MIT
|
||||
metadata:
|
||||
author: laravel
|
||||
---
|
||||
|
||||
# Tailwind CSS Development
|
||||
|
||||
## When to Apply
|
||||
|
||||
Activate this skill when:
|
||||
|
||||
- Adding styles to components or pages
|
||||
- Working with responsive design
|
||||
- Implementing dark mode
|
||||
- Extracting repeated patterns into components
|
||||
- Debugging spacing or layout issues
|
||||
|
||||
## Documentation
|
||||
|
||||
Use `search-docs` for detailed Tailwind CSS v4 patterns and documentation.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
- Use Tailwind CSS classes to style HTML. Check and follow existing Tailwind conventions in the project before introducing new patterns.
|
||||
- Offer to extract repeated patterns into components that match the project's conventions (e.g., Blade, JSX, Vue).
|
||||
- Consider class placement, order, priority, and defaults. Remove redundant classes, add classes to parent or child elements carefully to reduce repetition, and group elements logically.
|
||||
|
||||
## Tailwind CSS v4 Specifics
|
||||
|
||||
- Always use Tailwind CSS v4 and avoid deprecated utilities.
|
||||
- `corePlugins` is not supported in Tailwind v4.
|
||||
|
||||
### CSS-First Configuration
|
||||
|
||||
In Tailwind v4, configuration is CSS-first using the `@theme` directive — no separate `tailwind.config.js` file is needed:
|
||||
|
||||
<!-- CSS-First Config -->
|
||||
```css
|
||||
@theme {
|
||||
--color-brand: oklch(0.72 0.11 178);
|
||||
}
|
||||
```
|
||||
|
||||
### Import Syntax
|
||||
|
||||
In Tailwind v4, import Tailwind with a regular CSS `@import` statement instead of the `@tailwind` directives used in v3:
|
||||
|
||||
<!-- v4 Import Syntax -->
|
||||
```diff
|
||||
- @tailwind base;
|
||||
- @tailwind components;
|
||||
- @tailwind utilities;
|
||||
+ @import "tailwindcss";
|
||||
```
|
||||
|
||||
### Replaced Utilities
|
||||
|
||||
Tailwind v4 removed deprecated utilities. Use the replacements shown below. Opacity values remain numeric.
|
||||
|
||||
| Deprecated | Replacement |
|
||||
|------------|-------------|
|
||||
| bg-opacity-* | bg-black/* |
|
||||
| text-opacity-* | text-black/* |
|
||||
| border-opacity-* | border-black/* |
|
||||
| divide-opacity-* | divide-black/* |
|
||||
| ring-opacity-* | ring-black/* |
|
||||
| placeholder-opacity-* | placeholder-black/* |
|
||||
| flex-shrink-* | shrink-* |
|
||||
| flex-grow-* | grow-* |
|
||||
| overflow-ellipsis | text-ellipsis |
|
||||
| decoration-slice | box-decoration-slice |
|
||||
| decoration-clone | box-decoration-clone |
|
||||
|
||||
## Spacing
|
||||
|
||||
Use `gap` utilities instead of margins for spacing between siblings:
|
||||
|
||||
<!-- Gap Utilities -->
|
||||
```html
|
||||
<div class="flex gap-8">
|
||||
<div>Item 1</div>
|
||||
<div>Item 2</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Dark Mode
|
||||
|
||||
If existing pages and components support dark mode, new pages and components must support it the same way, typically using the `dark:` variant:
|
||||
|
||||
<!-- Dark Mode -->
|
||||
```html
|
||||
<div class="bg-white dark:bg-gray-900 text-gray-900 dark:text-white">
|
||||
Content adapts to color scheme
|
||||
</div>
|
||||
```
|
||||
|
||||
## Common Patterns
|
||||
|
||||
### Flexbox Layout
|
||||
|
||||
<!-- Flexbox Layout -->
|
||||
```html
|
||||
<div class="flex items-center justify-between gap-4">
|
||||
<div>Left content</div>
|
||||
<div>Right content</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
### Grid Layout
|
||||
|
||||
<!-- Grid Layout -->
|
||||
```html
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
<div>Card 1</div>
|
||||
<div>Card 2</div>
|
||||
<div>Card 3</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
## Common Pitfalls
|
||||
|
||||
- Using deprecated v3 utilities (bg-opacity-*, flex-shrink-*, etc.)
|
||||
- Using `@tailwind` directives instead of `@import "tailwindcss"`
|
||||
- Trying to use `tailwind.config.js` instead of CSS `@theme` directive
|
||||
- Using margins for spacing between siblings instead of gap utilities
|
||||
- Forgetting to add dark mode variants when the project uses dark mode
|
||||
@@ -0,0 +1,256 @@
|
||||
<laravel-boost-guidelines>
|
||||
=== foundation rules ===
|
||||
|
||||
# Laravel Boost Guidelines
|
||||
|
||||
The Laravel Boost guidelines are specifically curated by Laravel maintainers for this application. These guidelines should be followed closely to ensure the best experience when building Laravel applications.
|
||||
|
||||
## Foundational Context
|
||||
|
||||
This application is a Laravel application and its main Laravel ecosystems package & versions are below. You are an expert with them all. Ensure you abide by these specific packages & versions.
|
||||
|
||||
- php - 8.4.5
|
||||
- laravel/framework (LARAVEL) - v12
|
||||
- laravel/horizon (HORIZON) - v5
|
||||
- laravel/prompts (PROMPTS) - v0
|
||||
- laravel/reverb (REVERB) - v1
|
||||
- laravel/boost (BOOST) - v2
|
||||
- laravel/mcp (MCP) - v0
|
||||
- laravel/pail (PAIL) - v1
|
||||
- laravel/pint (PINT) - v1
|
||||
- laravel/sail (SAIL) - v1
|
||||
- phpunit/phpunit (PHPUNIT) - v11
|
||||
- laravel-echo (ECHO) - v2
|
||||
- tailwindcss (TAILWINDCSS) - v4
|
||||
|
||||
## Skills Activation
|
||||
|
||||
This project has domain-specific skills available. You MUST activate the relevant skill whenever you work in that domain—don't wait until you're stuck.
|
||||
|
||||
- `tailwindcss-development` — Styles applications using Tailwind CSS v4 utilities. Activates when adding styles, restyling components, working with gradients, spacing, layout, flex, grid, responsive design, dark mode, colors, typography, or borders; or when the user mentions CSS, styling, classes, Tailwind, restyle, hero section, cards, buttons, or any visual/UI changes.
|
||||
|
||||
## Conventions
|
||||
|
||||
- You must follow all existing code conventions used in this application. When creating or editing a file, check sibling files for the correct structure, approach, and naming.
|
||||
- Use descriptive names for variables and methods. For example, `isRegisteredForDiscounts`, not `discount()`.
|
||||
- Check for existing components to reuse before writing a new one.
|
||||
|
||||
## Verification Scripts
|
||||
|
||||
- Do not create verification scripts or tinker when tests cover that functionality and prove they work. Unit and feature tests are more important.
|
||||
|
||||
## Application Structure & Architecture
|
||||
|
||||
- Stick to existing directory structure; don't create new base folders without approval.
|
||||
- Do not change the application's dependencies without approval.
|
||||
|
||||
## Frontend Bundling
|
||||
|
||||
- If the user doesn't see a frontend change reflected in the UI, it could mean they need to run `npm run build`, `npm run dev`, or `composer run dev`. Ask them.
|
||||
|
||||
## Documentation Files
|
||||
|
||||
- You must only create documentation files if explicitly requested by the user.
|
||||
|
||||
## Replies
|
||||
|
||||
- Be concise in your explanations - focus on what's important rather than explaining obvious details.
|
||||
|
||||
=== boost rules ===
|
||||
|
||||
# Laravel Boost
|
||||
|
||||
- Laravel Boost is an MCP server that comes with powerful tools designed specifically for this application. Use them.
|
||||
|
||||
## Artisan
|
||||
|
||||
- Use the `list-artisan-commands` tool when you need to call an Artisan command to double-check the available parameters.
|
||||
|
||||
## URLs
|
||||
|
||||
- Whenever you share a project URL with the user, you should use the `get-absolute-url` tool to ensure you're using the correct scheme, domain/IP, and port.
|
||||
|
||||
## Tinker / Debugging
|
||||
|
||||
- You should use the `tinker` tool when you need to execute PHP to debug code or query Eloquent models directly.
|
||||
- Use the `database-query` tool when you only need to read from the database.
|
||||
- Use the `database-schema` tool to inspect table structure before writing migrations or models.
|
||||
|
||||
## Reading Browser Logs With the `browser-logs` Tool
|
||||
|
||||
- You can read browser logs, errors, and exceptions using the `browser-logs` tool from Boost.
|
||||
- Only recent browser logs will be useful - ignore old logs.
|
||||
|
||||
## Searching Documentation (Critically Important)
|
||||
|
||||
- Boost comes with a powerful `search-docs` tool you should use before trying other approaches when working with Laravel or Laravel ecosystem packages. This tool automatically passes a list of installed packages and their versions to the remote Boost API, so it returns only version-specific documentation for the user's circumstance. You should pass an array of packages to filter on if you know you need docs for particular packages.
|
||||
- Search the documentation before making code changes to ensure we are taking the correct approach.
|
||||
- Use multiple, broad, simple, topic-based queries at once. For example: `['rate limiting', 'routing rate limiting', 'routing']`. The most relevant results will be returned first.
|
||||
- Do not add package names to queries; package information is already shared. For example, use `test resource table`, not `filament 4 test resource table`.
|
||||
|
||||
### Available Search Syntax
|
||||
|
||||
1. Simple Word Searches with auto-stemming - query=authentication - finds 'authenticate' and 'auth'.
|
||||
2. Multiple Words (AND Logic) - query=rate limit - finds knowledge containing both "rate" AND "limit".
|
||||
3. Quoted Phrases (Exact Position) - query="infinite scroll" - words must be adjacent and in that order.
|
||||
4. Mixed Queries - query=middleware "rate limit" - "middleware" AND exact phrase "rate limit".
|
||||
5. Multiple Queries - queries=["authentication", "middleware"] - ANY of these terms.
|
||||
|
||||
=== php rules ===
|
||||
|
||||
# PHP
|
||||
|
||||
- Always use curly braces for control structures, even for single-line bodies.
|
||||
|
||||
## Constructors
|
||||
|
||||
- Use PHP 8 constructor property promotion in `__construct()`.
|
||||
- `public function __construct(public GitHub $github) { }`
|
||||
- Do not allow empty `__construct()` methods with zero parameters unless the constructor is private.
|
||||
|
||||
## Type Declarations
|
||||
|
||||
- Always use explicit return type declarations for methods and functions.
|
||||
- Use appropriate PHP type hints for method parameters.
|
||||
|
||||
<!-- Explicit Return Types and Method Params -->
|
||||
```php
|
||||
protected function isAccessible(User $user, ?string $path = null): bool
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Enums
|
||||
|
||||
- Typically, keys in an Enum should be TitleCase. For example: `FavoritePerson`, `BestLake`, `Monthly`.
|
||||
|
||||
## Comments
|
||||
|
||||
- Prefer PHPDoc blocks over inline comments. Never use comments within the code itself unless the logic is exceptionally complex.
|
||||
|
||||
## PHPDoc Blocks
|
||||
|
||||
- Add useful array shape type definitions when appropriate.
|
||||
|
||||
=== herd rules ===
|
||||
|
||||
# Laravel Herd
|
||||
|
||||
- The application is served by Laravel Herd and will be available at: `https?://[kebab-case-project-dir].test`. Use the `get-absolute-url` tool to generate valid URLs for the user.
|
||||
- You must not run any commands to make the site available via HTTP(S). It is always available through Laravel Herd.
|
||||
|
||||
=== laravel/core rules ===
|
||||
|
||||
# Do Things the Laravel Way
|
||||
|
||||
- Use `php artisan make:` commands to create new files (i.e. migrations, controllers, models, etc.). You can list available Artisan commands using the `list-artisan-commands` tool.
|
||||
- If you're creating a generic PHP class, use `php artisan make:class`.
|
||||
- Pass `--no-interaction` to all Artisan commands to ensure they work without user input. You should also pass the correct `--options` to ensure correct behavior.
|
||||
|
||||
## Database
|
||||
|
||||
- Always use proper Eloquent relationship methods with return type hints. Prefer relationship methods over raw queries or manual joins.
|
||||
- Use Eloquent models and relationships before suggesting raw database queries.
|
||||
- Avoid `DB::`; prefer `Model::query()`. Generate code that leverages Laravel's ORM capabilities rather than bypassing them.
|
||||
- Generate code that prevents N+1 query problems by using eager loading.
|
||||
- Use Laravel's query builder for very complex database operations.
|
||||
|
||||
### Model Creation
|
||||
|
||||
- When creating new models, create useful factories and seeders for them too. Ask the user if they need any other things, using `list-artisan-commands` to check the available options to `php artisan make:model`.
|
||||
|
||||
### APIs & Eloquent Resources
|
||||
|
||||
- For APIs, default to using Eloquent API Resources and API versioning unless existing API routes do not, then you should follow existing application convention.
|
||||
|
||||
## Controllers & Validation
|
||||
|
||||
- Always create Form Request classes for validation rather than inline validation in controllers. Include both validation rules and custom error messages.
|
||||
- Check sibling Form Requests to see if the application uses array or string based validation rules.
|
||||
|
||||
## Authentication & Authorization
|
||||
|
||||
- Use Laravel's built-in authentication and authorization features (gates, policies, Sanctum, etc.).
|
||||
|
||||
## URL Generation
|
||||
|
||||
- When generating links to other pages, prefer named routes and the `route()` function.
|
||||
|
||||
## Queues
|
||||
|
||||
- Use queued jobs for time-consuming operations with the `ShouldQueue` interface.
|
||||
|
||||
## Configuration
|
||||
|
||||
- Use environment variables only in configuration files - never use the `env()` function directly outside of config files. Always use `config('app.name')`, not `env('APP_NAME')`.
|
||||
|
||||
## Testing
|
||||
|
||||
- When creating models for tests, use the factories for the models. Check if the factory has custom states that can be used before manually setting up the model.
|
||||
- Faker: Use methods such as `$this->faker->word()` or `fake()->randomDigit()`. Follow existing conventions whether to use `$this->faker` or `fake()`.
|
||||
- When creating tests, make use of `php artisan make:test [options] {name}` to create a feature test, and pass `--unit` to create a unit test. Most tests should be feature tests.
|
||||
|
||||
## Vite Error
|
||||
|
||||
- If you receive an "Illuminate\Foundation\ViteException: Unable to locate file in Vite manifest" error, you can run `npm run build` or ask the user to run `npm run dev` or `composer run dev`.
|
||||
|
||||
=== laravel/v12 rules ===
|
||||
|
||||
# Laravel 12
|
||||
|
||||
- CRITICAL: ALWAYS use `search-docs` tool for version-specific Laravel documentation and updated code examples.
|
||||
- Since Laravel 11, Laravel has a new streamlined file structure which this project uses.
|
||||
|
||||
## Laravel 12 Structure
|
||||
|
||||
- In Laravel 12, middleware are no longer registered in `app/Http/Kernel.php`.
|
||||
- Middleware are configured declaratively in `bootstrap/app.php` using `Application::configure()->withMiddleware()`.
|
||||
- `bootstrap/app.php` is the file to register middleware, exceptions, and routing files.
|
||||
- `bootstrap/providers.php` contains application specific service providers.
|
||||
- The `app\Console\Kernel.php` file no longer exists; use `bootstrap/app.php` or `routes/console.php` for console configuration.
|
||||
- Console commands in `app/Console/Commands/` are automatically available and do not require manual registration.
|
||||
|
||||
## Database
|
||||
|
||||
- When modifying a column, the migration must include all of the attributes that were previously defined on the column. Otherwise, they will be dropped and lost.
|
||||
- Laravel 12 allows limiting eagerly loaded records natively, without external packages: `$query->latest()->limit(10);`.
|
||||
|
||||
### Models
|
||||
|
||||
- Casts can and likely should be set in a `casts()` method on a model rather than the `$casts` property. Follow existing conventions from other models.
|
||||
|
||||
=== pint/core rules ===
|
||||
|
||||
# Laravel Pint Code Formatter
|
||||
|
||||
- If you have modified any PHP files, you must run `vendor/bin/pint --dirty --format agent` before finalizing changes to ensure your code matches the project's expected style.
|
||||
- Do not run `vendor/bin/pint --test --format agent`, simply run `vendor/bin/pint --format agent` to fix any formatting issues.
|
||||
|
||||
=== phpunit/core rules ===
|
||||
|
||||
# PHPUnit
|
||||
|
||||
- This application uses PHPUnit for testing. All tests must be written as PHPUnit classes. Use `php artisan make:test --phpunit {name}` to create a new test.
|
||||
- If you see a test using "Pest", convert it to PHPUnit.
|
||||
- Every time a test has been updated, run that singular test.
|
||||
- When the tests relating to your feature are passing, ask the user if they would like to also run the entire test suite to make sure everything is still passing.
|
||||
- Tests should cover all happy paths, failure paths, and edge cases.
|
||||
- You must not remove any tests or test files from the tests directory without approval. These are not temporary or helper files; these are core to the application.
|
||||
|
||||
## Running Tests
|
||||
|
||||
- Run the minimal number of tests, using an appropriate filter, before finalizing.
|
||||
- To run all tests: `php artisan test --compact`.
|
||||
- To run all tests in a file: `php artisan test --compact tests/Feature/ExampleTest.php`.
|
||||
- To filter on a particular test name: `php artisan test --compact --filter=testName` (recommended after making a change to a related file).
|
||||
|
||||
=== tailwindcss/core rules ===
|
||||
|
||||
# Tailwind CSS
|
||||
|
||||
- Always use existing Tailwind conventions; check project patterns before adding new ones.
|
||||
- IMPORTANT: Always use `search-docs` tool for version-specific Tailwind CSS documentation and updated code examples. Never rely on training data.
|
||||
- IMPORTANT: Activate `tailwindcss-development` every time you're working with a Tailwind CSS or styling-related task.
|
||||
|
||||
</laravel-boost-guidelines>
|
||||
+699
-222
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,98 @@
|
||||
# 🎮 聊天室游戏开发进度
|
||||
|
||||
> 更新时间:2026-03-04
|
||||
|
||||
---
|
||||
|
||||
## ✅ 已完成
|
||||
|
||||
### 🎲 百家乐(Baccarat)
|
||||
|
||||
- **类型**:定时自动开局(调度器每分钟检查,间隔可配置)
|
||||
- **数据库**:`baccarat_rounds` + `baccarat_bets`
|
||||
- **模型**:`BaccaratRound` / `BaccaratBet`
|
||||
- **队列 Job**:`OpenBaccaratRoundJob` (开局) + `CloseBaccaratRoundJob` (摇骰结算)
|
||||
- **事件**:`BaccaratRoundOpened` / `BaccaratRoundSettled`(PresenceChannel 广播)
|
||||
- **控制器**:`BaccaratController`(`/baccarat/current` / `/baccarat/bet` / `/baccarat/history`)
|
||||
- **前端**:`chat/partials/baccarat-panel.blade.php`(倒计时/押注/骰子动画/趋势)
|
||||
- **货币来源**:`CurrencySource::BACCARAT_BET` / `BACCARAT_WIN`
|
||||
- **后台配置**:`game_configs` 表,管理员可配置开关/间隔/赔率/押注范围
|
||||
|
||||
### 🎰 老虎机(Slot Machine)
|
||||
|
||||
- **类型**:玩家随时主动触发(即时游戏)
|
||||
- **数据库**:`slot_machine_logs`
|
||||
- **模型**:`SlotMachineLog`(8种带权重图案、判奖逻辑)
|
||||
- **控制器**:`SlotMachineController`(`/slot/info` / `/slot/spin` / `/slot/history`)
|
||||
- **赔率**:三7×100(全服广播)/ 三钻×50 / 三同×10 / 两同×2 / 三骷髅诅咒(扣双倍)
|
||||
- **聊天通知**:中奖发私信通知;三7全服公屏广播
|
||||
- **前端**:`chat/partials/slot-machine.blade.php`(三列滚轮动画/逐列停止/可拖动FAB)
|
||||
- **货币来源**:`CurrencySource::SLOT_SPIN` / `SLOT_WIN` / `SLOT_CURSE`
|
||||
- **后台配置**:`game_configs` 表,可配置每次消耗/每日次数上限/各赔率
|
||||
|
||||
### 📦 神秘箱子(Mystery Box)
|
||||
|
||||
- **类型**:系统定时自动投放 + 管理员手动投放(即时广播暗号,先到先得)
|
||||
- **数据库**:`mystery_boxes`(箱子记录)+ `mystery_box_claims`(领取日志)
|
||||
- **模型**:`MysteryBox` / `MysteryBoxClaim`
|
||||
- **队列 Job**:`DropMysteryBoxJob`(投放 + 公屏广播暗号 + 派发 ExpireJob)/ `ExpireMysteryBoxJob`(到期处理)
|
||||
- **控制器**:`MysteryBoxController`(`/mystery-box/status` 状态查询 / `/mystery-box/claim` 领取)
|
||||
- **前端**:`chat/partials/mystery-box.blade.php`(5秒轮询检测 + 可拖动FAB + 快捷输入面板)
|
||||
- **领取方式**:① 聊天框直接输入暗号发送(前端拦截,不发普通消息)② 点击悬浮FAB打开面板输入
|
||||
- **箱子类型**:普通箱(500\~2000金)/ 稀有箱(5000\~20000金)/ 黑化箱(陷阱,倒扣200\~1000金)
|
||||
- **货币来源**:`CurrencySource::MYSTERY_BOX` / `MYSTERY_BOX_TRAP`(含 `room_id` 流水记录)
|
||||
- **后台配置**:`game_configs` 表,可配置开关/自动投放间隔/各奖励范围/陷阱概率;支持手动投放三种类型
|
||||
|
||||
### 🐎 赛马竞猜(Horse Racing)
|
||||
|
||||
- **类型**:定时自动开局(调度器每分钟检查,间隔可配置)
|
||||
- **数据库**:`horse_races` + `horse_bets`
|
||||
- **模型**:`HorseRace` / `HorseBet`
|
||||
- **队列 Job**:`OpenHorseRaceJob`(开赛广播)+ `RunHorseRaceJob`(每秒播报马匹进度 + 确定胜者)+ `CloseHorseRaceJob`(结算)
|
||||
- **事件**:`HorseRaceOpened` / `HorseRaceProgress` / `HorseRaceSettled`(PresenceChannel 广播)
|
||||
- **控制器**:`HorseRaceController`(`/horse-race/current` / `/horse-race/bet` / `/horse-race/history`)
|
||||
- **广播**:`horse.opened` / `horse.progress` / `horse.settled`
|
||||
- **前端**:`chat/partials/horse-race-panel.blade.php`(倒计时/赛马道动画/实时赔率/可拖动FAB)
|
||||
- **货币来源**:`CurrencySource::HORSE_BET` / `HORSE_WIN`
|
||||
- **后台配置**:`game_configs` 表,马匹数量/押注窗口/跨马时长/庄家抓水比例均可配置
|
||||
|
||||
### 🔮 神秘占卜(Fortune Telling)
|
||||
|
||||
- **类型**:玩家主动使用(每日免费 N 次,额外次数消耗金币)
|
||||
- **数据库**:`fortune_logs`
|
||||
- **模型**:`FortuneLog`(55+ 条签文内嵌在模型中)
|
||||
- **控制器**:`FortuneTellingController`(`/fortune/today` 查今日 / `/fortune/tell` 占卜 / `/fortune/history` 历史)
|
||||
- **前端**:`chat/partials/fortune-panel.blade.php`(卦象摇动动画/签文卡片/当日加成状态/可拖动FAB)
|
||||
- **每日限制**:免费 N 次(可配置),额外次数消耗金币
|
||||
- **广播**:暂无实时广播(占卜结果仅展示给本人)
|
||||
- **货币来源**:`CurrencySource::FORTUNE_COST`
|
||||
- **后台配置**:`game_configs` 表,免费次数/额外消耗/各签概率均可配置
|
||||
|
||||
---
|
||||
|
||||
## 🕐 待开发
|
||||
|
||||
---
|
||||
|
||||
## 📌 通用待办(所有游戏共用)
|
||||
|
||||
- [x] 后台游戏管理页面(`/admin/game-configs`)显示各游戏实时统计数据(点击"加载实时统计"异步加载各游戏汇总卡片)
|
||||
- [x] 各游戏历史记录在后台可查(管理员视角,新增 `/admin/game-history/` 路由组,支持百家乐/老虎机/赛马/神秘箱子/占卜各自的历史记录列表及详情页,含筛选分页)
|
||||
- [x] 生产环境部署:`php artisan db:seed --class=GameConfigSeeder`(初始化游戏配置) 已经完成了
|
||||
- [ ] 百家乐/老虎机 全面测试(多用户并发下注)
|
||||
|
||||
---
|
||||
|
||||
## 🔧 已修复的 Bug
|
||||
|
||||
1. **百家乐广播频道**:`Channel` → `PresenceChannel`,解决前端收不到 WebSocket 事件
|
||||
2. **百家乐余额检查**:`$user->gold` → `$user->jjb`(字段名错误)
|
||||
3. **老虎机积分日志**:普通中奖/诅咒发私信通知;三7全服广播
|
||||
4. **老虎机FAB**:支持拖动 + localStorage 位置持久化
|
||||
5. **星海小博士随机事件**:改走 `UserCurrencyService.change()`,补写流水日志
|
||||
6. **百家乐结算UI**:骰子改数字方块(跨平台);中奖/未中奖卡片重设计
|
||||
7. **全部 FAB 拖动统一**:百家乐 FAB 改为 Alpine.js `baccaratFab()` 组件,与老虎机 `slotFab()` 完全一致,位置持久化存 localStorage
|
||||
8. **Alpine.js 初始化顺序**:`frame.blade.php` 中 Alpine CDN 补加 `defer`,解决所有组件 `is not defined` 错误
|
||||
9. **神秘箱子暗号领取**:改为主动尝试模式(不依赖5秒轮询),聊天框输入暗号即可触发领取;`claim()` 暗号统一转大写
|
||||
10. **神秘箱子流水记录**:`change()` 调用补上 `room_id` 参数,确保积分统计页面可按房间筛选
|
||||
11. **后台弹窗**:游戏管理页所有 `alert/confirm` 替换为全局 `window.adminDialog`(毛玻璃弹窗)
|
||||
@@ -0,0 +1,256 @@
|
||||
<laravel-boost-guidelines>
|
||||
=== foundation rules ===
|
||||
|
||||
# Laravel Boost Guidelines
|
||||
|
||||
The Laravel Boost guidelines are specifically curated by Laravel maintainers for this application. These guidelines should be followed closely to ensure the best experience when building Laravel applications.
|
||||
|
||||
## Foundational Context
|
||||
|
||||
This application is a Laravel application and its main Laravel ecosystems package & versions are below. You are an expert with them all. Ensure you abide by these specific packages & versions.
|
||||
|
||||
- php - 8.4.5
|
||||
- laravel/framework (LARAVEL) - v12
|
||||
- laravel/horizon (HORIZON) - v5
|
||||
- laravel/prompts (PROMPTS) - v0
|
||||
- laravel/reverb (REVERB) - v1
|
||||
- laravel/boost (BOOST) - v2
|
||||
- laravel/mcp (MCP) - v0
|
||||
- laravel/pail (PAIL) - v1
|
||||
- laravel/pint (PINT) - v1
|
||||
- laravel/sail (SAIL) - v1
|
||||
- phpunit/phpunit (PHPUNIT) - v11
|
||||
- laravel-echo (ECHO) - v2
|
||||
- tailwindcss (TAILWINDCSS) - v4
|
||||
|
||||
## Skills Activation
|
||||
|
||||
This project has domain-specific skills available. You MUST activate the relevant skill whenever you work in that domain—don't wait until you're stuck.
|
||||
|
||||
- `tailwindcss-development` — Styles applications using Tailwind CSS v4 utilities. Activates when adding styles, restyling components, working with gradients, spacing, layout, flex, grid, responsive design, dark mode, colors, typography, or borders; or when the user mentions CSS, styling, classes, Tailwind, restyle, hero section, cards, buttons, or any visual/UI changes.
|
||||
|
||||
## Conventions
|
||||
|
||||
- You must follow all existing code conventions used in this application. When creating or editing a file, check sibling files for the correct structure, approach, and naming.
|
||||
- Use descriptive names for variables and methods. For example, `isRegisteredForDiscounts`, not `discount()`.
|
||||
- Check for existing components to reuse before writing a new one.
|
||||
|
||||
## Verification Scripts
|
||||
|
||||
- Do not create verification scripts or tinker when tests cover that functionality and prove they work. Unit and feature tests are more important.
|
||||
|
||||
## Application Structure & Architecture
|
||||
|
||||
- Stick to existing directory structure; don't create new base folders without approval.
|
||||
- Do not change the application's dependencies without approval.
|
||||
|
||||
## Frontend Bundling
|
||||
|
||||
- If the user doesn't see a frontend change reflected in the UI, it could mean they need to run `npm run build`, `npm run dev`, or `composer run dev`. Ask them.
|
||||
|
||||
## Documentation Files
|
||||
|
||||
- You must only create documentation files if explicitly requested by the user.
|
||||
|
||||
## Replies
|
||||
|
||||
- Be concise in your explanations - focus on what's important rather than explaining obvious details.
|
||||
|
||||
=== boost rules ===
|
||||
|
||||
# Laravel Boost
|
||||
|
||||
- Laravel Boost is an MCP server that comes with powerful tools designed specifically for this application. Use them.
|
||||
|
||||
## Artisan
|
||||
|
||||
- Use the `list-artisan-commands` tool when you need to call an Artisan command to double-check the available parameters.
|
||||
|
||||
## URLs
|
||||
|
||||
- Whenever you share a project URL with the user, you should use the `get-absolute-url` tool to ensure you're using the correct scheme, domain/IP, and port.
|
||||
|
||||
## Tinker / Debugging
|
||||
|
||||
- You should use the `tinker` tool when you need to execute PHP to debug code or query Eloquent models directly.
|
||||
- Use the `database-query` tool when you only need to read from the database.
|
||||
- Use the `database-schema` tool to inspect table structure before writing migrations or models.
|
||||
|
||||
## Reading Browser Logs With the `browser-logs` Tool
|
||||
|
||||
- You can read browser logs, errors, and exceptions using the `browser-logs` tool from Boost.
|
||||
- Only recent browser logs will be useful - ignore old logs.
|
||||
|
||||
## Searching Documentation (Critically Important)
|
||||
|
||||
- Boost comes with a powerful `search-docs` tool you should use before trying other approaches when working with Laravel or Laravel ecosystem packages. This tool automatically passes a list of installed packages and their versions to the remote Boost API, so it returns only version-specific documentation for the user's circumstance. You should pass an array of packages to filter on if you know you need docs for particular packages.
|
||||
- Search the documentation before making code changes to ensure we are taking the correct approach.
|
||||
- Use multiple, broad, simple, topic-based queries at once. For example: `['rate limiting', 'routing rate limiting', 'routing']`. The most relevant results will be returned first.
|
||||
- Do not add package names to queries; package information is already shared. For example, use `test resource table`, not `filament 4 test resource table`.
|
||||
|
||||
### Available Search Syntax
|
||||
|
||||
1. Simple Word Searches with auto-stemming - query=authentication - finds 'authenticate' and 'auth'.
|
||||
2. Multiple Words (AND Logic) - query=rate limit - finds knowledge containing both "rate" AND "limit".
|
||||
3. Quoted Phrases (Exact Position) - query="infinite scroll" - words must be adjacent and in that order.
|
||||
4. Mixed Queries - query=middleware "rate limit" - "middleware" AND exact phrase "rate limit".
|
||||
5. Multiple Queries - queries=["authentication", "middleware"] - ANY of these terms.
|
||||
|
||||
=== php rules ===
|
||||
|
||||
# PHP
|
||||
|
||||
- Always use curly braces for control structures, even for single-line bodies.
|
||||
|
||||
## Constructors
|
||||
|
||||
- Use PHP 8 constructor property promotion in `__construct()`.
|
||||
- `public function __construct(public GitHub $github) { }`
|
||||
- Do not allow empty `__construct()` methods with zero parameters unless the constructor is private.
|
||||
|
||||
## Type Declarations
|
||||
|
||||
- Always use explicit return type declarations for methods and functions.
|
||||
- Use appropriate PHP type hints for method parameters.
|
||||
|
||||
<!-- Explicit Return Types and Method Params -->
|
||||
```php
|
||||
protected function isAccessible(User $user, ?string $path = null): bool
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## Enums
|
||||
|
||||
- Typically, keys in an Enum should be TitleCase. For example: `FavoritePerson`, `BestLake`, `Monthly`.
|
||||
|
||||
## Comments
|
||||
|
||||
- Prefer PHPDoc blocks over inline comments. Never use comments within the code itself unless the logic is exceptionally complex.
|
||||
|
||||
## PHPDoc Blocks
|
||||
|
||||
- Add useful array shape type definitions when appropriate.
|
||||
|
||||
=== herd rules ===
|
||||
|
||||
# Laravel Herd
|
||||
|
||||
- The application is served by Laravel Herd and will be available at: `https?://[kebab-case-project-dir].test`. Use the `get-absolute-url` tool to generate valid URLs for the user.
|
||||
- You must not run any commands to make the site available via HTTP(S). It is always available through Laravel Herd.
|
||||
|
||||
=== laravel/core rules ===
|
||||
|
||||
# Do Things the Laravel Way
|
||||
|
||||
- Use `php artisan make:` commands to create new files (i.e. migrations, controllers, models, etc.). You can list available Artisan commands using the `list-artisan-commands` tool.
|
||||
- If you're creating a generic PHP class, use `php artisan make:class`.
|
||||
- Pass `--no-interaction` to all Artisan commands to ensure they work without user input. You should also pass the correct `--options` to ensure correct behavior.
|
||||
|
||||
## Database
|
||||
|
||||
- Always use proper Eloquent relationship methods with return type hints. Prefer relationship methods over raw queries or manual joins.
|
||||
- Use Eloquent models and relationships before suggesting raw database queries.
|
||||
- Avoid `DB::`; prefer `Model::query()`. Generate code that leverages Laravel's ORM capabilities rather than bypassing them.
|
||||
- Generate code that prevents N+1 query problems by using eager loading.
|
||||
- Use Laravel's query builder for very complex database operations.
|
||||
|
||||
### Model Creation
|
||||
|
||||
- When creating new models, create useful factories and seeders for them too. Ask the user if they need any other things, using `list-artisan-commands` to check the available options to `php artisan make:model`.
|
||||
|
||||
### APIs & Eloquent Resources
|
||||
|
||||
- For APIs, default to using Eloquent API Resources and API versioning unless existing API routes do not, then you should follow existing application convention.
|
||||
|
||||
## Controllers & Validation
|
||||
|
||||
- Always create Form Request classes for validation rather than inline validation in controllers. Include both validation rules and custom error messages.
|
||||
- Check sibling Form Requests to see if the application uses array or string based validation rules.
|
||||
|
||||
## Authentication & Authorization
|
||||
|
||||
- Use Laravel's built-in authentication and authorization features (gates, policies, Sanctum, etc.).
|
||||
|
||||
## URL Generation
|
||||
|
||||
- When generating links to other pages, prefer named routes and the `route()` function.
|
||||
|
||||
## Queues
|
||||
|
||||
- Use queued jobs for time-consuming operations with the `ShouldQueue` interface.
|
||||
|
||||
## Configuration
|
||||
|
||||
- Use environment variables only in configuration files - never use the `env()` function directly outside of config files. Always use `config('app.name')`, not `env('APP_NAME')`.
|
||||
|
||||
## Testing
|
||||
|
||||
- When creating models for tests, use the factories for the models. Check if the factory has custom states that can be used before manually setting up the model.
|
||||
- Faker: Use methods such as `$this->faker->word()` or `fake()->randomDigit()`. Follow existing conventions whether to use `$this->faker` or `fake()`.
|
||||
- When creating tests, make use of `php artisan make:test [options] {name}` to create a feature test, and pass `--unit` to create a unit test. Most tests should be feature tests.
|
||||
|
||||
## Vite Error
|
||||
|
||||
- If you receive an "Illuminate\Foundation\ViteException: Unable to locate file in Vite manifest" error, you can run `npm run build` or ask the user to run `npm run dev` or `composer run dev`.
|
||||
|
||||
=== laravel/v12 rules ===
|
||||
|
||||
# Laravel 12
|
||||
|
||||
- CRITICAL: ALWAYS use `search-docs` tool for version-specific Laravel documentation and updated code examples.
|
||||
- Since Laravel 11, Laravel has a new streamlined file structure which this project uses.
|
||||
|
||||
## Laravel 12 Structure
|
||||
|
||||
- In Laravel 12, middleware are no longer registered in `app/Http/Kernel.php`.
|
||||
- Middleware are configured declaratively in `bootstrap/app.php` using `Application::configure()->withMiddleware()`.
|
||||
- `bootstrap/app.php` is the file to register middleware, exceptions, and routing files.
|
||||
- `bootstrap/providers.php` contains application specific service providers.
|
||||
- The `app\Console\Kernel.php` file no longer exists; use `bootstrap/app.php` or `routes/console.php` for console configuration.
|
||||
- Console commands in `app/Console/Commands/` are automatically available and do not require manual registration.
|
||||
|
||||
## Database
|
||||
|
||||
- When modifying a column, the migration must include all of the attributes that were previously defined on the column. Otherwise, they will be dropped and lost.
|
||||
- Laravel 12 allows limiting eagerly loaded records natively, without external packages: `$query->latest()->limit(10);`.
|
||||
|
||||
### Models
|
||||
|
||||
- Casts can and likely should be set in a `casts()` method on a model rather than the `$casts` property. Follow existing conventions from other models.
|
||||
|
||||
=== pint/core rules ===
|
||||
|
||||
# Laravel Pint Code Formatter
|
||||
|
||||
- If you have modified any PHP files, you must run `vendor/bin/pint --dirty --format agent` before finalizing changes to ensure your code matches the project's expected style.
|
||||
- Do not run `vendor/bin/pint --test --format agent`, simply run `vendor/bin/pint --format agent` to fix any formatting issues.
|
||||
|
||||
=== phpunit/core rules ===
|
||||
|
||||
# PHPUnit
|
||||
|
||||
- This application uses PHPUnit for testing. All tests must be written as PHPUnit classes. Use `php artisan make:test --phpunit {name}` to create a new test.
|
||||
- If you see a test using "Pest", convert it to PHPUnit.
|
||||
- Every time a test has been updated, run that singular test.
|
||||
- When the tests relating to your feature are passing, ask the user if they would like to also run the entire test suite to make sure everything is still passing.
|
||||
- Tests should cover all happy paths, failure paths, and edge cases.
|
||||
- You must not remove any tests or test files from the tests directory without approval. These are not temporary or helper files; these are core to the application.
|
||||
|
||||
## Running Tests
|
||||
|
||||
- Run the minimal number of tests, using an appropriate filter, before finalizing.
|
||||
- To run all tests: `php artisan test --compact`.
|
||||
- To run all tests in a file: `php artisan test --compact tests/Feature/ExampleTest.php`.
|
||||
- To filter on a particular test name: `php artisan test --compact --filter=testName` (recommended after making a change to a related file).
|
||||
|
||||
=== tailwindcss/core rules ===
|
||||
|
||||
# Tailwind CSS
|
||||
|
||||
- Always use existing Tailwind conventions; check project patterns before adding new ones.
|
||||
- IMPORTANT: Always use `search-docs` tool for version-specific Tailwind CSS documentation and updated code examples. Never rely on training data.
|
||||
- IMPORTANT: Activate `tailwindcss-development` every time you're working with a Tailwind CSS or styling-related task.
|
||||
|
||||
</laravel-boost-guidelines>
|
||||
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:AI小班长专属极轻量心跳模拟器
|
||||
*
|
||||
* 专门用于让无法通过浏览器发送真实心跳的 AI实体用户
|
||||
* 也能够完美触原有的法发经验/金币逻辑以及触发随机事件(Autoact)。
|
||||
* 每分钟由 Laravel Scheduler 调用。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Enums\CurrencySource;
|
||||
use App\Events\MessageSent;
|
||||
use App\Jobs\SaveMessageJob;
|
||||
use App\Models\Autoact;
|
||||
use App\Models\DailySignIn;
|
||||
use App\Models\Sysparam;
|
||||
use App\Models\User;
|
||||
use App\Services\AiFinanceService;
|
||||
use App\Services\ChatStateService;
|
||||
use App\Services\SignInService;
|
||||
use App\Services\UserCurrencyService;
|
||||
use App\Services\VipService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
/**
|
||||
* 定时模拟 AI小班长心跳,并同步维护其常规存款理财行为。
|
||||
*/
|
||||
class AiHeartbeatCommand extends Command
|
||||
{
|
||||
/**
|
||||
* Artisan 指令名称
|
||||
*/
|
||||
protected $signature = 'chatroom:ai-heartbeat';
|
||||
|
||||
/**
|
||||
* 指令描述
|
||||
*/
|
||||
protected $description = '模拟 AI 小班长客户端心跳,触发经验金币与随机事件';
|
||||
|
||||
/**
|
||||
* 注入聊天室状态、VIP、积分与 AI 资金调度服务。
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ChatStateService $chatState,
|
||||
private readonly VipService $vipService,
|
||||
private readonly UserCurrencyService $currencyService,
|
||||
private readonly AiFinanceService $aiFinance,
|
||||
private readonly SignInService $signInService,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行 AI小班长单次心跳,并处理奖励、随机事件与资金调度。
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
// 1. 检查总开关
|
||||
if (Sysparam::getValue('chatbot_enabled', '0') !== '1') {
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// 2. 获取 AI 实体
|
||||
$user = User::where('username', 'AI小班长')->first();
|
||||
if (! $user) {
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
// 心跳开始前,若手上金币已高于 100 万,则先把超出的部分转入银行。
|
||||
$this->aiFinance->bankExcessGold($user);
|
||||
|
||||
// 2.5 自动每日签到(今日已签时 claim() 幂等返回,不重复发奖)
|
||||
$this->performDailySignIn($user);
|
||||
|
||||
// 3. 常规心跳经验与金币发放
|
||||
// (模拟前端每30-60秒发一次心跳的过程,此处每分钟跑一次,发放单人心跳奖励)
|
||||
$expGain = $this->parseRewardValue(Sysparam::getValue('exp_per_heartbeat', '1'));
|
||||
if ($expGain > 0) {
|
||||
$expMultiplier = $this->vipService->getExpMultiplier($user);
|
||||
$actualExpGain = (int) round($expGain * $expMultiplier);
|
||||
$user->exp_num += $actualExpGain;
|
||||
}
|
||||
|
||||
$jjbGain = $this->parseRewardValue(Sysparam::getValue('jjb_per_heartbeat', '0'));
|
||||
if ($jjbGain > 0) {
|
||||
$jjbMultiplier = $this->vipService->getJjbMultiplier($user);
|
||||
$actualJjbGain = (int) round($jjbGain * $jjbMultiplier);
|
||||
$user->jjb = ($user->jjb ?? 0) + $actualJjbGain;
|
||||
}
|
||||
|
||||
$user->save();
|
||||
$user->refresh();
|
||||
|
||||
// 4. 重算等级(基础心跳升级)
|
||||
$superLevel = (int) Sysparam::getValue('superlevel', '100');
|
||||
$leveledUp = $this->calculateNewLevel($user, $superLevel);
|
||||
|
||||
// 5. 随机事件触发
|
||||
$eventChance = (int) Sysparam::getValue('auto_event_chance', '10');
|
||||
if ($eventChance > 0 && rand(1, 100) <= $eventChance) {
|
||||
$autoEvent = Autoact::randomEvent();
|
||||
if ($autoEvent) {
|
||||
// 执行随机事件的金钱经验惩奖
|
||||
if ($autoEvent->exp_change !== 0) {
|
||||
$this->currencyService->change(
|
||||
$user, 'exp', $autoEvent->exp_change, CurrencySource::AUTO_EVENT, "随机事件:{$autoEvent->text_body}", 1
|
||||
);
|
||||
}
|
||||
if ($autoEvent->jjb_change !== 0) {
|
||||
$this->currencyService->change(
|
||||
$user, 'gold', $autoEvent->jjb_change, CurrencySource::AUTO_EVENT, "随机事件:{$autoEvent->text_body}", 1
|
||||
);
|
||||
}
|
||||
|
||||
$user->refresh();
|
||||
|
||||
// 重新计算等级
|
||||
if ($this->calculateNewLevel($user, $superLevel)) {
|
||||
$leveledUp = true;
|
||||
}
|
||||
|
||||
// 广播随机事件
|
||||
$this->broadcastSystemMessage(
|
||||
'星海小博士',
|
||||
$autoEvent->renderText($user->username),
|
||||
match ($autoEvent->event_type) {
|
||||
'good' => '#16a34a',
|
||||
'bad' => '#dc2626',
|
||||
default => '#7c3aed',
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 6. 如果由于心跳或事件导致了升级,广播升级消息
|
||||
if ($leveledUp) {
|
||||
$this->broadcastSystemMessage(
|
||||
'系统传音',
|
||||
"🌟 天道酬勤!恭喜侠客【{$user->username}】挂机苦修,境界突破至 LV.{$user->user_level}!",
|
||||
'#d97706',
|
||||
'大声宣告'
|
||||
);
|
||||
}
|
||||
|
||||
// 7. 钓鱼小游戏随机参与逻辑
|
||||
$fishingEnabled = Sysparam::getValue('chatbot_fishing_enabled', '0') === '1';
|
||||
$fishingChance = (int) Sysparam::getValue('chatbot_fishing_chance', '100'); // 默认 5% 概率
|
||||
if ($fishingEnabled && $fishingChance > 0 && rand(1, 100) <= $fishingChance && \App\Models\GameConfig::isEnabled('fishing')) {
|
||||
$cost = (int) (\App\Models\GameConfig::param('fishing', 'fishing_cost') ?? Sysparam::getValue('fishing_cost', '5'));
|
||||
// 常规小游戏只使用当前手上金币,不再自动从银行补到 100 万。
|
||||
if ($this->aiFinance->prepareSpend($user, $cost)) {
|
||||
// 先扣除费用
|
||||
$this->currencyService->change(
|
||||
$user, 'gold', -$cost,
|
||||
CurrencySource::FISHING_COST,
|
||||
"AI小班长钓鱼抛竿消耗 {$cost} 金币",
|
||||
1,
|
||||
);
|
||||
|
||||
// 模拟玩家等待时间
|
||||
$waitMin = (int) (\App\Models\GameConfig::param('fishing', 'fishing_wait_min') ?? Sysparam::getValue('fishing_wait_min', '8'));
|
||||
$waitMax = (int) (\App\Models\GameConfig::param('fishing', 'fishing_wait_max') ?? Sysparam::getValue('fishing_wait_max', '15'));
|
||||
$waitTime = rand($waitMin, $waitMax);
|
||||
|
||||
// 延迟派发收竿事件(AI目前统一将事件播报到房间 1,或者拿 active room ids)
|
||||
$activeRoomIds = $this->chatState->getAllActiveRoomIds();
|
||||
$roomId = ! empty($activeRoomIds) ? $activeRoomIds[0] : 1;
|
||||
|
||||
\App\Jobs\AiFishingJob::dispatch($user, $roomId)->delay(now()->addSeconds($waitTime));
|
||||
}
|
||||
}
|
||||
|
||||
// 心跳结束后,若新增金币让手上金额超过 100 万,则把超出的部分重新转回银行。
|
||||
$this->aiFinance->bankExcessGold($user);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算并更新用户等级
|
||||
*/
|
||||
private function calculateNewLevel(User $user, int $superLevel): bool
|
||||
{
|
||||
$oldLevel = $user->user_level;
|
||||
|
||||
if ($oldLevel >= $superLevel) {
|
||||
return false; // 管理员不自动升降级
|
||||
}
|
||||
|
||||
$newLevel = Sysparam::calculateLevel($user->exp_num);
|
||||
if ($newLevel !== $oldLevel && $newLevel < $superLevel) {
|
||||
$user->user_level = $newLevel;
|
||||
$user->save();
|
||||
|
||||
return $newLevel > $oldLevel;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析配置的奖励范围,如 "1" 或 "1-5"
|
||||
*/
|
||||
private function parseRewardValue(string $raw): int
|
||||
{
|
||||
$raw = trim($raw);
|
||||
if (str_contains($raw, '-')) {
|
||||
[$min, $max] = explode('-', $raw, 2);
|
||||
|
||||
return rand((int) $min, (int) $max);
|
||||
}
|
||||
|
||||
return (int) $raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 尝试为 AI小班长 执行今日签到,成功时广播签到通知。
|
||||
*/
|
||||
private function performDailySignIn(User $user): void
|
||||
{
|
||||
// 先检查今日是否已签,避免每分钟都调用事务
|
||||
$alreadySigned = DailySignIn::query()
|
||||
->where('user_id', $user->id)
|
||||
->whereDate('sign_in_date', today())
|
||||
->exists();
|
||||
|
||||
if ($alreadySigned) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取活跃房间作为签到归属(默认房间 1)
|
||||
$activeRoomIds = $this->chatState->getAllActiveRoomIds();
|
||||
$roomId = ! empty($activeRoomIds) ? (int) $activeRoomIds[0] : 1;
|
||||
|
||||
$dailySignIn = $this->signInService->claim($user, $roomId);
|
||||
|
||||
// 仅当本次心跳实际完成签到时才广播(幂等保护)
|
||||
if (! $dailySignIn->wasRecentlyCreated) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rewardParts = [];
|
||||
if ($dailySignIn->gold_reward > 0) {
|
||||
$rewardParts[] = $dailySignIn->gold_reward.' 金币';
|
||||
}
|
||||
if ($dailySignIn->exp_reward > 0) {
|
||||
$rewardParts[] = $dailySignIn->exp_reward.' 经验';
|
||||
}
|
||||
if ($dailySignIn->charm_reward > 0) {
|
||||
$rewardParts[] = $dailySignIn->charm_reward.' 魅力';
|
||||
}
|
||||
$rewardText = $rewardParts === [] ? '签到记录' : implode(' + ', $rewardParts);
|
||||
|
||||
$identityText = $dailySignIn->identity_badge_name
|
||||
? ',获得身份 '.e($dailySignIn->identity_badge_name)
|
||||
: '';
|
||||
|
||||
$content = '【'.e($user->username).'】完成今日签到,连续签到 '
|
||||
.$dailySignIn->streak_days.' 天,获得 '.$rewardText.$identityText.'。';
|
||||
|
||||
$this->broadcastSystemMessage('签到播报', $content, '#0f766e');
|
||||
}
|
||||
|
||||
/**
|
||||
* 往所有活跃房间发送系统广播消息
|
||||
*/
|
||||
private function broadcastSystemMessage(string $fromUser, string $content, string $color, string $action = ''): void
|
||||
{
|
||||
$activeRoomIds = $this->chatState->getAllActiveRoomIds();
|
||||
if (empty($activeRoomIds)) {
|
||||
$activeRoomIds = [1];
|
||||
}
|
||||
|
||||
foreach ($activeRoomIds as $roomId) {
|
||||
$sysMsg = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => $fromUser,
|
||||
'to_user' => '大家',
|
||||
'content' => $content,
|
||||
'is_secret' => false,
|
||||
'font_color' => $color,
|
||||
'action' => $action,
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
$this->chatState->pushMessage($roomId, $sysMsg);
|
||||
broadcast(new MessageSent($roomId, $sysMsg));
|
||||
SaveMessageJob::dispatch($sysMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,20 +9,25 @@
|
||||
* 3. 在聊天室内推送"系统为你自动存点"提示
|
||||
* 4. 若用户等级提升,向全频道广播恭喜消息
|
||||
*
|
||||
* @package App\Console\Commands
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Enums\CurrencySource;
|
||||
use App\Events\MessageSent;
|
||||
use App\Jobs\SaveMessageJob;
|
||||
use App\Models\PositionDutyLog;
|
||||
use App\Models\Sysparam;
|
||||
use App\Models\User;
|
||||
use App\Services\ChatStateService;
|
||||
use App\Services\ChatUserPresenceService;
|
||||
use App\Services\UserCurrencyService;
|
||||
use App\Services\VipService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class AutoSaveExp extends Command
|
||||
@@ -42,7 +47,9 @@ class AutoSaveExp extends Command
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ChatStateService $chatState,
|
||||
private readonly ChatUserPresenceService $chatUserPresenceService,
|
||||
private readonly VipService $vipService,
|
||||
private readonly UserCurrencyService $currencyService,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -61,13 +68,14 @@ class AutoSaveExp extends Command
|
||||
// 读取奖励配置
|
||||
$expGainRaw = Sysparam::getValue('exp_per_heartbeat', '1');
|
||||
$jjbGainRaw = Sysparam::getValue('jjb_per_heartbeat', '0');
|
||||
$superLevel = (int) Sysparam::getValue('superlevel', '100');
|
||||
$superLevel = (int) Sysparam::getValue('superlevel', '100');
|
||||
|
||||
// 从 Redis 扫描所有在线房间
|
||||
$roomMap = $this->scanOnlineRooms();
|
||||
|
||||
if (empty($roomMap)) {
|
||||
$this->info('当前没有在线用户,跳过存点。');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -116,11 +124,11 @@ class AutoSaveExp extends Command
|
||||
/**
|
||||
* 为单个在线用户执行存点逻辑,并在其所在房间推送存点通知。
|
||||
*
|
||||
* @param string $username 用户名
|
||||
* @param int $roomId 所在房间ID
|
||||
* @param string $username 用户名
|
||||
* @param int $roomId 所在房间ID
|
||||
* @param string $expGainRaw 经验奖励原始配置(支持 "1" 或 "1-10" 范围)
|
||||
* @param string $jjbGainRaw 金币奖励原始配置
|
||||
* @param int $superLevel 管理员等级阈值
|
||||
* @param int $superLevel 管理员等级阈值
|
||||
*/
|
||||
private function processUser(
|
||||
string $username,
|
||||
@@ -134,30 +142,53 @@ class AutoSaveExp extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 发放经验奖励(支持 VIP 倍率)
|
||||
$expGain = $this->parseRewardValue($expGainRaw);
|
||||
// 1. 计算奖励量(经验/金币 均支持 VIP 倍率)
|
||||
$expGain = $this->parseRewardValue($expGainRaw);
|
||||
$expMultiplier = $this->vipService->getExpMultiplier($user);
|
||||
$actualExpGain = (int) round($expGain * $expMultiplier);
|
||||
$user->exp_num += $actualExpGain;
|
||||
|
||||
// 2. 发放金币奖励(支持 VIP 倍率)
|
||||
$jjbGain = $this->parseRewardValue($jjbGainRaw);
|
||||
$jjbGain = $this->parseRewardValue($jjbGainRaw);
|
||||
$actualJjbGain = 0;
|
||||
if ($jjbGain > 0) {
|
||||
$jjbMultiplier = $this->vipService->getJjbMultiplier($user);
|
||||
$actualJjbGain = (int) round($jjbGain * $jjbMultiplier);
|
||||
$user->jjb = ($user->jjb ?? 0) + $actualJjbGain;
|
||||
}
|
||||
|
||||
// 3. 自动升降级(管理员不参与)
|
||||
$oldLevel = $user->user_level;
|
||||
// 2. 通过统一积分服务发放奖励(原子写入 + 流水记录)
|
||||
if ($actualExpGain > 0) {
|
||||
$this->currencyService->change(
|
||||
$user, 'exp', $actualExpGain, CurrencySource::AUTO_SAVE, '自动存点', $roomId,
|
||||
);
|
||||
}
|
||||
if ($actualJjbGain > 0) {
|
||||
$this->currencyService->change(
|
||||
$user, 'gold', $actualJjbGain, CurrencySource::AUTO_SAVE, '自动存点', $roomId,
|
||||
);
|
||||
}
|
||||
$user->refresh(); // 刷新获取最新属性(service 已原子更新)
|
||||
$user->load(['activePosition.position.department', 'vipLevel']); // 存点通知需要展示部门、职务与会员身份。
|
||||
|
||||
// 3. 自动升降级逻辑
|
||||
// - 有在职职务的用户:等级固定为职务对应等级,不随经验变化
|
||||
// - 管理员(>= superLevel):不变动
|
||||
// - 普通用户:按经验计算等级,支持升降级
|
||||
$oldLevel = $user->user_level;
|
||||
$leveledUp = false;
|
||||
|
||||
if ($oldLevel < $superLevel) {
|
||||
$activeUP = $user->activePosition; // 已在 refresh 后加载
|
||||
|
||||
if ($activeUP?->position) {
|
||||
// 有在职职务:等级锁定为职务设定值,确保不被经验系统覆盖
|
||||
$requiredLevel = (int) $activeUP->position->level;
|
||||
if ($requiredLevel > 0 && $user->user_level !== $requiredLevel) {
|
||||
$user->user_level = $requiredLevel;
|
||||
}
|
||||
} elseif ($oldLevel < $superLevel) {
|
||||
// 普通用户:按经验计算并更新等级
|
||||
$newLevel = Sysparam::calculateLevel($user->exp_num);
|
||||
if ($newLevel !== $oldLevel && $newLevel < $superLevel) {
|
||||
$user->user_level = $newLevel;
|
||||
$leveledUp = ($newLevel > $oldLevel);
|
||||
$leveledUp = ($newLevel > $oldLevel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,19 +197,27 @@ class AutoSaveExp extends Command
|
||||
// 4. 若升级,向全频道广播升级消息
|
||||
if ($leveledUp) {
|
||||
$sysMsg = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => '系统传音',
|
||||
'to_user' => '大家',
|
||||
'content' => "天道酬勤!恭喜侠客【{$user->username}】挂机苦修,境界突破至 LV.{$user->user_level}!",
|
||||
'is_secret' => false,
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => '系统传音',
|
||||
'to_user' => '大家',
|
||||
'content' => "天道酬勤!恭喜侠客【{$user->username}】挂机苦修,境界突破至 LV.{$user->user_level}!",
|
||||
'is_secret' => false,
|
||||
'font_color' => '#d97706',
|
||||
'action' => '大声宣告',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
'action' => '大声宣告',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
$this->chatState->pushMessage($roomId, $sysMsg);
|
||||
broadcast(new MessageSent($roomId, $sysMsg));
|
||||
SaveMessageJob::dispatch($sysMsg);
|
||||
|
||||
// 触发微信机器人私聊通知 (等级提升)
|
||||
try {
|
||||
$wechatService = app(\App\Services\WechatBot\WechatNotificationService::class);
|
||||
$wechatService->notifyLevelChange($user, $oldLevel, $newLevel);
|
||||
} catch (\Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error('WechatBot level change notification failed', ['error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 向用户私人推送"系统为你自动存点"信息,在其聊天框显示
|
||||
@@ -190,26 +229,31 @@ class AutoSaveExp extends Command
|
||||
$gainParts[] = "金币+{$actualJjbGain}";
|
||||
}
|
||||
$jjbDisplay = $user->jjb ?? 0;
|
||||
$gainStr = ! empty($gainParts) ? ' 本次获得:' . implode(',', $gainParts) : '';
|
||||
$gainStr = ! empty($gainParts) ? ' 本次获得:'.implode(',', $gainParts) : '';
|
||||
|
||||
// 格式:⏰ 自动存点 · LV.100 · 经验 10,468 · 金币 8,345 · 已满级 · 本次获得:经验+1,金币+3
|
||||
$statusTag = $user->user_level >= $superLevel ? ' · 已满级 ✓' : '';
|
||||
$content = "⏰ 自动存点 · LV.{$user->user_level} · 经验 {$user->exp_num} · 金币 {$jjbDisplay}{$statusTag}{$gainStr}";
|
||||
$identitySummary = $this->chatUserPresenceService->buildIdentitySummary($user);
|
||||
|
||||
// 格式:⏰ 自动存点 · 部门 X · 职务 Y · 会员 Z · LV.100 · 经验 10,468 · 金币 8,345 · 已满级 · 本次获得:经验+1,金币+3
|
||||
$statusTag = $user->user_level >= $superLevel ? ' · 已满级 ✓' : '';
|
||||
$content = "⏰ 自动存点 · {$identitySummary['inline']} · LV.{$user->user_level} · 经验 {$user->exp_num} · 金币 {$jjbDisplay}{$statusTag}{$gainStr}";
|
||||
|
||||
$noticeMsg = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => '系统',
|
||||
'to_user' => $username, // 定向推送给本人
|
||||
'content' => $content,
|
||||
'is_secret' => true, // 私信模式:前端过滤,只有收件人才能看到
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => '系统',
|
||||
'to_user' => $username, // 定向推送给本人
|
||||
'content' => $content,
|
||||
'is_secret' => true, // 私信模式:前端过滤,只有收件人才能看到
|
||||
'font_color' => '#16a34a', // 草绿色
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
$this->chatState->pushMessage($roomId, $noticeMsg);
|
||||
broadcast(new MessageSent($roomId, $noticeMsg));
|
||||
|
||||
// 6. 同步更新在职用户的勤务时长
|
||||
$this->tickDutyLog($user, $roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,16 +264,71 @@ class AutoSaveExp extends Command
|
||||
* - 随机范围:如 "3-10" → 返回 [3, 10] 之间的随机整数
|
||||
*
|
||||
* @param string $raw 原始配置字符串
|
||||
* @return int
|
||||
*/
|
||||
private function parseRewardValue(string $raw): int
|
||||
{
|
||||
$raw = trim($raw);
|
||||
if (str_contains($raw, '-')) {
|
||||
[$min, $max] = explode('-', $raw, 2);
|
||||
|
||||
return rand((int) $min, (int) $max);
|
||||
}
|
||||
|
||||
return (int) $raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动存点时同步更新或创建在职用户的勤务日志。
|
||||
*
|
||||
* 逻辑同 ChatController::tickDutyLog:
|
||||
* 1. 无在职职务 → 跳过
|
||||
* 2. 今日已有开放日志 → 刷新 duration_seconds
|
||||
* 3. 今日无日志 → 新建,login_at 取 user->in_time(进房时间)
|
||||
*
|
||||
* @param \App\Models\User $user 已 refresh 的用户实例
|
||||
* @param int $roomId 所在房间 ID
|
||||
*/
|
||||
private function tickDutyLog(User $user, int $roomId): void
|
||||
{
|
||||
// 无论有无职务,均记录在线流水
|
||||
$activeUP = $user->activePosition;
|
||||
|
||||
// ① 今日未关闭的开放日志 → 刷新时长
|
||||
$openLog = PositionDutyLog::query()
|
||||
->where('user_id', $user->id)
|
||||
->whereNull('logout_at')
|
||||
->whereDate('login_at', today())
|
||||
->first();
|
||||
|
||||
if ($openLog) {
|
||||
DB::table('position_duty_logs')
|
||||
->where('id', $openLog->id)
|
||||
->update([
|
||||
'duration_seconds' => DB::raw('GREATEST(0, TIMESTAMPDIFF(SECOND, login_at, NOW()))'),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// ② 今日无开放日志 → 新建
|
||||
// 若今日已有已关闭的日志(是重建场景),必须用 now(),防止重用旧 in_time 累积膨胀
|
||||
$hasClosedToday = PositionDutyLog::query()
|
||||
->where('user_id', $user->id)
|
||||
->whereDate('login_at', today())
|
||||
->whereNotNull('logout_at')
|
||||
->exists();
|
||||
|
||||
$loginAt = (! $hasClosedToday && $user->in_time && $user->in_time->isToday())
|
||||
? $user->in_time
|
||||
: now();
|
||||
|
||||
PositionDutyLog::create([
|
||||
'user_id' => $user->id,
|
||||
'user_position_id' => $activeUP?->id,
|
||||
'login_at' => $loginAt,
|
||||
'ip_address' => '0.0.0.0',
|
||||
'room_id' => $roomId,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:清理房间在线名单的 Redis 缓存
|
||||
* 用于清除历史遗留的「幽灵在线」脏数据
|
||||
*
|
||||
* 执行方式:php artisan room:clear-online-cache
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
class ClearRoomOnlineCache extends Command
|
||||
{
|
||||
/**
|
||||
* Artisan 命令名称
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'room:clear-online-cache';
|
||||
|
||||
/**
|
||||
* 命令描述
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '清空所有房间的 Redis 在线名单(清除幽灵在线脏数据)';
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
*
|
||||
* 扫描所有 room:*:users Redis Key 并删除,让用户重新进房时写入干净数据。
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$prefix = config('database.redis.options.prefix', '');
|
||||
$cursor = '0';
|
||||
$cleaned = 0;
|
||||
|
||||
$this->info("Redis 前缀:\"{$prefix}\"");
|
||||
$this->info('开始扫描 room:*:users ...');
|
||||
|
||||
do {
|
||||
[$cursor, $keys] = Redis::scan($cursor, ['match' => $prefix.'room:*:users', 'count' => 100]);
|
||||
foreach ($keys ?? [] as $fullKey) {
|
||||
// 去掉 Redis 前缀,还原为 Laravel Facade 使用的短 Key
|
||||
$shortKey = $prefix ? substr($fullKey, strlen($prefix)) : $fullKey;
|
||||
Redis::del($shortKey);
|
||||
$this->line(" ✓ 已清除:{$shortKey}");
|
||||
$cleaned++;
|
||||
}
|
||||
} while ($cursor !== '0');
|
||||
|
||||
$this->info("完成!共清理 {$cleaned} 个房间的在线名单。");
|
||||
$this->info('用户下次进房会重新写入正确数据,人数从 0 开始准确累计。');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:自动关闭掉线职务日志指令
|
||||
*
|
||||
* 每 15 分钟由 Laravel Scheduler 调用,扫描 position_duty_logs 表中:
|
||||
* - logout_at IS NULL(尚未结算的开放日志)
|
||||
* - updated_at 超过 15 分钟未刷新(说明心跳已中断,用户已掉线/关闭浏览器)
|
||||
*
|
||||
* 对此类日志写入 logout_at = NOW(),保留 duration_seconds 现有值不清零,
|
||||
* 确保累计时长计算准确,不因掉线而永久悬空。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\PositionDutyLog;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CloseStaleDutyLogs extends Command
|
||||
{
|
||||
/**
|
||||
* Artisan 指令名称
|
||||
*/
|
||||
protected $signature = 'duty:close-stale-logs';
|
||||
|
||||
/**
|
||||
* 指令描述(在 artisan list 中显示)
|
||||
*/
|
||||
protected $description = '自动关闭 15 分钟内无心跳的开放职务日志(解决掉线不结算问题)';
|
||||
|
||||
/**
|
||||
* 指令入口:将长时间无心跳刷新的开放日志判定为掉线,写入 logout_at 完成结算。
|
||||
*
|
||||
* 判定标准:updated_at 超过 15 分钟(心跳间隔约 30 秒,5 分钟自动存点最长 5 分钟,
|
||||
* 留足 10 分钟容差,总计 15 分钟无刷新即认为掉线)
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
// 15 分钟无心跳 = 掉线判定阈值
|
||||
$threshold = now()->subMinutes(15);
|
||||
|
||||
// 批量关闭符合条件的开放日志,保留现有 duration_seconds
|
||||
$affected = PositionDutyLog::query()
|
||||
->whereNull('logout_at')
|
||||
->where('updated_at', '<=', $threshold)
|
||||
->update([
|
||||
'logout_at' => DB::raw('NOW()'),
|
||||
// 补算最终在线时长,避免日榜 SUM 使用过时的旧值
|
||||
'duration_seconds' => DB::raw('GREATEST(0, TIMESTAMPDIFF(SECOND, login_at, NOW()))'),
|
||||
]);
|
||||
|
||||
if ($affected > 0) {
|
||||
$this->info("共关闭 {$affected} 条掉线职务日志。");
|
||||
} else {
|
||||
$this->info('无需处理,无掉线日志。');
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:微信机器人 Kafka 消费命令
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Services\WechatBot\KafkaConsumerService;
|
||||
use App\Services\WechatBot\WechatBotApiService;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ConsumeWechatMessages extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'wechat-bot:consume';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '消费 Kafka 微信机器人消息(守护进程)';
|
||||
|
||||
protected KafkaConsumerService $kafkaService;
|
||||
|
||||
public function __construct(KafkaConsumerService $kafkaService)
|
||||
{
|
||||
parent::__construct();
|
||||
$this->kafkaService = $kafkaService;
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$this->info('正在启动微信机器人 Kafka 消费者...');
|
||||
|
||||
$consumer = $this->kafkaService->createConsumer();
|
||||
if (! $consumer) {
|
||||
$this->error('Kafka 配置不完整或加载失败,请在后台检查机器人设置。');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->info('消费者已启动,等待消息...');
|
||||
|
||||
$apiService = new WechatBotApiService;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
$messageJson = $consumer->consume();
|
||||
if ($messageJson) {
|
||||
$rawJson = $messageJson->getValue();
|
||||
$this->info('--> 收到新的 Kafka 消息 (Raw Length: '.strlen($rawJson).')');
|
||||
|
||||
$messages = $this->kafkaService->parseKafkaMessage($rawJson);
|
||||
|
||||
if (empty($messages)) {
|
||||
$this->info('--> 解析后:无匹配的 AddMsgs 内容');
|
||||
}
|
||||
|
||||
foreach ($messages as $msg) {
|
||||
try {
|
||||
$this->processMessage($msg, $apiService);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('处理单条微信消息失败', [
|
||||
'error' => $e->getMessage(),
|
||||
'msg' => $msg,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$consumer->ack($messageJson);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Kafka 消费异常', ['error' => $e->getMessage()]);
|
||||
// 延迟重试避免死循环 CPU 空转
|
||||
sleep(2);
|
||||
}
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理单条消息逻辑
|
||||
*/
|
||||
protected function processMessage(array $msg, WechatBotApiService $apiService): void
|
||||
{
|
||||
// 仅处理文本消息 (msg_type = 1)
|
||||
if ($msg['msg_type'] != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
$content = trim($msg['content']);
|
||||
$fromUser = $msg['from_user'];
|
||||
$isChatroom = $msg['is_chatroom'];
|
||||
|
||||
// 绑定逻辑:必须是私聊(防止在群内绑定导致未来系统无法直接通过私聊推送个人通知)
|
||||
if (! $isChatroom && preg_match('/^BD-\d{6}$/i', $content)) {
|
||||
$this->info("收到潜在绑定请求: {$content} from {$fromUser}");
|
||||
$this->handleBindRequest(strtoupper($content), $fromUser, $apiService);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理账号绑定请求
|
||||
*/
|
||||
protected function handleBindRequest(string $code, string $wxid, WechatBotApiService $apiService): void
|
||||
{
|
||||
$cacheKey = 'wechat_bind_code:'.$code;
|
||||
$username = Cache::get($cacheKey);
|
||||
|
||||
if (! $username) {
|
||||
$apiService->sendTextMessage($wxid, '❌ 绑定失败:该验证码无效或已过有效期(5分钟)。请在个人中心重新生成。');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$user = User::where('username', $username)->first();
|
||||
if (! $user) {
|
||||
$apiService->sendTextMessage($wxid, '❌ 绑定失败:找不到对应的用户账号。');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 判断该微信号是否已经被其他用户绑定(防止碰撞或安全隐患)
|
||||
$existing = User::where('wxid', $wxid)->where('id', '!=', $user->id)->first();
|
||||
if ($existing) {
|
||||
$apiService->sendTextMessage($wxid, "❌ 绑定失败:当前微信号已经被其他账号 [{$existing->username}] 绑定。请先解绑后再试。");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$user->wxid = $wxid;
|
||||
$user->save();
|
||||
|
||||
// 验证成功后立即销毁验证码
|
||||
Cache::forget($cacheKey);
|
||||
|
||||
$this->info("用户 [{$username}] 成功绑定微信: {$wxid}");
|
||||
|
||||
$successMsg = "🎉 绑定成功!\n"
|
||||
."您已成功绑定聊天室账号:[{$username}]。\n"
|
||||
.'现在您可以接收重要系统通知了。';
|
||||
|
||||
$apiService->sendTextMessage($wxid, $successMsg);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,12 @@ use App\Models\Message;
|
||||
use App\Models\Sysparam;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* 定期清理聊天记录命令
|
||||
* 负责删除过期文本消息,并额外回收聊天图片文件。
|
||||
*/
|
||||
class PurgeOldMessages extends Command
|
||||
{
|
||||
/**
|
||||
@@ -27,6 +32,7 @@ class PurgeOldMessages extends Command
|
||||
*/
|
||||
protected $signature = 'messages:purge
|
||||
{--days= : 覆盖默认保留天数}
|
||||
{--image-days=3 : 聊天图片单独保留天数}
|
||||
{--dry-run : 仅预览不实际删除}';
|
||||
|
||||
/**
|
||||
@@ -34,7 +40,7 @@ class PurgeOldMessages extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '清理超过指定天数的聊天记录(保留天数由 sysparam message_retention_days 配置,默认 30 天)';
|
||||
protected $description = '清理过期聊天记录,并额外清理 3 天前的聊天图片文件';
|
||||
|
||||
/**
|
||||
* 执行命令
|
||||
@@ -46,10 +52,13 @@ class PurgeOldMessages extends Command
|
||||
// 保留天数:命令行参数 > sysparam 配置 > 默认 30 天
|
||||
$days = (int) ($this->option('days')
|
||||
?: Sysparam::getValue('message_retention_days', '30'));
|
||||
$imageDays = max(0, (int) $this->option('image-days'));
|
||||
|
||||
$cutoff = Carbon::now()->subDays($days);
|
||||
$isDryRun = $this->option('dry-run');
|
||||
|
||||
$this->cleanupExpiredImages($imageDays, $isDryRun);
|
||||
|
||||
// 统计待清理数量
|
||||
$totalCount = Message::where('sent_at', '<', $cutoff)->count();
|
||||
|
||||
@@ -88,4 +97,63 @@ class PurgeOldMessages extends Command
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理超过图片保留天数的聊天图片文件,并把消息改成过期占位。
|
||||
*/
|
||||
private function cleanupExpiredImages(int $imageDays, bool $isDryRun): void
|
||||
{
|
||||
$imageCutoff = Carbon::now()->subDays($imageDays);
|
||||
|
||||
$query = Message::query()
|
||||
->where('message_type', 'image')
|
||||
->where('sent_at', '<', $imageCutoff)
|
||||
->where(function ($builder) {
|
||||
$builder->whereNotNull('image_path')->orWhereNotNull('image_thumb_path');
|
||||
});
|
||||
|
||||
$totalCount = (clone $query)->count();
|
||||
|
||||
if ($totalCount === 0) {
|
||||
$this->line("🖼️ 没有超过 {$imageDays} 天的聊天图片需要清理。");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($isDryRun) {
|
||||
$this->warn("🔍 [预览模式] 将清理 {$totalCount} 条超过 {$imageDays} 天的聊天图片(截止 {$imageCutoff->toDateTimeString()})");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$processed = 0;
|
||||
$query->orderBy('id')->chunkById(200, function ($messages) use (&$processed) {
|
||||
foreach ($messages as $message) {
|
||||
$paths = array_values(array_filter([
|
||||
$message->image_path,
|
||||
$message->image_thumb_path,
|
||||
]));
|
||||
|
||||
// 先删物理文件,再把数据库消息降级成“图片已过期”占位,避免出现坏图。
|
||||
if ($paths !== []) {
|
||||
Storage::disk('public')->delete($paths);
|
||||
}
|
||||
|
||||
$placeholder = trim((string) $message->content);
|
||||
$placeholder = $placeholder !== '' ? $placeholder.' [图片已过期]' : '[图片已过期]';
|
||||
|
||||
$message->forceFill([
|
||||
'content' => $placeholder,
|
||||
'message_type' => 'expired_image',
|
||||
'image_path' => null,
|
||||
'image_thumb_path' => null,
|
||||
'image_original_name' => null,
|
||||
])->save();
|
||||
|
||||
$processed++;
|
||||
}
|
||||
});
|
||||
|
||||
$this->info("🖼️ 已清理 {$processed} 条超过 {$imageDays} 天的聊天图片。");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:测试发送微信机器人消息
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\SysParam;
|
||||
use App\Services\WechatBot\WechatBotApiService;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class WechatBotTestSend extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'wechat-bot:test-send';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '测试发送一条消息给管理员设定的微信群群 wxid';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$this->info('开始测试微信机器人发送...');
|
||||
|
||||
$param = SysParam::where('alias', 'wechat_bot_config')->first();
|
||||
if (! $param || empty($param->body)) {
|
||||
$this->error('错误:未找到 wechat_bot_config 配置,请先在后台保存一次配置。');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$config = json_decode($param->body, true);
|
||||
$targetWxid = $config['group_notify']['target_wxid'] ?? '';
|
||||
|
||||
if (empty($targetWxid)) {
|
||||
$this->error('错误:请于后台填写【目标微信群 Wxid】。');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
if (empty($config['api']['bot_key'] ?? '')) {
|
||||
$this->error('错误:未配置【机器人 Key (必需)】,API请求将被拒绝(返回该链接不存在)。');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$service = new WechatBotApiService;
|
||||
|
||||
$this->info("发送目标: {$targetWxid}");
|
||||
$this->info('发送 API Base: '.($config['api']['base_url'] ?? ''));
|
||||
|
||||
$message = "【系统连通性测试】\n发送时间:".now()->format('Y-m-d H:i:s')."\n如果您看到了这条消息,说明 ChatRoom 通知全站群发接口配置正确!";
|
||||
|
||||
$result = $service->sendTextMessage($targetWxid, $message);
|
||||
|
||||
if ($result['success']) {
|
||||
$this->info('✅ 发送成功!');
|
||||
|
||||
return self::SUCCESS;
|
||||
} else {
|
||||
$this->error('❌ 发送失败:'.($result['error'] ?? '未知错误'));
|
||||
$this->warn('如果提示『该链接不存在』代表您的基础API URL 或接入 Key 有误。');
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:积分来源活动枚举
|
||||
* 集中管理所有合法的 source 标识值,新增活动只需在此加一行常量,数据库字段无需任何变更。
|
||||
* 对应数据表:user_currency_logs.source(varchar 字段,非 ENUM,可自由扩展)
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum CurrencySource: string
|
||||
{
|
||||
/** 自动存点(Horizon 定时任务,每5分钟给在线用户加经验/金币) */
|
||||
case AUTO_SAVE = 'auto_save';
|
||||
|
||||
/** 钓鱼收竿奖励(获得经验或金币) */
|
||||
case FISHING_GAIN = 'fishing_gain';
|
||||
|
||||
/** 钓鱼抛竿消耗(扣除金币) */
|
||||
case FISHING_COST = 'fishing_cost';
|
||||
|
||||
/** 送出礼物(送方扣金币) */
|
||||
case SEND_GIFT = 'send_gift';
|
||||
|
||||
/** 收到礼物(收方魅力增加) */
|
||||
case RECV_GIFT = 'recv_gift';
|
||||
|
||||
/** 新人礼包(首次登录赠送金币) */
|
||||
case NEWBIE_BONUS = 'newbie_bonus';
|
||||
|
||||
/** 商城购买消耗(扣除金币) */
|
||||
case SHOP_BUY = 'shop_buy';
|
||||
|
||||
/** 管理员手动调整(后台直接修改经验/金币/魅力) */
|
||||
case ADMIN_ADJUST = 'admin_adjust';
|
||||
|
||||
/** 职务奖励(在职管理员通过名片弹窗向用户发放奖励金币) */
|
||||
case POSITION_REWARD = 'position_reward';
|
||||
|
||||
/** 每日签到奖励(连续签到按规则发放) */
|
||||
case SIGN_IN = 'sign_in';
|
||||
|
||||
/** AI赠送福利(用户向AI祈求获得的随机奖励) */
|
||||
case AI_GIFT = 'ai_gift';
|
||||
|
||||
/** 赠人玫瑰(用户或AI对外发放金币红包) */
|
||||
case GIFT_SENT = 'gift_sent';
|
||||
|
||||
// ─── 以后新增活动,在这里加一行即可,数据库无需变更 ───────────
|
||||
// case TASK_REWARD = 'task_reward'; // 任务奖励
|
||||
// case PVP_WIN = 'pvp_win'; // PVP 胜利奖励
|
||||
|
||||
// ─── 婚姻系统 ────────────────────────────────────────────────
|
||||
|
||||
/** 结婚魅力加成(双方各获得,由戒指档次决定) */
|
||||
case MARRY_CHARM = 'marry_charm';
|
||||
|
||||
/** 离婚魅力惩罚(协议/强制/超时自动)*/
|
||||
case DIVORCE_CHARM = 'divorce_charm';
|
||||
|
||||
/** 购买戒指(gold 消耗,由 ShopService 代理) */
|
||||
case RING_BUY = 'ring_buy';
|
||||
|
||||
/** 戒指消失记录(求婚被拒/超时,金额=0,仅存档) */
|
||||
case RING_LOST = 'ring_lost';
|
||||
|
||||
/** 发送婚礼红包(扣除金币) */
|
||||
case WEDDING_ENV_SEND = 'wedding_env_send';
|
||||
|
||||
/** 领取婚礼红包(收入金币) */
|
||||
case WEDDING_ENV_RECV = 'wedding_env_recv';
|
||||
|
||||
/** 强制离婚财产转移(付出方为负,接收方为正) */
|
||||
case FORCED_DIVORCE_TRANSFER = 'forced_divorce_transfer';
|
||||
|
||||
/** 节日福利红包(管理员设置的定时金币福利) */
|
||||
case HOLIDAY_BONUS = 'holiday_bonus';
|
||||
|
||||
/** 百家乐下注消耗(扣除金币) */
|
||||
case BACCARAT_BET = 'baccarat_bet';
|
||||
|
||||
/** 百家乐中奖赔付(收入金币,含本金返还) */
|
||||
case BACCARAT_WIN = 'baccarat_win';
|
||||
|
||||
/** 百家乐买单活动补偿领取(收入金币) */
|
||||
case BACCARAT_LOSS_COVER_CLAIM = 'baccarat_loss_cover_claim';
|
||||
|
||||
/** 星海小博士随机事件(好运/坏运/经验/金币奖惩) */
|
||||
case AUTO_EVENT = 'auto_event';
|
||||
|
||||
/** 老虎机转动消耗金币 */
|
||||
case SLOT_SPIN = 'slot_spin';
|
||||
|
||||
/** 老虎机中奖赔付(含本金返还) */
|
||||
case SLOT_WIN = 'slot_win';
|
||||
|
||||
/** 老虎机诅咒额外扣除 */
|
||||
case SLOT_CURSE = 'slot_curse';
|
||||
|
||||
/** 领取礼包红包——金币(用户抢到金币礼包时收入) */
|
||||
case RED_PACKET_RECV = 'red_packet_recv';
|
||||
|
||||
/** 领取礼包红包——经验(用户抢到经验礼包时收入) */
|
||||
case RED_PACKET_RECV_EXP = 'red_packet_recv_exp';
|
||||
|
||||
/** 神秘箱子——领取奖励(普通箱/稀有箱,正数金币) */
|
||||
case MYSTERY_BOX = 'mystery_box';
|
||||
|
||||
/** 神秘箱子——黑化陷阱(倒扣金币,负数) */
|
||||
case MYSTERY_BOX_TRAP = 'mystery_box_trap';
|
||||
|
||||
/** 赛马竞猜——下注消耗(扣除金币) */
|
||||
case HORSE_BET = 'horse_bet';
|
||||
|
||||
/** 赛马竞猜——中奖赔付(收入金币,含本金返还) */
|
||||
case HORSE_WIN = 'horse_win';
|
||||
|
||||
/** 神秘占卜——额外次数消耗(扣除金币) */
|
||||
case FORTUNE_COST = 'fortune_cost';
|
||||
|
||||
/** 双色球购票消耗(每注扣除 ticket_price 金币) */
|
||||
case LOTTERY_BUY = 'lottery_buy';
|
||||
|
||||
/** 双色球中奖派奖(所有奖级统一用此 source,备注写奖级详情) */
|
||||
case LOTTERY_WIN = 'lottery_win';
|
||||
|
||||
/** 五子棋 PvP 对战入场费(PvE 欻入场费) */
|
||||
case GOMOKU_ENTRY_FEE = 'gomoku_entry_fee';
|
||||
|
||||
/** 五子棋对战胜利奖励(PvP/PvE 获胜时收入) */
|
||||
case GOMOKU_WIN = 'gomoku_win';
|
||||
|
||||
/** 五子棋 PvE 入场费返还(平局时返还) */
|
||||
case GOMOKU_REFUND = 'gomoku_refund';
|
||||
|
||||
/** 看视频赚金币与经验奖励 */
|
||||
case VIDEO_REWARD = 'video_reward';
|
||||
|
||||
/** 查看别人隐藏信息扣费 */
|
||||
case USER_INFO_REVEAL = 'user_info_reveal';
|
||||
|
||||
/**
|
||||
* 返回该来源的中文名称,用于后台统计展示。
|
||||
*/
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::AUTO_SAVE => '自动存点',
|
||||
self::FISHING_GAIN => '钓鱼奖励',
|
||||
self::FISHING_COST => '钓鱼消耗',
|
||||
self::SEND_GIFT => '送出礼物',
|
||||
self::RECV_GIFT => '收到礼物',
|
||||
self::NEWBIE_BONUS => '新人礼包',
|
||||
self::SHOP_BUY => '商城购买',
|
||||
self::ADMIN_ADJUST => '管理员调整',
|
||||
self::POSITION_REWARD => '职务奖励',
|
||||
self::SIGN_IN => '每日签到',
|
||||
self::AI_GIFT => 'AI赠送',
|
||||
self::GIFT_SENT => '发红包',
|
||||
self::MARRY_CHARM => '结婚魅力加成',
|
||||
self::DIVORCE_CHARM => '离婚魅力惩罚',
|
||||
self::RING_BUY => '购买戒指',
|
||||
self::RING_LOST => '戒指消失',
|
||||
self::WEDDING_ENV_SEND => '发送婚礼红包',
|
||||
self::WEDDING_ENV_RECV => '领取婚礼红包',
|
||||
self::FORCED_DIVORCE_TRANSFER => '强制离婚财产转移',
|
||||
self::HOLIDAY_BONUS => '节日福利',
|
||||
self::BACCARAT_BET => '百家乐下注',
|
||||
self::BACCARAT_WIN => '百家乐赢钱',
|
||||
self::BACCARAT_LOSS_COVER_CLAIM => '百家乐买单活动补偿',
|
||||
self::AUTO_EVENT => '随机事件(星海小博士)',
|
||||
self::SLOT_SPIN => '老虎机转动',
|
||||
self::SLOT_WIN => '老虎机中奖',
|
||||
self::SLOT_CURSE => '老虎机诅咒',
|
||||
self::RED_PACKET_RECV => '领取礼包红包(金币)',
|
||||
self::RED_PACKET_RECV_EXP => '领取礼包红包(经验)',
|
||||
self::MYSTERY_BOX => '神秘箱子奖励',
|
||||
self::MYSTERY_BOX_TRAP => '神秘箱子陷阱',
|
||||
self::HORSE_BET => '赛马下注',
|
||||
self::HORSE_WIN => '赛马赢钱',
|
||||
self::FORTUNE_COST => '神秘占卜消耗',
|
||||
self::LOTTERY_BUY => '双色球购票',
|
||||
self::LOTTERY_WIN => '双色球中奖',
|
||||
self::GOMOKU_ENTRY_FEE => '五子棋入场费',
|
||||
self::GOMOKU_WIN => '五子棋获胜奖励',
|
||||
self::GOMOKU_REFUND => '五子棋入场费返还',
|
||||
self::VIDEO_REWARD => '看视频奖励',
|
||||
self::USER_INFO_REVEAL => '信息查看付费',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:婚姻亲密度来源枚举
|
||||
*
|
||||
* 集中管理所有合法的亲密度增减来源标识,写入 marriage_intimacy_logs.source。
|
||||
* 新增来源只需在此加一行,数据库字段无需变更(VARCHAR 类型)。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum IntimacySource: string
|
||||
{
|
||||
/** 每日时间奖励(Horizon 00:00 定时任务) */
|
||||
case DAILY_TIME = 'daily_time';
|
||||
|
||||
/** 双方同时在线(AutoSaveJob 每分钟检测) */
|
||||
case ONLINE_TOGETHER = 'online_together';
|
||||
|
||||
/** 收到伴侣送花 */
|
||||
case RECV_FLOWER = 'recv_flower';
|
||||
|
||||
/** 向伴侣送花 */
|
||||
case SEND_FLOWER = 'send_flower';
|
||||
|
||||
/** 发送私聊消息(每2条 +1) */
|
||||
case PRIVATE_CHAT = 'private_chat';
|
||||
|
||||
/** 结婚时戒指初始亲密度加成(一次性) */
|
||||
case WEDDING_BONUS = 'wedding_bonus';
|
||||
|
||||
/** 管理员手动调整 */
|
||||
case ADMIN_ADJUST = 'admin_adjust';
|
||||
|
||||
/**
|
||||
* 返回该来源的中文名称(后台统计展示用)。
|
||||
*/
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::DAILY_TIME => '每日时间奖励',
|
||||
self::ONLINE_TOGETHER => '双方同时在线',
|
||||
self::RECV_FLOWER => '收到伴侣送花',
|
||||
self::SEND_FLOWER => '向伴侣送花',
|
||||
self::PRIVATE_CHAT => '私聊消息',
|
||||
self::WEDDING_BONUS => '结婚戒指加成',
|
||||
self::ADMIN_ADJUST => '管理员调整',
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:任命公告广播事件
|
||||
* 任命操作成功后向对应聊天室 PresenceChannel 推送任命消息,
|
||||
* 前端接收后展示全屏礼花动画和隆重公告弹窗。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class AppointmentAnnounced implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* 构建任命公告事件
|
||||
*
|
||||
* @param int $roomId 广播目标房间 ID
|
||||
* @param string $targetUsername 被任命用户名
|
||||
* @param string $positionIcon 职务图标
|
||||
* @param string $positionName 职务名称
|
||||
* @param string $departmentName 所属部门名称
|
||||
* @param string $operatorName 任命人用户名
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly int $roomId,
|
||||
public readonly string $targetUsername,
|
||||
public readonly string $positionIcon,
|
||||
public readonly string $positionName,
|
||||
public readonly string $departmentName,
|
||||
public readonly string $operatorName,
|
||||
public readonly string $type = 'appoint', // appoint | revoke
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至目标房间的 PresenceChannel
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PresenceChannel('room.'.$this->roomId),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'type' => $this->type,
|
||||
'target_username' => $this->targetUsername,
|
||||
'position_icon' => $this->positionIcon,
|
||||
'position_name' => $this->positionName,
|
||||
'department_name' => $this->departmentName,
|
||||
'operator_name' => $this->operatorName,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:百家乐押注人数实时广播事件
|
||||
*
|
||||
* 当有用户成功下注时,向房间内所有用户广播最新的
|
||||
* 各选项下注总人次,供前端实时更新面板。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\BaccaratRound;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class BaccaratPoolUpdated implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param BaccaratRound $round 本局信息
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly BaccaratRound $round,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至房间公共频道。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PresenceChannel('room.1')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播事件名(前端监听 .baccarat.pool_updated)。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'baccarat.pool_updated';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'round_id' => $this->round->id,
|
||||
'bet_count_big' => $this->round->bet_count_big,
|
||||
'bet_count_small' => $this->round->bet_count_small,
|
||||
'bet_count_triple' => $this->round->bet_count_triple,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:百家乐开局广播事件
|
||||
*
|
||||
* 新局开始时广播给房间所有用户,携带局次 ID 和下注截止时间,
|
||||
* 前端收到后展示倒计时下注面板。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\BaccaratRound;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class BaccaratRoundOpened implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param BaccaratRound $round 本局信息
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly BaccaratRound $round,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至房间公共频道。
|
||||
*
|
||||
* @return array<Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PresenceChannel('room.1')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播事件名(前端监听 .baccarat.opened)。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'baccarat.opened';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'round_id' => $this->round->id,
|
||||
'bet_opens_at' => $this->round->bet_opens_at->toIso8601String(),
|
||||
'bet_closes_at' => $this->round->bet_closes_at->toIso8601String(),
|
||||
'bet_seconds' => (int) now()->diffInSeconds($this->round->bet_closes_at),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:百家乐结算广播事件
|
||||
*
|
||||
* 开奖后广播骰子结果和获奖类型,前端播放骰子动画,
|
||||
* 并显示用户是否中奖及赔付金额。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\BaccaratRound;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class BaccaratRoundSettled implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param BaccaratRound $round 已结算的局次
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly BaccaratRound $round,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至房间公共频道。
|
||||
*
|
||||
* @return array<Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PresenceChannel('room.1')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播事件名(前端监听 .baccarat.settled)。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'baccarat.settled';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据:骰子点数 + 开奖结果 + 统计。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'round_id' => $this->round->id,
|
||||
'dice' => [$this->round->dice1, $this->round->dice2, $this->round->dice3],
|
||||
'total_points' => $this->round->total_points,
|
||||
'result' => $this->round->result,
|
||||
'result_label' => $this->round->resultLabel(),
|
||||
'total_payout' => $this->round->total_payout,
|
||||
'bet_count' => $this->round->bet_count,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:通用大卡片通知广播事件
|
||||
*
|
||||
* 可向指定用户(私有频道)或房间所有人(Presence 频道)推送全屏大卡片通知。
|
||||
* 前端通过 window.chatBanner.show(options) 渲染,支持完全自定义。
|
||||
*
|
||||
* 使用示例(后端):
|
||||
*
|
||||
* // 推给单个用户
|
||||
* broadcast(new BannerNotification(
|
||||
* target: 'user',
|
||||
* targetId: 'lkddi',
|
||||
* options: [
|
||||
* 'icon' => '💚📩',
|
||||
* 'title' => '好友申请',
|
||||
* 'name' => 'lkddi1',
|
||||
* 'body' => '将你加为好友了!',
|
||||
* 'gradient' => ['#1e3a5f', '#1d4ed8', '#0891b2'],
|
||||
* 'autoClose' => 0,
|
||||
* 'buttons' => [
|
||||
* ['label' => '➕ 回加好友', 'color' => '#10b981', 'action' => 'add_friend', 'actionData' => 'lkddi1'],
|
||||
* ['label' => '稍后再说', 'color' => 'rgba(255,255,255,0.15)', 'action' => 'close'],
|
||||
* ],
|
||||
* ]
|
||||
* ));
|
||||
*
|
||||
* // 推给整个房间
|
||||
* broadcast(new BannerNotification(target: 'room', targetId: 1, options: [...] ));
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class BannerNotification implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* 构造通用大卡片通知事件。
|
||||
*
|
||||
* @param string $target 推送目标类型:'user'(私有频道)| 'room'(房间全员)
|
||||
* @param string|int $targetId 目标 ID:用户名(user)或 房间 ID(room)
|
||||
* @param array<string, mixed> $options 前端 chatBanner.show() 选项(详见文件顶部注释)
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $target,
|
||||
public readonly string|int $targetId,
|
||||
public readonly array $options = [],
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 根据 $target 决定广播到私有频道还是 Presence 频道。
|
||||
*/
|
||||
public function broadcastOn(): Channel
|
||||
{
|
||||
return match ($this->target) {
|
||||
'user' => new PrivateChannel('user.'.$this->targetId),
|
||||
'room' => new PresenceChannel('room.'.$this->targetId),
|
||||
default => new PrivateChannel('user.'.$this->targetId),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定广播事件名称,供前端 .listen('.BannerNotification') 匹配。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'BannerNotification';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播负载:传递完整的 options 给前端渲染。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'target' => $this->target,
|
||||
'target_id' => $this->targetId,
|
||||
'options' => $this->options,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:聊天室浏览器刷新请求广播事件
|
||||
*
|
||||
* 仅供站长触发“刷新全员”命令时使用,
|
||||
* 向当前房间所有在线用户广播前端刷新指令。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* 类功能:向房间内全部在线用户广播页面刷新指令。
|
||||
*/
|
||||
class BrowserRefreshRequested implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* 构造函数:记录房间与操作者信息。
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly int $roomId,
|
||||
public readonly string $operator,
|
||||
public readonly string $reason = '',
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播频道:当前聊天室 PresenceChannel。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PresenceChannel('room.'.$this->roomId),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据:前端用于展示提示并执行刷新。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'operator' => $this->operator,
|
||||
'reason' => $this->reason,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:开发日志发布广播事件
|
||||
* 当管理员发布新的开发日志并勾选"通知大厅"时触发
|
||||
* 广播至 Room ID=1(星光大厅)的 presence 频道
|
||||
* 前端监听此事件并在聊天消息区显示系统通知(含可点击的查看详情链接)
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\DevChangelog;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* 开发日志发布广播事件
|
||||
* 负责把更新日志的安全展示字段广播给大厅聊天室。
|
||||
*/
|
||||
class ChangelogPublished implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* 构造函数:传入触发通知的日志对象
|
||||
*
|
||||
* @param DevChangelog $changelog 刚发布的开发日志
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly DevChangelog $changelog,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播频道:仅向 Room 1(星光大厅)的 presence 频道广播
|
||||
* 复用现有聊天室频道机制,无需额外配置
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
// 固定广播至 Room ID = 1 的大厅频道
|
||||
new PresenceChannel('room.1'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播事件名称(前端 .listen('ChangelogPublished', ...) 监听此名称)
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'ChangelogPublished';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播携带的数据(前端可直接访问)
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'version' => $this->changelog->version,
|
||||
'title' => $this->changelog->title,
|
||||
'type' => $this->changelog->type,
|
||||
'type_label' => $this->changelog->type_label,
|
||||
// 同步提供已转义字段,便于前端在 innerHTML 场景下直接复用安全文本。
|
||||
'safe_version' => e((string) $this->changelog->version),
|
||||
'safe_title' => e((string) $this->changelog->title),
|
||||
'safe_type_label' => e((string) $this->changelog->type_label),
|
||||
// 前端点击后跳转的目标 URL,自动锚定至对应版本
|
||||
'url' => $this->buildDetailUrl(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成广播使用的更新日志详情地址,并编码版本锚点避免 href 注入。
|
||||
*/
|
||||
private function buildDetailUrl(): string
|
||||
{
|
||||
return route('changelog.index').'#v'.rawurlencode((string) $this->changelog->version);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ChatBotToggled implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*/
|
||||
public function __construct(
|
||||
public array $user,
|
||||
public bool $isOnline
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new Channel('chat.system'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,12 @@
|
||||
/**
|
||||
* 文件功能:聊天室全屏特效广播事件
|
||||
*
|
||||
* 管理员触发烟花/下雨/雷电等特效后,
|
||||
* 通过 WebSocket 广播给房间内所有在线用户,前端收到后播放对应 Canvas 动画。
|
||||
* 管理员或用户购买单次卡后触发,通过 WebSocket 广播给房间内用户播放 Canvas 动画。
|
||||
* 支持指定接收者;当存在 target_username 时,触发者本人和指定接收者都应可见。
|
||||
*
|
||||
* @package App\Events
|
||||
* @author ChatRoom Laravel
|
||||
* @version 1.0.0
|
||||
*
|
||||
* @version 2.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
@@ -26,19 +26,23 @@ class EffectBroadcast implements ShouldBroadcastNow
|
||||
/**
|
||||
* 支持的特效类型列表(用于校验)
|
||||
*/
|
||||
public const TYPES = ['fireworks', 'rain', 'lightning'];
|
||||
public const TYPES = ['fireworks', 'rain', 'lightning', 'snow', 'sakura', 'meteors', 'gold-rain', 'hearts', 'confetti', 'fireflies'];
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param int $roomId 房间 ID
|
||||
* @param string $type 特效类型:fireworks / rain / lightning
|
||||
* @param string $operator 触发特效的管理员用户名
|
||||
* @param int $roomId 房间 ID
|
||||
* @param string $type 特效类型:fireworks / rain / lightning / snow / sakura / meteors / gold-rain / hearts / confetti / fireflies
|
||||
* @param string $operator 触发特效的用户名(购买者)
|
||||
* @param string|null $targetUsername 接收者用户名(null = 全员)
|
||||
* @param string|null $giftMessage 附带赠言
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly int $roomId,
|
||||
public readonly string $type,
|
||||
public readonly string $operator,
|
||||
public readonly ?string $targetUsername = null,
|
||||
public readonly ?string $giftMessage = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -49,20 +53,23 @@ class EffectBroadcast implements ShouldBroadcastNow
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PresenceChannel('room.' . $this->roomId),
|
||||
new PresenceChannel('room.'.$this->roomId),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据:特效类型和操作者
|
||||
* 广播数据:特效类型、操作者、目标用户、赠言
|
||||
* 前端据此判断“全员可见”或“仅操作者 + 指定接收者可见”。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'type' => $this->type,
|
||||
'type' => $this->type,
|
||||
'operator' => $this->operator,
|
||||
'target_username' => $this->targetUsername, // null = 全员
|
||||
'gift_message' => $this->giftMessage,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:婚礼红包领取成功事件(广播至领取者私人频道)
|
||||
*
|
||||
* 触发时机:WeddingController::claim() 成功后广播,前端展示到账 Toast。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class EnvelopeClaimed implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param User $claimer 领取用户
|
||||
* @param int $amount 领取金额
|
||||
* @param int $ceremonyId 婚礼仪式 ID
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly User $claimer,
|
||||
public readonly int $amount,
|
||||
public readonly int $ceremonyId,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至领取者私人频道。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PrivateChannel('user.'.$this->claimer->id)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'ceremony_id' => $this->ceremonyId,
|
||||
'amount' => $this->amount,
|
||||
'message' => "🎉 成功领取 {$this->amount} 金币婚礼红包!",
|
||||
];
|
||||
}
|
||||
|
||||
/** 广播事件名称。 */
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'envelope.claimed';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:好友添加广播事件
|
||||
*
|
||||
* 当用户 A 添加用户 B 为好友时,向 B 的私有频道广播此事件。
|
||||
* 频道名使用数字 ID(user.{id}),避免中文用户名导致 Pusher 频道名验证失败。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class FriendAdded implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* 构造好友添加事件。
|
||||
*
|
||||
* @param string $fromUsername 发起添加的用户名(A)
|
||||
* @param string $toUsername 被添加的用户名(B,用于消息显示)
|
||||
* @param int $toUserId 被添加用户的数字 ID(用于私有频道,避免中文名非法)
|
||||
* @param bool $hasAddedBack B 是否已将 A 加为好友(互相添加=true)
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $fromUsername,
|
||||
public readonly string $toUsername,
|
||||
public readonly int $toUserId,
|
||||
public readonly bool $hasAddedBack = false,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播到被添加用户的私有频道(用数字 ID 命名,避免中文频道名不合法)。
|
||||
*/
|
||||
public function broadcastOn(): Channel
|
||||
{
|
||||
return new PrivateChannel('user.'.$this->toUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定广播事件名称(短名),供前端 listen('.FriendAdded') 匹配。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'FriendAdded';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播负载:包含发起人信息和互相好友状态,供前端弹窗使用。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'from_username' => $this->fromUsername,
|
||||
'to_username' => $this->toUsername,
|
||||
'type' => 'friend_added',
|
||||
'has_added_back' => $this->hasAddedBack,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:好友删除广播事件
|
||||
*
|
||||
* 当用户 A 删除用户 B 为好友时,向 B 的私有频道广播此事件。
|
||||
* 频道名使用数字 ID(user.{id}),避免中文用户名导致 Pusher 频道名验证失败。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class FriendRemoved implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* 构造好友删除事件。
|
||||
*
|
||||
* @param string $fromUsername 发起删除的用户名(A)
|
||||
* @param string $toUsername 被删除的用户名(B,用于消息显示)
|
||||
* @param int $toUserId 被删除用户的数字 ID(用于私有频道,避免中文名非法)
|
||||
* @param bool $hadAddedBack B 之前是否也将 A 加为好友(互相好友=true)
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly string $fromUsername,
|
||||
public readonly string $toUsername,
|
||||
public readonly int $toUserId,
|
||||
public readonly bool $hadAddedBack = false,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播到被删除用户的私有频道(用数字 ID 命名,避免中文频道名不合法)。
|
||||
*/
|
||||
public function broadcastOn(): Channel
|
||||
{
|
||||
return new PrivateChannel('user.'.$this->toUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定广播事件名称(短名),供前端 listen('.FriendRemoved') 匹配。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'FriendRemoved';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播负载:包含发起人信息和之前互相好友状态,供前端弹窗使用。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'from_username' => $this->fromUsername,
|
||||
'to_username' => $this->toUsername,
|
||||
'type' => 'friend_removed',
|
||||
'had_added_back' => $this->hadAddedBack,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:五子棋对局结束广播事件
|
||||
*
|
||||
* 对局结束(胜负/平局/认输/超时)时广播两个频道:
|
||||
* 1. 私有对局频道:通知双方结算并关闭棋盘
|
||||
* 2. 房间公共频道:广播战报消息
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\GomokuGame;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class GomokuFinishedEvent implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param GomokuGame $game 当前对局
|
||||
* @param string $winnerName 胜者用户名(平局时为空字符串)
|
||||
* @param string $loserName 败者用户名(平局时为空字符串)
|
||||
* @param string $reason 结束原因:win | draw | resign | timeout
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly GomokuGame $game,
|
||||
public readonly string $winnerName,
|
||||
public readonly string $loserName,
|
||||
public readonly string $reason,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 同时广播至对局私有频道 + 房间公共频道。
|
||||
*
|
||||
* @return array<\Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PrivateChannel("gomoku.{$this->game->id}"),
|
||||
new PresenceChannel("room.{$this->game->room_id}"),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播事件名(前端监听 .gomoku.finished)。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'gomoku.finished';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'game_id' => $this->game->id,
|
||||
'winner' => $this->game->winner,
|
||||
'winner_name' => $this->winnerName,
|
||||
'loser_name' => $this->loserName,
|
||||
'reason' => $this->reason,
|
||||
'reward_gold' => $this->game->reward_gold,
|
||||
'mode' => $this->game->mode,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:五子棋对战邀请广播事件
|
||||
*
|
||||
* 玩家发起对战邀请时广播至房间 Presence 频道,
|
||||
* 前端在聊天消息流中渲染「接受挑战」按钮。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\GomokuGame;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class GomokuInviteEvent implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param GomokuGame $game 对局记录
|
||||
* @param string $inviterName 发起者用户名
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly GomokuGame $game,
|
||||
public readonly string $inviterName,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至对应房间频道。
|
||||
*
|
||||
* @return array<\Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PresenceChannel("room.{$this->game->room_id}")];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播事件名(前端监听 .gomoku.invite)。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'gomoku.invite';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'game_id' => $this->game->id,
|
||||
'inviter_name' => $this->inviterName,
|
||||
'expires_at' => $this->game->invite_expires_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:五子棋落子广播事件
|
||||
*
|
||||
* 每次玩家(或 AI)落子后通过私有对局频道广播,
|
||||
* 双方前端实时更新棋盘显示并切换行棋方。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\GomokuGame;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class GomokuMovedEvent implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param GomokuGame $game 当前对局
|
||||
* @param int $row 落子行(0-14)
|
||||
* @param int $col 落子列(0-14)
|
||||
* @param int $color 落子颜色(1=黑 2=白)
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly GomokuGame $game,
|
||||
public readonly int $row,
|
||||
public readonly int $col,
|
||||
public readonly int $color,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至对局私有频道(仅双方可见)。
|
||||
*
|
||||
* @return array<\Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PrivateChannel("gomoku.{$this->game->id}")];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播事件名(前端监听 .gomoku.moved)。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'gomoku.moved';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'game_id' => $this->game->id,
|
||||
'row' => $this->row,
|
||||
'col' => $this->col,
|
||||
'color' => $this->color,
|
||||
'current_turn' => $this->game->current_turn,
|
||||
'board' => $this->game->board,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:节日福利开始广播事件
|
||||
*
|
||||
* 管理员配置的节日活动到达触发时间后,由 TriggerHolidayEventJob 触发,
|
||||
* 通过 Reverb WebSocket 广播给房间内所有在线用户,
|
||||
* 前端收到后弹出领取弹窗和公屏系统消息。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\HolidayEventRun;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* 类功能:向房间广播节日福利发放批次开始事件。
|
||||
*/
|
||||
class HolidayEventStarted implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param HolidayEventRun $run 节日福利发放批次
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly HolidayEventRun $run,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至房间公共频道(所有在线用户均可收到)。
|
||||
*
|
||||
* @return array<Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PresenceChannel('room.1'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播事件名。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'holiday.started';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据:供前端构建弹窗和公屏消息。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'run_id' => $this->run->id,
|
||||
'event_id' => $this->run->holiday_event_id,
|
||||
'name' => $this->run->event_name,
|
||||
'description' => $this->run->event_description,
|
||||
'total_amount' => $this->run->total_amount,
|
||||
'max_claimants' => $this->run->max_claimants,
|
||||
'distribute_type' => $this->run->distribute_type,
|
||||
'fixed_amount' => $this->run->fixed_amount,
|
||||
'claimed_count' => $this->run->claimed_count,
|
||||
'expires_at' => $this->run->expires_at?->toIso8601String(),
|
||||
'scheduled_for' => $this->run->scheduled_for?->toIso8601String(),
|
||||
'repeat_type' => $this->run->repeat_type,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:赛马开赛广播事件
|
||||
*
|
||||
* 新场次开始押注时广播给房间所有用户,携带场次 ID、
|
||||
* 参赛马匹信息和押注截止时间,前端展示倒计时押注面板。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\HorseRace;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class HorseRaceOpened implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param HorseRace $race 本场信息
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly HorseRace $race,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至房间公共频道。
|
||||
*
|
||||
* @return array<\Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PresenceChannel('room.1')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播事件名(前端监听 .horse.opened)。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'horse.opened';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'race_id' => $this->race->id,
|
||||
'horses' => $this->race->horses,
|
||||
'total_pool' => $this->race->total_pool,
|
||||
'bet_opens_at' => $this->race->bet_opens_at->toIso8601String(),
|
||||
'bet_closes_at' => $this->race->bet_closes_at->toIso8601String(),
|
||||
'bet_seconds' => (int) now()->diffInSeconds($this->race->bet_closes_at),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:赛马进行中实时进度广播事件
|
||||
*
|
||||
* 跑马过程中每隔1秒广播各马匹当前进度(0~100%),
|
||||
* 前端据此实时更新赛道动画。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class HorseRaceProgress implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param int $raceId 场次 ID
|
||||
* @param array<int, int> $positions 各马匹进度 [horse_id => progress(0~100)]
|
||||
* @param bool $finished 是否已到终点
|
||||
* @param int|null $leaderId 当前领跑马匹 ID
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly int $raceId,
|
||||
public readonly array $positions,
|
||||
public readonly bool $finished = false,
|
||||
public readonly ?int $leaderId = null,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至房间公共频道。
|
||||
*
|
||||
* @return array<\Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PresenceChannel('room.1')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播事件名(前端监听 .horse.progress)。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'horse.progress';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'race_id' => $this->raceId,
|
||||
'positions' => $this->positions,
|
||||
'finished' => $this->finished,
|
||||
'leader_id' => $this->leaderId,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:赛马结算广播事件
|
||||
*
|
||||
* 跑马结束後广播赛果(获胜马匹、赔付金额等)给房间所有用户,
|
||||
* 前端收到后展示结算面板并更新中奖信息。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\GameConfig;
|
||||
use App\Models\HorseBet;
|
||||
use App\Models\HorseRace;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* 类功能:赛马结算广播事件
|
||||
*
|
||||
* 向房间公共频道广播最终赛果,并附带前端展示个人奖金所需的
|
||||
* 奖池分配参数,避免结算弹窗只能显示固定的 0 金币。
|
||||
*/
|
||||
class HorseRaceSettled implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param HorseRace $race 已结算的场次
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly HorseRace $race,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至房间公共频道。
|
||||
*
|
||||
* @return array<\Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PresenceChannel('room.1')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播事件名(前端监听 .horse.settled)。
|
||||
*/
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'horse.settled';
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
$config = GameConfig::forGame('horse_racing')?->params ?? [];
|
||||
$houseTake = (int) ($config['house_take_percent'] ?? 5);
|
||||
$seedPool = (int) ($config['seed_pool'] ?? 0);
|
||||
|
||||
// 统计各马匹总下注,为前端还原个人分奖金额提供基础参数。
|
||||
$horsePools = HorseBet::query()
|
||||
->where('race_id', $this->race->id)
|
||||
->groupBy('horse_id')
|
||||
->selectRaw('horse_id, SUM(amount) as pool')
|
||||
->pluck('pool', 'horse_id')
|
||||
->map(fn ($pool) => (int) $pool)
|
||||
->toArray();
|
||||
|
||||
$winnerPool = (int) ($horsePools[$this->race->winner_horse_id] ?? 0);
|
||||
$distributablePool = (int) round(
|
||||
HorseRace::calcDistributablePool($horsePools, $houseTake, $seedPool, $winnerPool)
|
||||
);
|
||||
|
||||
// 找出获胜马匹的名称
|
||||
$horses = $this->race->horses ?? [];
|
||||
$winnerName = '未知';
|
||||
foreach ($horses as $horse) {
|
||||
if (($horse['id'] ?? 0) === $this->race->winner_horse_id) {
|
||||
$winnerName = ($horse['emoji'] ?? '').' '.($horse['name'] ?? '');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'race_id' => $this->race->id,
|
||||
'winner_horse_id' => $this->race->winner_horse_id,
|
||||
'winner_name' => $winnerName,
|
||||
'total_pool' => (int) $this->race->total_pool,
|
||||
'winner_pool' => $winnerPool,
|
||||
'distributable_pool' => $distributablePool,
|
||||
'settled_at' => $this->race->settled_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:结婚公告事件(广播至全房间)
|
||||
*
|
||||
* 触发时机:求婚被接受,正式结婚后广播。
|
||||
* 前端收到后展示全屏烟花特效 + 婚礼设置弹窗(仅婚姻双方)。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Marriage;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class MarriageAccepted implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param Marriage $marriage 婚姻记录
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly Marriage $marriage,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至当前所有房间(PresenceChannel room.*)。
|
||||
* 使用大厅房间 ID=1,若业务支持多房间可扩展。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PresenceChannel('room.1')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
$this->marriage->load(['user:id,username,headface', 'partner:id,username,headface', 'ringItem:id,name,icon']);
|
||||
|
||||
return [
|
||||
'marriage_id' => $this->marriage->id,
|
||||
'user' => $this->marriage->user?->only(['id', 'username', 'headface']),
|
||||
'partner' => $this->marriage->partner?->only(['id', 'username', 'headface']),
|
||||
'ring' => $this->marriage->ringItem?->only(['name', 'icon']),
|
||||
'married_at' => $this->marriage->married_at,
|
||||
];
|
||||
}
|
||||
|
||||
/** 广播事件名称。 */
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'marriage.accepted';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:协议离婚申请通知事件(广播至对方私人频道)
|
||||
*
|
||||
* 触发时机:一方申请协议离婚后广播,对方收到 Banner 含确认/拒绝按钮。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Marriage;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class MarriageDivorceRequested implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param Marriage $marriage 婚姻记录
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly Marriage $marriage,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至对方私人频道(divorcer 的对方)。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
// 离婚申请方的对方
|
||||
$targetId = $this->marriage->user_id === $this->marriage->divorcer_id
|
||||
? $this->marriage->partner_id
|
||||
: $this->marriage->user_id;
|
||||
|
||||
return [new PrivateChannel('user.'.$targetId)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
$this->marriage->load(['user:id,username', 'partner:id,username']);
|
||||
|
||||
$divorcerUsername = $this->marriage->user_id === $this->marriage->divorcer_id
|
||||
? $this->marriage->user?->username
|
||||
: $this->marriage->partner?->username;
|
||||
|
||||
// 读取协议离婚魅力惩罚供前端展示
|
||||
$penalty = (int) \App\Models\MarriageConfig::where('key', 'divorce_mutual_charm')->value('value');
|
||||
// 读取强制离婚魅力惩罚(被拒=强制离婚时申请方受此惩罚)
|
||||
$forcedPenalty = (int) \App\Models\MarriageConfig::where('key', 'divorce_forced_charm')->value('value');
|
||||
|
||||
return [
|
||||
'marriage_id' => $this->marriage->id,
|
||||
'divorcer_username' => $divorcerUsername,
|
||||
'initiator_name' => $divorcerUsername, // 前端兼容字段
|
||||
'timeout_hours' => 72,
|
||||
'requested_at' => $this->marriage->divorce_requested_at,
|
||||
'mutual_charm_penalty' => $penalty, // 协议离婚双方各扣魅力
|
||||
'forced_charm_penalty' => $forcedPenalty, // 不同意→强制,申请方受此惩罚
|
||||
];
|
||||
}
|
||||
|
||||
/** 广播事件名称。 */
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'marriage.divorce_requested';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:离婚公告事件(广播至全房间)
|
||||
*
|
||||
* 触发时机:协议/强制/自动离婚完成后广播。
|
||||
* 强制离婚时额外显示财产转移信息。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Marriage;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class MarriageDivorced implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param Marriage $marriage 婚姻记录
|
||||
* @param string $divorceType 离婚类型(mutual|forced|auto|admin)
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly Marriage $marriage,
|
||||
public readonly string $divorceType,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至全房间。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PresenceChannel('room.1')];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
$this->marriage->load(['user:id,username', 'partner:id,username']);
|
||||
|
||||
return [
|
||||
'user_username' => $this->marriage->user?->username,
|
||||
'partner_username' => $this->marriage->partner?->username,
|
||||
'divorce_type' => $this->divorceType,
|
||||
];
|
||||
}
|
||||
|
||||
/** 广播事件名称。 */
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'marriage.divorced';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:求婚超时失效事件(广播至求婚方私人频道)
|
||||
*
|
||||
* 触发时机:Horizon Job ExpireMarriageProposals 扫描到超时求婚后广播。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Marriage;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class MarriageExpired implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param Marriage $marriage 婚姻记录
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly Marriage $marriage,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至求婚方私人频道。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PrivateChannel('user.'.$this->marriage->user_id)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'partner_username' => $this->marriage->partner?->username,
|
||||
'ring_name' => $this->marriage->ringItem?->name,
|
||||
'message' => '求婚已超时失效,戒指已消失。',
|
||||
];
|
||||
}
|
||||
|
||||
/** 广播事件名称。 */
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'marriage.expired';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:求婚事件(广播至被求婚方私人频道)
|
||||
*
|
||||
* 触发时机:MarriageController::propose() 成功后广播。
|
||||
* B 上线时前端订阅频道立即收到,展示求婚 Banner 弹窗。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Marriage;
|
||||
use App\Models\User;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class MarriageProposed implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param Marriage $marriage 婚姻记录
|
||||
* @param User $proposer 求婚方
|
||||
* @param User $target 被求婚方
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly Marriage $marriage,
|
||||
public readonly User $proposer,
|
||||
public readonly User $target,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至被求婚方私人频道。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PrivateChannel('user.'.$this->target->id)];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'marriage_id' => $this->marriage->id,
|
||||
'proposer' => [
|
||||
'username' => $this->proposer->username,
|
||||
'headface' => $this->proposer->headface,
|
||||
'user_level' => $this->proposer->user_level,
|
||||
],
|
||||
'ring' => $this->marriage->ringItem?->only(['name', 'icon']),
|
||||
'expires_at' => $this->marriage->expires_at,
|
||||
];
|
||||
}
|
||||
|
||||
/** 广播事件名称。 */
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'marriage.proposed';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:求婚被拒事件(广播至求婚方私人频道)
|
||||
*
|
||||
* 触发时机:对方拒绝求婚,戒指消失后广播。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Marriage;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class MarriageRejected implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param Marriage $marriage 婚姻记录
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly Marriage $marriage,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至求婚方私人频道。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PrivateChannel('user.'.$this->marriage->user_id)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'partner_username' => $this->marriage->partner?->username,
|
||||
'ring_name' => $this->marriage->ringItem?->name,
|
||||
'message' => '对方拒绝了您的求婚,戒指已消失。',
|
||||
];
|
||||
}
|
||||
|
||||
/** 广播事件名称。 */
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'marriage.rejected';
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,18 @@
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class MessageSent implements ShouldBroadcast
|
||||
/**
|
||||
* 类功能:根据消息可见范围选择广播频道。
|
||||
*/
|
||||
class MessageSent implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
@@ -32,14 +37,25 @@ class MessageSent implements ShouldBroadcast
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get the channels the event should broadcast on.
|
||||
* 获取消息应广播到的频道。
|
||||
*
|
||||
* 聊天消息广播至包含在线状态管理的 PresenceChannel。
|
||||
* 公共消息走房间 Presence 频道;
|
||||
* 定向消息 / 悄悄话只发给发送方与接收方的私有用户频道。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
if ($this->shouldBroadcastPrivately()) {
|
||||
$privateChannels = [];
|
||||
|
||||
foreach ($this->resolveVisibleUserIds() as $userId) {
|
||||
$privateChannels[] = new PrivateChannel('user.'.$userId);
|
||||
}
|
||||
|
||||
return $privateChannels;
|
||||
}
|
||||
|
||||
return [
|
||||
new PresenceChannel('room.'.$this->roomId),
|
||||
];
|
||||
@@ -56,4 +72,42 @@ class MessageSent implements ShouldBroadcast
|
||||
'message' => $this->message,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前消息是否应仅广播给特定用户。
|
||||
*/
|
||||
private function shouldBroadcastPrivately(): bool
|
||||
{
|
||||
$toUser = trim((string) ($this->message['to_user'] ?? ''));
|
||||
|
||||
return $toUser !== '' && $toUser !== '大家';
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析本条消息真正可见的用户 ID 列表。
|
||||
*
|
||||
* @return array<int, int>
|
||||
*/
|
||||
private function resolveVisibleUserIds(): array
|
||||
{
|
||||
$userIds = [];
|
||||
|
||||
$fromUser = trim((string) ($this->message['from_user'] ?? ''));
|
||||
if ($fromUser !== '') {
|
||||
$senderId = User::query()->where('username', $fromUser)->value('id');
|
||||
if ($senderId !== null) {
|
||||
$userIds[] = (int) $senderId;
|
||||
}
|
||||
}
|
||||
|
||||
$toUser = trim((string) ($this->message['to_user'] ?? ''));
|
||||
if ($toUser !== '' && $toUser !== '大家') {
|
||||
$receiverId = User::query()->where('username', $toUser)->value('id');
|
||||
if ($receiverId !== null) {
|
||||
$userIds[] = (int) $receiverId;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($userIds));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:红包领取成功广播事件(广播至房间与领取者私有频道)
|
||||
*
|
||||
* 触发时机:RedPacketController::claim() 成功后广播,
|
||||
* 房间内在线用户收到后实时刷新剩余份数,领取者本人可同步收到到账提示。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* 类功能:广播礼包被领取后的实时状态
|
||||
*
|
||||
* 统一向房间频道推送剩余份数变化,同时向领取者私有频道推送到账结果,
|
||||
* 让红包弹窗与用户提示保持一致。
|
||||
*/
|
||||
class RedPacketClaimed implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param User $claimer 领取用户
|
||||
* @param int $amount 领取金额
|
||||
* @param int $envelopeId 红包 ID
|
||||
* @param int $roomId 房间 ID
|
||||
* @param int $remainingCount 剩余份数
|
||||
* @param string $type 红包类型
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly User $claimer,
|
||||
public readonly int $amount,
|
||||
public readonly int $envelopeId,
|
||||
public readonly int $roomId,
|
||||
public readonly int $remainingCount,
|
||||
public readonly string $type = 'gold',
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至房间频道与领取者私有频道。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PresenceChannel('room.'.$this->roomId),
|
||||
new PrivateChannel('user.'.$this->claimer->id),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播领取结果与剩余份数。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
$typeLabel = $this->type === 'exp' ? '经验' : '金币';
|
||||
|
||||
return [
|
||||
'envelope_id' => $this->envelopeId,
|
||||
'claimer_id' => $this->claimer->id,
|
||||
'claimer_username' => $this->claimer->username,
|
||||
'amount' => $this->amount,
|
||||
'remaining_count' => $this->remainingCount,
|
||||
'type' => $this->type,
|
||||
'message' => "🧧 成功抢到 {$this->amount} {$typeLabel}礼包!",
|
||||
];
|
||||
}
|
||||
|
||||
/** 广播事件名称。 */
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'red-packet.claimed';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:礼包红包发出事件(广播至房间所有用户)
|
||||
*
|
||||
* 触发时机:AdminCommandController::sendRedPacket() 成功后广播,
|
||||
* 前端接收后显示红包卡片弹窗,并在聊天窗口追加系统公告。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class RedPacketSent implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param int $roomId 房间 ID
|
||||
* @param int $envelopeId 红包 ID
|
||||
* @param string $senderUsername 发包人用户名
|
||||
* @param int $totalAmount 总金额(金币)
|
||||
* @param int $totalCount 总份数
|
||||
* @param int $expireSeconds 过期秒数(用于前端倒计时)
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly int $roomId,
|
||||
public readonly int $envelopeId,
|
||||
public readonly string $senderUsername,
|
||||
public readonly int $totalAmount,
|
||||
public readonly int $totalCount,
|
||||
public readonly int $expireSeconds,
|
||||
public readonly string $type = 'gold',
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至房间 Presence 频道(所有在线用户均可收到)。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PresenceChannel('room.'.$this->roomId)];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据:前端渲染红包弹窗所需字段。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'envelope_id' => $this->envelopeId,
|
||||
'sender_username' => $this->senderUsername,
|
||||
'total_amount' => $this->totalAmount,
|
||||
'total_count' => $this->totalCount,
|
||||
'expire_seconds' => $this->expireSeconds,
|
||||
'type' => $this->type,
|
||||
];
|
||||
}
|
||||
|
||||
/** 自定义事件名称(前端监听时使用)。 */
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'red-packet.sent';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:用户定向页面刷新广播事件
|
||||
*
|
||||
* 在任命或撤销职务成功后,向目标用户私有频道推送刷新指令,
|
||||
* 确保对方页面上的权限按钮与职务状态及时同步。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* 类功能:向指定用户广播页面刷新请求。
|
||||
*/
|
||||
class UserBrowserRefreshRequested implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* 构造函数:记录目标用户与刷新说明。
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly int $targetUserId,
|
||||
public readonly string $operator,
|
||||
public readonly string $reason = '',
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播频道:目标用户私有频道。
|
||||
*/
|
||||
public function broadcastOn(): PrivateChannel
|
||||
{
|
||||
return new PrivateChannel('user.'.$this->targetUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据:供前端展示提示并执行刷新。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'operator' => $this->operator,
|
||||
'reason' => $this->reason,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
/**
|
||||
* 文件功能:用户被踢出房间广播事件
|
||||
*
|
||||
* 管理员踢出/冻结用户时触发,前端监听后强制该用户跳转至大厅。
|
||||
* 管理员踢出/封禁用户时触发,前端监听后强制该用户跳转至大厅。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:聊天室用户状态变更广播事件
|
||||
* 负责在用户设置或清除当日状态后,实时同步当前房间在线名单展示。
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class UserStatusUpdated implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* 构造聊天室用户状态变更广播事件。
|
||||
*
|
||||
* @param int $roomId 房间 ID
|
||||
* @param string $username 状态变更用户昵称
|
||||
* @param array<string, mixed> $user 最新在线名单载荷
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly int $roomId,
|
||||
public readonly string $username,
|
||||
public readonly array $user,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 获取广播频道。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [
|
||||
new PresenceChannel('room.'.$this->roomId),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取广播数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
return [
|
||||
'username' => $this->username,
|
||||
'user' => $this->user,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:婚礼庆典事件(广播至全房间)
|
||||
*
|
||||
* 触发时机:婚礼红包触发分发后广播。
|
||||
* 前端收到后:播放烟花特效 + 婚礼音效 + 展示红包弹窗(含领取按钮)。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\Marriage;
|
||||
use App\Models\WeddingCeremony;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class WeddingCelebration implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
/**
|
||||
* @param WeddingCeremony $ceremony 婚礼仪式记录
|
||||
* @param Marriage $marriage 婚姻记录
|
||||
*/
|
||||
public function __construct(
|
||||
public readonly WeddingCeremony $ceremony,
|
||||
public readonly Marriage $marriage,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 广播至全房间。
|
||||
*
|
||||
* @return array<int, \Illuminate\Broadcasting\Channel>
|
||||
*/
|
||||
public function broadcastOn(): array
|
||||
{
|
||||
return [new PresenceChannel('room.1')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 广播数据(前端据此展示红包弹窗及新人信息)。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function broadcastWith(): array
|
||||
{
|
||||
$this->marriage->load(['user:id,username,headface', 'partner:id,username,headface', 'ringItem:id,name,icon']);
|
||||
|
||||
return [
|
||||
'ceremony_id' => $this->ceremony->id,
|
||||
'tier_name' => $this->ceremony->tier?->name ?? '婚礼',
|
||||
'tier_icon' => $this->ceremony->tier?->icon ?? '🎊',
|
||||
'total_amount' => $this->ceremony->total_amount,
|
||||
'expires_at' => $this->ceremony->expires_at,
|
||||
'user' => $this->marriage->user?->only(['id', 'username', 'headface']),
|
||||
'partner' => $this->marriage->partner?->only(['id', 'username', 'headface']),
|
||||
'ring' => $this->marriage->ringItem?->only(['name', 'icon']),
|
||||
];
|
||||
}
|
||||
|
||||
/** 广播事件名称。 */
|
||||
public function broadcastAs(): string
|
||||
{
|
||||
return 'wedding.celebration';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台隐藏登录控制器
|
||||
*
|
||||
* 仅提供站长独立登录入口,登录成功后直接进入后台控制台,
|
||||
* 不经过聊天室首页与“登录即注册”流程。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\AdminLoginRequest;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 类功能:处理站长隐藏登录页展示与登录提交。
|
||||
*/
|
||||
class AdminAuthController extends Controller
|
||||
{
|
||||
/**
|
||||
* 隐藏登录入口后缀。
|
||||
*/
|
||||
private const LOGIN_SUFFIX = 'lkddi';
|
||||
|
||||
/**
|
||||
* 站长账号固定主键。
|
||||
*/
|
||||
private const SITE_OWNER_ID = 1;
|
||||
|
||||
/**
|
||||
* 显示站长隐藏登录页面。
|
||||
*/
|
||||
public function create(Request $request): View|RedirectResponse
|
||||
{
|
||||
// 已通过隐藏入口登录的站长再次访问时,直接回后台首页
|
||||
if (Auth::id() === self::SITE_OWNER_ID && $request->session()->get('admin_login_via_hidden')) {
|
||||
return redirect()->route('admin.dashboard');
|
||||
}
|
||||
|
||||
return view('admin.auth.login', [
|
||||
'loginSuffix' => self::LOGIN_SUFFIX,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理站长隐藏登录请求。
|
||||
*/
|
||||
public function store(AdminLoginRequest $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validated();
|
||||
$siteOwner = User::query()->find(self::SITE_OWNER_ID);
|
||||
|
||||
// 只有 id=1 的站长账号允许通过该入口进入后台
|
||||
if (! $siteOwner || $siteOwner->username !== $validated['username']) {
|
||||
return back()
|
||||
->withInput($request->safe()->only(['username']))
|
||||
->withErrors(['username' => '该入口仅限站长账号使用。']);
|
||||
}
|
||||
|
||||
if (! $this->passwordMatches($siteOwner, $validated['password'])) {
|
||||
return back()
|
||||
->withInput($request->safe()->only(['username']))
|
||||
->withErrors(['password' => '账号或密码错误。']);
|
||||
}
|
||||
|
||||
// 若当前已有其他账号占用会话,先退出后再切换为站长会话
|
||||
if (Auth::check() && Auth::id() !== $siteOwner->id) {
|
||||
Auth::logout();
|
||||
}
|
||||
|
||||
Auth::login($siteOwner);
|
||||
$request->session()->regenerate();
|
||||
$request->session()->put('admin_login_via_hidden', true);
|
||||
|
||||
// 复用主登录的会话登记逻辑,保证后台入口也会更新登录痕迹
|
||||
$this->recordAdminLogin($siteOwner, (string) $request->ip());
|
||||
|
||||
return redirect()->route('admin.dashboard')->with('success', '站长后台登录成功。');
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验站长密码,兼容旧库 MD5 并自动升级为 bcrypt。
|
||||
*/
|
||||
private function passwordMatches(User $siteOwner, string $plainPassword): bool
|
||||
{
|
||||
try {
|
||||
if (Hash::check($plainPassword, $siteOwner->password)) {
|
||||
return true;
|
||||
}
|
||||
} catch (\RuntimeException $exception) {
|
||||
// 旧库非 bcrypt 密码会在这里抛异常,后续继续走 MD5 兼容逻辑
|
||||
}
|
||||
|
||||
if (md5($plainPassword) !== $siteOwner->password) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 兼容老密码登录成功后,立即升级为 Laravel 默认哈希
|
||||
$siteOwner->forceFill([
|
||||
'password' => Hash::make($plainPassword),
|
||||
])->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录站长通过隐藏入口登录后的访问痕迹。
|
||||
*/
|
||||
private function recordAdminLogin(User $siteOwner, string $ip): void
|
||||
{
|
||||
// 登录成功后补齐访问次数、IP 与时间,保持与前台登录统计一致
|
||||
$siteOwner->increment('visit_num');
|
||||
$siteOwner->update([
|
||||
'previous_ip' => $siteOwner->last_ip,
|
||||
'last_ip' => $ip,
|
||||
'log_time' => now(),
|
||||
'in_time' => now(),
|
||||
]);
|
||||
|
||||
\App\Models\IpLog::create([
|
||||
'ip' => $ip,
|
||||
'sdate' => now(),
|
||||
'uuname' => $siteOwner->username,
|
||||
]);
|
||||
|
||||
try {
|
||||
$wechatService = new \App\Services\WechatBot\WechatNotificationService;
|
||||
$wechatService->notifyAdminOnline($siteOwner);
|
||||
$wechatService->notifyFriendsOnline($siteOwner);
|
||||
$wechatService->notifySpouseOnline($siteOwner);
|
||||
} catch (\Exception $exception) {
|
||||
// 机器人通知异常不影响站长进入后台,但需要落日志便于排查
|
||||
Log::error('Hidden admin login notification failed', ['error' => $exception->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Models\AiProviderConfig;
|
||||
use App\Models\Sysparam;
|
||||
use App\Services\ChatStateService;
|
||||
use App\Services\ChatUserPresenceService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -33,6 +34,7 @@ class AiProviderController extends Controller
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ChatStateService $chatState,
|
||||
private readonly ChatUserPresenceService $chatUserPresenceService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -46,8 +48,76 @@ class AiProviderController extends Controller
|
||||
{
|
||||
$providers = AiProviderConfig::orderBy('sort_order')->get();
|
||||
$chatbotEnabled = Sysparam::getValue('chatbot_enabled', '0') === '1';
|
||||
$chatbotMaxGold = Sysparam::getValue('chatbot_max_gold', '5000');
|
||||
$chatbotMaxDailyRewards = Sysparam::getValue('chatbot_max_daily_rewards', '1');
|
||||
$chatbotFishingEnabled = Sysparam::getValue('chatbot_fishing_enabled', '0') === '1';
|
||||
$chatbotFishingChance = Sysparam::getValue('chatbot_fishing_chance', '5');
|
||||
$chatbotBaccaratEnabled = Sysparam::getValue('chatbot_baccarat_enabled', '0') === '1';
|
||||
|
||||
return view('admin.ai-providers.index', compact('providers', 'chatbotEnabled'));
|
||||
return view('admin.ai-providers.index', compact(
|
||||
'providers', 'chatbotEnabled', 'chatbotMaxGold',
|
||||
'chatbotMaxDailyRewards', 'chatbotFishingEnabled', 'chatbotFishingChance', 'chatbotBaccaratEnabled'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存全局设置
|
||||
*/
|
||||
public function updateSettings(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'chatbot_max_gold' => 'required|integer|min:1',
|
||||
'chatbot_max_daily_rewards' => 'required|integer|min:1',
|
||||
'chatbot_fishing_enabled' => 'required|in:0,1',
|
||||
'chatbot_fishing_chance' => 'required|integer|min:1|max:100',
|
||||
'chatbot_baccarat_enabled' => 'required|in:0,1',
|
||||
]);
|
||||
Sysparam::updateOrCreate(
|
||||
['alias' => 'chatbot_max_gold'],
|
||||
[
|
||||
'body' => (string) $data['chatbot_max_gold'],
|
||||
'guidetxt' => '单次最高发放金币金额',
|
||||
]
|
||||
);
|
||||
Sysparam::clearCache('chatbot_max_gold');
|
||||
|
||||
Sysparam::updateOrCreate(
|
||||
['alias' => 'chatbot_max_daily_rewards'],
|
||||
[
|
||||
'body' => (string) $data['chatbot_max_daily_rewards'],
|
||||
'guidetxt' => '每个用户单日最多获得金币次数',
|
||||
]
|
||||
);
|
||||
Sysparam::clearCache('chatbot_max_daily_rewards');
|
||||
|
||||
Sysparam::updateOrCreate(
|
||||
['alias' => 'chatbot_fishing_enabled'],
|
||||
[
|
||||
'body' => $data['chatbot_fishing_enabled'],
|
||||
'guidetxt' => 'AI 参与钓鱼游戏开关',
|
||||
]
|
||||
);
|
||||
Sysparam::clearCache('chatbot_fishing_enabled');
|
||||
|
||||
Sysparam::updateOrCreate(
|
||||
['alias' => 'chatbot_fishing_chance'],
|
||||
[
|
||||
'body' => (string) $data['chatbot_fishing_chance'],
|
||||
'guidetxt' => 'AI 钓鱼抛竿概率 (每分钟)',
|
||||
]
|
||||
);
|
||||
Sysparam::clearCache('chatbot_fishing_chance');
|
||||
|
||||
Sysparam::updateOrCreate(
|
||||
['alias' => 'chatbot_baccarat_enabled'],
|
||||
[
|
||||
'body' => $data['chatbot_baccarat_enabled'],
|
||||
'guidetxt' => 'AI 参与百家乐游戏开关',
|
||||
]
|
||||
);
|
||||
Sysparam::clearCache('chatbot_baccarat_enabled');
|
||||
|
||||
return back()->with('success', '全局设置保存成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,14 +262,150 @@ class AiProviderController extends Controller
|
||||
Sysparam::clearCache('chatbot_enabled');
|
||||
|
||||
$status = $newValue === '1' ? '开启' : '关闭';
|
||||
$isEnabled = $newValue === '1';
|
||||
|
||||
// 确保 AI 实体账号存在
|
||||
$user = \App\Models\User::firstOrCreate(
|
||||
['username' => 'AI小班长'],
|
||||
[
|
||||
'password' => \Illuminate\Support\Facades\Hash::make(\Illuminate\Support\Str::random(16)),
|
||||
'user_level' => 10,
|
||||
'sex' => 0, // 女性
|
||||
'usersf' => 'storage/avatars/ai_bot_cn_girl.png',
|
||||
'jjb' => 1000000,
|
||||
'sign' => '本群首席智慧小管家',
|
||||
]
|
||||
);
|
||||
|
||||
// 防止后期头像变动,强制更新到最新女生头像
|
||||
if (! str_contains($user->usersf ?? '', 'ai_bot_cn_girl.png')) {
|
||||
$user->update([
|
||||
'usersf' => 'storage/avatars/ai_bot_cn_girl.png',
|
||||
'sex' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
// 机器人在线载荷也统一走聊天室展示服务,避免名单字段口径逐步漂移。
|
||||
$userData = $this->chatUserPresenceService->build($user);
|
||||
|
||||
// 广播机器人进出事件(供前端名单增删)
|
||||
broadcast(new \App\Events\ChatBotToggled($userData, $isEnabled));
|
||||
|
||||
// 像真实的玩家一样,对全网活跃房间进行高调进出场播报
|
||||
$activeRoomIds = $this->chatState->getAllActiveRoomIds();
|
||||
if (empty($activeRoomIds)) {
|
||||
$activeRoomIds = [1]; // 兜底
|
||||
}
|
||||
|
||||
// 把 AI 实体挂名到一个主房间,即可被 app/Console/Commands/AutoSaveExp.php 扫描发经验
|
||||
$mainRoomId = $activeRoomIds[0];
|
||||
if ($isEnabled) {
|
||||
$this->chatState->userJoin($mainRoomId, $user->username, $userData);
|
||||
} else {
|
||||
// 清理可能存在的所有房间的残留挂名
|
||||
foreach ($activeRoomIds as $rId) {
|
||||
$this->chatState->userLeave($rId, $user->username);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($activeRoomIds as $roomId) {
|
||||
$content = $isEnabled
|
||||
? '<span style="color: #9333ea; font-weight: bold;">🤖 【AI小班长】 迈着整齐的步伐进入了房间,随时为您服务!</span>'
|
||||
: '<span style="color: #9ca3af; font-weight: bold;">🤖 【AI小班长】 去休息啦,大家聊得开心!</span>';
|
||||
|
||||
$botMsg = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => '进出播报',
|
||||
'to_user' => '大家',
|
||||
'content' => $content,
|
||||
'is_secret' => false,
|
||||
'font_color' => '#9333ea',
|
||||
'action' => 'system_welcome',
|
||||
'welcome_user' => $user->username,
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
$this->chatState->pushMessage($roomId, $botMsg);
|
||||
broadcast(new \App\Events\MessageSent($roomId, $botMsg));
|
||||
\App\Jobs\SaveMessageJob::dispatch($botMsg);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => "聊天机器人已{$status}",
|
||||
'enabled' => $newValue === '1',
|
||||
'enabled' => $isEnabled,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试指定 AI 厂商的接口连通性
|
||||
*
|
||||
* 通过 GET /v1/models 检查端点可达性与 API Key 有效性,毫秒级响应,
|
||||
* 不触发模型推理,避免经 Cloudflare 代理时因推理耗时导致 524 超时。
|
||||
*
|
||||
* @param int $id 厂商配置 ID
|
||||
* @return JsonResponse 测试结果(含可用模型列表)
|
||||
*/
|
||||
public function testConnection(int $id): JsonResponse
|
||||
{
|
||||
$provider = AiProviderConfig::findOrFail($id);
|
||||
|
||||
$apiKey = $provider->getDecryptedApiKey();
|
||||
$base = rtrim($provider->api_endpoint, '/');
|
||||
|
||||
// 拼接 /v1/models 端点(检查连通性,不触发推理)
|
||||
$modelsUrl = str_ends_with($base, '/v1')
|
||||
? $base.'/models'
|
||||
: $base.'/v1/models';
|
||||
|
||||
$startTime = microtime(true);
|
||||
|
||||
try {
|
||||
$response = \Illuminate\Support\Facades\Http::withToken($apiKey)
|
||||
->timeout(10)
|
||||
->get($modelsUrl);
|
||||
|
||||
$ms = (int) ((microtime(true) - $startTime) * 1000);
|
||||
|
||||
if (! $response->successful()) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => "HTTP {$response->status()}:{$response->body()}",
|
||||
'ms' => $ms,
|
||||
]);
|
||||
}
|
||||
|
||||
$data = $response->json();
|
||||
|
||||
// 提取可用模型列表(兼容 Ollama 和 OpenAI 格式)
|
||||
$models = collect($data['models'] ?? $data['data'] ?? [])
|
||||
->pluck('id')
|
||||
->filter()
|
||||
->values()
|
||||
->toArray();
|
||||
|
||||
$modelList = count($models) > 0
|
||||
? implode('、', array_slice($models, 0, 5)).(count($models) > 5 ? ' 等' : '')
|
||||
: $provider->model;
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'message' => "接口连通正常,可用模型:{$modelList}",
|
||||
'ms' => $ms,
|
||||
'models' => $models,
|
||||
]);
|
||||
} catch (\Illuminate\Http\Client\ConnectionException $e) {
|
||||
$ms = (int) ((microtime(true) - $startTime) * 1000);
|
||||
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => '连接失败:'.$e->getMessage(),
|
||||
'ms' => $ms,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除 AI 厂商配置
|
||||
*
|
||||
|
||||
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台任命管理控制器
|
||||
* 管理员可以在此查看所有在职人员、进行新增任命和撤销职务
|
||||
* 任命/撤销通过 AppointmentService 执行,权限日志自动记录
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Events\AppointmentAnnounced;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Department;
|
||||
use App\Models\Position;
|
||||
use App\Models\User;
|
||||
use App\Models\UserPosition;
|
||||
use App\Services\AppointmentService;
|
||||
use App\Services\ChatStateService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class AppointmentController extends Controller
|
||||
{
|
||||
/**
|
||||
* 注入任命服务
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly AppointmentService $appointmentService,
|
||||
private readonly ChatStateService $chatState,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 任命管理主列表(当前全部在职人员)
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
// 所有在职记录(按部门 rank 倒序、职务 rank 倒序)
|
||||
$activePositions = UserPosition::query()
|
||||
->where('is_active', true)
|
||||
->with([
|
||||
'user',
|
||||
'position.department',
|
||||
'appointedBy',
|
||||
])
|
||||
->join('positions', 'user_positions.position_id', '=', 'positions.id')
|
||||
->join('departments', 'positions.department_id', '=', 'departments.id')
|
||||
->orderByDesc('departments.rank')
|
||||
->orderByDesc('positions.rank')
|
||||
->select('user_positions.*')
|
||||
->get();
|
||||
|
||||
// 部门+职务(供新增任命弹窗下拉选择,带在职人数统计)
|
||||
$departments = Department::with([
|
||||
'positions' => fn ($q) => $q->withCount('activeUserPositions')->ordered(),
|
||||
])->ordered()->get();
|
||||
|
||||
return view('admin.appointments.index', compact('activePositions', 'departments'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行新增任命
|
||||
* 管理员在后台直接任命用户,操作人为当前登录管理员
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'username' => 'required|string|exists:users,username',
|
||||
'position_id' => 'required|exists:positions,id',
|
||||
'remark' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
$operator = Auth::user();
|
||||
$target = User::where('username', $request->username)->firstOrFail();
|
||||
$targetPosition = Position::with('department')->findOrFail($request->position_id);
|
||||
|
||||
$result = $this->appointmentService->appoint($operator, $target, $targetPosition, $request->remark);
|
||||
|
||||
if ($result['ok']) {
|
||||
// 向所有当前有人在线的聊天室广播礼花公告(后台操作人不在聊天室内)
|
||||
foreach ($this->chatState->getAllActiveRoomIds() as $roomId) {
|
||||
broadcast(new AppointmentAnnounced(
|
||||
roomId: $roomId,
|
||||
targetUsername: $target->username,
|
||||
positionIcon: $targetPosition->icon ?? '🎖️',
|
||||
positionName: $targetPosition->name,
|
||||
departmentName: $targetPosition->department?->name ?? '',
|
||||
operatorName: $operator->username,
|
||||
));
|
||||
}
|
||||
|
||||
return redirect()->route('admin.appointments.index')->with('success', $result['message']);
|
||||
}
|
||||
|
||||
return redirect()->route('admin.appointments.index')->with('error', $result['message']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 撤销职务
|
||||
*/
|
||||
public function revoke(Request $request, UserPosition $userPosition): RedirectResponse
|
||||
{
|
||||
$operator = Auth::user();
|
||||
$target = $userPosition->user;
|
||||
|
||||
// 撤销前先记录职务信息(撤销后关联就断了)
|
||||
$userPosition->load('position.department');
|
||||
$posIcon = $userPosition->position?->icon ?? '🎖️';
|
||||
$posName = $userPosition->position?->name ?? '';
|
||||
$deptName = $userPosition->position?->department?->name ?? '';
|
||||
|
||||
$result = $this->appointmentService->revoke($operator, $target, $request->remark);
|
||||
|
||||
if ($result['ok']) {
|
||||
// 向所有活跃房间广播撤销公告
|
||||
if ($posName) {
|
||||
foreach ($this->chatState->getAllActiveRoomIds() as $roomId) {
|
||||
broadcast(new AppointmentAnnounced(
|
||||
roomId: $roomId,
|
||||
targetUsername: $target->username,
|
||||
positionIcon: $posIcon,
|
||||
positionName: $posName,
|
||||
departmentName: $deptName,
|
||||
operatorName: $operator->username,
|
||||
type: 'revoke',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->route('admin.appointments.index')->with('success', $result['message']);
|
||||
}
|
||||
|
||||
return redirect()->route('admin.appointments.index')->with('error', $result['message']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看某任职记录的在职登录日志
|
||||
*/
|
||||
public function dutyLogs(UserPosition $userPosition): View
|
||||
{
|
||||
$userPosition->load(['user', 'position.department', 'appointedBy']);
|
||||
|
||||
$logs = $userPosition->dutyLogs()
|
||||
->orderByDesc('login_at')
|
||||
->paginate(30);
|
||||
|
||||
// 计算该任职记录的所有在线时长总和(而非当前页)
|
||||
$totalSeconds = $userPosition->dutyLogs()->sum('duration_seconds');
|
||||
|
||||
return view('admin.appointments.duty-logs', compact('userPosition', 'logs', 'totalSeconds'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看某任职记录的权限操作日志
|
||||
*/
|
||||
public function authorityLogs(UserPosition $userPosition): View
|
||||
{
|
||||
$userPosition->load(['user', 'position.department']);
|
||||
|
||||
$logs = $userPosition->authorityLogs()
|
||||
->with(['targetUser', 'targetPosition'])
|
||||
->orderByDesc('created_at')
|
||||
->paginate(30);
|
||||
|
||||
return view('admin.appointments.authority-logs', compact('userPosition', 'logs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 历史任职记录(全部 is_active=false 的记录)
|
||||
*/
|
||||
public function history(): View
|
||||
{
|
||||
$history = UserPosition::query()
|
||||
->where('is_active', false)
|
||||
->with(['user', 'position.department', 'appointedBy', 'revokedBy'])
|
||||
->orderByDesc('revoked_at')
|
||||
->paginate(30);
|
||||
|
||||
return view('admin.appointments.history', compact('history'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的履职记录:展示当前登录者自己所有的权限操作记录
|
||||
*
|
||||
* 不限于某一任职周期,展示全部历史操作,支持按操作类型和日期筛选。
|
||||
*/
|
||||
public function myDutyLogs(Request $request): View
|
||||
{
|
||||
$user = Auth::user();
|
||||
$query = \App\Models\PositionAuthorityLog::where('user_id', $user->id)
|
||||
->with(['targetUser:id,username', 'targetPosition:id,name', 'userPosition.position.department']);
|
||||
|
||||
// 按操作类型筛选
|
||||
if ($request->filled('type')) {
|
||||
$query->where('action_type', $request->type);
|
||||
}
|
||||
|
||||
// 按日期范围筛选
|
||||
if ($request->filled('date_from')) {
|
||||
$query->whereDate('created_at', '>=', $request->date_from);
|
||||
}
|
||||
if ($request->filled('date_to')) {
|
||||
$query->whereDate('created_at', '<=', $request->date_to);
|
||||
}
|
||||
|
||||
$logs = $query->orderByDesc('created_at')->paginate(30)->withQueryString();
|
||||
|
||||
// 汇总统计
|
||||
$summary = \App\Models\PositionAuthorityLog::where('user_id', $user->id)
|
||||
->selectRaw('action_type, COUNT(*) as total, COALESCE(SUM(amount),0) as amount_sum')
|
||||
->groupBy('action_type')
|
||||
->get()
|
||||
->keyBy('action_type');
|
||||
|
||||
return view('admin.appointments.my-duty-logs', compact('logs', 'summary', 'user'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索用户(供任命弹窗 Ajax 快速查找)
|
||||
*/
|
||||
public function searchUsers(Request $request): JsonResponse
|
||||
{
|
||||
$keyword = $request->input('q', '');
|
||||
|
||||
$users = User::query()
|
||||
->where('id', '!=', 1) // 排除超级管理员
|
||||
->where('username', 'like', "%{$keyword}%")
|
||||
->whereDoesntHave('activePosition') // 排除已有职务的用户
|
||||
->select('id', 'username', 'user_level')
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
return response()->json($users);
|
||||
}
|
||||
}
|
||||
@@ -52,10 +52,12 @@ class AutoactController extends Controller
|
||||
|
||||
/**
|
||||
* 更新事件
|
||||
*
|
||||
* @param Autoact $autoact 路由模型自动注入
|
||||
*/
|
||||
public function update(Request $request, int $id): RedirectResponse
|
||||
public function update(Request $request, Autoact $autoact): RedirectResponse
|
||||
{
|
||||
$event = Autoact::findOrFail($id);
|
||||
$event = $autoact;
|
||||
|
||||
$data = $request->validate([
|
||||
'text_body' => 'required|string|max:500',
|
||||
@@ -71,26 +73,29 @@ class AutoactController extends Controller
|
||||
|
||||
/**
|
||||
* 切换事件启用/禁用状态
|
||||
*
|
||||
* @param Autoact $autoact 路由模型自动注入
|
||||
*/
|
||||
public function toggle(int $id): JsonResponse
|
||||
public function toggle(Autoact $autoact): JsonResponse
|
||||
{
|
||||
$event = Autoact::findOrFail($id);
|
||||
$event->enabled = ! $event->enabled;
|
||||
$event->save();
|
||||
$autoact->enabled = ! $autoact->enabled;
|
||||
$autoact->save();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'enabled' => $event->enabled,
|
||||
'message' => $event->enabled ? '已启用' : '已禁用',
|
||||
'enabled' => $autoact->enabled,
|
||||
'message' => $autoact->enabled ? '已启用' : '已禁用',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除事件
|
||||
*
|
||||
* @param Autoact $autoact 路由模型自动注入
|
||||
*/
|
||||
public function destroy(int $id): RedirectResponse
|
||||
public function destroy(Autoact $autoact): RedirectResponse
|
||||
{
|
||||
Autoact::findOrFail($id)->delete();
|
||||
$autoact->delete();
|
||||
|
||||
return redirect()->route('admin.autoact.index')->with('success', '事件已删除!');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:百家乐买单活动后台控制器
|
||||
*
|
||||
* 提供聊天室管理员在输入框上方快捷创建活动、
|
||||
* 查看当前活动并手动结束活动的 JSON 接口。
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StoreBaccaratLossCoverEventRequest;
|
||||
use App\Models\BaccaratLossCoverEvent;
|
||||
use App\Services\BaccaratLossCoverService;
|
||||
use App\Services\PositionPermissionService;
|
||||
use App\Support\PositionPermissionRegistry;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* 类功能:处理聊天室顶部快捷入口创建与结束百家乐买单活动。
|
||||
*/
|
||||
class BaccaratLossCoverEventController extends Controller
|
||||
{
|
||||
/**
|
||||
* 注入百家乐买单活动服务。
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly BaccaratLossCoverService $lossCoverService,
|
||||
private readonly PositionPermissionService $positionPermissionService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 创建新的百家乐买单活动。
|
||||
*/
|
||||
public function store(StoreBaccaratLossCoverEventRequest $request): JsonResponse
|
||||
{
|
||||
if (! $this->positionPermissionService->hasPermission($request->user(), PositionPermissionRegistry::ROOM_BACCARAT_LOSS_COVER)) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => '当前职务无权创建买单活动。',
|
||||
], 403);
|
||||
}
|
||||
|
||||
try {
|
||||
$event = $this->lossCoverService->createEvent($request->user(), $request->validated());
|
||||
} catch (\RuntimeException $exception) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => $exception->getMessage(),
|
||||
], 422);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'message' => "活动「{$event->title}」已创建成功。",
|
||||
'event_id' => $event->id,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动结束或取消一场百家乐买单活动。
|
||||
*/
|
||||
public function close(Request $request, BaccaratLossCoverEvent $event): JsonResponse
|
||||
{
|
||||
if (! $this->positionPermissionService->hasPermission($request->user(), PositionPermissionRegistry::ROOM_BACCARAT_LOSS_COVER)) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => '当前职务无权结束买单活动。',
|
||||
], 403);
|
||||
}
|
||||
|
||||
$event = $this->lossCoverService->forceCloseEvent($event, $request->user());
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'message' => '活动状态已更新。',
|
||||
'status' => $event->status,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:管理员大卡片通知广播控制器
|
||||
*
|
||||
* 仅超级管理员(chat.level:super 中间件保护)可调用此接口,
|
||||
* 通过 BannerNotification 事件向指定用户或房间推送自定义大卡通知。
|
||||
*
|
||||
* 安全保证:
|
||||
* - 路由被 ['chat.auth', 'chat.has_position', 'chat.level:super'] 三层中间件保护
|
||||
* - 普通用户无权访问此接口,无法伪造对他人的广播
|
||||
* - options 中的用户输入字段在后端统一降级为纯文本 / 白名单样式值
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Events\BannerNotification;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* 类功能:安全地下发大卡片广播消息。
|
||||
*/
|
||||
class BannerBroadcastController extends Controller
|
||||
{
|
||||
/**
|
||||
* 向指定目标广播大卡片通知。
|
||||
*
|
||||
* 请求参数:
|
||||
* - target: 'user' | 'room'
|
||||
* - target_id: 用户名 或 房间 ID
|
||||
* - options: 与 window.chatBanner.show() 参数相同的对象
|
||||
* - icon, title, name, body, sub, gradient(array), titleColor, autoClose, buttons(array)
|
||||
*/
|
||||
public function send(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'target' => ['required', 'in:user,room'],
|
||||
'target_id' => ['required'],
|
||||
'options' => ['required', 'array'],
|
||||
'options.icon' => ['nullable', 'string', 'max:20'],
|
||||
'options.title' => ['nullable', 'string', 'max:50'],
|
||||
'options.name' => ['nullable', 'string', 'max:100'],
|
||||
'options.body' => ['nullable', 'string', 'max:500'],
|
||||
'options.sub' => ['nullable', 'string', 'max:200'],
|
||||
'options.gradient' => ['nullable', 'array', 'max:5'],
|
||||
'options.gradient.*' => ['nullable', 'string', 'max:30'],
|
||||
'options.titleColor' => ['nullable', 'string', 'max:30'],
|
||||
'options.autoClose' => ['nullable', 'integer', 'min:0', 'max:30000'],
|
||||
'options.buttons' => ['nullable', 'array', 'max:4'],
|
||||
'options.buttons.*.label' => ['nullable', 'string', 'max:30'],
|
||||
'options.buttons.*.color' => ['nullable', 'string', 'max:30'],
|
||||
'options.buttons.*.action' => ['nullable', 'string', 'max:20'],
|
||||
]);
|
||||
|
||||
// 所有可见文案一律降级为纯文本,避免允许标签残留属性后在前端 innerHTML 中执行。
|
||||
$opts = $validated['options'];
|
||||
foreach (['title', 'name', 'body', 'sub'] as $field) {
|
||||
if (isset($opts[$field])) {
|
||||
$opts[$field] = $this->sanitizeBannerText($opts[$field]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($opts['titleColor'])) {
|
||||
$opts['titleColor'] = $this->sanitizeCssValue($opts['titleColor'], '#fde68a');
|
||||
}
|
||||
|
||||
if (! empty($opts['gradient'])) {
|
||||
$opts['gradient'] = array_values(array_map(
|
||||
fn ($color) => $this->sanitizeCssValue($color, '#4f46e5'),
|
||||
$opts['gradient']
|
||||
));
|
||||
}
|
||||
|
||||
// 按钮 label 与颜色都只允许安全文本 / 颜色值。
|
||||
if (! empty($opts['buttons'])) {
|
||||
$opts['buttons'] = array_map(function ($btn) {
|
||||
$btn['label'] = $this->sanitizeBannerText($btn['label'] ?? '');
|
||||
$btn['color'] = $this->sanitizeCssValue($btn['color'] ?? '#10b981', '#10b981');
|
||||
// action 只允许预定义值,防止注入任意 JS
|
||||
$btn['action'] = in_array($btn['action'] ?? '', ['close', 'add_friend', 'remove_friend', 'link'])
|
||||
? $btn['action'] : 'close';
|
||||
|
||||
return $btn;
|
||||
}, $opts['buttons']);
|
||||
}
|
||||
|
||||
broadcast(new BannerNotification(
|
||||
target: $validated['target'],
|
||||
targetId: $validated['target_id'],
|
||||
options: $opts,
|
||||
));
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => '广播已发送']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 Banner 文案净化为安全纯文本。
|
||||
*/
|
||||
private function sanitizeBannerText(?string $text): string
|
||||
{
|
||||
return trim(strip_tags((string) $text));
|
||||
}
|
||||
|
||||
/**
|
||||
* 清洗颜色 / 渐变等 CSS 值,阻断样式属性注入。
|
||||
*/
|
||||
private function sanitizeCssValue(?string $value, string $default): string
|
||||
{
|
||||
$sanitized = strtolower(trim((string) $value));
|
||||
if ($sanitized === '' || preg_match('/(?:javascript|expression|url\s*\(|data:|var\s*\()/i', $sanitized)) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$allowedPatterns = [
|
||||
'/^#[0-9a-f]{3,8}$/i',
|
||||
'/^rgba?\(\s*(?:\d{1,3}\s*,\s*){2}\d{1,3}(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)$/i',
|
||||
'/^hsla?\(\s*\d{1,3}(?:deg)?\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)$/i',
|
||||
'/^(?:white|black|red|blue|green|gray|grey|yellow|orange|pink|purple|teal|cyan|indigo|amber|emerald|transparent|currentcolor)$/i',
|
||||
];
|
||||
|
||||
foreach ($allowedPatterns as $allowedPattern) {
|
||||
if (preg_match($allowedPattern, $sanitized)) {
|
||||
return $sanitized;
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台开发日志管理控制器(仅 id=1 超级管理员可访问)
|
||||
* 提供开发日志的 CRUD 功能,发布时可选择向 Room 1 大厅广播通知
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Events\ChangelogPublished;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\SaveMessageJob;
|
||||
use App\Models\DevChangelog;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ChangelogController extends Controller
|
||||
{
|
||||
/**
|
||||
* 后台日志列表(含草稿)
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$logs = DevChangelog::orderByDesc('created_at')->paginate(20);
|
||||
|
||||
return view('admin.changelog.index', compact('logs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增日志表单页(预填今日日期)
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
// 预填今日日期为版本号
|
||||
$todayVersion = now()->format('Y-m-d');
|
||||
|
||||
return view('admin.changelog.form', [
|
||||
'log' => null,
|
||||
'todayVersion' => $todayVersion,
|
||||
'typeOptions' => DevChangelog::TYPE_CONFIG,
|
||||
'isCreate' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新日志
|
||||
* 若勾选"立即发布",则记录 published_at 并可选向大厅广播通知
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'version' => 'required|string|max:30',
|
||||
'title' => 'required|string|max:200',
|
||||
'type' => 'required|in:feature,fix,improve,other',
|
||||
'content' => 'required|string',
|
||||
'is_published' => 'nullable|boolean',
|
||||
'notify_chat' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
$isPublished = (bool) ($data['is_published'] ?? false);
|
||||
$notifyChat = (bool) ($data['notify_chat'] ?? false);
|
||||
|
||||
/** @var DevChangelog $log */
|
||||
$log = DevChangelog::create([
|
||||
'version' => $data['version'],
|
||||
'title' => $data['title'],
|
||||
'type' => $data['type'],
|
||||
'content' => $data['content'],
|
||||
'is_published' => $isPublished,
|
||||
// 只有同时勾选"通知"才记录 notify_chat,否则置 false
|
||||
'notify_chat' => $isPublished && $notifyChat,
|
||||
// 首次发布时记录发布时间
|
||||
'published_at' => $isPublished ? Carbon::now() : null,
|
||||
]);
|
||||
|
||||
// 如果发布且勾选了"通知大厅用户",则触发 WebSocket 广播 + 持久化到消息库
|
||||
if ($isPublished && $notifyChat) {
|
||||
event(new ChangelogPublished($log));
|
||||
$this->saveChangelogNotification($log);
|
||||
}
|
||||
|
||||
return redirect()->route('admin.changelogs.index')
|
||||
->with('success', '开发日志创建成功!'.($isPublished ? '(已发布)' : '(草稿已保存)'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑日志表单页
|
||||
*
|
||||
* @param DevChangelog $changelog 路由模型自动注入
|
||||
*/
|
||||
public function edit(DevChangelog $changelog): View
|
||||
{
|
||||
return view('admin.changelog.form', [
|
||||
'log' => $changelog,
|
||||
'todayVersion' => $changelog->version,
|
||||
'typeOptions' => DevChangelog::TYPE_CONFIG,
|
||||
'isCreate' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新日志内容(编辑操作不更新 published_at,不触发通知)
|
||||
*
|
||||
* @param DevChangelog $changelog 路由模型自动注入
|
||||
*/
|
||||
public function update(Request $request, DevChangelog $changelog): RedirectResponse
|
||||
{
|
||||
$log = $changelog;
|
||||
|
||||
$data = $request->validate([
|
||||
'version' => 'required|string|max:30',
|
||||
'title' => 'required|string|max:200',
|
||||
'type' => 'required|in:feature,fix,improve,other',
|
||||
'content' => 'required|string',
|
||||
'is_published' => 'nullable|boolean',
|
||||
'notify_chat' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
$isPublished = (bool) ($data['is_published'] ?? false);
|
||||
|
||||
// 如果从草稿切换为发布,记录首次发布时间
|
||||
$publishedAt = $log->published_at;
|
||||
if ($isPublished && ! $log->is_published) {
|
||||
$publishedAt = Carbon::now();
|
||||
} elseif (! $isPublished) {
|
||||
// 从发布退回草稿,清除发布时间
|
||||
$publishedAt = null;
|
||||
}
|
||||
|
||||
$log->update([
|
||||
'version' => $data['version'],
|
||||
'title' => $data['title'],
|
||||
'type' => $data['type'],
|
||||
'content' => $data['content'],
|
||||
'is_published' => $isPublished,
|
||||
'published_at' => $publishedAt,
|
||||
]);
|
||||
|
||||
// 若勾选了「通知大厅用户」且当前已发布,则广播通知 + 持久化到消息库
|
||||
$notifyChat = (bool) ($data['notify_chat'] ?? false);
|
||||
if ($notifyChat && $isPublished) {
|
||||
event(new ChangelogPublished($log));
|
||||
$this->saveChangelogNotification($log);
|
||||
}
|
||||
|
||||
return redirect()->route('admin.changelogs.index')
|
||||
->with('success', '开发日志已更新!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除日志
|
||||
*
|
||||
* @param DevChangelog $changelog 路由模型自动注入
|
||||
*/
|
||||
public function destroy(DevChangelog $changelog): RedirectResponse
|
||||
{
|
||||
$changelog->delete();
|
||||
|
||||
return redirect()->route('admin.changelogs.index')
|
||||
->with('success', '日志已删除。');
|
||||
}
|
||||
|
||||
/**
|
||||
* 将版本更新通知持久化为 Room 1 系统消息
|
||||
* 确保用户重进聊天室时仍能在历史消息中看到该通知
|
||||
*
|
||||
* @param DevChangelog $log 已发布的日志
|
||||
*/
|
||||
private function saveChangelogNotification(DevChangelog $log): void
|
||||
{
|
||||
// 广播文案允许保留安全链接,但标题与版本号必须先做 HTML 转义,避免系统消息被拼成恶意标签。
|
||||
$safeTypeLabel = e(DevChangelog::TYPE_CONFIG[$log->type]['label'] ?? '更新');
|
||||
$safeVersion = e((string) $log->version);
|
||||
$safeTitle = e((string) $log->title);
|
||||
$detailUrl = e($this->buildChangelogDetailUrl($log));
|
||||
|
||||
SaveMessageJob::dispatch([
|
||||
'room_id' => 1,
|
||||
'from_user' => '系统公告',
|
||||
'to_user' => '大家',
|
||||
'content' => "📢 【版本更新 {$safeTypeLabel}】v{$safeVersion}《{$safeTitle}》— <a href=\"{$detailUrl}\" target=\"_blank\" rel=\"noopener\" class=\"underline\">点击查看详情</a>",
|
||||
'is_secret' => false,
|
||||
'font_color' => '#7c3aed',
|
||||
'action' => '',
|
||||
'sent_at' => now()->toIso8601String(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成开发日志详情链接,并对版本片段做 URL 编码,避免广播 href 被注入额外属性。
|
||||
*/
|
||||
private function buildChangelogDetailUrl(DevChangelog $log): string
|
||||
{
|
||||
return route('changelog.index').'#v'.rawurlencode((string) $log->version);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:用户金币/积分流水日志查询
|
||||
* 对应超级管理员级别的查询页面。可以按用户、增减、货币类型等筛选所有的账目流动。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Enums\CurrencySource;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\UserCurrencyLog;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 类功能:提供后台全局金币/积分流水查询与多条件筛选。
|
||||
*/
|
||||
class CurrencyLogController extends Controller
|
||||
{
|
||||
/**
|
||||
* 显示流水日志列表
|
||||
* 支持多条件检索,仅 superlevel 以及上可以访问此页面
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$query = UserCurrencyLog::query()->with('user');
|
||||
$allSources = CurrencySource::cases();
|
||||
$allowedSources = collect($allSources)->map(fn (CurrencySource $source) => $source->value)->all();
|
||||
$selectedSources = collect($request->array('sources'))
|
||||
->filter(fn (string $source) => in_array($source, $allowedSources, true))
|
||||
->values()
|
||||
->all();
|
||||
|
||||
// 查询条件过滤
|
||||
if ($request->filled('username')) {
|
||||
$query->where('username', 'like', '%'.$request->input('username').'%');
|
||||
}
|
||||
|
||||
if ($request->filled('currency')) {
|
||||
$query->where('currency', $request->input('currency'));
|
||||
}
|
||||
|
||||
if ($selectedSources !== []) {
|
||||
$query->whereIn('source', $selectedSources);
|
||||
}
|
||||
|
||||
if ($request->filled('remark')) {
|
||||
$query->where('remark', 'like', '%'.$request->input('remark').'%');
|
||||
}
|
||||
|
||||
if ($request->filled('direction')) {
|
||||
if ($request->input('direction') === 'in') {
|
||||
$query->where('amount', '>', 0);
|
||||
} elseif ($request->input('direction') === 'out') {
|
||||
$query->where('amount', '<', 0);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->filled('date_start')) {
|
||||
$query->whereDate('created_at', '>=', $request->input('date_start'));
|
||||
}
|
||||
|
||||
if ($request->filled('date_end')) {
|
||||
$query->whereDate('created_at', '<=', $request->input('date_end'));
|
||||
}
|
||||
|
||||
// 默认按时间倒序
|
||||
$logs = $query->latest('id')->paginate(50)->withQueryString();
|
||||
|
||||
return view('admin.currency-logs.index', compact('logs', 'allSources', 'selectedSources'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台积分活动统计控制器
|
||||
* 展示今日(或指定日期)各来源活动产生的经验/金币/魅力统计,以及今日净流通量。
|
||||
* 仅限 superlevel 以上管理员访问。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Enums\CurrencySource;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\UserCurrencyService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 类功能:展示后台积分流水统计与指定日期净流通数据。
|
||||
*/
|
||||
class CurrencyStatsController extends Controller
|
||||
{
|
||||
/**
|
||||
* 注入积分统计服务
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly UserCurrencyService $currencyService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 显示指定日期的积分活动统计(默认今日)。
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
// 日期选择(默认今日)
|
||||
$date = $request->input('date', today()->toDateString());
|
||||
|
||||
// 各来源活动产出统计(按 source + currency 分组汇总)
|
||||
$stats = $this->currencyService->activityStats($date);
|
||||
|
||||
// 按货币类型分组,方便视图展示
|
||||
$statsByType = $stats->groupBy('currency')->map(
|
||||
fn ($rows) => $rows->keyBy('source')
|
||||
);
|
||||
|
||||
// 今日净流通量(正向增加 - 负向消耗),可判断通货膨胀
|
||||
$netFlow = $this->currencyService->netFlowStats($date);
|
||||
|
||||
// 所有已知来源(供视图展示缺失来源的空行)
|
||||
$allSources = CurrencySource::cases();
|
||||
|
||||
return view('admin.currency-stats.index', compact(
|
||||
'date', 'stats', 'statsByType', 'netFlow', 'allSources',
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -13,18 +13,37 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use App\Services\ChatStateService;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 类功能:负责后台首页仪表盘的汇总统计展示。
|
||||
*/
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* 注入聊天室状态服务,供仪表盘读取实时在线数据。
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ChatStateService $chatState,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 显示后台首页与全局统计
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$onlineUsernames = collect();
|
||||
|
||||
foreach ($this->chatState->getAllActiveRoomIds() as $roomId) {
|
||||
// 使用在线名单服务的懒清理结果,保证统计口径与聊天室在线列表一致。
|
||||
$onlineUsernames = $onlineUsernames->merge(array_keys($this->chatState->getRoomUsers($roomId)));
|
||||
}
|
||||
|
||||
$stats = [
|
||||
'total_users' => User::count(),
|
||||
'total_rooms' => Room::count(),
|
||||
'online_users' => $onlineUsernames->unique()->count(),
|
||||
// 更多统计指标以后再发掘
|
||||
];
|
||||
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台部门管理控制器
|
||||
* 提供部门的 CRUD 功能(增删改查)
|
||||
* 部门是职务的上级分类,包含位阶、颜色、描述等配置
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Department;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DepartmentController extends Controller
|
||||
{
|
||||
/**
|
||||
* 部门列表页
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$departments = Department::withCount(['positions'])
|
||||
->orderBy('sort_order')
|
||||
->orderByDesc('rank')
|
||||
->get();
|
||||
|
||||
return view('admin.departments.index', compact('departments'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建部门
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:50|unique:departments,name',
|
||||
'rank' => 'required|integer|min:0|max:99',
|
||||
'color' => 'required|string|max:10',
|
||||
'sort_order' => 'required|integer|min:0',
|
||||
'description' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
Department::create($data);
|
||||
|
||||
return redirect()->route('admin.departments.index')->with('success', "部门【{$data['name']}】创建成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新部门
|
||||
*/
|
||||
public function update(Request $request, Department $department): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:50|unique:departments,name,'.$department->id,
|
||||
'rank' => 'required|integer|min:0|max:99',
|
||||
'color' => 'required|string|max:10',
|
||||
'sort_order' => 'required|integer|min:0',
|
||||
'description' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
||||
$department->update($data);
|
||||
|
||||
return redirect()->route('admin.departments.index')->with('success', "部门【{$data['name']}】更新成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除部门(级联删除职务)
|
||||
*/
|
||||
public function destroy(Department $department): RedirectResponse
|
||||
{
|
||||
// 检查是否有在职人员
|
||||
$activeMemberCount = $department->positions()
|
||||
->whereHas('activeUserPositions')
|
||||
->count();
|
||||
|
||||
if ($activeMemberCount > 0) {
|
||||
return redirect()->route('admin.departments.index')
|
||||
->with('error', "部门【{$department->name}】下尚有在职人员,请先撤销所有职务后再删除。");
|
||||
}
|
||||
|
||||
$department->delete();
|
||||
|
||||
return redirect()->route('admin.departments.index')->with('success', "部门【{$department->name}】已删除!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台用户反馈管理控制器(仅 id=1 超级管理员可访问)
|
||||
* 提供反馈列表查看、处理状态修改、官方回复功能
|
||||
* 侧边栏显示待处理数量徽标
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\FeedbackItem;
|
||||
use App\Models\FeedbackReply;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class FeedbackManagerController extends Controller
|
||||
{
|
||||
/**
|
||||
* 后台反馈列表页(支持类型+状态筛选)
|
||||
*
|
||||
* @param Request $request 含 type/status 筛选参数
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$type = $request->input('type');
|
||||
$status = $request->input('status');
|
||||
|
||||
$query = FeedbackItem::with(['replies'])
|
||||
->orderByDesc('created_at');
|
||||
|
||||
// 按类型筛选
|
||||
if ($type && in_array($type, ['bug', 'suggestion'])) {
|
||||
$query->ofType($type);
|
||||
}
|
||||
|
||||
// 按状态筛选
|
||||
if ($status && array_key_exists($status, FeedbackItem::STATUS_CONFIG)) {
|
||||
$query->ofStatus($status);
|
||||
}
|
||||
|
||||
$feedbacks = $query->paginate(20)->withQueryString();
|
||||
|
||||
// 待处理数量(用于侧边栏徽标)
|
||||
$pendingCount = FeedbackItem::pending()->count();
|
||||
|
||||
return view('admin.feedback.index', [
|
||||
'feedbacks' => $feedbacks,
|
||||
'pendingCount' => $pendingCount,
|
||||
'statusConfig' => FeedbackItem::STATUS_CONFIG,
|
||||
'typeConfig' => FeedbackItem::TYPE_CONFIG,
|
||||
'currentType' => $type,
|
||||
'currentStatus' => $status,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新反馈处理状态和官方回复(Ajax + 表单双模式)
|
||||
* Ajax 返回 JSON,普通表单提交返回重定向
|
||||
*
|
||||
* @param Request $request 含 status/admin_remark 字段
|
||||
* @param int $id 反馈 ID
|
||||
*/
|
||||
public function update(Request $request, int $id): JsonResponse|RedirectResponse
|
||||
{
|
||||
$feedback = FeedbackItem::findOrFail($id);
|
||||
|
||||
$data = $request->validate([
|
||||
'status' => 'required|in:'.implode(',', array_keys(FeedbackItem::STATUS_CONFIG)),
|
||||
'admin_remark' => 'nullable|string|max:2000',
|
||||
]);
|
||||
|
||||
$feedback->update([
|
||||
'status' => $data['status'],
|
||||
'admin_remark' => $data['admin_remark'] ?? $feedback->admin_remark,
|
||||
]);
|
||||
|
||||
// 如果有新的官方回复内容,同时写入 feedback_replies(带 is_admin 标记)
|
||||
if (! empty($data['admin_remark']) && $data['admin_remark'] !== $feedback->getOriginal('admin_remark')) {
|
||||
DB::transaction(function () use ($feedback, $data): void {
|
||||
FeedbackReply::create([
|
||||
'feedback_id' => $feedback->id,
|
||||
'user_id' => 1,
|
||||
'username' => '🛡️ 开发者',
|
||||
'content' => $data['admin_remark'],
|
||||
'is_admin' => true,
|
||||
]);
|
||||
$feedback->increment('replies_count');
|
||||
});
|
||||
}
|
||||
|
||||
// Ajax 请求返回 JSON
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'new_status' => $data['status'],
|
||||
'status_label' => FeedbackItem::STATUS_CONFIG[$data['status']]['icon'].' '.FeedbackItem::STATUS_CONFIG[$data['status']]['label'],
|
||||
'status_color' => FeedbackItem::STATUS_CONFIG[$data['status']]['color'],
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()->route('admin.feedback.index')
|
||||
->with('success', '反馈状态已更新!');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:钓鱼事件后台管理控制器
|
||||
* 提供钓鱼事件的列表展示、创建、编辑、删除、启用/禁用功能
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\FishingEvent;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class FishingEventController extends Controller
|
||||
{
|
||||
/**
|
||||
* 显示所有钓鱼事件列表
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$events = FishingEvent::orderBy('sort')->orderBy('id')->get();
|
||||
$totalWeight = $events->where('is_active', true)->sum('weight');
|
||||
|
||||
return view('admin.fishing.index', compact('events', 'totalWeight'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新钓鱼事件
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'emoji' => 'required|string|max:10',
|
||||
'name' => 'required|string|max:100',
|
||||
'message' => 'required|string|max:255',
|
||||
'exp' => 'required|integer',
|
||||
'jjb' => 'required|integer',
|
||||
'weight' => 'required|integer|min:1|max:9999',
|
||||
'sort' => 'required|integer|min:0',
|
||||
'is_active' => 'boolean',
|
||||
]);
|
||||
|
||||
$data['is_active'] = $request->boolean('is_active', true);
|
||||
FishingEvent::create($data);
|
||||
|
||||
return redirect()->route('admin.fishing.index')->with('success', '钓鱼事件已添加!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新钓鱼事件
|
||||
*
|
||||
* @param FishingEvent $fishing 路由模型绑定
|
||||
*/
|
||||
public function update(Request $request, FishingEvent $fishing): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'emoji' => 'required|string|max:10',
|
||||
'name' => 'required|string|max:100',
|
||||
'message' => 'required|string|max:255',
|
||||
'exp' => 'required|integer',
|
||||
'jjb' => 'required|integer',
|
||||
'weight' => 'required|integer|min:1|max:9999',
|
||||
'sort' => 'required|integer|min:0',
|
||||
'is_active' => 'boolean',
|
||||
]);
|
||||
|
||||
$data['is_active'] = $request->boolean('is_active');
|
||||
$fishing->update($data);
|
||||
|
||||
return redirect()->route('admin.fishing.index')->with('success', "事件「{$fishing->name}」已更新!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换事件启用/禁用状态(AJAX)
|
||||
*
|
||||
* @param FishingEvent $fishing 路由模型绑定
|
||||
*/
|
||||
public function toggle(FishingEvent $fishing): JsonResponse
|
||||
{
|
||||
$fishing->update(['is_active' => ! $fishing->is_active]);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'is_active' => $fishing->is_active,
|
||||
'message' => $fishing->is_active ? "「{$fishing->name}」已启用" : "「{$fishing->name}」已禁用",
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除钓鱼事件
|
||||
*
|
||||
* @param FishingEvent $fishing 路由模型绑定
|
||||
*/
|
||||
public function destroy(FishingEvent $fishing): RedirectResponse
|
||||
{
|
||||
$name = $fishing->name;
|
||||
$fishing->delete();
|
||||
|
||||
return redirect()->route('admin.fishing.index')->with('success', "事件「{$name}」已删除!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:禁用用户名管理控制器(站长专用)
|
||||
*
|
||||
* 管理 username_blacklist 表中 type=permanent 的永久禁用词列表。
|
||||
* 包含:国家领导人名称、攻击性词汇、违禁词等不允许注册或改名的词语。
|
||||
*
|
||||
* 用户在注册(AuthController)和改名(ShopService::useRenameCard)时均会经过该表检测。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\UsernameBlacklist;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
class ForbiddenUsernameController extends Controller
|
||||
{
|
||||
/**
|
||||
* 分页列出所有永久禁用词。
|
||||
* 支持关键词模糊搜索(GET ?q=xxx)。
|
||||
*/
|
||||
public function index(Request $request): \Illuminate\View\View
|
||||
{
|
||||
$q = $request->query('q', '');
|
||||
|
||||
$items = UsernameBlacklist::permanent()
|
||||
->when($q, fn ($query) => $query->where('username', 'like', "%{$q}%"))
|
||||
->orderByDesc('created_at')
|
||||
->paginate(20)
|
||||
->withQueryString();
|
||||
|
||||
return view('admin.forbidden-usernames.index', [
|
||||
'items' => $items,
|
||||
'q' => $q,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增一条永久禁用词。
|
||||
*
|
||||
* @param Request $request 请求体:username(必填),reason(选填)
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'username' => ['required', 'string', 'max:50'],
|
||||
'reason' => ['nullable', 'string', 'max:100'],
|
||||
], [
|
||||
'username.required' => '禁用词不能为空。',
|
||||
'username.max' => '禁用词最长50字符。',
|
||||
]);
|
||||
|
||||
$username = trim($validated['username']);
|
||||
|
||||
// 已存在同名的永久记录则不重复插入
|
||||
$exists = UsernameBlacklist::permanent()
|
||||
->where('username', $username)
|
||||
->exists();
|
||||
|
||||
if ($exists) {
|
||||
return response()->json(['status' => 'error', 'message' => '该词语已在永久禁用列表中。'], 422);
|
||||
}
|
||||
|
||||
UsernameBlacklist::create([
|
||||
'username' => $username,
|
||||
'type' => 'permanent',
|
||||
'reserved_until' => null,
|
||||
'reason' => $validated['reason'] ?? null,
|
||||
'created_at' => Carbon::now(),
|
||||
]);
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => "「{$username}」已加入永久禁用列表。"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加永久禁用词。
|
||||
*
|
||||
* 接受多行文本或逗号分隔的词语列表,自动去重并过滤已存在者。
|
||||
* 返回成功添加数量和跳过数量。
|
||||
*
|
||||
* @param Request $request 请求体:words(换行/逗号分隔),reason(选填,共用)
|
||||
*/
|
||||
public function batchStore(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'words' => ['required', 'string'],
|
||||
'reason' => ['nullable', 'string', 'max:100'],
|
||||
], [
|
||||
'words.required' => '请输入至少一个词语。',
|
||||
]);
|
||||
|
||||
// 净化输入:去除非法 UTF-8 字节(零宽字符、BOM、控制字符等),防止 json_encode 失败
|
||||
$rawInput = $this->sanitizeUtf8($validated['words']);
|
||||
$reason = $this->sanitizeUtf8(trim($validated['reason'] ?? ''));
|
||||
|
||||
// 支持换行、逗号、中文逗号、空格分隔
|
||||
$rawWords = preg_split('/[\r\n,,\s]+/u', $rawInput);
|
||||
|
||||
// 过滤空串、超长词、去重
|
||||
$words = collect($rawWords)
|
||||
->map(fn ($w) => trim($w))
|
||||
->filter(fn ($w) => $w !== '' && mb_strlen($w) <= 50)
|
||||
->unique()
|
||||
->values();
|
||||
|
||||
if ($words->isEmpty()) {
|
||||
return response()->json(['status' => 'error', 'message' => '没有有效的词语,请检查输入。'], 422);
|
||||
}
|
||||
|
||||
// 批量查询已存在的词(一次查询)
|
||||
$existing = UsernameBlacklist::permanent()
|
||||
->whereIn('username', $words->all())
|
||||
->pluck('username')
|
||||
->flip();
|
||||
|
||||
$now = Carbon::now();
|
||||
$added = 0;
|
||||
$rows = [];
|
||||
|
||||
foreach ($words as $word) {
|
||||
if ($existing->has($word)) {
|
||||
continue;
|
||||
}
|
||||
$rows[] = [
|
||||
'username' => $word,
|
||||
'type' => 'permanent',
|
||||
'reserved_until' => null,
|
||||
'reason' => $reason ?: null,
|
||||
'created_at' => $now,
|
||||
];
|
||||
$added++;
|
||||
}
|
||||
|
||||
if (! empty($rows)) {
|
||||
UsernameBlacklist::insert($rows);
|
||||
}
|
||||
|
||||
$skipped = $words->count() - $added;
|
||||
$msg = "成功添加 {$added} 个词语".($skipped > 0 ? ",跳过 {$skipped} 个(已存在)" : '').'。';
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => $msg, 'added' => $added], 200, [], JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 净化字符串,移除非法 UTF-8 字节及常见控制/零宽字符。
|
||||
*
|
||||
* @param string $str 待净化字符串
|
||||
* @return string 合法的 UTF-8 字符串
|
||||
*/
|
||||
private function sanitizeUtf8(string $str): string
|
||||
{
|
||||
// 去除 BOM
|
||||
$str = str_replace("\xEF\xBB\xBF", '', $str);
|
||||
// 去除零宽字符(零宽空格、零宽不连字等)
|
||||
$str = preg_replace('/[\x{200B}-\x{200D}\x{FEFF}\x{00AD}]/u', '', $str);
|
||||
// 转换为合法 UTF-8,忽略非法字节
|
||||
$str = mb_convert_encoding($str, 'UTF-8', 'UTF-8');
|
||||
// 保底:去除控制字符(保留换行 \r\n)
|
||||
$str = preg_replace('/[^\P{C}\r\n]+/u', '', $str);
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新指定禁用词的原因备注。
|
||||
*
|
||||
* @param int $id 记录 ID
|
||||
* @param Request $request 请求体:reason
|
||||
*/
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
{
|
||||
$item = UsernameBlacklist::permanent()->findOrFail($id);
|
||||
|
||||
$validated = $request->validate([
|
||||
'reason' => ['nullable', 'string', 'max:100'],
|
||||
]);
|
||||
|
||||
$item->update(['reason' => $validated['reason']]);
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => '备注已更新。']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定永久禁用词。
|
||||
*
|
||||
* @param int $id 记录 ID
|
||||
*/
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$item = UsernameBlacklist::permanent()->findOrFail($id);
|
||||
$name = $item->username;
|
||||
$item->delete();
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => "「{$name}」已从永久禁用列表移除。"]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:游戏配置后台管理控制器
|
||||
*
|
||||
* 管理员可在此页面统一管理所有娱乐游戏的开关状态和核心参数。
|
||||
* 每个游戏的参数说明通过前端渲染,后台只做通用 JSON 存储。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\GameConfig;
|
||||
use App\Models\LotteryIssue;
|
||||
use App\Services\LotteryService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class GameConfigController extends Controller
|
||||
{
|
||||
/**
|
||||
* 游戏管理总览页面。
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$games = GameConfig::orderBy('id')->get();
|
||||
|
||||
return view('admin.game-configs.index', compact('games'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换游戏开启/关闭状态。
|
||||
*/
|
||||
public function toggle(GameConfig $gameConfig): JsonResponse
|
||||
{
|
||||
$gameConfig->update(['enabled' => ! $gameConfig->enabled]);
|
||||
$gameConfig->clearCache();
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'enabled' => $gameConfig->enabled,
|
||||
'message' => $gameConfig->enabled
|
||||
? "「{$gameConfig->name}」已开启"
|
||||
: "「{$gameConfig->name}」已关闭",
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存游戏核心参数。
|
||||
*
|
||||
* 接收前端提交的 params JSON 对象并合并至现有配置。
|
||||
*/
|
||||
public function updateParams(Request $request, GameConfig $gameConfig): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'params' => 'required|array',
|
||||
]);
|
||||
|
||||
// 合并参数,保留已有键,只更新传入的键
|
||||
$current = $gameConfig->params ?? [];
|
||||
$updated = array_merge($current, $request->input('params'));
|
||||
|
||||
if ($gameConfig->game_key === 'mystery_box') {
|
||||
$legacyMap = [
|
||||
'min_reward' => 'normal_reward_min',
|
||||
'max_reward' => 'normal_reward_max',
|
||||
'rare_min_reward' => 'rare_reward_min',
|
||||
'rare_max_reward' => 'rare_reward_max',
|
||||
];
|
||||
|
||||
foreach ($legacyMap as $legacyKey => $newKey) {
|
||||
if (! array_key_exists($newKey, $updated) && array_key_exists($legacyKey, $updated)) {
|
||||
$updated[$newKey] = $updated[$legacyKey];
|
||||
}
|
||||
|
||||
unset($updated[$legacyKey]);
|
||||
}
|
||||
}
|
||||
|
||||
$gameConfig->update(['params' => $updated]);
|
||||
$gameConfig->clearCache();
|
||||
|
||||
return back()->with('success', "「{$gameConfig->name}」参数已保存!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员手动投放神秘箱子。
|
||||
*
|
||||
* 立即分发 DropMysteryBoxJob 到队列,由 Horizon 执行箱子投放和公屏广播。
|
||||
*/
|
||||
public function dropMysteryBox(Request $request): JsonResponse
|
||||
{
|
||||
if (! \App\Models\GameConfig::isEnabled('mystery_box')) {
|
||||
return response()->json(['ok' => false, 'message' => '神秘箱子功能未开放,请先开启。']);
|
||||
}
|
||||
|
||||
$boxType = $request->input('box_type', 'normal');
|
||||
|
||||
if (! in_array($boxType, ['normal', 'rare', 'trap'], true)) {
|
||||
return response()->json(['ok' => false, 'message' => '无效的箱子类型。']);
|
||||
}
|
||||
|
||||
// 检查是否有正在开放的箱子(避免同时多个)
|
||||
if (\App\Models\MysteryBox::currentOpenBox()) {
|
||||
return response()->json(['ok' => false, 'message' => '当前已有一个神秘箱子正在等待领取,请等它结束后再投放。']);
|
||||
}
|
||||
|
||||
\App\Jobs\DropMysteryBoxJob::dispatch($boxType, 1, null, (int) auth()->id());
|
||||
|
||||
$typeNames = ['normal' => '普通箱', 'rare' => '稀有箱', 'trap' => '黑化箱'];
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'message' => "✅ 已投放「{$typeNames[$boxType]}」到 #1 房间,暗号将实时发送到公屏!",
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动开启新一期双色球彩票。
|
||||
*
|
||||
* 仅在当前无进行中期次时生效,防止重复开期。
|
||||
*/
|
||||
public function openLotteryIssue(): JsonResponse
|
||||
{
|
||||
if (! GameConfig::isEnabled('lottery')) {
|
||||
return response()->json(['ok' => false, 'message' => '双色球彩票未开启,请先开启游戏。']);
|
||||
}
|
||||
|
||||
if (LotteryIssue::currentIssue()) {
|
||||
return response()->json(['ok' => false, 'message' => '当前已有进行中的期次,无需重复开期。']);
|
||||
}
|
||||
|
||||
\App\Jobs\OpenLotteryIssueJob::dispatch();
|
||||
|
||||
return response()->json(['ok' => true, 'message' => '✅ 已排队开期任务,新期次将就绪建立!']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员强制立即开奖(测试专用)。
|
||||
*
|
||||
* 将当前 open 或 closed 期次直接投入开奖队列。
|
||||
*/
|
||||
public function forceLotteryDraw(LotteryService $lottery): JsonResponse
|
||||
{
|
||||
$issue = LotteryIssue::query()
|
||||
->whereIn('status', ['open', 'closed'])
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if (! $issue) {
|
||||
return response()->json(['ok' => false, 'message' => '当前无可开奖的期次。']);
|
||||
}
|
||||
|
||||
// 强制将状态改为 closed
|
||||
$issue->update(['status' => 'closed']);
|
||||
\App\Jobs\DrawLotteryJob::dispatch($issue->fresh());
|
||||
|
||||
return response()->json(['ok' => true, 'message' => "✅ 开奖任务已入队,第 {$issue->issue_no} 期将就绪开奖!"]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:游戏历史记录后台查询控制器
|
||||
*
|
||||
* 提供百家乐、老虎机、赛马竞猜、神秘箱子、神秘占卜各游戏
|
||||
* 的历史记录查询页面及统计摘要接口,供管理员查阅。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\BaccaratBet;
|
||||
use App\Models\BaccaratRound;
|
||||
use App\Models\FortuneLog;
|
||||
use App\Models\GomokuGame;
|
||||
use App\Models\HorseBet;
|
||||
use App\Models\HorseRace;
|
||||
use App\Models\LotteryIssue;
|
||||
use App\Models\LotteryTicket;
|
||||
use App\Models\MysteryBox;
|
||||
use App\Models\SlotMachineLog;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class GameHistoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* 各游戏实时统计摘要(JSON 接口,供 game-configs 首页加载)。
|
||||
*/
|
||||
public function stats(): JsonResponse
|
||||
{
|
||||
// 百家乐:最近30天
|
||||
$baccarat = [
|
||||
'total_rounds' => BaccaratRound::query()->where('status', 'settled')->count(),
|
||||
'total_bets' => BaccaratBet::query()->count(),
|
||||
'total_payout' => BaccaratRound::query()->where('status', 'settled')->sum('total_payout'),
|
||||
'today_rounds' => BaccaratRound::query()->where('status', 'settled')->whereDate('settled_at', today())->count(),
|
||||
];
|
||||
|
||||
// 老虎机
|
||||
$slot = [
|
||||
'total_spins' => SlotMachineLog::query()->count(),
|
||||
'total_cost' => SlotMachineLog::query()->sum('cost'),
|
||||
'total_payout' => SlotMachineLog::query()->sum('payout'),
|
||||
'jackpot_count' => SlotMachineLog::query()->where('result_type', 'jackpot')->count(),
|
||||
'today_spins' => SlotMachineLog::query()->whereDate('created_at', today())->count(),
|
||||
];
|
||||
|
||||
// 赛马
|
||||
$horse = [
|
||||
'total_races' => HorseRace::query()->where('status', 'settled')->count(),
|
||||
'total_bets' => HorseBet::query()->count(),
|
||||
'total_pool' => HorseRace::query()->where('status', 'settled')->sum('total_pool'),
|
||||
'today_races' => HorseRace::query()->where('status', 'settled')->whereDate('settled_at', today())->count(),
|
||||
];
|
||||
|
||||
// 神秘箱子
|
||||
$mysteryBox = [
|
||||
'total_dropped' => MysteryBox::query()->count(),
|
||||
'total_claimed' => MysteryBox::query()->where('status', 'claimed')->count(),
|
||||
'total_expired' => MysteryBox::query()->where('status', 'expired')->count(),
|
||||
'today_dropped' => MysteryBox::query()->whereDate('created_at', today())->count(),
|
||||
];
|
||||
|
||||
// 占卜
|
||||
$fortune = [
|
||||
'total_times' => FortuneLog::query()->count(),
|
||||
'jackpot_count' => FortuneLog::query()->where('grade', 'jackpot')->count(),
|
||||
'curse_count' => FortuneLog::query()->where('grade', 'curse')->count(),
|
||||
'today_times' => FortuneLog::query()->whereDate('created_at', today())->count(),
|
||||
];
|
||||
|
||||
// 彩票
|
||||
$lottery = [
|
||||
'total_issues' => LotteryIssue::query()->count(),
|
||||
'total_bets' => LotteryTicket::query()->count(),
|
||||
'total_pool' => LotteryIssue::query()->where('status', 'settled')->sum('pool_amount'),
|
||||
'today_issues' => LotteryIssue::query()->whereDate('created_at', today())->count(),
|
||||
];
|
||||
|
||||
// 五子棋
|
||||
$gomoku = [
|
||||
'total_games' => GomokuGame::query()->count(),
|
||||
'pvp_count' => GomokuGame::query()->where('mode', 'pvp')->count(),
|
||||
'pve_count' => GomokuGame::query()->where('mode', 'pve')->count(),
|
||||
'today_games' => GomokuGame::query()->whereDate('created_at', today())->count(),
|
||||
];
|
||||
|
||||
return response()->json([
|
||||
'baccarat' => $baccarat,
|
||||
'slot' => $slot,
|
||||
'horse' => $horse,
|
||||
'mystery_box' => $mysteryBox,
|
||||
'fortune' => $fortune,
|
||||
'lottery' => $lottery,
|
||||
'gomoku' => $gomoku,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 百家乐历史记录页面(局次列表,支持分页)。
|
||||
*/
|
||||
public function baccarat(Request $request): View
|
||||
{
|
||||
// 各局统计摘要
|
||||
$summary = [
|
||||
'total_rounds' => BaccaratRound::query()->where('status', 'settled')->count(),
|
||||
'total_bets' => BaccaratBet::query()->count(),
|
||||
'total_payout' => (int) BaccaratRound::query()->where('status', 'settled')->sum('total_payout'),
|
||||
// 会员实际输掉的金币:所有已结算落败注单的押注金额合计
|
||||
'total_lost' => (int) BaccaratBet::query()->where('status', 'lost')->sum('amount'),
|
||||
'result_dist' => BaccaratRound::query()
|
||||
->where('status', 'settled')
|
||||
->select('result', \Illuminate\Support\Facades\DB::raw('count(*) as cnt'))
|
||||
->groupBy('result')
|
||||
->pluck('cnt', 'result'),
|
||||
];
|
||||
|
||||
$rounds = BaccaratRound::query()
|
||||
->latest()
|
||||
->paginate(20);
|
||||
|
||||
return view('admin.game-history.baccarat', compact('rounds', 'summary'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 百家乐单局下注明细。
|
||||
*/
|
||||
public function baccaratRound(BaccaratRound $round): View
|
||||
{
|
||||
$bets = $round->bets()->with('user')->latest()->paginate(30);
|
||||
|
||||
return view('admin.game-history.baccarat-round', compact('round', 'bets'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 老虎机历史记录页面(支持按结果类型筛选/分页)。
|
||||
*/
|
||||
public function slot(Request $request): View
|
||||
{
|
||||
// 统计摘要
|
||||
$summary = [
|
||||
'total_spins' => SlotMachineLog::query()->count(),
|
||||
'total_cost' => (int) SlotMachineLog::query()->sum('cost'),
|
||||
'total_payout' => (int) SlotMachineLog::query()->sum('payout'),
|
||||
'net_income' => (int) SlotMachineLog::query()->sum('cost') - (int) SlotMachineLog::query()->sum('payout'),
|
||||
'result_dist' => SlotMachineLog::query()
|
||||
->select('result_type', \Illuminate\Support\Facades\DB::raw('count(*) as cnt'))
|
||||
->groupBy('result_type')
|
||||
->pluck('cnt', 'result_type'),
|
||||
];
|
||||
|
||||
$query = SlotMachineLog::query()->with('user')->latest();
|
||||
|
||||
// 按结果类型筛选
|
||||
if ($request->filled('result_type')) {
|
||||
$query->where('result_type', $request->input('result_type'));
|
||||
}
|
||||
|
||||
// 按用户名筛选
|
||||
if ($request->filled('username')) {
|
||||
$query->whereHas('user', function ($q) use ($request) {
|
||||
$q->where('username', 'like', '%'.$request->input('username').'%');
|
||||
});
|
||||
}
|
||||
|
||||
$logs = $query->paginate(30)->withQueryString();
|
||||
|
||||
return view('admin.game-history.slot', compact('logs', 'summary'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 赛马竞猜历史记录页面(场次列表,支持分页)。
|
||||
*/
|
||||
public function horse(Request $request): View
|
||||
{
|
||||
$summary = [
|
||||
'total_races' => HorseRace::query()->where('status', 'settled')->count(),
|
||||
'total_bets' => HorseBet::query()->count(),
|
||||
'total_pool' => (int) HorseRace::query()->sum('total_pool'),
|
||||
];
|
||||
|
||||
$races = HorseRace::query()
|
||||
->latest()
|
||||
->paginate(20);
|
||||
|
||||
return view('admin.game-history.horse', compact('races', 'summary'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 赛马单场下注明细。
|
||||
*/
|
||||
public function horseRace(HorseRace $race): View
|
||||
{
|
||||
$bets = $race->bets()->with('user')->latest()->paginate(30);
|
||||
|
||||
return view('admin.game-history.horse-race', compact('race', 'bets'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 神秘箱子历史记录(投放/领取列表,支持分页和类型筛选)。
|
||||
*/
|
||||
public function mysteryBox(Request $request): View
|
||||
{
|
||||
$summary = [
|
||||
'total_dropped' => MysteryBox::query()->count(),
|
||||
'total_claimed' => MysteryBox::query()->where('status', 'claimed')->count(),
|
||||
'total_expired' => MysteryBox::query()->where('status', 'expired')->count(),
|
||||
'type_dist' => MysteryBox::query()
|
||||
->select('box_type', \Illuminate\Support\Facades\DB::raw('count(*) as cnt'))
|
||||
->groupBy('box_type')
|
||||
->pluck('cnt', 'box_type'),
|
||||
];
|
||||
|
||||
$query = MysteryBox::query()->with(['claim.user'])->latest();
|
||||
|
||||
if ($request->filled('box_type')) {
|
||||
$query->where('box_type', $request->input('box_type'));
|
||||
}
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->input('status'));
|
||||
}
|
||||
|
||||
$boxes = $query->paginate(20)->withQueryString();
|
||||
|
||||
return view('admin.game-history.mystery-box', compact('boxes', 'summary'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 神秘占卜历史记录(支持按用户/签文等级筛选,分页)。
|
||||
*/
|
||||
public function fortune(Request $request): View
|
||||
{
|
||||
$summary = [
|
||||
'total_times' => FortuneLog::query()->count(),
|
||||
'grade_dist' => FortuneLog::query()
|
||||
->select('grade', \Illuminate\Support\Facades\DB::raw('count(*) as cnt'))
|
||||
->groupBy('grade')
|
||||
->pluck('cnt', 'grade'),
|
||||
'total_cost' => (int) FortuneLog::query()->sum('cost'),
|
||||
'free_count' => FortuneLog::query()->where('is_free', true)->count(),
|
||||
];
|
||||
|
||||
$query = FortuneLog::query()->with('user')->latest();
|
||||
|
||||
if ($request->filled('grade')) {
|
||||
$query->where('grade', $request->input('grade'));
|
||||
}
|
||||
|
||||
if ($request->filled('username')) {
|
||||
$query->whereHas('user', function ($q) use ($request) {
|
||||
$q->where('username', 'like', '%'.$request->input('username').'%');
|
||||
});
|
||||
}
|
||||
|
||||
$logs = $query->paginate(30)->withQueryString();
|
||||
|
||||
return view('admin.game-history.fortune', compact('logs', 'summary'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 双色球彩票历史记录页面(期号列表,支持分页)。
|
||||
*/
|
||||
public function lottery(Request $request): View
|
||||
{
|
||||
$summary = [
|
||||
'total_issues' => LotteryIssue::query()->count(),
|
||||
'total_tickets' => LotteryTicket::query()->count(),
|
||||
'total_pool' => (int) LotteryIssue::query()->sum('pool_amount'),
|
||||
'drawn_count' => LotteryIssue::query()->where('status', 'settled')->count(),
|
||||
];
|
||||
|
||||
$issues = LotteryIssue::query()
|
||||
->latest()
|
||||
->paginate(20);
|
||||
|
||||
return view('admin.game-history.lottery', compact('issues', 'summary'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 双色球单期购买明细与中奖详情。
|
||||
*/
|
||||
public function lotteryIssue(LotteryIssue $issue): View
|
||||
{
|
||||
$tickets = $issue->tickets()->with('user')->latest()->paginate(30);
|
||||
|
||||
return view('admin.game-history.lottery-issue', compact('issue', 'tickets'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 五子棋历史记录页面。
|
||||
*/
|
||||
public function gomoku(Request $request): View
|
||||
{
|
||||
$summary = [
|
||||
'total_games' => GomokuGame::query()->count(),
|
||||
'pvp_count' => GomokuGame::query()->where('mode', 'pvp')->count(),
|
||||
'pve_count' => GomokuGame::query()->where('mode', 'pve')->count(),
|
||||
'completed' => GomokuGame::query()->where('status', 'finished')->count(),
|
||||
'today_games' => GomokuGame::query()->whereDate('created_at', today())->count(),
|
||||
];
|
||||
|
||||
$games = GomokuGame::query()
|
||||
->with(['playerBlack', 'playerWhite'])
|
||||
->latest()
|
||||
->paginate(30);
|
||||
|
||||
return view('admin.game-history.gomoku', compact('games', 'summary'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:节日福利后台管理控制器
|
||||
*
|
||||
* 管理员可在此创建、编辑、删除节日福利活动,
|
||||
* 也可手动立即触发活动,以及查看领取明细。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StoreHolidayEventRequest;
|
||||
use App\Http\Requests\UpdateHolidayEventRequest;
|
||||
use App\Jobs\TriggerHolidayEventJob;
|
||||
use App\Models\HolidayEvent;
|
||||
use App\Services\HolidayEventScheduleService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 类功能:管理节日福利模板的后台增删改查与手动触发操作。
|
||||
*/
|
||||
class HolidayEventController extends Controller
|
||||
{
|
||||
/**
|
||||
* 注入节日福利调度计算服务。
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly HolidayEventScheduleService $scheduleService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 节日福利活动列表页。
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$events = HolidayEvent::query()
|
||||
->orderByDesc('send_at')
|
||||
->paginate(20);
|
||||
|
||||
return view('admin.holiday-events.index', compact('events'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建活动表单页。
|
||||
*/
|
||||
public function create(): View
|
||||
{
|
||||
return view('admin.holiday-events.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新活动。
|
||||
*/
|
||||
public function store(StoreHolidayEventRequest $request): RedirectResponse
|
||||
{
|
||||
HolidayEvent::create($this->buildPayload($request->validated(), true));
|
||||
|
||||
return redirect()->route('admin.holiday-events.index')->with('success', '节日福利活动创建成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑活动表单页。
|
||||
*/
|
||||
public function edit(HolidayEvent $holidayEvent): View
|
||||
{
|
||||
return view('admin.holiday-events.edit', ['event' => $holidayEvent]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新活动。
|
||||
*/
|
||||
public function update(UpdateHolidayEventRequest $request, HolidayEvent $holidayEvent): RedirectResponse
|
||||
{
|
||||
$holidayEvent->update($this->buildPayload($request->validated()));
|
||||
|
||||
return redirect()->route('admin.holiday-events.index')->with('success', '活动已更新!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换活动启用/禁用状态。
|
||||
*/
|
||||
public function toggle(HolidayEvent $holidayEvent): JsonResponse
|
||||
{
|
||||
$holidayEvent->update(['enabled' => ! $holidayEvent->enabled]);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'enabled' => $holidayEvent->enabled,
|
||||
'message' => $holidayEvent->enabled ? '已启用' : '已禁用',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动立即触发活动(管理员操作)。
|
||||
*/
|
||||
public function triggerNow(HolidayEvent $holidayEvent): RedirectResponse
|
||||
{
|
||||
if (! $holidayEvent->enabled || $holidayEvent->status === 'cancelled') {
|
||||
return back()->with('error', '当前活动未启用或已取消,不能立即触发。');
|
||||
}
|
||||
|
||||
// 立即触发只生成临时批次,不覆盖年度锚点或下次计划时间。
|
||||
TriggerHolidayEventJob::dispatch($holidayEvent, true);
|
||||
|
||||
return back()->with('success', '活动已触发,请稍后刷新查看状态。');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除活动。
|
||||
*/
|
||||
public function destroy(HolidayEvent $holidayEvent): RedirectResponse
|
||||
{
|
||||
$holidayEvent->delete();
|
||||
|
||||
return redirect()->route('admin.holiday-events.index')->with('success', '活动已删除。');
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装节日福利模板的可持久化字段。
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function buildPayload(array $data, bool $isCreating = false): array
|
||||
{
|
||||
$payload = $data;
|
||||
|
||||
// 创建与编辑都统一回收无效字段,避免模板状态互相污染。
|
||||
if (($payload['distribute_type'] ?? 'random') === 'random') {
|
||||
$payload['fixed_amount'] = null;
|
||||
} else {
|
||||
$payload['min_amount'] = 1;
|
||||
$payload['max_amount'] = null;
|
||||
}
|
||||
|
||||
if (($payload['target_type'] ?? 'all') !== 'level') {
|
||||
$payload['target_value'] = null;
|
||||
}
|
||||
|
||||
if (($payload['repeat_type'] ?? 'once') !== 'cron') {
|
||||
$payload['cron_expr'] = null;
|
||||
}
|
||||
|
||||
if (($payload['repeat_type'] ?? 'once') === 'yearly') {
|
||||
$payload['send_at'] = $this->scheduleService
|
||||
->resolveNextConfiguredSendAt($payload)
|
||||
->toDateTimeString();
|
||||
} else {
|
||||
$payload['schedule_month'] = null;
|
||||
$payload['schedule_day'] = null;
|
||||
$payload['schedule_time'] = null;
|
||||
$payload['duration_days'] = 1;
|
||||
$payload['daily_occurrences'] = 1;
|
||||
$payload['occurrence_interval_minutes'] = null;
|
||||
}
|
||||
|
||||
// 每次保存模板时,都让系统按新配置重新进入待触发状态。
|
||||
$payload['status'] = 'pending';
|
||||
$payload['enabled'] = (bool) ($payload['enabled'] ?? true);
|
||||
$payload['triggered_at'] = null;
|
||||
$payload['expires_at'] = null;
|
||||
$payload['claimed_count'] = 0;
|
||||
$payload['claimed_amount'] = 0;
|
||||
|
||||
return $payload;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台等级经验阈值配置控制器
|
||||
*
|
||||
* 将 sysparam 表中的 levelexp 配置拆分为独立后台页面,
|
||||
* 以列表模式维护每一级所需的累计经验值。
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\UpdateLevelExpConfigRequest;
|
||||
use App\Models\Sysparam;
|
||||
use App\Services\ChatStateService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 类功能:负责展示和保存等级经验阈值列表。
|
||||
*/
|
||||
class LevelExpConfigController extends Controller
|
||||
{
|
||||
/**
|
||||
* 方法功能:注入系统参数缓存同步服务。
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ChatStateService $chatState
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 方法功能:显示等级经验阈值列表页。
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$rawThresholds = Sysparam::getLevelExpThresholds();
|
||||
$maxLevel = (int) Sysparam::getValue('maxlevel', '99');
|
||||
|
||||
$thresholds = collect($rawThresholds)
|
||||
->values()
|
||||
->map(fn (int $exp, int $index): array => [
|
||||
'level' => $index + 1,
|
||||
'exp' => $exp,
|
||||
'increment' => $index === 0 ? $exp : $exp - $rawThresholds[$index - 1],
|
||||
]);
|
||||
|
||||
return view('admin.level-exp-configs.index', [
|
||||
'thresholds' => $thresholds,
|
||||
'maxLevel' => $maxLevel,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:保存等级经验阈值配置,并同步刷新缓存。
|
||||
*/
|
||||
public function update(UpdateLevelExpConfigRequest $request): RedirectResponse
|
||||
{
|
||||
$thresholds = $request->validated('thresholds');
|
||||
|
||||
// 将列表页提交的阈值重新拼成兼容旧逻辑的逗号字符串。
|
||||
$body = implode(',', $thresholds);
|
||||
|
||||
Sysparam::updateOrCreate(
|
||||
['alias' => 'levelexp'],
|
||||
[
|
||||
'body' => $body,
|
||||
'guidetxt' => '按列表逐级维护升级所需的累计经验阈值',
|
||||
]
|
||||
);
|
||||
|
||||
// 同步更新 Redis / Cache,确保前台经验等级计算即时生效。
|
||||
$this->chatState->setSysParam('levelexp', $body);
|
||||
Sysparam::clearCache('levelexp');
|
||||
|
||||
return redirect()->route('admin.level-exp-configs.index')->with('success', '等级经验阈值已保存并生效!');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台婚姻系统管理控制器
|
||||
*
|
||||
* 提供总览统计、婚姻/求婚明细查询、婚礼档位管理、
|
||||
* 参数配置、亲密度日志审计、强制离婚等管理操作。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Marriage;
|
||||
use App\Models\MarriageIntimacyLog;
|
||||
use App\Models\WeddingCeremony;
|
||||
use App\Models\WeddingEnvelopeClaim;
|
||||
use App\Models\WeddingTier;
|
||||
use App\Services\MarriageConfigService;
|
||||
use App\Services\MarriageService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class MarriageManagerController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly MarriageConfigService $config,
|
||||
private readonly MarriageService $marriageService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 婚姻管理总览(统计卡片 + 最近记录)。
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$stats = [
|
||||
'total_married' => Marriage::where('status', 'married')->count(),
|
||||
'total_pending' => Marriage::where('status', 'pending')->count(),
|
||||
'total_divorced' => Marriage::where('status', 'divorced')->count(),
|
||||
'total_weddings' => WeddingCeremony::whereIn('status', ['active', 'completed'])->count(),
|
||||
'total_envelopes' => WeddingEnvelopeClaim::sum('amount'),
|
||||
'claimed_amount' => WeddingEnvelopeClaim::where('claimed', true)->sum('amount'),
|
||||
];
|
||||
|
||||
$recentMarriages = Marriage::with(['user:id,username', 'partner:id,username', 'ringItem:id,name,icon'])
|
||||
->where('status', 'married')
|
||||
->orderByDesc('married_at')
|
||||
->limit(10)
|
||||
->get();
|
||||
|
||||
$recentDivorces = Marriage::with(['user:id,username', 'partner:id,username'])
|
||||
->where('status', 'divorced')
|
||||
->orderByDesc('divorced_at')
|
||||
->limit(8)
|
||||
->get();
|
||||
|
||||
return view('admin.marriages.index', compact('stats', 'recentMarriages', 'recentDivorces'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 婚姻列表(支持按状态/用户名筛选)。
|
||||
*/
|
||||
public function list(Request $request): View
|
||||
{
|
||||
$query = Marriage::with(['user:id,username', 'partner:id,username', 'ringItem:id,name,icon'])
|
||||
->orderByDesc('id');
|
||||
|
||||
if ($status = $request->get('status')) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
if ($search = $request->get('search')) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->whereHas('user', fn ($u) => $u->where('username', 'like', "%{$search}%"))
|
||||
->orWhereHas('partner', fn ($u) => $u->where('username', 'like', "%{$search}%"));
|
||||
});
|
||||
}
|
||||
|
||||
$marriages = $query->paginate(20)->withQueryString();
|
||||
|
||||
return view('admin.marriages.list', compact('marriages'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 求婚记录列表(含 pending/expired/rejected)。
|
||||
*/
|
||||
public function proposals(Request $request): View
|
||||
{
|
||||
$proposals = Marriage::with(['user:id,username', 'partner:id,username', 'ringItem:id,name,icon'])
|
||||
->orderByDesc('proposed_at')
|
||||
->paginate(20)
|
||||
->withQueryString();
|
||||
|
||||
return view('admin.marriages.proposals', compact('proposals'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 婚礼红包记录。
|
||||
*/
|
||||
public function ceremonies(Request $request): View
|
||||
{
|
||||
$ceremonies = WeddingCeremony::with([
|
||||
'marriage.user:id,username',
|
||||
'marriage.partner:id,username',
|
||||
'tier:id,name,tier,icon',
|
||||
])
|
||||
->orderByDesc('id')
|
||||
->paginate(20)
|
||||
->withQueryString();
|
||||
|
||||
return view('admin.marriages.ceremonies', compact('ceremonies'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 红包领取明细(某场婚礼)。
|
||||
*/
|
||||
public function claimDetail(WeddingCeremony $ceremony): View
|
||||
{
|
||||
$ceremony->load(['marriage.user:id,username', 'marriage.partner:id,username', 'tier:id,name,icon']);
|
||||
|
||||
$claims = WeddingEnvelopeClaim::with('user:id,username,headface')
|
||||
->where('ceremony_id', $ceremony->id)
|
||||
->orderBy('amount', 'desc')
|
||||
->paginate(30);
|
||||
|
||||
return view('admin.marriages.claim-detail', compact('ceremony', 'claims'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 亲密度日志列表(支持按用户筛选)。
|
||||
*/
|
||||
public function intimacyLogs(Request $request): View
|
||||
{
|
||||
$query = MarriageIntimacyLog::with(['marriage.user:id,username', 'marriage.partner:id,username'])
|
||||
->orderByDesc('id');
|
||||
|
||||
if ($search = $request->get('search')) {
|
||||
$query->whereHas('marriage', function ($q) use ($search) {
|
||||
$q->whereHas('user', fn ($u) => $u->where('username', 'like', "%{$search}%"))
|
||||
->orWhereHas('partner', fn ($u) => $u->where('username', 'like', "%{$search}%"));
|
||||
});
|
||||
}
|
||||
if ($source = $request->get('source')) {
|
||||
$query->where('source', $source);
|
||||
}
|
||||
|
||||
$logs = $query->paginate(30)->withQueryString();
|
||||
|
||||
return view('admin.marriages.intimacy-logs', compact('logs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数配置页面(读取所有分组配置)。
|
||||
*/
|
||||
public function configs(): View
|
||||
{
|
||||
$groups = $this->config->allGrouped();
|
||||
|
||||
return view('admin.marriages.configs', compact('groups'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量保存参数配置。
|
||||
*/
|
||||
public function updateConfigs(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'configs' => 'required|array',
|
||||
'configs.*' => 'required|integer',
|
||||
]);
|
||||
|
||||
$this->config->batchSet($data['configs']);
|
||||
|
||||
return redirect()->route('admin.marriages.configs')->with('success', '婚姻参数配置已保存!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 婚礼档位配置页面。
|
||||
*/
|
||||
public function tiers(): View
|
||||
{
|
||||
$tiers = WeddingTier::orderBy('tier')->get();
|
||||
|
||||
return view('admin.marriages.tiers', compact('tiers'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新婚礼档位。
|
||||
*/
|
||||
public function updateTier(Request $request, WeddingTier $tier): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:30',
|
||||
'icon' => 'required|string|max:20',
|
||||
'amount' => 'required|integer|min:1',
|
||||
'description' => 'nullable|string|max:100',
|
||||
'is_active' => 'boolean',
|
||||
]);
|
||||
|
||||
$data['is_active'] = $request->boolean('is_active', true);
|
||||
$tier->update($data);
|
||||
|
||||
return redirect()->route('admin.marriages.tiers')->with('success', "档位【{$tier->name}】已更新!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员强制离婚。
|
||||
*/
|
||||
public function forceDissolve(Request $request, Marriage $marriage): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'admin_note' => 'required|string|max:200',
|
||||
]);
|
||||
|
||||
if ($marriage->status !== 'married') {
|
||||
return back()->with('error', '该婚姻不是已婚状态,无法操作。');
|
||||
}
|
||||
|
||||
$admin = $request->user();
|
||||
$result = $this->marriageService->forceDissolve($marriage, $admin, true);
|
||||
|
||||
// 写入管理员备注
|
||||
$marriage->update(['admin_note' => $data['admin_note']]);
|
||||
|
||||
$msg = $result['ok'] ? '强制离婚已完成。' : $result['message'];
|
||||
$type = $result['ok'] ? 'success' : 'error';
|
||||
|
||||
return back()->with($type, $msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员取消求婚(释放戒指 → 退还状态 active)。
|
||||
*/
|
||||
public function cancelProposal(Request $request, Marriage $marriage): RedirectResponse
|
||||
{
|
||||
if ($marriage->status !== 'pending') {
|
||||
return back()->with('error', '该求婚不是进行中状态,无法取消。');
|
||||
}
|
||||
|
||||
$this->marriageService->expireProposal($marriage);
|
||||
$marriage->update(['admin_note' => '管理员手动取消求婚:'.($request->input('reason', ''))]);
|
||||
|
||||
return back()->with('success', '求婚已取消,戒指标记遗失。');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:运维工具控制器
|
||||
* 提供缓存清理、路由清理、视图清理、房间在线名单清理等一键运维操作
|
||||
* 仅 id=1 超管可访问
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class OpsController extends Controller
|
||||
{
|
||||
/**
|
||||
* 运维工具主页
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
if (Auth::id() !== 1) {
|
||||
abort(403, '无权限操作');
|
||||
}
|
||||
|
||||
return view('admin.ops.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理应用缓存(config:clear + cache:clear)
|
||||
*/
|
||||
public function clearCache(): RedirectResponse
|
||||
{
|
||||
if (Auth::id() !== 1) {
|
||||
abort(403, '无权限操作');
|
||||
}
|
||||
|
||||
Artisan::call('config:clear');
|
||||
Artisan::call('cache:clear');
|
||||
|
||||
return redirect()->route('admin.ops.index')
|
||||
->with('ops_success', '✅ 应用缓存已清除(config:clear + cache:clear)');
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理路由缓存(route:clear)
|
||||
*/
|
||||
public function clearRoutes(): RedirectResponse
|
||||
{
|
||||
if (Auth::id() !== 1) {
|
||||
abort(403, '无权限操作');
|
||||
}
|
||||
|
||||
Artisan::call('route:clear');
|
||||
|
||||
return redirect()->route('admin.ops.index')
|
||||
->with('ops_success', '✅ 路由缓存已清除(route:clear)');
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理视图缓存(view:clear)
|
||||
*/
|
||||
public function clearViews(): RedirectResponse
|
||||
{
|
||||
if (Auth::id() !== 1) {
|
||||
abort(403, '无权限操作');
|
||||
}
|
||||
|
||||
Artisan::call('view:clear');
|
||||
|
||||
return redirect()->route('admin.ops.index')
|
||||
->with('ops_success', '✅ 视图缓存已清除(view:clear)');
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理所有房间 Redis 在线名单(清除幽灵在线脏数据)
|
||||
*/
|
||||
public function clearRoomOnline(): RedirectResponse
|
||||
{
|
||||
if (Auth::id() !== 1) {
|
||||
abort(403, '无权限操作');
|
||||
}
|
||||
|
||||
$prefix = config('database.redis.options.prefix', '');
|
||||
$cursor = '0';
|
||||
$cleaned = 0;
|
||||
|
||||
do {
|
||||
[$cursor, $keys] = Redis::scan($cursor, ['match' => $prefix.'room:*:users', 'count' => 100]);
|
||||
foreach ($keys ?? [] as $fullKey) {
|
||||
// 去掉前缀,还原为 Laravel Facade 使用的短 Key
|
||||
$shortKey = $prefix ? substr($fullKey, strlen($prefix)) : $fullKey;
|
||||
Redis::del($shortKey);
|
||||
$cleaned++;
|
||||
}
|
||||
} while ($cursor !== '0');
|
||||
|
||||
return redirect()->route('admin.ops.index')
|
||||
->with('ops_success', "✅ 已清理 {$cleaned} 个房间的在线名单(幽灵在线已清除)");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台职务管理控制器
|
||||
* 提供职务的 CRUD 功能,包含任命权限白名单(多选 position_appoint_limits)的同步
|
||||
* 职务属于部门,包含等级、图标、人数上限、奖励上限等配置
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Department;
|
||||
use App\Models\Position;
|
||||
use App\Models\Sysparam;
|
||||
use App\Support\PositionPermissionRegistry;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 类功能:负责后台职务资料、任命白名单与聊天室权限配置的维护。
|
||||
*/
|
||||
class PositionController extends Controller
|
||||
{
|
||||
/**
|
||||
* 职务列表页
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
// 按部门分组展示
|
||||
$departments = Department::with([
|
||||
'positions' => fn ($q) => $q->withCount(['activeUserPositions'])->with('appointablePositions')->ordered(),
|
||||
])->ordered()->get();
|
||||
|
||||
// 全部职务(供任命白名单多选框使用)
|
||||
$allPositions = Position::with('department')->ordered()->get();
|
||||
|
||||
// 全局奖励接收次数上限(0 = 不限)
|
||||
$globalRecipientDailyMax = (int) Sysparam::getValue('reward_recipient_daily_max', '0');
|
||||
|
||||
$positionPermissions = PositionPermissionRegistry::groupedDefinitions();
|
||||
$permissionLabels = PositionPermissionRegistry::labelMap();
|
||||
|
||||
return view('admin.positions.index', compact(
|
||||
'departments',
|
||||
'allPositions',
|
||||
'globalRecipientDailyMax',
|
||||
'positionPermissions',
|
||||
'permissionLabels',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建职务(同时同步任命白名单)
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'department_id' => 'required|exists:departments,id',
|
||||
'name' => 'required|string|max:50',
|
||||
'icon' => 'nullable|string|max:10',
|
||||
'rank' => 'required|integer|min:0|max:99',
|
||||
'level' => 'required|integer|min:1|max:100',
|
||||
'max_persons' => 'nullable|integer|min:1',
|
||||
'max_reward' => 'nullable|integer|min:0',
|
||||
'daily_reward_limit' => 'nullable|integer|min:0',
|
||||
'recipient_daily_limit' => 'nullable|integer|min:0',
|
||||
'red_packet_amount' => 'nullable|integer|min:1|max:999999999|gte:red_packet_count',
|
||||
'red_packet_count' => 'nullable|integer|min:1|max:100',
|
||||
'sort_order' => 'required|integer|min:0',
|
||||
'appointable_ids' => 'nullable|array',
|
||||
'appointable_ids.*' => 'exists:positions,id',
|
||||
'permissions' => 'nullable|array',
|
||||
'permissions.*' => ['string', Rule::in(PositionPermissionRegistry::codes())],
|
||||
]);
|
||||
|
||||
$appointableIds = $data['appointable_ids'] ?? [];
|
||||
unset($data['appointable_ids']);
|
||||
$data['permissions'] = array_values(array_unique($data['permissions'] ?? []));
|
||||
$data['red_packet_amount'] = (int) ($data['red_packet_amount'] ?? 8888);
|
||||
$data['red_packet_count'] = (int) ($data['red_packet_count'] ?? 10);
|
||||
|
||||
$position = Position::create($data);
|
||||
|
||||
// 同步任命白名单(有选则写,没选则清空=无任命权)
|
||||
$position->appointablePositions()->sync($appointableIds);
|
||||
|
||||
return redirect()->route('admin.positions.index')->with('success', "职务【{$data['name']}】创建成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速补丁:仅更新职务的数值限额字段(内联编辑专用)
|
||||
*
|
||||
* 允许修改的字段:max_persons / max_reward / daily_reward_limit。
|
||||
* 只接受 JSON AJAX 请求,只更新提交的字段,其余字段保持不变。
|
||||
*
|
||||
* @param Position $position 目标职务
|
||||
*/
|
||||
public function quickPatch(Request $request, Position $position): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'max_persons' => 'sometimes|nullable|integer|min:1|max:9999',
|
||||
'max_reward' => 'sometimes|nullable|integer|min:0|max:999999',
|
||||
'daily_reward_limit' => 'sometimes|nullable|integer|min:0|max:999999',
|
||||
]);
|
||||
|
||||
// 用 fill+save 确保 null 值(不限)也能正确写入
|
||||
$position->fill($data)->save();
|
||||
|
||||
return response()->json(['status' => 'success']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存全局奖励金币接收次数上限
|
||||
*
|
||||
* 控制每位用户单日内可从所有职务持有者处累计接收奖励的最高次数。
|
||||
* 0 表示不限制,保存到 sysparam 表中(key: reward_recipient_daily_max)。
|
||||
*/
|
||||
public function saveRewardConfig(Request $request): \Illuminate\Http\JsonResponse|RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'reward_recipient_daily_max' => 'required|integer|min:0|max:9999',
|
||||
]);
|
||||
|
||||
$value = (string) $request->integer('reward_recipient_daily_max');
|
||||
|
||||
Sysparam::updateOrCreate(
|
||||
['alias' => 'reward_recipient_daily_max'],
|
||||
[
|
||||
'body' => $value,
|
||||
'guidetxt' => '用户单日最多接收奖励金币次数(0=不限,统计所有职务持有者的发放总次数)',
|
||||
]
|
||||
);
|
||||
|
||||
Sysparam::clearCache('reward_recipient_daily_max');
|
||||
|
||||
$label = $value === '0' ? '不限' : "{$value} 次";
|
||||
|
||||
// AJAX 请求返回 JSON,普通表单提交返回重定向
|
||||
if ($request->expectsJson()) {
|
||||
return response()->json(['status' => 'success', 'message' => "全局接收次数上限已更新为:{$label}"]);
|
||||
}
|
||||
|
||||
return redirect()->route('admin.positions.index')
|
||||
->with('success', "全局接收次数上限已更新为:{$label}");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新职务(含任命白名单同步)
|
||||
*/
|
||||
public function update(Request $request, Position $position): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'department_id' => 'required|exists:departments,id',
|
||||
'name' => 'required|string|max:50',
|
||||
'icon' => 'nullable|string|max:10',
|
||||
'rank' => 'required|integer|min:0|max:99',
|
||||
'level' => 'required|integer|min:1|max:100',
|
||||
'max_persons' => 'nullable|integer|min:1',
|
||||
'max_reward' => 'nullable|integer|min:0',
|
||||
'daily_reward_limit' => 'nullable|integer|min:0',
|
||||
'recipient_daily_limit' => 'nullable|integer|min:0',
|
||||
'red_packet_amount' => 'nullable|integer|min:1|max:999999999|gte:red_packet_count',
|
||||
'red_packet_count' => 'nullable|integer|min:1|max:100',
|
||||
'sort_order' => 'required|integer|min:0',
|
||||
'appointable_ids' => 'nullable|array',
|
||||
'appointable_ids.*' => 'exists:positions,id',
|
||||
'permissions' => 'nullable|array',
|
||||
'permissions.*' => ['string', Rule::in(PositionPermissionRegistry::codes())],
|
||||
]);
|
||||
|
||||
$appointableIds = $data['appointable_ids'] ?? [];
|
||||
unset($data['appointable_ids']);
|
||||
$data['permissions'] = array_values(array_unique($data['permissions'] ?? []));
|
||||
$data['red_packet_amount'] = (int) ($data['red_packet_amount'] ?? 8888);
|
||||
$data['red_packet_count'] = (int) ($data['red_packet_count'] ?? 10);
|
||||
|
||||
$position->update($data);
|
||||
$position->appointablePositions()->sync($appointableIds);
|
||||
|
||||
return redirect()->route('admin.positions.index')->with('success', "职务【{$data['name']}】更新成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除职务(有在职人员时拒绝)
|
||||
*/
|
||||
public function destroy(Position $position): RedirectResponse
|
||||
{
|
||||
if ($position->isFull() || $position->activeUserPositions()->exists()) {
|
||||
return redirect()->route('admin.positions.index')
|
||||
->with('error', "职务【{$position->name}】尚有在职人员,请先撤销后再删除。");
|
||||
}
|
||||
|
||||
$position->delete();
|
||||
|
||||
return redirect()->route('admin.positions.index')->with('success', "职务【{$position->name}】已删除!");
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,12 @@
|
||||
|
||||
/**
|
||||
* 文件功能:后台房间管理控制器
|
||||
* 管理员可查看、编辑房间信息(名称、介绍、公告等)
|
||||
* 管理员可新增、编辑、删除房间信息(名称、介绍、公告等)
|
||||
* 系统房间(room_keep = true)不允许删除
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
* @version 1.1.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
@@ -30,12 +31,36 @@ class RoomManagerController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新房间信息
|
||||
* 新增房间
|
||||
*/
|
||||
public function update(Request $request, int $id): RedirectResponse
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$room = Room::findOrFail($id);
|
||||
$data = $request->validate([
|
||||
'room_name' => 'required|string|max:100|unique:rooms,room_name',
|
||||
'room_des' => 'nullable|string|max:500',
|
||||
'room_owner' => 'nullable|string|max:50',
|
||||
'permit_level' => 'required|integer|min:0|max:15',
|
||||
'door_open' => 'required|boolean',
|
||||
], [
|
||||
'room_name.unique' => '房间名称已存在,请换一个名称。',
|
||||
]);
|
||||
|
||||
// 设置新建房间的默认值
|
||||
$data['room_keep'] = false; // 新建房间均为非系统房间,可删除
|
||||
$data['build_time'] = now();
|
||||
|
||||
$room = Room::create($data);
|
||||
|
||||
return redirect()->route('admin.rooms.index')->with('success', "房间「{$room->room_name}」新建成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新房间信息
|
||||
*
|
||||
* @param Room $room 路由模型自动注入
|
||||
*/
|
||||
public function update(Request $request, Room $room): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'room_name' => 'required|string|max:100',
|
||||
'room_des' => 'nullable|string|max:500',
|
||||
@@ -47,22 +72,23 @@ class RoomManagerController extends Controller
|
||||
|
||||
$room->update($data);
|
||||
|
||||
return redirect()->route('admin.rooms.index')->with('success', "房间 [{$room->room_name}] 信息已更新!");
|
||||
return redirect()->route('admin.rooms.index')->with('success', "房间「{$room->room_name}」信息已更新!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除房间(非系统房间)
|
||||
* 删除房间(系统房间不允许删除)
|
||||
*
|
||||
* @param Room $room 路由模型自动注入
|
||||
*/
|
||||
public function destroy(int $id): RedirectResponse
|
||||
public function destroy(Room $room): RedirectResponse
|
||||
{
|
||||
$room = Room::findOrFail($id);
|
||||
|
||||
if ($room->room_keep) {
|
||||
return redirect()->route('admin.rooms.index')->with('error', '系统房间不允许删除!');
|
||||
}
|
||||
|
||||
$name = $room->room_name;
|
||||
$room->delete();
|
||||
|
||||
return redirect()->route('admin.rooms.index')->with('success', "房间 [{$room->room_name}] 已删除!");
|
||||
return redirect()->route('admin.rooms.index')->with('success', "房间「{$name}」已删除!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台商店商品管理控制器(站长功能)
|
||||
*
|
||||
* 提供商店商品的查看、编辑、切换上下架、删除等 CRUD 功能。
|
||||
* 仅 superlevel 及以上可访问,id=1 超级站长才能新增/删除。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ShopItem;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ShopItemController extends Controller
|
||||
{
|
||||
/**
|
||||
* 商品列表页(所有 superlevel 以上可查看)
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$items = ShopItem::orderBy('sort_order')->orderBy('id')->get();
|
||||
|
||||
return view('admin.shop.index', compact('items'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增商品(仅 id=1 超级站长)
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
abort_unless(Auth::id() === 1, 403);
|
||||
|
||||
$data = $this->validateItem($request);
|
||||
ShopItem::create($data);
|
||||
|
||||
return redirect()->route('admin.shop.index')->with('success', '商品「'.$data['name'].'」创建成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品信息
|
||||
*
|
||||
* @param ShopItem $shopItem 路由模型自动注入
|
||||
*/
|
||||
public function update(Request $request, ShopItem $shopItem): RedirectResponse
|
||||
{
|
||||
$data = $this->validateItem($request, $shopItem);
|
||||
$shopItem->update($data);
|
||||
|
||||
return redirect()->route('admin.shop.index')->with('success', '商品「'.$shopItem->name.'」更新成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换商品上下架状态
|
||||
*
|
||||
* @param ShopItem $shopItem 路由模型自动注入
|
||||
*/
|
||||
public function toggle(ShopItem $shopItem): RedirectResponse
|
||||
{
|
||||
$shopItem->update(['is_active' => ! $shopItem->is_active]);
|
||||
$status = $shopItem->is_active ? '上架' : '下架';
|
||||
|
||||
return redirect()->route('admin.shop.index')->with('success', "「{$shopItem->name}」已{$status}。");
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品(仅 id=1 超级站长)
|
||||
*
|
||||
* @param ShopItem $shopItem 路由模型自动注入
|
||||
*/
|
||||
public function destroy(ShopItem $shopItem): RedirectResponse
|
||||
{
|
||||
abort_unless(Auth::id() === 1, 403);
|
||||
|
||||
$name = $shopItem->name;
|
||||
$shopItem->delete();
|
||||
|
||||
return redirect()->route('admin.shop.index')->with('success', "「{$name}」已删除。");
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一验证商品表单(新增/编辑共用)
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function validateItem(Request $request, ?ShopItem $item = null): array
|
||||
{
|
||||
return $request->validate([
|
||||
'name' => 'required|string|max:100',
|
||||
'slug' => ['required', 'string', 'max:100',
|
||||
\Illuminate\Validation\Rule::unique('shop_items', 'slug')->ignore($item?->id),
|
||||
],
|
||||
'icon' => 'required|string|max:20',
|
||||
'description' => 'nullable|string|max:500',
|
||||
'price' => 'required|integer|min:0',
|
||||
'type' => 'required|in:instant,duration,one_time,ring,auto_fishing,'.ShopItem::TYPE_SIGN_REPAIR,
|
||||
'duration_days' => 'nullable|integer|min:0',
|
||||
'duration_minutes' => 'nullable|integer|min:0',
|
||||
'intimacy_bonus' => 'nullable|integer|min:0',
|
||||
'charm_bonus' => 'nullable|integer|min:0',
|
||||
'sort_order' => 'required|integer|min:0',
|
||||
'is_active' => 'boolean',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台签到奖励规则管理控制器
|
||||
*
|
||||
* 提供连续签到奖励档位的列表、新增、编辑、启停和删除功能。
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\SaveSignInRewardRuleRequest;
|
||||
use App\Models\SignInRewardRule;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 类功能:管理后台每日签到奖励规则。
|
||||
*/
|
||||
class SignInRewardRuleController extends Controller
|
||||
{
|
||||
/**
|
||||
* 方法功能:展示签到奖励规则列表。
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$rules = SignInRewardRule::query()
|
||||
->orderBy('sort_order')
|
||||
->orderBy('streak_days')
|
||||
->get();
|
||||
|
||||
return view('admin.sign-in-rules.index', compact('rules'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:新增签到奖励规则。
|
||||
*/
|
||||
public function store(SaveSignInRewardRuleRequest $request): RedirectResponse
|
||||
{
|
||||
SignInRewardRule::query()->create($this->payload($request));
|
||||
|
||||
return redirect()->route('admin.sign-in-rules.index')->with('success', '签到奖励规则已创建。');
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:更新签到奖励规则。
|
||||
*/
|
||||
public function update(SaveSignInRewardRuleRequest $request, SignInRewardRule $signInRewardRule): RedirectResponse
|
||||
{
|
||||
$signInRewardRule->update($this->payload($request));
|
||||
|
||||
return redirect()->route('admin.sign-in-rules.index')->with('success', '签到奖励规则已更新。');
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:切换签到奖励规则启用状态。
|
||||
*/
|
||||
public function toggle(SignInRewardRule $signInRewardRule): JsonResponse
|
||||
{
|
||||
$signInRewardRule->update(['is_enabled' => ! $signInRewardRule->is_enabled]);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'is_enabled' => $signInRewardRule->is_enabled,
|
||||
'message' => $signInRewardRule->is_enabled ? '规则已启用。' : '规则已停用。',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:删除签到奖励规则。
|
||||
*/
|
||||
public function destroy(SignInRewardRule $signInRewardRule): RedirectResponse
|
||||
{
|
||||
$signInRewardRule->delete();
|
||||
|
||||
return redirect()->route('admin.sign-in-rules.index')->with('success', '签到奖励规则已删除。');
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:整理后台表单提交的数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function payload(SaveSignInRewardRuleRequest $request): array
|
||||
{
|
||||
$data = $request->validated();
|
||||
$data['is_enabled'] = $request->boolean('is_enabled');
|
||||
|
||||
foreach (['identity_badge_code', 'identity_badge_name', 'identity_badge_icon', 'identity_badge_color'] as $field) {
|
||||
$data[$field] = filled($data[$field] ?? null) ? trim((string) $data[$field]) : null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ class SmtpController extends Controller
|
||||
public function test(Request $request): RedirectResponse
|
||||
{
|
||||
$request->validate([
|
||||
'test_email' => 'required|email'
|
||||
'test_email' => 'required|email',
|
||||
]);
|
||||
|
||||
$testEmail = $request->input('test_email');
|
||||
@@ -78,7 +78,7 @@ class SmtpController extends Controller
|
||||
|
||||
return redirect()->route('admin.smtp.edit')->with('success', "测试邮件已成功发送至 {$testEmail},请注意查收。");
|
||||
} catch (\Throwable $e) {
|
||||
return redirect()->route('admin.smtp.edit')->with('error', "测试发出失败,原因:" . $e->getMessage());
|
||||
return redirect()->route('admin.smtp.edit')->with('error', '测试发出失败,原因:'.$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
/**
|
||||
* 文件功能:系统参数配置控制器
|
||||
* (替代原版 VIEWSYS.ASP / SetSYS.ASP)
|
||||
* 运维工具已迁移至 OpsController
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
* @version 1.1.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
@@ -16,28 +17,37 @@ use App\Models\SysParam;
|
||||
use App\Services\ChatStateService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 类功能:后台通用系统参数配置控制器
|
||||
* 仅允许维护低敏公共参数,站长专属敏感配置需走各自独立页面。
|
||||
*/
|
||||
class SystemController extends Controller
|
||||
{
|
||||
/**
|
||||
* 构造函数注入聊天室状态服务
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ChatStateService $chatState
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 显示全局参数配置表单
|
||||
* 显示通用系统参数配置表单
|
||||
*/
|
||||
public function edit(): View
|
||||
{
|
||||
// 读取数据库中最新的参数 (剔除专属模块已接管的配置,避免重复显示)
|
||||
$params = SysParam::whereNotIn('alias', ['chatbot_enabled'])
|
||||
->where('alias', 'not like', 'smtp_%')
|
||||
->get()->pluck('body', 'alias')->toArray();
|
||||
$editableAliases = $this->editableSystemAliases();
|
||||
|
||||
// 为后台界面准备的文案对照 (可动态化或硬编码)
|
||||
$descriptions = SysParam::whereNotIn('alias', ['chatbot_enabled'])
|
||||
->where('alias', 'not like', 'smtp_%')
|
||||
->get()->pluck('guidetxt', 'alias')->toArray();
|
||||
// 通用系统页仅加载白名单字段,避免站长专属配置被普通高管查看。
|
||||
$systemParams = SysParam::query()
|
||||
->whereIn('alias', $editableAliases)
|
||||
->orderBy('id')
|
||||
->get(['alias', 'body', 'guidetxt']);
|
||||
|
||||
$params = $systemParams->pluck('body', 'alias')->all();
|
||||
$descriptions = $systemParams->pluck('guidetxt', 'alias')->all();
|
||||
|
||||
return view('admin.system.edit', compact('params', 'descriptions'));
|
||||
}
|
||||
@@ -47,16 +57,27 @@ class SystemController extends Controller
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->except(['_token', '_method']);
|
||||
// 只接受通用系统页白名单内的字段,忽略任何伪造提交的敏感键。
|
||||
$data = $request->only($this->editableSystemAliases());
|
||||
|
||||
if (array_key_exists('maxlevel', $data)) {
|
||||
$normalizedMaxLevel = max(1, (int) $data['maxlevel']);
|
||||
|
||||
// 管理员级别始终跟随最高等级 + 1,避免两个配置页出现口径漂移。
|
||||
$data['maxlevel'] = (string) $normalizedMaxLevel;
|
||||
$data['superlevel'] = (string) ($normalizedMaxLevel + 1);
|
||||
}
|
||||
|
||||
foreach ($data as $alias => $body) {
|
||||
$normalizedBody = (string) $body;
|
||||
|
||||
SysParam::updateOrCreate(
|
||||
['alias' => $alias],
|
||||
['body' => $body]
|
||||
['body' => $normalizedBody]
|
||||
);
|
||||
|
||||
// 写入 Cache 保证极速读取
|
||||
$this->chatState->setSysParam($alias, $body);
|
||||
// 仅对白名单字段同步缓存,杜绝越权请求覆盖站长专属配置。
|
||||
$this->chatState->setSysParam($alias, $normalizedBody);
|
||||
|
||||
// 同时清除 Sysparam 模型的内部缓存
|
||||
SysParam::clearCache($alias);
|
||||
@@ -64,4 +85,48 @@ class SystemController extends Controller
|
||||
|
||||
return redirect()->route('admin.system.edit')->with('success', '系统参数已成功更新并生效!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取通用系统页允许维护的参数别名白名单
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function editableSystemAliases(): array
|
||||
{
|
||||
return SysParam::query()
|
||||
->orderBy('id')
|
||||
->pluck('alias')
|
||||
->filter(fn (string $alias): bool => ! $this->isSensitiveAlias($alias) && ! $this->isDedicatedAlias($alias))
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断参数是否属于站长专属敏感配置
|
||||
*/
|
||||
private function isSensitiveAlias(string $alias): bool
|
||||
{
|
||||
if (Str::startsWith($alias, ['smtp_', 'vip_payment_', 'wechat_bot_', 'chatbot_'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Str::endsWith($alias, ['_password', '_secret', '_token', '_key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断参数是否已经迁移到独立配置页。
|
||||
*/
|
||||
private function isDedicatedAlias(string $alias): bool
|
||||
{
|
||||
return in_array($alias, [
|
||||
'levelexp',
|
||||
'level_warn',
|
||||
'level_mute',
|
||||
'level_kick',
|
||||
'level_announcement',
|
||||
'level_ban',
|
||||
'level_banip',
|
||||
'level_freeze',
|
||||
], true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,18 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Enums\CurrencySource;
|
||||
use App\Events\AppointmentAnnounced;
|
||||
use App\Events\UserBrowserRefreshRequested;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\UpdateManagedUserRequest;
|
||||
use App\Models\Department;
|
||||
use App\Models\Position;
|
||||
use App\Models\User;
|
||||
use App\Models\UserPosition;
|
||||
use App\Services\AppointmentService;
|
||||
use App\Services\ChatStateService;
|
||||
use App\Services\UserCurrencyService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -20,10 +30,22 @@ use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 类功能:负责后台用户列表展示、资料编辑与删除操作。
|
||||
*/
|
||||
class UserManagerController extends Controller
|
||||
{
|
||||
/**
|
||||
* 显示拥护列表及搜索
|
||||
* 注入统一积分服务和聊天室状态服务
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly UserCurrencyService $currencyService,
|
||||
private readonly ChatStateService $chatState,
|
||||
private readonly AppointmentService $appointmentService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 显示用户列表及搜索(支持按等级/经验/金币/魅力/在线状态排序)
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
@@ -33,66 +55,123 @@ class UserManagerController extends Controller
|
||||
$query->where('username', 'like', '%'.$request->input('username').'%');
|
||||
}
|
||||
|
||||
// 分页获取用户
|
||||
$users = $query->orderBy('id', 'desc')->paginate(20);
|
||||
// 从 Redis 获取所有在线用户名(跨所有房间去重)
|
||||
$onlineUsernames = collect();
|
||||
foreach ($this->chatState->getAllActiveRoomIds() as $roomId) {
|
||||
$onlineUsernames = $onlineUsernames->merge(array_keys($this->chatState->getRoomUsers($roomId)));
|
||||
}
|
||||
$onlineUsernames = $onlineUsernames->unique()->values();
|
||||
|
||||
// 排序:允许的字段白名单,防止 SQL 注入
|
||||
$sortable = ['user_level', 'exp_num', 'jjb', 'meili', 'id', 'online', 'wxid'];
|
||||
$sortBy = in_array($request->input('sort_by'), $sortable) ? $request->input('sort_by') : 'id';
|
||||
$sortDir = $request->input('sort_dir') === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
if ($sortBy === 'online') {
|
||||
// 用虚拟列排序:在线用户标记为 1,离线为 0;desc = 在线优先
|
||||
if ($onlineUsernames->isNotEmpty()) {
|
||||
$placeholders = implode(',', array_fill(0, $onlineUsernames->count(), '?'));
|
||||
$query->orderByRaw(
|
||||
"CASE WHEN username IN ({$placeholders}) THEN 1 ELSE 0 END {$sortDir}",
|
||||
$onlineUsernames->toArray(),
|
||||
);
|
||||
}
|
||||
$query->orderBy('id', 'desc'); // 二级排序
|
||||
} else {
|
||||
$query->orderBy($sortBy, $sortDir);
|
||||
}
|
||||
|
||||
$users = $query
|
||||
->with(['activePosition.position.department', 'vipLevel'])
|
||||
->paginate(20)
|
||||
->withQueryString();
|
||||
|
||||
// VIP 等级选项列表(供编辑弹窗使用)
|
||||
$vipLevels = \App\Models\VipLevel::orderBy('sort_order')->get();
|
||||
// 职务下拉选项(复用任命系统中的部门与职务数据)
|
||||
$departments = Department::with([
|
||||
'positions' => fn ($positionQuery) => $positionQuery->ordered(),
|
||||
])->ordered()->get();
|
||||
|
||||
return view('admin.users.index', compact('users', 'vipLevels'));
|
||||
return view('admin.users.index', compact('users', 'vipLevels', 'departments', 'sortBy', 'sortDir', 'onlineUsernames'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户资料、等级或密码 (AJAX 或表单)
|
||||
*
|
||||
* @param User $user 路由模型自动注入
|
||||
*/
|
||||
public function update(Request $request, int $id): JsonResponse|RedirectResponse
|
||||
public function update(UpdateManagedUserRequest $request, User $user): JsonResponse|RedirectResponse
|
||||
{
|
||||
$targetUser = User::findOrFail($id);
|
||||
$targetUser = $user;
|
||||
$currentUser = Auth::user();
|
||||
$responseMessages = [];
|
||||
|
||||
// 超级管理员专属:仅 id=1 的账号可编辑用户信息
|
||||
if ($currentUser->id !== 1) {
|
||||
if ($request->wantsJson()) {
|
||||
return response()->json(['status' => 'error', 'message' => '仅超级管理员(id=1)可编辑用户信息。'], 403);
|
||||
}
|
||||
abort(403, '仅超级管理员(id=1)可编辑用户信息。');
|
||||
}
|
||||
|
||||
// 越权防护:不能修改 等级大于或等于自己 的目标(除非修改自己)
|
||||
if ($targetUser->id !== $currentUser->id && $targetUser->user_level >= $currentUser->user_level) {
|
||||
return response()->json(['status' => 'error', 'message' => '权限不足:您无法修改同级或高级管理人员资料。'], 403);
|
||||
}
|
||||
|
||||
// 管理员级别 = 最高等级 + 1,后台编辑最高可设到管理员级别
|
||||
$adminLevel = (int) \App\Models\Sysparam::getValue('maxlevel', '15') + 1;
|
||||
|
||||
$validated = $request->validate([
|
||||
'sex' => 'sometimes|integer|in:0,1,2',
|
||||
'user_level' => "sometimes|integer|min:0|max:{$adminLevel}",
|
||||
'exp_num' => 'sometimes|integer|min:0',
|
||||
'jjb' => 'sometimes|integer|min:0',
|
||||
'meili' => 'sometimes|integer|min:0',
|
||||
'qianming' => 'sometimes|nullable|string|max:255',
|
||||
'headface' => 'sometimes|string|max:50',
|
||||
'password' => 'nullable|string|min:6',
|
||||
'vip_level_id' => 'sometimes|nullable|integer|exists:vip_levels,id',
|
||||
'hy_time' => 'sometimes|nullable|date',
|
||||
]);
|
||||
|
||||
// 如果传了且没超权,直接赋予
|
||||
if (isset($validated['user_level'])) {
|
||||
if ($currentUser->id !== $targetUser->id) {
|
||||
// 修改别人:只有真正的创始人 (ID=1) 才能修改别人的等级
|
||||
if ($currentUser->id !== 1) {
|
||||
return response()->json(['status' => 'error', 'message' => '权限越界:只有星系创始人(站长)才能调整其他用户的行政等级!'], 403);
|
||||
}
|
||||
}
|
||||
$targetUser->user_level = $validated['user_level'];
|
||||
}
|
||||
$validated = $request->validated();
|
||||
|
||||
if (isset($validated['sex'])) {
|
||||
$targetUser->sex = $validated['sex'];
|
||||
}
|
||||
if (isset($validated['exp_num'])) {
|
||||
$targetUser->exp_num = $validated['exp_num'];
|
||||
// 计算差值并通过统一服务记录流水(管理员手动调整)
|
||||
$expDiff = $validated['exp_num'] - ($targetUser->exp_num ?? 0);
|
||||
if ($expDiff !== 0) {
|
||||
$this->currencyService->change(
|
||||
$targetUser, 'exp', $expDiff, CurrencySource::ADMIN_ADJUST,
|
||||
"管理员 {$currentUser->username} 手动调整经验",
|
||||
);
|
||||
$targetUser->refresh();
|
||||
}
|
||||
|
||||
// 调整经验后重新计算等级(有职务用户锁定职务等级,无职务用户按经验重算)
|
||||
$targetUser->load('activePosition.position');
|
||||
$superLevel = (int) \App\Models\Sysparam::getValue('superlevel', '100');
|
||||
if ($targetUser->activePosition?->position) {
|
||||
// 有在职职务:等级锁定为职务级,不受经验影响
|
||||
$lockedLevel = (int) $targetUser->activePosition->position->level;
|
||||
if ($lockedLevel > 0 && $targetUser->user_level !== $lockedLevel) {
|
||||
$targetUser->user_level = $lockedLevel;
|
||||
}
|
||||
} elseif ($targetUser->user_level < $superLevel) {
|
||||
// 无职务普通用户:按经验重算等级(不超过满级阈值)
|
||||
$newLevel = \App\Models\Sysparam::calculateLevel($targetUser->exp_num ?? 0);
|
||||
$safeLevel = max(1, min($newLevel, $superLevel - 1));
|
||||
$targetUser->user_level = $safeLevel;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($validated['jjb'])) {
|
||||
$targetUser->jjb = $validated['jjb'];
|
||||
$jjbDiff = $validated['jjb'] - ($targetUser->jjb ?? 0);
|
||||
if ($jjbDiff !== 0) {
|
||||
$this->currencyService->change(
|
||||
$targetUser, 'gold', $jjbDiff, CurrencySource::ADMIN_ADJUST,
|
||||
"管理员 {$currentUser->username} 手动调整金币",
|
||||
);
|
||||
$targetUser->refresh();
|
||||
}
|
||||
}
|
||||
if (isset($validated['meili'])) {
|
||||
$targetUser->meili = $validated['meili'];
|
||||
$meiliDiff = $validated['meili'] - ($targetUser->meili ?? 0);
|
||||
if ($meiliDiff !== 0) {
|
||||
$this->currencyService->change(
|
||||
$targetUser, 'charm', $meiliDiff, CurrencySource::ADMIN_ADJUST,
|
||||
"管理员 {$currentUser->username} 手动调整魅力",
|
||||
);
|
||||
$targetUser->refresh();
|
||||
}
|
||||
}
|
||||
if (array_key_exists('qianming', $validated)) {
|
||||
$targetUser->qianming = $validated['qianming'];
|
||||
@@ -115,34 +194,158 @@ class UserManagerController extends Controller
|
||||
|
||||
$targetUser->save();
|
||||
|
||||
if ($request->wantsJson()) {
|
||||
return response()->json(['status' => 'success', 'message' => '用户资料已强行更新完毕!']);
|
||||
if (array_key_exists('position_id', $validated)) {
|
||||
$positionSyncResult = $this->syncUserPosition(
|
||||
operator: $currentUser,
|
||||
targetUser: $targetUser,
|
||||
targetPositionId: $validated['position_id'],
|
||||
);
|
||||
|
||||
if (! $positionSyncResult['ok']) {
|
||||
return response()->json(['status' => 'error', 'message' => $positionSyncResult['message']], 422);
|
||||
}
|
||||
|
||||
if (! empty($positionSyncResult['message'])) {
|
||||
$responseMessages[] = $positionSyncResult['message'];
|
||||
}
|
||||
}
|
||||
|
||||
return back()->with('success', '用户资料已更新!');
|
||||
if ($request->wantsJson()) {
|
||||
$message = array_merge(['用户资料已强行更新完毕!'], $responseMessages);
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => implode(' ', $message)]);
|
||||
}
|
||||
|
||||
$message = array_merge(['用户资料已更新!'], $responseMessages);
|
||||
|
||||
return back()->with('success', implode(' ', $message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 物理删除杀封用户
|
||||
*
|
||||
* @param User $user 路由模型自动注入
|
||||
*/
|
||||
public function destroy(Request $request, int $id): RedirectResponse
|
||||
public function destroy(Request $request, User $user): RedirectResponse
|
||||
{
|
||||
$targetUser = User::findOrFail($id);
|
||||
$targetUser = $user;
|
||||
$currentUser = Auth::user();
|
||||
|
||||
// 超级管理员专属:仅 id=1 的账号可删除用户
|
||||
if ($currentUser->id !== 1) {
|
||||
abort(403, '仅超级管理员(id=1)可删除用户。');
|
||||
}
|
||||
|
||||
// 越权防护:不允许删除同级或更高等级的账号
|
||||
if ($targetUser->id !== $currentUser->id && $targetUser->user_level >= $currentUser->user_level) {
|
||||
abort(403, '权限不足:无法删除同级或高级账号!');
|
||||
}
|
||||
|
||||
// 管理员保护:达到踢人等级(level_kick)的用户视为管理员,不可被强杀
|
||||
$levelKick = (int) \App\Models\Sysparam::getValue('level_kick', '10');
|
||||
if ($targetUser->user_level >= $levelKick) {
|
||||
abort(403, '该用户为管理员,不允许强杀!请先在用户编辑中降低其等级。');
|
||||
// 任命体系保护:仍持有在职职务的账号不可直接强杀,必须先走撤职流程。
|
||||
$targetUser->loadMissing('activePosition.position');
|
||||
if ($targetUser->id === 1 || $targetUser->activePosition?->position) {
|
||||
abort(403, '该用户当前拥有在职职务,不允许强杀!请先撤销职务。');
|
||||
}
|
||||
|
||||
$targetUser->delete();
|
||||
|
||||
return back()->with('success', '目标已被物理删除。');
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:同步后台编辑页选择的目标职务。
|
||||
*
|
||||
* @return array{ok: bool, message: string}
|
||||
*/
|
||||
private function syncUserPosition(User $operator, User $targetUser, ?int $targetPositionId): array
|
||||
{
|
||||
$currentAssignment = $this->appointmentService->getActivePosition($targetUser);
|
||||
$currentPositionId = $currentAssignment?->position_id;
|
||||
|
||||
if ($targetPositionId === $currentPositionId) {
|
||||
return ['ok' => true, 'message' => ''];
|
||||
}
|
||||
|
||||
if ($targetPositionId === null) {
|
||||
if (! $currentAssignment) {
|
||||
return ['ok' => true, 'message' => ''];
|
||||
}
|
||||
|
||||
$result = $this->appointmentService->revoke($operator, $targetUser, '后台用户管理编辑');
|
||||
if (! $result['ok']) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$this->broadcastRevokedPosition($operator, $targetUser, $currentAssignment);
|
||||
|
||||
return ['ok' => true, 'message' => '用户职务已撤销。'];
|
||||
}
|
||||
|
||||
$targetPosition = Position::with('department')->findOrFail($targetPositionId);
|
||||
|
||||
if ($currentAssignment) {
|
||||
$revokeResult = $this->appointmentService->revoke($operator, $targetUser, '后台用户管理编辑');
|
||||
if (! $revokeResult['ok']) {
|
||||
return $revokeResult;
|
||||
}
|
||||
}
|
||||
|
||||
$appointResult = $this->appointmentService->appoint($operator, $targetUser, $targetPosition, '后台用户管理编辑');
|
||||
if (! $appointResult['ok']) {
|
||||
return $appointResult;
|
||||
}
|
||||
|
||||
$this->broadcastAppointedPosition($operator, $targetUser, $targetPosition);
|
||||
|
||||
return ['ok' => true, 'message' => "用户职务已更新为【{$targetPosition->name}】。"];
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:广播后台任命成功后的公告与目标用户刷新事件。
|
||||
*/
|
||||
private function broadcastAppointedPosition(User $operator, User $targetUser, Position $targetPosition): void
|
||||
{
|
||||
foreach ($this->chatState->getAllActiveRoomIds() as $roomId) {
|
||||
broadcast(new AppointmentAnnounced(
|
||||
roomId: $roomId,
|
||||
targetUsername: $targetUser->username,
|
||||
positionIcon: $targetPosition->icon ?? '🎖️',
|
||||
positionName: $targetPosition->name,
|
||||
departmentName: $targetPosition->department?->name ?? '',
|
||||
operatorName: $operator->username,
|
||||
));
|
||||
}
|
||||
|
||||
broadcast(new UserBrowserRefreshRequested(
|
||||
targetUserId: $targetUser->id,
|
||||
operator: $operator->username,
|
||||
reason: '你的职务已发生变更,页面权限正在同步更新。',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:广播后台撤销职务后的公告与目标用户刷新事件。
|
||||
*/
|
||||
private function broadcastRevokedPosition(User $operator, User $targetUser, UserPosition $currentAssignment): void
|
||||
{
|
||||
$currentAssignment->loadMissing('position.department');
|
||||
|
||||
foreach ($this->chatState->getAllActiveRoomIds() as $roomId) {
|
||||
broadcast(new AppointmentAnnounced(
|
||||
roomId: $roomId,
|
||||
targetUsername: $targetUser->username,
|
||||
positionIcon: $currentAssignment->position?->icon ?? '🎖️',
|
||||
positionName: $currentAssignment->position?->name ?? '',
|
||||
departmentName: $currentAssignment->position?->department?->name ?? '',
|
||||
operatorName: $operator->username,
|
||||
type: 'revoke',
|
||||
));
|
||||
}
|
||||
|
||||
broadcast(new UserBrowserRefreshRequested(
|
||||
targetUserId: $targetUser->id,
|
||||
operator: $operator->username,
|
||||
reason: '你的职务已被撤销,页面权限正在同步更新。',
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,21 +13,124 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Models\VipLevel;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/**
|
||||
* 后台 VIP 会员等级管理控制器
|
||||
* 负责会员等级维护,以及查看各等级下的会员名单。
|
||||
*/
|
||||
class VipController extends Controller
|
||||
{
|
||||
/**
|
||||
* 会员主题支持的特效下拉选项。
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private const EFFECT_LABELS = [
|
||||
'none' => '无特效',
|
||||
'fireworks' => '烟花',
|
||||
'rain' => '下雨',
|
||||
'lightning' => '闪电',
|
||||
'snow' => '下雪',
|
||||
'sakura' => '樱花飘落',
|
||||
'meteors' => '流星',
|
||||
'gold-rain' => '金币雨',
|
||||
'hearts' => '爱心飘落',
|
||||
'confetti' => '彩带庆典',
|
||||
'fireflies' => '萤火虫',
|
||||
];
|
||||
|
||||
/**
|
||||
* 会员主题支持的横幅风格下拉选项。
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
private const BANNER_STYLE_LABELS = [
|
||||
'aurora' => '鎏光星幕',
|
||||
'storm' => '雷霆风暴',
|
||||
'royal' => '王者金辉',
|
||||
'cosmic' => '星穹幻彩',
|
||||
'farewell' => '告别暮光',
|
||||
];
|
||||
|
||||
/**
|
||||
* 会员等级管理列表页
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$levels = VipLevel::orderBy('sort_order')->get();
|
||||
$levels = VipLevel::query()
|
||||
->withCount('users')
|
||||
->orderBy('sort_order')
|
||||
->get();
|
||||
|
||||
return view('admin.vip.index', compact('levels'));
|
||||
return view('admin.vip.index', [
|
||||
'levels' => $levels,
|
||||
'effectOptions' => self::EFFECT_LABELS,
|
||||
'bannerStyleOptions' => self::BANNER_STYLE_LABELS,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看某个会员等级下的会员名单。
|
||||
*
|
||||
* @param Request $request 当前筛选请求
|
||||
* @param VipLevel $vip 当前会员等级
|
||||
*/
|
||||
public function members(Request $request, VipLevel $vip): View
|
||||
{
|
||||
$query = User::query()->where('vip_level_id', $vip->id);
|
||||
$now = now();
|
||||
|
||||
if ($request->filled('keyword')) {
|
||||
$keyword = trim((string) $request->input('keyword'));
|
||||
|
||||
// 支持后台按用户名快速筛选某个等级下的会员。
|
||||
$query->where('username', 'like', '%'.$keyword.'%');
|
||||
}
|
||||
|
||||
if ($request->input('status') === 'active') {
|
||||
// 当前有效会员:永久会员或到期时间仍在未来。
|
||||
$query->where(function ($builder) use ($now): void {
|
||||
$builder->whereNull('hy_time')->orWhere('hy_time', '>', $now);
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->input('status') === 'expired') {
|
||||
// 已过期会员:到期时间存在且已经早于当前时间。
|
||||
$query->whereNotNull('hy_time')->where('hy_time', '<=', $now);
|
||||
}
|
||||
|
||||
$members = $query
|
||||
->select(['id', 'username', 'sex', 'vip_level_id', 'hy_time', 'created_at'])
|
||||
->orderByRaw('CASE WHEN hy_time IS NULL THEN 0 WHEN hy_time > ? THEN 1 ELSE 2 END', [$now])
|
||||
->orderByRaw('hy_time IS NULL DESC')
|
||||
->orderByDesc('hy_time')
|
||||
->orderBy('username')
|
||||
->paginate(20)
|
||||
->withQueryString();
|
||||
|
||||
$totalAssignedCount = User::query()
|
||||
->where('vip_level_id', $vip->id)
|
||||
->count();
|
||||
|
||||
$activeCount = User::query()
|
||||
->where('vip_level_id', $vip->id)
|
||||
->where(function ($builder) use ($now): void {
|
||||
$builder->whereNull('hy_time')->orWhere('hy_time', '>', $now);
|
||||
})
|
||||
->count();
|
||||
|
||||
return view('admin.vip.members', [
|
||||
'vip' => $vip,
|
||||
'members' => $members,
|
||||
'totalAssignedCount' => $totalAssignedCount,
|
||||
'activeCount' => $activeCount,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,22 +138,7 @@ class VipController extends Controller
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'icon' => 'required|string|max:20',
|
||||
'color' => 'required|string|max:10',
|
||||
'exp_multiplier' => 'required|numeric|min:1|max:99',
|
||||
'jjb_multiplier' => 'required|numeric|min:1|max:99',
|
||||
'sort_order' => 'required|integer|min:0',
|
||||
'price' => 'required|integer|min:0',
|
||||
'duration_days' => 'required|integer|min:0',
|
||||
'join_templates' => 'nullable|string',
|
||||
'leave_templates' => 'nullable|string',
|
||||
]);
|
||||
|
||||
// 将文本框的多行模板转为 JSON 数组
|
||||
$data['join_templates'] = $this->textToJson($data['join_templates'] ?? '');
|
||||
$data['leave_templates'] = $this->textToJson($data['leave_templates'] ?? '');
|
||||
$data = $this->validatedPayload($request);
|
||||
|
||||
VipLevel::create($data);
|
||||
|
||||
@@ -60,27 +148,13 @@ class VipController extends Controller
|
||||
/**
|
||||
* 更新会员等级
|
||||
*
|
||||
* @param int $id 等级ID
|
||||
* @param VipLevel $vip 路由模型自动注入
|
||||
*/
|
||||
public function update(Request $request, int $id): RedirectResponse
|
||||
public function update(Request $request, VipLevel $vip): RedirectResponse
|
||||
{
|
||||
$level = VipLevel::findOrFail($id);
|
||||
$level = $vip;
|
||||
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'icon' => 'required|string|max:20',
|
||||
'color' => 'required|string|max:10',
|
||||
'exp_multiplier' => 'required|numeric|min:1|max:99',
|
||||
'jjb_multiplier' => 'required|numeric|min:1|max:99',
|
||||
'sort_order' => 'required|integer|min:0',
|
||||
'price' => 'required|integer|min:0',
|
||||
'duration_days' => 'required|integer|min:0',
|
||||
'join_templates' => 'nullable|string',
|
||||
'leave_templates' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$data['join_templates'] = $this->textToJson($data['join_templates'] ?? '');
|
||||
$data['leave_templates'] = $this->textToJson($data['leave_templates'] ?? '');
|
||||
$data = $this->validatedPayload($request);
|
||||
|
||||
$level->update($data);
|
||||
|
||||
@@ -90,12 +164,11 @@ class VipController extends Controller
|
||||
/**
|
||||
* 删除会员等级(关联用户的 vip_level_id 会自动置 null)
|
||||
*
|
||||
* @param int $id 等级ID
|
||||
* @param VipLevel $vip 路由模型自动注入
|
||||
*/
|
||||
public function destroy(int $id): RedirectResponse
|
||||
public function destroy(VipLevel $vip): RedirectResponse
|
||||
{
|
||||
$level = VipLevel::findOrFail($id);
|
||||
$level->delete();
|
||||
$vip->delete();
|
||||
|
||||
return redirect()->route('admin.vip.index')->with('success', '会员等级已删除!');
|
||||
}
|
||||
@@ -120,4 +193,37 @@ class VipController extends Controller
|
||||
|
||||
return json_encode(array_values($lines), JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一整理后台提交的会员等级主题配置数据。
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function validatedPayload(Request $request): array
|
||||
{
|
||||
$data = $request->validate([
|
||||
'name' => 'required|string|max:50',
|
||||
'icon' => 'required|string|max:20',
|
||||
'color' => 'required|string|max:10',
|
||||
'exp_multiplier' => 'required|numeric|min:1|max:99',
|
||||
'jjb_multiplier' => 'required|numeric|min:1|max:99',
|
||||
'sort_order' => 'required|integer|min:0',
|
||||
'price' => 'required|integer|min:0',
|
||||
'duration_days' => 'required|integer|min:0',
|
||||
'join_templates' => 'nullable|string',
|
||||
'leave_templates' => 'nullable|string',
|
||||
'join_effect' => ['required', 'string', Rule::in(VipLevel::EFFECT_OPTIONS)],
|
||||
'leave_effect' => ['required', 'string', Rule::in(VipLevel::EFFECT_OPTIONS)],
|
||||
'join_banner_style' => 'required|in:aurora,storm,royal,cosmic,farewell',
|
||||
'leave_banner_style' => 'required|in:aurora,storm,royal,cosmic,farewell',
|
||||
'allow_custom_messages' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
// 将多行文本框内容转为 JSON 数组,便于后续随机抽取模板。
|
||||
$data['join_templates'] = $this->textToJson($data['join_templates'] ?? '');
|
||||
$data['leave_templates'] = $this->textToJson($data['leave_templates'] ?? '');
|
||||
$data['allow_custom_messages'] = $request->boolean('allow_custom_messages');
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台 VIP 支付配置控制器
|
||||
* 用于管理聊天室对接 NovaLink 支付中心所需的开关、地址、App Key 与 App Secret
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\UpdateVipPaymentConfigRequest;
|
||||
use App\Models\SysParam;
|
||||
use App\Services\ChatStateService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class VipPaymentConfigController extends Controller
|
||||
{
|
||||
/**
|
||||
* 构造函数注入聊天室状态服务
|
||||
*
|
||||
* @param ChatStateService $chatState 系统参数缓存同步服务
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ChatStateService $chatState,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 显示 VIP 支付配置页
|
||||
*/
|
||||
public function edit(): View
|
||||
{
|
||||
$aliases = array_keys($this->fieldDescriptions());
|
||||
|
||||
// 仅读取 VIP 支付专属配置,避免与系统参数页重复展示。
|
||||
$params = SysParam::query()
|
||||
->whereIn('alias', $aliases)
|
||||
->pluck('body', 'alias')
|
||||
->toArray();
|
||||
|
||||
return view('admin.vip-payment.config', [
|
||||
'params' => $params,
|
||||
'descriptions' => $this->fieldDescriptions(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存 VIP 支付配置并刷新缓存
|
||||
*
|
||||
* @param UpdateVipPaymentConfigRequest $request 已校验的后台配置请求
|
||||
*/
|
||||
public function update(UpdateVipPaymentConfigRequest $request): RedirectResponse
|
||||
{
|
||||
$data = $request->validated();
|
||||
$descriptions = $this->fieldDescriptions();
|
||||
|
||||
foreach ($descriptions as $alias => $guidetxt) {
|
||||
$body = (string) ($data[$alias] ?? '');
|
||||
|
||||
// 写入数据库并同步描述文案,确保后续后台与缓存读取一致。
|
||||
SysParam::updateOrCreate(
|
||||
['alias' => $alias],
|
||||
['body' => $body, 'guidetxt' => $guidetxt]
|
||||
);
|
||||
|
||||
$this->chatState->setSysParam($alias, $body);
|
||||
SysParam::clearCache($alias);
|
||||
}
|
||||
|
||||
return redirect()->route('admin.vip-payment.edit')->with('success', 'VIP 支付配置已成功保存。');
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回 VIP 支付字段说明文案
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function fieldDescriptions(): array
|
||||
{
|
||||
return [
|
||||
'vip_payment_enabled' => 'VIP 在线支付开关(1=开启,0=关闭)',
|
||||
'vip_payment_base_url' => 'NovaLink 支付中心地址(例如 https://novalink.test)',
|
||||
'vip_payment_app_key' => 'NovaLink 支付中心 App Key',
|
||||
'vip_payment_app_secret' => 'NovaLink 支付中心 App Secret',
|
||||
'vip_payment_timeout' => '调用支付中心超时时间(秒)',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:后台会员购买日志控制器
|
||||
* 负责展示聊天室 VIP 在线支付订单列表,并支持按用户、状态、订单号和日期筛选
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\VipPaymentOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class VipPaymentLogController extends Controller
|
||||
{
|
||||
/**
|
||||
* 显示会员购买日志列表
|
||||
*
|
||||
* @param Request $request 当前查询请求
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$query = VipPaymentOrder::query()->with(['user:id,username', 'vipLevel:id,name,color,icon']);
|
||||
|
||||
if ($request->filled('username')) {
|
||||
$username = (string) $request->input('username');
|
||||
|
||||
// 通过用户关联模糊匹配用户名,便于后台快速定位某个会员订单。
|
||||
$query->whereHas('user', function ($builder) use ($username): void {
|
||||
$builder->where('username', 'like', '%'.$username.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', (string) $request->input('status'));
|
||||
}
|
||||
|
||||
if ($request->filled('order_no')) {
|
||||
$keyword = (string) $request->input('order_no');
|
||||
$query->where(function ($builder) use ($keyword): void {
|
||||
$builder->where('order_no', 'like', '%'.$keyword.'%')
|
||||
->orWhere('merchant_order_no', 'like', '%'.$keyword.'%')
|
||||
->orWhere('payment_order_no', 'like', '%'.$keyword.'%')
|
||||
->orWhere('provider_trade_no', 'like', '%'.$keyword.'%');
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->filled('date_start')) {
|
||||
$query->whereDate('created_at', '>=', (string) $request->input('date_start'));
|
||||
}
|
||||
|
||||
if ($request->filled('date_end')) {
|
||||
$query->whereDate('created_at', '<=', (string) $request->input('date_end'));
|
||||
}
|
||||
|
||||
$logs = $query->latest('id')->paginate(30)->withQueryString();
|
||||
|
||||
return view('admin.vip-payment-logs.index', [
|
||||
'logs' => $logs,
|
||||
'statusOptions' => [
|
||||
'created' => '待创建',
|
||||
'pending' => '待支付',
|
||||
'paid' => '已支付',
|
||||
'closed' => '已关闭',
|
||||
'failed' => '失败',
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:微信机器人配置控制器
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\SysParam;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class WechatBotController extends Controller
|
||||
{
|
||||
/**
|
||||
* 显示微信机器人配置表单
|
||||
*/
|
||||
public function edit(): View
|
||||
{
|
||||
// 从 SysParam 获取配置,若不存在赋予默认空 JSON
|
||||
$param = SysParam::firstOrCreate(
|
||||
['alias' => 'wechat_bot_config'],
|
||||
[
|
||||
'body' => json_encode([
|
||||
'kafka' => [
|
||||
'brokers' => '',
|
||||
'topic' => '',
|
||||
'group_id' => 'chatroom_wechat_bot',
|
||||
'bot_wxid' => '',
|
||||
],
|
||||
'api' => [
|
||||
'base_url' => '',
|
||||
'bot_key' => '',
|
||||
],
|
||||
'global_notify' => [
|
||||
'start_time' => '08:00',
|
||||
'end_time' => '22:00',
|
||||
],
|
||||
'group_notify' => [
|
||||
'target_wxid' => '',
|
||||
'toggle_admin_online' => false,
|
||||
'toggle_baccarat_result' => false,
|
||||
'toggle_lottery_result' => false,
|
||||
],
|
||||
'personal_notify' => [
|
||||
'toggle_friend_online' => false,
|
||||
'toggle_spouse_online' => false,
|
||||
'toggle_level_change' => false,
|
||||
],
|
||||
]),
|
||||
'guidetxt' => '微信机器人全站配置(包含群聊推送和私聊推送开关及Kafka连接)',
|
||||
]
|
||||
);
|
||||
|
||||
$config = json_decode($param->body, true);
|
||||
|
||||
return view('admin.wechat_bot.edit', compact('config'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新微信机器人配置
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'kafka_brokers' => 'nullable|string',
|
||||
'kafka_topic' => 'nullable|string',
|
||||
'kafka_group_id' => 'nullable|string',
|
||||
'kafka_bot_wxid' => 'nullable|string',
|
||||
'api_base_url' => 'nullable|string',
|
||||
'api_bot_key' => 'nullable|string',
|
||||
'qrcode_image' => 'nullable|image|max:2048',
|
||||
'global_start_time' => 'nullable|string',
|
||||
'global_end_time' => 'nullable|string',
|
||||
'group_target_wxid' => 'nullable|string',
|
||||
'toggle_admin_online' => 'nullable|boolean',
|
||||
'toggle_baccarat_result' => 'nullable|boolean',
|
||||
'toggle_lottery_result' => 'nullable|boolean',
|
||||
'toggle_friend_online' => 'nullable|boolean',
|
||||
'toggle_spouse_online' => 'nullable|boolean',
|
||||
'toggle_level_change' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
$param = SysParam::where('alias', 'wechat_bot_config')->first();
|
||||
$oldConfig = $param ? (json_decode($param->body, true) ?? []) : [];
|
||||
|
||||
$qrcodePath = $oldConfig['api']['qrcode_image'] ?? '';
|
||||
if ($request->hasFile('qrcode_image')) {
|
||||
// 删除旧图
|
||||
if ($qrcodePath && \Illuminate\Support\Facades\Storage::disk('public')->exists($qrcodePath)) {
|
||||
\Illuminate\Support\Facades\Storage::disk('public')->delete($qrcodePath);
|
||||
}
|
||||
$qrcodePath = $request->file('qrcode_image')->store('wechat', 'public');
|
||||
}
|
||||
|
||||
$config = [
|
||||
'kafka' => [
|
||||
'brokers' => $validated['kafka_brokers'] ?? '',
|
||||
'topic' => $validated['kafka_topic'] ?? '',
|
||||
'group_id' => $validated['kafka_group_id'] ?? 'chatroom_wechat_bot',
|
||||
'bot_wxid' => $validated['kafka_bot_wxid'] ?? '',
|
||||
],
|
||||
'api' => [
|
||||
'base_url' => $validated['api_base_url'] ?? '',
|
||||
'bot_key' => $validated['api_bot_key'] ?? '',
|
||||
'qrcode_image' => $qrcodePath,
|
||||
],
|
||||
'global_notify' => [
|
||||
'start_time' => $validated['global_start_time'] ?? '',
|
||||
'end_time' => $validated['global_end_time'] ?? '',
|
||||
],
|
||||
'group_notify' => [
|
||||
'target_wxid' => $validated['group_target_wxid'] ?? '',
|
||||
'toggle_admin_online' => $validated['toggle_admin_online'] ?? false,
|
||||
'toggle_baccarat_result' => $validated['toggle_baccarat_result'] ?? false,
|
||||
'toggle_lottery_result' => $validated['toggle_lottery_result'] ?? false,
|
||||
],
|
||||
'personal_notify' => [
|
||||
'toggle_friend_online' => $validated['toggle_friend_online'] ?? false,
|
||||
'toggle_spouse_online' => $validated['toggle_spouse_online'] ?? false,
|
||||
'toggle_level_change' => $validated['toggle_level_change'] ?? false,
|
||||
],
|
||||
];
|
||||
|
||||
if ($param) {
|
||||
$param->update(['body' => json_encode($config)]);
|
||||
SysParam::clearCache('wechat_bot_config');
|
||||
}
|
||||
|
||||
return redirect()->route('admin.wechat_bot.edit')->with('success', '机器相关配置已更新完成。如修改了Kafka请重启后端监听队列守护进程。');
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送群内公告
|
||||
*/
|
||||
public function sendAnnouncement(Request $request, \App\Services\WechatBot\WechatNotificationService $wechatService): RedirectResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'announcement_content' => 'required|string|max:1000',
|
||||
], [
|
||||
'announcement_content.required' => '请输入公告内容',
|
||||
'announcement_content.max' => '公告内容太长,不能超过1000字',
|
||||
]);
|
||||
|
||||
try {
|
||||
$wechatService->sendCustomGroupAnnouncement($validated['announcement_content']);
|
||||
|
||||
return back()->with('success', '群公告已通过微信机器人发送成功!(消息已进入队列)');
|
||||
} catch (\Exception $e) {
|
||||
return back()->withInput()->withErrors(['announcement_content' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -17,7 +17,7 @@ class VerificationController extends Controller
|
||||
public function sendEmailCode(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'email' => 'required|email'
|
||||
'email' => 'required|email',
|
||||
]);
|
||||
|
||||
$email = $request->input('email');
|
||||
@@ -27,23 +27,24 @@ class VerificationController extends Controller
|
||||
if (SysParam::where('alias', 'smtp_enabled')->value('body') !== '1') {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => '抱歉,当前系统未开启外部邮件发信服务,请联系管理员。'
|
||||
'message' => '抱歉,当前系统未开启外部邮件发信服务,请联系管理员。',
|
||||
], 403);
|
||||
}
|
||||
|
||||
// 2. 检查是否有频率限制(同一用户或同一邮箱,60秒只允许发1次)
|
||||
$throttleKey = 'email_throttle_' . $user->id;
|
||||
$throttleKey = 'email_throttle_'.$user->id;
|
||||
if (Cache::has($throttleKey)) {
|
||||
$ttl = Cache::ttl($throttleKey);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => "发送过于频繁,请等待 {$ttl} 秒后再试。"
|
||||
'message' => "发送过于频繁,请等待 {$ttl} 秒后再试。",
|
||||
], 429);
|
||||
}
|
||||
|
||||
// 3. 生成 6 位随机验证码并缓存,有效期 5 分钟
|
||||
$code = mt_rand(100000, 999999);
|
||||
$codeKey = 'email_verify_code_' . $user->id . '_' . $email;
|
||||
$codeKey = 'email_verify_code_'.$user->id.'_'.$email;
|
||||
Cache::put($codeKey, $code, now()->addMinutes(5));
|
||||
|
||||
// 设置频率锁,过期时间 60 秒
|
||||
@@ -57,14 +58,15 @@ class VerificationController extends Controller
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => '验证码已发送,请注意查收邮件。'
|
||||
'message' => '验证码已发送,请注意查收邮件。',
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
// 如果发信失败,主动接触频率限制锁方便用户下一次立重试
|
||||
Cache::forget($throttleKey);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => '邮件系统发送异常,请稍后再试: ' . $e->getMessage()
|
||||
'message' => '邮件系统发送异常,请稍后再试: '.$e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,18 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\LoginRequest;
|
||||
use App\Models\Sysparam;
|
||||
use App\Models\User;
|
||||
use App\Models\UsernameBlacklist;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Sysparam;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
/**
|
||||
* 类功能:处理聊天室前台登录、自动注册与退出登录。
|
||||
*/
|
||||
class AuthController extends Controller
|
||||
{
|
||||
/**
|
||||
@@ -38,7 +42,15 @@ class AuthController extends Controller
|
||||
|
||||
if ($user) {
|
||||
// 用户存在,验证密码
|
||||
if (Hash::check($password, $user->password)) {
|
||||
$passwordMatches = false;
|
||||
try {
|
||||
$passwordMatches = Hash::check($password, $user->password);
|
||||
} catch (\RuntimeException $e) {
|
||||
// Hash::check() in Laravel 11/12 throws if the hash isn't a valid bcrypt string
|
||||
$passwordMatches = false;
|
||||
}
|
||||
|
||||
if ($passwordMatches) {
|
||||
// Bcrypt 验证通过
|
||||
|
||||
// 检测是否被封禁 (后台管理员级别获得豁免权,防止误把自己关在门外)
|
||||
@@ -52,7 +64,7 @@ class AuthController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$this->performLogin($user, $ip);
|
||||
$this->performLogin($user, $ip, $request);
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => '登录成功']);
|
||||
}
|
||||
@@ -74,7 +86,7 @@ class AuthController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$this->performLogin($user, $ip);
|
||||
$this->performLogin($user, $ip, $request);
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => '登录成功,且安全策略已自动升级']);
|
||||
}
|
||||
@@ -99,6 +111,26 @@ class AuthController extends Controller
|
||||
return response()->json(['status' => 'error', 'message' => '您所在的 IP 地址已被管理员封禁,禁止注册新账号。'], 403);
|
||||
}
|
||||
|
||||
// 检测用户名是否在禁用词列表(永久禁用 或 改名临时保留期内)
|
||||
if ($blockingRecord = UsernameBlacklist::getBlockingRecord($username)) {
|
||||
$reason = '';
|
||||
if ($blockingRecord->type === 'permanent') {
|
||||
$reason = "(包含违禁敏感词:{$blockingRecord->username})";
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'error', 'message' => "该用户名已被系统禁止注册{$reason},请更换其他名称。"], 422);
|
||||
}
|
||||
|
||||
// --- 提取邀请人 Cookie ---
|
||||
$inviterIdCookie = $request->cookie('inviter_id');
|
||||
$inviterId = null;
|
||||
if ($inviterIdCookie && is_numeric($inviterIdCookie)) {
|
||||
// 简单校验邀请人是否存在,防止脏数据
|
||||
if (User::where('id', $inviterIdCookie)->exists()) {
|
||||
$inviterId = (int) $inviterIdCookie;
|
||||
}
|
||||
}
|
||||
|
||||
$newUser = User::create([
|
||||
'username' => $username,
|
||||
'password' => Hash::make($password),
|
||||
@@ -107,9 +139,15 @@ class AuthController extends Controller
|
||||
'user_level' => 1, // 默认普通用户等级
|
||||
'sex' => $sex,
|
||||
'usersf' => '1.gif', // 默认头像
|
||||
'inviter_id' => $inviterId, // 记录邀请人
|
||||
]);
|
||||
|
||||
$this->performLogin($newUser, $ip);
|
||||
$this->performLogin($newUser, $ip, $request);
|
||||
|
||||
// 如果是通过邀请注册的,响应成功后建议清除 Cookie,防止污染后续注册
|
||||
if ($inviterId) {
|
||||
\Illuminate\Support\Facades\Cookie::queue(\Illuminate\Support\Facades\Cookie::forget('inviter_id'));
|
||||
}
|
||||
|
||||
return response()->json(['status' => 'success', 'message' => '注册并登录成功!']);
|
||||
}
|
||||
@@ -117,15 +155,18 @@ class AuthController extends Controller
|
||||
/**
|
||||
* 执行实际的登录操作并记录时间、IP 等。
|
||||
*/
|
||||
private function performLogin(User $user, string $ip): void
|
||||
private function performLogin(User $user, string $ip, Request $request): void
|
||||
{
|
||||
Auth::login($user);
|
||||
// 登录成功后立即轮换 session id,阻断会话固定攻击。
|
||||
$request->session()->regenerate();
|
||||
|
||||
// 递增访问次数
|
||||
$user->increment('visit_num');
|
||||
|
||||
// 更新最后登录IP和时间
|
||||
|
||||
// 更新最后登录IP和时间(同时将旧IP转移到 previous_ip 作上次登录记录)
|
||||
$user->update([
|
||||
'previous_ip' => $user->last_ip,
|
||||
'last_ip' => $ip,
|
||||
'log_time' => now(),
|
||||
'in_time' => now(),
|
||||
@@ -137,6 +178,16 @@ class AuthController extends Controller
|
||||
'sdate' => now(),
|
||||
'uuname' => $user->username,
|
||||
]);
|
||||
|
||||
// 触发微信机器人消息推送 (登录上线类)
|
||||
try {
|
||||
$wechatService = new \App\Services\WechatBot\WechatNotificationService;
|
||||
$wechatService->notifyAdminOnline($user);
|
||||
$wechatService->notifyFriendsOnline($user);
|
||||
$wechatService->notifySpouseOnline($user);
|
||||
} catch (\Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error('WechatBot presence notification failed', ['error' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,6 +202,17 @@ class AuthController extends Controller
|
||||
'out_time' => now(),
|
||||
'out_info' => '正常退出了聊天室',
|
||||
]);
|
||||
|
||||
// [NEW] 同步清除该用户在所有房间的在线状态和心跳,确保其如果马上重登,能触发全新入场欢迎
|
||||
try {
|
||||
$chatState = app(\App\Services\ChatStateService::class);
|
||||
$roomIds = $chatState->getUserRooms($user->username);
|
||||
foreach ($roomIds as $roomId) {
|
||||
$chatState->userLeave($roomId, $user->username);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// 忽略清理缓存时发生的异常
|
||||
}
|
||||
}
|
||||
|
||||
Auth::logout();
|
||||
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:百家乐前台下注控制器
|
||||
*
|
||||
* 提供用户在聊天室内下注的 API 接口:
|
||||
* - 查询当前局次信息
|
||||
* - 提交下注(扣除金币 + 写入下注记录)
|
||||
* - 查询本人在当前局的下注状态
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\CurrencySource;
|
||||
use App\Models\BaccaratBet;
|
||||
use App\Models\BaccaratRound;
|
||||
use App\Models\GameConfig;
|
||||
use App\Services\BaccaratLossCoverService;
|
||||
use App\Services\UserCurrencyService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class BaccaratController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly UserCurrencyService $currency,
|
||||
private readonly BaccaratLossCoverService $lossCoverService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 获取当前进行中的局次信息(前端轮询或开局事件后调用)。
|
||||
*/
|
||||
public function currentRound(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
$round = BaccaratRound::currentRound();
|
||||
|
||||
if (! $round) {
|
||||
return response()->json([
|
||||
'round' => null,
|
||||
// 即使当前无局次,也返回最新金币余额,供前端每次打开弹窗时刷新右上角显示。
|
||||
'jjb' => (int) ($user->jjb ?? 0),
|
||||
]);
|
||||
}
|
||||
|
||||
$myBet = BaccaratBet::query()
|
||||
->where('round_id', $round->id)
|
||||
->where('user_id', $user->id)
|
||||
->first();
|
||||
|
||||
$config = GameConfig::forGame('baccarat')?->params ?? [];
|
||||
$minBet = (int) ($config['min_bet'] ?? 100);
|
||||
$maxBet = (int) ($config['max_bet'] ?? 50000);
|
||||
|
||||
return response()->json([
|
||||
'round' => [
|
||||
'id' => $round->id,
|
||||
'status' => $round->status,
|
||||
'bet_closes_at' => $round->bet_closes_at->toIso8601String(),
|
||||
'seconds_left' => max(0, (int) now()->diffInSeconds($round->bet_closes_at, false)),
|
||||
'total_bet_big' => $round->total_bet_big,
|
||||
'total_bet_small' => $round->total_bet_small,
|
||||
'total_bet_triple' => $round->total_bet_triple,
|
||||
'bet_count_big' => $round->bet_count_big,
|
||||
'bet_count_small' => $round->bet_count_small,
|
||||
'bet_count_triple' => $round->bet_count_triple,
|
||||
'min_bet' => $minBet,
|
||||
'max_bet' => $maxBet,
|
||||
'my_bet' => $myBet ? [
|
||||
'bet_type' => $myBet->bet_type,
|
||||
'amount' => $myBet->amount,
|
||||
] : null,
|
||||
],
|
||||
// 返回当前用户最新金币,前端每次打开弹窗都可同步右上角余额。
|
||||
'jjb' => (int) ($user->jjb ?? 0),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户提交下注。
|
||||
*
|
||||
* 同一局每人限下一注(后台强制幂等)。
|
||||
* 下注成功后立即扣除金币,结算时中奖者才返还本金+赔付。
|
||||
*/
|
||||
public function bet(Request $request): JsonResponse
|
||||
{
|
||||
if (! GameConfig::isEnabled('baccarat')) {
|
||||
return response()->json(['ok' => false, 'message' => '百家乐游戏当前未开启。']);
|
||||
}
|
||||
|
||||
$data = $request->validate([
|
||||
'round_id' => 'required|integer|exists:baccarat_rounds,id',
|
||||
'bet_type' => 'required|in:big,small,triple',
|
||||
'amount' => 'required|integer|min:1',
|
||||
]);
|
||||
|
||||
$config = GameConfig::forGame('baccarat')?->params ?? [];
|
||||
$minBet = (int) ($config['min_bet'] ?? 100);
|
||||
$maxBet = (int) ($config['max_bet'] ?? 50000);
|
||||
|
||||
if ($data['amount'] < $minBet || $data['amount'] > $maxBet) {
|
||||
return response()->json(['ok' => false, 'message' => "押注金额须在 {$minBet}~{$maxBet} 金币之间。"]);
|
||||
}
|
||||
|
||||
$round = BaccaratRound::find($data['round_id']);
|
||||
|
||||
if (! $round || ! $round->isBettingOpen()) {
|
||||
return response()->json(['ok' => false, 'message' => '当前不在下注时间内。']);
|
||||
}
|
||||
|
||||
$user = $request->user();
|
||||
|
||||
// 检查用户金币余额(金币字段为 jjb)
|
||||
if (($user->jjb ?? 0) < $data['amount']) {
|
||||
return response()->json(['ok' => false, 'message' => '金币不足,无法下注。']);
|
||||
}
|
||||
|
||||
$currency = $this->currency;
|
||||
$lossCoverService = $this->lossCoverService;
|
||||
|
||||
return DB::transaction(function () use ($user, $round, $data, $currency, $lossCoverService): JsonResponse {
|
||||
// 幂等:同一局只能下一注
|
||||
$existing = BaccaratBet::query()
|
||||
->where('round_id', $round->id)
|
||||
->where('user_id', $user->id)
|
||||
->lockForUpdate()
|
||||
->exists();
|
||||
|
||||
if ($existing) {
|
||||
return response()->json(['ok' => false, 'message' => '本局您已下注,请等待开奖。']);
|
||||
}
|
||||
|
||||
// 扣除金币
|
||||
$currency->change(
|
||||
$user,
|
||||
'gold',
|
||||
-$data['amount'],
|
||||
CurrencySource::BACCARAT_BET,
|
||||
"百家乐 #{$round->id} 押 ".match ($data['bet_type']) {
|
||||
'big' => '大', 'small' => '小', default => '豹子'
|
||||
},
|
||||
);
|
||||
|
||||
// 下注时间命中活动窗口时,将本次下注挂到对应的买单活动下。
|
||||
$lossCoverEvent = $lossCoverService->findEventForBetTime(now());
|
||||
|
||||
// 写入下注记录
|
||||
$bet = BaccaratBet::create([
|
||||
'round_id' => $round->id,
|
||||
'user_id' => $user->id,
|
||||
'loss_cover_event_id' => $lossCoverEvent?->id,
|
||||
'bet_type' => $data['bet_type'],
|
||||
'amount' => $data['amount'],
|
||||
'status' => 'pending',
|
||||
]);
|
||||
|
||||
// 命中活动的下注要同步累计到用户活动记录中,便于后续前台查看。
|
||||
$lossCoverService->registerBet($bet);
|
||||
|
||||
// 更新局次汇总统计
|
||||
$field = 'total_bet_'.$data['bet_type'];
|
||||
$countField = 'bet_count_'.$data['bet_type'];
|
||||
$round->increment($field, $data['amount']);
|
||||
$round->increment($countField);
|
||||
$round->increment('bet_count');
|
||||
|
||||
// 广播各选项的最新押注人数
|
||||
event(new \App\Events\BaccaratPoolUpdated($round));
|
||||
|
||||
$betLabel = match ($data['bet_type']) {
|
||||
'big' => '大', 'small' => '小', default => '豹子'
|
||||
};
|
||||
|
||||
// 发送系统传音到聊天室,公示该用户的押注信息
|
||||
$chatState = app(\App\Services\ChatStateService::class);
|
||||
$formattedAmount = number_format($data['amount']);
|
||||
$roomId = $round->room_id ?? 1;
|
||||
|
||||
// 格式:🌟 🎲 娜姐 押注了 119 金币(大)!✨
|
||||
$content = "🎲 <b> 【百家乐】【{$user->username}】</b> 押注了 <b>{$formattedAmount}</b> 金币({$betLabel})!✨";
|
||||
$msg = [
|
||||
'id' => $chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => '系统传音',
|
||||
'to_user' => '大家',
|
||||
'content' => $content,
|
||||
'is_secret' => false,
|
||||
'font_color' => '#d97706',
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
$chatState->pushMessage($roomId, $msg);
|
||||
event(new \App\Events\MessageSent($roomId, $msg));
|
||||
\App\Jobs\SaveMessageJob::dispatch($msg);
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'message' => "✅ 已押注「{$betLabel}」{$data['amount']} 金币,等待开奖!",
|
||||
'amount' => $data['amount'],
|
||||
'bet_type' => $data['bet_type'],
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询最近5局的历史记录(前端展示趋势)。
|
||||
*/
|
||||
public function history(): JsonResponse
|
||||
{
|
||||
$rounds = BaccaratRound::query()
|
||||
->where('status', 'settled')
|
||||
->orderByDesc('id')
|
||||
->limit(10)
|
||||
->get(['id', 'dice1', 'dice2', 'dice3', 'total_points', 'result', 'settled_at']);
|
||||
|
||||
return response()->json(['history' => $rounds]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:百家乐买单活动前台控制器
|
||||
*
|
||||
* 提供活动摘要、历史记录以及用户领取补偿的接口,
|
||||
* 供娱乐大厅弹窗与聊天室系统消息按钮调用。
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\BaccaratLossCoverEvent;
|
||||
use App\Services\BaccaratLossCoverService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BaccaratLossCoverController extends Controller
|
||||
{
|
||||
/**
|
||||
* 注入百家乐买单活动服务。
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly BaccaratLossCoverService $lossCoverService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 返回当前最值得关注的一次活动摘要。
|
||||
*/
|
||||
public function summary(Request $request): JsonResponse
|
||||
{
|
||||
$event = BaccaratLossCoverEvent::query()
|
||||
->with(['creator:id,username'])
|
||||
->whereIn('status', $this->summaryStatuses($request))
|
||||
->orderByRaw($this->summaryStatusOrder($request))
|
||||
->orderByDesc('starts_at')
|
||||
->first();
|
||||
|
||||
$record = null;
|
||||
if ($event) {
|
||||
$record = $event->records()->where('user_id', $request->user()->id)->first();
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'event' => $event ? $this->transformEvent($event, $record) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回最近的活动列表以及当前用户的领取记录。
|
||||
*/
|
||||
public function history(Request $request): JsonResponse
|
||||
{
|
||||
$events = BaccaratLossCoverEvent::query()
|
||||
->with(['creator:id,username', 'records' => function ($query) use ($request) {
|
||||
$query->where('user_id', $request->user()->id);
|
||||
}])
|
||||
->latest('starts_at')
|
||||
->limit(20)
|
||||
->get()
|
||||
->map(function (BaccaratLossCoverEvent $event) {
|
||||
$record = $event->records->first();
|
||||
|
||||
return $this->transformEvent($event, $record);
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'events' => $events,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取指定活动的补偿金币。
|
||||
*/
|
||||
public function claim(Request $request, BaccaratLossCoverEvent $event): JsonResponse
|
||||
{
|
||||
$result = $this->lossCoverService->claim($event, $request->user());
|
||||
|
||||
return response()->json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将活动与个人记录整理为前端更容易消费的结构。
|
||||
*/
|
||||
private function transformEvent(BaccaratLossCoverEvent $event, mixed $record): array
|
||||
{
|
||||
return [
|
||||
'id' => $event->id,
|
||||
'title' => $event->title,
|
||||
'description' => $event->description,
|
||||
'status' => $event->status,
|
||||
'status_label' => $event->statusLabel(),
|
||||
'starts_at' => $event->starts_at?->toIso8601String(),
|
||||
'ends_at' => $event->ends_at?->toIso8601String(),
|
||||
'claim_deadline_at' => $event->claim_deadline_at?->toIso8601String(),
|
||||
'participant_count' => $event->participant_count,
|
||||
'compensable_user_count' => $event->compensable_user_count,
|
||||
'total_loss_amount' => $event->total_loss_amount,
|
||||
'total_claimed_amount' => $event->total_claimed_amount,
|
||||
'creator_username' => $event->creator?->username ?? '管理员',
|
||||
'my_record' => $record ? [
|
||||
'total_bet_amount' => $record->total_bet_amount,
|
||||
'total_win_payout' => $record->total_win_payout,
|
||||
'total_loss_amount' => $record->total_loss_amount,
|
||||
'compensation_amount' => $record->compensation_amount,
|
||||
'claim_status' => $record->claim_status,
|
||||
'claim_status_label' => $record->claimStatusLabel(),
|
||||
'claimed_amount' => $record->claimed_amount,
|
||||
'claimed_at' => $record->claimed_at?->toIso8601String(),
|
||||
] : null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 按调用场景返回活动摘要允许出现的状态集合。
|
||||
*
|
||||
* “当前活动”页签只展示未开始、进行中或结算中的活动,
|
||||
* 避免把已结束但仍可领取的历史活动误显示在当前页签里。
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
private function summaryStatuses(Request $request): array
|
||||
{
|
||||
if ($request->string('scene')->toString() === 'overview') {
|
||||
return ['active', 'settlement_pending', 'scheduled'];
|
||||
}
|
||||
|
||||
return ['active', 'settlement_pending', 'claimable', 'scheduled'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 按调用场景生成活动状态排序规则。
|
||||
*/
|
||||
private function summaryStatusOrder(Request $request): string
|
||||
{
|
||||
if ($request->string('scene')->toString() === 'overview') {
|
||||
return "CASE status WHEN 'active' THEN 0 WHEN 'settlement_pending' THEN 1 WHEN 'scheduled' THEN 2 ELSE 3 END";
|
||||
}
|
||||
|
||||
return "CASE status WHEN 'active' THEN 0 WHEN 'settlement_pending' THEN 1 WHEN 'claimable' THEN 2 WHEN 'scheduled' THEN 3 ELSE 4 END";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:银行控制器
|
||||
*
|
||||
* 提供存款、取款、余额查询三个接口,金币在流通账户(jjb)
|
||||
* 与银行账户(bank_jjb)之间互转,所有操作记录到 bank_logs。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\BankLog;
|
||||
use App\Models\Sysparam;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* 类功能:处理银行余额、存取款和存款排行展示。
|
||||
*/
|
||||
class BankController extends Controller
|
||||
{
|
||||
/**
|
||||
* 查询银行余额及最近20条流水记录
|
||||
*/
|
||||
public function info(): JsonResponse
|
||||
{
|
||||
$user = Auth::user();
|
||||
$logs = BankLog::where('user_id', $user->id)
|
||||
->latest()
|
||||
->limit(20)
|
||||
->get(['type', 'amount', 'balance_after', 'created_at']);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'jjb' => $user->jjb ?? 0,
|
||||
'bank_jjb' => $user->bank_jjb ?? 0,
|
||||
'logs' => $logs,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询银行存款排行榜 (分页显示)
|
||||
*/
|
||||
public function ranking(Request $request): JsonResponse
|
||||
{
|
||||
/** @var User $operator */
|
||||
$operator = Auth::user();
|
||||
$direction = strtolower($request->query('sort', 'desc')) === 'asc' ? 'asc' : 'desc';
|
||||
|
||||
$users = User::where('bank_jjb', '>', 0)
|
||||
->orderBy('bank_jjb', $direction)
|
||||
->paginate(20, ['id', 'username', 'bank_jjb', 'sex', 'usersf', 'user_level']);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'ranking' => $users->map(function (User $u) use ($operator) {
|
||||
$canViewBalance = $this->canViewBankBalance($operator, $u);
|
||||
|
||||
// 提供必要的前端展示字段,普通用户查看别人存款时只返回星号,防止前端绕过遮罩。
|
||||
return [
|
||||
'id' => $u->id,
|
||||
'username' => $u->username,
|
||||
'bank_jjb' => $canViewBalance ? ($u->bank_jjb ?? 0) : '******',
|
||||
'bank_jjb_masked' => ! $canViewBalance,
|
||||
'can_reveal' => ! $canViewBalance,
|
||||
'reveal_cost' => UserController::INFO_REVEAL_COST,
|
||||
'sex' => $u->sex,
|
||||
'usersf' => $u->usersf,
|
||||
'user_level' => $u->user_level,
|
||||
'headfaceUrl' => $u->headfaceUrl,
|
||||
];
|
||||
}),
|
||||
'pagination' => [
|
||||
'current_page' => $users->currentPage(),
|
||||
'last_page' => $users->lastPage(),
|
||||
'total' => $users->total(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 存款:从流通金币(jjb)转入银行(bank_jjb)
|
||||
*
|
||||
* 请求参数:amount(正整数)
|
||||
*/
|
||||
public function deposit(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'amount' => 'required|integer|min:1|max:9999999',
|
||||
]);
|
||||
|
||||
$amount = $request->integer('amount');
|
||||
$user = Auth::user();
|
||||
|
||||
if (($user->jjb ?? 0) < $amount) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => '流通金币不足!当前余额 '.($user->jjb ?? 0)." 枚,无法存入 {$amount} 枚。",
|
||||
]);
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($user, $amount): void {
|
||||
$user->decrement('jjb', $amount);
|
||||
$user->increment('bank_jjb', $amount);
|
||||
|
||||
BankLog::create([
|
||||
'user_id' => $user->id,
|
||||
'type' => 'deposit',
|
||||
'amount' => $amount,
|
||||
'balance_after' => $user->fresh()->bank_jjb,
|
||||
]);
|
||||
});
|
||||
|
||||
$fresh = $user->fresh();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => "成功存入 {$amount} 枚金币!",
|
||||
'jjb' => $fresh->jjb,
|
||||
'bank_jjb' => $fresh->bank_jjb,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 取款:从银行(bank_jjb)转回流通金币(jjb)
|
||||
*
|
||||
* 请求参数:amount(正整数)
|
||||
*/
|
||||
public function withdraw(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'amount' => 'required|integer|min:1|max:9999999',
|
||||
]);
|
||||
|
||||
$amount = $request->integer('amount');
|
||||
$user = Auth::user();
|
||||
|
||||
if (($user->bank_jjb ?? 0) < $amount) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => '银行余额不足!当前存款 '.($user->bank_jjb ?? 0)." 枚,无法取出 {$amount} 枚。",
|
||||
]);
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($user, $amount): void {
|
||||
$user->decrement('bank_jjb', $amount);
|
||||
$user->increment('jjb', $amount);
|
||||
|
||||
BankLog::create([
|
||||
'user_id' => $user->id,
|
||||
'type' => 'withdraw',
|
||||
'amount' => $amount,
|
||||
'balance_after' => $user->fresh()->bank_jjb,
|
||||
]);
|
||||
});
|
||||
|
||||
$fresh = $user->fresh();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => "成功取出 {$amount} 枚金币!",
|
||||
'jjb' => $fresh->jjb,
|
||||
'bank_jjb' => $fresh->bank_jjb,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断操作者是否可以免费查看目标用户银行存款。
|
||||
*/
|
||||
private function canViewBankBalance(User $operator, User $targetUser): bool
|
||||
{
|
||||
if ($operator->id === $targetUser->id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$superLevel = (int) Sysparam::getValue('superlevel', '100');
|
||||
|
||||
return (int) $operator->user_level >= $superLevel;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:开发日志前台控制器
|
||||
* 对应独立页面 /changelog,展示已发布的版本更新日志
|
||||
* 支持懒加载(IntersectionObserver + 游标分页)
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\DevChangelog;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ChangelogController extends Controller
|
||||
{
|
||||
/** 每次加载的条数 */
|
||||
private const PAGE_SIZE = 10;
|
||||
|
||||
/**
|
||||
* 更新日志列表页(SSR首屏)
|
||||
* 预加载最新 10 条已发布日志
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
$changelogs = DevChangelog::published()
|
||||
->limit(self::PAGE_SIZE)
|
||||
->get();
|
||||
|
||||
return view('changelog.index', compact('changelogs'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 懒加载更多日志(JSON API)
|
||||
* 游标分页:传入已加载的最后一条 ID,返回更旧的 10 条
|
||||
*
|
||||
* @param Request $request 含 after_id 参数
|
||||
*/
|
||||
public function loadMoreChangelogs(Request $request): JsonResponse
|
||||
{
|
||||
$afterId = (int) $request->input('after_id', PHP_INT_MAX);
|
||||
|
||||
$items = DevChangelog::published()
|
||||
->after($afterId)
|
||||
->limit(self::PAGE_SIZE)
|
||||
->get();
|
||||
|
||||
$data = $items->map(fn (DevChangelog $log) => [
|
||||
'id' => $log->id,
|
||||
'version' => $log->version,
|
||||
'title' => $log->title,
|
||||
'type_label' => $log->type_label,
|
||||
'type_color' => $log->type_color,
|
||||
'content_html' => $log->content_html,
|
||||
'summary' => $log->summary,
|
||||
'published_at' => $log->published_at?->format('Y-m-d'),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'items' => $data,
|
||||
'has_more' => $items->count() === self::PAGE_SIZE,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:聊天室内快速任命/撤销控制器
|
||||
* 供有职务的管理员在聊天室用户名片弹窗中快速任命或撤销目标用户的职务。
|
||||
* 权限校验委托给 AppointmentService,本控制器只做请求解析和返回 JSON。
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\AppointmentAnnounced;
|
||||
use App\Events\MessageSent;
|
||||
use App\Events\UserBrowserRefreshRequested;
|
||||
use App\Jobs\SaveMessageJob;
|
||||
use App\Models\Position;
|
||||
use App\Models\User;
|
||||
use App\Services\AppointmentService;
|
||||
use App\Services\ChatStateService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ChatAppointmentController extends Controller
|
||||
{
|
||||
/**
|
||||
* 注入任命服务
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly AppointmentService $appointmentService,
|
||||
private readonly ChatStateService $chatState,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 获取可用职务列表(供名片弹窗下拉选择)
|
||||
* 返回操作人有权限任命的职务
|
||||
*/
|
||||
public function positions(): JsonResponse
|
||||
{
|
||||
$operator = Auth::user();
|
||||
$superLevel = (int) \App\Models\Sysparam::getValue('superlevel', '100');
|
||||
$operatorPosition = $operator->activePosition?->position;
|
||||
|
||||
$query = Position::query()
|
||||
->with('department')
|
||||
->orderByDesc('rank');
|
||||
|
||||
// 仅有具体职务(非 superlevel 直通)的操作人才限制 rank 范围
|
||||
if ($operatorPosition && $operator->user_level < $superLevel) {
|
||||
$query->where('rank', '<', $operatorPosition->rank);
|
||||
}
|
||||
|
||||
$positions = $query->get()->map(fn ($p) => [
|
||||
'id' => $p->id,
|
||||
'name' => $p->name,
|
||||
'icon' => $p->icon,
|
||||
'rank' => $p->rank,
|
||||
'department' => $p->department?->name,
|
||||
]);
|
||||
|
||||
return response()->json(['status' => 'success', 'positions' => $positions]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速任命:将目标用户任命为指定职务
|
||||
* 成功后向操作人所在聊天室广播任命公告
|
||||
*/
|
||||
public function appoint(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'username' => 'required|string|exists:users,username',
|
||||
'position_id' => 'required|exists:positions,id',
|
||||
'remark' => 'nullable|string|max:100',
|
||||
'room_id' => 'nullable|integer|exists:rooms,id',
|
||||
]);
|
||||
|
||||
$operator = Auth::user();
|
||||
$target = User::where('username', $request->username)->firstOrFail();
|
||||
$position = Position::with('department')->findOrFail($request->position_id);
|
||||
|
||||
$result = $this->appointmentService->appoint($operator, $target, $position, $request->remark);
|
||||
|
||||
// 任命成功后广播礼花通知:优先用前端传来的 room_id,否则从 Redis 查操作人所在房间
|
||||
if ($result['ok']) {
|
||||
$roomId = $request->integer('room_id') ?: ($this->chatState->getUserRooms($operator->username)[0] ?? null);
|
||||
if ($roomId) {
|
||||
broadcast(new AppointmentAnnounced(
|
||||
roomId: (int) $roomId,
|
||||
targetUsername: $target->username,
|
||||
positionIcon: $position->icon ?? '🎖️',
|
||||
positionName: $position->name,
|
||||
departmentName: $position->department?->name ?? '',
|
||||
operatorName: $operator->username,
|
||||
));
|
||||
|
||||
// 给被任命用户补一条私聊提示,并复用右下角 toast 通知。
|
||||
$this->pushTargetToastMessage(
|
||||
roomId: (int) $roomId,
|
||||
targetUsername: $target->username,
|
||||
content: "✨ <b>{$operator->username}</b> 已任命你为 {$position->icon} {$position->name}。",
|
||||
title: '✨ 职务任命通知',
|
||||
toastMessage: "<b>{$operator->username}</b> 已任命你为 <b>{$position->icon} {$position->name}</b>。",
|
||||
color: '#a855f7',
|
||||
icon: '✨',
|
||||
);
|
||||
}
|
||||
|
||||
// 任命成功后,通知目标用户刷新页面,及时同步输入框上方的管理按钮与权限状态。
|
||||
broadcast(new UserBrowserRefreshRequested(
|
||||
targetUserId: (int) $target->id,
|
||||
operator: $operator->username,
|
||||
reason: '你的职务已发生变更,页面权限正在同步更新。',
|
||||
));
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => $result['ok'] ? 'success' : 'error',
|
||||
'message' => $result['message'],
|
||||
], $result['ok'] ? 200 : 422);
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速撤销:撤销目标用户当前的职务
|
||||
*/
|
||||
public function revoke(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'username' => 'required|string|exists:users,username',
|
||||
'remark' => 'nullable|string|max:100',
|
||||
'room_id' => 'nullable|integer|exists:rooms,id',
|
||||
]);
|
||||
|
||||
$operator = Auth::user();
|
||||
$target = User::where('username', $request->username)->firstOrFail();
|
||||
|
||||
// 撤销前先取目标当前职务信息(撤销后就查不到了)
|
||||
$activeUp = $target->activePosition?->load('position.department');
|
||||
$posIcon = $activeUp?->position?->icon ?? '🎖️';
|
||||
$posName = $activeUp?->position?->name ?? '';
|
||||
$deptName = $activeUp?->position?->department?->name ?? '';
|
||||
|
||||
$result = $this->appointmentService->revoke($operator, $target, $request->remark);
|
||||
|
||||
// 撤销成功后广播通知到聊天室
|
||||
if ($result['ok'] && $posName) {
|
||||
$roomId = $request->integer('room_id') ?: ($this->chatState->getUserRooms($operator->username)[0] ?? null);
|
||||
if ($roomId) {
|
||||
broadcast(new AppointmentAnnounced(
|
||||
roomId: (int) $roomId,
|
||||
targetUsername: $target->username,
|
||||
positionIcon: $posIcon,
|
||||
positionName: $posName,
|
||||
departmentName: $deptName,
|
||||
operatorName: $operator->username,
|
||||
type: 'revoke',
|
||||
));
|
||||
|
||||
// 给被撤职用户补一条私聊提示,并复用右下角 toast 通知。
|
||||
$this->pushTargetToastMessage(
|
||||
roomId: (int) $roomId,
|
||||
targetUsername: $target->username,
|
||||
content: "📋 <b>{$operator->username}</b> 已撤销你的 {$posIcon} {$posName} 职务。",
|
||||
title: '📋 职务变动通知',
|
||||
toastMessage: "<b>{$operator->username}</b> 已撤销你的 <b>{$posIcon} {$posName}</b> 职务。",
|
||||
color: '#6b7280',
|
||||
icon: '📋',
|
||||
);
|
||||
}
|
||||
|
||||
// 撤职成功后,同步通知目标用户刷新页面,移除已失效的管理入口和权限按钮。
|
||||
broadcast(new UserBrowserRefreshRequested(
|
||||
targetUserId: (int) $target->id,
|
||||
operator: $operator->username,
|
||||
reason: '你的职务已被撤销,页面权限正在同步更新。',
|
||||
));
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => $result['ok'] ? 'success' : 'error',
|
||||
'message' => $result['message'],
|
||||
], $result['ok'] ? 200 : 422);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向目标用户补发一条系统私聊消息,并附带右下角 toast 配置。
|
||||
*/
|
||||
private function pushTargetToastMessage(
|
||||
int $roomId,
|
||||
string $targetUsername,
|
||||
string $content,
|
||||
string $title,
|
||||
string $toastMessage,
|
||||
string $color,
|
||||
string $icon,
|
||||
): void {
|
||||
$msg = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => '系统',
|
||||
'to_user' => $targetUsername,
|
||||
'content' => $content,
|
||||
'is_secret' => true,
|
||||
'font_color' => $color,
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
// 复用现有聊天 toast 机制,在右下角弹出职务变动提示。
|
||||
'toast_notification' => [
|
||||
'title' => $title,
|
||||
'message' => $toastMessage,
|
||||
'icon' => $icon,
|
||||
'color' => $color,
|
||||
'duration' => 10000,
|
||||
],
|
||||
];
|
||||
|
||||
$this->chatState->pushMessage($roomId, $msg);
|
||||
broadcast(new MessageSent($roomId, $msg));
|
||||
SaveMessageJob::dispatch($msg);
|
||||
}
|
||||
}
|
||||
@@ -13,15 +13,22 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\CurrencySource;
|
||||
use App\Events\MessageSent;
|
||||
use App\Jobs\SaveMessageJob;
|
||||
use App\Models\Sysparam;
|
||||
use App\Services\AiChatService;
|
||||
use App\Services\AiFinanceService;
|
||||
use App\Services\ChatStateService;
|
||||
use App\Services\UserCurrencyService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
/**
|
||||
* 处理用户与 AI小班长的对话、金币福利与上下文清理。
|
||||
*/
|
||||
class ChatBotController extends Controller
|
||||
{
|
||||
/**
|
||||
@@ -30,6 +37,8 @@ class ChatBotController extends Controller
|
||||
public function __construct(
|
||||
private readonly AiChatService $aiChat,
|
||||
private readonly ChatStateService $chatState,
|
||||
private readonly UserCurrencyService $currencyService,
|
||||
private readonly AiFinanceService $aiFinance,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -47,8 +56,12 @@ class ChatBotController extends Controller
|
||||
$request->validate([
|
||||
'message' => 'required|string|max:2000',
|
||||
'room_id' => 'required|integer',
|
||||
'is_secret' => 'nullable|boolean',
|
||||
]);
|
||||
|
||||
// 私聊模式:AI 回复也走悄悄话,仅发言人和 AI 可见
|
||||
$isSecret = (bool) $request->input('is_secret', false);
|
||||
|
||||
// 检查全局开关
|
||||
$enabled = Sysparam::getValue('chatbot_enabled', '0');
|
||||
if ($enabled !== '1') {
|
||||
@@ -58,37 +71,95 @@ class ChatBotController extends Controller
|
||||
], 403);
|
||||
}
|
||||
|
||||
$aiUser = \App\Models\User::where('username', 'AI小班长')->first();
|
||||
if ($aiUser) {
|
||||
$aiUser->increment('exp_num', 1);
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
$message = $request->input('message');
|
||||
$roomId = $request->input('room_id');
|
||||
|
||||
try {
|
||||
// 先广播用户的提问消息
|
||||
$userMsg = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => $user->username,
|
||||
'to_user' => 'AI小班长',
|
||||
'content' => $message,
|
||||
'is_secret' => false,
|
||||
'font_color' => '#000000',
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
$this->chatState->pushMessage($roomId, $userMsg);
|
||||
broadcast(new MessageSent($roomId, $userMsg));
|
||||
SaveMessageJob::dispatch($userMsg);
|
||||
|
||||
$result = $this->aiChat->chat($user->id, $message, $roomId);
|
||||
|
||||
// 广播 AI 回复消息
|
||||
$reply = $result['reply'];
|
||||
|
||||
// 检查 AI 是否决定给用户发金币
|
||||
if (str_contains($reply, '[ACTION:GIVE_GOLD]')) {
|
||||
$reply = str_replace('[ACTION:GIVE_GOLD]', '', $reply);
|
||||
$reply = trim($reply);
|
||||
|
||||
$maxDailyRewards = (int) Sysparam::getValue('chatbot_max_daily_rewards', '1');
|
||||
$maxGold = (int) Sysparam::getValue('chatbot_max_gold', '5000');
|
||||
|
||||
$redisKey = 'ai_chat:give_gold:'.date('Ymd').':'.$user->id;
|
||||
$dailyCount = (int) Redis::get($redisKey);
|
||||
|
||||
if ($dailyCount < $maxDailyRewards) {
|
||||
$goldAmount = rand(100, $maxGold);
|
||||
|
||||
// 常规发福利只检查 AI 当前手上金币,不再为了维持 100 万而自动从银行提钱。
|
||||
if ($aiUser && $this->aiFinance->prepareSpend($aiUser, $goldAmount)) {
|
||||
Redis::incr($redisKey);
|
||||
Redis::expire($redisKey, 86400); // 缓存 24 小时
|
||||
|
||||
// 真实扣除 AI 金币
|
||||
$this->currencyService->change(
|
||||
$aiUser,
|
||||
'gold',
|
||||
-$goldAmount,
|
||||
CurrencySource::GIFT_SENT,
|
||||
"赏赐给 {$user->username} 的金币福利",
|
||||
$roomId
|
||||
);
|
||||
|
||||
// 给用户发放金币
|
||||
$this->currencyService->change(
|
||||
$user,
|
||||
'gold',
|
||||
$goldAmount,
|
||||
CurrencySource::AI_GIFT,
|
||||
'AI小班长发善心赠送的金币福利',
|
||||
$roomId
|
||||
);
|
||||
|
||||
// 发送全场大广播
|
||||
$sysMsg = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => 'AI小班长',
|
||||
'to_user' => $user->username,
|
||||
'content' => "🤖 听闻小萌新哭穷,本班长看你骨骼惊奇,大方地赏赐了 {$goldAmount} 枚金币福利!",
|
||||
'is_secret' => false,
|
||||
'font_color' => '#d97706', // 橙色醒目
|
||||
'action' => '大声宣告',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
$this->chatState->pushMessage($roomId, $sysMsg);
|
||||
broadcast(new MessageSent($roomId, $sysMsg));
|
||||
SaveMessageJob::dispatch($sysMsg);
|
||||
|
||||
// 福利发放完成后,若手上金币仍高于 100 万,则把超出的部分回存银行。
|
||||
$this->aiFinance->bankExcessGold($aiUser);
|
||||
} else {
|
||||
// 如果余额不足
|
||||
$reply .= "\n\n(哎呀,我这个月的工资花光啦,没钱发金币了,大家多赏点吧~)";
|
||||
}
|
||||
} else {
|
||||
// 如果已经领过了,修改回复提醒
|
||||
$reply .= "\n\n(系统提示:你今天已经领过金币福利啦,把机会留给其他人吧!)";
|
||||
}
|
||||
}
|
||||
|
||||
// 广播 AI 回复消息(私聊模式下仅发言人与 AI 可见)
|
||||
$botMsg = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => 'AI小班长',
|
||||
'to_user' => $user->username,
|
||||
'content' => $result['reply'],
|
||||
'is_secret' => false,
|
||||
'content' => $reply,
|
||||
'is_secret' => $isSecret,
|
||||
'font_color' => '#16a34a',
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,305 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:前台每日签到控制器
|
||||
*
|
||||
* 提供签到状态查询、领取奖励、刷新在线名单载荷和聊天室签到通知。
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\MessageSent;
|
||||
use App\Events\UserStatusUpdated;
|
||||
use App\Http\Requests\ClaimDailySignInRequest;
|
||||
use App\Http\Requests\DailySignInCalendarRequest;
|
||||
use App\Http\Requests\MakeupDailySignInRequest;
|
||||
use App\Models\DailySignIn;
|
||||
use App\Models\User;
|
||||
use App\Models\UserIdentityBadge;
|
||||
use App\Services\ChatStateService;
|
||||
use App\Services\ChatUserPresenceService;
|
||||
use App\Services\SignInService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* 类功能:处理前台用户每日签到状态与领取奖励流程。
|
||||
*/
|
||||
class DailySignInController extends Controller
|
||||
{
|
||||
/**
|
||||
* 构造每日签到控制器依赖。
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly SignInService $signInService,
|
||||
private readonly ChatStateService $chatState,
|
||||
private readonly ChatUserPresenceService $presenceService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 方法功能:查询当前用户今日签到状态和奖励预览。
|
||||
*/
|
||||
public function status(): JsonResponse
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
$status = $this->signInService->status($user);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'data' => $this->formatStatusPayload($user, $status),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:查询指定月份的签到日历与补签卡状态。
|
||||
*/
|
||||
public function calendar(DailySignInCalendarRequest $request): JsonResponse
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'data' => $this->signInService->calendar($user, $request->validated('month')),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:领取今日签到奖励并同步聊天室在线名单。
|
||||
*/
|
||||
public function claim(ClaimDailySignInRequest $request): JsonResponse
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
$roomId = $request->validated('room_id');
|
||||
$roomId = $roomId === null ? null : (int) $roomId;
|
||||
|
||||
$dailySignIn = $this->signInService->claim($user, $roomId);
|
||||
if (! $dailySignIn->wasRecentlyCreated) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => '今日已签到,请明天再来。',
|
||||
'data' => $this->formatClaimPayload($user->fresh(), $dailySignIn),
|
||||
], 422);
|
||||
}
|
||||
|
||||
$freshUser = $user->fresh(['vipLevel', 'activePosition.position.department']);
|
||||
$presencePayload = $this->presenceService->build($freshUser);
|
||||
$this->refreshOnlinePresence($freshUser, $presencePayload);
|
||||
|
||||
if ($roomId !== null && $this->chatState->isUserInRoom($roomId, $freshUser->username)) {
|
||||
$this->broadcastSignInNotice($freshUser, $dailySignIn, $roomId);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => $this->buildSuccessMessage($dailySignIn),
|
||||
'data' => $this->formatClaimPayload($freshUser, $dailySignIn, $presencePayload),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:使用补签卡补签历史漏签日期。
|
||||
*/
|
||||
public function makeup(MakeupDailySignInRequest $request): JsonResponse
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
$roomId = $request->validated('room_id');
|
||||
$roomId = $roomId === null ? null : (int) $roomId;
|
||||
|
||||
$dailySignIn = $this->signInService->makeup($user, (string) $request->validated('target_date'), $roomId);
|
||||
$refreshedSignIn = $dailySignIn->fresh();
|
||||
$latestSignIn = DailySignIn::query()
|
||||
->where('user_id', $user->id)
|
||||
->latest('sign_in_date')
|
||||
->first();
|
||||
$currentStreakDays = (int) ($latestSignIn?->streak_days ?? $refreshedSignIn?->streak_days ?? 0);
|
||||
|
||||
$freshUser = $user->fresh(['vipLevel', 'activePosition.position.department']);
|
||||
$presencePayload = $this->presenceService->build($freshUser);
|
||||
$this->refreshOnlinePresence($freshUser, $presencePayload);
|
||||
|
||||
if ($roomId !== null && $this->chatState->isUserInRoom($roomId, $freshUser->username)) {
|
||||
$this->broadcastSignInNotice($freshUser, $refreshedSignIn, $roomId, $currentStreakDays);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => '补签成功,'.$refreshedSignIn?->sign_in_date?->format('Y-m-d').' 已补签,当前连续签到 '.$currentStreakDays.' 天。',
|
||||
'data' => $this->formatClaimPayload($freshUser, $refreshedSignIn, $presencePayload, $currentStreakDays),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:刷新用户当前所在房间的 Redis 在线载荷并广播名单更新。
|
||||
*
|
||||
* @param array<string, mixed> $presencePayload
|
||||
*/
|
||||
private function refreshOnlinePresence(User $user, array $presencePayload): void
|
||||
{
|
||||
foreach ($this->chatState->getUserRooms($user->username) as $activeRoomId) {
|
||||
// 签到身份会展示在在线名单里,必须立即回写 Redis 载荷。
|
||||
$this->chatState->userJoin((int) $activeRoomId, $user->username, $presencePayload);
|
||||
broadcast(new UserStatusUpdated((int) $activeRoomId, $user->username, $presencePayload));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:向当前聊天室广播签到成功通知。
|
||||
*/
|
||||
private function broadcastSignInNotice(User $user, DailySignIn $dailySignIn, int $roomId, ?int $currentStreakDays = null): void
|
||||
{
|
||||
$message = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => '签到播报',
|
||||
'to_user' => '大家',
|
||||
'content' => $this->buildNoticeContent($user, $dailySignIn, $currentStreakDays),
|
||||
'is_secret' => false,
|
||||
'font_color' => '#0f766e',
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
$this->chatState->pushMessage($roomId, $message);
|
||||
broadcast(new MessageSent($roomId, $message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:生成聊天室内的签到播报内容。
|
||||
*/
|
||||
private function buildNoticeContent(User $user, DailySignIn $dailySignIn, ?int $currentStreakDays = null): string
|
||||
{
|
||||
$rewardText = $this->buildRewardText($dailySignIn);
|
||||
$identityText = $dailySignIn->identity_badge_name
|
||||
? ',获得身份 '.e($dailySignIn->identity_badge_name)
|
||||
: '';
|
||||
|
||||
if ($dailySignIn->is_makeup) {
|
||||
$signInDate = $dailySignIn->sign_in_date?->format('Y-m-d') ?? '漏签日期';
|
||||
$streakDays = $currentStreakDays ?? (int) $dailySignIn->streak_days;
|
||||
|
||||
return '【'.e($user->username).'】使用补签卡补签 '.$signInDate
|
||||
.',当前连续签到 '.$streakDays.' 天,获得 '.$rewardText.$identityText.'。';
|
||||
}
|
||||
|
||||
$quickButton = '<button type="button" onclick="window.quickDailySignIn && window.quickDailySignIn()" '
|
||||
.'style="display:inline-block;margin-left:6px;padding:1px 8px;border:none;border-radius:999px;'
|
||||
.'background:#ccfbf1;color:#0f766e;font-size:10px;font-weight:bold;cursor:pointer;vertical-align:middle;">'
|
||||
.'✅ 快速签到</button>';
|
||||
|
||||
return '【'.e($user->username).'】完成今日签到,连续签到 '
|
||||
.$dailySignIn->streak_days.' 天,获得 '.$rewardText.$identityText.'。'.$quickButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:生成本机签到成功提示文案。
|
||||
*/
|
||||
private function buildSuccessMessage(DailySignIn $dailySignIn): string
|
||||
{
|
||||
return '签到成功,连续签到 '.$dailySignIn->streak_days.' 天,获得 '.$this->buildRewardText($dailySignIn).'。';
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:按实际签到奖励快照生成奖励描述。
|
||||
*/
|
||||
private function buildRewardText(DailySignIn $dailySignIn): string
|
||||
{
|
||||
$items = [];
|
||||
if ($dailySignIn->gold_reward > 0) {
|
||||
$items[] = $dailySignIn->gold_reward.' 金币';
|
||||
}
|
||||
if ($dailySignIn->exp_reward > 0) {
|
||||
$items[] = $dailySignIn->exp_reward.' 经验';
|
||||
}
|
||||
if ($dailySignIn->charm_reward > 0) {
|
||||
$items[] = $dailySignIn->charm_reward.' 魅力';
|
||||
}
|
||||
|
||||
return $items === [] ? '签到记录' : implode(' + ', $items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:格式化状态查询响应载荷。
|
||||
*
|
||||
* @param array<string, mixed> $status
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function formatStatusPayload(User $user, array $status): array
|
||||
{
|
||||
return [
|
||||
'signed_today' => $status['signed_today'],
|
||||
'can_claim' => $status['can_claim'],
|
||||
'current_streak_days' => $status['current_streak_days'],
|
||||
'claimable_streak_days' => $status['claimable_streak_days'],
|
||||
'preview_rule' => $status['matched_rule']?->only([
|
||||
'streak_days',
|
||||
'gold_reward',
|
||||
'exp_reward',
|
||||
'charm_reward',
|
||||
'identity_badge_name',
|
||||
'identity_badge_icon',
|
||||
'identity_badge_color',
|
||||
'identity_duration_days',
|
||||
]),
|
||||
'identity' => $this->formatIdentityPayload($status['current_identity']),
|
||||
'user' => [
|
||||
'jjb' => (int) $user->jjb,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:格式化签到领取响应载荷。
|
||||
*
|
||||
* @param array<string, mixed>|null $presencePayload
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function formatClaimPayload(User $user, DailySignIn $dailySignIn, ?array $presencePayload = null, ?int $currentStreakDays = null): array
|
||||
{
|
||||
$identity = $user->currentSignInIdentity();
|
||||
|
||||
return [
|
||||
'sign_in' => [
|
||||
'id' => $dailySignIn->id,
|
||||
'sign_in_date' => $dailySignIn->sign_in_date?->toDateString(),
|
||||
'is_makeup' => (bool) $dailySignIn->is_makeup,
|
||||
'streak_days' => (int) $dailySignIn->streak_days,
|
||||
'gold_reward' => (int) $dailySignIn->gold_reward,
|
||||
'exp_reward' => (int) $dailySignIn->exp_reward,
|
||||
'charm_reward' => (int) $dailySignIn->charm_reward,
|
||||
],
|
||||
'current_streak_days' => $currentStreakDays ?? (int) $dailySignIn->streak_days,
|
||||
'identity' => $this->formatIdentityPayload($identity),
|
||||
'presence' => $presencePayload ?? $this->presenceService->build($user),
|
||||
'user' => [
|
||||
'jjb' => (int) $user->jjb,
|
||||
'gold' => (int) $user->jjb,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 方法功能:格式化签到身份数据供前端展示。
|
||||
*
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
private function formatIdentityPayload(?UserIdentityBadge $identity): ?array
|
||||
{
|
||||
if ($identity === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'key' => $identity->badge_code,
|
||||
'label' => $identity->badge_name,
|
||||
'name' => $identity->badge_name,
|
||||
'icon' => $identity->badge_icon ?? '✅',
|
||||
'color' => $identity->badge_color ?? '#0f766e',
|
||||
'expires_at' => $identity->expires_at?->toIso8601String(),
|
||||
'streak_days' => (int) data_get($identity->metadata, 'streak_days', 0),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 文件功能:勤务台页面控制器
|
||||
* 左侧五个子菜单:任职列表、日榜、周榜、月榜、总榜
|
||||
* 路由:GET /duty-hall?tab=roster|day|week|month|all
|
||||
*
|
||||
* 榜单统计三项指标:
|
||||
* 1. 在线时长 — position_duty_logs.duration_seconds 合计
|
||||
* 2. 管理操作次数 — position_authority_logs 非任免类操作次数(warn/kick/mute/banip/other)
|
||||
* 3. 奖励金币次数 — position_authority_logs WHERE action_type='reward' 的次数及累计金额
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.2.0
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Department;
|
||||
use App\Models\PositionAuthorityLog;
|
||||
use App\Models\PositionDutyLog;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DutyHallController extends Controller
|
||||
{
|
||||
/**
|
||||
* 勤务台主页(根据 tab 切换内容)
|
||||
*/
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$tab = $request->input('tab', 'roster');
|
||||
|
||||
// ── 任职列表:按部门→职务展示全部(含空缺) ──────────────────
|
||||
$currentStaff = null;
|
||||
if ($tab === 'roster') {
|
||||
$currentStaff = Department::query()
|
||||
->with([
|
||||
'positions' => fn ($q) => $q->orderByDesc('rank'),
|
||||
'positions.activeUserPositions.user',
|
||||
])
|
||||
->orderByDesc('rank')
|
||||
->get();
|
||||
}
|
||||
|
||||
// ── 日/周/月/总榜:三项指标综合排行 ─────────────────────────
|
||||
$leaderboard = null;
|
||||
if (in_array($tab, ['day', 'week', 'month', 'all'])) {
|
||||
|
||||
// ① 在线时长(position_duty_logs)
|
||||
$dutyQuery = PositionDutyLog::query()
|
||||
->selectRaw('user_id, SUM(duration_seconds) as total_seconds, COUNT(*) as checkin_count')
|
||||
// 只统计有离开时间的已完结记录,open session 不计入(防止实时计算偏差)
|
||||
->whereNotNull('logout_at');
|
||||
|
||||
// ② 管理操作(position_authority_logs,排除任命/撤销等人事操作)
|
||||
$authQuery = PositionAuthorityLog::query()
|
||||
->selectRaw('
|
||||
user_id,
|
||||
COUNT(*) as admin_count,
|
||||
SUM(CASE WHEN action_type = \'reward\' THEN 1 ELSE 0 END) as reward_count,
|
||||
SUM(CASE WHEN action_type = \'reward\' THEN COALESCE(amount, 0) ELSE 0 END) as reward_total
|
||||
')
|
||||
->whereNotIn('action_type', ['appoint', 'revoke']);
|
||||
|
||||
// 按时间段同步过滤两张表
|
||||
match ($tab) {
|
||||
'day' => [
|
||||
$dutyQuery->whereDate('login_at', today()),
|
||||
$authQuery->whereDate('created_at', today()),
|
||||
],
|
||||
'week' => [
|
||||
$dutyQuery->whereBetween('login_at', [now()->startOfWeek(), now()->endOfWeek()]),
|
||||
$authQuery->whereBetween('created_at', [now()->startOfWeek(), now()->endOfWeek()]),
|
||||
],
|
||||
'month' => [
|
||||
$dutyQuery->whereYear('login_at', now()->year)->whereMonth('login_at', now()->month),
|
||||
$authQuery->whereYear('created_at', now()->year)->whereMonth('created_at', now()->month),
|
||||
],
|
||||
'all' => null, // 不限制时间
|
||||
};
|
||||
|
||||
// 执行查询
|
||||
$dutyRows = $dutyQuery
|
||||
->groupBy('user_id')
|
||||
->orderByDesc('total_seconds')
|
||||
->limit(20)
|
||||
->with('user')
|
||||
->get();
|
||||
|
||||
// 管理操作数据(按 user_id 索引,方便后续合并)
|
||||
$authMap = $authQuery
|
||||
->groupBy('user_id')
|
||||
->get()
|
||||
->keyBy('user_id');
|
||||
|
||||
// 合并两表数据:为每条勤务记录附加管理操作指标
|
||||
$leaderboard = $dutyRows->map(function ($row) use ($authMap) {
|
||||
$auth = $authMap->get($row->user_id);
|
||||
$row->admin_count = (int) ($auth?->admin_count ?? 0);
|
||||
$row->reward_count = (int) ($auth?->reward_count ?? 0);
|
||||
$row->reward_total = (int) ($auth?->reward_total ?? 0);
|
||||
|
||||
return $row;
|
||||
});
|
||||
}
|
||||
|
||||
// 各榜标签配置
|
||||
$tabs = [
|
||||
'roster' => ['label' => '任职列表', 'icon' => '🏛️'],
|
||||
'day' => ['label' => '日榜', 'icon' => '☀️'],
|
||||
'week' => ['label' => '周榜', 'icon' => '📆'],
|
||||
'month' => ['label' => '月榜', 'icon' => '🗓️'],
|
||||
'all' => ['label' => '总榜', 'icon' => '🏆'],
|
||||
];
|
||||
|
||||
return view('duty-hall.index', compact(
|
||||
'tab',
|
||||
'tabs',
|
||||
'currentStaff',
|
||||
'leaderboard',
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Enums\CurrencySource;
|
||||
use App\Events\MessageSent;
|
||||
use App\Models\User;
|
||||
use App\Services\ChatStateService;
|
||||
use App\Services\UserCurrencyService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
/**
|
||||
* 文件功能:用户赚取金币与经验(观看视频广告等任务)控制器
|
||||
*
|
||||
* @author ChatRoom Laravel
|
||||
*
|
||||
* @version 1.0.0
|
||||
*/
|
||||
class EarnController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private readonly ChatStateService $chatState,
|
||||
private readonly UserCurrencyService $currencyService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @var int 每日观看最大次数限制
|
||||
*/
|
||||
private int $maxDailyLimit = 3;
|
||||
|
||||
/**
|
||||
* @var int 每次领奖后至少需要的冷却时间(秒)
|
||||
*/
|
||||
private int $cooldownSeconds = 5;
|
||||
|
||||
/**
|
||||
* 申领看视频的奖励
|
||||
* 成功看完视频后前端发起此请求。
|
||||
* 为防止刷包,必须加上每日总次数及短时频率限制。
|
||||
*/
|
||||
public function claimVideoReward(Request $request): JsonResponse
|
||||
{
|
||||
/** @var User $user */
|
||||
$user = Auth::user();
|
||||
|
||||
$userId = $user->id;
|
||||
$dateKey = now()->format('Y-m-d');
|
||||
|
||||
$dailyCountKey = "earn_video:count:{$userId}:{$dateKey}";
|
||||
$cooldownKey = "earn_video:cooldown:{$userId}";
|
||||
|
||||
// 1. 检查冷却时间
|
||||
if (Redis::exists($cooldownKey)) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => '操作过快,请稍后再试。',
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. 检查每日最大次数
|
||||
$todayCount = (int) Redis::get($dailyCountKey);
|
||||
if ($todayCount >= $this->maxDailyLimit) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "今日视频收益次数已达上限(每天最多{$this->maxDailyLimit}次),请明天再来。",
|
||||
]);
|
||||
}
|
||||
|
||||
// 3. 增加今日次数计数
|
||||
$newCount = Redis::incr($dailyCountKey);
|
||||
if ($newCount === 1) {
|
||||
Redis::expire($dailyCountKey, 86400 * 2);
|
||||
}
|
||||
|
||||
// 4. 配置:单次 5000 金币,500 经验
|
||||
$rewardCoins = 5000;
|
||||
$rewardExp = 500;
|
||||
$roomId = (int) $request->input('room_id', 0);
|
||||
|
||||
// 参照钓鱼逻辑:通过 UserCurrencyService 写日志并变更金币/经验
|
||||
$this->currencyService->change(
|
||||
$user, 'gold', $rewardCoins, CurrencySource::VIDEO_REWARD,
|
||||
"看视频赚取金币(第{$newCount}次)", $roomId,
|
||||
);
|
||||
|
||||
$this->currencyService->change(
|
||||
$user, 'exp', $rewardExp, CurrencySource::VIDEO_REWARD,
|
||||
"看视频赚取经验(第{$newCount}次)", $roomId,
|
||||
);
|
||||
|
||||
// 刷新模型以获取 service 原子更新后的最新字段值
|
||||
$user->refresh();
|
||||
|
||||
// 5. 设置冷却时间
|
||||
Redis::setex($cooldownKey, $this->cooldownSeconds, 1);
|
||||
|
||||
// 6. 广播全服系统消息
|
||||
if ($roomId > 0) {
|
||||
$promoTag = ' <span onclick="window.dispatchEvent(new CustomEvent(\'open-earn-panel\'))" '
|
||||
.'style="display:inline-block;margin-left:6px;padding:1px 7px;background:#e9e4f5;'
|
||||
.'color:#6d4fa8;border-radius:10px;font-size:10px;cursor:pointer;font-weight:bold;vertical-align:middle;'
|
||||
.'border:1px solid #d0c4ec;" title="点击赚金币">💰 看视频赚金币</span>';
|
||||
|
||||
$sysMsg = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => '系统播报',
|
||||
'to_user' => '大家',
|
||||
'content' => "👍 【{$user->username}】刚刚看视频赚取了 {$rewardCoins} 金币 + {$rewardExp} 经验!{$promoTag}",
|
||||
'is_secret' => false,
|
||||
'font_color' => '#16a34a',
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
$this->chatState->pushMessage($roomId, $sysMsg);
|
||||
broadcast(new MessageSent($roomId, $sysMsg));
|
||||
}
|
||||
|
||||
$remainingToday = $this->maxDailyLimit - $newCount;
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => "观看完毕!获得 {$rewardCoins} 金币 + {$rewardExp} 经验。今日还可观看 {$remainingToday} 次。",
|
||||
'new_jjb' => $user->jjb,
|
||||
'level_up' => false,
|
||||
'new_level_name' => '',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user