diff --git a/Application/Base/Service/PromoteService.class.php b/Application/Base/Service/PromoteService.class.php index ccb8db809..4d89a3ae9 100644 --- a/Application/Base/Service/PromoteService.class.php +++ b/Application/Base/Service/PromoteService.class.php @@ -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'=>'数据异常' - ]; - } - } + return [ + 'status' => true, + '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' => '系统异常,添加变更记录失败']; + } - $userPlayer = new UserPlayModel(); - $userPlayer->where('promote_id=' . $fromPromoteId)->save(['promote_id' => $toPromoteId, 'promote_account' => $toPromote['account']]); + $updateData = [ + 'promote_id' => $toPromote['id'], + '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, diff --git a/Application/Base/Tool/IdCard.class.php b/Application/Base/Tool/IdCard.class.php new file mode 100644 index 000000000..da539ffce --- /dev/null +++ b/Application/Base/Tool/IdCard.class.php @@ -0,0 +1,52 @@ +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 = '每页5条每页10条每页25条每页50条每页100条'; diff --git a/Application/Home/View/default/Promote/add_chlid.html b/Application/Home/View/default/Promote/add_chlid.html deleted file mode 100644 index 5d9d63c2a..000000000 --- a/Application/Home/View/default/Promote/add_chlid.html +++ /dev/null @@ -1,182 +0,0 @@ - - - - - - - - - - 当前位置:管理中心>添加组长添加推广员 - - - 添加组长添加推广员 - - - - - - - - - - - - *上级渠道: - - - 请选择上级渠道 - - {$promote.account} - - - - - - - - *帐号: - - - - - - *姓名: - - - - - - *身份证: - - - - - - *手机号: - - - - - - *密码: - - - - - - - *确认密码: - - - - - - - 昵称: - - - - - - - - - - 返回 - - - - - - - - - - - - - - \ No newline at end of file