error('您没有权限'); } } public function index($p = 1) { $month = I('month', date('Y-m')); $loginPromote = $this->getLoginPromote(); $promoteGradeService = new PromoteGradeService(); $setting = $promoteGradeService->getCurrentSetting($loginPromote); if (is_null($setting)) { return $this->error('未设置评级规则'); } $parentId = I('parent_id', 0); $promoteId = I('promote_id', 0); $searchLevel = 0; $searchLevelName = ''; $currentDisplay = ''; $prevParentId = 0; $promoteService = new PromoteService(); $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 = '自己'; } $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); if (I('p', 1) == 1) { array_unshift($promotes, $parent); } $records = $promoteGradeService->searchGradeByPromotes($promotes, [ 'month' => $month, ], $setting); if (I('p', 1) == 1) { $records[0]['current_display'] = $currentDisplay; } $this->meta_title = '团队评级'; $this->assign('month', $month); $this->assign('prevParentId', $prevParentId); $this->assign('searchLevelName', $searchLevelName); $this->assign('subPromotes', $subPromotes); $this->assign('parentId', $parentId); $this->assign('records', $records); $this->assign('pagination', $pagination); $this->display(); } public function settings() { $loginPromote = $this->getLoginPromote(); $items = M('promote_grade_setting', 'tab_')->where(['company_id' => $loginPromote['company_id']])->select(); $symbols = PromoteGradeService::$symbols; $records = []; foreach ($items as $item) { $i = 0; $config = json_decode($item['config'], true); $gradeCount = count($config['grades']) + 1; if ($gradeCount == 1) { $records[] = [ 'id' => $item['id'], 'name' => $item['name'], 'grade_count' => $gradeCount, 'reach_level' => $config['reach_level'], 'grade_name' => $config['default_grade_name'], 'grade_value' => '全部' ]; } else { $firstGrade = $config['grades'][0]; $records[] = [ 'id' => $item['id'], 'name' => $item['name'], 'grade_count' => $gradeCount, 'reach_level' => $config['reach_level'], 'grade_name' => $config['default_grade_name'], 'grade_value' => ($firstGrade['symbol'] == 1 ? '<' : '<=') . $firstGrade['value'] ]; foreach ($config['grades'] as $key => $grade) { $records[] = [ 'id' => $item['id'], 'name' => $item['name'], 'grade_count' => 0, 'reach_level' => $config['reach_level'], 'grade_name' => $grade['name'], 'grade_value' => $symbols[$grade['symbol']] . $grade['value'] ]; } } } $this->assign('records', $records); $this->display(); } public function setting() { $id = I('id', 0); $setting = null; if ($id > 0) { $setting = M('promote_grade_setting', 'tab_')->where(['id' => $id])->find(); if (is_null($setting)) { return $this->error('记录不存在'); } else { $setting['config'] = json_decode($setting['config'], true); } } $this->assign('setting', $setting); $this->display(); } public function delete() { $id = I('id', 0); if ($id == 0) { return $this->error('记录不存在'); } $setting = M('promote_grade_setting', 'tab_')->field(['id'])->where(['id' => $id])->find(); if (is_null($setting)) { return $this->error('记录不存在'); } M('promote_grade_setting', 'tab_')->where(['id' => $id])->delete(); return $this->success('删除成功'); } public function saveSetting() { $params = I('post.'); $loginPromote = $this->getLoginPromote(); $promoteGradeService = new PromoteGradeService(); try { $promoteGradeService->saveSetting($params, $loginPromote); return $this->success('保存成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } }