修改订单完结分佣
This commit is contained in:
@@ -21,8 +21,8 @@ class ReceiverOrderSubsidyEntity
|
||||
$ci = &get_instance();
|
||||
$ci->load->helper('string');
|
||||
$ci->load->model('agent/auto_product_coupon_model');
|
||||
$ci->load->model('agent/auto_product_model');
|
||||
$ci->load->model('agent/receiver_order_subsidy_model');
|
||||
$ci->load->model('agent/auto_product_model');
|
||||
$ci->load->model('agent/pingan/pingan_users_cmmssn_model');
|
||||
$ci->load->model('agent/pingan/pingan_users_model');
|
||||
$ci->load->model('agent/organization/organization_cmmssn_model', 'mdOrganizationCmmssn');
|
||||
@@ -31,10 +31,6 @@ class ReceiverOrderSubsidyEntity
|
||||
$ci->load->model('receiver/receiver_clues_model');
|
||||
$ci->load->model('biz/biz_account_model', 'account_model');
|
||||
$ci->load->model('biz/biz_accountLog_model', 'accountlog_model');
|
||||
$ci->receiver_orders_model->set_db('ssdb');
|
||||
$ci->receiver_clues_model->set_db('ssdb');
|
||||
$ci->account_model->set_db('ssdb');
|
||||
$ci->accountlog_model->set_db('ssdb');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,6 +42,10 @@ class ReceiverOrderSubsidyEntity
|
||||
public function ifCheckSubsidy($status, $reason = '')
|
||||
{
|
||||
$ci = &get_instance();
|
||||
$ci->receiver_orders_model->set_db('ssdb');
|
||||
$ci->receiver_clues_model->set_db('ssdb');
|
||||
$ci->account_model->set_db('ssdb');
|
||||
$ci->accountlog_model->set_db('ssdb');
|
||||
$ci->receiver_order_subsidy_model->db->trans_begin();
|
||||
$ci->account_model->db->trans_begin();
|
||||
try {
|
||||
@@ -143,17 +143,32 @@ class ReceiverOrderSubsidyEntity
|
||||
}
|
||||
}
|
||||
|
||||
public function cmmssn()
|
||||
/**
|
||||
* 分佣
|
||||
* @return MyResponse
|
||||
*/
|
||||
public function commission()
|
||||
{
|
||||
$log_path = 'commission.log';
|
||||
$log_dir = 'order_subsidy';
|
||||
$ci = &get_instance();
|
||||
try {
|
||||
$log_path = 'cmmssn.log';
|
||||
$log_dir = 'pingan';
|
||||
debug_log("开始分佣:" . $this->id, $log_path, $log_dir);
|
||||
$cmmssn = $ci->pingan_users_cmmssn_model->get(['orderId' => $this->orderId]);
|
||||
$cmmssn = $ci->pingan_users_cmmssn_model->get(['cfId' => $this->orderId, 'cfType' => Pingan_users_cmmssn_model::CF_TYPE_ORDER_OWN]);
|
||||
if ($cmmssn) {
|
||||
throw new Exception("订单已经存在分佣记录");
|
||||
}
|
||||
$productCoupon = $ci->auto_product_coupon_model->get(['id' => $this->couponId]);
|
||||
$product = $ci->auto_product_model->get(['id' => $productCoupon['product_id']]);
|
||||
if (!$product) {
|
||||
throw new Exception("产品不存在");
|
||||
}
|
||||
$money = $product['orderCommission'];
|
||||
debug_log("订单分佣金额:" . $money, $log_path, $log_dir);
|
||||
if ($money <= 0) { //不需要分佣
|
||||
$ci->receiver_order_subsidy_model->update(['commStatus' => Receiver_order_subsidy_model::COMM_STATUS_NOT], ['id' => $this->id]);
|
||||
return new MyResponse(EXIT_SUCCESS, "不需要分佣,分佣金额为:{$money}");
|
||||
}
|
||||
$order = $ci->receiver_orders_model->get(['id' => $this->orderId]);
|
||||
if (!$order) {
|
||||
throw new Exception("订单不存在");
|
||||
@@ -170,102 +185,98 @@ class ReceiverOrderSubsidyEntity
|
||||
throw new Exception("线索不存在绑定用户关系");
|
||||
}
|
||||
//获取分佣配置
|
||||
$cmmssn = $ci->mdOrganizationCmmssn->get(['teamId' => $pinanUser['orgTeamId'], 'status' => 1]);
|
||||
$cmmssn = $ci->mdOrganizationCmmssn->get(['teamId' => $pinanUser['orgTeamId'], 'status' => 0]);
|
||||
if (!$cmmssn) {
|
||||
throw new Exception("分佣配置不存在");
|
||||
}
|
||||
//团队设置分佣等级
|
||||
$level = $ci->organization_model->getTeamLevel($pinanUser['orgTeamId']);
|
||||
$brokerage1 = $brokerage2 = $brokerage3 = $brokerage4 = 0;
|
||||
$sourceId = 0;
|
||||
if ($clues['cf2_id'] == 39) { //产品来源
|
||||
$product = $ci->auto_product_model->get(['id' => $clues['out_id']]);
|
||||
$brokerage1 = $product['orderCommission'] * ($cmmssn['orderLevel1'] / 100) ?: 0;
|
||||
$brokerage2 = $product['orderCommission'] * ($cmmssn['orderLevel2'] / 100) ?: 0;
|
||||
$brokerage3 = $product['orderCommission'] * ($cmmssn['orderLevel3'] / 100) ?: 0;
|
||||
$brokerage4 = $product['orderCommission'] * ($cmmssn['orderLevel4'] / 100) ?: 0;
|
||||
$sourceId = $product['id'] ?: 0;
|
||||
} elseif ($clues['cf2_id'] == 40) { //活动获取分佣配置
|
||||
|
||||
}
|
||||
$brokerage1 = $money * ($cmmssn['cluesLevel1'] / 100) ?: 0;
|
||||
$brokerage2 = $money * ($cmmssn['cluesLevel2'] / 100) ?: 0;
|
||||
$brokerage3 = $money * ($cmmssn['cluesLevel3'] / 100) ?: 0;
|
||||
$brokerage4 = $money * ($cmmssn['cluesLevel4'] / 100) ?: 0;
|
||||
debug_log('分佣金额:' . json_encode([$brokerage1, $brokerage2, $brokerage3, $brokerage4]), $log_path, $log_dir);
|
||||
$add_data = [];
|
||||
if ($brokerage1 && $clues['area_id']) { //一级佣金
|
||||
$add_data[] = [
|
||||
'cfId' => $this->orderId,
|
||||
'sourceId' => $sourceId,
|
||||
'cfType' => Pingan_users_cmmssn_model::CF_TYPE_ORDER_TEAM,
|
||||
'money' => $brokerage1,
|
||||
'pinganUserId' => $clues['area_id'],
|
||||
'teamId' => 0,
|
||||
'depId' => 0,
|
||||
'areaId' => $clues['area_id'],
|
||||
'createTime' => date('Y-m-d H:i:s')
|
||||
'createTime' => date('Y-m-d H:i:s'),
|
||||
'bizId' => $this->bizId
|
||||
];
|
||||
}
|
||||
if ($brokerage2 && $clues['dep_id']) { //二级佣金
|
||||
$add_data[] = [
|
||||
'cfId' => $this->orderId,
|
||||
'sourceId' => $sourceId,
|
||||
'cfType' => Pingan_users_cmmssn_model::CF_TYPE_ORDER_TEAM,
|
||||
'money' => $brokerage2,
|
||||
'pinganUserId' => $clues['dep_id'],
|
||||
'teamId' => 0,
|
||||
'depId' => $clues['dep_id'],
|
||||
'areaId' => $clues['area_id'] ?: 0,
|
||||
'createTime' => date('Y-m-d H:i:s')
|
||||
'createTime' => date('Y-m-d H:i:s'),
|
||||
'bizId' => $this->bizId
|
||||
];
|
||||
}
|
||||
if ($level >= 4) { //4级
|
||||
if ($brokerage3 && $clues['team_id']) {
|
||||
$add_data[] = [
|
||||
'cfId' => $this->orderId,
|
||||
'sourceId' => $sourceId,
|
||||
'cfType' => Pingan_users_cmmssn_model::CF_TYPE_ORDER_TEAM,
|
||||
'money' => $brokerage3,
|
||||
'pinganUserId' => $clues['team_id'],
|
||||
'teamId' => $clues['team_id'],
|
||||
'depId' => $clues['dep_id'],
|
||||
'areaId' => $clues['area_id'] ?: 0,
|
||||
'createTime' => date('Y-m-d H:i:s')
|
||||
'createTime' => date('Y-m-d H:i:s'),
|
||||
'bizId' => $this->bizId
|
||||
];
|
||||
}
|
||||
if ($brokerage4 && $clues['pingan_user_id']) {
|
||||
$add_data[] = [
|
||||
'cfId' => $this->orderId,
|
||||
'sourceId' => $sourceId,
|
||||
'cfType' => Pingan_users_cmmssn_model::CF_TYPE_ORDER_OWN,
|
||||
'money' => $brokerage4,
|
||||
'pinganUserId' => $clues['pingan_user_id'],
|
||||
'teamId' => $clues['team_id'],
|
||||
'depId' => $clues['dep_id'],
|
||||
'areaId' => $clues['area_id'] ?: 0,
|
||||
'createTime' => date('Y-m-d H:i:s')
|
||||
'createTime' => date('Y-m-d H:i:s'),
|
||||
'bizId' => $this->bizId
|
||||
];
|
||||
}
|
||||
} else { //三级
|
||||
if ($brokerage3 && $clues['pingan_user_id']) {
|
||||
$add_data[] = [
|
||||
'cfId' => $this->orderId,
|
||||
'sourceId' => $sourceId,
|
||||
'cfType' => Pingan_users_cmmssn_model::CF_TYPE_ORDER_TEAM,
|
||||
'cfType' => Pingan_users_cmmssn_model::CF_TYPE_ORDER_OWN,
|
||||
'money' => $brokerage3,
|
||||
'pinganUserId' => $clues['team_id'],
|
||||
'teamId' => 0,
|
||||
'depId' => $clues['dep_id'],
|
||||
'areaId' => $clues['area_id'] ?: 0,
|
||||
'createTime' => date('Y-m-d H:i:s')
|
||||
'createTime' => date('Y-m-d H:i:s'),
|
||||
'bizId' => $this->bizId
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
debug_log('分佣数据:' . json_encode($add_data, JSON_UNESCAPED_UNICODE), $log_path, $log_dir);
|
||||
if (count($add_data)) {
|
||||
$result = $ci->pingan_users_cmmssn_model->add_batch($add_data);
|
||||
if (!$result) {
|
||||
throw new Exception("保存失败");
|
||||
}
|
||||
}
|
||||
$ci->receiver_order_subsidy_model->update(['commStatus' => Receiver_order_subsidy_model::COMM_STATUS_SUCCESS], ['id' => $this->id]);
|
||||
debug_log('分佣结束', $log_path, $log_dir);
|
||||
return new MyResponse(EXIT_SUCCESS, '保存成功');
|
||||
} catch (Exception $e) {
|
||||
$ci->receiver_order_subsidy_model->update(['commStatus' => Receiver_order_subsidy_model::COMM_STATUS_FAIL], ['id' => $this->id]);
|
||||
debug_log($e->getMessage(), $log_path, $log_dir);
|
||||
return new MyResponse(EXIT_ERROR, $e->getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user