master
ELF 5 years ago
parent 74be3407b1
commit 9abb4ebb2c

@ -5,6 +5,7 @@ use Base\Model\PromoteModel;
use Base\Model\UserPlayInfoModel;
use Base\Model\UserPlayModel;
use Base\Model\UserModel;
use Base\Tool\IdCard;
use Think\Model;
class PromoteService {
@ -129,25 +130,10 @@ class PromoteService {
];
if (M('ShiftTask')->add($data)) {
$id = M()->getLastInsID();
$data['id'] = $id;
if ($isFuture) {
return [
'status' => true,
'msg'=>'迁移任务创建成功'
];
} else {
if ($type == 1) {
return $this->shiftPromote($data);
} elseif ($type == 2) {
return $this->shiftPlayer($data);
} else {
return [
'status' => false,
'msg'=>'数据异常'
];
}
}
} else {
return [
'status' => false,
@ -196,7 +182,7 @@ class PromoteService {
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, 'handle_time' => time()]);
if (!$status1) {
$model->rollback();
return ['status' => false, 'msg' => '系统异常,修改迁移任务状态失败'];
@ -300,22 +286,25 @@ class PromoteService {
public function shiftPlayer($task)
{
/**
* @todo 加事务
*/
$toPromoteId = $task['to_promote_id'];
$fromPromoteId = $task['from_promote_id'];
$shiftIds = json_decode($task['shift_ids'], true) ?? [];
$createPromote = D('promote')->where(['create_promote_id' => $task['create_promote_id']])->find();
$createPromote = M('promote', 'tab_')->where(['create_promote_id' => $task['create_promote_id']])->find();
$toPromote = D('promote')->where(['id' => $toPromoteId])->find();
$fromPromote = D('promote')->where(['id' => $fromPromoteId])->find();
$toPromote = M('promote', 'tab_')->where(['id' => $toPromoteId])->find();
$fromPromote = M('promote', 'tab_')->where(['id' => $fromPromoteId])->find();
$user1 = new UserModel();
$users = $user1->field(['id', 'account', 'nickname'])->where('promote_id=' . $fromPromoteId)->select();
$map = ['promote_id' => $fromPromote['id']];
if (count($shiftIds) > 0) {
$map['id'] = ['in', $shiftIds];
}
$users = M('user', 'tab_')->field(['id', 'account', 'nickname'])->where($map)->select();
$mends = [];
foreach ($users as $item) {
$data = [
$mends[] = [
'user_id' => $item['id'],
'user_account' => $item['account'],
'user_nickname' => $item['nickname'],
@ -330,20 +319,57 @@ class PromoteService {
'op_type' => 1,
'bind_type' => 1,
];
M('Mend', 'tab_')->add($data);
}
$user = new UserModel();
$user->where('promote_id=' . $fromPromoteId)->save(['promote_id' => $toPromoteId, 'promote_account' => $toPromote['account']]);
$model = new Model();
$model->startTrans();
$status = M('mend', 'tab_')->addAll($mends);
if (!$status) {
$model->rollback();
return ['status' => false, 'msg' => '系统异常,添加变更记录失败'];
}
$updateData = [
'promote_id' => $toPromote['id'],
'promote_account' => $toPromote['account']
];
$userPlayer = new UserPlayModel();
$userPlayer->where('promote_id=' . $fromPromoteId)->save(['promote_id' => $toPromoteId, 'promote_account' => $toPromote['account']]);
$map = $otherMap = ['promote_id' => $fromPromote['id']];
if (count($shiftIds) > 0) {
$map['id'] = ['in', $shiftIds];
$otherMap['user_id'] = ['in', $shiftIds];
}
$userPlayerInfo = new UserPlayInfoModel();
$userPlayerInfo->where('promote_id=' . $fromPromoteId)->save(['promote_id' => $toPromoteId, 'promote_account' => $toPromote['account']]);
$status = M('user', 'tab_')->where($map)->save($updateData);
if (!$status) {
$model->rollback();
return ['status' => false, 'msg' => '系统异常,修改用户推广员失败'];
}
M('ShiftTask')->where('id=' . $task['id'])->save(['status' => 1]);
$status = M('user_play', 'tab_')->where($otherMap)->save($updateData);
if (!$status) {
$model->rollback();
return ['status' => false, 'msg' => '系统异常,修改玩家推广员失败'];
}
$status = M('user_play_info', 'tab_')->where($otherMap)->save($updateData);
if (!$status) {
$model->rollback();
return ['status' => false, 'msg' => '系统异常,修改角色推广员失败'];
}
M('spend', 'tab_')->where($otherMap)->where(['is_check' => ['in','1,2']])->save($updateData); // 只改未对账的数据
M('deposit', 'tab_')->where($otherMap)->save($updateData);
M('bind_spend', 'tab_')->where($otherMap)->save($updateData);
$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();
return ['status' => true, 'msg' => '玩家迁移成功'];
}
@ -784,6 +810,45 @@ class PromoteService {
'message' => '账号长度为6-15个字符',
];
}
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,

@ -0,0 +1,52 @@
<?php
namespace Base\Tool;
class IdCard
{
public static function isIdcard($id)
{
$id = strtoupper($id);
$regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";
$arr_split = array();
if (!preg_match($regx, $id)) {
return false;
}
if (15 == strlen($id)) {
$regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";
@preg_match($regx, $id, $arr_split);
//检查生日日期是否正确
$dtm_birth = "19" . $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];
if (!strtotime($dtm_birth)) {
return false;
} else {
return true;
}
} else {
$regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
@preg_match($regx, $id, $arr_split);
$dtm_birth = $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];
if (!strtotime($dtm_birth)) {
return false;
} else {
//检验18位身份证的校验码是否正确。
//校验位按照ISO 7064:1983.MOD 11-2的规定生成X可以认为是数字10。
$arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
$arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
$sign = 0;
for ($i = 0; $i < 17; $i++) {
$b = (int)$id{$i};
$w = $arr_int[$i];
$sign += $b * $w;
}
$n = $sign % 11;
$val_num = $arr_ch[$n];
if ($val_num != substr($id, 17, 1)) {
return false;
} else {
return true;
}
}
}
}
}

@ -962,99 +962,6 @@ class PromoteController extends BaseController
}
}
public function add_chlid()
{
if (IS_POST) {
$parentId = 0;
if (isset($_POST['promote_type']) && $_POST['promote_type'] == 2 && isset($_POST['parent_id'])) {
if ($_POST['parent_id'] == 0) {
$this->ajaxReturn(array('status' => -1, 'msg' => '请选择上级渠道'));
}
$parentId = $_POST['parent_id'];
} else {
$parentId = session('promote_auth.pid');
}
$user = new PromoteApi();
$promote = D('promote')->where(['id' => $parentId])->find();
$status = promoteCan(session('promote_auth.pid'), function ($level) use ($promote) {
if ($level == 1) {
return true;
} elseif ($level == 2) {
return true;
} elseif ($level == 3) {
return false;
}
});
if (!$status) {
$this->ajaxReturn(array('status' => -1, 'msg' => '无权限操作'));
}
$_POST['ba_id'] = $promote['ba_id'];
$_POST['parent_id'] = $parentId;
$_POST['parent_account'] = $promote['account'];
//三级渠道
if ($promote['parent_id'] > 0) {
$_POST['grand_id'] = $promote['parent_id'];
$_POST['grand_account'] = $promote['promote_account'];
}
if (isset($_POST['mobile_phone'])) {
if (!preg_match("/^1[3456789]{1}\d{9}$/", $_POST['mobile_phone'])) {
$this->ajaxReturn(array('status' => -1, 'msg' => '手机号格式错误'));
}
}
if (isset($_POST['idcard'])) {
if (!$this->isIdcard($_POST['idcard'])) {
$this->ajaxReturn(array('status' => -1, 'msg' => '身份证格式错误'));
}
}
if (mb_strlen($_POST['account']) < 6 || mb_strlen($_POST['account']) > 15) {
$this->error('账号长度为6-15个字符', U('Promote/edit_chlid', array('id' => $id, 'type' => I('type', 0))));
return false;
}
if (mb_strlen($_POST['real_name']) < 2 || mb_strlen($_POST['real_name']) > 4) {
$this->error('姓名长度为2-4个字符', U('Promote/edit_chlid', array('id' => $id, 'type' => I('type', 0))));
return false;
}
$res = $user->promote_add($_POST);
if (is_numeric($res)) {
$ba = new \Admin\Model\BusinessAffairsModel();
$ba->add_child($_POST['ba_id'], $res);
$this->ajaxReturn(array('status' => 1, 'msg' => "添加成功"));
} else {
$msg = $res == "渠道账号已存在" ? "子渠道账号已存在" : $res;
$this->ajaxReturn(array('status' => -1, 'msg' => $msg));
}
} else {
$type = I('type', 0);
$status = promoteCan(session('promote_auth.pid'), function ($level) use ($type) {
if ($level == 1) {
return true;
} elseif ($level == 2) {
if ($type == 1) {
return false;
}
return true;
} elseif ($level == 3) {
return false;
}
});
if (!$status) {
$this->error('无权限操作');
}
$model = new PromoteModel();
$promotes = $model->field(['id', 'account'])->where('parent_id=' . session("promote_auth.pid"))->select();
$this->assign('promotes', $promotes);
$this->meta_title = "添加子渠道";
$this->display();
}
}
public function resetPassword()
{
$promoteId = I('promote_id', 0);
@ -1922,54 +1829,6 @@ class PromoteController extends BaseController
$this->ajaxReturn(['status' => true, 'msg' => '下架成功']);
}
public function isIdcard($id)
{
$id = strtoupper($id);
$regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";
$arr_split = array();
if (!preg_match($regx, $id)) {
return false;
}
if (15 == strlen($id)) {
$regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";
@preg_match($regx, $id, $arr_split);
//检查生日日期是否正确
$dtm_birth = "19" . $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];
if (!strtotime($dtm_birth)) {
return false;
} else {
return true;
}
} else {
$regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
@preg_match($regx, $id, $arr_split);
$dtm_birth = $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];
if (!strtotime($dtm_birth)) {
return false;
} else {
//检验18位身份证的校验码是否正确。
//校验位按照ISO 7064:1983.MOD 11-2的规定生成X可以认为是数字10。
$arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
$arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
$sign = 0;
for ($i = 0; $i < 17; $i++) {
$b = (int)$id{$i};
$w = $arr_int[$i];
$sign += $b * $w;
}
$n = $sign % 11;
$val_num = $arr_ch[$n];
if ($val_num != substr($id, 17, 1)) {
return false;
} else {
return true;
}
}
}
}
function ajax_page($count, $row, $ajax_func = 'index', $current = 1)
{
$aside = '<select id="pagechange" name="row" onchange="seach(this)"><option value="5">每页5条</option><option value="10">每页10条</option><option value="25">每页25条</option><option value="50">每页50条</option><option value="100">每页100条</option></select>';

@ -1,182 +0,0 @@
<extend name="Public/promote_base"/>
<block name="css">
<link href="__CSS__/20180207/account.css" rel="stylesheet" >
</block>
<block name="body">
<div class="page-list normal_list promote-add_chlid-form">
<div class="trunk-title">
<div class="location">
<div class="location-container">当前位置:<span>管理中心></span><span><if condition="I('type') == 1">添加组长<else/>添加推广员</if></span></div>
</div>
<img src="__IMG__/20180207/icon_normal_ziqudao.png">
<span class="title_main"><if condition="I('type') == 1">添加组长<else/>添加推广员</if></span>
</div>
<div class="trunk-content article">
<div class="trunk-list list_normal">
<form action="{:U('Promote/add_chlid')}" novalidate="novalidate" method="post" class="base_info" id="form_reg">
<table class="table2">
<if condition="($parent_id eq 0) and ($grand_id eq 0) and (I('type') == 1)">
<input type="hidden" name="promote_type" value="1">
<else/>
<input type="hidden" name="promote_type" value="2">
<if condition="($parent_id eq 0) and ($grand_id eq 0)">
<tr>
<td class="l"><span class="req">*</span>上级渠道:</td>
<td class="r">
<select id="parent_id" name="parent_id" class="reselect select_gallery" style="width: 252px;" >
<option value="0">请选择上级渠道</option>
<volist name="promotes" id="promote">
<option ba-id="{$promote.id}" value="{$promote.id}">{$promote.account}</option>
</volist>
</select>
</td>
</tr>
</if>
</if>
<tr>
<td class="l"><span class="req">*</span>帐号:</td>
<td class="r">
<input type="text" class="name input-txt txt" name="account" id="account" maxlength="15" minlength="6" placeholder="请输入帐号">
</td>
</tr>
<tr>
<td class="l"><span class="req">*</span>姓名:</td>
<td class="r">
<input type="text" class="name input-txt txt" name="real_name" id="real_name" maxlength="4" minlength="2" placeholder="请输入姓名">
</td>
</tr>
<tr>
<td class="l"><span class="req">*</span>身份证:</td>
<td class="r">
<input type="text" class="name input-txt txt" name="idcard" id="idcard" placeholder="请输入身份证">
</td>
</tr>
<tr>
<td class="l"><span class="req">*</span>手机号:</td>
<td class="r">
<input type="text" class="name input-txt txt" name="mobile_phone" id="mobile_phone" placeholder="请输入手机号">
</td>
</tr>
<tr>
<td class="l"><span class="req">*</span>密码:</td>
<td class="r">
<input type="password" class="name txt" name="password" id="password" placeholder="请输入子渠道密码">
<span id="password_tip"></span>
</td>
</tr>
<tr>
<td class="l"><span class="req">*</span>确认密码:</td>
<td class="r">
<input type="password" class="name txt" name="repassword" id="repassword" placeholder="请输入确认密码">
<span id="repassword_tip"></span>
</td>
</tr>
<tr>
<td class="l">昵称:</td>
<td class="r">
<input type="text" class="name txt" name="nickname" id="nickname" placeholder="请输入子渠道昵称">
<span id="nickname_tip"></span>
</td>
</tr>
<tr>
<td class="l"></td>
<td class="r">
<input type="button" class="tj btn ajax-post" onclick="check()" value="确认添加" title="" target-form="base_info">
<a class="back_btn " alt="返回上一页" title="返回上一页" href="javascript:window.history.back();">返回</a>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
</block>
<block name="script">
<script type="text/javascript" src="__JS__/20170831/select2.min.js"></script>
<script type="text/javascript">
$(".select_gallery").select2();
function check() {
data = validation();
if(data.status !=1){layer.msg(data.msg,{icon:2}); return false;};
var account = $('#account').val();
var password = $('#password').val();
var nickname = $('#nickname').val();
var idcard = $('#idcard').val();
var mobile_phone = $('#mobile_phone').val();
var real_name = $('#real_name').val();
var promote_type = $('[name=promote_type]').val();
var repassword = $('#repassword').val();
var parent_id = $('#parent_id').val();
$.ajax({
type:"POST",
url:"{:U('add_chlid')}",
data:{
account: account,
password: password,
real_name: real_name,
repassword: repassword,
promote_type: promote_type,
parent_id: parent_id,
mobile_phone: mobile_phone,
idcard: idcard,
nickname: nickname,
},
success:function(res){
if(res.status == 1){
layer.msg(res.msg);
setTimeout(function(){
window.location.href="{:U(I('type') == 2 ? 'mygrand' : 'mychlid')}";
},1000);
}else{
layer.msg(res.msg);
}
}
});
// $('#form_reg').submit();
}
function validation(){
var json_data = "";
if($('#account').val()==""){
return json_data = {'status':0,'msg':'子渠道账号不能为空'}
}
// if($.trim($('#account').val()).length < 6){
// return json_data = {'status':0,'msg':'子渠道账号不能小于6位字符'}
// }
if($.trim($('#account').val()).length < 6 || $.trim($('#account').val()).length > 15){
return json_data = {'status':0,'msg':'子渠道账号长度为6-15位字符'}
}
if($.trim($('#real_name').val()).length < 2 || $.trim($('#real_name').val()).length > 4){
return json_data = {'status':0,'msg':'子渠道姓名长度为2-4位字符'}
}
if($('#password').val()==""){
return json_data = {'status':0,'msg':'子渠道密码不能为空'}
}
if($.trim($('#password').val()).length < 6){
return json_data = {'status':0,'msg':'子渠道密码不能小于6位字符'}
}
if($('#repassword').val()==""){
return json_data = {'status':0,'msg':'确认密码不能为空'}
}
if($('#repassword').val()!==$('#password').val()){
return json_data = {'status':0,'msg':'子渠道密码和确认密码不一致'}
}
var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
// if(!myreg.test($('#mobile_phone').val())){
// return json_data = {'status':0,'msg':'请输入正确的手机号'}
// }
// var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
// if(!myreg.test($('#email').val())){
// return json_data = {'status':0,'msg':'请输入正确的邮箱'}
// }
// if($.trim($('#nickname').val()).length == 0){
// return json_data = {'status':0,'msg':'昵称不能为空'};
// }
return json_data = {'status':1,'msg':'成功'};
}
</script>
</block>
Loading…
Cancel
Save