Invcode.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\admin\controller\csminvite;
  3. use addons\csminvite\library\CsmBackend;
  4. use fast\Random;
  5. /**
  6. * 邀请码邀请函
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Invcode extends CsmBackend
  11. {
  12. /**
  13. * Invcode模型对象
  14. * @var \app\admin\model\csminvite\Invcode
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\csminvite\Invcode;
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. }
  23. /**
  24. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  25. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  26. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  27. */
  28. /**
  29. * 查看
  30. */
  31. public function index()
  32. {
  33. //如果没有开启邀请码登录,则提示
  34. $config = get_addon_config("csminvite");
  35. $this->view->assign("isspportinvcode", $config['isspportinvcode']);
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags']);
  38. if ($this->request->isAjax()) {
  39. //如果发送的来源是Selectpage,则转发到Selectpage
  40. if ($this->request->request('keyField')) {
  41. return $this->selectpage();
  42. }
  43. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  44. $total = $this->model
  45. ->where($where)
  46. ->order($sort, $order)
  47. ->count();
  48. $list = $this->model
  49. ->where($where)
  50. ->order($sort, $order)
  51. ->limit($offset, $limit)
  52. ->select();
  53. $list = collection($list)->toArray();
  54. $result = array("total" => $total, "rows" => $list);
  55. return json($result);
  56. }
  57. return $this->view->fetch();
  58. }
  59. public function addinvcode($ids){
  60. $row = $this->model->where("id","=",$ids)->find();
  61. if(!$row){
  62. return;
  63. }
  64. if ($this->request->isPost()) {
  65. $params = $this->request->post("row/a");
  66. $addnum = $params["addnum"];
  67. $dao = new \app\admin\model\csminvite\Invcodeuser();
  68. $iparam = [
  69. "csminvite_invcode_id"=>$ids,
  70. "codestatus"=>"unused",
  71. "generatetime"=>time(),
  72. "status"=>"normal",
  73. "createtime"=>time()
  74. ];
  75. for($i=0;$i<$addnum;$i++){
  76. $iparam["invkey"] =$row->id.Random::alpha(3).Random::alnum(4);
  77. $dao->create($iparam);
  78. }
  79. $this->success("验证码生成成功,一共生成".$addnum."个");
  80. }
  81. $this->view->assign("row", $row);
  82. return $this->view->fetch();
  83. }
  84. }