*
Showing
17 changed files
with
374 additions
and
6 deletions
app/Helper/CacheKeyTools.php
0 → 100644
... | @@ -16,6 +16,7 @@ class ErrorCode | ... | @@ -16,6 +16,7 @@ class ErrorCode |
16 | const ORDER_ILLEGAl = 40040; | 16 | const ORDER_ILLEGAl = 40040; |
17 | const ORDER_WITHDRAW_ERROR = 40041; | 17 | const ORDER_WITHDRAW_ERROR = 40041; |
18 | const ORDER_MONEY_ERROR = 40042; | 18 | const ORDER_MONEY_ERROR = 40042; |
19 | const ORDER_NO_FOUND = 40043; | ||
19 | const WITHDRAW_NO_RECORD = 40051; | 20 | const WITHDRAW_NO_RECORD = 40051; |
20 | const WITHDRAW_HANDLE_ERROR = 40052; | 21 | const WITHDRAW_HANDLE_ERROR = 40052; |
21 | 22 | ||
... | @@ -33,6 +34,7 @@ class ErrorCode | ... | @@ -33,6 +34,7 @@ class ErrorCode |
33 | self::ORDER_ILLEGAl => '提现订单有误', | 34 | self::ORDER_ILLEGAl => '提现订单有误', |
34 | self::ORDER_WITHDRAW_ERROR => '提现记录有误', | 35 | self::ORDER_WITHDRAW_ERROR => '提现记录有误', |
35 | self::ORDER_MONEY_ERROR => '提现金额有误', | 36 | self::ORDER_MONEY_ERROR => '提现金额有误', |
37 | self::ORDER_NO_FOUND => '未找到订单记录', | ||
36 | self::WITHDRAW_NO_RECORD => '未匹配有效提现记录', | 38 | self::WITHDRAW_NO_RECORD => '未匹配有效提现记录', |
37 | self::WITHDRAW_HANDLE_ERROR => '提现操作失败', | 39 | self::WITHDRAW_HANDLE_ERROR => '提现操作失败', |
38 | ]; | 40 | ]; | ... | ... |
app/Helper/Snowflake.php
0 → 100644
... | @@ -3,6 +3,7 @@ | ... | @@ -3,6 +3,7 @@ |
3 | namespace App\Http\Controllers\Musician; | 3 | namespace App\Http\Controllers\Musician; |
4 | 4 | ||
5 | use App\Http\Controllers\Controller; | 5 | use App\Http\Controllers\Controller; |
6 | use App\Http\Requests\Musician\MusicianWalletDetailRequest; | ||
6 | use App\Http\Requests\Musician\MusicianWithdrawReceiptByNameRequest; | 7 | use App\Http\Requests\Musician\MusicianWithdrawReceiptByNameRequest; |
7 | use App\Http\Requests\Musician\MusicianWithdrawReceiptRequest; | 8 | use App\Http\Requests\Musician\MusicianWithdrawReceiptRequest; |
8 | use App\Http\Requests\Musician\MusicianWithdrawRequest; | 9 | use App\Http\Requests\Musician\MusicianWithdrawRequest; |
... | @@ -29,6 +30,11 @@ class MusicianWithdrawController extends Controller | ... | @@ -29,6 +30,11 @@ class MusicianWithdrawController extends Controller |
29 | $this->musicianWithdrawService = $musicianWithdrawService; | 30 | $this->musicianWithdrawService = $musicianWithdrawService; |
30 | } | 31 | } |
31 | 32 | ||
33 | public function walletDetail(MusicianWalletDetailRequest $request) | ||
34 | { | ||
35 | return $this->musicianWithdrawService->walletDetail(); | ||
36 | } | ||
37 | |||
32 | /** | 38 | /** |
33 | * 发票信息 | 39 | * 发票信息 |
34 | * @param MusicianWithdrawReceiptRequest $request | 40 | * @param MusicianWithdrawReceiptRequest $request | ... | ... |
1 | <?php | ||
2 | |||
3 | namespace App\Http\Requests\Musician; | ||
4 | |||
5 | use Illuminate\Foundation\Http\FormRequest; | ||
6 | |||
7 | class MusicianWalletDetailRequest extends FormRequest | ||
8 | { | ||
9 | /** | ||
10 | * Determine if the user is authorized to make this request. | ||
11 | * | ||
12 | * @return bool | ||
13 | */ | ||
14 | public function authorize() | ||
15 | { | ||
16 | return true; | ||
17 | } | ||
18 | |||
19 | /** | ||
20 | * Get the validation rules that apply to the request. | ||
21 | * | ||
22 | * @return array | ||
23 | */ | ||
24 | public function rules() | ||
25 | { | ||
26 | return [ | ||
27 | 'busi_id' => ['required', 'bail', 'string'], | ||
28 | ]; | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * @return string[] | ||
33 | */ | ||
34 | public function messages(): array | ||
35 | { | ||
36 | return [ | ||
37 | 'busi_id.required' => '请提供业务流水号', | ||
38 | ]; | ||
39 | } | ||
40 | } |
app/Jobs/StakeholderIncomeSyncJob.php
0 → 100644
1 | <?php | ||
2 | |||
3 | namespace App\Jobs; | ||
4 | |||
5 | use App\Helper\CacheKeyTools; | ||
6 | use App\Helper\RedisClient; | ||
7 | use App\Models\Legal\Bills; | ||
8 | use App\Models\Legal\Company; | ||
9 | use App\Services\ApiService; | ||
10 | use App\Traits\TaxReckon; | ||
11 | use Illuminate\Bus\Queueable; | ||
12 | use Illuminate\Contracts\Queue\ShouldBeUnique; | ||
13 | use Illuminate\Contracts\Queue\ShouldQueue; | ||
14 | use Illuminate\Foundation\Bus\Dispatchable; | ||
15 | use Illuminate\Queue\InteractsWithQueue; | ||
16 | use Illuminate\Queue\SerializesModels; | ||
17 | use Illuminate\Support\Facades\Log; | ||
18 | |||
19 | class StakeholderIncomeSyncJob implements ShouldQueue | ||
20 | { | ||
21 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, TaxReckon; | ||
22 | |||
23 | const COUNT = 1; | ||
24 | const BLOCK_TIME = 3; | ||
25 | |||
26 | const TYPE_BILLS = 1001601; //账单分成 | ||
27 | const TYPE_ROYALTY = 1001602; //合作伙伴打款 type = 1 版税分成 | ||
28 | |||
29 | /** | ||
30 | * Create a new job instance. | ||
31 | * | ||
32 | * @return void | ||
33 | */ | ||
34 | public function __construct() | ||
35 | { | ||
36 | Log::info(__METHOD__."入账数据同步任务", ['time'=>now()->toDateTimeString()]); | ||
37 | } | ||
38 | |||
39 | /** | ||
40 | * Execute the job. | ||
41 | * | ||
42 | * @return void | ||
43 | */ | ||
44 | public function handle() | ||
45 | { | ||
46 | $id = '0'; | ||
47 | |||
48 | while (true) { | ||
49 | |||
50 | $redis = RedisClient::instance('bills'); | ||
51 | $key = CacheKeyTools::billsSync(); | ||
52 | |||
53 | //处理消息体 | ||
54 | if($msg = $redis->xread([$key=>$id], 1, 3)) { | ||
55 | |||
56 | $id = key($msg[$key]); | ||
57 | $income_item = $msg[$key][$id]; | ||
58 | |||
59 | $company = Company::query()->find($income_item['company_id']); | ||
60 | $bills = Bills::query()->find($income_item['related_id']); | ||
61 | $channel = 'TME'; | ||
62 | $title = "{$bills->bill_section_start}-{$bills->bill_section_end}账单/{$channel}"; | ||
63 | |||
64 | $http_res = ApiService::walletAddIncome([ | ||
65 | 'cardNo'=>$income_item['identifier'], | ||
66 | 'faxMoney'=>$income_item['fax_money'], | ||
67 | 'money'=>$income_item['money'], | ||
68 | 'totalMoney'=>$income_item['total_money'], | ||
69 | 'paymentCompany'=>$company->receipt_name, | ||
70 | 'type'=>self::TYPE_BILLS, | ||
71 | 'title'=>"{$bills->bill_section_start}-{$bills->bill_section_end}账单/{$channel}", | ||
72 | ]); | ||
73 | |||
74 | if (empty($http_res)) { | ||
75 | //重试 401/403/403 | ||
76 | Log::info(__METHOD__.'请求失败'); | ||
77 | } else { | ||
78 | switch ($http_res['code']) { | ||
79 | |||
80 | } | ||
81 | } | ||
82 | |||
83 | |||
84 | } | ||
85 | |||
86 | } | ||
87 | } | ||
88 | } |
app/Models/Legal/Bills.php
0 → 100644
1 | <?php | ||
2 | |||
3 | namespace App\Models\Legal; | ||
4 | |||
5 | use App\Models\BaseModel; | ||
6 | use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
7 | use Illuminate\Database\Eloquent\SoftDeletes; | ||
8 | |||
9 | /** | ||
10 | * Class Bills | ||
11 | * @package App\Models\Legal | ||
12 | */ | ||
13 | class Bills extends BaseModel | ||
14 | { | ||
15 | use HasFactory,SoftDeletes; | ||
16 | |||
17 | protected $table = 'bills'; | ||
18 | |||
19 | } |
... | @@ -14,6 +14,10 @@ class StakeholderIncomeByPayer extends BaseModel | ... | @@ -14,6 +14,10 @@ class StakeholderIncomeByPayer extends BaseModel |
14 | { | 14 | { |
15 | use HasFactory; | 15 | use HasFactory; |
16 | 16 | ||
17 | const TYPE_INCOME = 1; | ||
18 | const TYPE_PAY = 2; | ||
19 | |||
20 | |||
17 | public $table = 'stakeholder_income_by_payer'; | 21 | public $table = 'stakeholder_income_by_payer'; |
18 | 22 | ||
19 | /** | 23 | /** | ... | ... |
1 | <?php | ||
2 | |||
3 | namespace App\Models\Legal; | ||
4 | |||
5 | use App\Models\BaseModel; | ||
6 | use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
7 | |||
8 | /** | ||
9 | * Class StakeholderIncomeSyncLogs | ||
10 | * @package App\Models\Legal | ||
11 | */ | ||
12 | class StakeholderIncomeSyncLogs extends BaseModel | ||
13 | { | ||
14 | public $table = 'stakeholder_income_sync_logs'; | ||
15 | } |
... | @@ -36,4 +36,12 @@ class StakeholderSongCollate extends BaseModel | ... | @@ -36,4 +36,12 @@ class StakeholderSongCollate extends BaseModel |
36 | { | 36 | { |
37 | return $this->belongsTo(Subject::class, 'subject_no', 'no'); | 37 | return $this->belongsTo(Subject::class, 'subject_no', 'no'); |
38 | } | 38 | } |
39 | |||
40 | /** | ||
41 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | ||
42 | */ | ||
43 | public function stakeholder() | ||
44 | { | ||
45 | return $this->belongsTo(Stakeholder::class, 'stakeholder_id')->withTrashed(); | ||
46 | } | ||
39 | } | 47 | } | ... | ... |
app/Services/ApiService.php
0 → 100644
1 | <?php | ||
2 | |||
3 | namespace App\Services; | ||
4 | |||
5 | use App\Helper\ErrorCode; | ||
6 | use App\Helper\Http; | ||
7 | use App\Helper\Response; | ||
8 | use App\Models\Legal\Company; | ||
9 | use App\Models\Legal\StakeholderIncomeByPayer; | ||
10 | |||
11 | /** | ||
12 | * Class ApiService | ||
13 | * @package App\Services | ||
14 | */ | ||
15 | class ApiService | ||
16 | { | ||
17 | protected static $uri = [ | ||
18 | 'walletAddIncome'=> '/api/wallet/addIncome', //外部系统入账-外部可调用 | ||
19 | ]; | ||
20 | |||
21 | /** | ||
22 | * 钱包 - 同步收入/支出数据 | ||
23 | * @param $data | ||
24 | * @return array | ||
25 | */ | ||
26 | public static function walletAddIncome($data) | ||
27 | { | ||
28 | return Http::post(self::getUri(__FUNCTION__), $data); | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * 获取uri | ||
33 | * @param $method | ||
34 | * @return mixed | ||
35 | */ | ||
36 | private static function getUri($method) | ||
37 | { | ||
38 | return self::$uri[$method]; | ||
39 | } | ||
40 | } |
... | @@ -5,7 +5,9 @@ namespace App\Services; | ... | @@ -5,7 +5,9 @@ namespace App\Services; |
5 | use App\Helper\ErrorCode; | 5 | use App\Helper\ErrorCode; |
6 | use App\Helper\Response; | 6 | use App\Helper\Response; |
7 | use App\Models\Legal\Company; | 7 | use App\Models\Legal\Company; |
8 | use App\Models\Legal\Contract; | ||
8 | use App\Models\Legal\StakeholderIncomeByPayer; | 9 | use App\Models\Legal\StakeholderIncomeByPayer; |
10 | use App\Models\Legal\StakeholderSongCollate; | ||
9 | 11 | ||
10 | /** | 12 | /** |
11 | * Class MusicianAgreementService | 13 | * Class MusicianAgreementService |
... | @@ -14,6 +16,26 @@ use App\Models\Legal\StakeholderIncomeByPayer; | ... | @@ -14,6 +16,26 @@ use App\Models\Legal\StakeholderIncomeByPayer; |
14 | class MusicianWithdrawService extends Service | 16 | class MusicianWithdrawService extends Service |
15 | { | 17 | { |
16 | /** | 18 | /** |
19 | * 返回账单详情 | ||
20 | * @return \Illuminate\Http\JsonResponse | ||
21 | */ | ||
22 | public function walletDetail() | ||
23 | { | ||
24 | $income_by_payer = StakeholderIncomeByPayer::query()->where(['busi_id'=>$this->request->input('busi_id'), 'sync_status'=>1])->first(); | ||
25 | if (empty($income_by_payer)) return Response::error(ErrorCode::ORDER_NO_FOUND); | ||
26 | |||
27 | $collate = StakeholderSongCollate::query()->with('song:id,name,singer')->where([ | ||
28 | 'bills_id'=>$income_by_payer->related_id, 'subject_no'=>$income_by_payer->subject_no]) | ||
29 | ->select(['song_id', 'role', 'cost_amount', 'deduct_amount', 'real_share_amount'])->paginate($this->pageSize); | ||
30 | |||
31 | foreach ($collate as &$item) { | ||
32 | $item->setAttribute('role', Contract::transformRole($item->role)); | ||
33 | } | ||
34 | |||
35 | return Response::success($collate); | ||
36 | } | ||
37 | |||
38 | /** | ||
17 | * 发票信息 - 通过名字 | 39 | * 发票信息 - 通过名字 |
18 | * @return \Illuminate\Http\JsonResponse|mixed | 40 | * @return \Illuminate\Http\JsonResponse|mixed |
19 | */ | 41 | */ | ... | ... |
... | @@ -6,13 +6,15 @@ | ... | @@ -6,13 +6,15 @@ |
6 | "license": "MIT", | 6 | "license": "MIT", |
7 | "require": { | 7 | "require": { |
8 | "php": "^7.3|^8.0", | 8 | "php": "^7.3|^8.0", |
9 | "ext-bcmath": "*", | ||
10 | "ext-json": "*", | ||
9 | "fideloper/proxy": "^4.4", | 11 | "fideloper/proxy": "^4.4", |
10 | "fruitcake/laravel-cors": "^2.0", | 12 | "fruitcake/laravel-cors": "^2.0", |
13 | "godruoyi/php-snowflake": "^1.1", | ||
11 | "guzzlehttp/guzzle": "^7.0.1", | 14 | "guzzlehttp/guzzle": "^7.0.1", |
12 | "laravel/framework": "^8.40", | 15 | "laravel/framework": "^8.40", |
13 | "laravel/tinker": "^2.5", | 16 | "laravel/tinker": "^2.5", |
14 | "phpseclib/phpseclib": "~3.0", | 17 | "phpseclib/phpseclib": "~3.0" |
15 | "ext-json": "*" | ||
16 | }, | 18 | }, |
17 | "require-dev": { | 19 | "require-dev": { |
18 | "facade/ignition": "^2.5", | 20 | "facade/ignition": "^2.5", | ... | ... |
... | @@ -4,7 +4,7 @@ | ... | @@ -4,7 +4,7 @@ |
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", |
5 | "This file is @generated automatically" | 5 | "This file is @generated automatically" |
6 | ], | 6 | ], |
7 | "content-hash": "b213fcbde9166c244e46315445a8ead2", | 7 | "content-hash": "a4efc4c63ff2de523232f0fe790550fb", |
8 | "packages": [ | 8 | "packages": [ |
9 | { | 9 | { |
10 | "name": "asm89/stack-cors", | 10 | "name": "asm89/stack-cors", |
... | @@ -606,6 +606,72 @@ | ... | @@ -606,6 +606,72 @@ |
606 | "time": "2021-04-26T11:24:25+00:00" | 606 | "time": "2021-04-26T11:24:25+00:00" |
607 | }, | 607 | }, |
608 | { | 608 | { |
609 | "name": "godruoyi/php-snowflake", | ||
610 | "version": "1.1.1", | ||
611 | "source": { | ||
612 | "type": "git", | ||
613 | "url": "https://github.com/godruoyi/php-snowflake.git", | ||
614 | "reference": "d8cbe72ed375b45033b7042e3d03340ce4fa479f" | ||
615 | }, | ||
616 | "dist": { | ||
617 | "type": "zip", | ||
618 | "url": "https://api.github.com/repos/godruoyi/php-snowflake/zipball/d8cbe72ed375b45033b7042e3d03340ce4fa479f", | ||
619 | "reference": "d8cbe72ed375b45033b7042e3d03340ce4fa479f", | ||
620 | "shasum": "", | ||
621 | "mirrors": [ | ||
622 | { | ||
623 | "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", | ||
624 | "preferred": true | ||
625 | } | ||
626 | ] | ||
627 | }, | ||
628 | "require-dev": { | ||
629 | "phpunit/phpunit": "~7" | ||
630 | }, | ||
631 | "type": "library", | ||
632 | "autoload": { | ||
633 | "psr-4": { | ||
634 | "Godruoyi\\Snowflake\\": "src" | ||
635 | } | ||
636 | }, | ||
637 | "notification-url": "https://packagist.org/downloads/", | ||
638 | "license": [ | ||
639 | "MIT" | ||
640 | ], | ||
641 | "authors": [ | ||
642 | { | ||
643 | "name": "Godruoyi", | ||
644 | "email": "g@godruoyi.com" | ||
645 | } | ||
646 | ], | ||
647 | "description": "An ID Generator for PHP based on Snowflake Algorithm (Twitter announced).", | ||
648 | "homepage": "https://github.com/godruoyi/php-snowflake", | ||
649 | "keywords": [ | ||
650 | "Unique ID", | ||
651 | "laravel snowflake", | ||
652 | "order id", | ||
653 | "php snowflake", | ||
654 | "php unique id", | ||
655 | "snowflake algorithm", | ||
656 | "unique order id" | ||
657 | ], | ||
658 | "support": { | ||
659 | "issues": "https://github.com/godruoyi/php-snowflake/issues", | ||
660 | "source": "https://github.com/godruoyi/php-snowflake/tree/1.1.1" | ||
661 | }, | ||
662 | "funding": [ | ||
663 | { | ||
664 | "url": "https://images.godruoyi.com/wechat.png", | ||
665 | "type": "custom" | ||
666 | }, | ||
667 | { | ||
668 | "url": "https://github.com/godruoyi", | ||
669 | "type": "github" | ||
670 | } | ||
671 | ], | ||
672 | "time": "2021-05-25T05:56:30+00:00" | ||
673 | }, | ||
674 | { | ||
609 | "name": "graham-campbell/result-type", | 675 | "name": "graham-campbell/result-type", |
610 | "version": "v1.0.1", | 676 | "version": "v1.0.1", |
611 | "source": { | 677 | "source": { |
... | @@ -8207,7 +8273,9 @@ | ... | @@ -8207,7 +8273,9 @@ |
8207 | "prefer-stable": true, | 8273 | "prefer-stable": true, |
8208 | "prefer-lowest": false, | 8274 | "prefer-lowest": false, |
8209 | "platform": { | 8275 | "platform": { |
8210 | "php": "^7.3|^8.0" | 8276 | "php": "^7.3|^8.0", |
8277 | "ext-bcmath": "*", | ||
8278 | "ext-json": "*" | ||
8211 | }, | 8279 | }, |
8212 | "platform-dev": [], | 8280 | "platform-dev": [], |
8213 | "plugin-api-version": "2.0.0" | 8281 | "plugin-api-version": "2.0.0" | ... | ... |
... | @@ -107,4 +107,9 @@ return [ | ... | @@ -107,4 +107,9 @@ return [ |
107 | 107 | ||
108 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'), | 108 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'), |
109 | 109 | ||
110 | //cache_key | ||
111 | 'key'=> [ | ||
112 | 'bills_sync'=>"bills:sync", | ||
113 | ] | ||
114 | |||
110 | ]; | 115 | ]; | ... | ... |
... | @@ -167,7 +167,15 @@ return [ | ... | @@ -167,7 +167,15 @@ return [ |
167 | 'password' => env('REDIS_PASSWORD', null), | 167 | 'password' => env('REDIS_PASSWORD', null), |
168 | 'port' => env('REDIS_PORT', '6379'), | 168 | 'port' => env('REDIS_PORT', '6379'), |
169 | 'database' => 0, | 169 | 'database' => 0, |
170 | ] | 170 | ], |
171 | |||
172 | 'bills'=>[ | ||
173 | 'url' => env('REDIS_URL'), | ||
174 | 'host' => env('REDIS_HOST', '127.0.0.1'), | ||
175 | 'password' => env('REDIS_PASSWORD', null), | ||
176 | 'port' => env('REDIS_PORT', 6379), | ||
177 | 'database' => env('REDIS_BILLS_DB', 4), | ||
178 | ], | ||
171 | 179 | ||
172 | ], | 180 | ], |
173 | 181 | ... | ... |
... | @@ -39,8 +39,11 @@ Route::group([], function (){ | ... | @@ -39,8 +39,11 @@ Route::group([], function (){ |
39 | Route::post('withdraw/receipt', 'MusicianWithdrawController@receipt'); | 39 | Route::post('withdraw/receipt', 'MusicianWithdrawController@receipt'); |
40 | //提现发票抬头 - 通过公司中文 | 40 | //提现发票抬头 - 通过公司中文 |
41 | Route::post('withdraw/receipt_by_name', 'MusicianWithdrawController@receiptByName'); | 41 | Route::post('withdraw/receipt_by_name', 'MusicianWithdrawController@receiptByName'); |
42 | |||
43 | //账单状态修改 | 42 | //账单状态修改 |
44 | Route::post('withdraw/status', 'MusicianWithdrawController@status'); | 43 | Route::post('withdraw/status', 'MusicianWithdrawController@status'); |
45 | 44 | ||
45 | //钱包-账单收益 | ||
46 | Route::get('wallet/detail', 'MusicianWithdrawController@walletDetail'); | ||
47 | |||
48 | |||
46 | }); | 49 | }); | ... | ... |
-
Please register or sign in to post a comment