master
ELF 4 years ago
parent dbfad2d69c
commit a153fb9a0e

@ -10,6 +10,7 @@ use Base\Tool\TaskClient;
use Base\Service\PromoteService;
use GuzzleHttp\Client;
use think\Db;
use Base\Task\Task;
class ConsoleController extends Think {
@ -92,6 +93,47 @@ class ConsoleController extends Think {
}
}
public function runTask($type = null, $count = 1)
{
Printer::export($type);
Printer::export($count);
try {
$task = new Task($type);
$task->run($count);
Printer::export('运行完成');
} catch (\Exception $e) {
Printer::export($e->getMessage());
}
}
public function addTask()
{
$id = M('market_shift', 'tab_')->add([
'from_id' => 1,
'to_id' => 2,
'split_time' => 0,
'created_time' => time()
]);
$params = [
'market_shift_id' => $id
];
Task::add('market-shift', $params);
}
public function initMarketAdmin()
{
$marketService = new MarketService();
$promoteService = new PromoteService();
$promotes = M('promote', 'tab_')->where(['level' => ['gt', 1], 'admin_id' => ['gt', 0], 'company_belong' => ['in', [1, 2]]])->select();
foreach ($promotes as $promote) {
$subPromotes = $promoteService->getAllChildren($promote, 0, ['id']);
$promoteIds = [$promote['id']];
$promoteIds = array_merge(array_column($subPromotes, 'id'), $promoteIds);
$marketService->shiftSpend($promoteIds, 0, $promote['admin_id']);
$marketService->shiftDeposit($promoteIds, 0, $promote['admin_id']);
}
}
public function modifyLoginRepair()
{
$this->modifyLogin(1569686400);

@ -0,0 +1,189 @@
<?php
namespace Admin\Controller;
use User\Api\UserApi as UserApi;
use Base\Service\PresidentDepositService;
use Base\Task\Task;
/**
* 市场
*/
class MarketController extends ThinkController
{
public function rebindRecords()
{
$page = I('p', 1);
$row = I('row', 10);
$companyId = I('company_id', 0);
$promoteId = I('promote_id', 0);
$conditions = [];
$promoteIds = [];
if ($promoteId !== 0) {
$promoteIds = [$promoteId];
}
if ($companyId !== 0) {
$companyPromoteIds = M('promote', 'tab_')->field(['id'])->where(['company_id' => $companyId, 'level' => 1])->getField('id', true);
if (count($companyPromoteIds) > 0) {
$promoteIds = count($promoteIds) ? array_intersect($companyPromoteIds, $promoteIds) : $companyPromoteIds;
$promoteIds[] = 0;
} else {
$promoteIds = [0];
}
}
if (count($promoteIds)) {
$conditions['promote_id'] = ['in', $promoteIds];
}
$query = M('market_shift', 'tab_')->where($conditions);
$countQuery = clone $query;
$items = $query->order('id desc')->page($page, $row)->select();
$count = $countQuery->count();
$recordPromotes = [];
$recordCompanys = [];
if (count($items) > 0) {
$recordPromotes = M('promote', 'tab_')->field(['id', 'account', 'company_id'])->where(['id' => ['in', array_column($items, 'promote_id')]])->select();
$recordCompanyIds = array_column($recordPromotes, 'company_id');
if (count($recordCompanyIds) > 0) {
$recordCompanys = M('promote_company', 'tab_')->field(['id', 'company_name', 'company_belong'])->where(['id' => ['in', $recordCompanyIds]])->select();
}
$adminIds = array_merge(array_column($items, 'from_id'), array_column($items, 'to_id'));
$recordAdmins = M('ucenter_member', 'sys_')->field(['id', 'username'])->where(['id' => ['in', $adminIds]])->select();
$recordPromotes = index_by_column('id', $recordPromotes);
$recordCompanys = index_by_column('id', $recordCompanys);
$recordAdmins = index_by_column('id', $recordAdmins);
}
$companyTypes = [
0 => '内团',
1 => '外团',
2 => '外团-分发联盟',
3 => '无'
];
$statusList = [
0 => '待处理',
1 => '处理成功',
2 => '处理失败',
];
$records = [];
foreach ($items as $item) {
$records[] = [
'id' => $item['id'],
'promote_account' => $recordPromotes[$item['promote_id']]['account'],
'company_name' => $recordCompanys[$recordPromotes[$item['promote_id']]['company_id']]['company_name'],
'company_belong' => $companyTypes[$recordCompanys[$recordPromotes[$item['promote_id']]['company_id']]['company_belong']],
'remark' => $item['remark'],
'from_username' => $recordAdmins[$item['from_id']]['username'],
'to_username' => $recordAdmins[$item['to_id']]['username'],
'split_time' => date('Y-m-d H:i:s', $item['split_time']),
'created_time' => date('Y-m-d H:i:s', $item['created_time']),
'status_text' => $statusList[$item['status']],
'status' => $item['status']
];
}
$companys = M('promote_company', 'tab_')->field(['id', 'company_name'])->where(['company_belong' => ['in', [1, 2]]])->select();
$page = set_pagination($count, $row);
if($page) {
$this->assign('_page', $page);
}
$this->assign('records', $records);
$this->assign('companys', $companys);
$this->display();
}
public function rebind()
{
$this->meta_title = '新增换绑';
$id = I('id', 0);
$companys = M('promote_company', 'tab_')->field(['id', 'company_name'])->where(['company_belong' => ['in', [1, 2]]])->select();
$marketAdmins = getMarketAdmins();
$this->assign('companys', $companys);
$this->assign('marketAdmins', $marketAdmins);
$this->display('rebind');
}
public function save()
{
$records = I('records', []);
if (count($records) == 0) {
$this->ajaxReturn([
'status' => 0,
'message' => '未提交换绑数据'
]);
}
$userAuth = session('user_auth');
foreach ($records as $record) {
$item = [
'promote_id' => $record['promote_id'],
'from_id' => $record['from_id'],
'to_id' => $record['to_id'],
'split_time' => $record['split_time'],
'remark' => $record['remark'],
'creator_id' => $userAuth['uid'],
'created_time' => time()
];
$id = M('market_shift', 'tab_')->add($item);
if ($id) {
Task::add('market-shift', ['market_shift_id' => $id]);
}
}
$this->ajaxReturn([
'status' => 1,
'message' => '提交成功,等待后台处理'
]);
}
public function delete()
{
$id = I('id', 0);
M('market_shift', 'tab_')->where(['id' => $id])->delete();
addOperationLog([
'op_type' => 2,
'key' => $id,
'op_name' => '删除市场换绑记录',
'url' => U('Market/delete', ['id' => $id]),
'menu' => '推广员-推广员管理-市场换绑-删除市场换绑记录'
]);
$this->ajaxReturn([
'status' => 1,
'message' => '删除成功'
]);
}
public function getPromotesByCompany()
{
$companyId = I('company_id', 0);
$promotes = M('promote', 'tab_')->field(['id', 'account', 'admin_id'])
->where(['level' => 1, 'company_id' => $companyId, 'admin_id' => ['gt', 0]])
->select();
$marketAdmins = index_by_column('id', getMarketAdmins());
$records = [];
foreach ($promotes as $promote) {
$admin = isset($marketAdmins[$promote['admin_id']]) ? $marketAdmins[$promote['admin_id']] : null;
$records[] = [
'id' => $promote['id'],
'account' => $promote['account'],
'admin_id' => $promote['admin_id'],
'admin_username' => $admin ? $admin['username'] : '',
];
}
$this->ajaxReturn([
'status' => 1,
'message' => '获取成功',
'data' => [
'promotes' => $records
]
]);
}
}

@ -79,6 +79,16 @@ class MemberController extends ThinkController
$is_repeat = true;
}
$marketAdminId = I('market_admin_id', 0);
if ($marketAdminId) {
$map['tab_user.market_admin_id'] = $marketAdminId;
}
$isMarketAdmin = isMarketAdmin();
if ($isMarketAdmin) {
$userAuth = session('user_auth');
$map['tab_user.market_admin_id'] = $userAuth['uid'];
}
if (isset($_REQUEST['status'])) {
$map['lock_status'] = $_REQUEST['status'];
@ -135,7 +145,7 @@ class MemberController extends ThinkController
//计算用户列表
$data = M("user","tab_")
->field("tab_user.id,`device_number`,`age_status`,`account`,`balance`,`gold_coin`,`alipay`,tab_user.promote_id,`register_type`,tab_user.promote_account,`register_time`,`lock_status`,lock_remark,
`register_way`,`register_ip`,`login_time`,`check_status`,IFNULL(ss.pay_amount,0) AS recharge_total,tab_user.is_repeat")
`register_way`,`register_ip`,`login_time`,`check_status`,IFNULL(ss.pay_amount,0) AS recharge_total,tab_user.is_repeat,tab_user.market_admin_id")
->where($map)
->group("tab_user.id")
->order($order);
@ -217,7 +227,13 @@ class MemberController extends ThinkController
));
data2csv($data,"玩家_玩家列表",$field);
}
$adminUsernameList = getAdminUsernameList(array_column($data, 'market_admin_id'));
foreach ($data as $key=>&$value ) {
($value['promote_account']=='官方渠道')?($value['promote_account']=C('OFFICIEL_CHANNEL')):'';
$value['market_admin_username'] = $adminUsernameList[$value['market_admin_id']] ?? '无';
}
//计算总人数
if($is_repeat){
$field ="count(*) user_count,IFNULL(sum(ss.pay_amount), 0) recharge_total";
@ -258,6 +274,8 @@ class MemberController extends ThinkController
$no_repeat_count = $userDbRes['no_repeat_count'];
}
$this->assign('isMarketAdmin', $isMarketAdmin);
$this->assign('marketAdmins', getMarketAdmins());
$this->assign('repeat_count',$repeat_count);
$this->assign('no_repeat_count',$no_repeat_count);

