Exppoints.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. *
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 经验值管理 控制器
  14. */
  15. class Exppoints 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') . '/membergrade.lang.php');
  22. }
  23. /**
  24. * 设置经验值获取规则
  25. */
  26. public function expsetting()
  27. {
  28. $config_model = model('config');
  29. if (request()->isPost()) {
  30. $exp_arr = array();
  31. $exp_arr['exp_login'] = intval(input('post.exp_login'));
  32. $exp_arr['exp_comments'] = intval(input('post.exp_comments'));
  33. $exp_arr['exp_orderrate'] = intval(input('post.exp_orderrate'));
  34. $exp_arr['exp_ordermax'] = intval(input('post.exp_ordermax'));
  35. $result = $config_model->editConfig(array('exppoints_rule' => serialize($exp_arr)));
  36. if ($result === true) {
  37. $this->log(lang('ds_edit') . lang('ds_exppoints_manage') . lang('ds_exppoints_setting'), 1);
  38. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  39. } else {
  40. $this->error(lang('ds_common_save_fail'));
  41. }
  42. } else {
  43. $list_setting = $config_model->getOneConfigByCode('exppoints_rule');
  44. $list_setting = unserialize($list_setting['value']);
  45. View::assign('list_setting', $list_setting);
  46. return View::fetch();
  47. }
  48. }
  49. /**
  50. * 经验值日志列表
  51. */
  52. public function index()
  53. {
  54. $where = array();
  55. $search_mname = trim(input('param.mname'));
  56. if (!empty($search_mname)) {
  57. $where[] = array('explog_membername', 'like', "%{$search_mname}%");
  58. }
  59. if (input('param.stage')) {
  60. $where[] = array('explog_stage', '=', trim(input('param.stage')));
  61. }
  62. $stime = input('param.stime') ? strtotime(input('param.stime')) : 0;
  63. $etime = input('param.etime') ? strtotime(input('param.etime')) : 0;
  64. if ($stime > 0) {
  65. $where[] = array('explog_addtime', '>=', $stime);
  66. }
  67. if ($etime > 0) {
  68. $etime = $etime + 86399;
  69. $where[] = array('explog_addtime', '<=', $etime);
  70. }
  71. $search_desc = trim(input('param.description'));
  72. if (!empty($search_desc)) {
  73. $where[] = array('explog_desc', 'like', "%" . $search_desc . "%");
  74. }
  75. //查询经验值日志列表
  76. $exppoints_model = model('exppoints');
  77. $list_log = $exppoints_model->getExppointslogList($where, '*', 20, 'explog_id desc');
  78. //信息输出
  79. View::assign('stage_arr', $exppoints_model->getExppointsStage());
  80. View::assign('show_page', $exppoints_model->page_info->render());
  81. View::assign('list_log', $list_log);
  82. $this->setAdminCurItem('explog');
  83. return View::fetch();
  84. }
  85. /**
  86. * 经验值调整
  87. */
  88. public function edit()
  89. {
  90. if (!request()->isPost()) {
  91. return View::fetch();
  92. } else {
  93. $data = [
  94. 'member_name' => input('post.member_name'),
  95. 'exppoints_type' => input('post.exppoints_type'),
  96. 'exppoints_num' => intval(input('post.exppoints_num')),
  97. 'exppoints_desc' => input('post.exppoints_desc'),
  98. ];
  99. if (empty($data['member_name']) || intval($data['exppoints_type']) <= 0) {
  100. $this->error(lang('param_error'));
  101. }
  102. $member_name = $data['member_name'];
  103. $member_info = model('member')->getMemberInfo(array('member_name' => $member_name));
  104. if (!is_array($member_info) || count($member_info) <= 0) {
  105. $this->error(lang('admin_exppoints_userrecord_error'));
  106. }
  107. if ($data['exppoints_type'] == 2 && $data['exppoints_num'] > $member_info['member_exppoints']) {
  108. $this->error(lang('admin_exppoints_short_error') . $member_info['member_exppoints']);
  109. }
  110. //积分数据记录
  111. $insert_arr['explog_memberid'] = $member_info['member_id'];
  112. $insert_arr['explog_membername'] = $member_info['member_name'];
  113. if ($data['exppoints_type'] == 2) {
  114. $insert_arr['explog_points'] = -$data['exppoints_num'];
  115. } else {
  116. $insert_arr['explog_points'] = $data['exppoints_num'];
  117. }
  118. $insert_arr['explog_desc'] = $data['exppoints_desc'];
  119. $result = model('exppoints')->saveExppointslog('system', $insert_arr);
  120. if ($result) {
  121. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  122. } else {
  123. $this->error(lang('error'), 'Exppoints/index');
  124. }
  125. }
  126. }
  127. public function checkmember()
  128. {
  129. $member_name = trim(input('param.member_name'));
  130. if (!$member_name) {
  131. exit(json_encode(array('member_id' => 0)));
  132. }
  133. $obj_member = model('member');
  134. $member_info = $obj_member->getMemberInfo(array('member_name' => $member_name));
  135. if (is_array($member_info) && count($member_info) > 0) {
  136. echo json_encode(array('member_id' => $member_info['member_id'], 'member_name' => $member_info['member_name'], 'member_exppoints' => $member_info['member_exppoints']));
  137. } else {
  138. exit(json_encode(array('member_id' => 0)));
  139. die;
  140. }
  141. }
  142. /**
  143. * 经验值日志列表导出
  144. */
  145. public function export_step1()
  146. {
  147. $where = array();
  148. $search_mname = trim(input('param.mname'));
  149. $where[] = array('explog_membername', 'like', "%{$search_mname}%");
  150. if (input('param.stage')) {
  151. $where[] = array('explog_stage', '=', trim(input('param.stage')));
  152. }
  153. $stime = input('param.stime') ? strtotime(input('param.stime')) : 0;
  154. $etime = input('param.etime') ? strtotime(input('param.etime')) : 0;
  155. if ($stime > 0 && $etime > 0) {
  156. $where[] = array('explog_addtime', 'between', array($stime, $etime));
  157. } elseif ($stime > 0) {
  158. $where[] = array('explog_addtime', '>=', $stime);
  159. } elseif ($etime > 0) {
  160. $where[] = array('explog_addtime', '<=', $etime);
  161. }
  162. $search_desc = trim(input('param.description'));
  163. $where[] = array('explog_desc', 'like', "%$search_desc%");
  164. //查询经验值日志列表
  165. $exppoints_model = model('exppoints');
  166. $list_log = $exppoints_model->getExppointslogList($where, '*', self::EXPORT_SIZE, 'explog_id desc');
  167. if (!is_numeric(input('param.page'))) {
  168. $count = $exppoints_model->getExppointslogCount($where);
  169. $export_list = array();
  170. if ($count > self::EXPORT_SIZE) { //显示下载链接
  171. $page = ceil($count / self::EXPORT_SIZE);
  172. for ($i = 1; $i <= $page; $i++) {
  173. $limit1 = ($i - 1) * self::EXPORT_SIZE + 1;
  174. $limit2 = $i * self::EXPORT_SIZE > $count ? $count : $i * self::EXPORT_SIZE;
  175. $export_list[$i] = $limit1 . ' ~ ' . $limit2;
  176. }
  177. View::assign('export_list', $export_list);
  178. return View::fetch('/public/excel');
  179. } else { //如果数量小,直接下载
  180. $this->createExcel($list_log);
  181. }
  182. } else { //下载
  183. $this->createExcel($list_log);
  184. }
  185. }
  186. /**
  187. * 生成excel
  188. *
  189. * @param array $data
  190. */
  191. private function createExcel($data = array())
  192. {
  193. Lang::load(base_path() . 'admin/lang/' . config('lang.default_lang') . '/export.lang.php');
  194. $excel_obj = new \excel\Excel();
  195. $excel_data = array();
  196. //设置样式
  197. $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
  198. //header
  199. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('ds_member_name'));
  200. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('exp_value'));
  201. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('explog_addtime'));
  202. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('explog_stage'));
  203. $excel_data[0][] = array('styleid' => 's_title', 'data' => lang('explog_desc'));
  204. $stage_arr = model('exppoints')->getExppointsStage();
  205. foreach ((array)$data as $k => $v) {
  206. $tmp = array();
  207. $tmp[] = array('data' => $v['explog_membername']);
  208. $tmp[] = array('format' => 'Number', 'data' => ds_price_format($v['explog_points']));
  209. $tmp[] = array('data' => date('Y-m-d H:i:s', $v['explog_addtime']));
  210. $tmp[] = array('data' => $stage_arr[$v['explog_stage']]);
  211. $tmp[] = array('data' => $v['explog_desc']);
  212. $excel_data[] = $tmp;
  213. }
  214. $excel_data = $excel_obj->charset($excel_data, CHARSET);
  215. $excel_obj->addArray($excel_data);
  216. $excel_obj->addWorksheet($excel_obj->charset(lang('membergrade_exppoints_list'), CHARSET));
  217. $excel_obj->generateXML($excel_obj->charset(lang('membergrade_exppoints_list'), CHARSET) . input('param.page') . '-' . date('Y-m-d-H', TIMESTAMP));
  218. }
  219. /**
  220. * 获取卖家栏目列表,针对控制器下的栏目
  221. */
  222. protected function getAdminItemList()
  223. {
  224. $menu_array = array(
  225. array(
  226. 'name' => 'explog',
  227. 'text' => lang('ds_exppoints_manage'),
  228. 'url' => (string)url('Exppoints/index')
  229. ),
  230. array(
  231. 'name' => 'expset',
  232. 'text' => lang('ds_exppoints_setting'),
  233. 'url' => "javascript:dsLayerOpen('" . (string)url('Exppoints/expsetting') . "','" . lang('ds_exppoints_setting') . "')"
  234. ),
  235. array(
  236. 'name' => 'edit',
  237. 'text' => lang('ds_exppoints_edit'),
  238. 'url' => "javascript:dsLayerOpen('" . (string)url('Exppoints/edit') . "','" . lang('ds_exppoints_edit') . "')"
  239. ),
  240. );
  241. return $menu_array;
  242. }
  243. }