队列任务分佣框架搭建

This commit is contained in:
monanxiao 2023-03-11 18:00:01 +08:00
parent 531f595745
commit 2a70ad4623
3 changed files with 98 additions and 1 deletions

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 SupplyChainBorkerage extends BaseModel
{
// 设置当前模型的数据库连接
protected $connection = 'nongke';
protected $table = 'fa_supply_brokerage';
/**
* @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_brokerage';
}
}

View File

@ -59,6 +59,7 @@ class UserBrokerageRepository extends BaseRepository
return $this->dao->search(['type' => $type])->order('brokerage_level ASC,create_time DESC')->select(); return $this->dao->search(['type' => $type])->order('brokerage_level ASC,create_time DESC')->select();
} }
// 推广分销分佣记录方法
public function inc(User $user, $type, $inc) public function inc(User $user, $type, $inc)
{ {
$nextLevel = $this->getNextLevel($user->brokerage_level); $nextLevel = $this->getNextLevel($user->brokerage_level);
@ -80,6 +81,29 @@ class UserBrokerageRepository extends BaseRepository
return $this->checkLevel($user, $nextLevel); return $this->checkLevel($user, $nextLevel);
} }
// 供应链分润分佣记录方法
public function supplyChain(User $user, $type, $inc)
{
$nextLevel = $this->getNextLevel($user->brokerage_level);
if (!$nextLevel) return false;
$make = app()->make(UserBillRepository::class);
$bill = $make->getWhere(['uid' => $user->uid, 'link_id' => $nextLevel->user_brokerage_id, 'category' => 'sys_brokerage', 'type' => $type]);
if ($bill) {
$bill->number = bcadd($bill->number, $inc, 2);
$bill->save();
} else {
$make->incBill($user->uid, 'sys_brokerage', $type, [
'number' => $inc,
'title' => $type,
'balance' => 0,
'status' => 0,
'link_id' => $nextLevel->user_brokerage_id
]);
}
return $this->checkLevel($user, $nextLevel);
}
public function checkLevel(User $user, UserBrokerage $nextLevel) public function checkLevel(User $user, UserBrokerage $nextLevel)
{ {

View File

@ -20,6 +20,7 @@ use crmeb\interfaces\JobInterface;
use think\facade\Log; use think\facade\Log;
/** /**
*
* 供应链分佣队列 * 供应链分佣队列
* *
*/ */
@ -27,7 +28,32 @@ class SupplyChainOrderBrokerAgeJob implements JobInterface
{ {
public function fire($job, $data) public function fire($job, $data)
{ {
Log::info('供应链分佣'); 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();
}
}
// 执行供应链佣金分账
app()->make(UserBrokerageRepository::class)->inc($user, $data['type'], $data['inc']);
} catch (\Exception $e) {
Log::info('分销等级同步失败: ' . var_export($data, 1) . $e->getMessage());
}
$job->delete();
} }
public function failed($data) public function failed($data)