@ -72,6 +72,17 @@ class SpendController extends ThinkController
unset($_REQUEST['pay_game_status']);
}
$marketAdminId = I('market_admin_id', 0);
if ($marketAdminId) {
$map['market_admin_id'] = $marketAdminId;
}
$isMarketAdmin = isMarketAdmin();
if ($isMarketAdmin) {
$userAuth = session('user_auth');
$map['market_admin_id'] = $userAuth['uid'];
}
// $promoteRoot = getPowerPromoteIds();
// $data_empower_type = session('user_auth')['data_empower_type'];
//
@ -125,6 +136,14 @@ class SpendController extends ThinkController
$data = D(self::model_name)->lists($_GET["p"], $map, $order);
$adminUsernameList = getAdminUsernameList(array_column($data, 'market_admin_id'));
foreach ($data['data'] as $key=>&$value ) {
($value['promote_account']=='官方渠道')?($value['promote_account']=C('OFFICIEL_CHANNEL')):'';
$value['market_admin_username'] = $adminUsernameList[$value['market_admin_id']] ?? '无';
}
$this->assign('isMarketAdmin', $isMarketAdmin);
$this->assign('marketAdmins', getMarketAdmins());
$this->assign('startDate', $startDate);
$this->assign('endDate', $endDate);
$this->assign('list_data', $data['data']);

@ -666,6 +666,17 @@ class UserController extends AdminController
unset($_REQUEST['role_id']);
}
$marketAdminId = I('market_admin_id', 0);
if ($marketAdminId) {
$map['market_admin_id'] = $marketAdminId;
}
$isMarketAdmin = isMarketAdmin();
if ($isMarketAdmin) {
$userAuth = session('user_auth');
$map['market_admin_id'] = $userAuth['uid'];
}
// $promoteRoot = getPowerPromoteIds();
// $data_empower_type = session('user_auth')['data_empower_type'];
//
@ -704,10 +715,19 @@ class UserController extends AdminController
empty(I('user_account')) || $map['user_account'] = ['like', "%" . I('user_account') . "%"];
$this->checkListOrCountAuthRestMap($map,["role_id", "role_name", "user_account"]);
$list = $this->lists(M('user_play_info', 'tab_'), $map, 'play_time desc');
$adminUsernameList = getAdminUsernameList(array_column($list, 'market_admin_id'));
foreach ($list as $key=>&$value ) {
($value['promote_account']=='官方渠道')?($value['promote_account']=C('OFFICIEL_CHANNEL')):'';
$value['market_admin_username'] = $adminUsernameList[$value['market_admin_id']] ?? '无';
}
$this->assign('list', $list);
$this->meta_title = '角色数据';
$this->m_title = '角色查询';
$this->assign('isMarketAdmin', $isMarketAdmin);
$this->assign('marketAdmins', getMarketAdmins());
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'User/rolelist', 'status' => 1])->find());
$this->assign("is_admin",is_administrator());
$show_data_power = (is_administrator()|| session('user_auth')['show_data']);

