Merge branch 'develop'

This commit is contained in:
monanxiao 2023-03-14 15:37:25 +08:00
commit a87d9e6fab
8 changed files with 404 additions and 30 deletions

View File

@ -112,7 +112,11 @@ class UserBillDao extends BaseDao
public function lockBrokerage($uid)
{
$lst = UserBill::getDB()->where('category', 'brokerage')
->whereIn('type', ['order_one', 'order_two'])->where('uid', $uid)->where('status', 0)->field('link_id,number')->select()->toArray();
->whereIn('type', ['order_one', 'order_two'])
->where('uid', $uid)
->where('status', 0)
->field('link_id,number')
->select()->toArray();
$refundPrice = 0;
if (count($lst)) {
$refundPrice = -1 * UserBill::getDB()->whereIn('link_id', array_column($lst, 'link_id'))->where('uid', $uid)
@ -230,6 +234,9 @@ class UserBillDao extends BaseDao
->when(isset($where['mer_id']) && $where['mer_id'] !== '', function ($query) use ($where) {
$query->where('mer_id', $where['mer_id']);
})
->when(isset($where['source']) && $where['source'] !== '', function ($query) use ($where) {
$query->where('source', $where['source']);
})
->when(isset($where['link_id']) && $where['link_id'] !== '', function ($query) use ($where) {
$query->where('link_id', $where['link_id']);
});

View 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';
}
}

View 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');
}
}

View File

