Exppoints.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. * DSMall多用户商城
  8. * ============================================================================
  9. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  10. * 网站地址: http://www.csdeshang.com
  11. * ----------------------------------------------------------------------------
  12. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  13. * 不允许对程序代码以任何形式任何目的的再发布。
  14. * ============================================================================
  15. * 经验值管理 控制器
  16. */
  17. class Exppoints extends AdminControl
  18. {
  19. const EXPORT_SIZE = 5000;
  20. public function initialize()
  21. {
  22. parent::initialize();
  23. Lang::load(base_path() . 'admin/lang/'.config('lang.default_lang').'/membergrade.lang.php');
  24. }
  25. /**
  26. * 设置经验值获取规则
  27. */
  28. public function expsetting() {
  29. $config_model = model('config');
  30. if (request()->isPost()) {
  31. $exp_arr = array();
  32. $exp_arr['exp_login'] = intval(input('post.exp_login'));
  33. $exp_arr['exp_comments'] = intval(input('post.exp_comments'));
  34. $exp_arr['exp_orderrate'] = intval(input('post.exp_orderrate'));
  35. $exp_arr['exp_ordermax'] = intval(input('post.exp_ordermax'));
  36. $result = $config_model->editConfig(array('exppoints_rule' => serialize($exp_arr)));
  37. if ($result === true) {
  38. $this->log(lang('ds_edit') . lang('ds_exppoints_manage') . lang('ds_exppoints_setting'), 1);
  39. dsLayerOpenSuccess(lang('ds_common_save_succ'));
  40. } else {
  41. $this->error(lang('ds_common_save_fail'));
  42. }
  43. } else {
  44. $list_setting = $config_model->getOneConfigByCode('exppoints_rule');
  45. $list_setting = unserialize($list_setting['value']);
  46. View::assign('list_setting', $list_setting);
  47. return View::fetch();
  48. }
  49. }
  50. /**
  51. * 经验值日志列表
  52. */
  53. public function index(){
  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. $member_name = trim(input('param.member_name'));
  129. if (!$member_name) {
  130. exit(json_encode(array('member_id' => 0)));
  131. }
  132. $obj_member = model('member');
  133. $member_info = $obj_member->getMemberInfo(array('member_name' => $member_name));
  134. if (is_array($member_info) && count($member_info) > 0) {
  135. echo json_encode(array('member_id' => $member_info['member_id'], 'member_name' => $member_info['member_name'], 'member_exppoints' => $member_info['member_exppoints']));
  136. } else {
  137. exit(json_encode(array('member_id' => 0)));
  138. die;
  139. }
  140. }
  141. /**
  142. * 经验值日志列表导出
  143. */
  144. public function export_step1(){
  145. $where = array();
  146. $search_mname = trim(input('param.mname'));
  147. $where[]=array('explog_membername','like',"%{$search_mname}%");
  148. if (input('param.stage')){
  149. $where[]=array('explog_stage','=',trim(input('param.stage')));
  150. }
  151. $stime = input('param.stime')?strtotime(input('param.stime')):0;
  152. $etime = input('param.etime')?strtotime(input('param.etime')):0;
  153. if ($stime > 0 && $etime>0){
  154. $where[]=array('explog_addtime','between',array($stime,$etime));
  155. }elseif ($stime > 0){
  156. $where[]=array('explog_addtime','>=',$stime);
  157. }elseif ($etime > 0){
  158. $where[]=array('explog_addtime','<=',$etime);
  159. }
  160. $search_desc = trim(input('param.description'));
  161. $where[]=array('explog_desc','like',"%$search_desc%");
  162. //查询经验值日志列表
  163. $exppoints_model = model('exppoints');
  164. $list_log = $exppoints_model->getExppointslogList($where, '*', self::EXPORT_SIZE, 'explog_id desc');
  165. if (!is_numeric(input('param.page'))){
  166. $count = $exppoints_model->getExppointslogCount($where);
  167. $export_list = array();
  168. if ($count > self::EXPORT_SIZE ){ //显示下载链接
  169. $page = ceil($count/self::EXPORT_SIZE);
  170. for ($i=1;$i<=$page;$i++){
  171. $limit1 = ($i-1)*self::EXPORT_SIZE + 1;
  172. $limit2 = $i*self::EXPORT_SIZE > $count ? $count : $i*self::EXPORT_SIZE;
  173. $export_list[$i] = $limit1.' ~ '.$limit2 ;
  174. }
  175. View::assign('export_list',$export_list);
  176. return View::fetch('/public/excel');
  177. }else{ //如果数量小,直接下载
  178. $this->createExcel($list_log);
  179. }
  180. }else{ //下载
  181. $this->createExcel($list_log);
  182. }
  183. }
  184. /**
  185. * 生成excel
  186. *
  187. * @param array $data
  188. */
  189. private function createExcel($data = array()){
  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. $menu_array = array(
  221. array(
  222. 'name' => 'explog',
  223. 'text' => lang('ds_exppoints_manage'),
  224. 'url' => (string)url('Exppoints/index')
  225. ),
  226. array(
  227. 'name' => 'expset',
  228. 'text' => lang('ds_exppoints_setting'),
  229. 'url' => "javascript:dsLayerOpen('".(string)url('Exppoints/expsetting')."','".lang('ds_exppoints_setting')."')"
  230. ),
  231. array(
  232. 'name' => 'edit',
  233. 'text' => lang('ds_exppoints_edit'),
  234. 'url' => "javascript:dsLayerOpen('".(string)url('Exppoints/edit')."','".lang('ds_exppoints_edit')."')"
  235. ),
  236. );
  237. return $menu_array;
  238. }
  239. }