@ -0,0 +1,365 @@
<extend name="Public/base" />
<block name="body">
<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="__CSS__/admin_table.css" media="all">
<link href="__STATIC__/icons_alibaba/iconfont.css" rel="stylesheet">
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript" src="__STATIC__/provincecityarea/AreaData_min.js"></script>
<script src="__STATIC__/layer/layer.js"></script>
<script type="text/javascript" src="__JS__/select2.min.js"></script>
<style>
.tabcon1711 input.time {
width: 150px;
}
#form .txt_area {
width: 300px;
height: 150px;
}
.tabcon1711 .form_unit {
margin-left: 2px;
}
.tabcon1711 .mustmark {
margin-left:-7px;
}
.list-ratio {
display: table;
}
.list-ratio .li-ratio {
display: flex;
margin-bottom: 20px;
align-items: center;
}
.list-ratio .li-ratio .turnover, .list-ratio .li-ratio .turnover-ratio {
position: relative;
}
.list-ratio .li-ratio .turnover span, .list-ratio .li-ratio .turnover-ratio .error-message {
color: red;
position: absolute;
left: 0;
top: 30px;
white-space: nowrap;
display: none;
}
.iconfont-btn {
cursor: pointer;
}
.iconfont-style {
font-size: 18px;
color: #fff;
border-radius: 4px;
border: 0;
padding: 5px;
margin-left: 10px;
}
.iconfont-selected {
background-color: #0A9AF2;
}
.iconfont-selected:hover {
background-color: #03a9f4;
}
.iconfont-unselected {
background-color: #999;
}
.iconfont-unselected:hover {
background-color: #ababab;
}
.tabcon1711 .submit_btn.small-btn {
float: none;
line-height: 25px;
width: 50px;
height: 25px;
font-size: 12px;
padding: 0px 8px 0px 0px;
}
</style>
<div class="cf main-place top_nav_list navtab_list">
<h3 class="page_title">{$meta_title}</h3>
<!-- <p class="description_text">说明:此功是创建推广员时所需填写信息</p>-->
</div>
<!-- 标签页导航 -->
<div class="tab-wrap">
<div class="tab-content tabcon1711">
<!-- 表单 -->
<form id="form" method="post" class="form-horizontal" style="margin-bottom: 40px;">
<!-- 基础文档模型 -->
<div id="tab1" class="tab-pane in tab1">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="l"><i class="mustmark">*</i>推广公司:</td>
<td class="r">
<select name="company_id" id="company-select" class="select_gallery">
<option value="">请选择推广公司</option>
<?php foreach($companys as $company):?>
<option value="<?=$company['id']?>" <?php if($company['id'] == $promote['company_id']):?>selected<?php endif;?>><?=$company['company_name']?></option>
<?php endforeach;?>
</select>
</td>
</tr>
<tr>
<td class="l"><i class="mustmark">*</i>会长:</td>
<td class="r">
<select name="promote_id" id="promote-select" class="select_gallery">
<option value="">请选择会长</option>
</select>
</td>
</tr>
<tr>
<td class="l"><i class="mustmark">*</i>原市场专员:</td>
<td class="r">
<span id="from-market-name" class="form_radio table_btn" style="color: red;">--</span>
</td>
</tr>
<tr>
<td class="l"><i class="mustmark">*</i>新市场专员:</td>
<td class="r">
<select name="to_id" id="market-select" class="select_gallery">
<option value="">请选择新市场专员</option>
<?php foreach($marketAdmins as $admin):?>
<option value="<?=$admin['id']?>"><?=$admin['username']?></option>
<?php endforeach;?>
</select>
</td>
</tr>
<tr>
<td class="l">订单切分时间:</td>
<td class="r">
<input type="text" id="split_time" name="split_time" class="time" value="" autocomplete="off" placeholder="请选择订单切分时间" style="width: 200px"/>
</td>
</tr>
<tr>
<td class="l">备注:</td>
<td class="r">
<textarea name="" id="remark" cols="30" rows="10"></textarea>
</td>
</tr>
</tbody>
</table>
</div>
<input type="hidden" name="id" id="id" value="{$record.id}" />
<div class="form-item cf">
<button class="submit_btn mlspacing" id="add-item" type="button" target-form="form-horizontal" style="margin-top: 10px;">
新增
</button>
</div>
</form>
<div class="data_list">
<div class="">
<table id="record-table">
<!-- 表头 -->
<thead>
<tr>
<th>推广公司</th>
<th>会长账号</th>
<th>内外团</th>
<th>原市场专员</th>
<th>新市场专员</th>
<th>订单切分时间</th>
<th>备注</th>
<th>操作</th>
</tr>
</thead>
<!-- 列表 -->
<tbody>
</tbody>
</table>
</div>
</div>
<div style="margin-top: 30px; height: 35px; width: 100%;">
<a class="submit_btn" href="javascript:;" id="submit" style="margin: 0px auto; margin-left: 208px; ">全部提交</a>
</div>
</div>
</div>
<div class="common_settings">
<span class="plus_icon"><span><img src="__IMG__/zwmimages/icon_jia.png"></span></span>
<form class="addShortcutIcon">
<input type="hidden" name="title" value="{$m_title}">
<input type="hidden" name="url" value="Promote/lists/type/1">
</form>
<a class="ajax-post add-butn <notempty name='commonset'>addSIsetted</notempty>" href="javascript:;" target-form="addShortcutIcon" url="{:U('Think/addShortcutIcon')}"><img src="__IMG__/zwmimages/icon_jia.png"><span><notempty name='commonset'>已添加<else />添加至常用设置</notempty></span></a>
</div>
</block>
<block name="script">
<link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
<php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
<link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
//导航高亮
highlight_subnav("{:U('PromoteLimitRule/records')}");
$(".select_gallery").select2();
$(function(){
$('.time').datetimepicker({
format: 'yyyy-mm-dd',
language: "zh-CN",
autoclose: true,
scrollMonth: false,
scrollTime: false,
scrollInput: false,
startView: 'month',
minView:'month',
maxView:'month',
});
showTab();
var promoteIds = []
$('#company-select').on({
change: function() {
var companyId = $(this).val()
getPromotesByCompany(companyId, function(promotes) {
var html = '<option value="">请选择会长</option>'
for (var key in promotes) {
html += '<option value="' +
promotes[key].id +
'" data-admin-id="' +
promotes[key].admin_id +
'" data-admin-username="' +
promotes[key].admin_username +
'">' + promotes[key].account + '</option>'
}
$('#promote-select').html(html)
$('#promote-select').select2()
})
}
})
$('#promote-select').on({
change: function() {
var promoteOption = $("#promote-select option:selected");
var fromMarketUsername = promoteOption.attr('data-admin-username')
var fromMarketId = promoteOption.attr('data-admin-id')
$('#from-market-name').text(fromMarketUsername)
$('#from-market-name').attr('data-id', fromMarketId)
}
})
function getPromotesByCompany(companyId, callback) {
$.ajax({
url: '{:U("getPromotesByCompany")}',
type: 'get',
dataType: 'json',
data: {company_id: companyId},
success: function(result) {
if (result.status == 1) {
callback(result.data.promotes)
} else {
layer.msg(result.message)
}
}
})
}
$('#add-item').on({
click: function () {
var companyOption = $("#company-select option:selected");
var companyId = companyOption.val()
var companyName = companyOption.text()
var promoteOption = $("#promote-select option:selected");
var promoteId = promoteOption.val()
var promoteName = promoteOption.text()
var marketOption = $("#market-select option:selected");
var marketId = marketOption.val()
var marketName = marketOption.text()
var splitTime = $('#split_time').val()
var remark = $('#remark').val()
var fromId = $('#from-market-name').attr('data-id')
if (companyId == '') {
return layer.msg('请选择推广公司')
}
if (promoteId == '') {
return layer.msg('请选择会长')
}
if (marketId == '') {
return layer.msg('请新市场专员')
}
if (promoteIds.includes(promoteId)) {
return layer.msg('该会长已添加')
}
var data = {
company_id: companyId,
promote_id: promoteId,
from_id: fromId,
to_id: marketId,
split_time: splitTime,
remark: remark,
}
disabledPromote(promoteId)
promoteIds.push(promoteId)
console.log(promoteIds)
var html = '<tr data-post=' + JSON.stringify(data) + '><td>' + companyName + '</td>' +
'<td class="promote-item" data-id="' + promoteId + '">' + promoteName + '</td>' +
'<td>' + 'ssb' + '</td>' +
'<td>' + $('#from-market-name').text() + '</td>' +
'<td>' + marketName + '</td>' +
'<td>' + splitTime + '</td>' +
'<td>' + remark + '</td>' +
'<td><a class="delete-btn">删除</a></td>' +
'</tr>';
$('#record-table').find('tbody').append(html);
}
})
$('#record-table').on('click', '.delete-btn', function() {
var tr = $(this).parents('tr').eq(0)
tr.remove()
var promoteId = tr.find('.promote-item').attr('data-id')
var index = promoteIds.indexOf(promoteId)
console.log(promoteId)
console.log(index)
if (index !== -1) {
promoteIds.splice(index, 1)
}
console.log(promoteIds)
undisabledPromote(promoteId)
})
function disabledPromote(promoteId) {
var promoteOption = $("#promote-select").children('option').each(function() {
if ($(this).val() == promoteId) {
$(this).attr('disabled', true)
$('#promote-select').select2()
}
})
}
function undisabledPromote(promoteId) {
var promoteOption = $("#promote-select").children('option').each(function() {
if ($(this).val() == promoteId) {
$(this).attr('disabled', false)
$('#promote-select').select2()
}
})
}
$('#submit').click(function (e) {
var records = []
$('#record-table').find('tbody').children('tr').each(function() {
records.push(JSON.parse($(this).attr('data-post')))
})
$.ajax({
url: '{:U("save")}',
type: 'post',
dataType: 'json',
data: {records: records},
success: function(result) {
if (result.status == 1) {
layer.msg(result.message)
setTimeout(function() {
window.location.href = '{:U("rebindRecords")}'
}, 200)
} else {
layer.msg(result.message)
}
}
})
});
});
</script>
</block>

