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