Rose.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\cmgadm\controller\user;
  3. use app\common\controller\Backend;
  4. /**
  5. *
  6. *
  7. * @icon fa fa-circle-o
  8. */
  9. class Rose extends Backend
  10. {
  11. /**
  12. * Rose模型对象
  13. * @var \app\cmgadm\model\Rose
  14. */
  15. protected $model = null;
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->model = new \app\cmgadm\model\Rose;
  20. }
  21. /**
  22. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  23. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  24. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  25. */
  26. /**
  27. * 查看
  28. */
  29. public function index()
  30. {
  31. //当前是否为关联查询
  32. $this->relationSearch = false;
  33. //设置过滤方法
  34. $this->request->filter(['strip_tags']);
  35. if ($this->request->isAjax())
  36. {
  37. //如果发送的来源是Selectpage,则转发到Selectpage
  38. if ($this->request->request('keyField'))
  39. {
  40. return $this->selectpage();
  41. }
  42. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  43. $total = $this->model
  44. ->where($where)
  45. ->order($sort, $order)
  46. ->count();
  47. $list = $this->model
  48. ->where($where)
  49. ->order($sort, $order)
  50. ->limit($offset, $limit)
  51. ->select();
  52. foreach ($list as &$row) {
  53. //$row->visible(['id','userid','mobile','level','pid','pic','status','ctime']);
  54. $row['userid']=get_user_data($row['userid'],'username');
  55. $row['pid']=get_user_data($row['pid'],'username');
  56. }
  57. $list = collection($list)->toArray();
  58. $result = array("total" => $total, "rows" => $list);
  59. return json($result);
  60. }
  61. return $this->view->fetch();
  62. }
  63. function view()
  64. {
  65. $ids = input('ids');
  66. $status=input('status');
  67. $info=$this->model->where(['id'=>$ids,'status'=>1])->find();
  68. if(!$info)
  69. {
  70. $this->error("信息不存在,或已审核");
  71. }else{
  72. if($status == 1) {#审核
  73. db()->startTrans();
  74. $res1=db('user')->where(['id'=>$info['userid']])->update(['rose'=>$info['level']+1]);
  75. $res2=db('rose')->where(['id'=>$ids])->update(['status'=>2]);
  76. if($res1 && $res2)
  77. {
  78. $pinfo=db('user_parent')->where(['userid'=>$info['userid']])->find();
  79. $pids=db('user_parent')->where(['id'=>['in',$pinfo['pids']],'system'=>0])->column('userid');
  80. db('user')->where(['id'=>['in',$pids],'rose'=>$info['level']+1])->update(['isup'=>1]);
  81. db()->commit();
  82. $this->success('审核完成');
  83. }else{
  84. db()->rollback();
  85. $this->error('审核失败');
  86. }
  87. }else{
  88. $res1=$this->model->where('id',$ids)->update(['status'=>-1]);
  89. if($res1)
  90. {
  91. $this->success('审核完成');
  92. }else{
  93. $this->error('审核失败');
  94. }
  95. }
  96. }
  97. }
  98. }