LoginbonusController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. /**
  3. * 登录奖励
  4. */
  5. namespace app\admin\controller;
  6. use cmf\controller\AdminBaseController;
  7. use think\facade\Db;
  8. class LoginbonusController extends AdminbaseController {
  9. function index(){
  10. $lists = Db::name("loginbonus")
  11. ->order("day asc")
  12. ->paginate(20);
  13. $page = $lists->render();
  14. $this->assign('lists', $lists);
  15. $this->assign("page", $page);
  16. return $this->fetch();
  17. }
  18. function del(){
  19. $id = $this->request->param('id', 0, 'intval');
  20. $rs = DB::name('loginbonus')->where("id={$id}")->delete();
  21. if(!$rs){
  22. $this->error("删除失败!");
  23. }
  24. $action="删除登录奖励:{$id}";
  25. setAdminLog($action);
  26. $this->resetcache();
  27. $this->success("删除成功!");
  28. }
  29. function add(){
  30. return $this->fetch();
  31. }
  32. function addPost(){
  33. if ($this->request->isPost()) {
  34. $data = $this->request->param();
  35. $data['addtime']=time();
  36. $id = DB::name('loginbonus')->insertGetId($data);
  37. if(!$id){
  38. $this->error("添加失败!");
  39. }
  40. $action="添加登录奖励:{$id}";
  41. setAdminLog($action);
  42. $this->resetcache();
  43. $this->success("添加成功!");
  44. }
  45. }
  46. function edit(){
  47. $id = $this->request->param('id', 0, 'intval');
  48. $data=Db::name('loginbonus')
  49. ->where("id={$id}")
  50. ->find();
  51. if(!$data){
  52. $this->error("信息错误");
  53. }
  54. $this->assign('data', $data);
  55. return $this->fetch();
  56. }
  57. function editPost(){
  58. if ($this->request->isPost()) {
  59. $data = $this->request->param();
  60. $data['uptime']=time();
  61. $rs = DB::name('loginbonus')->update($data);
  62. if($rs===false){
  63. $this->error("修改失败!");
  64. }
  65. $action="编辑登录奖励:{$data['id']}";
  66. setAdminLog($action);
  67. $this->resetcache();
  68. $this->success("修改成功!");
  69. }
  70. }
  71. function resetcache(){
  72. $key='loginbonus';
  73. $list=DB::name('loginbonus')
  74. ->field("day,coin")
  75. ->order('day asc')
  76. ->select();
  77. if($list){
  78. setcaches($key,$list);
  79. }else{
  80. delcache($key);
  81. }
  82. return 1;
  83. }
  84. function index2(){
  85. $data = $this->request->param();
  86. $map[]=['type','=','income'];
  87. $map[]=['action','=','signin_reward'];
  88. $uid=isset($data['uid']) ? $data['uid']: '';
  89. if($uid!=''){
  90. $map[]=['uid','=',$uid];
  91. }
  92. $lists = Db::name("user_coinrecord")
  93. ->where($map)
  94. ->order("id desc")
  95. ->paginate(20);
  96. $lists->each(function($v,$k){
  97. $v['userinfo']=getUserInfo($v['uid']);
  98. $name='第'.$v['giftid'].'天';
  99. $v['name']=$name;
  100. return $v;
  101. });
  102. $lists->appends($data);
  103. $page = $lists->render();
  104. $this->assign('lists', $lists);
  105. $this->assign("page", $page);
  106. return $this->fetch();
  107. }
  108. }