增加初步分佣算法,待完善后台分佣规则
This commit is contained in:
parent
d97dbe8fcf
commit
4015a21417
47
app/common/model/system/supplychain/SupplyChainLevel.php
Normal file
47
app/common/model/system/supplychain/SupplyChainLevel.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: CRMEB Team <admin@crmeb.com>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
namespace app\common\model\system\supplychain;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
|
||||||
|
// 供应链后台团队等级表
|
||||||
|
class SupplyChainLevel extends BaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
// 设置当前模型的数据库连接
|
||||||
|
protected $connection = 'nongke';
|
||||||
|
protected $table = 'fa_supply_level';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-03-30
|
||||||
|
*/
|
||||||
|
public static function tablePk(): string
|
||||||
|
{
|
||||||
|
return 'id';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-03-30
|
||||||
|
*/
|
||||||
|
public static function tableName(): string
|
||||||
|
{
|
||||||
|
return 'fa_supply_level';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
app/common/model/system/supplychain/SupplyChainTeam.php
Normal file
53
app/common/model/system/supplychain/SupplyChainTeam.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
// | Author: CRMEB Team <admin@crmeb.com>
|
||||||
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
namespace app\common\model\system\supplychain;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\BaseModel;
|
||||||
|
|
||||||
|
use app\common\model\system\supplychain\SupplyChainLevel;
|
||||||
|
|
||||||
|
// 供应链后台团队表
|
||||||
|
class SupplyChainTeam extends BaseModel
|
||||||
|
{
|
||||||
|
|
||||||
|
// 设置当前模型的数据库连接
|
||||||
|
protected $connection = 'nongke';
|
||||||
|
protected $table = 'fa_supply_team';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-03-30
|
||||||
|
*/
|
||||||
|
public static function tablePk(): string
|
||||||
|
{
|
||||||
|
return 'id';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020-03-30
|
||||||
|
*/
|
||||||
|
public static function tableName(): string
|
||||||
|
{
|
||||||
|
return 'fa_supply_team';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function level()
|
||||||
|
{
|
||||||
|
return $this->hasOne(SupplyChainLevel::class, 'id', 'fa_supply_team_id');
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,7 @@ use app\common\repositories\user\UserExtractRepository;
|
|||||||
use app\common\repositories\user\UserHistoryRepository;
|
use app\common\repositories\user\UserHistoryRepository;
|
||||||
use app\common\repositories\user\UserRelationRepository;
|
use app\common\repositories\user\UserRelationRepository;
|
||||||
use app\common\repositories\user\UserRepository;
|
use app\common\repositories\user\UserRepository;
|
||||||
|
use app\common\model\system\supplychain\SupplyChainTeam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class User
|
* Class User
|
||||||
@ -176,6 +177,11 @@ class User extends BaseModel
|
|||||||
return $this->hasOne(UserBrokerage::class, 'brokerage_level', 'member_level')->where('type',1);
|
return $this->hasOne(UserBrokerage::class, 'brokerage_level', 'member_level')->where('type',1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function supplyChainTeam()
|
||||||
|
{
|
||||||
|
return $this->hasOne(SupplyChainTeam::class, 'fa_supply_team_id', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $spreadUid
|
* @param $spreadUid
|
||||||
* @author xaboy
|
* @author xaboy
|
||||||
|
@ -385,20 +385,29 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
//自动打印订单
|
//自动打印订单
|
||||||
$this->autoPrinter($order->order_id, $order->mer_id);
|
$this->autoPrinter($order->order_id, $order->mer_id);
|
||||||
}
|
}
|
||||||
if ($groupOrder->user->spread_uid) {
|
|
||||||
|
|
||||||
// 来源检测,1 服务小组 2 普通商品
|
// 来源检测,1 服务小组 2 普通商品
|
||||||
if($order->source == 1)
|
if($order->source == 1)
|
||||||
{
|
{
|
||||||
\think\facade\Log::record('供应链佣金--开始');
|
// 验证是否服务小组人员
|
||||||
Queue::push(SupplyChainOrderBrokerAgeJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_pay_num', 'inc' => 1]);
|
if ($groupOrder->user->fa_supply_team_id) {
|
||||||
\think\facade\Log::record('供应链佣金---结束');
|
Queue::push(SupplyChainOrderBrokerAgeJob::class, [
|
||||||
|
'uid' => $groupOrder->user->uid,
|
||||||
|
'inc' => $order->pay_price, // 订单金额
|
||||||
|
'order_sn' => $order->order_sn, // 订单编号
|
||||||
|
'order_id' => $order->order_id, // 订单ID
|
||||||
|
'mer_id' => $order->mer_id, // 商户ID
|
||||||
|
'brokerage_price' => $order->supply_chain_price, // 订单佣金金额
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_pay_num', 'inc' => 1]);
|
|
||||||
|
if ($groupOrder->user->spread_uid) {
|
||||||
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_money', 'inc' => $groupOrder->pay_price]);
|
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_money', 'inc' => $groupOrder->pay_price]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app()->make(UserRepository::class)->update($groupOrder->uid, [
|
app()->make(UserRepository::class)->update($groupOrder->uid, [
|
||||||
'pay_count' => Db::raw('pay_count+' . count($groupOrder->orderList)),
|
'pay_count' => Db::raw('pay_count+' . count($groupOrder->orderList)),
|
||||||
'pay_price' => Db::raw('pay_price+' . $groupOrder->pay_price),
|
'pay_price' => Db::raw('pay_price+' . $groupOrder->pay_price),
|
||||||
@ -1619,6 +1628,11 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
])->page($page, $limit)->order('pay_time DESC')->append(['refund_status'])->select();
|
])->page($page, $limit)->order('pay_time DESC')->append(['refund_status'])->select();
|
||||||
|
|
||||||
foreach ($list as $order) {
|
foreach ($list as $order) {
|
||||||
|
|
||||||
|
if ($order->order_type == 1) {
|
||||||
|
$order->append(['take', 'refund_status']);
|
||||||
|
}
|
||||||
|
|
||||||
if ($order->activity_type == 2) {
|
if ($order->activity_type == 2) {
|
||||||
if ($order->presellOrder) {
|
if ($order->presellOrder) {
|
||||||
$order->presellOrder->append(['activeStatus']);
|
$order->presellOrder->append(['activeStatus']);
|
||||||
|
@ -18,6 +18,9 @@ use app\common\repositories\user\UserBrokerageRepository;
|
|||||||
use app\common\repositories\user\UserRepository;
|
use app\common\repositories\user\UserRepository;
|
||||||
use crmeb\interfaces\JobInterface;
|
use crmeb\interfaces\JobInterface;
|
||||||
use think\facade\Log;
|
use think\facade\Log;
|
||||||
|
use app\common\model\system\supplychain\SupplyChainBorkerage;
|
||||||
|
use app\common\model\system\supplychain\SupplyChainTeam;
|
||||||
|
use app\common\model\system\supplychain\SupplyChainLevel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -29,26 +32,44 @@ class SupplyChainOrderBrokerAgeJob implements JobInterface
|
|||||||
public function fire($job, $data)
|
public function fire($job, $data)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
// 获取当前用户
|
||||||
$user = app()->make(UserRepository::class)->get($data['uid']);
|
$user = app()->make(UserRepository::class)->get($data['uid']);
|
||||||
if ($user) {
|
$supplyTeam = SupplyChainTeam::find($user['fa_supply_team_id']); // 获取供应链团队
|
||||||
$flag = true;
|
$supplyLevel = SupplyChainLevel::find($supplyTeam['supply_level_id']); // 获取供应链等级
|
||||||
if ($data['type'] == 'spread_money') {
|
$price = $data['brokerage_price']; // 待分润金额 == 订单佣金金额
|
||||||
$user->spread_pay_price = bcadd($user->spread_pay_price, $data['inc'], 2);
|
|
||||||
} else if ($data['type'] == 'spread_pay_num') {
|
// 判断 存在数据的话,进行分润
|
||||||
$user->spread_pay_count = bcadd($user->spread_pay_count, $data['inc'], 0);
|
if($supplyTeam)
|
||||||
} else {
|
{
|
||||||
$flag = false;
|
// 可获得金额
|
||||||
}
|
$usrPrice = sprintf("%.2f", $price/100*$supplyLevel['rate']);
|
||||||
if ($flag) {
|
|
||||||
$user->save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($user && $user->is_promoter) {
|
|
||||||
app()->make(UserBrokerageRepository::class)->inc($user, $data['type'], $data['inc']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 分润数据
|
||||||
|
$dataArr = [
|
||||||
|
'user_id' => $data['uid'], // 用户ID
|
||||||
|
'pay_price' => $data['inc'], // 订单金额
|
||||||
|
'order_sn' => $data['order_sn'], // 订单编号
|
||||||
|
'supply_sn' => $data['order_sn'], // 订单编号
|
||||||
|
'order_id' => $data['order_id'], // 订单ID
|
||||||
|
'mer_id' => $data['mer_id'], // 商户ID
|
||||||
|
'supply_level_id' => $supplyLevel['id'], // 分佣等级ID
|
||||||
|
'brokerage_price' => $usrPrice, // 获取的佣金金额
|
||||||
|
'user_info' => $user['nickname'], // 用户名
|
||||||
|
'fa_supply_chain_id' => $supplyTeam['id'], // 供应链团队ID
|
||||||
|
];
|
||||||
|
|
||||||
|
// 储存小组服务分佣记录
|
||||||
|
$status = SupplyChainBorkerage::create($dataArr);
|
||||||
|
// 增加小组服务佣金明细
|
||||||
|
|
||||||
|
\think\facade\Log::record($status);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::info('分销等级同步失败: ' . var_export($data, 1) . $e->getMessage());
|
Log::info('小组服务佣金同步失败: ' . var_export($data, 1) . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$job->delete();
|
$job->delete();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user