diff --git a/Application/Admin/Common/extend.php b/Application/Admin/Common/extend.php index 88fa10232..2135e7aec 100644 --- a/Application/Admin/Common/extend.php +++ b/Application/Admin/Common/extend.php @@ -3277,4 +3277,14 @@ function array_repeat($array,$keyid="id",$desc=false) $c = array_rsort($c,true); } return $c; +} + +function getShiftingMends(array $userIds = null) +{ + $map = ['status' => 0]; + if (!is_null($userIds)) { + $map['user_id'] = ['in', $userIds]; + } + $mends = M('mend', 'tab_')->field(['id', 'user_id'])->where($map)->select(); + return index_by_column('user_id', $mends); } \ No newline at end of file diff --git a/Application/Admin/Controller/MendController.class.php b/Application/Admin/Controller/MendController.class.php index 6b4bf9ca6..6a6c5a8fd 100644 --- a/Application/Admin/Controller/MendController.class.php +++ b/Application/Admin/Controller/MendController.class.php @@ -1,6 +1,8 @@ field("user_account,promote_account,pay_amount,promote_account_to,order_time,create_time,op_account,remark") + ->field("user_account,promote_account,pay_amount,promote_account_to,order_time,create_time,op_account,remark,status") ->where($map) ->order("create_time desc"); @@ -79,6 +81,7 @@ class MendController extends ThinkController { $data = $data->page($page, $row)->select(); } //格式化信息 + $mendService = new MendService(); foreach ($data as $key => $value) { ($data[$key]['promote_account']=='官方渠道')?($data[$key]['promote_account']=C('OFFICIEL_CHANNEL')):''; @@ -88,9 +91,10 @@ class MendController extends ThinkController { if(!$show_data_power){ $data[$key]['user_account'] = encryptStr($data[$key]['user_account']); } + $data[$key]['status'] = $mendService->getStatusText($value['status']); } - if($export) db2csv($data,"推广员管理_推广补链_补链记录",["玩家账号","补链前渠道","补链前归属金额","补链后渠道","切分时间","补链时间","操作人员","备注"]); + if($export) db2csv($data,"推广员管理_推广补链_补链记录",["玩家账号","补链前渠道","补链前归属金额","补链后渠道","切分时间","补链时间","操作人员","备注","处理状态"]); if(IS_POST){ $page = set_pagination($_REQUEST['row_count'],$row); @@ -112,73 +116,31 @@ class MendController extends ThinkController { $this->assign('show_data_power', $show_data_power); $this->display(); - // parent::lists("Mend",$p,$map); } public function edit($id = null) { if (IS_POST) { - $promoteService = new PromoteService(); - if ($_POST['prmoote_id_to'] == -1){ - $_POST['prmoote_id_to'] = 0; - } - if ($_POST['prmoote_id_to'] === ''){ - $this->error('请选择需要变更的渠道'); - } - if ($_POST['promote_id'] == $_POST['prmoote_id_to']) { - $this->error('没有变更数据'); - } - if ($_POST['order_time'] == '') { - $this->error('没有订单日期'); - } - //判断是否已经结算 - // if(self::checkSettlement(strtotime($_POST['order_time']),$_POST['promote_id'])){ - // $this->error('在订单日期内含有已经结算的订单,无法补链'); - // } - - // if(self::checkSpend(strtotime($_POST['order_time']),$_POST['account'])){ - // $this->error("在订单日期内含有已经结算的订单,无法补链。"); - // } - if(self::checkOrderTime(strtotime($_POST['order_time']))){ - $this->error('仅能补链本周数据,请重新选择补链时间'); - } - if(self::checkPromote(strtotime($_POST['order_time']),$_POST['account'])){ - $this->error('在订单日期内含有多个推广员,无法补链'); - } - - $create = $_REQUEST; - $create['order_time'] = date($create['order_time']); - $params = array( - "from_promote_id"=>$create['promote_id'], - "to_promote_id"=>$create['prmoote_id_to'], - "order_time"=>$create['order_time'], - "type"=>2, - "shift_ids"=>[$create['user_id']], - "creator_type"=>0, - "creator_id"=>$_SESSION["onethink_admin"]["user_auth"]["uid"] - ); - if(!empty($create['remark'])){ - $params['remark'] = $create['remark']; - } - -// dump($create);die(); - - $res = $promoteService->addShiftTask($params); - if($res['status']){ - - $userData = M('user','tab_')->field('account')->where(['id'=>$create['user_id']])->find(); - $promoteToData = M('promote','tab_')->field('account')->where(['id'=>$create['prmoote_id_to']])->find(); - $promoteFromData = M('promote','tab_')->field('account')->where(['id'=>$create['promote_id']])->find(); - if ($create['promote_id'] == '0') { - $promoteFromData['account'] = '官方渠道'; - } - - addOperationLog(['op_type'=>1,'key'=>$userData['account'].'/'.$promoteFromData['account'].'/'.$promoteToData['account'],'op_name'=>'编辑推广补链','url'=>U('Mend/edit',['id'=>$create['user_id']]),'menu'=>'推广员-推广员管理-推广补链-编辑推广补链']); + $params = I('post.'); + $service = new MendService(); + try { + + $service->addMendTask($params); + + $userData = M('user','tab_')->field(['account', 'promote_id', 'promote_account'])->where(['id' => $params['user_id']])->find(); + $promoteToData = M('promote','tab_')->field('account')->where(['id'=> $params['prmoote_id_to']])->find(); + addOperationLog([ + 'op_type' => 1, + 'key' => $userData['account'].'/'.$userData['promote_account'].'/'.$promoteToData['account'], + 'op_name' => '编辑推广补链', + 'url' => U('Mend/edit', ['id' => $userData['id']]), + 'menu' => '推广员-推广员管理-推广补链-编辑推广补链' + ]); $this->success('补链成功', U('lists'), 2); - }else{ - $this->error($res['msg']); + } catch (\Exception $e) { + $this->error($e->getMessage()); } } else { // echo 1;die(); @@ -300,17 +262,11 @@ class MendController extends ThinkController { public function shiftInfo() { $id = I('id'); - $info = M("shift_task")->where("id = {$id} and status = 0")->find(); - - if(empty($info)){ + $info = M("mend", 'tab_')->where("id = {$id} and status = 0")->find(); + if(empty($mend)){ $this->error("补链不存在或已处理"); } - - - $info['user_id'] = json_decode($info['shift_ids'])[0]; $info['order_time'] = date("Y-m-d",$info['order_time']); - $userid = $info['user_id']; - $info['account'] = M("User","tab_")->field("account")->where("id = '{$userid}'")->find()['account']; $this->assign('data',$info); $this->display(); } diff --git a/Application/Admin/View/Mend/edit.html b/Application/Admin/View/Mend/edit.html index 16f777fc6..07e05226d 100644 --- a/Application/Admin/View/Mend/edit.html +++ b/Application/Admin/View/Mend/edit.html @@ -72,7 +72,7 @@ 补链后渠道 - @@ -152,7 +152,7 @@ $(".select_gallery").select2(); //导航高亮 highlight_subnav('{:U('Mend/lists')}'); -Think.setValue("prmoote_id_to", {$data.promote_id|default = "''"}); +Think.setValue("promote_id_to", {$data.promote_id|default = "''"}); $('#submit').click(function(){ $('#form').submit(); }); diff --git a/Application/Admin/View/Mend/lists.html b/Application/Admin/View/Mend/lists.html index f84c816b9..4cc6f4019 100644 --- a/Application/Admin/View/Mend/lists.html +++ b/Application/Admin/View/Mend/lists.html @@ -65,7 +65,9 @@ aOh! 暂时还没有内容! + + @@ -96,12 +98,11 @@ - - 补链 - - 补链中 - - + + 补链 + + 补链中 + diff --git a/Application/Admin/View/Mend/recordList.html b/Application/Admin/View/Mend/recordList.html index 14bf92805..6e1fe62f8 100644 --- a/Application/Admin/View/Mend/recordList.html +++ b/Application/Admin/View/Mend/recordList.html @@ -75,6 +75,7 @@ 备注 切分时间 补链时间 + 处理状态 操作人员 @@ -115,6 +116,7 @@ {$data.order_time} {$data.create_time} + {$data.status} {$data.op_account} diff --git a/Application/Admin/View/Mend/shiftInfo.html b/Application/Admin/View/Mend/shiftInfo.html index c8a272de3..c37ffb375 100644 --- a/Application/Admin/View/Mend/shiftInfo.html +++ b/Application/Admin/View/Mend/shiftInfo.html @@ -57,20 +57,20 @@ 用户账号 - + 修改前渠道 - + 补链后渠道 - + @@ -102,7 +102,7 @@
- diff --git a/Application/Base/Service/MendService.class.php b/Application/Base/Service/MendService.class.php new file mode 100644 index 000000000..8d79e9683 --- /dev/null +++ b/Application/Base/Service/MendService.class.php @@ -0,0 +1,93 @@ + '处理中', + 1 => '处理成功', + 2 => '处理失败', + ]; + + public function getStatusText($status) + { + return self::$statusList[$status] ?? '未知'; + } + + public function addMendTask($params, $handlePromote = null) + { + $userId = $params['user_id'] ?? 0; + $remark = $params['remark'] ?? ''; + $orderTime = $params['order_time'] ?? ''; + $toPromoteId = $params['promote_id_to'] ?? ''; + + $promoteService = new PromoteService(); + if ($toPromoteId == -1) { + $toPromoteId = 0; + } + if ($toPromoteId === '') { + throw new \Exception('请选择需要变更的渠道'); + } + + $user = M('user', 'tab_')->where(['id' => $userId])->find(); + if (!$user) { + throw new \Exception('用户不存在'); + } + if ($user['promote_id'] == $toPromoteId) { + throw new \Exception('没有变更数据'); + } + if ($orderTime == '') { + throw new \Exception('没有订单日期'); + } + + if ($this->checkOrderTime(strtotime($orderTime))) { + throw new \Exception('仅能补链本周数据,请重新选择补链时间'); + } + + if ($this->checkPromote(strtotime($orderTime), $user['account'])) { + throw new \Exception('在订单日期内含有多个推广员,无法补链'); + } + + $data = [ + 'from_promote_id' => $user['promote_id'], + 'to_promote_id' => $toPromoteId, + 'order_time' => $orderTime, + 'type' => 2, + 'shift_ids' => [$userId], + 'creator_type' => $handlePromote ? 1 : 0, + 'creator_id' => $handlePromote ? $handlePromote['id'] : $_SESSION["onethink_admin"]["user_auth"]["uid"] + ]; + + if(!empty($params['remark'])){ + $data['remark'] = $params['remark']; + } + + $result = $promoteService->addShiftTask($data); + if (!$result['status']) { + throw new \Exception($result['msg']); + } + } + + private function checkOrderTime($orderTime) + { + $sdefaultDate = date('Y-m-d'); + $first = 1; //周一开始 + $w = date('w',strtotime($sdefaultDate)); + $checktime = strtotime("$sdefaultDate -" . ($w ? $w - $first : 6) .' days'); //本周开始时间 + if($orderTime >= $checktime){ + //在本周允许换绑 + return false; + } + return true; + } + + private function checkPromote($orderTime, $account) + { + $res = M('Spend','tab_')->field('promote_id')->where(['pay_time' => array('EGT', $orderTime), 'user_account' => $account])->group('promote_id')->select(); + if(count($res)>1) { + return true; + } + return false; + } + +} \ No newline at end of file diff --git a/Application/Base/Service/PromoteService.class.php b/Application/Base/Service/PromoteService.class.php index 885fd2019..cf9eb1c73 100644 --- a/Application/Base/Service/PromoteService.class.php +++ b/Application/Base/Service/PromoteService.class.php @@ -134,11 +134,6 @@ class PromoteService { ]; } - $isFuture = false; - if (strtotime($orderTime) > strtotime(date('Y-m-d 23:59:59'))) { - $isFuture = true; - } - $data = [ 'from_promote_id' => $fromPromoteId, 'to_promote_id' => $toPromoteId, @@ -154,6 +149,10 @@ class PromoteService { ]; if (M('shift_task', 'sys_')->add($data)) { + if ($type == 2) { + $data['id'] = M()->getLastInsID(); + $this->addMendsByTask($data); + } return [ 'status' => true, 'msg'=>'迁移任务创建成功' @@ -166,6 +165,49 @@ class PromoteService { } } + public function addMendsByTask($task) + { + $userIds = json_decode($task['shift_ids'], true); + $users = M('user', 'tab_')->field(['id', 'account', 'nickname'])->where(['id' => ['in', $userIds]])->select(); + $users = index_by_column('id', $users); + $toPromote = M('promote','tab_')->field(['id', 'account'])->where(['id' => $task['to_promote_id']])->find(); + $fromPromote = M('promote','tab_')->field(['id', 'account'])->where(['id' => $task['from_promote_id']])->find(); + + $creator = null; + $opAccount = ''; + if ($task['creator_type'] == 1) { + $creator = M('promote', 'tab_')->where(['id' => $task['creator_id']])->find(); + $opAccount = $creator ? $creator['account'] : ''; + } else { + $creator = M('ucenter_member', 'sys_')->where(['id' => $task['creator_id']])->find(); + $opAccount = $creator ? $creator['username'] : ''; + } + + $mends = []; + foreach ($userIds as $userId) { + $user = $users[$userId]; + $mends[] = [ + 'task_id' => $task['id'], + 'user_id' => $userId, + 'user_account' => $user['account'], + 'user_nickname' => $user['nickname'], + 'promote_id' => $fromPromote ? $fromPromote['id'] : 0, + 'promote_account' => $fromPromote ? $fromPromote['account'] : C('OFFICIEL_CHANNEL'), + 'promote_id_to' => $toPromote ? $toPromote['id'] : 0, + 'promote_account_to' => $toPromote ? $toPromote['account'] : C('OFFICIEL_CHANNEL'), + 'remark' => $task['remark'] == '' ? ($task['creator_type'] == 0 ? '后台补链' : '玩家迁移') : $task['remark'], + 'order_time' => $task['order_time'], + 'create_time' => time(), + 'pay_amount' => 0, + 'op_id' => $task['creator_id'], + 'op_account' => $opAccount, + 'op_type' => $task['creator_type'], + 'bind_type' => 1, + ]; + } + M('mend', 'tab_')->addAll($mends); + } + public function shiftPromote($task) { $model = new Model(); @@ -309,17 +351,6 @@ class PromoteService { $fromPromoteId = $task['from_promote_id']; $orderTime = $task['order_time']; $shiftIds = json_decode($task['shift_ids'], true) ?? []; - $remark = $task['remark'] ?? ''; - - $creator = null; - $opAccount = ''; - if ($task['creator_type'] == 1) { - $creator = M('promote', 'tab_')->where(['id' => $task['creator_id']])->find(); - $opAccount = $creator ? $creator['account'] : ''; - } else { - $creator = M('ucenter_member', 'sys_')->where(['id' => $task['creator_id']])->find(); - $opAccount = $creator ? $creator['username'] : ''; - } $toPromote = M('promote', 'tab_')->where(['id' => $toPromoteId])->find(); $fromPromote = M('promote', 'tab_')->where(['id' => $fromPromoteId])->find(); @@ -357,26 +388,17 @@ class PromoteService { $formConpany = M('promote_company', 'tab_')->field(['company_name', 'company_belong'])->where(['id' => $fromPromote['company_id']])->find(); $toConpany = M('promote_company', 'tab_')->field(['company_name', 'company_belong'])->where(['id' => $toPromote['company_id']])->find(); $belongs = PromoteCompanyService::$belongs; - $mends = []; + + $model = new Model(); + $model->startTrans(); + + $hasError = false; foreach ($users as $item) { $amount = isset($payAmountRows[$item['id']]) ? round(floatval($payAmountRows[$item['id']]['pay_amount']), 2) : 0; - $mends[] = [ - 'user_id' => $item['id'], - 'user_account' => $item['account'], - 'user_nickname' => $item['nickname'], - 'promote_id' => $fromPromote['id'], - 'promote_account' => $fromPromote['account'], - 'promote_id_to' => $toPromote['id'], - 'promote_account_to' => $toPromote['account'], - 'remark' => $remark == '' ? ($task['creator_type'] == 0 ? '后台补链' : '玩家迁移') : $remark, - 'order_time' => $orderTime, - 'create_time' => time(), - 'pay_amount' => $amount, - 'op_id' => $creator ? $creator['id'] : 0, - 'op_account' => $opAccount, - 'op_type' => $task['creator_type'], - 'bind_type' => 1, - ]; + $status = M('mend', 'tab_')->where(['task_id' => $task['id'], 'user_id' => $item['id']])->save(['status' => 1, 'pay_amount' => $amount, 'update_time' => time()]); + if (!$status) { + $hasError = true; + } if ($amount > 500) { $userWord = '玩家账号' . $item['account']; $fromWord = $fromPromote['account'] . ($formConpany ? '(' . $belongs[$formConpany['company_belong']] . '-' . $formConpany['company_name'] : ''); @@ -395,20 +417,16 @@ class PromoteService { } } + if ($hasError) { + $model->rollback(); + return ['status' => false, 'msg' => '系统异常,修改补链记录失败']; + } + $toTopPromote = $this->getTopPromote($toPromote); $hasGameIds = $toTopPromote['game_ids'] == '' ? [] : explode(',', $toTopPromote['game_ids']); $hasNotGameIds = M('game', 'tab_')->where(['game_id' => ['not in', $hasGameIds]])->getField('id', true); $hasNotGameIds = $hasNotGameIds ?? []; - $model = new Model(); - $model->startTrans(); - - $status = M('mend', 'tab_')->addAll($mends); - if (!$status) { - $model->rollback(); - return ['status' => false, 'msg' => '系统异常,添加变更记录失败']; - } - if (count($notices) > 0) { M('admin_notice', 'tab_')->addAll($notices); } diff --git a/Application/Common/Common/extend.php b/Application/Common/Common/extend.php index 415a862d5..e9041ef69 100644 --- a/Application/Common/Common/extend.php +++ b/Application/Common/Common/extend.php @@ -3057,4 +3057,9 @@ function getAggExceptIds($gameSettings) } } return $exceptIds; +} + +function getHideAccount($account) +{ + return substr($account, 0, 2) . '******' . substr($account, 8); } \ No newline at end of file diff --git a/Application/Home/Controller/MendController.class.php b/Application/Home/Controller/MendController.class.php new file mode 100644 index 000000000..d46867079 --- /dev/null +++ b/Application/Home/Controller/MendController.class.php @@ -0,0 +1,110 @@ +getLoginPromote(); + + $map = ['op_type' => 1, '_string' => '1=1']; + if(isset($params['account'])) { + $map['user_account']= ['like', '%' . $params['account'] . '%']; + } + if(!empty($params['promote_id'])) { + $map['promote_id']= $params['promote_id']; + } + if(!empty($params['promote_id_to'])) { + $map['promote_id_to'] = $params['promote_id_to']; + } + if(!empty($params['op_id'])) { + $map['op_id'] = $params['op_id']; + } + if (!empty($params['time_start'])) { + $map['order_time'] = ['egt', strtotime($params['time_start'])]; + } + if (!empty($params['time_end'])) { + $map['order_time'] = ['elt', strtotime($params['time_end']) + 86399]; + } + + $promoteService = new PromoteService(); + $subInSql = $promoteService->subInSql($loginer); + $map['_string'] .= ' and (promote_id in (' . $subInSql . ') or promote_id_to in (' . $subInSql . '))'; + + $records = M('mend', 'tab_')->where($map)->order('create_time desc')->page($page, $row)->select(); + $count = M('mend', 'tab_')->where($map)->count(); + + $mendService = new MendService(); + foreach ($records as $key => $record) { + $record['status_text'] = $mendService->getStatusText($record['status']); + $records[$key] = $record; + } + + + $page = set_pagination($count, $row, $params); + if ($page) { + $this->assign('_page', $page); + } + + $levelColumn = 'level'. $loginer['level'] . '_id'; + $promotes = M('promote', 'tab_')->field(['id', 'account'])->where([$levelColumn => $loginer['id']])->select(); + + $this->assign('promotes', $promotes); + $this->assign('count', $count); + $this->assign('records', $records); + $this->meta_title = '补链记录'; + $this->display(); + } + + public function add() + { + $userId = I('user_id', 0); + $user = M('user', 'tab_')->where(['id' => $userId])->find(); + if (!$user) { + return $this->error('用户不存在'); + } + + $loginer = $this->getLoginPromote(); + $levelColumn = 'level'. $loginer['level'] . '_id'; + $promote = M('promote', 'tab_')->where(['id' => $user['promote_id']])->where([$levelColumn => $loginer['id']])->find(); + if (!$promote) { + return $this->error('所属推广员异常'); + } + + $promotes = M('promote', 'tab_')->field(['id', 'account'])->where([$levelColumn => $loginer['id']])->select(); + + $this->meta_title = '玩家补链'; + $this->assign('user', $user); + $this->assign('promotes', $promotes); + $this->display(); + } + + public function save() + { + $params = I('post.'); + $loginer = $this->getLoginPromote(); + $service = new MendService(); + try { + $service->addMendTask($params, $loginer); + $this->ajaxReturn(['status' => 1, 'msg' => '补链申请成功']); + } catch (\Exception $e) { + $this->ajaxReturn(['status' => 0, 'msg' => $e->getMessage()]); + } + } +} diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index ec413f8b3..3312f920a 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -341,7 +341,7 @@ class QueryController extends BaseController $list['new_login_time'] = date('Y-m-d H:i:s', $newLoginData['login_time']); $list['new_login_ip'] = $newLoginData['login_ip']; - $list['account'] = substr($list['account'], 0, 2) . '******' . substr($list['account'], 8); + $list['account'] = getHideAccount($list['account']); if(!empty($list['device_number'])) { $list['device_number'] = encryption($list['device_number']); } @@ -1786,6 +1786,7 @@ class QueryController extends BaseController } $columns = [ + 'role.user_id', 'user_account', 'role.promote_account', 'role.game_name', diff --git a/Application/Home/View/default/Mend/add.html b/Application/Home/View/default/Mend/add.html new file mode 100644 index 000000000..ca5bd7b69 --- /dev/null +++ b/Application/Home/View/default/Mend/add.html @@ -0,0 +1,168 @@ + + + + + + + + +
+ + + + + + + + + + \ No newline at end of file diff --git a/Application/Home/View/default/Mend/index.html b/Application/Home/View/default/Mend/index.html new file mode 100644 index 000000000..9334c5bf0 --- /dev/null +++ b/Application/Home/View/default/Mend/index.html @@ -0,0 +1,179 @@ + + + + + + + + + + + + + + + + + + + diff --git a/Application/Home/View/default/Public/promote_base.html b/Application/Home/View/default/Public/promote_base.html index eec420a4b..f76fba722 100644 --- a/Application/Home/View/default/Public/promote_base.html +++ b/Application/Home/View/default/Public/promote_base.html @@ -89,6 +89,7 @@ IOS下载数统计 用户留存率 游戏分区数据汇总 + 补链记录 diff --git a/Application/Home/View/default/Query/userRoles.html b/Application/Home/View/default/Query/userRoles.html index 31f4a578a..ba6c0e25f 100644 --- a/Application/Home/View/default/Query/userRoles.html +++ b/Application/Home/View/default/Query/userRoles.html @@ -157,6 +157,7 @@ + 操作

暂无数据

@@ -179,6 +180,8 @@ {$record.role_name} {$record.role_level} {$record.create_time} + 补链