update: commission type and opt knowledge sort timestamp

This commit is contained in:
tokumeikoi 2021-07-14 20:08:30 +09:00
parent 88948eb8ee
commit 77aec7d553
7 changed files with 32 additions and 10 deletions

View File

@ -77,11 +77,15 @@ class KnowledgeController extends Controller
public function sort(KnowledgeSort $request) public function sort(KnowledgeSort $request)
{ {
DB::beginTransaction(); DB::beginTransaction();
foreach ($request->input('knowledge_ids') as $k => $v) { try {
if (!Knowledge::find($v)->update(['sort' => $k + 1])) { foreach ($request->input('knowledge_ids') as $k => $v) {
DB::rollBack(); $knowledge = new Knowledge();
abort(500, '保存失败'); $knowledge->timestamps = false;
$knowledge->update(['sort' => $k + 1]);
} }
} catch (\Exception $e) {
DB::rollBack();
abort(500, '保存失败');
} }
DB::commit(); DB::commit();
return response([ return response([

View File

@ -27,6 +27,7 @@ class UserUpdate extends FormRequest
'u' => 'integer', 'u' => 'integer',
'd' => 'integer', 'd' => 'integer',
'balance' => 'integer', 'balance' => 'integer',
'commission_type' => 'integer',
'commission_balance' => 'integer', 'commission_balance' => 'integer',
'remarks' => 'nullable' 'remarks' => 'nullable'
]; ];

View File

@ -132,13 +132,26 @@ class OrderService
$order->total_amount = $order->total_amount - $order->discount_amount; $order->total_amount = $order->total_amount - $order->discount_amount;
} }
public function setInvite(User $user) public function setInvite(User $user):void
{ {
$order = $this->order; $order = $this->order;
if ($user->invite_user_id && $order->total_amount > 0) { if ($user->invite_user_id && $order->total_amount > 0) {
$order->invite_user_id = $user->invite_user_id; $order->invite_user_id = $user->invite_user_id;
$commissionFirstTime = (int)config('v2board.commission_first_time_enable', 1); $isCommission = false;
if (!$commissionFirstTime || ($commissionFirstTime && !$this->haveValidOrder($user))) { switch ((int)$user->commission_type) {
case 0:
$commissionFirstTime = (int)config('v2board.commission_first_time_enable', 1);
$isCommission = (!$commissionFirstTime || ($commissionFirstTime && !$this->haveValidOrder($user)));
break;
case 1:
$isCommission = true;
break;
case 2:
$isCommission = !$this->haveValidOrder($user);
break;
}
if ($isCommission) {
$inviter = User::find($user->invite_user_id); $inviter = User::find($user->invite_user_id);
if ($inviter && $inviter->commission_rate) { if ($inviter && $inviter->commission_rate) {
$order->commission_balance = $order->total_amount * ($inviter->commission_rate / 100); $order->commission_balance = $order->total_amount * ($inviter->commission_rate / 100);

View File

@ -321,6 +321,7 @@ CREATE TABLE `v2_user` (
`password_algo` char(10) DEFAULT NULL, `password_algo` char(10) DEFAULT NULL,
`balance` int(11) NOT NULL DEFAULT '0', `balance` int(11) NOT NULL DEFAULT '0',
`discount` int(11) DEFAULT NULL, `discount` int(11) DEFAULT NULL,
`commission_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0: system 1: cycle 2: onetime',
`commission_rate` int(11) DEFAULT NULL, `commission_rate` int(11) DEFAULT NULL,
`commission_balance` int(11) NOT NULL DEFAULT '0', `commission_balance` int(11) NOT NULL DEFAULT '0',
`t` int(11) NOT NULL DEFAULT '0', `t` int(11) NOT NULL DEFAULT '0',
@ -347,4 +348,4 @@ CREATE TABLE `v2_user` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 2021-07-01 11:00:48 -- 2021-07-13 13:50:52

View File

@ -422,3 +422,6 @@ DROP `deleted_at`;
ALTER TABLE `v2_user` ALTER TABLE `v2_user`
ADD UNIQUE `email` (`email`), ADD UNIQUE `email` (`email`),
DROP INDEX `email_deleted_at`; DROP INDEX `email_deleted_at`;
ALTER TABLE `v2_user`
ADD `commission_type` tinyint NOT NULL DEFAULT '0' COMMENT '0: system 1: cycle 2: onetime' AFTER `discount`;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long