Points.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. /**
  3. * 积分管理
  4. */
  5. namespace app\admin\controller;
  6. use think\facade\View;
  7. use think\facade\Lang;
  8. /**
  9. * ============================================================================
  10. * DSMall多用户商城
  11. * ============================================================================
  12. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  13. * 网站地址: http://www.csdeshang.com
  14. * ----------------------------------------------------------------------------
  15. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  16. * 不允许对程序代码以任何形式任何目的的再发布。
  17. * ============================================================================
  18. * 控制器
  19. */
  20. class Points extends AdminControl {
  21. const EXPORT_SIZE = 5000;
  22. public function initialize() {
  23. parent::initialize();
  24. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/points.lang.php');
  25. }
  26. public function index() {
  27. if (!request()->isPost()) {
  28. $condition_arr = array();
  29. $mname = input('param.mname');
  30. if (!empty($mname)) {
  31. $condition_arr[] = array('pl_membername','like', '%' . $mname . '%');
  32. }
  33. $aname = input('param.aname');
  34. if (!empty($aname)) {
  35. $condition_arr[] = array('pl_adminname','like', '%' . $aname . '%');
  36. }
  37. $stage = input('get.stage');
  38. if ($stage) {
  39. $condition_arr[]=array('pl_stage','=',trim($stage));
  40. }
  41. $stime = input('get.stime');
  42. $etime = input('get.etime');
  43. $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
  44. $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
  45. $start_unixtime = $if_start_time ? strtotime($stime) : null;
  46. $end_unixtime = $if_end_time ? strtotime($etime) : null;
  47. if ($start_unixtime) {
  48. $condition_arr[] = array('pl_addtime','>=', $start_unixtime);
  49. }
  50. if ($end_unixtime) {
  51. $end_unixtime=$end_unixtime+86399;
  52. $condition_arr[] = array('pl_addtime','<=', $end_unixtime);
  53. }
  54. $search_desc = trim(input('param.description'));
  55. if (!empty($search_desc)) {
  56. $condition_arr[] = array('pl_desc','like', "%" . $search_desc . "%");
  57. }
  58. $points_model = model('points');
  59. $list_log = $points_model->getPointslogList($condition_arr, 10, '*', '');
  60. View::assign('pointslog', $list_log);
  61. View::assign('show_page', $points_model->page_info->render());
  62. $this->setAdminCurItem('index');
  63. return View::fetch();
  64. }
  65. }
  66. //积分规则设置
  67. function setting(){
  68. $config_model = model('config');
  69. if (request()->isPost()) {
  70. $update_array = array();
  71. $update_array['points_reg'] = intval(input('post.points_reg'));
  72. $update_array['points_login'] = intval(input('post.points_login'));
  73. $update_array['points_comments'] = intval(input('post.points_comments'));
  74. $update_array['points_orderrate'] = intval(input('post.points_orderrate'));
  75. $update_array['points_ordermax'] = intval(input('post.points_ordermax'));
  76. $update_array['points_invite'] = intval(input('post.points_invite'));
  77. $update_array['points_rebate'] = intval(input('post.points_rebate'));
  78. $result = $config_model->editConfig($update_array);
  79. if ($result === true) {
  80. $this->success(lang('ds_common_save_succ'));
  81. } else {
  82. $this->error(lang('ds_common_save_fail'));
  83. }
  84. } else {
  85. $list_setting = rkcache('config', true);
  86. View::assign('list_setting', $list_setting);
  87. $this->setAdminCurItem('setting');
  88. return View::fetch('setting');
  89. }
  90. }
  91. //积分明细查询
  92. function pointslog() {
  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. $name = trim(input('param.name'));
  134. if (!$name) {
  135. exit(json_encode(array('id' => 0)));
  136. }
  137. $member_info = model('member')->getMemberInfo(array('member_name' => $name));
  138. if (is_array($member_info) && count($member_info) > 0) {
  139. echo json_encode(array('id' => $member_info['member_id'], 'name' => $member_info['member_name'], 'points' => $member_info['member_points']));
  140. } else {
  141. exit(json_encode(array('id' => 0)));
  142. die;
  143. }
  144. }
  145. /**
  146. * 积分日志列表导出
  147. */
  148. public function export_step1() {
  149. $condition_arr = array();
  150. $mname = input('param.mname');
  151. if (!empty($mname)) {
  152. $condition_arr[] = array('pl_membername','like', '%' . $mname . '%');
  153. }
  154. $aname = input('param.aname');
  155. if (!empty($aname)) {
  156. $condition_arr[] = array('pl_adminname','like', '%' . $aname . '%');
  157. }
  158. $stage = input('get.stage');
  159. if ($stage) {
  160. $condition_arr[]=array('pl_stage','=',trim($stage));
  161. }
  162. $stime = input('get.stime');
  163. $etime = input('get.etime');
  164. $if_start_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $stime);
  165. $if_end_time = preg_match('/^20\d{2}-\d{2}-\d{2}$/', $etime);
  166. $start_unixtime = $if_start_time ? strtotime($stime) : null;
  167. $end_unixtime = $if_end_time ? strtotime($etime) : null;
  168. if ($start_unixtime || $end_unixtime) {
  169. $condition_arr[] = array('pl_addtime','between', array($start_unixtime, $end_unixtime));
  170. }
  171. $search_desc = trim(input('param.description'));
  172. if (!empty($search_desc)) {
  173. $condition_arr[] = array('pl_desc','like', "%" . $search_desc . "%");
  174. }
  175. $points_model = model('points');
  176. if (!is_numeric(input('param.page'))) {
  177. $count = $points_model->getPointsCount($condition_arr);
  178. $array = array();
  179. if ($count > self::EXPORT_SIZE) { //显示下载链接
  180. $page = ceil($count / self::EXPORT_SIZE);
  181. for ($i = 1; $i <= $page; $i++) {
  182. $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
  183. $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
  184. $array[$i] = $limit1 . ' ~ ' . $limit2;
  185. }
  186. View::assign('export_list', $array);
  187. return View::fetch('/public/excel');
  188. } else { //如果数量小,直接下载
  189. $list_log = $points_model->getPointsLogList($condition_arr, '', '*', self::EXPORT_SIZE);
  190. $this->createExcel($list_log);
  191. }
  192. } else { //下载
  193. $limit1 = (input('param.page') - 1) * self::EXPORT_SIZE;
  194. $limit2 = self::EXPORT_SIZE;
  195. $list_log = $points_model->getPointsLogList($condition_arr, $limit2);
  196. $this->createExcel($list_log);
  197. }
  198. }
  199. /**
  200. * 生成excel
  201. *
  202. * @param array $data
  203. */
  204. private function createExcel($data = array()) {
  205. Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
  206. $excel_obj = new \excel\Excel();
  207. $excel_data = array();
  208. //设置样式
  209. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  210. //header
  211. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_member'));
  212. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_system'));
  213. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_point'));
  214. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_time'));
  215. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_jd'));
  216. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_pi_ms'));
  217. $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'));
  218. foreach ((array) $data as $k => $v) {
  219. $tmp = array();
  220. $tmp[] = array('data' => $v['pl_membername']);
  221. $tmp[] = array('data' => $v['pl_adminname']);
  222. $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['pl_points']));
  223. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['pl_addtime']));
  224. $tmp[] = array('data' => str_replace(array('regist', 'login', 'comments', 'order', 'system', 'pointorder', 'app'), $state_cn, $v['pl_stage']));
  225. $tmp[] = array('data' => $v['pl_desc']);
  226. $excel_data[] = $tmp;
  227. }
  228. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  229. $excel_obj->addArray($excel_data);
  230. $excel_obj->addWorksheet($excel_obj->charset(lang('exp_pi_jfmx'), CHARSET));
  231. $excel_obj->generateXML($excel_obj->charset(lang('exp_pi_jfmx'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
  232. }
  233. protected function getAdminItemList() {
  234. $menu_array = array(
  235. array(
  236. 'name' => 'index',
  237. 'text' => lang('admin_points_log_title'),
  238. 'url' => (string)url('Points/index')
  239. ),
  240. array(
  241. 'name' => 'pointslog',
  242. 'text' => lang('pointslog'),
  243. 'url' => "javascript:dsLayerOpen('".(string)url('Points/pointslog')."','".lang('pointslog')."')"
  244. ),
  245. array(
  246. 'name' => 'setting',
  247. 'text' => lang('points_setting'),
  248. 'url' => (string)url('Points/setting')
  249. ),
  250. );
  251. return $menu_array;
  252. }
  253. }