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