@ -0,0 +1,241 @@
<extend name="Public/base"/>
<block name="css">
<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
<link rel="stylesheet" href="__CSS__/promote.css" type="text/css"/>
<link rel="stylesheet" type="text/css" href="__STATIC__/webuploader/webuploader.css" media="all">
<style>
.select2-container--default .select2-selection--single {
color: #000;
resize: none;
border-width: 1px;
border-style: solid;
border-color: #a7b5bc #ced9df #ced9df #a7b5bc;
box-shadow: 0px 3px 3px #F7F8F9 inset;height:35px;
height:28px;border-radius:3px;font-size:12px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
line-height:35px;
line-height:28px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height:26px;
}
.select2-container--default .select2-search--dropdown .select2-search__field {
height:26px;line-height:26px;font-size:12px;
}
.select2-results__option[aria-selected] {font-size:12px;}
.textarea-style {
width: 200px;
height: 80px;
border-radius: 5px;
padding: 5px;
}
.mustmark {
color: #FF0000;
font-style: normal;
margin: 0 3px;
}
</style>
</block>
<block name="body">
<script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
<script type="text/javascript" src="__JS__/select2.min.js"></script>
<script type="text/javascript" src="__JS__/jquery.form.js"></script>
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
<script src="__STATIC__/md5.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="__STATIC__/webuploader/webuploader.js"></script>
<script src="__STATIC__/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript" src="__STATIC__/layer/extend/layer.ext.js"></script>
<div class="cf main-place top_nav_list navtab_list">
<h3 class="page_title">市场换绑</h3>
</div>
<div class="cf top_nav_list">
<!-- 高级搜索 -->
<div class="jssearch fl cf search_list">
<div class="input-list search-title-box">
<label>搜索:</label>
</div>
<div class="input-list input-list-promote search_label_rehab">
<select id="company_select" name="company_id" class="select_gallery" style="width:200px;">
<option value="">请选择公司</option>
<?php foreach($companys as $company):?>
<option value="<?=$company['id']?>"><?=$company['company_name']?></option>
<?php endforeach;?>
</select>
</div>
<div class="input-list input-list-promote search_label_rehab">
<select id="promote-select" name="promote_id" class="select_gallery" style="width:120px;">
<option value="">请选择会长</option>
<volist name=":get_promote_list_by_id()" id="vo">
<option value="{$vo.id}">{$vo.account}</option>
</volist>
</select>
</div>
<div class="input-list">
<a class="sch-btn" href="javascript:;" id="search" url="{:U('Market/rebind')}">搜索</a>
<a class="sch-btn" href="{:U('Market/rebind')}">添加</a>
<!-- <a class="sch-btn" href="javascript:;" id="batch-delete-btn">删除</a> -->
</div>
<!-- <div class="input-list">
<a class="sch-btn" href="{:U('Export/expUser',array_merge(array('id'=>12,),I('get.')))}">导出</a>
</div> -->
</div>
</div>
<!-- 数据列表 -->
<div class="data_list">
<div class="">
<table>
<!-- 表头 -->
<thead>
<tr>
<th>推广公司</th>
<th>会长账号</th>
<th>内外团</th>
<th>原市场专员</th>
<th>新市场专员</th>
<th>备注</th>
<th>订单切分时间</th>
<th>状态</th>
<th>换绑操作时间</th>
<th>操作</th>
</tr>
</thead>
<!-- 列表 -->
<tbody>
<empty name ="records">
<td colspan="14" class="text-center">aOh! 暂时还没有内容!</td>
<else />
<volist name="records" id="data">
<tr data-id="<?=$data['id']?>">
<td>{$data.company_name}</td>
<td>{$data.promote_account}</td>
<td>{$data.company_belong}</td>
<td>{$data.from_username}</td>
<td>{$data.to_username}</td>
<td>{$data.remark}</td>
<td>{$data.split_time}</td>
<td>{$data.status_text}</td>
<td>{$data.created_time}</td>
<td>
<div class="partakebtn">
<a class="delete-btn">删除</a>
</div>
</td>
</tr>
</volist>
</empty>
</tbody>
</table>
</div>
</div>
<div class="page">
<if condition="$role_export_check eq true ">
<!-- <a class="sch-btn export-btn"
href="{:U(CONTROLLER_NAME.'/'.ACTION_NAME,array_merge(['export'=>1],I('get.')))}" target="_blank">导出</a> -->
</if>
{$_page|default=''}
</div>
<div class="common_settings">
<span class="plus_icon"><span><img src="__IMG__/zwmimages/icon_jia.png"></span></span>
<form class="addShortcutIcon">
<input type="hidden" name="title" value="{$m_title}">
<input type="hidden" name="url" value="Query/withdraw">
</form>
<a class="ajax-post add-butn <notempty name='commonset'>addSIsetted</notempty>" href="javascript:;" target-form="addShortcutIcon" url="{:U('Think/addShortcutIcon')}"><img src="__IMG__/zwmimages/icon_jia.png"><span><notempty name='commonset'>已添加<else />添加至常用设置</notempty></span></a>
</div>
</block>
<block name="script">
<script src="__STATIC__/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript" src="__STATIC__/layer/extend/layer.ext.js" ></script>
<script src="__STATIC__/jquery.cookie.js" charset="utf-8"></script>
<script>
<volist name=":I('get.')" id="vo">
Think.setValue('{$key}',"{$vo}");
</volist>
$(".select_gallery").select2();
</script>
<script type="text/javascript">
//导航高亮
highlight_subnav("{:U('PromoteLimitRule/records')}");
$(function(){
//搜索功能
$("#search").click(function(){
var url = $(this).attr('url');
var query = $('.jssearch').find('input').serialize();
query += "&"+$('.jssearch').find('select').serialize();
query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
query = query.replace(/^&/g,'');
if( url.indexOf('?')>0 ){
url += '&' + query;
}else{
url += '?' + query;
}
window.location.href = url;
});
//回车自动提交
$('.jssearch').find('input').keyup(function(event){
if(event.keyCode===13){
$("#search").click();
}
})
$('#batch-delete-btn').on({
click: function() {
var ids = getIds();
$.ajax({
url: '{:U("batchDelete")}',
type: 'post',
dataType: 'json',
data: {ids: ids},
success: function(result) {
if (result.status == 1) {
layer.msg(result.message)
setTimeout(function() {
window.location.href = window.location.href
}, 200)
} else {
layer.msg(result.message)
}
}
})
}
})
function getIds() {
var ids = [];
$('.ids:checked').each(function() {
ids.push($(this).val());
})
return ids;
}
$('.delete-btn').on({
click: function() {
var id = $(this).parents('tr').eq(0).attr('data-id');
$.ajax({
url: '{:U("delete")}',
type: 'post',
dataType: 'json',
data: {id: id},
success: function(result) {
if (result.status == 1) {
layer.msg(result.message)
setTimeout(function() {
window.location.href = window.location.href
}, 200)
} else {
layer.msg(result.message)
}
}
})
}
})
});
/* $(".export-btn").on("click",function(e){
e.preventDefault();
window.location.href=$(this).attr("href")
}) */
</script>
</block>

