|
@@ -6,6 +6,7 @@ use app\model\Member;
|
|
|
use app\model\MemberAccount;
|
|
|
use app\model\MemberAccountList;
|
|
|
use app\model\Order;
|
|
|
+use app\model\PayDetail;
|
|
|
use app\model\SysConfig;
|
|
|
use support\Db;
|
|
|
use support\exception\BusinessException;
|
|
@@ -46,10 +47,18 @@ class CommissionEvent
|
|
|
//}
|
|
|
public function order($params)
|
|
|
{
|
|
|
- Log::info("计算消费提成",$params);
|
|
|
+ Log::info("计算消费提成", $params);
|
|
|
+ $accountListCategory = $params['member_account_list_category'] ?? '消费';
|
|
|
Db::beginTransaction();
|
|
|
try {
|
|
|
$order = Order::where('order_id', $params['orderId'])->where('order_status_payment', 'SUCCESS')->first();
|
|
|
+ $actualPaymentAmount = PayDetail::whereJsonContains('join_pay_object_json->order_id', $params['orderId'])
|
|
|
+ ->where('pay_status', 'SUCCESS')
|
|
|
+ ->whereIn('pay_prepayid', ['WXPAY', 'ALIPAY', 'OFFLINE_WXPAY', 'OFFLINE_ALIPAY', 'MONEY'])
|
|
|
+ ->sum('pay_amount');
|
|
|
+ if ($actualPaymentAmount == 0) {
|
|
|
+ throw new BusinessException("微信、支付宝、现金支付金额为0");
|
|
|
+ }
|
|
|
// 有传过来的
|
|
|
if (!empty($params['join_invite_member_id'])) {
|
|
|
$inviteMemberId = $params['join_invite_member_id'];
|
|
@@ -71,8 +80,7 @@ class CommissionEvent
|
|
|
$identity = 'REFERRER';
|
|
|
// 提成设置
|
|
|
$config = SysConfig::where('config_key', 'app-identity-referrer-config')->first();
|
|
|
-// $configParams = json_decode($config->config_value_json, true);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new BusinessException("直属上级非合伙人或者推荐官");
|
|
|
}
|
|
|
$configParams = json_decode($config->config_value_json, true);
|
|
@@ -84,19 +92,19 @@ class CommissionEvent
|
|
|
'order_id' => $order->order_id,
|
|
|
'master_member_id' => $order->join_order_member_id
|
|
|
];
|
|
|
- Log::info("提成参数",$accountListJson);
|
|
|
+ Log::info("提成参数", $accountListJson);
|
|
|
// 提成
|
|
|
- $this->commissionToMember($inviteMemberId, $accountListJson, round($configParams['commission']['relate-consum'] * $order->order_amount_pay, 2), '消费');
|
|
|
+ $this->commissionToMember($inviteMemberId, $accountListJson, round($configParams['commission']['relate-consum'] * $actualPaymentAmount, 2), $accountListCategory);
|
|
|
|
|
|
Db::commit();
|
|
|
_syslog("提成", "计算提成成功");
|
|
|
} catch (BusinessException $e) {
|
|
|
Db::rollBack();
|
|
|
- Log::error("计算消费提成异常",['msg'=>$e->getMessage()]);
|
|
|
+ Log::error("计算消费提成异常", ['msg' => $e->getMessage()]);
|
|
|
_syslog("提成", "计算提成失败:" . $e->getMessage());
|
|
|
} catch (\Exception $e) {
|
|
|
Db::rollBack();
|
|
|
- Log::error("计算消费提成异常",['msg'=>$e->getMessage()]);
|
|
|
+ Log::error("计算消费提成异常", ['msg' => $e->getMessage()]);
|
|
|
_syslog("提成", "计算提成失败");
|
|
|
}
|
|
|
}
|
|
@@ -131,8 +139,8 @@ class CommissionEvent
|
|
|
'member_account_list_json' => json_encode($accountListJson),
|
|
|
'member_account_list_addtimes' => time()
|
|
|
]);
|
|
|
- }catch (\Exception $e){
|
|
|
- Log::error("提成入账失败",['msg'=>$e->getMessage()]);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::error("提成入账失败", ['msg' => $e->getMessage()]);
|
|
|
}
|
|
|
}
|
|
|
}
|