Points.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. /**
  3. * 积分管理
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. *
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * 控制器
  14. */
  15. class Points extends AdminControl
  16. {
  17. const EXPORT_SIZE = 5000;
  18. public function initialize()
  19. {
  20. parent::initialize();
  21. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/points.lang.php');
  22. }
  23. public function index()
  24. {
  25. if (!request()->isPost()) {
  26. $condition_arr = array();
  27. $mname = input('param.mname');
  28. if (!empty($mname)) {
  29. $condition_arr[] = array('pl_membername', 'like', '%' . $mname . '%');
  30. }
  31. $aname = input('param.aname');
  32. if (!empty($aname)) {
  33. $condition_arr[] = array('pl_adminname', 'like', '%' . $aname . '%');
  34. }
  35. $stage = input('get.stage');
  36. if ($stage) {
  37. $condition_arr[] = array('pl_stage', '=', trim($stage));
  38. }
  39. $stime = input('get.stime');
  40. $etime = input('get.etime');
  41. $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
  42. $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
  43. $start_unixtime = $if_start_time ? strtotime($stime) : null;
  44. $end_unixtime = $if_end_time ? strtotime($etime) : null;
  45. if ($start_unixtime) {
  46. $condition_arr[] = array('pl_addtime', '>=', $start_unixtime);
  47. }
  48. if ($end_unixtime) {
  49. $end_unixtime = $end_unixtime + 86399;
  50. $condition_arr[] = array('pl_addtime', '<=', $end_unixtime);
  51. }
  52. $search_desc = trim(input('param.description'));
  53. if (!empty($search_desc)) {
  54. $condition_arr[] = array('pl_desc', 'like', "%" . $search_desc . "%");
  55. }
  56. $points_model = model('points');
  57. $list_log = $points_model->getPointslogList($condition_arr, 10, '*', '');
  58. View::assign('pointslog', $list_log);
  59. View::assign('show_page', $points_model->page_info->render());
  60. $this->setAdminCurItem('index');
  61. return View::fetch();
  62. }
  63. }
  64. //积分规则设置
  65. function setting()
  66. {
  67. $config_model = model('config');
  68. if (request()->isPost()) {
  69. $update_array = array();
  70. $update_array['points_reg'] = intval(input('post.points_reg'));
  71. $update_array['points_login'] = intval(input('post.points_login'));
  72. $update_array['points_comments'] = intval(input('post.points_comments'));
  73. $update_array['points_orderrate'] = intval(input('post.points_orderrate'));
  74. $update_array['points_ordermax'] = intval(input('post.points_ordermax'));
  75. $update_array['points_invite'] = intval(input('post.points_invite'));
  76. $update_array['points_rebate'] = intval(input('post.points_rebate'));
  77. $result = $config_model->editConfig($update_array);
  78. if ($result === true) {
  79. $this->success(lang('ds_common_save_succ'));
  80. } else {
  81. $this->error(lang('ds_common_save_fail'));
  82. }
  83. } else {
  84. $list_setting = rkcache('config', true);
  85. View::assign('list_setting', $list_setting);
  86. $this->setAdminCurItem('setting');
  87. return View::fetch('setting');
  88. }
  89. }
  90. //积分明细查询
  91. function pointslog()
  92. {
  93. if (!request()->isPost()) {
  94. return View::fetch();
  95. } else {
  96. $data = [
  97. 'member_name' => input('post.member_name'),
  98. 'points_type' => input('post.points_type'),
  99. 'points_num' => intval(input('post.points_num')),
  100. 'points_desc' => input('post.points_desc'),
  101. ];
  102. $point_validate = ds_validate('point');
  103. if (!$point_validate->scene('pointslog')->check($data)) {
  104. $this->error($point_validate->getError());
  105. }
  106. $member_name = $data['member_name'];
  107. $member_info = model('member')->getMemberInfo(array('member_name' => $member_name));
  108. if (!is_array($member_info) || count($member_info) <= 0) {
  109. $this->error(lang('admin_points_userrecord_error'));
  110. }
  111. if ($data['points_type'] == 2 && $data['points_num'] > $member_info['member_points']) {
  112. $this->error(lang('admin_points_points_short_error') . $member_info['member_points']);
  113. }
  114. //积分数据记录
  115. $insert_arr['pl_memberid'] = $member_info['member_id'];
  116. $insert_arr['pl_membername'] = $member_info['member_name'];
  117. if ($data['points_type'] == 2) {
  118. $insert_arr['pl_points'] = -$data['points_num'];
  119. } else {
  120. $insert_arr['pl_points'] = $data['points_num'];
  121. }
  122. $insert_arr['pl_desc'] = $data['points_desc'];
  123. $insert_arr['pl_adminname'] = session('admin_name');
  124. $result = model('points')->savePointslog('system', $insert_arr);
  125. if ($result) {
  126. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  127. } else {
  128. $this->error(lang('error'), 'Points/index');
  129. }
  130. }
  131. }
  132. public function checkmember()
  133. {
  134. $name = trim(input('param.name'));
  135. if (!$name) {
  136. exit(json_encode(array('id' => 0)));
  137. }
  138. $member_info = model('member')->getMemberInfo(array('member_name' => $name));
  139. if (is_array($member_info) && count($member_info) > 0) {
  140. echo json_encode(array('id' => $member_info['member_id'], 'name' => $member_info['member_name'], 'points' => $member_info['member_points']));
  141. } else {
  142. exit(json_encode(array('id' => 0)));
  143. die;
  144. }
  145. }
  146. /**
  147. * 积分日志列表导出
  148. */
  149. public function export_step1()
  150. {
  151. $condition_arr = array();
  152. $mname = input('param.mname');
  153. if (!empty($mname)) {
  154. $condition_arr[] = array('pl_membername', 'like', '%' . $mname . '%');
  155. }
  156. $aname = input('param.aname');
  157. if (!empty($aname)) {
  158. $condition_arr[] = array('pl_adminname', 'like', '%' . $aname . '%');
  159. }
  160. $stage = input('get.stage');
  161. if ($stage) {
  162. $condition_arr[] = array('pl_stage', '=', trim($stage));
  163. }
  164. $stime = input('get.stime');
  165. $etime = input('get.etime');
  166. $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
  167. $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
  168. $start_unixtime = $if_start_time ? strtotime($stime) : null;
  169. $end_unixtime = $if_end_time ? strtotime($etime) : null;
  170. if ($start_unixtime || $end_unixtime) {
  171. $condition_arr[] = array('pl_addtime', 'between', array($start_unixtime, $end_unixtime));
  172. }
  173. $search_desc = trim(input('param.description'));
  174. if (!empty($search_desc)) {
  175. $condition_arr[] = array('pl_desc', 'like', "%" . $search_desc . "%");
  176. }
  177. $points_model = model('points');
  178. if (!is_numeric(input('param.page'))) {
  179. $count = $points_model->getPointsCount($condition_arr);
  180. $array = array();
  181. if ($count > self::EXPORT_SIZE) { //显示下载链接
  182. $page = ceil($count / self::EXPORT_SIZE);
  183. for ($i = 1; $i <= $page; $i++) {
  184. $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
  185. $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
  186. $array[$i] = $limit1 . ' ~ ' . $limit2;
  187. }
  188. View::assign('export_list', $array);
  189. return View::fetch('/public/excel');
  190. } else { //如果数量小,直接下载
  191. $list_log = $points_model->getPointsLogList($condition_arr, '', '*', self::EXPORT_SIZE);
  192. $this->createExcel($list_log);
  193. }
  194. } else { //下载
  195. $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
  196. $limit2 = self::EXPORT_SIZE;
  197. $list_log = $points_model->getPointsLogList($condition_arr, $limit2);
  198. $this->createExcel($list_log);
  199. }
  200. }
  201. /**
  202. * 生成excel
  203. *
  204. * @param array $data
  205. */
  206. private function createExcel($data = array())
  207. {
  208. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/export.lang.php');
  209. $excel_obj = new \excel\Excel();
  210. $excel_data = array();
  211. //设置样式
  212. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  213. //header
  214. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_member'));
  215. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_system'));
  216. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_point'));
  217. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_time'));
  218. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_jd'));
  219. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_ms'));
  220. $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'));
  221. foreach ((array) $data as $k => $v) {
  222. $tmp = array();
  223. $tmp[] = array('data' => $v['pl_membername']);
  224. $tmp[] = array('data' => $v['pl_adminname']);
  225. $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['pl_points']));
  226. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['pl_addtime']));
  227. $tmp[] = array('data' => str_replace(array('regist', 'login', 'comments', 'order', 'system', 'pointorder', 'app'), $state_cn, $v['pl_stage']));
  228. $tmp[] = array('data' => $v['pl_desc']);
  229. $excel_data[] = $tmp;
  230. }
  231. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  232. $excel_obj->addArray($excel_data);
  233. $excel_obj->addWorksheet($excel_obj->charset(lang('exp_pi_jfmx'), CHARSET));
  234. $excel_obj->generateXML($excel_obj->charset(lang('exp_pi_jfmx'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
  235. }
  236. protected function getAdminItemList()
  237. {
  238. $menu_array = array(
  239. array(
  240. 'name' => 'index',
  241. 'text' => lang('admin_points_log_title'),
  242. 'url' => (string)url('Points/index')
  243. ),
  244. array(
  245. 'name' => 'pointslog',
  246. 'text' => lang('pointslog'),
  247. 'url' => "javascript:dsLayerOpen('" . (string)url('Points/pointslog') . "','" . lang('pointslog') . "')"
  248. ),
  249. array(
  250. 'name' => 'setting',
  251. 'text' => lang('points_setting'),
  252. 'url' => (string)url('Points/setting')
  253. ),
  254. );
  255. return $menu_array;
  256. }
  257. }