Merge branch 'develop'
This commit is contained in:
commit
3e94e88f89
@ -1154,7 +1154,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
$_order = [
|
$_order = [
|
||||||
'cartInfo' => $merchantCart,
|
'cartInfo' => $merchantCart,
|
||||||
'activity_type' => $orderInfo['order_type'],
|
'activity_type' => $orderInfo['order_type'],
|
||||||
'commission_rate' => $rate,
|
'commission_rate' => $makePrice,
|
||||||
'order_type' => $merchantCart['order']['isTake'] ? 1 : 0,
|
'order_type' => $merchantCart['order']['isTake'] ? 1 : 0,
|
||||||
'is_virtual' => $order_model ? 1 : 0,
|
'is_virtual' => $order_model ? 1 : 0,
|
||||||
'order_sn' => $this->getNewOrderId() . ($k + 1),
|
'order_sn' => $this->getNewOrderId() . ($k + 1),
|
||||||
|
@ -45,7 +45,7 @@ class UserExtractRepository extends BaseRepository
|
|||||||
* TODO
|
* TODO
|
||||||
* @param $id
|
* @param $id
|
||||||
* @return bool
|
* @return bool
|
||||||
* @author Qinii
|
* @author QiniiuserTotalExtract
|
||||||
* @day 2020-06-16
|
* @day 2020-06-16
|
||||||
*/
|
*/
|
||||||
public function getWhereCount($id)
|
public function getWhereCount($id)
|
||||||
@ -97,41 +97,86 @@ class UserExtractRepository extends BaseRepository
|
|||||||
* @author Qinii
|
* @author Qinii
|
||||||
* @day 2020-06-16
|
* @day 2020-06-16
|
||||||
*/
|
*/
|
||||||
public function create($user,$data)
|
public function create($user, $data, $source = 2)
|
||||||
{
|
{
|
||||||
event('user.extract.before',compact('user','data'));
|
// 如果是小组服务提现
|
||||||
$userExtract = Db::transaction(function()use($user,$data){
|
if($source == 1)
|
||||||
|
{
|
||||||
|
event('user.extract.before',compact('user','data'));
|
||||||
|
$userExtract = Db::transaction(function()use($user,$data,$source){
|
||||||
|
|
||||||
if($user['brokerage_price'] < (systemConfig('user_extract_min')))
|
if($user['supply_brokerage_price'] < (systemConfig('user_extract_min')))
|
||||||
throw new ValidateException('可提现金额不足');
|
throw new ValidateException('可提现金额不足');
|
||||||
if($data['extract_price'] < (systemConfig('user_extract_min')))
|
if($data['extract_price'] < (systemConfig('user_extract_min')))
|
||||||
throw new ValidateException('提现金额不得小于最低额度');
|
throw new ValidateException('提现金额不得小于最低额度');
|
||||||
if($user['brokerage_price'] < $data['extract_price'])
|
if($user['supply_brokerage_price'] < $data['extract_price'])
|
||||||
throw new ValidateException('提现金额不足');
|
throw new ValidateException('提现金额不足');
|
||||||
if($data['extract_type'] == 3) {
|
if($data['extract_type'] == 3) {
|
||||||
$make = app()->make(WechatUserRepository::class);
|
$make = app()->make(WechatUserRepository::class);
|
||||||
$openid = $make->idByOpenId((int)$user['wechat_user_id']);
|
$openid = $make->idByOpenId((int)$user['wechat_user_id']);
|
||||||
if (!$openid){
|
if (!$openid){
|
||||||
$openid = $make->idByRoutineId((int)$user['wechat_user_id']);
|
$openid = $make->idByRoutineId((int)$user['wechat_user_id']);
|
||||||
if(!$openid) throw new ValidateException('openID获取失败,请确认是微信用户');
|
if(!$openid) throw new ValidateException('openID获取失败,请确认是微信用户');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
$supply_brokerage_price = bcsub($user['supply_brokerage_price'],$data['extract_price'],2);
|
||||||
$brokerage_price = bcsub($user['brokerage_price'],$data['extract_price'],2);
|
$user->supply_brokerage_price = $supply_brokerage_price;
|
||||||
$user->brokerage_price = $brokerage_price;
|
$user->save();
|
||||||
$user->save();
|
|
||||||
|
|
||||||
$data['extract_sn'] = $this->createSn();
|
$data['extract_sn'] = $this->createSn();
|
||||||
$data['uid'] = $user['uid'];
|
$data['uid'] = $user['uid'];
|
||||||
$data['balance'] = $brokerage_price;
|
$data['balance'] = $supply_brokerage_price;
|
||||||
|
$data['source'] = $source;
|
||||||
|
|
||||||
return $this->dao->create($data);
|
return $this->dao->create($data);
|
||||||
});
|
});
|
||||||
event('user.extract',compact('userExtract'));
|
event('user.extract',compact('userExtract'));
|
||||||
SwooleTaskService::admin('notice', [
|
SwooleTaskService::admin('notice', [
|
||||||
'type' => 'extract',
|
'type' => 'extract',
|
||||||
'title' => '您有一条新的提醒申请',
|
'title' => '您有一条新的提醒申请',
|
||||||
'id' => $userExtract->extract_id
|
'id' => $userExtract->extract_id
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分销推广提现 或者 余额提现
|
||||||
|
if($source == 2)
|
||||||
|
{
|
||||||
|
event('user.extract.before',compact('user','data'));
|
||||||
|
$userExtract = Db::transaction(function()use($user,$data,$source){
|
||||||
|
|
||||||
|
if($user['brokerage_price'] < (systemConfig('user_extract_min')))
|
||||||
|
throw new ValidateException('可提现金额不足');
|
||||||
|
if($data['extract_price'] < (systemConfig('user_extract_min')))
|
||||||
|
throw new ValidateException('提现金额不得小于最低额度');
|
||||||
|
if($user['brokerage_price'] < $data['extract_price'])
|
||||||
|
throw new ValidateException('提现金额不足');
|
||||||
|
if($data['extract_type'] == 3) {
|
||||||
|
$make = app()->make(WechatUserRepository::class);
|
||||||
|
$openid = $make->idByOpenId((int)$user['wechat_user_id']);
|
||||||
|
if (!$openid){
|
||||||
|
$openid = $make->idByRoutineId((int)$user['wechat_user_id']);
|
||||||
|
if(!$openid) throw new ValidateException('openID获取失败,请确认是微信用户');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$brokerage_price = bcsub($user['brokerage_price'],$data['extract_price'],2);
|
||||||
|
$user->brokerage_price = $brokerage_price;
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
$data['extract_sn'] = $this->createSn();
|
||||||
|
$data['uid'] = $user['uid'];
|
||||||
|
$data['balance'] = $brokerage_price;
|
||||||
|
$data['source'] = $source;
|
||||||
|
|
||||||
|
return $this->dao->create($data);
|
||||||
|
});
|
||||||
|
event('user.extract',compact('userExtract'));
|
||||||
|
SwooleTaskService::admin('notice', [
|
||||||
|
'type' => 'extract',
|
||||||
|
'title' => '您有一条新的提醒申请',
|
||||||
|
'id' => $userExtract->extract_id
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function switchStatus($id,$data)
|
public function switchStatus($id,$data)
|
||||||
|
@ -856,6 +856,29 @@ class UserRepository extends BaseRepository
|
|||||||
return User::getDB()->where('uid', $uid)->value('nickname');
|
return User::getDB()->where('uid', $uid)->value('nickname');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $uid
|
||||||
|
* @param $inc
|
||||||
|
* @param string $type
|
||||||
|
* @author xaboy
|
||||||
|
* @day 2020/6/22
|
||||||
|
* 供应链佣金增加
|
||||||
|
*/
|
||||||
|
public function incSupplyBrokerage($uid, $inc, $type = '+')
|
||||||
|
{
|
||||||
|
$moneyKey = 'b_top_' . date('Y-m');
|
||||||
|
$weekKey = 'b_top_' . monday();
|
||||||
|
//TODO 佣金周榜
|
||||||
|
$brokerage = Cache::zscore($weekKey, $uid);
|
||||||
|
$brokerage = $type == '+' ? bcadd($brokerage, $inc, 2) : bcsub($brokerage, $inc, 2);
|
||||||
|
Cache::zadd($weekKey, $brokerage, $uid);
|
||||||
|
|
||||||
|
//TODO 佣金月榜
|
||||||
|
$brokerage = Cache::zscore($moneyKey, $uid);
|
||||||
|
$brokerage = $type == '+' ? bcadd($brokerage, $inc, 2) : bcsub($brokerage, $inc, 2);
|
||||||
|
Cache::zadd($moneyKey, $brokerage, $uid);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $uid
|
* @param $uid
|
||||||
* @param $inc
|
* @param $inc
|
||||||
|
@ -35,17 +35,20 @@ use think\db\exception\ModelNotFoundException;
|
|||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use app\common\model\user\UserBill;
|
use app\common\model\user\UserBill;
|
||||||
|
use app\common\dao\user\UserExtractDao as dao;
|
||||||
|
|
||||||
class User extends BaseController
|
class User extends BaseController
|
||||||
{
|
{
|
||||||
protected $repository;
|
protected $repository;
|
||||||
protected $user;
|
protected $user;
|
||||||
|
protected $dao;
|
||||||
|
|
||||||
public function __construct(App $app, UserRepository $repository)
|
public function __construct(App $app, UserRepository $repository, dao $dao)
|
||||||
{
|
{
|
||||||
parent::__construct($app);
|
parent::__construct($app);
|
||||||
$this->repository = $repository;
|
$this->repository = $repository;
|
||||||
$this->user = $this->request->userInfo();
|
$this->user = $this->request->userInfo();
|
||||||
|
$this->dao = $dao;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -78,35 +81,35 @@ class User extends BaseController
|
|||||||
|
|
||||||
public function spread_info()
|
public function spread_info()
|
||||||
{
|
{
|
||||||
$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 = $this->request->param('source');
|
||||||
$source = !isset($source)?2:$source; // 默认来源为2 普通商品订单
|
$source = !isset($source)?2:$source; // 默认来源为2 普通商品订单
|
||||||
|
|
||||||
|
$user = $this->user;
|
||||||
|
$make = app()->make(UserBrokerageRepository::class);
|
||||||
|
|
||||||
// 小组采购佣金另外处理
|
// 小组采购佣金另外处理
|
||||||
if($source == 1)
|
if($source == 1)
|
||||||
{
|
{
|
||||||
|
$user->append([
|
||||||
|
'one_level_count',
|
||||||
|
'two_level_count',
|
||||||
|
'spread_total',
|
||||||
|
]);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
// 'total_brokerage_price' => $this->totalBrokerage($user->uid, $source), // 可提现金额
|
'total_brokerage_price' => $this->totalBrokeragePrice($user['uid'], $source, $user['supply_brokerage_price']),
|
||||||
'total_brokerage_price' => $user->total_brokerage, // 可提现金额
|
'lock_brokerage' => $this->lockBrokerage($user['uid'], 0, $source), // 冻结 待确定
|
||||||
'total_extract' => $this->lockBrokerage($user->uid, $source), // 已提现金额
|
'yesterday_brokerage' => $this->yesterdayBrokerage($user['uid'], $source),
|
||||||
'yesterday_brokerage' => $this->yesterdayBrokerage($user->uid, $source), // 昨日提现收益
|
'total_extract' => $this->userTotalExtract($user['uid'], $source),
|
||||||
'lock_brokerage' => $this->lockBrokerage($user->uid, $source), // 冻结中金额
|
'total_brokerage' => $this->totalBrokerage($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);
|
return app('json')->success($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'total_brokerage_price' => $user->total_brokerage_price,
|
'total_brokerage_price' => $user->total_brokerage_price,
|
||||||
'lock_brokerage' => $user->lock_brokerage,
|
'lock_brokerage' => $user->lock_brokerage,
|
||||||
@ -126,30 +129,40 @@ class User extends BaseController
|
|||||||
return app('json')->success($data);
|
return app('json')->success($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function lockBrokerage($uid, $source)
|
public function totalBrokeragePrice($uid, $source, $supply_brokerage_price)
|
||||||
{
|
{
|
||||||
$lst = UserBill::getDB()->where('category', 'brokerage')
|
return bcadd($this->lockBrokerage($uid, 0, $source), $supply_brokerage_price, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算佣金
|
||||||
|
public function lockBrokerage($uid, $status, $source)
|
||||||
|
{
|
||||||
|
$lst = UserBill::getDB()
|
||||||
|
->where('category', 'brokerage')
|
||||||
->whereIn('type', ['order_one', 'order_two'])
|
->whereIn('type', ['order_one', 'order_two'])
|
||||||
->where('uid', $uid)
|
->where('uid', $uid)
|
||||||
|
->where('status', $status)
|
||||||
->where('source', $source)
|
->where('source', $source)
|
||||||
->where('status', 0)
|
|
||||||
->field('link_id,number')
|
->field('link_id,number')
|
||||||
->select()->toArray();
|
->select()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
$refundPrice = 0;
|
$refundPrice = 0;
|
||||||
|
|
||||||
if (count($lst)) {
|
if (count($lst)) {
|
||||||
$refundPrice = -1 * UserBill::getDB()->whereIn('link_id', array_column($lst, 'link_id'))->where('uid', $uid)
|
$refundPrice = -1 * UserBill::getDB()
|
||||||
->where('category', 'brokerage')->whereIn('type', ['refund_two', 'refund_one'])->sum('number');
|
->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) {
|
foreach ($lst as $bill) {
|
||||||
$refundPrice = bcadd($refundPrice, $bill['number'], 2);
|
$refundPrice = bcadd($refundPrice, $bill['number'], 2);
|
||||||
}
|
}
|
||||||
return $refundPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function yesterdayBrokerage($uid, $source)
|
return $refundPrice;
|
||||||
{
|
|
||||||
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)
|
public function totalBrokerage($uid, $source)
|
||||||
@ -157,7 +170,24 @@ class User extends BaseController
|
|||||||
return bcsub(UserBill::getDB()->where('category', 'brokerage')
|
return bcsub(UserBill::getDB()->where('category', 'brokerage')
|
||||||
->whereIn('type', ['order_one', 'order_two'])->where('source', $source)->where('uid', $uid)->sum('number'),
|
->whereIn('type', ['order_one', 'order_two'])->where('source', $source)->where('uid', $uid)->sum('number'),
|
||||||
UserBill::getDB()->where('uid', $uid)
|
UserBill::getDB()->where('uid', $uid)
|
||||||
->where('category', 'brokerage')->whereIn('type', ['refund_two', 'refund_one'])->sum('number'), 2);
|
->where('category', 'brokerage')->where('source', $source)->whereIn('type', ['refund_two', 'refund_one'])->sum('number'), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 已提现金额
|
||||||
|
public function userTotalExtract($uid, $source)
|
||||||
|
{
|
||||||
|
return $this->dao->search(['status' => 1, 'uid' => $uid, 'source' => $source])->sum('extract_price');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 昨日佣金
|
||||||
|
public function yesterdayBrokerage($uid, $source)
|
||||||
|
{
|
||||||
|
return getModelTime(UserBill::getDB()
|
||||||
|
->where('category', 'brokerage')
|
||||||
|
->where('source', $source)
|
||||||
|
->whereIn('type', ['order_one', 'order_two'])
|
||||||
|
->where('uid', $uid), 'yesterday')
|
||||||
|
->sum('number');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function brokerage_all()
|
public function brokerage_all()
|
||||||
|
@ -48,8 +48,10 @@ class UserExtract extends BaseController
|
|||||||
{
|
{
|
||||||
$data = $this->checkParams($validate);
|
$data = $this->checkParams($validate);
|
||||||
$user = $this->request->userInfo();
|
$user = $this->request->userInfo();
|
||||||
|
$source = $this->request->param('source'); // 1 小组服务 2 普通来源
|
||||||
|
$source = !isset($source)?2:$source; // 默认来源为2 普通商品订单
|
||||||
if($data['extract_type'] == 3 && !systemConfig('sys_extension_type') ) return app('json')->fail('未开启付款到零钱');
|
if($data['extract_type'] == 3 && !systemConfig('sys_extension_type') ) return app('json')->fail('未开启付款到零钱');
|
||||||
$this->repository->create($user,$data);
|
$this->repository->create($user,$data,$source);
|
||||||
return app('json')->success('申请已提交');
|
return app('json')->success('申请已提交');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,13 +44,14 @@ class SupplyChainOrderBrokerAgeJob implements JobInterface
|
|||||||
if($supplyTeam)
|
if($supplyTeam)
|
||||||
{
|
{
|
||||||
// 可获得金额
|
// 可获得金额
|
||||||
$usrPrice = sprintf("%.2f", $price/100*$supplyLevel['rate']);
|
$usrPrice = floatval(($price/100)*$supplyLevel['rate']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分润数据
|
// 分润数据
|
||||||
$dataArr = [
|
$dataArr = [
|
||||||
'user_id' => $data['uid'], // 用户ID
|
'user_id' => $data['uid'], // 用户ID
|
||||||
'pay_price' => $data['inc'], // 订单金额
|
'pay_price' => $data['inc'], // 订单金额
|
||||||
|
'price' => $price, // 订单分佣金额
|
||||||
'order_sn' => $data['order_sn'], // 订单编号
|
'order_sn' => $data['order_sn'], // 订单编号
|
||||||
'supply_sn' => $data['order_sn'], // 订单编号
|
'supply_sn' => $data['order_sn'], // 订单编号
|
||||||
'order_id' => $data['order_id'], // 订单ID
|
'order_id' => $data['order_id'], // 订单ID
|
||||||
@ -62,7 +63,7 @@ class SupplyChainOrderBrokerAgeJob implements JobInterface
|
|||||||
];
|
];
|
||||||
|
|
||||||
// 储存小组服务分佣记录
|
// 储存小组服务分佣记录
|
||||||
$status = SupplyChainBorkerage::create($dataArr);
|
SupplyChainBorkerage::create($dataArr);
|
||||||
|
|
||||||
// 写入冻结佣金
|
// 写入冻结佣金
|
||||||
$userBillRepository = app()->make(UserBillRepository::class);
|
$userBillRepository = app()->make(UserBillRepository::class);
|
||||||
@ -81,7 +82,7 @@ class SupplyChainOrderBrokerAgeJob implements JobInterface
|
|||||||
$userRepository = app()->make(UserRepository::class);
|
$userRepository = app()->make(UserRepository::class);
|
||||||
|
|
||||||
// 增加
|
// 增加
|
||||||
$userRepository->incBrokerage($data['uid'], $price);
|
$userRepository->incSupplyBrokerage($data['uid'], $price);
|
||||||
|
|
||||||
// 增加小组服务佣金明细
|
// 增加小组服务佣金明细
|
||||||
// $onePrice = '0.00'; // 一级佣金
|
// $onePrice = '0.00'; // 一级佣金
|
||||||
|
Loading…
x
Reference in New Issue
Block a user