@ -160,6 +160,16 @@
<option value="UC" <?php if ($_POST['promote_id'] == 'UC'):?>selected<?php endif;?>>UC用户</option>
</select>
</div>
<?php if(!$isMarketAdmin):?>
<div class="input-list search_item input-list-gamenoticestatus">
<select name="market_admin_id" style="color:#444" class="select_gallery" id="market_admin_id">
<option value="0">所属市场专员</option>
<?php foreach($marketAdmins as $marketAdmin):?>
<option value="<?=$marketAdmin['id']?>" <?php if ($_POST['market_admin_id'] == $marketAdmin['id']):?>selected<?php endif;?>><?=$marketAdmin['username']?></option>
<?php endforeach;?>
</select>
</div>
<?php endif;?>
<div class="input-list">
<input type="text" name="device_number" class="" placeholder="设备号" value="{:I('device_number')}"/>&nbsp;
</div>
@ -202,6 +212,7 @@
<th>玩家账号</th>
</if>
<th>所属推广员</th>
<th>所属市场专员</th>
<th>
<a class="paixu" data-order="{:I('balance_status',1)}" name="balance_status">
@ -244,7 +255,7 @@
<!-- 列表 -->
<tbody>
<empty name ="list_data">
<td colspan="18" class="text-center">aOh! 暂时还没有内容!</td>
<td colspan="19" class="text-center">aOh! 暂时还没有内容!</td>
<else/>
<volist name="list_data" id="data">
<tr>
@ -284,6 +295,7 @@
</empty>
</if>
</td>
<td >{$data.market_admin_username}</td>
<td >{$data.balance}</td>
<td >{$data.recharge_total}</td>
<td >{$data.gold_coin|default='0.00'}</td>

