Exppoints.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 经验值管理 控制器
  15. */
  16. class Exppoints extends AdminControl
  17. {
  18. const EXPORT_SIZE = 5000;
  19. public function initialize()
  20. {
  21. parent::initialize();
  22. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/membergrade.lang.php');
  23. }
  24. /**
  25. * 设置经验值获取规则
  26. */
  27. public function expsetting() {
  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. $where = array();
  54. $search_mname = trim(input('param.mname'));
  55. if(!empty($search_mname)){
  56. $where[]=array('explog_membername','like',"%{$search_mname}%");
  57. }
  58. if (input('param.stage')){
  59. $where[]=array('explog_stage','=',trim(input('param.stage')));
  60. }
  61. $stime = input('param.stime')?strtotime(input('param.stime')):0;
  62. $etime = input('param.etime')?strtotime(input('param.etime')):0;
  63. if ($stime > 0){
  64. $where[]=array('explog_addtime','>=',$stime);
  65. }
  66. if ($etime > 0){
  67. $etime=$etime+86399;
  68. $where[]=array('explog_addtime','<=',$etime);
  69. }
  70. $search_desc = trim(input('param.description'));
  71. if(!empty($search_desc)){
  72. $where[]=array('explog_desc','like',"%".$search_desc."%");
  73. }
  74. //查询经验值日志列表
  75. $exppoints_model = model('exppoints');
  76. $list_log = $exppoints_model->getExppointslogList($where, '*', 20, 'explog_id desc');
  77. //信息输出
  78. View::assign('stage_arr',$exppoints_model->getExppointsStage());
  79. View::assign('show_page',$exppoints_model->page_info->render());
  80. View::assign('list_log',$list_log);
  81. $this->setAdminCurItem('explog');
  82. return View::fetch();
  83. }
  84. /**
  85. * 经验值调整
  86. */
  87. public function edit()
  88. {
  89. if (!request()->isPost()) {
  90. return View::fetch();
  91. } else {
  92. $data = [
  93. 'member_name' => input('post.member_name'),
  94. 'exppoints_type' => input('post.exppoints_type'),
  95. 'exppoints_num' => intval(input('post.exppoints_num')),
  96. 'exppoints_desc' => input('post.exppoints_desc'),
  97. ];
  98. if(empty($data['member_name']) || intval($data['exppoints_type'])<=0){
  99. $this->error(lang('param_error'));
  100. }
  101. $member_name = $data['member_name'];
  102. $member_info = model('member')->getMemberInfo(array('member_name' => $member_name));
  103. if (!is_array($member_info) || count($member_info) <= 0) {
  104. $this->error(lang('admin_exppoints_userrecord_error'));
  105. }
  106. if ($data['exppoints_type'] == 2 && $data['exppoints_num'] > $member_info['member_exppoints']) {
  107. $this->error(lang('admin_exppoints_short_error') . $member_info['member_exppoints']);
  108. }
  109. //积分数据记录
  110. $insert_arr['explog_memberid'] = $member_info['member_id'];
  111. $insert_arr['explog_membername'] = $member_info['member_name'];
  112. if ($data['exppoints_type'] == 2) {
  113. $insert_arr['explog_points'] = -$data['exppoints_num'];
  114. } else {
  115. $insert_arr['explog_points'] = $data['exppoints_num'];
  116. }
  117. $insert_arr['explog_desc'] = $data['exppoints_desc'];
  118. $result = model('exppoints')->saveExppointslog('system', $insert_arr);
  119. if ($result) {
  120. dsLayerOpenSuccess(lang('ds_common_op_succ'));
  121. } else {
  122. $this->error(lang('error'), 'Exppoints/index');
  123. }
  124. }
  125. }
  126. public function checkmember() {
  127. $member_name = trim(input('param.member_name'));
  128. if (!$member_name) {
  129. exit(json_encode(array('member_id' => 0)));
  130. }
  131. $obj_member = model('member');
  132. $member_info = $obj_member->getMemberInfo(array('member_name' => $member_name));
  133. if (is_array($member_info) && count($member_info) > 0) {
  134. echo json_encode(array('member_id' => $member_info['member_id'], 'member_name' => $member_info['member_name'], 'member_exppoints' => $member_info['member_exppoints']));
  135. } else {
  136. exit(json_encode(array('member_id' => 0)));
  137. die;
  138. }
  139. }
  140. /**
  141. * 经验值日志列表导出
  142. */
  143. public function export_step1(){
  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. Lang::load(base_path() .'admin/lang/'.config('lang.default_lang').'/export.lang.php');
  190. $excel_obj = new \excel\Excel();
  191. $excel_data = array();
  192. //设置样式
  193. $excel_obj->setStyle(array('id'=>'s_title','Font'=>array('FontName'=>'宋体','Size'=>'12','Bold'=>'1')));
  194. //header
  195. $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('ds_member_name'));
  196. $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('exp_value'));
  197. $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('explog_addtime'));
  198. $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('explog_stage'));
  199. $excel_data[0][] = array('styleid'=>'s_title','data'=>lang('explog_desc'));
  200. $stage_arr = model('exppoints')->getExppointsStage();
  201. foreach ((array)$data as $k=>$v){
  202. $tmp = array();
  203. $tmp[] = array('data'=>$v['explog_membername']);
  204. $tmp[] = array('format'=>'Number','data'=>ds_price_format($v['explog_points']));
  205. $tmp[] = array('data'=>date('Y-m-d H:i:s',$v['explog_addtime']));
  206. $tmp[] = array('data'=>$stage_arr[$v['explog_stage']]);
  207. $tmp[] = array('data'=>$v['explog_desc']);
  208. $excel_data[] = $tmp;
  209. }
  210. $excel_data = $excel_obj->charset($excel_data,CHARSET);
  211. $excel_obj->addArray($excel_data);
  212. $excel_obj->addWorksheet($excel_obj->charset(lang('membergrade_exppoints_list'),CHARSET));
  213. $excel_obj->generateXML($excel_obj->charset(lang('membergrade_exppoints_list'),CHARSET).input('param.page').'-'.date('Y-m-d-H',TIMESTAMP));
  214. }
  215. /**
  216. * 获取卖家栏目列表,针对控制器下的栏目
  217. */
  218. protected function getAdminItemList() {
  219. $menu_array = array(
  220. array(
  221. 'name' => 'explog',
  222. 'text' => lang('ds_exppoints_manage'),
  223. 'url' => (string)url('Exppoints/index')
  224. ),
  225. array(
  226. 'name' => 'expset',
  227. 'text' => lang('ds_exppoints_setting'),
  228. 'url' => "javascript:dsLayerOpen('".(string)url('Exppoints/expsetting')."','".lang('ds_exppoints_setting')."')"
  229. ),
  230. array(
  231. 'name' => 'edit',
  232. 'text' => lang('ds_exppoints_edit'),
  233. 'url' => "javascript:dsLayerOpen('".(string)url('Exppoints/edit')."','".lang('ds_exppoints_edit')."')"
  234. ),
  235. );
  236. return $menu_array;
  237. }
  238. }