修改代理

This commit is contained in:
邹景立 2021-03-15 16:50:54 +08:00
parent d262c576ed
commit fb582550f9
5 changed files with 43 additions and 43 deletions

View File

@ -33,7 +33,7 @@ class UserBalance extends Command
[$total, $count] = [$this->app->db->name('DataUser')->count(), 0];
foreach ($this->app->db->name('DataUser')->field('id')->cursor() as $user) {
$this->queue->message($total, ++$count, "正在计算用户 [{$user['id']}] 的余额");
UserUpgradeService::instance()->balance($user['id']);
UserUpgradeService::instance()->syncBalance($user['id']);
$this->queue->message($total, $count, "完成计算用户 [{$user['id']}] 的余额", 1);
}
} catch (\Exception $exception) {

View File

@ -91,7 +91,7 @@ class UserBalance extends Controller
protected function _form_result(bool $state, array $data)
{
if ($state && isset($data['uid'])) {
UserUpgradeService::instance()->balance($data['uid']);
UserUpgradeService::instance()->syncBalance($data['uid']);
}
}
@ -116,7 +116,7 @@ class UserBalance extends Controller
$ids = str2arr(input('id', ''));
$query = $this->app->db->name($this->table);
foreach ($query->whereIn('id', $ids)->cursor() as $vo) {
UserUpgradeService::instance()->balance($vo['uid']);
UserUpgradeService::instance()->syncBalance($vo['uid']);
}
}
}

View File

@ -165,7 +165,7 @@ class RebateCurrentService extends Service
'remark' => "来自订单{$this->order['order_no']}的余额充值",
'amount' => $this->order['reward_balance'],
], 'code');
return UserUpgradeService::instance()->balance($this->order['uid']);
return UserUpgradeService::instance()->syncBalance($this->order['uid']);
}
/**

View File

@ -13,39 +13,16 @@ class UserUpgradeService extends Service
{
/**
* 同步刷新用户返利
* @param integer $uuid
* @return array [total, count, lock]
* 获取用户等级数据
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function syncRebate(int $uuid): array
public function levels(): array
{
$total = abs($this->app->db->name('DataUserRebate')->where("uid='{$uuid}' and status=1 and amount>0 and deleted=0")->sum('amount'));
$count = abs($this->app->db->name('DataUserRebate')->where("uid='{$uuid}' and status=1 and amount<0 and deleted=0")->sum('amount'));
$lockd = abs($this->app->db->name('DataUserRebate')->where("uid='{$uuid}' and status=0 and amount<0 and deleted=0")->sum('amount'));
$this->app->db->name('DataUser')->where(['id' => $uuid])->update([
'rebate_total' => $total, 'rebate_used' => $count, 'rebate_lock' => $lockd,
]);
return [$total, $count, $lockd];
}
/**
* 同步刷新用户余额
* @param int $uuid 用户UID
* @param array $nots 排除的订单
* @return array [total, count]
* @throws \think\db\exception\DbException
*/
public function balance(int $uuid, array $nots = []): array
{
$total = abs($this->app->db->name('DataUserBalance')->where("uid='{$uuid}' and status=1 and amount>0 and deleted=0")->sum('amount'));
$count = abs($this->app->db->name('DataUserBalance')->where("uid='{$uuid}' and status=1 and amount<0 and deleted=0")->sum('amount'));
if (empty($nots)) {
$this->app->db->name('DataUser')->where(['id' => $uuid])->update(['balance_total' => $total, 'balance_used' => $count]);
} else {
$count -= $this->app->db->name('DataUserBalance')->whereRaw("uid={$uuid}")->whereIn('code', $nots)->sum('amount');
}
return [$total, $count];
$query = $this->app->db->name('DataUserUpgrade');
return $query->where(['status' => 1])->order('number asc')->select()->toArray();
}
/**
@ -85,16 +62,39 @@ class UserUpgradeService extends Service
}
/**
* 获取用户等级数据
* @return array
* @throws \think\db\exception\DataNotFoundException
* 同步刷新用户返利
* @param integer $uuid
* @return array [total, count, lock]
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function levels(): array
public function syncRebate(int $uuid): array
{
$query = $this->app->db->name('DataUserUpgrade');
return $query->where(['status' => 1])->order('number asc')->select()->toArray();
$total = abs($this->app->db->name('DataUserRebate')->where("uid='{$uuid}' and status=1 and amount>0 and deleted=0")->sum('amount'));
$count = abs($this->app->db->name('DataUserRebate')->where("uid='{$uuid}' and status=1 and amount<0 and deleted=0")->sum('amount'));
$lockd = abs($this->app->db->name('DataUserRebate')->where("uid='{$uuid}' and status=0 and amount<0 and deleted=0")->sum('amount'));
$this->app->db->name('DataUser')->where(['id' => $uuid])->update([
'rebate_total' => $total, 'rebate_used' => $count, 'rebate_lock' => $lockd,
]);
return [$total, $count, $lockd];
}
/**
* 同步刷新用户余额
* @param int $uuid 用户UID
* @param array $nots 排除的订单
* @return array [total, count]
* @throws \think\db\exception\DbException
*/
public function syncBalance(int $uuid, array $nots = []): array
{
$total = abs($this->app->db->name('DataUserBalance')->where("uid='{$uuid}' and status=1 and amount>0 and deleted=0")->sum('amount'));
$count = abs($this->app->db->name('DataUserBalance')->where("uid='{$uuid}' and status=1 and amount<0 and deleted=0")->sum('amount'));
if (empty($nots)) {
$this->app->db->name('DataUser')->where(['id' => $uuid])->update(['balance_total' => $total, 'balance_used' => $count]);
} else {
$count -= $this->app->db->name('DataUserBalance')->whereRaw("uid={$uuid}")->whereIn('code', $nots)->sum('amount');
}
return [$total, $count];
}
/**

View File

@ -56,7 +56,7 @@ class BalancePyamentService extends PaymentService
// 创建支付行为
$this->createPaymentAction($orderNo, $paymentTitle, $paymentAmount);
// 扣减用户余额
[$total, $count] = UserUpgradeService::instance()->balance($order['uid'], [$orderNo]);
[$total, $count] = UserUpgradeService::instance()->syncBalance($order['uid'], [$orderNo]);
if ($paymentAmount > $total - $count) throw new Exception("可抵扣余额不足");
$this->app->db->name('ShopOrder')->where(['order_no' => $orderNo])->update(['payment_balance' => $paymentAmount]);
// 扣除余额金额
@ -70,7 +70,7 @@ class BalancePyamentService extends PaymentService
// 更新支付行为
$this->updatePaymentAction($orderNo, CodeExtend::uniqidDate(20), $paymentAmount, '账户余额支付');
// 刷新用户余额
UserUpgradeService::instance()->balance($order['uid']);
UserUpgradeService::instance()->syncBalance($order['uid']);
return ['info' => '余额支付完成'];
}
}