@ -122,6 +122,16 @@
<option value="">请选择推广员</option>
</select>
</div>
<?php if(!$isMarketAdmin):?>
<div class="input-list search_item input-list-gamenoticestatus">
<select name="market_admin_id" style="color:#444" class="select_gallery" id="market_admin_id">
<option value="0">所属市场专员</option>
<?php foreach($marketAdmins as $marketAdmin):?>
<option value="<?=$marketAdmin['id']?>" <?php if ($_POST['market_admin_id'] == $marketAdmin['id']):?>selected<?php endif;?>><?=$marketAdmin['username']?></option>
<?php endforeach;?>
</select>
</div>
<?php endif;?>
<input type="hidden" name="" value="" class="sortBy">
<div class="input-list search_item">
@ -151,6 +161,7 @@
<th>玩家账号</th>
<th>游戏名称</th>
<th>所属推广员</th>
<th>所属市场专员</th>
<th>充值ip</th>
<th>区服ID</th>
<th>游戏区服</th>
@ -170,7 +181,7 @@
<!-- 列表 -->
<tbody>
<empty name="list_data">
<td colspan="18" class="text-center">aOh! 暂时还没有内容!</td>
<td colspan="19" class="text-center">aOh! 暂时还没有内容!</td>
<else/>
<volist name="list_data" id="data">
<tr>
@ -215,6 +226,7 @@
<!-- {:get_promote_account($data['promote_id'])}-->
</eq>
</td>
<td >{$data.market_admin_username}</td>
<td>{$data.spend_ip}</td>
<empty name='data.server_name'>
<td>— —</td>
@ -272,7 +284,7 @@
<if condition="$rule_count_check">
<tr class="data_summary">
<td>汇总</td>
<td colspan="17">
<td colspan="18">
当页充值:{:null_to_0(array_sum(array_column(array_status2value('pay_status','',$list_data),'pay_amount')))}
<!-- 今日充值:{$ttotal}-->
<!-- 昨日充值:{$ytotal}-->

@ -108,6 +108,16 @@
<span class="add-on"><i class="icon-th"></i></span>
</div>
</div>
<?php if(!$isMarketAdmin):?>
<div class="input-list search_item input-list-gamenoticestatus">
<select name="market_admin_id" style="color:#444" class="select_gallery" id="market_admin_id">
<option value="0">所属市场专员</option>
<?php foreach($marketAdmins as $marketAdmin):?>
<option value="<?=$marketAdmin['id']?>" <?php if ($_POST['market_admin_id'] == $marketAdmin['id']):?>selected<?php endif;?>><?=$marketAdmin['username']?></option>
<?php endforeach;?>
</select>
</div>
<?php endif;?>
<div class="input-list">
<a class="sch-btn" href="javascript:;" id="search" url="{:U('rolelist',array('row'=>I('row')))}">搜索</a>
</div>
@ -127,6 +137,7 @@
<th class="">角色名</th>
<th class="">游戏等级</th>
<th class="">所属推广员</th>
<th class="">所属市场专员</th>
<th class="">最后登录时间</th>
<th class="">最后登录IP</th>
<!-- <th class="">操作</th> -->
@ -161,13 +172,14 @@
{$data.promote_account|encryptStr}
</if>
</td>
<td >{$data.market_admin_username}</td>
<td><?= date('Y-m-d H:i:s', $data['play_time']) ?></td>
<td>{$data.play_ip}</td>
<!-- <td><a class="ajax-get" href="{:U('user_update',['ids'=>$data['id']])}">更新</a></td> -->
</tr>
</volist>
<else/>
<td colspan="9" class="text-center">aOh! 暂时还没有内容!</td>
<td colspan="12" class="text-center">aOh! 暂时还没有内容!</td>
</notempty>
</tbody>
</table>

