123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549 |
- <?php
- namespace App\Http\Controllers\Manage\Finance;
- use App\Http\Controllers\Manage\Finance\Transformers\PaymentDetailTransformer;
- use App\Http\Controllers\Manage\Finance\Transformers\PaymentTransformer;
- use App\Libs\PayHelper;
- use App\Modules\Channel\Services\ChannelService;
- use App\Modules\Finance\Models\FinanceMerchantStat;
- use App\Modules\Finance\Models\LiquidatedStat;
- use App\Modules\Finance\Services\CashAccountService;
- use App\Modules\Finance\Services\FinanceMerchantStatService;
- use App\Modules\Finance\Services\FinancialConfigService;
- use App\Modules\Finance\Services\LiquidatedStatService;
- use App\Modules\Finance\Services\PaymentService;
- use App\Modules\Finance\Services\WithdrawCashService;
- use Illuminate\Http\Request;
- use DB;
- class PaymentController extends BaseController
- {
-
-
- function add_payment(Request $request) {
- $withdraw_cash_id = $request->has('withdraw_cash_id') ? $request->input('withdraw_cash_id') : '';
- if(!is_numeric($withdraw_cash_id)) {
- return response()->error("PARAM_ERROR");
- }
- $amount = $request->has('amount') ? $request->input('amount') : '';
- if(!is_numeric($amount) || (float)$amount <= 0) {
- return response()->error("PARAM_ERROR");
- }
- $userId = $this->getLoginUserId();
- $remark = $request->has('remark') ? $request->input('remark') : '';
- $withdrawCash = WithdrawCashService::getWithdrawCash($withdraw_cash_id);
- if(empty($withdrawCash)) {
- return response()->error("PARAM_ERROR");
- }
-
- if($withdrawCash['is_company'] == 1) {
- return response()->error("PAYMENT_AUTO_NOT_OPEN");
- }
-
- if(WithdrawCashService::isEditWithdrawCashStatus($withdraw_cash_id)) {
- return response()->error("PAYMENT_WITHDRAW_MONEY_TOO");
- }
-
- $money = (float)$withdrawCash['amount'] - (float)$withdrawCash['tallage'];
- if($amount != $money) {
- return response()->error("PAYMENT_WITHDRAW_MONEY");
- }
- $channelId = $withdrawCash['distribution_channel_id'];
-
- if(FinancialConfigService::isFrozenDistributionChannel($channelId)) {
- return response()->error("WITHDRAW_CASH_AMOUNT_FROZEN");
- }
-
- if(!CashAccountService::isCashAccountExits($channelId)) {
- return response()->error("WITHDRAW_CASH_AMOUNT_ACCOUNT");
- }
-
- if(!env('PAYMENT_AUTO_PAY_ON')) {
- return response()->error("PAYMENT_AUTO_NOT_OPEN");
- }
- $isTD = 0;
- $source = $request->has('source') ? $request->input('source') : '';
- if ("tl" == $source || "ll" == $source) {
- if("tl" == $source) {
-
- $tonglianpayLiquidatedStatData = LiquidatedStatService::getLiquidatedStatSingleBySource(config('common.tonglianpay'));
- if(!empty($tonglianpayLiquidatedStatData) && $tonglianpayLiquidatedStatData['account_balance_amount_day'] > ($money - 1)) {
-
- $isTD = 2;
- }
- }
- if("ll" == $source) {
-
- $lianlianpayLiquidatedStatData = LiquidatedStatService::getLiquidatedStatSingleBySource(config('common.lianlianpay'));
- if(!empty($lianlianpayLiquidatedStatData) && $lianlianpayLiquidatedStatData['account_balance_amount_day'] > ($money - 1)) {
-
- $isTD = 1;
- }
- }
- } else {
-
- $tonglianpayLiquidatedStatData = LiquidatedStatService::getLiquidatedStatSingleBySource(config('common.tonglianpay'));
- if($isTD == 0) {
-
- if(!empty($tonglianpayLiquidatedStatData) && $tonglianpayLiquidatedStatData['account_balance_amount_day'] > ($money - 1)) {
-
- $isTD = 2;
- }
- }
-
- $lianlianpayLiquidatedStatData = LiquidatedStatService::getLiquidatedStatSingleBySource(config('common.lianlianpay'));
- if($isTD == 0) {
-
- if(!empty($lianlianpayLiquidatedStatData) && $lianlianpayLiquidatedStatData['account_balance_amount_day'] > ($money - 1)) {
-
- $isTD = 1;
- }
- }
- }
- if($isTD == 0) {
-
-
-
- return response()->error("PAYMENT_CHANNEL_AMOUNT_WITHOUT");
- }
-
- if(env('PAYMENT_AUTO_PAY_TEST') == 2) {
- if($isTD == 1) {
-
- PaymentService::makeThreeSourcePayment($userId, $withdraw_cash_id, (float)$amount, $remark, $lianlianpayLiquidatedStatData);
- return response()->success();
- }
- if($isTD == 2) {
-
- PaymentService::makeThreeSourcePayment($userId, $withdraw_cash_id, (float)$amount, $remark, $tonglianpayLiquidatedStatData);
- return response()->success();
- }
- } else {
-
- $tradeNo = "测试_".$channelId;
- $pay_merchant_source = "测试";
- if($isTD == 1) {
- $pay_merchant_source = $lianlianpayLiquidatedStatData['pay_merchant_source'];
- }
- if($isTD == 2) {
- $pay_merchant_source = $tonglianpayLiquidatedStatData['pay_merchant_source'];
- }
-
- $payment = PaymentService::addPayment($withdraw_cash_id, $amount, $remark, $pay_merchant_source, $tradeNo, WithdrawCashService::getWithdrawCashStatusStr(32), "测试", $withdrawCash['is_company'], 0);
-
- FinanceMerchantStatService::createOrUpdate($channelId, $pay_merchant_source, -$amount);
-
- LiquidatedStatService::updateAccountBalanceAmountDay($pay_merchant_source, -$amount);
-
- WithdrawCashService::updateWithdrawCashStatus($withdraw_cash_id, $userId, 32, $remark, $tradeNo);
- return response()->success();
- }
-
- return response()->error("PAYMENT_CHANNEL_AMOUNT_WITHOUT");
- }
-
- function add_paymentPersonMade(Request $request) {
- $withdraw_cash_id = $request->has('withdraw_cash_id') ? $request->input('withdraw_cash_id') : '';
- if(!is_numeric($withdraw_cash_id)) {
- return response()->error("PARAM_ERROR");
- }
- $userId = $this->getLoginUserId();
- $amount_person = $request->has('amount_person') ? $request->input('amount_person') : '';
- if(!is_numeric($amount_person)) {
- return response()->error("PARAM_ERROR");
- }
- $trade_no = $request->has('trade_no') ? $request->input('trade_no') : '';
- if(empty($trade_no)) {
- return response()->error("PARAM_ERROR");
- }
- $remark = $request->has('remark') ? $request->input('remark') : '';
- $remark = "[人工打款]{".$remark."}";
- $withdrawCash = WithdrawCashService::getWithdrawCash($withdraw_cash_id);
- if(empty($withdrawCash)) {
- return response()->error("PARAM_ERROR");
- }
-
- if(WithdrawCashService::isWithdrawCashStatusSuccess($withdraw_cash_id)) {
- return response()->error("PAYMENT_WITHDRAW_MONEY_TOO");
- }
- $channelId = $withdrawCash['distribution_channel_id'];
-
- if(FinancialConfigService::isFrozenDistributionChannel($channelId)) {
- return response()->error("ACCOUNT_FRONZEN");
- }
-
- $amount = (float)$withdrawCash['amount'] - (float)$withdrawCash['tallage'];
-
-
-
-
-
- PaymentService::makePersonMadePayment($userId, $withdraw_cash_id, $amount, $remark, $trade_no, $amount_person);
- return response()->success();
- }
-
- function get_list(Request $request) {
- $withdraw_cash_id = $request->has('withdraw_cash_id') ? $request->input('withdraw_cash_id') : '';
- $start_time = $request->has('start_time') && !empty($request->input('start_time')) ? date('Ymd',strtotime($request->input('start_time'))) : '';
- $end_time = $request->has('end_time') && !empty($request->input('end_time')) ? date('Ymd',strtotime($request->input('end_time'))) : '';
- $end_time = self::getMaxDay($end_time);
- $payments = PaymentService::getPaymentList($withdraw_cash_id, $start_time, $end_time);
- return response()->pagination(new PaymentTransformer(), $payments);
- }
-
- function get_listDetail(Request $request) {
- $distribution_channel_id = $request->has('distribution_channel_id') ? $request->input('distribution_channel_id') : '';
- $distribution_channel_name = $request->has('distribution_channel_name') ? $request->input('distribution_channel_name') : '';
- $withdraw_cash_id = $request->has('withdraw_cash_id') ? $request->input('withdraw_cash_id') : '';
- $start_time = $request->has('start_time') && !empty($request->input('start_time')) ? date('Ymd',strtotime($request->input('start_time'))) : '';
- $end_time = $request->has('end_time') && !empty($request->input('end_time')) ? date('Ymd',strtotime($request->input('end_time'))) : '';
- $end_time = self::getMaxDay($end_time);
- $account_name = $request->has('account_name') ? $request->input('account_name') : '';
- $search_name = $request->has('search_name') ? $request->input('search_name') : '';
- $status = $request->has('status') ? $request->input('status') : '';
- $is_company = $request->has('is_company') ? $request->input('is_company') : '';
- $params = [
- 'withdraw_cash_id'=>$withdraw_cash_id,
- 'channel_id'=>$distribution_channel_id,
- 'channel_name'=>$distribution_channel_name,
- 'start_date'=>$start_time,
- 'end_date'=>$end_time,
- 'account_name'=>$account_name,
- 'search_name'=>$search_name,
- 'is_company'=>$is_company,
- ];
- $payments = PaymentService::getPaymentDetailList($params, $status);
- return response()->pagination(new PaymentDetailTransformer(), $payments);
- }
-
- function updatePaymentStatus(Request $request)
- {
- $id = $request->has('id') ? $request->input('id') : '';
-
- if (!$id) {
- return response()->error("PARAM_EMPTY");
- }
- $status = WithdrawCashService::getWithdrawCashStatusStr(10);
- $result = PaymentService::updateSimplePaymentStatus($id, $status);
- if ($result) {
- return response()->success();
- } else {
- return response()->error("HANDLE_FAILED");
- }
- }
- function test_add_payment(Request $request)
- {
- $payType = "ALLINPAY";
- $payType = "LIANLIANPAY";
- return response()->success();
- }
- }
|