123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- <?php
- /**
- * 积分管理
- */
- namespace app\admin\controller;
- use think\facade\View;
- use think\facade\Lang;
- /**
-
- *
-
- *
- * ----------------------------------------------------------------------------
- *
-
- * 控制器
- */
- class Points extends AdminControl
- {
- const EXPORT_SIZE = 5000;
- public function initialize()
- {
- parent::initialize();
- Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/points.lang.php');
- }
- public function index()
- {
- if (!request()->isPost()) {
- $condition_arr = array();
- $mname = input('param.mname');
- if (!empty($mname)) {
- $condition_arr[] = array('pl_membername', 'like', '%' . $mname . '%');
- }
- $aname = input('param.aname');
- if (!empty($aname)) {
- $condition_arr[] = array('pl_adminname', 'like', '%' . $aname . '%');
- }
- $stage = input('get.stage');
- if ($stage) {
- $condition_arr[] = array('pl_stage', '=', trim($stage));
- }
- $stime = input('get.stime');
- $etime = input('get.etime');
- $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
- $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
- $start_unixtime = $if_start_time ? strtotime($stime) : null;
- $end_unixtime = $if_end_time ? strtotime($etime) : null;
- if ($start_unixtime) {
- $condition_arr[] = array('pl_addtime', '>=', $start_unixtime);
- }
- if ($end_unixtime) {
- $end_unixtime = $end_unixtime + 86399;
- $condition_arr[] = array('pl_addtime', '<=', $end_unixtime);
- }
- $search_desc = trim(input('param.description'));
- if (!empty($search_desc)) {
- $condition_arr[] = array('pl_desc', 'like', "%" . $search_desc . "%");
- }
- $points_model = model('points');
- $list_log = $points_model->getPointslogList($condition_arr, 10, '*', '');
- View::assign('pointslog', $list_log);
- View::assign('show_page', $points_model->page_info->render());
- $this->setAdminCurItem('index');
- return View::fetch();
- }
- }
- //积分规则设置
- function setting()
- {
- $config_model = model('config');
- if (request()->isPost()) {
- $update_array = array();
- $update_array['points_reg'] = intval(input('post.points_reg'));
- $update_array['points_login'] = intval(input('post.points_login'));
- $update_array['points_comments'] = intval(input('post.points_comments'));
- $update_array['points_orderrate'] = intval(input('post.points_orderrate'));
- $update_array['points_ordermax'] = intval(input('post.points_ordermax'));
- $update_array['points_invite'] = intval(input('post.points_invite'));
- $update_array['points_rebate'] = intval(input('post.points_rebate'));
- $result = $config_model->editConfig($update_array);
- if ($result === true) {
- $this->success(lang('ds_common_save_succ'));
- } else {
- $this->error(lang('ds_common_save_fail'));
- }
- } else {
- $list_setting = rkcache('config', true);
- View::assign('list_setting', $list_setting);
- $this->setAdminCurItem('setting');
- return View::fetch('setting');
- }
- }
- //积分明细查询
- function pointslog()
- {
- if (!request()->isPost()) {
- return View::fetch();
- } else {
- $data = [
- 'member_name' => input('post.member_name'),
- 'points_type' => input('post.points_type'),
- 'points_num' => intval(input('post.points_num')),
- 'points_desc' => input('post.points_desc'),
- ];
- $point_validate = ds_validate('point');
- if (!$point_validate->scene('pointslog')->check($data)) {
- $this->error($point_validate->getError());
- }
- $member_name = $data['member_name'];
- $member_info = model('member')->getMemberInfo(array('member_name' => $member_name));
- if (!is_array($member_info) || count($member_info) <= 0) {
- $this->error(lang('admin_points_userrecord_error'));
- }
- if ($data['points_type'] == 2 && $data['points_num'] > $member_info['member_points']) {
- $this->error(lang('admin_points_points_short_error') . $member_info['member_points']);
- }
- //积分数据记录
- $insert_arr['pl_memberid'] = $member_info['member_id'];
- $insert_arr['pl_membername'] = $member_info['member_name'];
- if ($data['points_type'] == 2) {
- $insert_arr['pl_points'] = -$data['points_num'];
- } else {
- $insert_arr['pl_points'] = $data['points_num'];
- }
- $insert_arr['pl_desc'] = $data['points_desc'];
- $insert_arr['pl_adminname'] = session('admin_name');
- $result = model('points')->savePointslog('system', $insert_arr);
- if ($result) {
- dsLayerOpenSuccess(lang('ds_common_op_succ'));
- } else {
- $this->error(lang('error'), 'Points/index');
- }
- }
- }
- public function checkmember()
- {
- $name = trim(input('param.name'));
- if (!$name) {
- exit(json_encode(array('id' => 0)));
- }
- $member_info = model('member')->getMemberInfo(array('member_name' => $name));
- if (is_array($member_info) && count($member_info) > 0) {
- echo json_encode(array('id' => $member_info['member_id'], 'name' => $member_info['member_name'], 'points' => $member_info['member_points']));
- } else {
- exit(json_encode(array('id' => 0)));
- die;
- }
- }
- /**
- * 积分日志列表导出
- */
- public function export_step1()
- {
- $condition_arr = array();
- $mname = input('param.mname');
- if (!empty($mname)) {
- $condition_arr[] = array('pl_membername', 'like', '%' . $mname . '%');
- }
- $aname = input('param.aname');
- if (!empty($aname)) {
- $condition_arr[] = array('pl_adminname', 'like', '%' . $aname . '%');
- }
- $stage = input('get.stage');
- if ($stage) {
- $condition_arr[] = array('pl_stage', '=', trim($stage));
- }
- $stime = input('get.stime');
- $etime = input('get.etime');
- $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
- $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
- $start_unixtime = $if_start_time ? strtotime($stime) : null;
- $end_unixtime = $if_end_time ? strtotime($etime) : null;
- if ($start_unixtime || $end_unixtime) {
- $condition_arr[] = array('pl_addtime', 'between', array($start_unixtime, $end_unixtime));
- }
- $search_desc = trim(input('param.description'));
- if (!empty($search_desc)) {
- $condition_arr[] = array('pl_desc', 'like', "%" . $search_desc . "%");
- }
- $points_model = model('points');
- if (!is_numeric(input('param.page'))) {
- $count = $points_model->getPointsCount($condition_arr);
- $array = array();
- if ($count > self::EXPORT_SIZE) { //显示下载链接
- $page = ceil($count / self::EXPORT_SIZE);
- for ($i = 1; $i <= $page; $i++) {
- $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
- $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
- $array[$i] = $limit1 . ' ~ ' . $limit2;
- }
- View::assign('export_list', $array);
- return View::fetch('/public/excel');
- } else { //如果数量小,直接下载
- $list_log = $points_model->getPointsLogList($condition_arr, '', '*', self::EXPORT_SIZE);
- $this->createExcel($list_log);
- }
- } else { //下载
- $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
- $limit2 = self::EXPORT_SIZE;
- $list_log = $points_model->getPointsLogList($condition_arr, $limit2);
- $this->createExcel($list_log);
- }
- }
- /**
- * 生成excel
- *
- * @param array $data
- */
- private function createExcel($data = array())
- {
- Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/export.lang.php');
- $excel_obj = new \excel\Excel();
- $excel_data = array();
- //设置样式
- $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
- //header
- $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_member'));
- $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_system'));
- $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_point'));
- $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_time'));
- $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_jd'));
- $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_ms'));
- $state_cn = array(lang('admin_points_stage_regist'), lang('admin_points_stage_login'), lang('admin_points_stage_comments'), lang('admin_points_stage_order'), lang('admin_points_stage_system'), lang('admin_points_stage_pointorder'), lang('admin_points_stage_app'));
- foreach ((array) $data as $k => $v) {
- $tmp = array();
- $tmp[] = array('data' => $v['pl_membername']);
- $tmp[] = array('data' => $v['pl_adminname']);
- $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['pl_points']));
- $tmp[] = array('data' => date('Y-m-d H:i:s', $v['pl_addtime']));
- $tmp[] = array('data' => str_replace(array('regist', 'login', 'comments', 'order', 'system', 'pointorder', 'app'), $state_cn, $v['pl_stage']));
- $tmp[] = array('data' => $v['pl_desc']);
- $excel_data[] = $tmp;
- }
- $excel_data = $excel_obj->charset($excel_data, CHARSET);
- $excel_obj->addArray($excel_data);
- $excel_obj->addWorksheet($excel_obj->charset(lang('exp_pi_jfmx'), CHARSET));
- $excel_obj->generateXML($excel_obj->charset(lang('exp_pi_jfmx'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
- }
- protected function getAdminItemList()
- {
- $menu_array = array(
- array(
- 'name' => 'index',
- 'text' => lang('admin_points_log_title'),
- 'url' => (string)url('Points/index')
- ),
- array(
- 'name' => 'pointslog',
- 'text' => lang('pointslog'),
- 'url' => "javascript:dsLayerOpen('" . (string)url('Points/pointslog') . "','" . lang('pointslog') . "')"
- ),
- array(
- 'name' => 'setting',
- 'text' => lang('points_setting'),
- 'url' => (string)url('Points/setting')
- ),
- );
- return $menu_array;
- }
- }
|