@ -374,4 +374,175 @@ class SpendRepository
{
// return M('spend', 'tab_')->field($columns)->where($map);
}
public function achievement()
{
$time = I('time', date('Y-m-d'));
if (!empty($time)) {
$defaultTime = $time;
} else {
$defaultTime = date('Y-m-d', time());
}
$sdkVersion = I('sdk_version', 0);
$relationGameId = I('relation_game_id', 0);
$serverId = I('server_id', 0);
$parentId = I('parent_id', 0);
$promoteId = I('promote_id', 0);
$status = I('status', 0);
$searchLevel = 0;
$searchLevelName = '';
$currentDisplay = '';
$prevParentId = 0;
$promoteService = new PromoteService();
$loginPromote = $this->getLoginPromote();
$parent = null;
if ($parentId > 0) {
$parent = M('promote', 'tab_')->where(['id' => $parentId])->find();
$currentDisplay = $promoteService->getLevelName($parent['level']) . '推广';
$prevParentId = $parent['parent_id'] == $loginPromote['parent_id'] ? 0 : $parent['parent_id'];
} else {
$parent = $loginPromote;
$currentDisplay = '自己';
}
$searchLevel = $parent['level'] + 1;
$searchLevelName = $promoteService->getLevelName($searchLevel);
$games = get_promote_serach_game();
$subPromotes = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'group_remark'])->where(['parent_id' => $parent['id']])->select();
$map = ['parent_id' => $parent['id']];
if ($promoteId > 0) {
$map['id'] = $promoteId;
}
$query = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'level', 'chain'])->where($map);
list($promotes, $pagination, $count) = $this->paginate($query);
$ids = array_column($promotes, 'id');
$rows = [];
if (count($ids) > 0) {
$rows = M('promote', 'tab_')
->field(['id', 'chain'])
->where(['chain' => ['like', [$parent['chain'] . $parent['id'] . '/%']], 'level' => ['gt', $parent['level'] + 1]])
->select();
}
$basicPromotes = [];
foreach ($ids as $id) {
foreach ($rows as $row) {
$needChain = $parent['chain'] . $parent['id'] . '/' . $id . '/';
if (strpos($row['chain'], $needChain) !== false) {
$basicPromotes[$row['id']] = $id;
}
}
}
$params = [
'isContainSubs' => true,
'basicPromotes' => $basicPromotes,
];
if ($relationGameId != 0 || $sdkVersion != 0) {
$gameIds = gameSearch($relationGameId, $sdkVersion);
$params['game_id'] = ['in', $gameIds];
}
if ($serverId > 0) {
$params['server_id'] = $serverId;
}
if ($status > 0) {
$params['lock_status'] = $status;
}
list($beginTime, $endTime) = $this->getBetweenTime($time);
$params['begin_time'] = $beginTime;
$params['end_time'] = $endTime;
$timeout = 0;
$records = [];
if (intval($endTime - $beginTime) / (24 * 3600) <= 7) {
$promoteRepository = new PromoteRepository();
$createRoleCountList = $promoteRepository->getCreateRoleCountByIds($ids, $params);
$createRoleUserCountList = $promoteRepository->getCreateRoleUserCountByIds($ids, $params);
$newCreateRoleUserCountList = $promoteRepository->getNewCreateRoleUserCountByIds($ids, $params);
// $newCreateRoleDeviceCountList = $promoteRepository->getNewCreateRoleDeviceCountByIds($ids, $params);
$newCreateRoleIpCountList = $promoteRepository->getNewCreateRoleIpCountByIds($ids, $params);
$loginUserCountList = $promoteRepository->getLoginUserCountByIds($ids, $params);
$rechargeCountList = [];
$rechargeUserCountList = [];
$rechargeAmountList = [];
if ($this->canViewUserRecharge) {
$rechargeCountList = $promoteRepository->getRechargeCountByIds($ids, $params);
$rechargeUserCountList = $promoteRepository->getRechargeUserCountByIds($ids, $params);
$rechargeAmountList = $promoteRepository->getRechargeAmountByIds($ids, $params);
}
$promoteService = new PromoteService();
if (I('p', 1) == 1) {
$selfParams = $params;
$selfParams['isContainSubs'] = false;
$selfCreateRoleCountList = $promoteRepository->getCreateRoleCountByIds([$parent['id']], $selfParams);
$selfCreateRoleUserCountList = $promoteRepository->getCreateRoleUserCountByIds([$parent['id']], $selfParams);
$selfNewCreateRoleUserCountList = $promoteRepository->getNewCreateRoleUserCountByIds([$parent['id']], $selfParams);
// $selfNewCreateRoleDeviceCountList = $promoteRepository->getNewCreateRoleDeviceCountByIds([$parent['id']], $selfParams);
$selfNewCreateRoleIpCountList = $promoteRepository->getNewCreateRoleIpCountByIds([$parent['id']], $selfParams);
$selfLoginUserCountList = $promoteRepository->getLoginUserCountByIds([$parent['id']], $selfParams);
$record = [
'id' => $parent['id'],
'account' => $parent['account'],
'promote_group' => $promoteService->getGroupNameByChain($parent['chain'], $parent['id']),
'real_name' => hideRealName($parent['real_name']),
'level' => $parent['level'],
'create_role_count' => $selfCreateRoleCountList[$parent['id']],
'create_role_user_count' => $selfCreateRoleUserCountList[$parent['id']],
'new_create_role_user_count' => $selfNewCreateRoleUserCountList[$parent['id']],
// 'new_create_role_device_count' => $selfNewCreateRoleDeviceCountList[$parent['id']],
'new_create_role_ip_count' => $selfNewCreateRoleIpCountList[$parent['id']],
'login_user_count' => $selfLoginUserCountList[$parent['id']],
'current_display' => $currentDisplay,
];
if ($this->canViewUserRecharge) {
$selfRechargeCountList = $promoteRepository->getRechargeCountByIds([$parent['id']], $selfParams);
$selfRechargeUserCountList = $promoteRepository->getRechargeUserCountByIds([$parent['id']], $selfParams);
$selfRechargeAmountList = $promoteRepository->getRechargeAmountByIds([$parent['id']], $selfParams);
$record['recharge_count'] = $selfRechargeCountList[$parent['id']];
$record['recharge_user_count'] = $selfRechargeUserCountList[$parent['id']];
$record['recharge_amount'] = $selfRechargeAmountList[$parent['id']]['ban_coin'] + $selfRechargeAmountList[$parent['id']]['coin'] + $selfRechargeAmountList[$parent['id']]['cash'];
$record['recharge_by_ban_coin'] = $selfRechargeAmountList[$parent['id']]['ban_coin'];
$record['recharge_by_coin'] = $selfRechargeAmountList[$parent['id']]['coin'];
$record['recharge_by_cash'] = $selfRechargeAmountList[$parent['id']]['cash'];
}
$records[] = $record;
}
foreach ($promotes as $promote) {
$id = $promote['id'];
$record = [
'id' => $id,
'account' => $promote['account'],
'promote_group' => $promoteService->getGroupNameByChain($promote['chain'], $promote['id']),
'real_name' => hideRealName($promote['real_name']),
'level' => $promote['level'],
'create_role_count' => $createRoleCountList[$id],
'create_role_user_count' => $createRoleUserCountList[$id],
'new_create_role_user_count' => $newCreateRoleUserCountList[$id],
// 'new_create_role_device_count' => $newCreateRoleDeviceCountList[$id],
'new_create_role_ip_count' => $newCreateRoleIpCountList[$id],
'login_user_count' => $loginUserCountList[$id],
'current_display' => '',
];
if ($this->canViewUserRecharge) {
$record['recharge_count'] = $rechargeCountList[$id];
$record['recharge_user_count'] = $rechargeUserCountList[$id];
$record['recharge_amount'] = $rechargeAmountList[$id]['ban_coin'] + $rechargeAmountList[$id]['coin'] + $rechargeAmountList[$id]['cash'];
$record['recharge_by_ban_coin'] = $rechargeAmountList[$id]['ban_coin'];
$record['recharge_by_coin'] = $rechargeAmountList[$id]['coin'];
$record['recharge_by_cash'] = $rechargeAmountList[$id]['cash'];
}
$records[] = $record;
}
} else {
$timeout = 1;
}
}