@ -25,6 +25,7 @@ use app\common\repositories\user\UserExtractRepository;
use app\common\repositories\user\UserHistoryRepository;
use app\common\repositories\user\UserRelationRepository;
use app\common\repositories\user\UserRepository;
use app\common\model\system\supplychain\SupplyChainTeam;
/**
* Class User
@ -176,6 +177,11 @@ class User extends BaseModel
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
* @author xaboy

View File

@ -385,20 +385,29 @@ class StoreOrderRepository extends BaseRepository
//自动打印订单
$this->autoPrinter($order->order_id, $order->mer_id);
}
if ($groupOrder->user->spread_uid) {
// 来源检测1 服务小组 2 普通商品
if($order->source == 1)
{
\think\facade\Log::record('供应链佣金--开始');
Queue::push(SupplyChainOrderBrokerAgeJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_pay_num', 'inc' => 1]);
\think\facade\Log::record('供应链佣金---结束');
}else{
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_pay_num', 'inc' => 1]);
// 来源检测1 服务小组 2 普通商品
if($order->source == 1)
{
// 验证是否服务小组人员
if ($groupOrder->user->fa_supply_team_id) {
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{
if ($groupOrder->user->spread_uid) {
Queue::push(UserBrokerageLevelJob::class, ['uid' => $groupOrder->user->spread_uid, 'type' => 'spread_money', 'inc' => $groupOrder->pay_price]);
}
}
}
app()->make(UserRepository::class)->update($groupOrder->uid, [
'pay_count' => Db::raw('pay_count+' . count($groupOrder->orderList)),
'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();
foreach ($list as $order) {
if ($order->order_type == 1) {
$order->append(['take', 'refund_status']);
}
if ($order->activity_type == 2) {
if ($order->presellOrder) {
$order->presellOrder->append(['activeStatus']);

View File

@ -72,10 +72,12 @@ class UserBillRepository extends BaseRepository
$this->dao = $dao;
}
public function userList($where, $uid, $page, $limit)
public function userList($where, $uid, $page, $limit, $source = 2)
{
$where['uid'] = $uid;
$where['source'] = $source;
$query = $this->dao->search($where)->order('create_time DESC');
$count = $query->count();
$list = $query->setOption('field', [])->field('bill_id,pm,title,number,balance,mark,create_time,status')->page($page, $limit)->select();
return compact('count', 'list');

View File

@ -34,6 +34,7 @@ use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\exception\ValidateException;
use think\facade\Db;
use app\common\model\user\UserBill;
class User extends BaseController
{
@ -80,7 +81,32 @@ class User extends BaseController
$user = $this->user;
$make = app()->make(UserBrokerageRepository::class);
$user->append(['one_level_count', 'lock_brokerage', 'two_level_count', 'spread_total', 'yesterday_brokerage', 'total_extract', 'total_brokerage', 'total_brokerage_price']);
$show_brokerage = (bool)$make->search(['type' => 0])->count();
$source = $this->request->param('source');
$source = !isset($source)?2:$source; // 默认来源为2 普通商品订单
// 小组采购佣金另外处理
if($source == 1)
{
$data = [
// 'total_brokerage_price' => $this->totalBrokerage($user->uid, $source), // 可提现金额
'total_brokerage_price' => $user->total_brokerage, // 可提现金额
'total_extract' => $this->lockBrokerage($user->uid, $source), // 已提现金额
'yesterday_brokerage' => $this->yesterdayBrokerage($user->uid, $source), // 昨日提现收益
'lock_brokerage' => $this->lockBrokerage($user->uid, $source), // 冻结中金额
'spread_total' => $user->spread_total,
'total_brokerage' => $user->total_brokerage,
'brokerage_price' => $user->brokerage_price,
'show_brokerage' => $show_brokerage,
'broken_day' => (int)systemConfig('lock_brokerage_timer'),
'user_extract_min' => (int)systemConfig('user_extract_min'),
];
return app('json')->success($data);
}
$data = [
'total_brokerage_price' => $user->total_brokerage_price,
'lock_brokerage' => $user->lock_brokerage,
@ -100,6 +126,40 @@ class User extends BaseController
return app('json')->success($data);
}
public function lockBrokerage($uid, $source)
{
$lst = UserBill::getDB()->where('category', 'brokerage')
->whereIn('type', ['order_one', 'order_two'])
->where('uid', $uid)
->where('source', $source)
->where('status', 0)
->field('link_id,number')
->select()->toArray();
$refundPrice = 0;
if (count($lst)) {
$refundPrice = -1 * UserBill::getDB()->whereIn('link_id', array_column($lst, 'link_id'))->where('uid', $uid)
->where('category', 'brokerage')->whereIn('type', ['refund_two', 'refund_one'])->sum('number');
}
foreach ($lst as $bill) {
$refundPrice = bcadd($refundPrice, $bill['number'], 2);
}
return $refundPrice;
}
public function yesterdayBrokerage($uid, $source)
{
return getModelTime(UserBill::getDB()->where('category', 'brokerage')
->whereIn('type', ['order_one', 'order_two'])->where('source', $source)->where('uid', $uid), 'yesterday')->sum('number');
}
public function totalBrokerage($uid, $source)
{
return bcsub(UserBill::getDB()->where('category', 'brokerage')
->whereIn('type', ['order_one', 'order_two'])->where('source', $source)->where('uid', $uid)->sum('number'),
UserBill::getDB()->where('uid', $uid)
->where('category', 'brokerage')->whereIn('type', ['refund_two', 'refund_one'])->sum('number'), 2);
}
public function brokerage_all()
{
return app('json')->success(app()->make(UserBrokerageRepository::class)->all(0));
@ -163,10 +223,13 @@ class User extends BaseController
*/
public function brokerage_list(UserBillRepository $billRepository)
{
$source = $this->request->param('source');
$source = !isset($source)?2:$source; // 默认来源为2 普通商品订单
[$page, $limit] = $this->getPage();
return app('json')->success($billRepository->userList([
'category' => 'brokerage',
], $this->request->uid(), $page, $limit));
], $this->request->uid(), $page, $limit, $source));
}
/**

View File

@ -18,6 +18,10 @@ use app\common\repositories\user\UserBrokerageRepository;
use app\common\repositories\user\UserRepository;
use crmeb\interfaces\JobInterface;
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;
use app\common\repositories\user\UserBillRepository;
/**
*
@ -29,26 +33,204 @@ class SupplyChainOrderBrokerAgeJob implements JobInterface
public function fire($job, $data)
{
try {
// 获取当前用户
$user = app()->make(UserRepository::class)->get($data['uid']);
if ($user) {
$flag = true;
if ($data['type'] == 'spread_money') {
$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);
} else {
$flag = false;
}
if ($flag) {
$user->save();
}
}
if ($user && $user->is_promoter) {
app()->make(UserBrokerageRepository::class)->inc($user, $data['type'], $data['inc']);
$supplyTeam = SupplyChainTeam::find($user['fa_supply_team_id']); // 获取供应链团队
$supplyLevel = SupplyChainLevel::find($supplyTeam['supply_level_id']); // 获取供应链等级
$price = $data['brokerage_price']; // 待分润金额 == 订单佣金金额
// 判断 存在数据的话,进行分润
if($supplyTeam)
{
// 可获得金额
$usrPrice = sprintf("%.2f", $price/100*$supplyLevel['rate']);
}
// 分润数据
$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);
// 写入冻结佣金
$userBillRepository = app()->make(UserBillRepository::class);
// 加入账单记录 佣金明细
$userBillRepository->incBill($data['uid'], 'brokerage', 'order_one', [
'link_id' => $data['order_id'],
'status' => 0,
'title' => '获得采购佣金',
'number' => $usrPrice, // 增加金额
'mark' => $data['order_sn'] . '采购:' . $data['inc'] . '元,获得采购佣金' . $usrPrice,
'balance' => 0,
'source' => 1 // 1 小组采购 2 普通商品
]);
$userRepository = app()->make(UserRepository::class);
// 增加
$userRepository->incBrokerage($data['uid'], $price);
// 增加小组服务佣金明细
// $onePrice = '0.00'; // 一级佣金
// $twoPrice = '0.00'; // 二级佣金
// $threePrice = '0.00'; // 三级佣金
// $fourPrice = '0.00'; // 四级佣金
// $fivePrice = '0.00'; // 五级佣金
// $sixPrice = '0.00'; // 六级佣金
// $supplyTeamLevelOne = ['rate' => 0];
// $supplyTeamLevelTwo = ['rate' => 0];
// $supplyTeamLevelThree = ['rate' => 0];
// $supplyTeamLevelFour = ['rate' => 0];
// $supplyTeamLevelFive = ['rate' => 0];
// $supplyTeamLevelSix = ['rate' => 0];
// if($supplyTeamLevelOne)
// {
// // 一级可获得金额
// $onePrice = sprintf("%.2f", $price/100*$supplyTeamLevelOne['rate']);
// // 分润数据
// $dataArrOne = [
// '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' => $onePrice, // 获取的佣金金额
// 'user_info' => $user['nickname'], // 用户名
// 'fa_supply_chain_id' => $supplyTeam['id'], // 供应链团队ID
// ];
// SupplyChainBorkerage::create($dataArrOne);
// }
// if($supplyTeamLevelTwo)
// {
// // 二级可获得金额
// $twoPrice = sprintf("%.2f", $price/100*$supplyTeamLevelTwo['rate']);
// // 分润数据
// $dataArrTwo = [
// '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
// ];
// SupplyChainBorkerage::create($dataArrTwo);
// }
// if($supplyTeamLevelThree)
// {
// // 三级可获得金额
// $threePrice = sprintf("%.2f", $price/100*$supplyTeamLevelThree['rate']);
// // 分润数据
// $dataArrThree = [
// '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
// ];
// SupplyChainBorkerage::create($dataArrThree);
// }
// if($supplyTeamLevelFour)
// {
// // 四级可获得金额
// $fourPrice = sprintf("%.2f", $price/100*$supplyTeamLevelFour['rate']);
// // 分润数据
// $dataArrFour = [
// '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
// ];
// SupplyChainBorkerage::create($dataArrFour);
// }
// if($supplyTeamLevelFive)
// {
// // 五级可获得金额
// $fivePrice = sprintf("%.2f", $price/100*$supplyTeamLevelFive['rate']);
// // 分润数据
// $dataArrFive = [
// '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' => $fivePrice, // 获取的佣金金额
// 'user_info' => $user['nickname'], // 用户名
// 'fa_supply_chain_id' => $supplyTeam['id'], // 供应链团队ID
// ];
// SupplyChainBorkerage::create($dataArrFive);
// }
// if($supplyTeamLevelSix)
// {
// // 六级可获得金额
// $sixPrice = sprintf("%.2f", $price/100*$supplyTeamLevelSix['rate']);
// // 分润数据
// $dataArrSix = [
// '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' => $sixPrice, // 获取的佣金金额
// 'user_info' => $user['nickname'], // 用户名
// 'fa_supply_chain_id' => $supplyTeam['id'], // 供应链团队ID
// ];
// SupplyChainBorkerage::create($dataArrSix);
// }
\think\facade\Log::record('执行完毕');
} catch (\Exception $e) {
Log::info('分销等级同步失败: ' . var_export($data, 1) . $e->getMessage());
Log::info('小组服务佣金同步失败: ' . var_export($data, 1) . $e->getMessage());
}
$job->delete();
}