exppoints.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. /**
  3. * 经验值管理
  4. *
  5. ***/
  6. defined('InShopNC') or exit('Access Invalid!');
  7. class exppointsControl extends SystemControl{
  8. const EXPORT_SIZE = 5000;
  9. public function __construct(){
  10. parent::__construct();
  11. }
  12. /**
  13. * 设置经验值获取规则
  14. */
  15. public function expsettingOp(){
  16. $model_setting = Model('setting');
  17. if (chksubmit()){
  18. $exp_arr = array();
  19. $exp_arr['exp_login'] = intval($_POST['exp_login'])?$_POST['exp_login']:0;
  20. $exp_arr['exp_comments'] = intval($_POST['exp_comments'])?$_POST['exp_comments']:0;
  21. $exp_arr['exp_orderrate'] = intval($_POST['exp_orderrate'])?$_POST['exp_orderrate']:0;
  22. $exp_arr['exp_ordermax'] = intval($_POST['exp_ordermax'])?$_POST['exp_ordermax']:0;
  23. $result = $model_setting->updateSetting(array('exppoints_rule'=>serialize($exp_arr)));
  24. if ($result === true){
  25. $this->log(L('nc_edit,nc_exppoints_manage,nc_exppoints_setting'),1);
  26. showMessage(L('nc_common_save_succ'));
  27. }else {
  28. showMessage(L('nc_common_save_fail'));
  29. }
  30. }
  31. $list_setting = $model_setting->getListSetting();
  32. $list_setting['exppoints_rule'] = $list_setting['exppoints_rule']?unserialize($list_setting['exppoints_rule']):array();
  33. Tpl::output('list_setting',$list_setting);
  34. Tpl::showpage('exppoints.setting');
  35. }
  36. /**
  37. * 积分日志列表
  38. */
  39. public function indexOp(){
  40. $where = array();
  41. $search_mname = trim($_GET['mname']);
  42. $where['exp_membername'] = array('like',"%{$search_mname}%");
  43. if ($_GET['stage']){
  44. $where['exp_stage'] = trim($_GET['stage']);
  45. }
  46. $stime = $_GET['stime']?strtotime($_GET['stime']):0;
  47. $etime = $_GET['etime']?strtotime($_GET['etime']):0;
  48. if ($stime > 0 && $etime>0){
  49. $where['exp_addtime'] = array('between',array($stime,$etime));
  50. }elseif ($stime > 0){
  51. $where['exp_addtime'] = array('egt',$stime);
  52. }elseif ($etime > 0){
  53. $where['exp_addtime'] = array('elt',$etime);
  54. }
  55. $search_desc = trim($_GET['description']);
  56. $where['exp_desc'] = array('like',"%$search_desc%");
  57. //查询积分日志列表
  58. $model = Model('exppoints');
  59. $list_log = $model->getExppointsLogList($where, '*', 20, 0, 'exp_id desc');
  60. //信息输出
  61. Tpl::output('stage_arr',$model->getStage());
  62. Tpl::output('show_page',$model->showpage(2));
  63. Tpl::output('list_log',$list_log);
  64. Tpl::showpage('exppoints.log');
  65. }
  66. /**
  67. * 积分日志列表导出
  68. */
  69. public function export_step1Op(){
  70. $where = array();
  71. $search_mname = trim($_GET['mname']);
  72. $where['exp_membername'] = array('like',"%{$search_mname}%");
  73. if ($_GET['stage']){
  74. $where['exp_stage'] = trim($_GET['stage']);
  75. }
  76. $stime = $_GET['stime']?strtotime($_GET['stime']):0;
  77. $etime = $_GET['etime']?strtotime($_GET['etime']):0;
  78. if ($stime > 0 && $etime>0){
  79. $where['exp_addtime'] = array('between',array($stime,$etime));
  80. }elseif ($stime > 0){
  81. $where['exp_addtime'] = array('egt',$stime);
  82. }elseif ($etime > 0){
  83. $where['exp_addtime'] = array('elt',$etime);
  84. }
  85. $search_desc = trim($_GET['description']);
  86. $where['exp_desc'] = array('like',"%$search_desc%");
  87. //查询积分日志列表
  88. $model = Model('exppoints');
  89. $list_log = $model->getExppointsLogList($where, '*', self::EXPORT_SIZE, 0, 'exp_id desc');
  90. if (!is_numeric($_GET['curpage'])){
  91. $count = $model->getExppointsLogCount($where);
  92. $array = array();
  93. if ($count > self::EXPORT_SIZE ){ //显示下载链接
  94. $page = ceil($count/self::EXPORT_SIZE);
  95. for ($i=1;$i<=$page;$i++){
  96. $limit1 = ($i-1)*self::EXPORT_SIZE + 1;
  97. $limit2 = $i*self::EXPORT_SIZE > $count ? $count : $i*self::EXPORT_SIZE;
  98. $array[$i] = $limit1.' ~ '.$limit2 ;
  99. }
  100. Tpl::output('list',$array);
  101. Tpl::showpage('export.excel');
  102. }else{ //如果数量小,直接下载
  103. $this->createExcel($list_log);
  104. }
  105. }else{ //下载
  106. $this->createExcel($list_log);
  107. }
  108. }
  109. /**
  110. * 生成excel
  111. *
  112. * @param array $data
  113. */
  114. private function createExcel($data = array()){
  115. import('libraries.excel');
  116. $excel_obj = new Excel();
  117. $excel_data = array();
  118. //设置样式
  119. $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
  120. //header
  121. $excel_data[0][] = array('styleid'=>'s_title','data'=>'会员名称');
  122. $excel_data[0][] = array('styleid'=>'s_title','data'=>'经验值');
  123. $excel_data[0][] = array('styleid'=>'s_title','data'=>'添加时间');
  124. $excel_data[0][] = array('styleid'=>'s_title','data'=>'操作阶段');
  125. $excel_data[0][] = array('styleid'=>'s_title','data'=>'描述');
  126. $stage_arr = Model('exppoints')->getStage();
  127. foreach ((array)$data as $k=>$v){
  128. $tmp = array();
  129. $tmp[] = array('data'=>$v['exp_membername']);
  130. $tmp[] = array('format'=>'Number','data'=>ncPriceFormat($v['exp_points']));
  131. $tmp[] = array('data'=>date('Y-m-d H:i:s',$v['exp_addtime']));
  132. $tmp[] = array('data'=>$stage_arr[$v['exp_stage']]);
  133. $tmp[] = array('data'=>$v['exp_desc']);
  134. $excel_data[] = $tmp;
  135. }
  136. $excel_data = $excel_obj->charset($excel_data,CHARSET);
  137. $excel_obj->addArray($excel_data);
  138. $excel_obj->addWorksheet($excel_obj->charset('经验值明细',CHARSET));
  139. $excel_obj->generateXML($excel_obj->charset('经验值明细',CHARSET).$_GET['curpage'].'-'.date('Y-m-d-H',time()));
  140. }
  141. }