@ -0,0 +1,74 @@
<?php
namespace Base\Service;
use Base\Facade\Request;
class MarketService
{
public function shift($marketShift)
{
$formId = $marketShift['form_id'];
$promoteId = $marketShift['promote_id'];
$toId = $marketShift['to_id'];
$time = $marketShift['split_time'] == 0 ? null : $marketShift['split_time'];
$promote = M('promote', 'tab_')->field(['chain', 'id', 'level', 'admin_id'])->where(['id' => $promoteId, 'admin_id' => $formId])->find();
if (!$promote) {
throw new \Exception('会长不存在');
}
if ($promote['level'] != 1) {
throw new \Exception('该账号非会长');
}
$promotes = (new PromoteService)->getAllChildren($promote, 0, ['id']);
$promoteIds = [$promote['id']];
$promoteIds = array_merge(array_column($promotes, 'id'), $promoteIds);
$this->shiftPromote($formId, $toId);
$this->shiftSpend($promoteIds, $formId, $toId, $time);
$this->shiftDeposit($promoteIds, $formId, $toId, $time);
}
private function shiftPromote($promoteId, $formId, $toId, $time = null)
{
$map = [];
$map['id'] = $promoteId;
M('promote', 'tab_')->where($map)->save(['admin_id' => $toId]);
}
private function shiftSpend($promoteIds, $formId, $toId, $time = null)
{
$map = [];
$map['promote_id'] = ['in', $promoteIds];
$map['market_admin_id'] = $formId;
if ($time) {
$map['pay_time'] = ['egt', $time];
}
$count = M('spend', 'tab_')->where($map)->count();
$limit = 50;
$pageCount = ceil($count/$limit);
for ($page = 0; $page <= $pageCount; $page ++) {
M('spend', 'tab_')->where($map)->limit($limit)->save(['market_admin_id' => $toId]);
}
M('spend', 'tab_')->where($map)->save(['market_admin_id' => $toId]);
}
private function shiftDeposit($promoteIds, $formId, $toId, $time = null)
{
$map = [];
$map['promote_id'] = ['in', $promoteIds];
$map['market_admin_id'] = $formId;
if ($time) {
$map['create_time'] = ['egt', $time];
}
$count = M('deposit', 'tab_')->where($map)->count();
$limit = 50;
$pageCount = ceil($count/$limit);
for ($page = 0; $page <= $pageCount; $page ++) {
M('deposit', 'tab_')->where($map)->limit($limit)->save(['market_admin_id' => $toId]);
}
M('deposit', 'tab_')->where($map)->save(['market_admin_id' => $toId]);
}
}

@ -0,0 +1,8 @@
<?php
namespace Base\Service;
use Base\Facade\Request;
class PaymentService
{
}

@ -0,0 +1,21 @@
<?php
namespace Base\Task;
/**
* 任务基类
* @author elf<360197197@qq.com>
*/
class BaseTask
{
public $params;
public function __construct($params = [])
{
$this->params = $params;
}
public function run()
{
}
}

@ -0,0 +1,31 @@
<?php
namespace Base\Task;
use Base\Service\MarketService;
/**
* 任务处理
* @author elf<360197197@qq.com>
*/
class MarketShiftTask extends BaseTask
{
public function run()
{
$id = $this->params['market_shift_id'];
$record = M('market_shift', 'tab_')->where(['id' => $id])->find();
if (!$record) {
throw new \Exception('换绑记录不存在');
}
if ($record['status'] != 0) {
throw new \Exception('换绑记录状态错误');
}
try {
$marketService = new MarketService();
$marketService->shift($record);
M('market_shift', 'tab_')->where(['id' => $id])->save(['status' => 1]);
} catch (\Exception $e) {
M('market_shift', 'tab_')->where(['id' => $id])->save(['status' => 2]);
throw new \Exception($e->getMessage());
}
}
}

@ -0,0 +1,83 @@
<?php
namespace Base\Task;
/**
* 任务处理
* @author elf<360197197@qq.com>
*/
class Task
{
public static $types = [
'market-shift' => '\Base\Task\MarketShiftTask',
];
public $type;
public $tasks;
public function __construct($type = null)
{
$this->type = $type;
}
public function run($count = 1)
{
$map = ['status' => 0];
if ($this->type !== null) {
$map['type'] = $this->type;
}
$this->tasks = M('tasks', 'tab_')->where($map)->limit($count)->select();
if (count($this->tasks) == 0) {
throw new \Exception('暂无任务');
}
$this->updateTasks(['status' => 1, 'start_time' => time()]);
foreach ($this->tasks as $task) {
$class = $this->getTypeClass($task);
if (is_null($class) || !class_exists($class)) {
$this->updateTask($task, ['status' => 3, 'end_time' => time(), 'result' => '任务处理类不存在']);
continue;
}
try {
$params = json_decode($task['params'], true);
$obj = new $class($params);
$obj->run();
$this->updateTask($task, ['status' => 2, 'end_time' => time(), 'result' => '处理成功']);
} catch (\Exception $e) {
$this->updateTask($task, ['status' => 3, 'end_time' => time(), 'result' => $e->getMessage()]);
}
}
}
public function getTypeClass($task)
{
if (!isset(self::$types[$task['type']])) {
return null;
}
return self::$types[$task['type']];
}
private function updateTask($task, $data)
{
M('tasks', 'tab_')->where(['id' => $task['id']])->save($data);
}
private function updateTasks($data)
{
$ids = array_column($this->tasks, 'id');
M('tasks', 'tab_')->where(['id' => ['in', $ids]])->save($data);
}
public static function add($type, $params = [])
{
if (!isset(self::$types[$type])) {
return false;
}
$record = [
'type' => $type,
'params' => json_encode($params),
'created_time' => time()
];
return M('tasks', 'tab_')->add($record);
}
}

@ -0,0 +1,63 @@
<?php
namespace Base\Tool;
use GuzzleHttp\Client;
class ServiceClient
{
const SUCCESS = '0000';
protected $client;
public function __construct()
{
$this->client = new Client([
'base_uri' => C('SERVICE_URL'),
'timeout' => 10.0,
]);
}
protected function post($uri, $data)
{
$response = $this->client->post($uri, [
'verify' => false,
'form_params' => $data
]);
$result = (string)$response->getBody();
return json_decode($result, true);
}
public function sendSmsCode(string $mobile, string $clientIp)
{
$options = ['type' => 'code', 'client_ip' => $clientIp];
return $this->sendSms($mobile, $options);
}
public function sendSmsContent(string $mobile, string $content)
{
$options = ['type' => 'content', 'content' => $content];
return $this->sendSms($mobile, $options);
}
public function sendSmsBatch(array $mobiles, string $content)
{
$options = ['type' => 'batch', 'content' => $content];
return $this->sendSms($mobiles, $options);
}
private function sendSms($mobile, array $options)
{
return $this->post('/message/sms-send', ['mobile' => $mobile, 'options' => $options]);
}
public function checkSms($mobile, $code)
{
return $this->post('/message/sms-check', ['mobile' => $mobile, 'code' => $code]);
}
public function registerEvent($userId, $source)
{
return $this->post('/game-event/register', ['user_id' => $userId, 'source' => $source]);
}
}
Loading…
Cancel
Save