From edc40b8a1b2bc25db440a984ed90382e91f68b33 Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Fri, 1 Nov 2019 18:43:26 +0800 Subject: [PATCH] ss --- .../Base/Service/PromoteService.class.php | 60 ++++++++++--------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/Application/Base/Service/PromoteService.class.php b/Application/Base/Service/PromoteService.class.php index c8b3e8381..e07dba79c 100644 --- a/Application/Base/Service/PromoteService.class.php +++ b/Application/Base/Service/PromoteService.class.php @@ -155,11 +155,6 @@ class PromoteService { } public function shiftPromote($task) - { - - } - - public function shiftChildPromote($task) { $model = new Model(); $model->startTrans(); @@ -172,53 +167,64 @@ class PromoteService { $toPromote = M('promote', 'tab_')->where(['id' => $task['to_promote_id']])->find(); $fromPromote = M('promote', 'tab_')->where(['id' => $task['from_promote_id']])->find(); $topPromote = $this->getTopPromote($fromPromote); - - $status = $this->shiftRemoveCoin($fromPromote, $topPromote, $task); + $status = $this->shiftRemoveCoin($fromPromote, $task); if (!$status) { $model->rollback(); - return ['status' => false, 'msg' => '系统异常2']; + return ['status' => false, 'msg' => '系统异常, 处理推广员平台币失败']; } - $promote = new PromoteModel(); - $updateData = [ - 'parent_id' => $toPromote['id'] - ]; - $updateData = [ - 'chain' => ['exp', 'replace(chain,\''.$fromPromote['chain'].'\',\''. $toPromote['chain'].'\')'] - ]; - if ($fromPromote['grand_id'] == 0) { - $status = $promote->where('parent_id=' . $fromPromoteId)->save($updateData); - } else { - $status = $promote->where('id=' . $fromPromoteId)->save($updateData); + $firstMap = ['parent_id' => $fromPromote['id']]; + $secondMap = ['chain' => ['like', $fromPromote['chain'] . $fromPromote['id'] . '/%']]; + if ($task['shift_ids'] != '') { + $shiftIds = json_decode($task['shift_ids'], true) ?? []; + $firstMap['id'] = ['in', $shiftIds]; + $secondMap['id'] = ['in', $shiftIds]; } + $status = M('promote', 'tab_')->where($firstMap)->save(['parent_id' => $toPromote['id']]); if (!$status) { $model->rollback(); - return ['status' => false, 'msg' => '系统异常1']; + return ['status' => false, 'msg' => '系统异常,修改推广员上级失败']; + } + + $status = M('promote', 'tab_')->where($secondMap)->save(['chain' => $toPromote['chain'] . $toPromote['id'] . '/']); + if (!$status) { + $model->rollback(); + return ['status' => false, 'msg' => '系统异常,修改推广员CHAIN失败']; } $status1 = M('ShiftTask')->where('id=' . $task['id'])->save(['status' => 1]); if (!$status1) { $model->rollback(); - return ['status' => false, 'msg' => '系统异常3']; + return ['status' => false, 'msg' => '系统异常,修改迁移任务状态失败']; } $model->commit(); return ['status' => true, 'msg' => '推广帐号迁移成功']; } - public function shiftRemoveCoin($promote, $topPromote, $task) + public function shiftRemoveCoin($promote, $task) { + $shiftIds = null; + if ($task['shift_ids'] != '') { + $shiftIds = json_decode($task['shift_ids'], true) ?? []; + } + + $topPromote = $this->getTopPromote($promote); $coinRecordService = new PromoteCoinRecordService(); $promoteCoinService = new PromoteCoinService(); $topBalanceCoin = $this->getBalanceCoin($topPromote['id'], 0); $topBalancePlus = 0; - $promotes = D('promote')->field(['id', 'balance_coin'])->where(['parent_id' => $promote['id']])->select(); - $ids = array_column($promotes, 'id'); - + $map = ['chain' => $promote['chain'] . $chain['id'] . '/%']; + if ($shiftIds != null) { + $map['id'] = ['in', $shiftIds]; + } + $subPromotes = M('promote', 'tab_')->field(['id', 'balance_coin'])->where($map)->select(); + $ids = array_column($subPromotes, 'id'); $ids[] = $promote['id']; + $promoteCoins = []; $balances = M('PromoteBalanceCoin', 'tab_')->where(['promote_id' => ['in', $ids]])->select(); @@ -306,9 +312,7 @@ class PromoteService { $toPromote = D('promote')->where(['id' => $toPromoteId])->find(); $fromPromote = D('promote')->where(['id' => $fromPromoteId])->find(); - // $promote = new PromoteModel(); - // $promote->where('parent_id=' . $fromPromoteId)->save(['parent_id' => $toPromoteId]); - + $user1 = new UserModel(); $users = $user1->field(['id', 'account', 'nickname'])->where('promote_id=' . $fromPromoteId)->select();