Commit add2061c add2061c5178a8a5e9285a1865f8957f86a11baa by lemon

*

1 parent 02474e2b
<?php
namespace App\Helper;
/**
* Class CacheKeyTools
* @package App\Helper
*/
class CacheKeyTools
{
/**
* @return mixed
*/
public static function billsSync()
{
return config('cache.key')['bills_sync'];
}
}
......@@ -16,6 +16,7 @@ class ErrorCode
const ORDER_ILLEGAl = 40040;
const ORDER_WITHDRAW_ERROR = 40041;
const ORDER_MONEY_ERROR = 40042;
const ORDER_NO_FOUND = 40043;
const WITHDRAW_NO_RECORD = 40051;
const WITHDRAW_HANDLE_ERROR = 40052;
......@@ -33,6 +34,7 @@ class ErrorCode
self::ORDER_ILLEGAl => '提现订单有误',
self::ORDER_WITHDRAW_ERROR => '提现记录有误',
self::ORDER_MONEY_ERROR => '提现金额有误',
self::ORDER_NO_FOUND => '未找到订单记录',
self::WITHDRAW_NO_RECORD => '未匹配有效提现记录',
self::WITHDRAW_HANDLE_ERROR => '提现操作失败',
];
......
<?php
namespace App\Helper;
/**
* Class Snowflake
* @package App\Helper
*/
class Snowflake
{
/**
* @return string
*/
public static function gen()
{
return (string)(new \Godruoyi\Snowflake\Snowflake)->id();
}
}
......@@ -3,6 +3,7 @@
namespace App\Http\Controllers\Musician;
use App\Http\Controllers\Controller;
use App\Http\Requests\Musician\MusicianWalletDetailRequest;
use App\Http\Requests\Musician\MusicianWithdrawReceiptByNameRequest;
use App\Http\Requests\Musician\MusicianWithdrawReceiptRequest;
use App\Http\Requests\Musician\MusicianWithdrawRequest;
......@@ -29,6 +30,11 @@ class MusicianWithdrawController extends Controller
$this->musicianWithdrawService = $musicianWithdrawService;
}
public function walletDetail(MusicianWalletDetailRequest $request)
{
return $this->musicianWithdrawService->walletDetail();
}
/**
* 发票信息
* @param MusicianWithdrawReceiptRequest $request
......
<?php
namespace App\Http\Requests\Musician;
use Illuminate\Foundation\Http\FormRequest;
class MusicianWalletDetailRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'busi_id' => ['required', 'bail', 'string'],
];
}
/**
* @return string[]
*/
public function messages(): array
{
return [
'busi_id.required' => '请提供业务流水号',
];
}
}
<?php
namespace App\Jobs;
use App\Helper\CacheKeyTools;
use App\Helper\RedisClient;
use App\Models\Legal\Bills;
use App\Models\Legal\Company;
use App\Services\ApiService;
use App\Traits\TaxReckon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
class StakeholderIncomeSyncJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, TaxReckon;
const COUNT = 1;
const BLOCK_TIME = 3;
const TYPE_BILLS = 1001601; //账单分成
const TYPE_ROYALTY = 1001602; //合作伙伴打款 type = 1 版税分成
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
Log::info(__METHOD__."入账数据同步任务", ['time'=>now()->toDateTimeString()]);
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$id = '0';
while (true) {
$redis = RedisClient::instance('bills');
$key = CacheKeyTools::billsSync();
//处理消息体
if($msg = $redis->xread([$key=>$id], 1, 3)) {
$id = key($msg[$key]);
$income_item = $msg[$key][$id];
$company = Company::query()->find($income_item['company_id']);
$bills = Bills::query()->find($income_item['related_id']);
$channel = 'TME';
$title = "{$bills->bill_section_start}-{$bills->bill_section_end}账单/{$channel}";
$http_res = ApiService::walletAddIncome([
'cardNo'=>$income_item['identifier'],
'faxMoney'=>$income_item['fax_money'],
'money'=>$income_item['money'],
'totalMoney'=>$income_item['total_money'],
'paymentCompany'=>$company->receipt_name,
'type'=>self::TYPE_BILLS,
'title'=>"{$bills->bill_section_start}-{$bills->bill_section_end}账单/{$channel}",
]);
if (empty($http_res)) {
//重试 401/403/403
Log::info(__METHOD__.'请求失败');
} else {
switch ($http_res['code']) {
}
}
}
}
}
}
<?php
namespace App\Models\Legal;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class Bills
* @package App\Models\Legal
*/
class Bills extends BaseModel
{
use HasFactory,SoftDeletes;
protected $table = 'bills';
}
......@@ -14,6 +14,10 @@ class StakeholderIncomeByPayer extends BaseModel
{
use HasFactory;
const TYPE_INCOME = 1;
const TYPE_PAY = 2;
public $table = 'stakeholder_income_by_payer';
/**
......
<?php
namespace App\Models\Legal;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
/**
* Class StakeholderIncomeSyncLogs
* @package App\Models\Legal
*/
class StakeholderIncomeSyncLogs extends BaseModel
{
public $table = 'stakeholder_income_sync_logs';
}
......@@ -36,4 +36,12 @@ class StakeholderSongCollate extends BaseModel
{
return $this->belongsTo(Subject::class, 'subject_no', 'no');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function stakeholder()
{
return $this->belongsTo(Stakeholder::class, 'stakeholder_id')->withTrashed();
}
}
......
<?php
namespace App\Services;
use App\Helper\ErrorCode;
use App\Helper\Http;
use App\Helper\Response;
use App\Models\Legal\Company;
use App\Models\Legal\StakeholderIncomeByPayer;
/**
* Class ApiService
* @package App\Services
*/
class ApiService
{
protected static $uri = [
'walletAddIncome'=> '/api/wallet/addIncome', //外部系统入账-外部可调用
];
/**
* 钱包 - 同步收入/支出数据
* @param $data
* @return array
*/
public static function walletAddIncome($data)
{
return Http::post(self::getUri(__FUNCTION__), $data);
}
/**
* 获取uri
* @param $method
* @return mixed
*/
private static function getUri($method)
{
return self::$uri[$method];
}
}
......@@ -5,7 +5,9 @@ namespace App\Services;
use App\Helper\ErrorCode;
use App\Helper\Response;
use App\Models\Legal\Company;
use App\Models\Legal\Contract;
use App\Models\Legal\StakeholderIncomeByPayer;
use App\Models\Legal\StakeholderSongCollate;
/**
* Class MusicianAgreementService
......@@ -14,6 +16,26 @@ use App\Models\Legal\StakeholderIncomeByPayer;
class MusicianWithdrawService extends Service
{
/**
* 返回账单详情
* @return \Illuminate\Http\JsonResponse
*/
public function walletDetail()
{
$income_by_payer = StakeholderIncomeByPayer::query()->where(['busi_id'=>$this->request->input('busi_id'), 'sync_status'=>1])->first();
if (empty($income_by_payer)) return Response::error(ErrorCode::ORDER_NO_FOUND);
$collate = StakeholderSongCollate::query()->with('song:id,name,singer')->where([
'bills_id'=>$income_by_payer->related_id, 'subject_no'=>$income_by_payer->subject_no])
->select(['song_id', 'role', 'cost_amount', 'deduct_amount', 'real_share_amount'])->paginate($this->pageSize);
foreach ($collate as &$item) {
$item->setAttribute('role', Contract::transformRole($item->role));
}
return Response::success($collate);
}
/**
* 发票信息 - 通过名字
* @return \Illuminate\Http\JsonResponse|mixed
*/
......
......@@ -6,13 +6,15 @@
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"ext-bcmath": "*",
"ext-json": "*",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"godruoyi/php-snowflake": "^1.1",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.40",
"laravel/tinker": "^2.5",
"phpseclib/phpseclib": "~3.0",
"ext-json": "*"
"phpseclib/phpseclib": "~3.0"
},
"require-dev": {
"facade/ignition": "^2.5",
......
......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "b213fcbde9166c244e46315445a8ead2",
"content-hash": "a4efc4c63ff2de523232f0fe790550fb",
"packages": [
{
"name": "asm89/stack-cors",
......@@ -606,6 +606,72 @@
"time": "2021-04-26T11:24:25+00:00"
},
{
"name": "godruoyi/php-snowflake",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/godruoyi/php-snowflake.git",
"reference": "d8cbe72ed375b45033b7042e3d03340ce4fa479f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/godruoyi/php-snowflake/zipball/d8cbe72ed375b45033b7042e3d03340ce4fa479f",
"reference": "d8cbe72ed375b45033b7042e3d03340ce4fa479f",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require-dev": {
"phpunit/phpunit": "~7"
},
"type": "library",
"autoload": {
"psr-4": {
"Godruoyi\\Snowflake\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Godruoyi",
"email": "g@godruoyi.com"
}
],
"description": "An ID Generator for PHP based on Snowflake Algorithm (Twitter announced).",
"homepage": "https://github.com/godruoyi/php-snowflake",
"keywords": [
"Unique ID",
"laravel snowflake",
"order id",
"php snowflake",
"php unique id",
"snowflake algorithm",
"unique order id"
],
"support": {
"issues": "https://github.com/godruoyi/php-snowflake/issues",
"source": "https://github.com/godruoyi/php-snowflake/tree/1.1.1"
},
"funding": [
{
"url": "https://images.godruoyi.com/wechat.png",
"type": "custom"
},
{
"url": "https://github.com/godruoyi",
"type": "github"
}
],
"time": "2021-05-25T05:56:30+00:00"
},
{
"name": "graham-campbell/result-type",
"version": "v1.0.1",
"source": {
......@@ -8207,7 +8273,9 @@
"prefer-stable": true,
"prefer-lowest": false,
"platform": {
"php": "^7.3|^8.0"
"php": "^7.3|^8.0",
"ext-bcmath": "*",
"ext-json": "*"
},
"platform-dev": [],
"plugin-api-version": "2.0.0"
......
......@@ -107,4 +107,9 @@ return [
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'),
//cache_key
'key'=> [
'bills_sync'=>"bills:sync",
]
];
......
......@@ -167,7 +167,15 @@ return [
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', '6379'),
'database' => 0,
]
],
'bills'=>[
'url' => env('REDIS_URL'),
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_BILLS_DB', 4),
],
],
......
......@@ -39,8 +39,11 @@ Route::group([], function (){
Route::post('withdraw/receipt', 'MusicianWithdrawController@receipt');
//提现发票抬头 - 通过公司中文
Route::post('withdraw/receipt_by_name', 'MusicianWithdrawController@receiptByName');
//账单状态修改
Route::post('withdraw/status', 'MusicianWithdrawController@status');
//钱包-账单收益
Route::get('wallet/detail', 'MusicianWithdrawController@walletDetail');
});
......