修改返利

This commit is contained in:
邹景立 2021-03-18 13:53:29 +08:00
parent 4d7594e764
commit 578d09d567
2 changed files with 27 additions and 34 deletions

View File

@ -49,9 +49,6 @@ class UserBalance extends Controller
/** /**
* 数据列表处理 * 数据列表处理
* @param array $data * @param array $data
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
protected function _index_page_filter(array &$data) protected function _index_page_filter(array &$data)
{ {
@ -83,22 +80,20 @@ class UserBalance extends Controller
/** /**
* 表单数据处理 * 表单数据处理
* @param array $data * @param array $data
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/ */
protected function _form_filter(array &$data) protected function _form_filter(array &$data)
{ {
if (empty($data['code'])) { if (empty($data['code'])) {
$data['code'] = CodeExtend::uniqidDate('20', 'B'); $data['code'] = CodeExtend::uniqidDate('20', 'B');
} }
if ($this->request->isGet()) {
$this->upgrades = UserUpgradeService::instance()->levels();
}
if ($this->request->isPost()) { if ($this->request->isPost()) {
$data['create_by'] = AdminService::instance()->getUserId(); $data['create_by'] = AdminService::instance()->getUserId();
if (empty(floatval($data['amount'])) && empty($data['vip_upgrade'])) { if (empty(floatval($data['amount'])) && empty($data['vip_upgrade'])) {
$this->error('充值金额为零并没有升级行为!'); $this->error('充值金额为零并没有升级行为!');
} }
} else {
$this->upgrades = UserUpgradeService::instance()->levels();
} }
} }
@ -112,9 +107,7 @@ class UserBalance extends Controller
{ {
if ($state && isset($data['uid'])) { if ($state && isset($data['uid'])) {
UserBalanceService::instance()->amount($data['uid']); UserBalanceService::instance()->amount($data['uid']);
if ($data['vip_upgrade'] > 0) { UserUpgradeService::instance()->upgrade($data['uid']);
UserUpgradeService::instance()->upgrade($data['uid']);
}
} }
} }
@ -125,7 +118,8 @@ class UserBalance extends Controller
*/ */
public function remove() public function remove()
{ {
$this->_delete($this->table); $db = $this->app->db->name($this->table);
$this->_delete($db->whereLike('code', "B%"));
} }
/** /**
@ -136,9 +130,8 @@ class UserBalance extends Controller
protected function _delete_result(bool $state) protected function _delete_result(bool $state)
{ {
if ($state) { if ($state) {
$ids = str2arr(input('id', '')); $map = [['id', 'in', str2arr(input('id', ''))]];
$query = $this->app->db->name($this->table); foreach ($this->app->db->name($this->table)->where($map)->cursor() as $vo) {
foreach ($query->whereIn('id', $ids)->cursor() as $vo) {
UserBalanceService::instance()->amount($vo['uid']); UserBalanceService::instance()->amount($vo['uid']);
} }
} }

View File

@ -146,14 +146,14 @@ class RebateService extends Service
if ($this->config("frist_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) { if ($this->config("frist_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) {
$value = $this->config("frist_value_vip_{$key}"); $value = $this->config("frist_value_vip_{$key}");
if ($this->config("frist_type_vip_{$key}") == 1) { if ($this->config("frist_type_vip_{$key}") == 1) {
$amount = $value ?: '0.00'; $val = floatval($value ?: '0.00');
$name = "{$this->name(self::PRIZE_01)},每{$amount}"; $name = "{$this->name(self::PRIZE_01)},每{$val}";
} else { } else {
$amount = $value * $this->order['rebate_amount'] / 100; $val = floatval($value * $this->order['rebate_amount'] / 100);
$name = "{$this->name(self::PRIZE_01)},订单 {$value}%"; $name = "{$this->name(self::PRIZE_01)},订单 {$value}%";
} }
$this->app->db->name($this->table)->insert(array_merge($map, [ $this->app->db->name($this->table)->insert(array_merge($map, [
'uid' => $this->from1['id'], 'name' => $name, 'amount' => $amount, 'status' => $this->status, 'order_amount' => $this->order['amount_total'], 'uid' => $this->from1['id'], 'name' => $name, 'amount' => $val, 'status' => $this->status, 'order_amount' => $this->order['amount_total'],
])); ]));
// 更新用户奖利金额 // 更新用户奖利金额
UserUpgradeService::instance()->upgrade($this->from1['id']); UserUpgradeService::instance()->upgrade($this->from1['id']);
@ -180,14 +180,14 @@ class RebateService extends Service
if ($this->config("repeat_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) { if ($this->config("repeat_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) {
$value = $this->config("repeat_value_vip_{$key}"); $value = $this->config("repeat_value_vip_{$key}");
if ($this->config("repeat_type_vip_{$key}") == 1) { if ($this->config("repeat_type_vip_{$key}") == 1) {
$amount = $value ?: '0.00'; $val = floatval($value ?: '0.00');
$name = "{$this->name(self::PRIZE_02)},每人 {$amount}"; $name = "{$this->name(self::PRIZE_02)},每人 {$val}";
} else { } else {
$amount = $value * $this->order['rebate_amount'] / 100; $val = floatval($value * $this->order['rebate_amount'] / 100);
$name = "{$this->name(self::PRIZE_02)},订单 {$value}%"; $name = "{$this->name(self::PRIZE_02)},订单 {$value}%";
} }
$this->app->db->name($this->table)->insert(array_merge($map, [ $this->app->db->name($this->table)->insert(array_merge($map, [
'uid' => $this->from1['id'], 'name' => $name, 'amount' => $amount, 'status' => $this->status, 'order_amount' => $this->order['amount_total'], 'uid' => $this->from1['id'], 'name' => $name, 'amount' => $val, 'status' => $this->status, 'order_amount' => $this->order['amount_total'],
])); ]));
// 更新用户奖利金额 // 更新用户奖利金额
UserUpgradeService::instance()->upgrade($this->from1['id']); UserUpgradeService::instance()->upgrade($this->from1['id']);
@ -211,8 +211,8 @@ class RebateService extends Service
$map = ['type' => self::PRIZE_03, 'order_no' => $this->order['order_no'], 'order_uid' => $this->order['uid']]; $map = ['type' => self::PRIZE_03, 'order_no' => $this->order['order_no'], 'order_uid' => $this->order['uid']];
if ($this->config("direct_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) { if ($this->config("direct_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) {
$value = $this->config("direct_value_vip_{$key}"); $value = $this->config("direct_value_vip_{$key}");
$amount = $value * $this->order['rebate_amount'] / 100;
$name = "{$this->name(self::PRIZE_03)},订单 {$value}%"; $name = "{$this->name(self::PRIZE_03)},订单 {$value}%";
$amount = floatval($value * $this->order['rebate_amount'] / 100);
$this->app->db->name($this->table)->insert(array_merge($map, [ $this->app->db->name($this->table)->insert(array_merge($map, [
'uid' => $this->from1['id'], 'name' => $name, 'amount' => $amount, 'status' => $this->status, 'order_amount' => $this->order['amount_total'], 'uid' => $this->from1['id'], 'name' => $name, 'amount' => $amount, 'status' => $this->status, 'order_amount' => $this->order['amount_total'],
])); ]));
@ -237,10 +237,10 @@ class RebateService extends Service
$map = ['type' => self::PRIZE_04, 'order_no' => $this->order['order_no'], 'order_uid' => $this->order['uid']]; $map = ['type' => self::PRIZE_04, 'order_no' => $this->order['order_no'], 'order_uid' => $this->order['uid']];
if ($this->config("indirect_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) { if ($this->config("indirect_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) {
$value = $this->config("indirect_value_vip_{$key}"); $value = $this->config("indirect_value_vip_{$key}");
$amount = $value * $this->order['rebate_amount'] / 100; $val = floatval($value * $this->order['rebate_amount'] / 100);
$name = "{$this->name(self::PRIZE_04)},订单 {$value}%"; $name = "{$this->name(self::PRIZE_04)},订单 {$value}%";
$this->app->db->name($this->table)->insert(array_merge($map, [ $this->app->db->name($this->table)->insert(array_merge($map, [
'uid' => $this->from2['id'], 'name' => $name, 'amount' => $amount, 'status' => $this->status, 'order_amount' => $this->order['amount_total'], 'uid' => $this->from2['id'], 'name' => $name, 'amount' => $val, 'status' => $this->status, 'order_amount' => $this->order['amount_total'],
])); ]));
// 更新代理奖利金额 // 更新代理奖利金额
UserUpgradeService::instance()->upgrade($this->from2['id']); UserUpgradeService::instance()->upgrade($this->from2['id']);
@ -368,14 +368,14 @@ class RebateService extends Service
if ($this->config("upgrade_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) { if ($this->config("upgrade_state_vip_{$key}") && $this->app->db->name($this->table)->where($map)->count() < 1) {
$value = $this->config("upgrade_value_vip_{$key}"); $value = $this->config("upgrade_value_vip_{$key}");
if ($this->config("upgrade_type_vip_{$key}") == 1) { if ($this->config("upgrade_type_vip_{$key}") == 1) {
$amount = $value ?: '0.00'; $val = floatval($value ?: '0.00');
$name = "{$this->name(self::PRIZE_07)},每人 {$amount}"; $name = "{$this->name(self::PRIZE_07)},每人 {$val}";
} else { } else {
$amount = $value * $this->order['rebate_amount'] / 100; $val = floatval($value * $this->order['rebate_amount'] / 100);
$name = "{$this->name(self::PRIZE_07)},订单 {$value}%"; $name = "{$this->name(self::PRIZE_07)},订单 {$value}%";
} }
$this->app->db->name($this->table)->insert(array_merge($map, [ $this->app->db->name($this->table)->insert(array_merge($map, [
'uid' => $this->from1['id'], 'name' => $name, 'amount' => $amount, 'status' => $this->status, 'order_amount' => $this->order['amount_total'], 'uid' => $this->from1['id'], 'name' => $name, 'amount' => $val, 'status' => $this->status, 'order_amount' => $this->order['amount_total'],
])); ]));
// 更新用户奖利金额 // 更新用户奖利金额
UserUpgradeService::instance()->upgrade($this->from1['id']); UserUpgradeService::instance()->upgrade($this->from1['id']);
@ -385,7 +385,7 @@ class RebateService extends Service
/** /**
* 获取配置数据 * 获取配置数据
* @param ?string $name * @param ?string $name 配置名称
* @return array|string * @return array|string
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException * @throws \think\db\exception\DbException
@ -400,11 +400,11 @@ class RebateService extends Service
/** /**
* 检查等级是否有奖励 * 检查等级是否有奖励
* @param string $prize * @param string $prize 奖励规则
* @param integer $level * @param integer $level 用户等级
* @return boolean * @return boolean
*/ */
protected function checkLevelPrize(string $prize, int $level): bool private function checkLevelPrize(string $prize, int $level): bool
{ {
$map = [['number', '=', $level], ['rebate_rule', 'like', "%,{$prize},%"]]; $map = [['number', '=', $level], ['rebate_rule', 'like', "%,{$prize},%"]];
return $this->app->db->name('DataUserUpgrade')->where($map)->count() > 0; return $this->app->db->name('DataUserUpgrade')->where($map)->count() > 0;