diff --git a/Application/Admin/Controller/MendController.class.php b/Application/Admin/Controller/MendController.class.php index 6b4bf9ca6..e937f5b80 100644 --- a/Application/Admin/Controller/MendController.class.php +++ b/Application/Admin/Controller/MendController.class.php @@ -1,8 +1,11 @@ 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 +82,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 +92,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 +117,37 @@ 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'] = '官方渠道'; + $params = I('post.'); + $service = new MendService(); + try { + + if (session('user_auth')['allow_over_week'] && $params['allow_over_week'] == 1) { + $params['allow_over_week'] = 1; + } else { + $params['allow_over_week'] = 0; } - - addOperationLog(['op_type'=>1,'key'=>$userData['account'].'/'.$promoteFromData['account'].'/'.$promoteToData['account'],'op_name'=>'编辑推广补链','url'=>U('Mend/edit',['id'=>$create['user_id']]),'menu'=>'推广员-推广员管理-推广补链-编辑推广补链']); + $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' => '推广员-推广员管理-推广补链-编辑推广补链', + 'content' => json_encode($params) + ]); $this->success('补链成功', U('lists'), 2); - }else{ - $this->error($res['msg']); + } catch (\Exception $e) { + $this->error($e->getMessage()); } } else { // echo 1;die(); @@ -194,8 +163,7 @@ class MendController extends ThinkController { $this->m_title = '推广补链'; $this->assign('commonset',M('Kuaijieicon')->where(['url'=>'Mend/lists','status'=>1])->find()); - - + $this->assign('allow_over_week', session('user_auth')['allow_over_week']); $this->display(); } } @@ -300,17 +268,11 @@ class MendController extends ThinkController { public function shiftInfo() { $id = I('id'); - $info = M("shift_task")->where("id = {$id} and status = 0")->find(); - + $info = M("mend", 'tab_')->where("id = {$id} and status = 0")->find(); if(empty($info)){ $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(); } @@ -318,11 +280,16 @@ class MendController extends ThinkController { public function cancelShift() { $id = I('id'); - $status = M('ShiftTask')->where(['id' => $id,'status' => 0])->save(['status' => 2]); - if ($status) { - addOperationLog(['op_type'=>1,'key'=>$id,'op_name'=>'取消补链','url'=>U('Mend/shiftInfo',['id'=>$id]),'menu'=>'推广员-推广员管理-推广补链-取消补链']); + $model = new Model(); + $model->startTrans(); + $status1 = M('ShiftTask')->where(['id' => $id,'status' => 0])->save(['status' => 2]); + $status2 = M('mend', 'tab_')->where(['task_id' => $id, 'status' => 0])->save(['status' => 2, 'update_time' => time()]); + + if ($status1 && $status2) { + $model->commit(); + addOperationLog(['op_type'=>1,'key'=>$id,'op_name'=>'取消补链','url'=>U('Mend/shiftInfo',['id'=>$id]),'menu'=>'推广员-推广员管理-推广补链-取消补链']); $this->ajaxReturn(array("status"=>1,"url"=> U('lists'))); } else { $this->ajaxReturn(array("status"=>0,"url"=> U('lists'))); diff --git a/Application/Admin/View/Mend/edit.html b/Application/Admin/View/Mend/edit.html index 16f777fc6..30b5e336f 100644 --- a/Application/Admin/View/Mend/edit.html +++ b/Application/Admin/View/Mend/edit.html @@ -72,7 +72,7 @@ 补链后渠道 - @@ -90,6 +90,22 @@ + + + 是否跨周补链: + + + + + + + + + 备注 @@ -152,7 +168,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..552097c55 --- /dev/null +++ b/Application/Base/Service/MendService.class.php @@ -0,0 +1,104 @@ + '处理中', + 1 => '处理成功', + 2 => '处理失败', + ]; + + public function getStatusText($status) + { + return self::$statusList[$status] ?? '未知'; + } + + public function addMendTask($params, $permPromote = null, $handlePromote = null) + { + $userId = $params['user_id'] ?? 0; + $orderTime = $params['order_time'] ?? ''; + $toPromoteId = $params['promote_id_to'] ?? ''; + $allowOverWeek = $params['allow_over_week'] ?? 0; + + $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 (strtotime($orderTime) > time()) { + throw new \Exception('订单时间不能大于今天'); + } + + if ($permPromote) { + $levelColumn = 'level'. $permPromote['level'] . '_id'; + $promote = M('promote', 'tab_')->where(['id' => $user['promote_id']])->where([$levelColumn => $permPromote['id']])->find(); + if (!$promote) { + throw new \Exception('所属推广员异常'); + } + } + + if (!$allowOverWeek && !$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 true; + } + return false; + } + + 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 false; + } + return true; + } + +} \ 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..074793b6e --- /dev/null +++ b/Application/Home/Controller/MendController.class.php @@ -0,0 +1,136 @@ +canViewMend) { + return $this->error('没有权限'); + } + + $page = intval(I('p', 1)); + $row = intval(I('row', 10)); + $params = I('get.'); + $loginer = $this->getLoginPromote(); + $promoteService = new PromoteService(); + + $permPromote = $loginer; + if ($loginer['shift_over_apply'] == 1) { + $permPromote = $promoteService->getTopPromote($loginer); + } + + $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]; + } + + $subInSql = $promoteService->subInSql($permPromote); + $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'. $permPromote['level'] . '_id'; + $promotes = M('promote', 'tab_')->field(['id', 'account'])->where([$levelColumn => $permPromote['id']])->select(); + + $this->assign('promotes', $promotes); + $this->assign('count', $count); + $this->assign('records', $records); + $this->meta_title = '补链记录'; + $this->display(); + } + + public function add() + { + if (!$this->canViewMend) { + return $this->error('没有权限'); + } + + $userId = I('user_id', 0); + $user = M('user', 'tab_')->where(['id' => $userId])->find(); + if (!$user) { + return $this->error('用户不存在'); + } + + $loginer = $this->getLoginPromote(); + $permPromote = $loginer; + $promoteService = new PromoteService(); + if ($loginer['shift_over_apply'] == 1) { + $permPromote = $promoteService->getTopPromote($loginer); + } + + $levelColumn = 'level'. $permPromote['level'] . '_id'; + $promote = M('promote', 'tab_')->where(['id' => $user['promote_id']])->where([$levelColumn => $permPromote['id']])->find(); + if (!$promote) { + return $this->error('所属推广员异常'); + } + + $promotes = M('promote', 'tab_')->field(['id', 'account'])->where([$levelColumn => $permPromote['id']])->select(); + + $this->meta_title = '玩家补链'; + $this->assign('user', $user); + $this->assign('promotes', $promotes); + $this->display(); + } + + public function save() + { + $params = I('post.'); + $loginer = $this->getLoginPromote(); + + $permPromote = $loginer; + $promoteService = new PromoteService(); + if ($loginer['shift_over_apply'] == 1) { + $permPromote = $promoteService->getTopPromote($loginer); + } + + $service = new MendService(); + try { + $service->addMendTask($params, $permPromote, $loginer); + $this->ajaxReturn(['status' => 1, 'msg' => '补链申请成功']); + } catch (\Exception $e) { + $this->ajaxReturn(['status' => 0, 'msg' => $e->getMessage()]); + } + } +} diff --git a/Application/Home/View/default/Mend/add.html b/Application/Home/View/default/Mend/add.html new file mode 100644 index 000000000..f3d024184 --- /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 @@ + + + + + + + + + + + + + + + + + + +