Points.php 12 KB

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