修改订单完结分佣

This commit is contained in:
lcc
2025-08-01 13:29:53 +08:00
parent a671c09be7
commit e1f80d538e
6 changed files with 119 additions and 54 deletions
+3 -2
View File
@@ -37,8 +37,9 @@ class Plan extends CI_Controller
$plan[] = array('url' => base_url(array('plan', 'score', 'mergeBiz')), 'interval' => 1); //合并上月门店分数日志
$plan[] = array('url' => base_url(array('plan', 'score', 'mergeAvgUser')), 'interval' => 1); //合并本月个人分数日志
$plan[] = array('url' => base_url(array('plan', 'score', 'mergeAvgBiz')), 'interval' => 1); //合并本月门店分数日志
//线索分佣
$plan[] = array('url' => base_url(array('plan', 'agent/commission', 'bizClues')), 'interval' => 1); //合并本月门店分数日志
$plan[] = array('url' => base_url(array('plan', 'agent/commission', 'bizClues')), 'interval' => 1);//线索分佣
$plan[] = array('url' => base_url(array('plan', 'agent/commission', 'orderSubsidy')), 'interval' => 1);//订单完结分佣
$plan[] = array('url' => base_url(array('plan', 'report', 'index')), 'interval' => 20); //门店日报
+44 -7
View File
@@ -1,11 +1,5 @@
<?php
/**
* Notes:狸车宝任务
* Created on: 2021/10/19 17:15
* Created by: dengbw
*/
class Commission extends HD_Controller
{
private $dir;
@@ -16,12 +10,29 @@ class Commission extends HD_Controller
$this->load->model('receiver/receiver_clues_model', 'clues_model');
$this->load->model('biz/biz_account_model', 'account_model');
$this->load->model('biz/biz_accountLog_model', 'bizAccountLog');
$this->load->model('receiver/order/receiver_orders_model');
$this->load->model('agent/receiver_order_subsidy_model');
$this->load->model('agent/auto_product_coupon_model');
$this->load->model('agent/auto_product_model');
$this->load->model('agent/pingan/pingan_users_cmmssn_model');
$this->load->model('agent/organization/organization_cmmssn_model', 'mdOrganizationCmmssn');
$this->load->model('agent/organization/organization_model');
$this->load->model('agent/pingan/pingan_users_model');
$this->receiver_order_subsidy_model->set_db('agentdb');
$this->auto_product_coupon_model->set_db('agentdb');
$this->auto_product_model->set_db('agentdb');
$this->pingan_users_cmmssn_model->set_db('agentdb');
$this->mdOrganizationCmmssn->set_db('agentdb');
$this->organization_model->set_db('agentdb');
$this->pingan_users_model->set_db('agentdb');
$this->load->library('myResponse');
$this->dir = 'commission';
}
/**
* 店铺线索分佣
* 线索分佣
* @return void
*/
public function bizClues()
@@ -54,4 +65,30 @@ class Commission extends HD_Controller
debug_log($e->getMessage(), $log_path, $this->dir);
}
}
/**
* 订单分佣
* @return void
*/
public function orderSubsidy()
{
$log_path = 'order_subsidy.log';
try {
$page = 1;
$size = 20;
$where = ['commStatus' => Receiver_order_subsidy_model::COMM_STATUS_WAIT];
/** @var ReceiverOrderSubsidyEntity[] $rows */
$rows = $this->receiver_order_subsidy_model->select($where, 'id asc', $page, $size, '', 'ReceiverOrderSubsidyEntity');
if (!$rows) {
throw new Exception('没有需要分佣的记录');
}
foreach ($rows as $row) {
debug_log('开始分佣,ID:' . $row->id, $log_path, $this->dir);
$result = $row->commission();
debug_log("分佣结束:" . $result->getMessage(), $log_path, $this->dir);
}
} catch (Exception $e) {
debug_log($e->getMessage(), $log_path, $this->dir);
}
}
}
+19 -11
View File
@@ -156,7 +156,7 @@ class HD_Model extends CI_Model {
* @param $data
* @return mixed
*/
public function replace($data)
public function replace($data)
{
if($data)
{
@@ -202,7 +202,7 @@ class HD_Model extends CI_Model {
return $this->db->query($sql);
}
}
/**
* 获取单条数据
* @param $where
@@ -271,16 +271,24 @@ class HD_Model extends CI_Model {
$this->db->from($this->table_name);
$this->db->limit($limit, $offset);
$query = $this->db->get();
$result = $query ? $query->result_array() : [];
if($obj && file_exists($class = APPPATH.'libraries/entity/'.ucfirst($obj).'.php'))
if($obj)
{
require_once $class;
if(class_exists($obj))
{
$result = $this->db->get($this->table_name, $limit, $offset)->custom_result_object($obj);
if(file_exists($class = APPPATH.'libraries/entity/'.ucfirst($obj).'.php')){
require_once $class;
if(class_exists($obj))
{
return $query->custom_result_object($obj);
}
}
if(file_exists($class = COMMPATH.'libraries/entity/'.ucfirst($obj).'.php')){
require_once $class;
if(class_exists($obj))
{
return $query->custom_result_object($obj);
}
}
}
return $result;
return $query ? $query->result_array() : [];
}
/**
@@ -549,7 +557,7 @@ class HD_Model extends CI_Model {
* @param array $param
* @return mixed
*/
public function un_file_cache($func, $param =array())
public function un_file_cache($func, $param =array())
{
if(IF_FILE_CACHE)
{
@@ -565,7 +573,7 @@ class HD_Model extends CI_Model {
* @param $type
* @return bool
*/
public function del_cache($method, $type, $skey = '')
public function del_cache($method, $type, $skey = '')
{
$cache = & load_cache($type);
$db = $this->load->database('default', true);
@@ -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());
}
@@ -24,6 +24,12 @@ class Receiver_order_subsidy_model extends HD_Model
self::STATUS_FAIL => '发放失败'
];
//分佣状态
const COMM_STATUS_WAIT = 0; //待处理
const COMM_STATUS_SUCCESS = 1; //成功
const COMM_STATUS_FAIL = 2;//失败
const COMM_STATUS_NOT = 3;//不需要分佣
public function __construct()
{
parent::__construct($this->table_name, 'default');
@@ -15,4 +15,6 @@ class Biz_accountLog_model extends HD_Model
{
parent::__construct($this->table_name, 'default');
}
}