diff --git a/app/common/controller/FinPaymentApplyController.php b/app/common/controller/FinPaymentApplyController.php index 57c4b75..37fc4d7 100644 --- a/app/common/controller/FinPaymentApplyController.php +++ b/app/common/controller/FinPaymentApplyController.php @@ -66,6 +66,8 @@ class FinPaymentApplyController extends BaseController $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['claimed_at'])) + $data['claimed_at'] = date('Y-m-d H:i:s', $data['claimed_at']); return $data; } diff --git a/app/common/controller/FinReceiptController.php b/app/common/controller/FinReceiptController.php index 486bfde..d8ef9c2 100644 --- a/app/common/controller/FinReceiptController.php +++ b/app/common/controller/FinReceiptController.php @@ -53,6 +53,24 @@ class FinReceiptController extends BaseController return $this->error($e->getMessage()); } } + + /** + * 更新 + * + * @param Request $request 请求对象 + * @return mixed 返回更新成功的数据或信息 + */ + public function payment(Request $request) + { + try { + $data = $this->validate($this->service->getValidator(), $request->post(), 'update'); + $res = $this->service->serviceUpdatePayment($request, $data); + return $this->success([], '更新成功'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + /** * 列表页数据格式化 * @@ -61,8 +79,10 @@ class FinReceiptController extends BaseController */ protected function indexFormat($data) { - if (isset($data['created_at'])) + if (isset($data['created_at'])){ + $data['claim_timeout'] = (($data['created_at'] < (time()-86400)) && empty($data['payment_apply_id'])) ?1:0; $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + } if (isset($data['updated_at'])) $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); if (isset($data['arrived_at'])) diff --git a/app/common/model/FinPaymentApply.php b/app/common/model/FinPaymentApply.php index f02f137..82f81cb 100644 --- a/app/common/model/FinPaymentApply.php +++ b/app/common/model/FinPaymentApply.php @@ -40,7 +40,7 @@ class FinPaymentApply extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files', 'created_at', 'updated_at']; + protected $fillable = ['id', 'apply_no', 'doc_user_id', 'sales_user_id', 'corp_id', 'account_id', 'payment_account', 'payment_entity', 'entity_type', 'currency_id', 'amount', 'swift', 'remit_bank', 'country_id', 'remitter', 'exchange_rate', 'total_amount_cny', 'voucher_file', 'voucher_name', 'submit_files','receipt_id','claimed_at', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 diff --git a/app/common/service/FinReceiptService.php b/app/common/service/FinReceiptService.php index bc9ff6a..6e7b7e3 100644 --- a/app/common/service/FinReceiptService.php +++ b/app/common/service/FinReceiptService.php @@ -3,6 +3,7 @@ namespace app\common\service; use app\common\logic\FinReceiptLogic; +use app\common\model\FinPaymentApply; use app\common\model\FinReceiptHis; use app\common\validate\FinReceiptValidate; use app\common\traits\crud\CrudServiceTrait; @@ -89,6 +90,7 @@ class FinReceiptService $config['where']['id'] = $p['id']; break; case 'update': + case 'payment': case 'destroy': $config['where']['id'] = $p['id']; break; @@ -272,4 +274,28 @@ class FinReceiptService $this->afterServiceUpdate(['id'=>$id]); return $res; } + + /** + * 更新计算折让金额 + * @param Request $request + * @param array $data + * @param string $scene + * @return mixed + */ + public function serviceUpdatePayment(Request $request, array $data = [], string $scene = 'payment') + { + $payment_apply_id = $request->input('payment_apply_id'); + $id = $request->input('id'); + $data = $this->preProcess(ucfirst($scene), $data, $request); + $config = $this->buildQueryConfig($request, $scene); + FinPaymentApply::where('id', $payment_apply_id)->update(['receipt_id' => $id, 'claimed_at' => time()]); + + //折让金额 + $payment = FinPaymentApply::where('id', $payment_apply_id)->first(); + $receipt = FinReceipt::find($id); + $data['discount_amount'] = $payment->amount - $payment->amount ?? 0; + + $updated = $this->logicUpdateBy($config, $data); + return $this->postProcess(ucfirst($scene), $data); + } } \ No newline at end of file diff --git a/config/route.php b/config/route.php index 29c4e6e..b962ee9 100644 --- a/config/route.php +++ b/config/route.php @@ -358,7 +358,7 @@ Route::group('/admin', function () { Route::any('/show', [app\common\controller\FinReceiptController::class, 'show']); Route::any('/store', [app\common\controller\FinReceiptController::class, 'store']); Route::any('/update', [app\common\controller\FinReceiptController::class, 'update']); - Route::any('/payment', [app\common\controller\FinReceiptController::class, 'update']); + Route::any('/payment', [app\common\controller\FinReceiptController::class, 'payment']); Route::any('/destroy', [app\common\controller\FinReceiptController::class, 'destroy']); Route::any('/credit', [app\common\controller\FinReceiptController::class, 'credit']); });