分贝确认账单接口
Showing
7 changed files
with
182 additions
and
36 deletions
| ... | @@ -26,4 +26,12 @@ class CacheKeyTools | ... | @@ -26,4 +26,12 @@ class CacheKeyTools |
| 26 | return config('cache.key')['channelname']; | 26 | return config('cache.key')['channelname']; |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | /** | ||
| 30 | * @return mixed | ||
| 31 | */ | ||
| 32 | public static function billsConfirm($busi_id) | ||
| 33 | { | ||
| 34 | return str_replace('#busi_id#', $busi_id, config('cache.key')['bills_confirm']); | ||
| 35 | } | ||
| 36 | |||
| 29 | } | 37 | } | ... | ... |
| ... | @@ -7,36 +7,38 @@ namespace App\Helper; | ... | @@ -7,36 +7,38 @@ namespace App\Helper; |
| 7 | */ | 7 | */ |
| 8 | class ErrorCode | 8 | class ErrorCode |
| 9 | { | 9 | { |
| 10 | const SERVER_ERROR = -1; | 10 | const SERVER_ERROR = -1; |
| 11 | const SERVER_OK = 0; | 11 | const SERVER_OK = 0; |
| 12 | const IDENTIFIER_FAIL = 40001; | 12 | const IDENTIFIER_FAIL = 40001; |
| 13 | const MATCH_IDENTIFIER_FAIL = 40002; | 13 | const MATCH_IDENTIFIER_FAIL = 40002; |
| 14 | const REPEAT_SUBMIT = 40003; | 14 | const REPEAT_SUBMIT = 40003; |
| 15 | const ILLEGAL_PARAMS = 40035; | 15 | const ILLEGAL_PARAMS = 40035; |
| 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 ORDER_NO_FOUND = 40043; |
| 20 | const WITHDRAW_NO_RECORD = 40051; | 20 | const WITHDRAW_NO_RECORD = 40051; |
| 21 | const WITHDRAW_HANDLE_ERROR = 40052; | 21 | const WITHDRAW_HANDLE_ERROR = 40052; |
| 22 | const WITHDRAW_CONFIRM_BILLS_FAIL = 40053; | ||
| 22 | 23 | ||
| 23 | 24 | ||
| 24 | /** | 25 | /** |
| 25 | * @var string[] | 26 | * @var string[] |
| 26 | */ | 27 | */ |
| 27 | public static $messages = [ | 28 | public static $messages = [ |
| 28 | self::SERVER_ERROR => '服务器繁忙', | 29 | self::SERVER_ERROR => '服务器繁忙', |
| 29 | self::MATCH_IDENTIFIER_FAIL => '匹配身份失败', | 30 | self::MATCH_IDENTIFIER_FAIL => '匹配身份失败', |
| 30 | self::REPEAT_SUBMIT => '请勿重复提交', | 31 | self::REPEAT_SUBMIT => '请勿重复提交', |
| 31 | self::SERVER_OK => '成功', | 32 | self::SERVER_OK => '成功', |
| 32 | self::IDENTIFIER_FAIL => '身份验证失败', | 33 | self::IDENTIFIER_FAIL => '身份验证失败', |
| 33 | self::ILLEGAL_PARAMS => '不合法的参数', | 34 | self::ILLEGAL_PARAMS => '不合法的参数', |
| 34 | self::ORDER_ILLEGAl => '提现订单有误', | 35 | self::ORDER_ILLEGAl => '提现订单有误', |
| 35 | self::ORDER_WITHDRAW_ERROR => '提现记录有误', | 36 | self::ORDER_WITHDRAW_ERROR => '提现记录有误', |
| 36 | self::ORDER_MONEY_ERROR => '提现金额有误', | 37 | self::ORDER_MONEY_ERROR => '提现金额有误', |
| 37 | self::ORDER_NO_FOUND => '未找到订单记录', | 38 | self::ORDER_NO_FOUND => '未找到订单记录', |
| 38 | self::WITHDRAW_NO_RECORD => '未匹配有效提现记录', | 39 | self::WITHDRAW_NO_RECORD => '未匹配有效提现记录', |
| 39 | self::WITHDRAW_HANDLE_ERROR => '提现操作失败', | 40 | self::WITHDRAW_HANDLE_ERROR => '提现操作失败', |
| 41 | self::WITHDRAW_CONFIRM_BILLS_FAIL => '确认账单失败', | ||
| 40 | ]; | 42 | ]; |
| 41 | 43 | ||
| 42 | 44 | ... | ... |
| ... | @@ -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\MusicianWithdrawBillConfirmRequest; | ||
| 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\MusicianWithdrawStatusRequest; | 9 | use App\Http\Requests\Musician\MusicianWithdrawStatusRequest; |
| ... | @@ -29,26 +30,25 @@ class MusicianWithdrawController extends Controller | ... | @@ -29,26 +30,25 @@ class MusicianWithdrawController extends Controller |
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | /** | 32 | /** |
| 32 | * 发票信息 | 33 | * 通过公司名称查询发票信息 |
| 33 | * @param MusicianWithdrawReceiptRequest $request | 34 | * @param MusicianWithdrawReceiptByNameRequest $request |
| 34 | * @return \Illuminate\Http\JsonResponse | 35 | * @return \Illuminate\Http\JsonResponse |
| 35 | */ | 36 | */ |
| 36 | public function receipt(MusicianWithdrawReceiptRequest $request) | 37 | public function receiptByName(MusicianWithdrawReceiptByNameRequest $request) |
| 37 | { | 38 | { |
| 38 | return $this->musicianWithdrawService->receiptInfo(); | 39 | return $this->musicianWithdrawService->receiptInfoByName(); |
| 39 | } | 40 | } |
| 40 | 41 | ||
| 41 | /** | 42 | /** |
| 42 | * 通过公司名称查询发票信息 | 43 | * 账单确认 |
| 43 | * @param MusicianWithdrawReceiptByNameRequest $request | 44 | * @param MusicianWithdrawBillConfirmRequest $request |
| 44 | * @return \Illuminate\Http\JsonResponse | 45 | * @return \Illuminate\Http\JsonResponse |
| 45 | */ | 46 | */ |
| 46 | public function receiptByName(MusicianWithdrawReceiptByNameRequest $request) | 47 | public function billConfirm(MusicianWithdrawBillConfirmRequest $request) |
| 47 | { | 48 | { |
| 48 | return $this->musicianWithdrawService->receiptInfoByName(); | 49 | return $this->musicianWithdrawService->billConfirm(); |
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | |||
| 52 | /** | 52 | /** |
| 53 | * 提现修改状态 | 53 | * 提现修改状态 |
| 54 | * @return \Illuminate\Http\JsonResponse | 54 | * @return \Illuminate\Http\JsonResponse | ... | ... |
| 1 | <?php | ||
| 2 | |||
| 3 | namespace App\Http\Requests\Musician; | ||
| 4 | |||
| 5 | use Illuminate\Foundation\Http\FormRequest; | ||
| 6 | |||
| 7 | /** | ||
| 8 | * Class MusicianWithdrawBillConfirmRequest | ||
| 9 | * @package App\Http\Requests\Musician | ||
| 10 | */ | ||
| 11 | class MusicianWithdrawBillConfirmRequest extends FormRequest | ||
| 12 | { | ||
| 13 | /** | ||
| 14 | * Determine if the user is authorized to make this request. | ||
| 15 | * | ||
| 16 | * @return bool | ||
| 17 | */ | ||
| 18 | public function authorize() | ||
| 19 | { | ||
| 20 | return true; | ||
| 21 | } | ||
| 22 | |||
| 23 | /** | ||
| 24 | * Get the validation rules that apply to the request. | ||
| 25 | * | ||
| 26 | * @return array | ||
| 27 | */ | ||
| 28 | public function rules() | ||
| 29 | { | ||
| 30 | return [ | ||
| 31 | 'busi_id' => ['required', 'bail'], | ||
| 32 | ]; | ||
| 33 | } | ||
| 34 | |||
| 35 | /** | ||
| 36 | * @return string[] | ||
| 37 | */ | ||
| 38 | public function messages(): array | ||
| 39 | { | ||
| 40 | return [ | ||
| 41 | 'busi_id.required' => '请提供分贝订单流水号', | ||
| 42 | ]; | ||
| 43 | } | ||
| 44 | } |
app/Models/Legal/StakeholderPrepaid.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 | |||
| 8 | /** | ||
| 9 | * Class StakeholderBalance | ||
| 10 | * @package App\Models\Legal | ||
| 11 | */ | ||
| 12 | class StakeholderPrepaid extends BaseModel | ||
| 13 | { | ||
| 14 | use HasFactory; | ||
| 15 | |||
| 16 | /** | ||
| 17 | * @var string | ||
| 18 | */ | ||
| 19 | protected $table = 'stakeholder_prepaid'; | ||
| 20 | } |
| ... | @@ -2,13 +2,20 @@ | ... | @@ -2,13 +2,20 @@ |
| 2 | 2 | ||
| 3 | namespace App\Services; | 3 | namespace App\Services; |
| 4 | 4 | ||
| 5 | use App\Helper\CacheKeyTools; | ||
| 5 | use App\Helper\ErrorCode; | 6 | use App\Helper\ErrorCode; |
| 7 | use App\Helper\RedisClient; | ||
| 6 | use App\Helper\Response; | 8 | use App\Helper\Response; |
| 7 | use App\Models\Legal\Company; | 9 | use App\Models\Legal\Company; |
| 8 | use App\Models\Legal\Contract; | 10 | use App\Models\Legal\Contract; |
| 9 | use App\Models\Legal\StakeholderIncomeByPayer; | 11 | use App\Models\Legal\StakeholderBalanceByPayer; |
| 12 | use App\Models\Legal\StakeholderBalanceDetail; | ||
| 13 | use App\Models\Legal\StakeholderIncomeSyncApp; | ||
| 10 | use App\Models\Legal\StakeholderIncomeSyncAppDetails; | 14 | use App\Models\Legal\StakeholderIncomeSyncAppDetails; |
| 15 | use App\Models\Legal\StakeholderPrepaid; | ||
| 11 | use App\Models\Legal\StakeholderSongCollate; | 16 | use App\Models\Legal\StakeholderSongCollate; |
| 17 | use Illuminate\Support\Facades\DB; | ||
| 18 | use Illuminate\Support\Facades\Log; | ||
| 12 | 19 | ||
| 13 | /** | 20 | /** |
| 14 | * Class MusicianAgreementService | 21 | * Class MusicianAgreementService |
| ... | @@ -97,4 +104,68 @@ class MusicianWithdrawService extends Service | ... | @@ -97,4 +104,68 @@ class MusicianWithdrawService extends Service |
| 97 | } | 104 | } |
| 98 | } | 105 | } |
| 99 | 106 | ||
| 107 | /** | ||
| 108 | * 确认账单 | ||
| 109 | * @return \Illuminate\Http\JsonResponse | ||
| 110 | */ | ||
| 111 | public function billConfirm() | ||
| 112 | { | ||
| 113 | if (RedisClient::instance('bills')->set(CacheKeyTools::billsConfirm($this->request->busi_id), true, 'EX', 3, 'NX')) { | ||
| 114 | |||
| 115 | $app = StakeholderIncomeSyncApp::query()->where(['busi_id'=>$this->request->busi_id, 'sync_status'=>0])->select(['id', 'subject_no', 'company_id', 'stakeholder_id', 'related_id'])->first(); | ||
| 116 | |||
| 117 | DB::beginTransaction(); | ||
| 118 | |||
| 119 | try { | ||
| 120 | |||
| 121 | if (empty($app)) throw new \Exception('找不到同步到分贝收益记录'); | ||
| 122 | |||
| 123 | $condition = "{$app->stakeholder_id}|{$app->subject_no}"; | ||
| 124 | |||
| 125 | $balance_detail = StakeholderBalanceDetail::query()->where(['status'=>0, 'company_id'=>$app->company_id, 'stakeholder_id'=>$app->stakeholder_id, 'bills_id'=>$app->related_id, 'subject_no'=>$app->subject_no])->first(); | ||
| 126 | |||
| 127 | if (empty($app)) throw new \Exception('找不到相关入账记录'); | ||
| 128 | |||
| 129 | |||
| 130 | //权益人-付款主体账户 | ||
| 131 | StakeholderBalanceByPayer::query()->where(['condition'=>$condition])->update([ | ||
| 132 | 'account' => DB::raw("account + {$balance_detail->real_share_amount}"), //总收入 | ||
| 133 | 'balance' => DB::raw("balance + {$balance_detail->real_share_amount}"), //剩余提现余额 | ||
| 134 | 'confirmed_amount' => DB::raw("confirmed_amount - {$balance_detail->real_share_amount}"), //待确认收益 | ||
| 135 | 'deduct_prepaid' => DB::raw("deduct_prepaid + {$balance_detail->deduct_prepaid}"), //核销预付 | ||
| 136 | 'freeze_prepaid' => DB::raw("freeze_prepaid - {$balance_detail->deduct_prepaid}"), //冻结预付 | ||
| 137 | ]); | ||
| 138 | |||
| 139 | //权益人-付款主体预付账本 | ||
| 140 | if (!empty($balance_detail['prepaid_detail'])) { | ||
| 141 | foreach ($balance_detail['prepaid_detail'] as $prepaid=>$prepaid_detail) { | ||
| 142 | StakeholderPrepaid::query()->where(['id'=>$prepaid])->update([ | ||
| 143 | 'freeze_prepaid' => DB::raw("freeze_prepaid - {$prepaid_detail['freeze_prepaid']}"), | ||
| 144 | 'deduct_prepaid' => DB::raw("deduct_prepaid + {$prepaid_detail['freeze_prepaid']}"), | ||
| 145 | ]); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | //改变状态 - 已入账 | ||
| 150 | StakeholderBalanceDetail::query()->where(['id'=>$balance_detail->id, 'status'=>0])->update(['status'=>1]); | ||
| 151 | |||
| 152 | //更新同步分贝记录 | ||
| 153 | StakeholderIncomeSyncApp::query()->where(['id'=>$app->id, 'withdraw_status'=>0])->update([ | ||
| 154 | 'withdraw_status' => 1, | ||
| 155 | ]); | ||
| 156 | |||
| 157 | DB::commit(); | ||
| 158 | return Response::success(); | ||
| 159 | |||
| 160 | } catch (\Exception $e) { | ||
| 161 | DB::rollBack(); | ||
| 162 | Log::info(__METHOD__.':确认账单失败', ['msg' => $e->getMessage(), 'params'=>$this->request->all()]); | ||
| 163 | return Response::error(ErrorCode::WITHDRAW_CONFIRM_BILLS_FAIL); | ||
| 164 | } | ||
| 165 | |||
| 166 | } else { | ||
| 167 | return Response::error(ErrorCode::REPEAT_SUBMIT); | ||
| 168 | } | ||
| 169 | } | ||
| 170 | |||
| 100 | } | 171 | } | ... | ... |
| ... | @@ -109,8 +109,9 @@ return [ | ... | @@ -109,8 +109,9 @@ return [ |
| 109 | 109 | ||
| 110 | //cache_key | 110 | //cache_key |
| 111 | 'key'=> [ | 111 | 'key'=> [ |
| 112 | 'bills_sync' =>'bills:sync', | 112 | 'bills_sync' => 'bills:sync', |
| 113 | 'channelname'=>'channelname', | 113 | 'channelname' => 'channelname', |
| 114 | 'bills_confirm' => 'busid:#busi_id#', | ||
| 114 | ] | 115 | ] |
| 115 | 116 | ||
| 116 | ]; | 117 | ]; | ... | ... |
-
Please register or sign in to post a comment