Record.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace app\admin\controller\invite;
  3. use app\common\controller\Backend;
  4. use think\Controller;
  5. use think\Request;
  6. use fast\Random;
  7. /**
  8. * #邀请记录管理
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Record extends Backend
  13. {
  14. /**
  15. * InviteRecord模型对象
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = model('InviteRecord');
  22. $this->view->assign("payTypeList", $this->model->getPayTypeList());
  23. $this->view->assign("statusList", $this->model->getStatusList());
  24. }
  25. /**
  26. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个方法
  27. * 因此在当前控制器中可不用编写增删改查的代码,如果需要自己控制这部分逻辑
  28. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  29. */
  30. /**
  31. * 查看
  32. */
  33. public function index()
  34. {
  35. //设置过滤方法
  36. $this->request->filter(['strip_tags']);
  37. if ($this->request->isAjax())
  38. {
  39. //如果发送的来源是Selectpage,则转发到Selectpage
  40. if ($this->request->request('pkey_name'))
  41. {
  42. return $this->selectpage();
  43. }
  44. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  45. $total = $this->model->alias('r')
  46. ->join('admin_extend e','e.admin_id=r.invite_id and e.create_by='.$this->auth->id)
  47. ->where($where)
  48. ->count();
  49. $list = $this->model->alias('r')
  50. ->join('admin a','r.invite_id = a.id')
  51. ->join('admin_extend e','e.admin_id=r.invite_id and e.create_by='.$this->auth->id)
  52. ->field('r.*,a.nickname as anickname')
  53. ->where($where)
  54. ->order('r.status asc,r.id desc')
  55. ->limit($offset, $limit)
  56. ->select();
  57. $result = array("total" => $total, "rows" => $list);
  58. return json($result);
  59. }
  60. return $this->view->fetch();
  61. }
  62. /**
  63. * 编辑
  64. */
  65. public function edit($ids = NULL)
  66. {
  67. $row = $this->model->get($ids);
  68. $this->assign('id',$ids);
  69. $extend = model('admin_extend')->where('admin_id',$this->auth->id)->find();
  70. $this->assign('extend',$extend);
  71. if (!$row)
  72. $this->error(__('No Results were found'));
  73. $adminIds = $this->getDataLimitAdminIds();
  74. if (is_array($adminIds))
  75. {
  76. if (!in_array($row[$this->dataLimitField], $adminIds))
  77. {
  78. $this->error(__('You have no permission'));
  79. }
  80. }
  81. if ($this->request->isPost())
  82. {
  83. $params = $this->request->post("row/a");
  84. $extends = $this->request->post("extend/a");
  85. $id = $this->request->post("activity_id");
  86. if ($params)
  87. {
  88. try
  89. {
  90. $this->model=model('admin');
  91. $params['salt'] = Random::alnum();
  92. $params['password'] = md5(md5($params['password']) . $params['salt']);
  93. $params['avatar'] = asset('/img/avatar.png'); //设置新管理员默认头像。
  94. $result = $this->model->validate('Admin.add')->insertGetId($params);
  95. if ($result)
  96. {
  97. $dataset = [];
  98. $dataset[] = ['uid' => $result, 'group_id' => 4];
  99. model('AuthGroupAccess')->saveAll($dataset); //分组表
  100. model('invite_record')->update(['admin_id'=>$result,'status'=>'1'],['id'=>$id]);
  101. $extends['create_by'] = $this->auth->id;
  102. $extends['admin_id'] = $result;
  103. $extends['createtime'] = time();
  104. $extends['updatetime'] = time();
  105. if($extends['pay_method'] == 1){
  106. $extends['pay_method'] = 3;
  107. }elseif($extends['pay_method'] == 2){
  108. $extends['pay_method'] = 4;
  109. }else{
  110. $extends['pay_method'] = 2;
  111. }
  112. model('admin_extend')->insert($extends);
  113. $this->success();
  114. }
  115. else
  116. {
  117. $this->error($row->getError());
  118. }
  119. }
  120. catch (\think\exception\PDOException $e)
  121. {
  122. $this->error($e->getMessage());
  123. }
  124. }
  125. $this->error(__('Parameter %s can not be empty', ''));
  126. }
  127. $this->view->assign("row", $row);
  128. return $this->view->fetch();
  129. }
  130. }