From dd8a5504dba3a45d53f6bb00d2ae721b20d77f66 Mon Sep 17 00:00:00 2001 From: weigang Date: Fri, 21 Aug 2020 19:36:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=AE=8C=E6=88=90=E5=88=86?= =?UTF-8?q?=E8=B4=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/FinancialRecord.php | 27 +++++++++---------------- app/Model/UserBalance.php | 7 +++++-- app/Service/FinancialRecordService.php | 6 +++--- app/Service/SeparateAccountsService.php | 18 ++++++++--------- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/app/Model/FinancialRecord.php b/app/Model/FinancialRecord.php index 0096c9a..b56adbe 100644 --- a/app/Model/FinancialRecord.php +++ b/app/Model/FinancialRecord.php @@ -42,24 +42,17 @@ class FinancialRecord extends Model const SOURCE_TYPE_ORDER = 1; /** - * 流水类型,大的分类,<=50是奖励,>50是分账 - * - * MONEY_TYPE_PLAT_NEW_USER - * 社区服务点新用户奖励(线上订单完成) / 1 - * - * MONEY_TYPE_FIRST_ORDER - * 社区服务点新用户线上首单奖励(线上订单完成) / 2 - * - * MONEY_TYPE_OL_ORDER - * 社区服务点用户线上订单分账(线上订单完成) / 51 + * 流水类型,大的分类,<100是奖励分账等收入项 >=100是提现消费等支出项 */ - const MONEY_TYPE_PLAT_NEW_USER = 1; - const MONEY_TYPE_FIRST_ORDER = 2; - const MONEY_TYPE_OL_ORDER = 3; - const MONEY_TYPE_STORE_PLAT_NEW_USER = 4; - const MONEY_TYPE_STORE_FIRST_ORDER = 5; - const MONEY_TYPE_USER_OFL_ORDER = 100; - const MONEY_TYPE_USER_OL_ORDER = 101; + const MONEY_TYPE_PLAT_NEW_USER = 1; // 社区服务点新用户奖励(线上订单完成) + const MONEY_TYPE_FIRST_ORDER = 2; // 社区服务点新用户线上首单奖励(线上订单完成) + const MONEY_TYPE_OL_ORDER = 3; // 社区服务点用户线上订单分账(线上订单完成) + const MONEY_TYPE_STORE_PLAT_NEW_USER = 4; // 商户平台新用户奖励 + const MONEY_TYPE_STORE_FIRST_ORDER = 5; // 商户当日首单奖励 + const MONEY_TYPE_STORE_OL_ORDER_COMP = 6; // 商户线上订单完成收入 + const MONEY_TYPE_STORE_OFL_ORDER_COMP = 7; // 商户线下订单完成收入 + const MONEY_TYPE_USER_OFL_ORDER = 100; // 用户线下支付订单 + const MONEY_TYPE_USER_OL_ORDER = 101; // 用户线上支付订单 /** * 状态 diff --git a/app/Model/UserBalance.php b/app/Model/UserBalance.php index 62f988e..3883747 100644 --- a/app/Model/UserBalance.php +++ b/app/Model/UserBalance.php @@ -3,7 +3,6 @@ declare (strict_types=1); namespace App\Model; -use Hyperf\DbConnection\Model\Model; /** */ class UserBalance extends Model @@ -23,7 +22,11 @@ class UserBalance extends Model * * @var array */ - protected $fillable = []; + protected $fillable = [ + 'source_id', + 'user_type', + 'balance' + ]; /** * The attributes that should be cast to native types. * diff --git a/app/Service/FinancialRecordService.php b/app/Service/FinancialRecordService.php index f6e5c80..574de5c 100644 --- a/app/Service/FinancialRecordService.php +++ b/app/Service/FinancialRecordService.php @@ -64,7 +64,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface // 维护社区服务点余额 $balance = UserBalance::firstOrNew([ 'user_type' => UserBalance::USER_TYPE_CS, - 'source_id' => $source_id + 'source_id' => $user_id ]); $balance->balance = bcadd($balance->balance, $money); $balance->save(); @@ -79,7 +79,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface // 维护社区服务点余额 $balance = UserBalance::firstOrNew([ 'user_type' => UserBalance::USER_TYPE_CS, - 'source_id' => $source_id + 'source_id' => $user_id ]); $balance->balance = bcadd($balance->balance, $money); $balance->save(); @@ -94,7 +94,7 @@ class FinancialRecordService implements FinancialRecordServiceInterface // 维护社区服务点余额 $balance = UserBalance::firstOrNew([ 'user_type' => UserBalance::USER_TYPE_CS, - 'source_id' => $source_id + 'source_id' => $user_id ]); $balance->balance = bcadd($balance->balance, $money); $balance->save(); diff --git a/app/Service/SeparateAccountsService.php b/app/Service/SeparateAccountsService.php index 109dcd2..4217a24 100644 --- a/app/Service/SeparateAccountsService.php +++ b/app/Service/SeparateAccountsService.php @@ -59,7 +59,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface } // =======用户支付流水 / Start======= - $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $orderMain->id, $orderMain->money); + $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $global_order_id, $orderMain->money); // =======用户支付流水 / End======= } @@ -113,7 +113,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface StoreAccount::query()->insert(array_merge($storeAccountBase, $storeAccount)); // 新商户流水 - $this->financialRecordService->storeByOLOrderComp($store->user_id, $orderMain->id ,$order['money']); + $this->financialRecordService->storeByOLOrderComp($store->user_id, $global_order_id ,$order['money']); } // =======商户订单收入流水 / End======= @@ -141,13 +141,13 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface // 平台新用户 if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) { - $this->financialRecordService->communityAwardByPlatNewUser($communityBind->source_id, $orderMain->global_order_id, $award['new_user_reward']); - $this->financialRecordService->communityAwardByPlatNewUserFirstOLOrder($communityBind->source_id, $orderMain->global_order_id, $award['first_reward']); + $this->financialRecordService->communityAwardByPlatNewUser($communityBind->source_id, $global_order_id, $award['new_user_reward']); + $this->financialRecordService->communityAwardByPlatNewUserFirstOLOrder($communityBind->source_id, $global_order_id, $award['first_reward']); } // 账单分成 $money = bcmul($orderMain->money, bcdiv($award['flow_reward'], 100, 6), 2); - $this->financialRecordService->communitySeparateAccountsByOrderComp($communityBind->source_id, $orderMain->global_order_id, $money); + $this->financialRecordService->communitySeparateAccountsByOrderComp($communityBind->source_id, $global_order_id, $money); } // =======社区服务点分账 / End======= @@ -193,7 +193,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface try { // =======用户支付流水 / Start======= - $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $orderMain->id, $orderMain->money); + $this->financialRecordService->userByOFLOrderPaid($orderMain->user_id, $global_order_id, $orderMain->money); // =======用户支付流水 / End======= // =======线下订单支付完成商户分账 / Start======= @@ -224,7 +224,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface $store = Store::find($order->store_id); // 新商户订单流水 - $this->financialRecordService->storeByOFLOrderComp($store->user_id, $orderMain->id, $order->money); + $this->financialRecordService->storeByOFLOrderComp($store->user_id, $global_order_id, $order->money); $needAward = false; $awardAmount = 0; @@ -239,7 +239,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface 'category' => 3, ]; // 新商户流水 - $this->financialRecordService->storeAwardByPlatNewUserOFLOrder($store->user_id, $orderMain->id, $awardAmount); + $this->financialRecordService->storeAwardByPlatNewUserOFLOrder($store->user_id, $global_order_id, $awardAmount); $needAward = true; } else { @@ -261,7 +261,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface 'category' => 4, ]; // 新商户流水 - $this->financialRecordService->storeAwardByTodayFirstOFLOrder($store->user_id, $orderMain->id, $awardAmount); + $this->financialRecordService->storeAwardByTodayFirstOFLOrder($store->user_id, $global_order_id, $awardAmount); $needAward = true; }