From a0c74c7b7354b96fcb0c40b2bf8fba49c088cccf Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 17 Sep 2020 10:45:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?v1=E6=9C=8D=E5=8A=A1=E5=95=86=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/Service/SeparateAccountsService.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/Service/SeparateAccountsService.php b/app/Service/SeparateAccountsService.php index 32d2742..c07e91c 100644 --- a/app/Service/SeparateAccountsService.php +++ b/app/Service/SeparateAccountsService.php @@ -193,6 +193,7 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface $mpInfo = MpInfo::query()->find($market->mp_id); // 服务商 if (empty($mpInfo)) continue; + // $ssdbName = 'mm_'.$mmInfo->id.'_award_'.$store->id; $ssdbName = 'mm_'.$mpInfo->id.'_award_'.$store->id; // TODO 暂时在这里初始化 @@ -226,12 +227,14 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface $this->financialRecordService->mpAwardByNewStore($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_store'], '发展新商户【'.$store->name.'】'); // 服务商新商户奖励 } - } + // 线上订单服务商分账 + if ($orderMain->type == OrderMain::ORDER_TYPE_ONLINE) { + $rate = bcdiv($order['money'], $orderMain->total_money, 6); + $preMoney = bcmul($orderMain->money, $rate, 6); + $money = bcmul($preMoney, bcdiv($MmMpAwardConfig['separate_rate'], 100, 6), 2); + $this->financialRecordService->mpSeparateAccountByOLOrderComp($mpInfo->admin_user_id, $global_order_id, $money); + } - // 线上订单服务商分账 - if ($orderMain->type == OrderMain::ORDER_TYPE_ONLINE) { - $money = bcmul($orderMain->money, bcdiv($MmMpAwardConfig['separate_rate'], 100, 6), 2); - $this->financialRecordService->mpSeparateAccountByOLOrderComp($mpInfo->admin_user_id, $global_order_id, $money); } // =======服务商、市场经理奖励分账 / End======= From 330d80605650e24272f72dcb16a1a75f5b2b0e1d Mon Sep 17 00:00:00 2001 From: weigang Date: Thu, 17 Sep 2020 10:59:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=95=86=E5=88=86?= =?UTF-8?q?=E8=B4=A6=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Service/SeparateAccountsService.php | 59 +++++++++-------- .../SeparateAccountsService.php | 65 +++++++++++++++++++ 2 files changed, 97 insertions(+), 27 deletions(-) diff --git a/app/Service/SeparateAccountsService.php b/app/Service/SeparateAccountsService.php index c07e91c..694e41d 100644 --- a/app/Service/SeparateAccountsService.php +++ b/app/Service/SeparateAccountsService.php @@ -389,39 +389,44 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface // 当前订单(子)对应商户是否有市场经理绑定关系 $store = Store::query()->find($order['store_id']); // 商户 - $mmInfo = MmInfo::query()->where(['user_id' => $store->mm_user_id])->first(); // 市场经理 - $market = Market::query()->find($mmInfo->market_id); // 市场 + // $mmInfo = MmInfo::query()->where(['user_id' => $store->mm_user_id])->first(); // 市场经理 + $market = Market::query()->find($orderMain->market_id); // 市场 $mpInfo = MpInfo::query()->find($market->mp_id); // 服务商 - $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); - $ssdbName = 'mm_'.$mmInfo->id.'_award_'.$store->id; + if (!empty($mpInfo)) { + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + // $ssdbName = 'mm_'.$mmInfo->id.'_award_'.$store->id; + $ssdbName = 'mm_'.$mpInfo->id.'_award_'.$store->id; - // TODO 暂时在这里初始化 - if (!$ssdb->exec('hexists', $ssdbName, 'is_awarded')) { - $ssdb->exec('hset', $ssdbName, 'is_awarded', 0); - } + // TODO 暂时在这里初始化 + if (!$ssdb->exec('hexists', $ssdbName, 'is_awarded')) { + $ssdb->exec('hset', $ssdbName, 'is_awarded', 0); + } - if (!$ssdb->exec('hexists', $ssdbName, 'new_user_number')) { - $ssdb->exec('hset', $ssdbName, 'new_user_number', 0); - } + if (!$ssdb->exec('hexists', $ssdbName, 'new_user_number')) { + $ssdb->exec('hset', $ssdbName, 'new_user_number', 0); + } - // 平台新用户 - if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) { - $ssdb->exec('hincr', $ssdbName, 'new_user_number', 1); - $this->financialRecordService->mmAwardByPlatNewUser($mmInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mm_new_user'], '发展新用户'); // 市场经理新用户奖励 - $this->financialRecordService->mpAwardByPlatNewUser($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_user'], '市场经理「'.$mmInfo->name.'」发展新用户'); // 服务商新用户奖励 - } + // 平台新用户 + if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) { + $ssdb->exec('hincr', $ssdbName, 'new_user_number', 1); + // $this->financialRecordService->mmAwardByPlatNewUser($mmInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mm_new_user'], '发展新用户'); // 市场经理新用户奖励 + // $this->financialRecordService->mpAwardByPlatNewUser($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_user'], '市场经理「'.$mmInfo->name.'」发展新用户'); // 服务商新用户奖励 + $this->financialRecordService->mpAwardByPlatNewUser($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_user'], '发展新用户'); // 服务商新用户奖励 + } - $record = $ssdb->exec('hgetall', $ssdbName); - // 判断是否已经奖励过新拓展商户的奖励,没有的话判断新用户个数是否达到要求,进行奖励 - if ( - !empty($record) - &&$record['is_awarded']==0 - &&$record['new_user_number']>=$MmMpAwardConfig['limit_new_user_number'] - ) { // 存在记录且未发放奖励,同时新用户数已经超过10 - $ssdb->exec('hset', $ssdbName, 'is_awarded', 1); - $this->financialRecordService->mmAwardByNewStore($mmInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mm_new_store'], '发展新商户【'.$store->name.'】'); // 市场经理新商户奖励 - $this->financialRecordService->mpAwardByNewStore($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_store'], '市场经理「'.$mmInfo->name.'」发展新新商户【'.$store->name.'】'); // 服务商新商户奖励 + $record = $ssdb->exec('hgetall', $ssdbName); + // 判断是否已经奖励过新拓展商户的奖励,没有的话判断新用户个数是否达到要求,进行奖励 + if ( + !empty($record) + &&$record['is_awarded']==0 + &&$record['new_user_number']>=$MmMpAwardConfig['limit_new_user_number'] + ) { // 存在记录且未发放奖励,同时新用户数已经超过10 + $ssdb->exec('hset', $ssdbName, 'is_awarded', 1); + // $this->financialRecordService->mmAwardByNewStore($mmInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mm_new_store'], '发展新商户【'.$store->name.'】'); // 市场经理新商户奖励 + // $this->financialRecordService->mpAwardByNewStore($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_store'], '市场经理「'.$mmInfo->name.'」发展新新商户【'.$store->name.'】'); // 服务商新商户奖励 + $this->financialRecordService->mpAwardByNewStore($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_store'], '发展新商户【'.$store->name.'】'); // 服务商新商户奖励 + } } // =======服务商、市场经理奖励分账 / End======= diff --git a/app/Service/v3/Implementations/SeparateAccountsService.php b/app/Service/v3/Implementations/SeparateAccountsService.php index dc8ed78..59e485a 100644 --- a/app/Service/v3/Implementations/SeparateAccountsService.php +++ b/app/Service/v3/Implementations/SeparateAccountsService.php @@ -348,6 +348,71 @@ class SeparateAccountsService implements SeparateAccountsServiceInterface // =======线下订单支付完成商户分账 / End======= + // =======线下订单支付完成商户分账 / End======= + + // =======服务商、市场经理奖励分账 / Start======= + // 前提A:新用户下单并且订单完成(线上、线下都行) + // 奖励规则A:用户是平台新用户,奖励市场经理 1 元,服务商 0.5 元,如果是线上订单,服务商有6%的订单分成 + // 前提B:新商户旗下产生 10 个新用户 + // 奖励规则B:奖励市场经理 25 元,服务商 10 元(仅仅奖励一次) + // 前提C:用户线上下单并且订单完成 + // 奖励规则C:奖励服务商账单 6% 分成 + // 判断是新商户:入驻绑定的时候把关系存在SSDB + // =======服务商、市场经理奖励分账 / Start======= + + $MmMpAwardConfig = [ + 'mm_new_user' => 1, + 'mm_new_store' => 25, + 'mp_new_user' => 0.5, + 'mp_new_store' => 10, + 'separate_rate' => 6, + 'limit_new_user_number' => 10, + ]; + + // 当前订单(子)对应商户是否有市场经理绑定关系 + $store = Store::query()->find($order['store_id']); // 商户 + // $mmInfo = MmInfo::query()->where(['user_id' => $store->mm_user_id])->first(); // 市场经理 + $market = Market::query()->find($orderMain->market_id); // 市场 + $mpInfo = MpInfo::query()->find($market->mp_id); // 服务商 + + if (!empty($mpInfo)) { + $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); + // $ssdbName = 'mm_'.$mmInfo->id.'_award_'.$store->id; + $ssdbName = 'mm_'.$mpInfo->id.'_award_'.$store->id; + + // TODO 暂时在这里初始化 + if (!$ssdb->exec('hexists', $ssdbName, 'is_awarded')) { + $ssdb->exec('hset', $ssdbName, 'is_awarded', 0); + } + + if (!$ssdb->exec('hexists', $ssdbName, 'new_user_number')) { + $ssdb->exec('hset', $ssdbName, 'new_user_number', 0); + } + + // 平台新用户 + if ($this->userService->isPlatformNewUser($orderMain->user_id, $orderMain->id)) { + $ssdb->exec('hincr', $ssdbName, 'new_user_number', 1); + // $this->financialRecordService->mmAwardByPlatNewUser($mmInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mm_new_user'], '发展新用户'); // 市场经理新用户奖励 + // $this->financialRecordService->mpAwardByPlatNewUser($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_user'], '市场经理「'.$mmInfo->name.'」发展新用户'); // 服务商新用户奖励 + $this->financialRecordService->mpAwardByPlatNewUser($mpInfo->admin_user_id, $globalOrderId, $MmMpAwardConfig['mp_new_user'], '发展新用户'); // 服务商新用户奖励 + } + + $record = $ssdb->exec('hgetall', $ssdbName); + // 判断是否已经奖励过新拓展商户的奖励,没有的话判断新用户个数是否达到要求,进行奖励 + if ( + !empty($record) + &&$record['is_awarded']==0 + &&$record['new_user_number']>=$MmMpAwardConfig['limit_new_user_number'] + ) { // 存在记录且未发放奖励,同时新用户数已经超过10 + $ssdb->exec('hset', $ssdbName, 'is_awarded', 1); + // $this->financialRecordService->mmAwardByNewStore($mmInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mm_new_store'], '发展新商户【'.$store->name.'】'); // 市场经理新商户奖励 + // $this->financialRecordService->mpAwardByNewStore($mpInfo->admin_user_id, $global_order_id, $MmMpAwardConfig['mp_new_store'], '市场经理「'.$mmInfo->name.'」发展新新商户【'.$store->name.'】'); // 服务商新商户奖励 + $this->financialRecordService->mpAwardByNewStore($mpInfo->admin_user_id, $globalOrderId, $MmMpAwardConfig['mp_new_store'], '发展新商户【'.$store->name.'】'); // 服务商新商户奖励 + } + } + + // =======服务商、市场经理奖励分账 / End======= + Db::commit(); return true; } catch (\Exception $e) {