You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

958 lines
32 KiB
PHTML

5 years ago
<?php
namespace Base\Service;
use Base\Model\PromoteModel;
use Base\Model\UserPlayInfoModel;
use Base\Model\UserPlayModel;
use Base\Model\UserModel;
5 years ago
use Base\Tool\IdCard;
5 years ago
use Think\Model;
class PromoteService {
private $model;
5 years ago
public static $levels = [
1 => '会长',
2 => '部门长',
3 => '组长',
4 => '推广员',
];
5 years ago
public function __construct()
{
$this->model = new PromoteModel();
}
public function froze($id)
{
$data = [
'status' => 2
];
return $this->model->where("id=".$id)->save($data);
}
public function unfreeze($id)
{
$data = [
'status' => 1
];
return $this->model->where("id=".$id)->save($data);
}
public function resetPassword($id, $password = null)
{
if (!$password) {
$password = $this->getRandomPassword(10, false);
}
$passwordSecret = $this->password($password, UC_AUTH_KEY);
if ($this->model->where("id=".$id)->save(['password' => $passwordSecret])) {
return $password;
}
}
public function password($str, $key = 'ThinkUCenter')
{
return '' === $str ? '' : md5(sha1($str) . $key);
}
private function getRandomPassword($length, $special = true){
$chars = array(
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2',
'3', '4', '5', '6', '7', '8', '9'
);
if($special){
$chars = array_merge($chars, array(
'!', '@', '#', '$', '?', '|', '{', '/', ':', ';',
'%', '^', '&', '*', '(', ')', '-', '_', '[', ']',
'}', '<', '>', '~', '+', '=', ',', '.'
));
}
$charsLen = count($chars) - 1;
shuffle($chars);
$password = '';
for($i=0; $i<$length; $i++){
$password .= $chars[mt_rand(0, $charsLen)];
}
return $password;
}
public function addShiftTask($params)
{
$fromPromoteId = isset($params['from_promote_id']) ? $params['from_promote_id'] : 0;
$toPromoteId = isset($params['to_promote_id']) ? $params['to_promote_id'] : 0;
$orderTime = isset($params['order_time']) ? $params['order_time'] : '';
$balanceCoinMode = isset($params['balance_coin_mode']) ? $params['balance_coin_mode'] : 0;
$type = isset($params['type']) ? $params['type'] : 0;
5 years ago
$shiftIds = isset($params['shift_ids']) && $params['shift_ids'] ? $params['shift_ids'] : [];
$creatorId = isset($params['creator_id']) ? $params['creator_id'] : 0;
$creatorType = isset($params['creator_type']) ? $params['creator_type'] : 0;
5 years ago
if ($fromPromoteId == $toPromoteId) {
return [
'status' => false,
'msg'=>'相同推广帐号不可迁移'
];
}
if ($orderTime == 0) {
return [
'status' => false,
'msg'=>'订单日期不能为空'
];
}
5 years ago
5 years ago
/* if ($type == 1 && $balanceCoinMode == 0) {
5 years ago
return [
'status' => false,
'msg'=>'请选择平台币管理方式'
];
5 years ago
} */
5 years ago
5 years ago
if (count($shiftIds) > 15) {
return [
'status' => false,
'msg'=>'部分迁移时迁移人数不能超过15'
];
}
$shiftTask = M('shift_task', 'sys_')->field(['id'])->where(['type' => $type, 'status' => 0, 'from_promote_id'])->find();
if ($shiftTask) {
return [
'status' => false,
'msg' => '含有类似未执行迁移任务,请稍后再试'
];
}
5 years ago
$isFuture = false;
if (strtotime($orderTime) > strtotime(date('Y-m-d 23:59:59'))) {
$isFuture = true;
}
$data = [
'from_promote_id' => $fromPromoteId,
'to_promote_id' => $toPromoteId,
'order_time' => strtotime($orderTime),
'balance_coin_mode' => $balanceCoinMode,
'create_time' => time(),
'creator_id' => $creatorId,
'creator_type' => $creatorType,
5 years ago
'status' => 0,
5 years ago
'type' => $type,
'shift_ids' => json_encode($shiftIds)
5 years ago
];
5 years ago
if (M('shift_task', 'sys_')->add($data)) {
5 years ago
return [
'status' => true,
'msg'=>'迁移任务创建成功'
];
5 years ago
} else {
return [
'status' => false,
'msg'=>'迁移失败'
];
}
}
public function shiftPromote($task)
{
$model = new Model();
$model->startTrans();
$coinRecordService = new PromoteCoinRecordService();
$promoteCoinService = new PromoteCoinService();
5 years ago
$shiftIds = json_decode($task['shift_ids'], true) ?? [];
5 years ago
5 years ago
$toPromote = M('promote', 'tab_')->where(['id' => $task['to_promote_id']])->find();
$fromPromote = M('promote', 'tab_')->where(['id' => $task['from_promote_id']])->find();
5 years ago
$childrenMap = ['parent_id' => $fromPromote['id']];
if (count($shiftIds) > 0) {
$childrenMap['id'] = ['in', $shiftIds];
}
$count = M('promote', 'tab_')->where($childrenMap)->count();
if ($count == 0) {
return ['status' => true, 'msg' => '推广帐号迁移成功,无子账号需要迁移'];
}
5 years ago
$topPromote = $this->getTopPromote($fromPromote);
5 years ago
// $status = $this->shiftRemoveCoin($fromPromote, $task);
5 years ago
5 years ago
/* if (!$status) {
5 years ago
$model->rollback();
5 years ago
return ['status' => false, 'msg' => '系统异常, 处理推广员平台币失败'];
5 years ago
} */
5 years ago
5 years ago
$firstMap = ['parent_id' => $fromPromote['id']];
$secondMap = ['chain' => ['like', $fromPromote['chain'] . $fromPromote['id'] . '/%']];
5 years ago
if (count($shiftIds) > 0) {
5 years ago
$firstMap['id'] = ['in', $shiftIds];
5 years ago
$secondMap['parent_id'] = ['in', $shiftIds];
5 years ago
}
5 years ago
M('promote', 'tab_')->where($firstMap)->save([
5 years ago
'parent_id' => $toPromote['id'],
'parent_name' => $toPromote['account'],
'chain' => $toPromote['chain'] . $toPromote['id'] . '/'
]);
5 years ago
5 years ago
M('promote', 'tab_')->where($secondMap)->save([
5 years ago
'chain' => ['exp', 'REPLACE(chain, "/' . $fromPromote['id'] . '/","/' . $toPromote['id'] . '/")'],
]);
5 years ago
5 years ago
$status = M('ShiftTask')->where('id=' . $task['id'])->save(['status' => 1, 'handle_time' => time()]);
5 years ago
if (!$status) {
5 years ago
$model->rollback();
5 years ago
return ['status' => false, 'msg' => '系统异常,修改迁移任务状态失败'];
5 years ago
}
$model->commit();
return ['status' => true, 'msg' => '推广帐号迁移成功'];
}
5 years ago
public function shiftRemoveCoin($promote, $task)
5 years ago
{
5 years ago
$shiftIds = json_decode($task['shift_ids'], true) ?? [];
5 years ago
$topPromote = $this->getTopPromote($promote);
5 years ago
$coinRecordService = new PromoteCoinRecordService();
$promoteCoinService = new PromoteCoinService();
$topBalanceCoin = $this->getBalanceCoin($topPromote['id'], 0);
$topBalancePlus = 0;
5 years ago
$map = ['chain' => $promote['chain'] . $chain['id'] . '/%'];
5 years ago
if (count($shiftIds) > 0) {
5 years ago
$map['id'] = ['in', $shiftIds];
}
5 years ago
$subPromotes = M('promote', 'tab_')->field(['id', 'balance_coin', 'level'])->where($map)->select();
$subPromotes = index_by_column('id', $subPromotes);
$ids = array_keys($subPromotes);
// $ids[] = $promote['id'];
5 years ago
5 years ago
if (count($ids) == 0) {
return true;
}
5 years ago
$promoteCoins = [];
$balances = M('PromoteBalanceCoin', 'tab_')->where(['promote_id' => ['in', $ids]])->select();
if (count($balances) == 0) {
return true;
}
$records = [];
foreach ($balances as $balance) {
if ($balance['num'] == 0) {
continue;
}
$records[] = $coinRecordService->createRecord([
'type' => 2,
5 years ago
'sub_type' => 7,
'ref_id' => 0,
'promote_id' => $balance['promote_id'],
'target_id' => $topPromote['id'],
'target_level' => $topPromote['level'],
5 years ago
'target_type' => 1,
5 years ago
'game_id' => $balance['game_id'],
5 years ago
'coin' => $balance['num'],
'balance_coin' => 0,
'description' => $balance['game_id'] > 0 ? '绑定币回收' : '迁移扣除',
]);
if ($task['balance_coin_mode'] == 1 && $balance['game_id'] == 0) {
$topBalanceCoin += $balance['num'];
$topBalancePlus += $balance['num'];
$records[] = $coinRecordService->createRecord([
'type' => 1,
'sub_type' => 6,
5 years ago
'ref_id' => 0,
'promote_id' => $topPromote['id'],
'target_id' => $balance['promote_id'],
5 years ago
'target_type' => 1,
5 years ago
'target_level' => $subPromotes[$balance['promote_id']]['level'],
'game_id' => $balance['game_id'],
5 years ago
'coin' => $balance['num'],
'balance_coin' => $topBalanceCoin,
'description' => '迁移回收',
]);
}
}
M('PromoteBalanceCoin', 'tab_')->where(['promote_id' => ['in', $ids]])->save(['num' => 0]);
M('Promote', 'tab_')->where(['id' => ['in', $ids]])->save(['balance_coin' => 0]);
if (count($records) > 0) {
M('PromoteCoinRecord', 'tab_')->addAll($records);
}
if ($topBalancePlus > 0) {
return $this->incCoin($topPromote['id'], $topBalancePlus, 0);
}
return true;
}
public function shiftPlayer($task)
{
$toPromoteId = $task['to_promote_id'];
$fromPromoteId = $task['from_promote_id'];
$orderTime = $task['order_time'];
5 years ago
$shiftIds = json_decode($task['shift_ids'], true) ?? [];
5 years ago
$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'] : '';
}
5 years ago
5 years ago
$toPromote = M('promote', 'tab_')->where(['id' => $toPromoteId])->find();
$fromPromote = M('promote', 'tab_')->where(['id' => $fromPromoteId])->find();
5 years ago
5 years ago
$toPromote = $toPromote ?? ['id' => 0, 'account' => '官方渠道'];
$fromPromote = $fromPromote ?? ['id' => 0, 'account' => '官方渠道'];
if ($fromPromote['id'] == 0 && count($shiftIds) == 0) {
5 years ago
return ['status' => false, 'msg' => '官方渠道玩家不能全部迁移'];
}
$map = [];
5 years ago
$map['promote_id'] = $fromPromote['id'];
5 years ago
if (count($shiftIds) > 0) {
$map['id'] = ['in', $shiftIds];
}
$users = M('user', 'tab_')->field(['id', 'account', 'nickname'])->where($map)->select();
5 years ago
5 years ago
$mends = [];
5 years ago
foreach ($users as $item) {
5 years ago
$mends[] = [
5 years ago
'user_id' => $item['id'],
'user_account' => $item['account'],
'user_nickname' => $item['nickname'],
5 years ago
'promote_id' => $fromPromote['id'],
'promote_account' => $fromPromote['account'],
'promote_id_to' => $toPromote['id'],
'promote_account_to' => $toPromote['account'],
5 years ago
'remark' => $task['creator_type'] == 0 ? '后台补链' : '玩家迁移',
'order_time' => $orderTime,
5 years ago
'create_time' => time(),
'op_id' => $creator ? $creator['id'] : 0,
'op_account' => $opAccount,
'op_type' => $task['creator_type'],
5 years ago
'bind_type' => 1,
];
}
5 years ago
$model = new Model();
$model->startTrans();
$status = M('mend', 'tab_')->addAll($mends);
if (!$status) {
$model->rollback();
return ['status' => false, 'msg' => '系统异常,添加变更记录失败'];
}
5 years ago
5 years ago
$updateData = [
5 years ago
'promote_id' => $toPromote['id'],
'promote_account' => $toPromote['account']
5 years ago
];
$map = $otherMap = ['promote_id' => $fromPromote['id']];
if (count($shiftIds) > 0) {
$map['id'] = ['in', $shiftIds];
$otherMap['user_id'] = ['in', $shiftIds];
}
5 years ago
5 years ago
$status = M('user', 'tab_')->where($map)->save($updateData);
if (!$status) {
$model->rollback();
return ['status' => false, 'msg' => '系统异常,修改用户推广员失败'];
}
5 years ago
5 years ago
M('user_play', 'tab_')->where($otherMap)->save($updateData);
M('user_play_info', 'tab_')->where($otherMap)->save($updateData);
5 years ago
$orderMap1 = $otherMap;
$orderMap1['pay_time'] = ['egt', $orderTime];
M('spend', 'tab_')->where($orderMap1)->where(['is_check' => ['in','1,2']])->save($updateData); // 只改未对账的数据
M('bind_spend', 'tab_')->where($orderMap1)->save($updateData);
$orderMap2 = $otherMap;
$orderMap2['create_time'] = ['egt', $orderTime];
M('deposit', 'tab_')->where($orderMap2)->save($updateData);
5 years ago
M('user_play_data_count', 'tab_')->where($orderMap2)->save(['promote_id' => $toPromote['id']]);
5 years ago
$status = M('shift_task', 'sys_')->where('id=' . $task['id'])->save(['status' => 1, 'handle_time' => time()]);
if (!$status) {
$model->rollback();
return ['status' => false, 'msg' => '系统异常,修改迁移任务失败'];
}
$model->commit();
5 years ago
return ['status' => true, 'msg' => '玩家迁移成功'];
}
public function cancelShift($params)
{
$promoteId = $params['promote_id'];
$type = $params['type'];
5 years ago
$status = M('ShiftTask')->where(['from_promote_id' => $promoteId, 'type' => $type, 'status' => 0])->save(['status' => 2, 'handle_time' => time()]);
5 years ago
if ($status) {
return ['status' => true, 'msg' => '取消成功'];
} else {
return ['status' => false, 'msg' => '取消失败'];
}
}
public function shiftUserCoin($params)
{
$model = new Model();
$model->startTrans();
5 years ago
$promoteId = $params['from_promote_id'];
5 years ago
$userId = $params['user_id'];
$remark = $params['remark'];
$num = $params['num'];
$gameId = $params['game_id'];
$isUseBind = $params['is_use_bind'];
5 years ago
$promote = M('promote', 'tab_')->where(['id' => $promoteId])->find();
$user = M('user', 'tab_')->where(['id' => $userId])->find();
$userPlay = M('user_play', 'tab_')->where(['user_id' => $userId])->find();
$game = M('game', 'tab_')->where(['id' => $gameId])->find();
5 years ago
$fromBalanceCoin = 0;
if ($isUseBind) {
$fromBalanceCoin = $this->getBalanceCoin($promoteId, $gameId);
} else {
$fromBalanceCoin = $this->getBalanceCoin($promoteId, 0);
}
if ($fromBalanceCoin < $num) {
return [
'msg' => '平台币不足',
'status' => false,
];
}
$agentParams = [];
$agentParams['game_name'] = $game['game_name'];
$agentParams['game_appid'] = $game['game_appid'];
$agentParams['game_id'] = $gameId;
$agentParams['pay_order_number'] = '';
$agentParams['order_number'] = '';
$agentParams['promote_id'] = $promoteId;
$agentParams['promote_account'] = $promote['account'];
$agentParams['user_id'] = $userId;
$agentParams['user_account'] = $user['account'];
$agentParams['user_nickname'] = $user['nickname'];
$agentParams['amount'] = $num;
$agentParams['real_amount'] = $num;
$agentParams['pay_status'] = 1;
$agentParams['pay_type'] = 0;
$agentParams['create_time'] = time();
$agentParams['zhekou'] = 10;
$agentParams['pay_way'] = 4;
$fromParams = [];
$fromParams['game_id'] = $gameId;
$fromParams['num'] = $num;
$fromParams['promote_id'] = $promoteId;
5 years ago
$fromParams['target_id'] = $userId;
$fromParams['target_type'] = 2;
5 years ago
$fromParams['target_level'] = 0;
5 years ago
$fromParams['remark'] = $remark;
$fromParams['description'] = $isUseBind ? '绑定币转账' : '通用币转账';
5 years ago
$agentService = new AgentService();
$transferLogService = new PromoteCoinTransferLogService();
$agentRefId = $agentService->addRecord($agentParams);
$formRefId = $transferLogService->addRecord($fromParams);
5 years ago
if ($formRefId == 0 || $agentRefId == 0) {
$model->rollback();
return [
'msg' => '系统异常',
'status' => false,
];
}
$promoteCoinRecordService = new PromoteCoinRecordService();
5 years ago
$fromRecord = [
'type' => 2,
'sub_type' => 4,
5 years ago
'promote_id' => $promoteId,
5 years ago
'ref_id' => $formRefId,
'target_id' => $userId,
'target_type' => 2,
5 years ago
'game_id' => $gameId,
5 years ago
'coin' => $num,
5 years ago
'balance_coin' => $fromBalanceCoin - $num,
5 years ago
'description' => $isUseBind ? '绑定币转账' : '通用币转账',
'remark' => $remark,
];
5 years ago
$promoteCoinRecordService->addRecord($fromRecord);
5 years ago
$incStatus = M('user_play', 'tab_')->where(['game_id' => $gameId, 'user_id' => $userId])->setInc('bind_balance', $num);
5 years ago
$decStatus = $this->decCoin($promoteId, $num, $isUseBind ? $gameId : 0);
if (!$incStatus || !$decStatus) {
$model->rollback();
return [
'msg' => '系统异常',
'status' => false,
];
}
$model->commit();
return [
'msg' => '转帐成功',
'status' => true,
];
}
5 years ago
public function shiftPromoteCoin($params)
5 years ago
{
5 years ago
$toPromoteId = $params['promote_id'];
5 years ago
$fromPromoteId = $params['from_promote_id'];
$remark = $params['remark'];
$num = $params['num'];
5 years ago
$gameId = $params['game_id'] ?? 0;
5 years ago
$isUseBind = $params['is_use_bind'];
5 years ago
$toPromote = M('promote', 'tab_')->where(['id' => $toPromoteId])->find();
$fromPromote = M('promote', 'tab_')->where(['id' => $fromPromoteId])->find();
5 years ago
$toBalanceCoin = $this->getBalanceCoin($toPromoteId, $gameId);
$fromBalanceCoin = 0;
5 years ago
if ($isUseBind && $gameId == 0) {
return [
'msg' => '请选择游戏',
'status' => false,
];
}
5 years ago
if ($isUseBind) {
$fromBalanceCoin = $this->getBalanceCoin($fromPromoteId, $gameId);
} else {
$fromBalanceCoin = $this->getBalanceCoin($fromPromoteId, 0);
}
5 years ago
if ($isUseBind && $gameId) {
return [
'msg' => '平台币不足',
'status' => false,
];
}
5 years ago
if ($fromBalanceCoin < $num) {
return [
'msg' => '平台币不足',
'status' => false,
];
}
$model = new Model();
$model->startTrans();
$params = [];
$params['game_id'] = $gameId;
5 years ago
$params['promote_id'] = $fromPromoteId;
5 years ago
$params['num'] = $num;
5 years ago
$params['target_type'] = 1;
$params['target_id'] = $toPromoteId;
$params['target_level'] = $toPromote['level'];
5 years ago
$params['remark'] = $remark;
$params['description'] = $isUseBind ? '绑定币转账' : '通用币转账';
5 years ago
$transferLogService = new PromoteCoinTransferLogService();
$refId = $transferLogService->addRecord($params);
5 years ago
5 years ago
if ($refId == 0) {
5 years ago
$model->rollback();
return [
'msg' => '系统异常',
'status' => false,
];
}
$promoteCoinRecordService = new PromoteCoinRecordService();
5 years ago
$fromRecord = [
'type' => 2,
5 years ago
'sub_type' => 3,
'ref_id' => $refId,
'promote_id' => $fromPromoteId,
'target_id' => $toPromoteId,
5 years ago
'target_type' => 1,
5 years ago
'target_level' => $toPromote['level'],
'game_id' => $gameId,
5 years ago
'coin' => $num,
'balance_coin' => $fromBalanceCoin - $num,
'description' => '平台币转账',
'remark' => $remark,
];
$promoteCoinRecordService->addRecord($fromRecord);
5 years ago
$toRecord = [
'type' => 1,
'sub_type' => 3,
5 years ago
'ref_id' => $refId,
'promote_id' => $toPromoteId,
'target_id' => $fromPromote['id'],
5 years ago
'target_type' => 1,
5 years ago
'target_level' => $fromPromote['level'],
'game_id' => $gameId,
5 years ago
'coin' => $num,
'balance_coin' => $toBalanceCoin + $num,
'description' => '平台币转账',
'remark' => $remark,
];
$promoteCoinRecordService->addRecord($toRecord);
5 years ago
$incStatus = $this->incCoin($toPromoteId, $num, $gameId);
$decStatus = $this->decCoin($fromPromoteId, $num, $isUseBind ? $gameId : 0);
if (!$incStatus || !$decStatus) {
$model->rollback();
return [
'msg' => '系统异常',
'status' => false,
];
}
$model->commit();
return [
'msg' => '转帐成功',
'status' => true,
];
}
/**
* 添加平台币(不主动产生流水)
*/
public function incCoin($promoteId, $num, $gameId = 0)
{
$status = M('Promote', 'tab_')->where(['id' => $promoteId])->setInc('balance_coin', $num);
if (!$status) {
return false;
}
$promoteBalance = M('PromoteBalanceCoin', 'tab_')->where(['promote_id' => $promoteId, 'game_id' => $gameId])->find();
if (empty($promoteBalance)) {
$record = [
'promote_id' => $promoteId,
'game_id' => $gameId,
'num' => $num,
'status' => 1
];
return M('PromoteBalanceCoin', 'tab_')->add($record);
} else {
return M('PromoteBalanceCoin', 'tab_')->where(['promote_id' => $promoteId, 'game_id' => $gameId])->setInc('num', $num);
}
}
/**
* 减少平台币(不主动产生流水)
*/
public function decCoin($promoteId, $num, $gameId = 0)
{
$status = M('Promote', 'tab_')->where(['id' => $promoteId])->setDec('balance_coin', $num);
if (!$status) {
return false;
}
$promoteBalance = M('PromoteBalanceCoin', 'tab_')->where(['promote_id' => $promoteId, 'game_id' => $gameId])->find();
if (empty($promoteBalance)) {
return false;
} else {
return M('PromoteBalanceCoin', 'tab_')->where(['promote_id' => $promoteId, 'game_id' => $gameId])->setDec('num', $num);
}
}
/**
* 清除绑定平台币(不主动产生流水)
*/
public function clearBindCoin($promoteId)
{
$num = M('PromoteBalanceCoin', 'tab_')->where(['promote_id' => $promoteId, 'game_id' => ['gt', 0]])->sum('num');
$num = intval($num);
if ($num == 0) {
return true;
}
$status = M('Promote', 'tab_')->where(['id' => $promoteId])->setDec('balance_coin', $num);
if (!$status) {
return false;
}
return M('PromoteBalanceCoin', 'tab_')->where(['promote_id' => $promoteId, 'game_id' => ['gt', 0]])->save(['num' => 0]);
}
/**
* 管理员给推广员扣回平台币
*/
public function adminDecCoin($promoteId, $num, $adminId, $gameId = 0)
{
$balanceCoin = $this->getBalanceCoin($promoteId, $gameId);
5 years ago
$promote = M('promote', 'tab_')->where(['id' => $promoteId])->find();
5 years ago
$model = new Model();
$model->startTrans();
$log = [];
$log['game_id'] = $gameId;
$log['banlan_type'] = $gameId > 0 ? 2 : 1;
$log['num'] = $num;
5 years ago
$log['promote_id'] = $promote['id'];
5 years ago
$log['source_id'] = 0;
$log['type'] = 2;
$log['op_id'] = $adminId;
$promoteCoinService = new PromoteCoinService();
$refId = $promoteCoinService->addRecord($log);
$promoteCoinRecordService = new PromoteCoinRecordService();
5 years ago
$record = [
'type' => 2,
'sub_type' => 5,
'ref_id' => $refId,
5 years ago
'promote_id' => $promote['id'],
'target_id' => $adminId,
'target_type' => 3,
'target_level' => $promote['level'],
'game_id' => $gameId,
5 years ago
'coin' => $num,
'balance_coin' => $balanceCoin - $num,
5 years ago
'description' => '后台回收平台币',
5 years ago
'remark' => '',
];
$promoteCoinRecordService->addRecord($record);
5 years ago
5 years ago
$status = $this->decCoin($promote['id'], $num, $gameId);
if ($refId && $status) {
5 years ago
$model->commit();
return true;
}
$model->rollback();
return false;
}
/**
* 管理员给推广员添加平台币
*/
public function adminIncCoin($promoteId, $num, $adminId, $gameId = 0)
{
$balanceCoin = $this->getBalanceCoin($promoteId, $gameId);
5 years ago
$promote = M('promote', 'tab_')->where(['id' => $promoteId])->find();
5 years ago
$model = new Model();
$model->startTrans();
$log = [];
$log['game_id'] = $gameId;
$log['banlan_type'] = $gameId > 0 ? 2 : 1;
$log['num'] = $num;
5 years ago
$log['promote_id'] = $promote['id'];
5 years ago
$log['source_id'] = 0;
$log['type'] = 1;
$log['op_id'] = $adminId;
$promoteCoinService = new PromoteCoinService();
$refId = $promoteCoinService->addRecord($log);
5 years ago
$status = $this->incCoin($promote['id'], $num, $gameId);
5 years ago
$record = [
'type' => 1,
5 years ago
'sub_type' => 8,
5 years ago
'ref_id' => $refId,
5 years ago
'promote_id' => $promote['id'],
'target_id' => $adminId,
'target_type' => 3,
'target_level' => $promote['level'],
5 years ago
'coin' => $num,
5 years ago
'game_id' => $gameId,
5 years ago
'balance_coin' => $balanceCoin + $num,
5 years ago
'description' => '后台发放平台币',
5 years ago
'remark' => '',
];
5 years ago
$promoteCoinRecordService = new PromoteCoinRecordService();
$promoteCoinRecordService->addRecord($record);
5 years ago
if ($refId && $status) {
5 years ago
$model->commit();
return true;
}
$model->rollback();
return false;
}
public function getBalanceCoin($promoteId, $gameId = 0)
{
$promoteBalance = M('PromoteBalanceCoin', 'tab_')->where(['promote_id' => $promoteId, 'game_id' => $gameId])->find();
$balanceCoin = 0;
if (!empty($promoteBalance)) {
$balanceCoin = $promoteBalance['num'];
}
return $balanceCoin;
}
5 years ago
public function getLevelByChain($chain)
{
5 years ago
$chain = trim($chain, '/');
return $chain == '' ? 1 : count(explode('/', $chain));
}
/**
* 获取最上级的推广员
*/
public function getTopPromote($promote)
{
$chain = trim($promote['chain'], '/');
if ($chain == '') {
return $promote;
} else {
$topPromoteId = explode('/', $chain)[0];
return M('promote', 'tab_')->where(['id' => $topPromoteId])->find();
}
5 years ago
}
public function getLevelName($level)
{
return self::$levels[$level] ?? '未知';
5 years ago
}
public function checkAddPromote($params)
{
$account = isset($params['account']) ? trim($params['account']) : '';
$password = $params['password'] ?? '';
$repassword = $params['repassword'] ?? '';
$mobile = $params['mobile_phone'] ?? '';
$idcard = $params['idcard'] ?? '';
$realName = $params['real_name'] ?? '';
if ($account == '') {
return [
'status' => false,
'message' => '请输入推广员账号',
];
}
if (strlen($account) > 15 || strlen($account) < 6) {
return [
'status' => false,
'message' => '账号长度为6-15个字符',
];
}
5 years ago
if (!preg_match("/^[a-zA-Z0-9_\.]+$/", $account)) {
return [
'status' => false,
'message' => '账号只能为数字,字母和下划线',
];
}
5 years ago
if ($mobile == '') {
return [
'status' => false,
'message' => '请输入手机号',
];
} else {
if (!preg_match("/^1[3456789]{1}\d{9}$/", $mobile)) {
return [
'status' => false,
'message' => '手机号格式错误',
];
}
}
if ($idcard == '') {
return [
'status' => false,
'message' => '请输入身份证号',
];
} else {
if (!IdCard::isIdcard($idcard)) {
return [
'status' => false,
'message' => '身份证格式错误',
];
}
}
if ($realName == '') {
return [
'status' => false,
'message' => '请输入姓名',
];
} else {
if (mb_strlen($realName) < 2 || mb_strlen($realName) > 4) {
return [
'status' => false,
'message' => '姓名长度为2-4个字符',
];
}
}
if ($password == '') {
return [
'status' => false,
'message' => '请输入登录密码',
];
}
if ($repassword != $password) {
return [
'status' => false,
'message' => '确认密码跟密码不一致',
];
}
if (strlen($password) < 6) {
return [
'status' => false,
'message' => '密码长度必须大于6位',
];
}
$promote = M('promote', 'tab_')->field(['id'])->where(['account' => $account])->find();
if ($promote) {
return [
'status' => false,
'message' => '渠道账号已存在',
];
}
return [
'status' => true,
'message' => '验证成功',
];
}
5 years ago
public function addPromote($params, $parent = null)
{
$data = [
'account' => $params['account'],
5 years ago
'password' => $this->password($params['password'], UC_AUTH_KEY),
5 years ago
'nickname' => $params['nickname'] ?? $params['account'],
'second_pwd' => $params['second_pwd'] ?? null,
'real_name' => $params['real_name'],
'email' => $params['email'],
'idcard' => $params['idcard'] ?? '',
'status' => $params['status'],
'mobile_phone' => $params['mobile_phone'],
'bank_name' => $params['bank_name'] ?? '',
'bank_card' => $params['bank_card'],
'status' => 1,
'parent_id' => $parent ? $parent['id'] : 0,
'parent_name' => $parent ? $parent['account'] : '官方渠道',
'admin_id' => $params['admin_id'] ?? 0,
'invite_code' => $params['invite_code'] ?? '',
'create_time' => time(),
];
if ($parent) {
$data['chain'] = $parent['chain'] . $parent['id'] . '/';
$data['level'] = $this->getLevelByChain($data['chain']) + 1;
} else {
$data['chain'] = '/';
$data['level'] = 1;
}
return M('promote', 'tab_')->add($data);
}
5 years ago
}