|
|
|
@ -1,15 +1,12 @@
|
|
|
|
|
<?php
|
|
|
|
|
namespace Base\Service;
|
|
|
|
|
|
|
|
|
|
use Base\Business\ShiftPlayer;
|
|
|
|
|
use Base\Model\PromoteModel;
|
|
|
|
|
use Base\Model\UserPlayInfoModel;
|
|
|
|
|
use Base\Model\UserPlayModel;
|
|
|
|
|
use Base\Model\UserModel;
|
|
|
|
|
use Base\Tool\IdCard;
|
|
|
|
|
use Base\Tool\Registry;
|
|
|
|
|
use Base\Tool\Redis;
|
|
|
|
|
use Think\Model;
|
|
|
|
|
use Base\Repository\SpendRepository;
|
|
|
|
|
|
|
|
|
|
class PromoteService {
|
|
|
|
|
|
|
|
|
@ -126,18 +123,13 @@ class PromoteService {
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$shiftTask = M('shift_task', 'sys_')->field(['id'])->where(['type' => $type, 'status' => 0, 'from_promote_id' => $fromPromoteId])->find();
|
|
|
|
|
/* $shiftTask = M('shift_task', 'sys_')->field(['id'])->where(['type' => $type, 'status' => 0, 'from_promote_id' => $fromPromoteId])->find();
|
|
|
|
|
if ($shiftTask) {
|
|
|
|
|
return [
|
|
|
|
|
'status' => false,
|
|
|
|
|
'msg' => '含有类似未执行迁移任务,请稍后再试'
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$isFuture = false;
|
|
|
|
|
if (strtotime($orderTime) > strtotime(date('Y-m-d 23:59:59'))) {
|
|
|
|
|
$isFuture = true;
|
|
|
|
|
}
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
'from_promote_id' => $fromPromoteId,
|
|
|
|
@ -154,6 +146,10 @@ class PromoteService {
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (M('shift_task', 'sys_')->add($data)) {
|
|
|
|
|
if ($type == 2) {
|
|
|
|
|
$data['id'] = M()->getLastInsID();
|
|
|
|
|
$this->addMendsByTask($data);
|
|
|
|
|
}
|
|
|
|
|
return [
|
|
|
|
|
'status' => true,
|
|
|
|
|
'msg'=>'迁移任务创建成功'
|
|
|
|
@ -166,15 +162,55 @@ class PromoteService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addMendsByTask($task)
|
|
|
|
|
{
|
|
|
|
|
$userIds = json_decode($task['shift_ids'], true);
|
|
|
|
|
$users = M('user', 'tab_')->field(['id', 'account', 'nickname'])->where(['id' => ['in', $userIds]])->select();
|
|
|
|
|
$users = index_by_column('id', $users);
|
|
|
|
|
$toPromote = M('promote','tab_')->field(['id', 'account'])->where(['id' => $task['to_promote_id']])->find();
|
|
|
|
|
$fromPromote = M('promote','tab_')->field(['id', 'account'])->where(['id' => $task['from_promote_id']])->find();
|
|
|
|
|
|
|
|
|
|
$creator = null;
|
|
|
|
|
$opAccount = '';
|
|
|
|
|
if ($task['creator_type'] == 1) {
|
|
|
|
|
$creator = M('promote', 'tab_')->where(['id' => $task['creator_id']])->find();
|
|
|
|
|
$opAccount = $creator ? $creator['account'] : '';
|
|
|
|
|
} else {
|
|
|
|
|
$creator = M('ucenter_member', 'sys_')->where(['id' => $task['creator_id']])->find();
|
|
|
|
|
$opAccount = $creator ? $creator['username'] : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$mends = [];
|
|
|
|
|
foreach ($userIds as $userId) {
|
|
|
|
|
$user = $users[$userId];
|
|
|
|
|
$mends[] = [
|
|
|
|
|
'task_id' => $task['id'],
|
|
|
|
|
'user_id' => $userId,
|
|
|
|
|
'user_account' => $user['account'],
|
|
|
|
|
'user_nickname' => $user['nickname'],
|
|
|
|
|
'promote_id' => $fromPromote ? $fromPromote['id'] : 0,
|
|
|
|
|
'promote_account' => $fromPromote ? $fromPromote['account'] : C('OFFICIEL_CHANNEL'),
|
|
|
|
|
'promote_id_to' => $toPromote ? $toPromote['id'] : 0,
|
|
|
|
|
'promote_account_to' => $toPromote ? $toPromote['account'] : C('OFFICIEL_CHANNEL'),
|
|
|
|
|
'remark' => $task['remark'] == '' ? ($task['creator_type'] == 0 ? '后台补链' : '玩家迁移') : $task['remark'],
|
|
|
|
|
'order_time' => $task['order_time'],
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
'pay_amount' => 0,
|
|
|
|
|
'op_id' => $task['creator_id'],
|
|
|
|
|
'op_account' => $opAccount,
|
|
|
|
|
'op_type' => $task['creator_type'],
|
|
|
|
|
'bind_type' => 1,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
M('mend', 'tab_')->addAll($mends);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function shiftPromote($task)
|
|
|
|
|
{
|
|
|
|
|
$model = new Model();
|
|
|
|
|
$model->startTrans();
|
|
|
|
|
|
|
|
|
|
$coinRecordService = new PromoteCoinRecordService();
|
|
|
|
|
$promoteCoinService = new PromoteCoinService();
|
|
|
|
|
$shiftIds = json_decode($task['shift_ids'], true) ?? [];
|
|
|
|
|
|
|
|
|
|
$shiftIds = $task['shift_ids'] ? (json_decode($task['shift_ids'], true) ?? []) : [];
|
|
|
|
|
|
|
|
|
|
$toPromote = M('promote', 'tab_')->where(['id' => $task['to_promote_id']])->find();
|
|
|
|
|
$fromPromote = M('promote', 'tab_')->where(['id' => $task['from_promote_id']])->find();
|
|
|
|
@ -196,33 +232,34 @@ class PromoteService {
|
|
|
|
|
return ['status' => false, 'msg' => '系统异常, 处理推广员平台币失败'];
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
|
|
$levelColumn = 'level' . $toPromote['level'] . '_id';
|
|
|
|
|
$subLevelColumn = 'level' . ($toPromote['level'] + 1) . '_id';
|
|
|
|
|
$firstMap = ['parent_id' => $fromPromote['id']];
|
|
|
|
|
$secondMap = ['chain' => ['like', $fromPromote['chain'] . $fromPromote['id'] . '/%']];
|
|
|
|
|
if (count($shiftIds) > 0) {
|
|
|
|
|
$firstMap['id'] = ['in', $shiftIds];
|
|
|
|
|
$secondMap['parent_id'] = ['in', $shiftIds];
|
|
|
|
|
$secondMap[$subLevelColumn] = ['in', $shiftIds];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
M('promote', 'tab_')->where($firstMap)->save([
|
|
|
|
|
'parent_id' => $toPromote['id'],
|
|
|
|
|
'parent_name' => $toPromote['account'],
|
|
|
|
|
'chain' => $toPromote['chain'] . $toPromote['id'] . '/',
|
|
|
|
|
'level' . $toPromote['level'] => $toPromote['id']
|
|
|
|
|
]);
|
|
|
|
|
try {
|
|
|
|
|
M('promote', 'tab_')->where($firstMap)->save([
|
|
|
|
|
'parent_id' => $toPromote['id'],
|
|
|
|
|
'parent_name' => $toPromote['account'],
|
|
|
|
|
'chain' => $toPromote['chain'] . $toPromote['id'] . '/',
|
|
|
|
|
$levelColumn => $toPromote['id']
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
M('promote', 'tab_')->where($secondMap)->save([
|
|
|
|
|
'chain' => ['exp', 'REPLACE(chain, "/' . $fromPromote['id'] . '/","/' . $toPromote['id'] . '/")'],
|
|
|
|
|
'level' . $toPromote['level'] => $toPromote['id']
|
|
|
|
|
]);
|
|
|
|
|
M('promote', 'tab_')->where($secondMap)->save([
|
|
|
|
|
'chain' => ['exp', 'REPLACE(chain, "/' . $fromPromote['id'] . '/","/' . $toPromote['id'] . '/")'],
|
|
|
|
|
$levelColumn => $toPromote['id']
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$status = M('ShiftTask')->where('id=' . $task['id'])->save(['status' => 1, 'handle_time' => time()]);
|
|
|
|
|
if (!$status) {
|
|
|
|
|
$model->commit();
|
|
|
|
|
return ['status' => true, 'msg' => '推广帐号迁移成功'];
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
$model->rollback();
|
|
|
|
|
return ['status' => false, 'msg' => '系统异常,修改迁移任务状态失败'];
|
|
|
|
|
return ['status' => true, 'msg' => '推广帐号迁移失败: ' . $e->getMessage()];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$model->commit();
|
|
|
|
|
return ['status' => true, 'msg' => '推广帐号迁移成功'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function shiftRemoveCoin($promote, $task)
|
|
|
|
@ -234,7 +271,7 @@ class PromoteService {
|
|
|
|
|
$topBalanceCoin = $this->getBalanceCoin($topPromote['id'], 0);
|
|
|
|
|
$topBalancePlus = 0;
|
|
|
|
|
|
|
|
|
|
$map = ['chain' => $promote['chain'] . $chain['id'] . '/%'];
|
|
|
|
|
$map = ['chain' => $promote['chain'] . $promote['id'] . '/%'];
|
|
|
|
|
if (count($shiftIds) > 0) {
|
|
|
|
|
$map['id'] = ['in', $shiftIds];
|
|
|
|
|
}
|
|
|
|
@ -306,168 +343,53 @@ class PromoteService {
|
|
|
|
|
|
|
|
|
|
public function shiftPlayer($task)
|
|
|
|
|
{
|
|
|
|
|
$toPromoteId = $task['to_promote_id'];
|
|
|
|
|
$fromPromoteId = $task['from_promote_id'];
|
|
|
|
|
$orderTime = $task['order_time'];
|
|
|
|
|
$shiftIds = json_decode($task['shift_ids'], true) ?? [];
|
|
|
|
|
$remark = $task['remark'] ?? '';
|
|
|
|
|
|
|
|
|
|
$creator = null;
|
|
|
|
|
$opAccount = '';
|
|
|
|
|
if ($task['creator_type'] == 1) {
|
|
|
|
|
$creator = M('promote', 'tab_')->where(['id' => $task['creator_id']])->find();
|
|
|
|
|
$opAccount = $creator ? $creator['account'] : '';
|
|
|
|
|
} else {
|
|
|
|
|
$creator = M('ucenter_member', 'sys_')->where(['id' => $task['creator_id']])->find();
|
|
|
|
|
$opAccount = $creator ? $creator['username'] : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$toPromote = M('promote', 'tab_')->where(['id' => $toPromoteId])->find();
|
|
|
|
|
$fromPromote = M('promote', 'tab_')->where(['id' => $fromPromoteId])->find();
|
|
|
|
|
|
|
|
|
|
$toPromote = $toPromote ?? ['id' => 0, 'account' => C('OFFICIEL_CHANNEL'), 'company_id' => 0];
|
|
|
|
|
$fromPromote = $fromPromote ?? ['id' => 0, 'account' => C('OFFICIEL_CHANNEL'), 'company_id' => 0];
|
|
|
|
|
|
|
|
|
|
if ($fromPromote['id'] == 0 && count($shiftIds) == 0) {
|
|
|
|
|
return ['status' => false, 'msg' => '官方渠道玩家不能全部迁移'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$map = [];
|
|
|
|
|
$map['promote_id'] = $fromPromote['id'];
|
|
|
|
|
$spendMap = $map;
|
|
|
|
|
if (count($shiftIds) > 0) {
|
|
|
|
|
$spendMap['user_id'] = $map['id'] = ['in', $shiftIds];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$users = M('user', 'tab_')->field(['id', 'account', 'nickname'])->where($map)->select();
|
|
|
|
|
|
|
|
|
|
$spendMap['pay_time'] = ['egt', $orderTime];
|
|
|
|
|
// $spendMap['is_check'] = ['in','1,2'];
|
|
|
|
|
$spendMap['settle_check'] = 0;
|
|
|
|
|
$spendMap['selle_status'] = 0;
|
|
|
|
|
$spendMap['pay_status'] = 1;
|
|
|
|
|
|
|
|
|
|
$payAmountRows = M('spend', 'tab_')
|
|
|
|
|
->field(['user_id', 'sum(pay_amount) pay_amount'])
|
|
|
|
|
->where($spendMap)
|
|
|
|
|
->group('user_id')
|
|
|
|
|
->select();
|
|
|
|
|
$payAmountRows = index_by_column('user_id', $payAmountRows);
|
|
|
|
|
$users = index_by_column('id', $users);
|
|
|
|
|
$notices = [];
|
|
|
|
|
$formConpany = M('promote_company', 'tab_')->field(['company_name', 'company_belong'])->where(['id' => $fromPromote['company_id']])->find();
|
|
|
|
|
$toConpany = M('promote_company', 'tab_')->field(['company_name', 'company_belong'])->where(['id' => $toPromote['company_id']])->find();
|
|
|
|
|
$belongs = PromoteCompanyService::$belongs;
|
|
|
|
|
|
|
|
|
|
$mends = [];
|
|
|
|
|
foreach ($users as $item) {
|
|
|
|
|
$amount = isset($payAmountRows[$item['id']]) ? round(floatval($payAmountRows[$item['id']]['pay_amount']), 2) : 0;
|
|
|
|
|
$mends[] = [
|
|
|
|
|
'user_id' => $item['id'],
|
|
|
|
|
'user_account' => $item['account'],
|
|
|
|
|
'user_nickname' => $item['nickname'],
|
|
|
|
|
'promote_id' => $fromPromote['id'],
|
|
|
|
|
'promote_account' => $fromPromote['account'],
|
|
|
|
|
'promote_id_to' => $toPromote['id'],
|
|
|
|
|
'promote_account_to' => $toPromote['account'],
|
|
|
|
|
'remark' => $remark == '' ? ($task['creator_type'] == 0 ? '后台补链' : '玩家迁移') : $remark,
|
|
|
|
|
'order_time' => $orderTime,
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
'pay_amount' => $amount,
|
|
|
|
|
'op_id' => $creator ? $creator['id'] : 0,
|
|
|
|
|
'op_account' => $opAccount,
|
|
|
|
|
'op_type' => $task['creator_type'],
|
|
|
|
|
'bind_type' => 1,
|
|
|
|
|
];
|
|
|
|
|
if ($amount > 500) {
|
|
|
|
|
$userWord = '玩家账号' . $item['account'];
|
|
|
|
|
$fromWord = $fromPromote['account'] . ($formConpany ? '(' . $belongs[$formConpany['company_belong']] . '-' . $formConpany['company_name'] : '');
|
|
|
|
|
$toWord = $toPromote['account'] . ($toConpany ? '(' . $belongs[$toConpany['company_belong']] . '-' . $toConpany['company_name'] : '');
|
|
|
|
|
$content = $userWord . ', 从' . $fromWord . '换绑到' . $toWord . ',换绑金额超过500,达到' . $amount . '元';
|
|
|
|
|
$notices[] = [
|
|
|
|
|
'type' => 'shift-player',
|
|
|
|
|
'title' => '换绑额度超500',
|
|
|
|
|
'content' => $content,
|
|
|
|
|
'admin_ids' => '31',
|
|
|
|
|
'create_time' => time(),
|
|
|
|
|
'target' => $item['account'],
|
|
|
|
|
'start_time' => time(),
|
|
|
|
|
'end_time' => time() + 7*24*3600,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$toTopPromote = $this->getTopPromote($toPromote);
|
|
|
|
|
$hasGameIds = $toTopPromote['game_ids'] == '' ? [] : explode(',', $toTopPromote['game_ids']);
|
|
|
|
|
$hasNotGameIds = M('game', 'tab_')->where(['game_id' => ['not in', $hasGameIds]])->getField('id', true);
|
|
|
|
|
$hasNotGameIds = $hasNotGameIds ?? [];
|
|
|
|
|
|
|
|
|
|
$model = new Model();
|
|
|
|
|
$model->startTrans();
|
|
|
|
|
|
|
|
|
|
$status = M('mend', 'tab_')->addAll($mends);
|
|
|
|
|
if (!$status) {
|
|
|
|
|
$model->rollback();
|
|
|
|
|
return ['status' => false, 'msg' => '系统异常,添加变更记录失败'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count($notices) > 0) {
|
|
|
|
|
M('admin_notice', 'tab_')->addAll($notices);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$updateData = [
|
|
|
|
|
'promote_id' => $toPromote['id'],
|
|
|
|
|
'promote_account' => $toPromote['account']
|
|
|
|
|
];
|
|
|
|
|
$updateMarket = [
|
|
|
|
|
'market_admin_id' => $toPromote['admin_id'],
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$map = $otherMap = ['promote_id' => $fromPromote['id']];
|
|
|
|
|
if (count($shiftIds) > 0) {
|
|
|
|
|
$map['id'] = ['in', $shiftIds];
|
|
|
|
|
$otherMap['user_id'] = ['in', $shiftIds];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$status = M('user', 'tab_')->where($map)->save($updateData);
|
|
|
|
|
if (!$status) {
|
|
|
|
|
$model->rollback();
|
|
|
|
|
return ['status' => false, 'msg' => '系统异常,修改用户推广员失败'];
|
|
|
|
|
try {
|
|
|
|
|
$shiftPlayer = new ShiftPlayer($task);
|
|
|
|
|
$shiftPlayer->handle();
|
|
|
|
|
return ['status' => true, 'msg' => '玩家迁移成功'];
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return ['status' => false, 'msg' => $e->getMessage()];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
M('user_play', 'tab_')->where($otherMap)->save($updateData);
|
|
|
|
|
M('user_play_info', 'tab_')->where($otherMap)->save($updateData);
|
|
|
|
|
|
|
|
|
|
unset($spendMap['pay_status']);
|
|
|
|
|
|
|
|
|
|
$updateCheck = [];
|
|
|
|
|
if (count($hasGameIds) > 0) {
|
|
|
|
|
$spendMap['game_id'] = ['in', $hasGameIds];
|
|
|
|
|
M('spend', 'tab_')->where($spendMap)->save(array_merge($updateData, $updateMarket, ['is_check' => 1]));
|
|
|
|
|
public function afterShift($task, $result)
|
|
|
|
|
{
|
|
|
|
|
$data = [];
|
|
|
|
|
if ($result['status']) {
|
|
|
|
|
$data = ['status' => 1, 'result' => $result['msg'], 'handle_time' => time()];
|
|
|
|
|
} else {
|
|
|
|
|
$data = ['status' => 2, 'result' => $result['msg'], 'handle_time' => time()];
|
|
|
|
|
}
|
|
|
|
|
M('shift_task', 'sys_')->where('id=' . $task['id'])->save($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (count($hasNotGameIds) > 0) {
|
|
|
|
|
$spendMap['game_id'] = ['in', $hasNotGameIds];
|
|
|
|
|
M('spend', 'tab_')->where($spendMap)->save(array_merge($updateData, $updateMarket, ['is_check' => 2]));
|
|
|
|
|
/**
|
|
|
|
|
* 玩家补充迁移(处理在迁移过程中玩家正在充值的订单无法迁移的问题)
|
|
|
|
|
*/
|
|
|
|
|
public function replenishShift($task)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$shiftPlayer = new ShiftPlayer($task);
|
|
|
|
|
$shiftPlayer->handleReplenish();
|
|
|
|
|
M('shift_task', 'sys_')->where('id=' . $task['id'])->save(['is_replenished' => 1]);
|
|
|
|
|
return ['status' => true, 'msg' => '玩家补充迁移完成'];
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
return ['status' => false, 'msg' => $e->getMessage()];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$bindMap = $otherMap;
|
|
|
|
|
$bindMap['pay_time'] = ['egt', $orderTime];
|
|
|
|
|
M('bind_spend', 'tab_')->where($bindMap)->save($updateData);
|
|
|
|
|
|
|
|
|
|
$orderMap = $otherMap;
|
|
|
|
|
$orderMap['create_time'] = ['egt', $orderTime];
|
|
|
|
|
M('deposit', 'tab_')->where($orderMap)->save(array_merge($updateData, $updateMarket));
|
|
|
|
|
M('user_play_data_count', 'tab_')->where($orderMap)->save(['promote_id' => $toPromote['id']]);
|
|
|
|
|
|
|
|
|
|
$status = M('shift_task', 'sys_')->where('id=' . $task['id'])->save(['status' => 1, 'handle_time' => time()]);
|
|
|
|
|
if (!$status) {
|
|
|
|
|
$model->rollback();
|
|
|
|
|
return ['status' => false, 'msg' => '系统异常,修改迁移任务失败'];
|
|
|
|
|
public function shift($task)
|
|
|
|
|
{
|
|
|
|
|
$result = null;
|
|
|
|
|
if ($task['type'] == 1) {
|
|
|
|
|
$result = $this->shiftPromote($task);
|
|
|
|
|
} elseif ($task['type'] == 2) {
|
|
|
|
|
$result = $this->shiftPlayer($task);
|
|
|
|
|
} else {
|
|
|
|
|
$result = ['status' => false, 'msg' => '类型错误'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$model->commit();
|
|
|
|
|
return ['status' => true, 'msg' => '玩家迁移成功'];
|
|
|
|
|
$this->afterShift($task, $result);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function cancelShift($params)
|
|
|
|
@ -944,6 +866,11 @@ class PromoteService {
|
|
|
|
|
return M('promote', 'tab_')->field(['id'])->where($conditions)->select(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function subInCompanySql($companyId, $withSelf = true)
|
|
|
|
|
{
|
|
|
|
|
return M('promote', 'tab_')->field(['id'])->where(['company_id' => $companyId])->select(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getLevelName($level)
|
|
|
|
|
{
|
|
|
|
|
return self::$levels[$level] ?? '未知';
|
|
|
|
|