master
ELF 5 years ago
parent 689cc08b69
commit edc40b8a1b

@ -155,11 +155,6 @@ class PromoteService {
} }
public function shiftPromote($task) public function shiftPromote($task)
{
}
public function shiftChildPromote($task)
{ {
$model = new Model(); $model = new Model();
$model->startTrans(); $model->startTrans();
@ -172,53 +167,64 @@ class PromoteService {
$toPromote = M('promote', 'tab_')->where(['id' => $task['to_promote_id']])->find(); $toPromote = M('promote', 'tab_')->where(['id' => $task['to_promote_id']])->find();
$fromPromote = M('promote', 'tab_')->where(['id' => $task['from_promote_id']])->find(); $fromPromote = M('promote', 'tab_')->where(['id' => $task['from_promote_id']])->find();
$topPromote = $this->getTopPromote($fromPromote); $topPromote = $this->getTopPromote($fromPromote);
$status = $this->shiftRemoveCoin($fromPromote, $task);
$status = $this->shiftRemoveCoin($fromPromote, $topPromote, $task);
if (!$status) { if (!$status) {
$model->rollback(); $model->rollback();
return ['status' => false, 'msg' => '系统异常2']; return ['status' => false, 'msg' => '系统异常, 处理推广员平台币失败'];
} }
$promote = new PromoteModel(); $firstMap = ['parent_id' => $fromPromote['id']];
$updateData = [ $secondMap = ['chain' => ['like', $fromPromote['chain'] . $fromPromote['id'] . '/%']];
'parent_id' => $toPromote['id'] if ($task['shift_ids'] != '') {
]; $shiftIds = json_decode($task['shift_ids'], true) ?? [];
$updateData = [ $firstMap['id'] = ['in', $shiftIds];
'chain' => ['exp', 'replace(chain,\''.$fromPromote['chain'].'\',\''. $toPromote['chain'].'\')'] $secondMap['id'] = ['in', $shiftIds];
];
if ($fromPromote['grand_id'] == 0) {
$status = $promote->where('parent_id=' . $fromPromoteId)->save($updateData);
} else {
$status = $promote->where('id=' . $fromPromoteId)->save($updateData);
} }
$status = M('promote', 'tab_')->where($firstMap)->save(['parent_id' => $toPromote['id']]);
if (!$status) { if (!$status) {
$model->rollback(); $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]); $status1 = M('ShiftTask')->where('id=' . $task['id'])->save(['status' => 1]);
if (!$status1) { if (!$status1) {
$model->rollback(); $model->rollback();
return ['status' => false, 'msg' => '系统异常3']; return ['status' => false, 'msg' => '系统异常,修改迁移任务状态失败'];
} }
$model->commit(); $model->commit();
return ['status' => true, 'msg' => '推广帐号迁移成功']; 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(); $coinRecordService = new PromoteCoinRecordService();
$promoteCoinService = new PromoteCoinService(); $promoteCoinService = new PromoteCoinService();
$topBalanceCoin = $this->getBalanceCoin($topPromote['id'], 0); $topBalanceCoin = $this->getBalanceCoin($topPromote['id'], 0);
$topBalancePlus = 0; $topBalancePlus = 0;
$promotes = D('promote')->field(['id', 'balance_coin'])->where(['parent_id' => $promote['id']])->select(); $map = ['chain' => $promote['chain'] . $chain['id'] . '/%'];
$ids = array_column($promotes, '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']; $ids[] = $promote['id'];
$promoteCoins = []; $promoteCoins = [];
$balances = M('PromoteBalanceCoin', 'tab_')->where(['promote_id' => ['in', $ids]])->select(); $balances = M('PromoteBalanceCoin', 'tab_')->where(['promote_id' => ['in', $ids]])->select();
@ -306,9 +312,7 @@ class PromoteService {
$toPromote = D('promote')->where(['id' => $toPromoteId])->find(); $toPromote = D('promote')->where(['id' => $toPromoteId])->find();
$fromPromote = D('promote')->where(['id' => $fromPromoteId])->find(); $fromPromote = D('promote')->where(['id' => $fromPromoteId])->find();
// $promote = new PromoteModel();
// $promote->where('parent_id=' . $fromPromoteId)->save(['parent_id' => $toPromoteId]);
$user1 = new UserModel(); $user1 = new UserModel();
$users = $user1->field(['id', 'account', 'nickname'])->where('promote_id=' . $fromPromoteId)->select(); $users = $user1->field(['id', 'account', 'nickname'])->where('promote_id=' . $fromPromoteId)->select();

Loading…
Cancel
Save