No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Level.php 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\admin\controller;
  14. use think\Page;
  15. use think\Db;
  16. use think\Config;
  17. class Level extends Base {
  18. /**
  19. * 构造方法
  20. */
  21. public function __construct(){
  22. parent::__construct();
  23. /*会员中心数据表*/
  24. $this->users_db = Db::name('users'); // 会员信息表
  25. $this->users_money_db = Db::name('users_money'); // 会员充值表
  26. $this->users_type_manage_db = Db::name('users_type_manage'); // 会员等级表
  27. /*结束*/
  28. // 是否开启支付功能设置
  29. $UsersConfigData = getUsersConfigData('all');
  30. $this->assign('userConfig',$UsersConfigData);
  31. // 模型是否开启
  32. $channeltype_row = \think\Cache::get('extra_global_channeltype');
  33. $this->assign('channeltype_row',$channeltype_row);
  34. }
  35. /**
  36. * 列表
  37. */
  38. public function index()
  39. {
  40. // 会员级别
  41. $list = model('UsersLevel')->getList('*', ['is_system'=>0]);
  42. $this->assign('list',$list);
  43. // 会员升级期限
  44. $member_limit_arr = Config::get('global.admin_member_limit_arr');
  45. $this->assign('member_limit_arr',$member_limit_arr);
  46. // 会员升级产品分类
  47. $users_type = $this->users_type_manage_db->order('sort_order asc, type_id asc')->select();
  48. $this->assign('users_type',$users_type);
  49. return $this->fetch();
  50. }
  51. /**
  52. * 会员升级业务列表
  53. */
  54. public function upgrade_index()
  55. {
  56. // 查询条件
  57. $where = [
  58. 'a.cause_type' => 0,
  59. 'a.status' => ['IN', [2, 3]],
  60. 'a.lang' => $this->admin_lang,
  61. ];
  62. // 订单号或会员名查询
  63. $keywords = input('keywords/s');
  64. if (!empty($keywords)) $where['a.order_number|b.username'] = array('LIKE', "%{$keywords}%");
  65. // 支付方式查询
  66. $pay_method = input('pay_method/s');
  67. if (!empty($pay_method)) $where['a.pay_method'] = $pay_method;
  68. // 会员级别查询
  69. $level_id = input('level_id/d');
  70. if (!empty($level_id)) $where['a.level_id'] = $level_id;
  71. // 时间检索条件
  72. $begin = strtotime(input('param.add_time_begin/s'));
  73. $end = input('param.add_time_end/s');
  74. !empty($end) && $end .= ' 23:59:59';
  75. $end = strtotime($end);
  76. // 时间检索
  77. if ($begin > 0 && $end > 0) {
  78. $where['a.add_time'] = array('between', "$begin, $end");
  79. } else if ($begin > 0) {
  80. $where['a.add_time'] = array('egt', $begin);
  81. } else if ($end > 0) {
  82. $where['a.add_time'] = array('elt', $end);
  83. }
  84. // 分页查询
  85. $count = $this->users_money_db->alias('a')->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')->where($where)->count();
  86. $Page = new Page($count, config('paginate.list_rows'));
  87. // 数据查询
  88. $list = $this->users_money_db->field('a.*, b.head_pic, b.username, b.nickname')
  89. ->alias('a')
  90. ->join('__USERS__ b', 'a.users_id = b.users_id', 'LEFT')
  91. ->where($where)
  92. ->order('a.moneyid desc')
  93. ->limit($Page->firstRow.','.$Page->listRows)
  94. ->select();
  95. foreach ($list as $key => $value) {
  96. $value['username'] = !empty($value['nickname']) ? $value['nickname'] : $value['username'];
  97. // 反序列化参数
  98. $value['cause'] = unserialize($value['cause']);
  99. $value['head_pic'] = get_head_pic($value['head_pic']);
  100. $list[$key] = $value;
  101. }
  102. $show = $Page->show();
  103. $this->assign('page', $show);
  104. $this->assign('list', $list);
  105. $this->assign('pager', $Page);
  106. // 会员等级列表
  107. $usersLevel = model('UsersLevel')->getList('level_id, level_name', [], 'level_id');
  108. $this->assign('usersLevel', $usersLevel);
  109. // 支付状态
  110. $pay_status_arr = config('global.pay_status_arr');
  111. $this->assign('pay_status_arr', $pay_status_arr);
  112. // 是否开启文章付费
  113. $channelRow = Db::name('channeltype')->where('nid', 'in',['article','download'])->getAllWithIndex('nid');
  114. foreach ($channelRow as &$val){
  115. if (!empty($val['data'])) $val['data'] = json_decode($val['data'], true);
  116. }
  117. $this->assign('channelRow', $channelRow);
  118. return $this->fetch();
  119. }
  120. /**
  121. * 删除会员升级
  122. */
  123. public function upgrade_del()
  124. {
  125. if (IS_POST) {
  126. $id_arr = input('del_id/a');
  127. $id_arr = eyIntval($id_arr);
  128. if(!empty($id_arr)){
  129. $result = Db::name('users_money')->field('order_number')
  130. ->where([
  131. 'moneyid' => ['IN', $id_arr],
  132. 'cause_type' => 0,
  133. 'lang' => $this->admin_lang,
  134. ])->select();
  135. $order_number_list = get_arr_column($result, 'order_number');
  136. $r = Db::name('users_money')->where([
  137. 'moneyid' => ['IN', $id_arr],
  138. 'cause_type' => 0,
  139. 'lang' => $this->admin_lang,
  140. ])
  141. ->cache(true, null, "users_money")
  142. ->delete();
  143. if($r !== false){
  144. adminLog('删除会员升级记录:'.implode(',', $order_number_list));
  145. $this->success('删除成功');
  146. }
  147. }
  148. $this->error('删除失败');
  149. }
  150. $this->error('非法访问');
  151. }
  152. // 删除
  153. public function level_type_del()
  154. {
  155. $type_id = input('type_id/d');
  156. if (IS_AJAX_POST && !empty($type_id)) {
  157. $where = [
  158. 'type_id' => $type_id,
  159. 'lang' => $this->admin_lang,
  160. ];
  161. $type_name_list = $this->users_type_manage_db->where($where)->getField('type_name');
  162. // 删除会员升级级别
  163. $return = $this->users_type_manage_db->where($where)->delete();
  164. if ($return) {
  165. adminLog('删除会员升级级别:'.$type_name_list);
  166. $this->success('删除成功');
  167. }else{
  168. $this->error('删除失败');
  169. }
  170. }
  171. $this->error('参数有误');
  172. }
  173. // 新增/修改
  174. public function add_level_data()
  175. {
  176. if (IS_POST) {
  177. $post = input('post.');
  178. // 处理新增数据
  179. $AddLevelData = [];
  180. foreach ($post['type_name'] as $key => $value) {
  181. $type_id = $post['type_id'][$key];
  182. $type_name = trim($value);
  183. $level_id = $post['level_id'][$key];
  184. $price = $post['price'][$key];
  185. $limit_id = $post['limit_id'][$key];
  186. $sort_order = $post['sort_order'][$key];
  187. if (empty($type_name)) $this->error('产品名称不可为空');
  188. if (empty($level_id)) $this->error('会员级别不可为空');
  189. if (empty($price)) $this->error('产品价格不可为空');
  190. if (empty($limit_id)) $this->error('会员期限不可为空');
  191. $AddLevelData[] = [
  192. 'type_id' => $type_id,
  193. 'type_name' => $type_name,
  194. 'level_id' => $level_id,
  195. 'price' => $price,
  196. 'limit_id' => $limit_id,
  197. 'sort_order' => $sort_order,
  198. 'update_time' => getTime(),
  199. ];
  200. if (empty($type_id)) {
  201. $AddLevelData[$key]['lang'] = $this->admin_lang;
  202. $AddLevelData[$key]['add_time'] = getTime();
  203. unset($AddLevelData[$key]['type_id']);
  204. }
  205. }
  206. if (!empty($AddLevelData)) {
  207. $ReturnId = model('UsersTypeManage')->saveAll($AddLevelData);
  208. }
  209. // 返回
  210. if (!empty($ReturnId)) {
  211. $this->success('保存成功');
  212. }else{
  213. $this->error('保存失败');
  214. }
  215. }
  216. }
  217. }