Trainactive.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 培训活动
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Trainactive extends Backend
  11. {
  12. /**
  13. * Trainactive模型对象
  14. * @var \app\admin\model\Trainactive
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Trainactive;
  21. $this->view->assign("statusList", $this->model->getStatusList());
  22. $this->view->assign("userauthStatusList", $this->model->getUserauthStatusList());
  23. }
  24. /**
  25. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  26. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  27. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  28. */
  29. /**
  30. * 查看
  31. */
  32. public function index()
  33. {
  34. //当前是否为关联查询
  35. $this->relationSearch = true;
  36. //设置过滤方法
  37. $this->request->filter(['strip_tags', 'trim']);
  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. $list = $this->model
  45. ->with(['cate','level','type'])
  46. ->where($where)
  47. ->order($sort, $order)
  48. ->paginate($limit);
  49. foreach ($list as $row) {
  50. $row->getRelation('cate')->visible(['name']);
  51. $row->getRelation('level')->visible(['name']);
  52. $row->getRelation('type')->visible(['name']);
  53. }
  54. $result = array("total" => $list->total(), "rows" => $list->items());
  55. return json($result);
  56. }
  57. return $this->view->fetch();
  58. }
  59. /**
  60. * 二维码
  61. */
  62. public function qrcode(){
  63. $id = input('id');
  64. $info = Db::name('train_active')->where('id',$id)->find();
  65. //二维码
  66. $sign_data = [
  67. 'type' => 'sign',
  68. 'name' => $info['name'],
  69. 'id' => $info['id'],
  70. ];
  71. $pingjia_data = [
  72. 'type' => 'pingjia',
  73. 'name' => $info['name'],
  74. 'id' => $info['id'],
  75. ];
  76. $info['sign_qrcode'] = $this->introimage(json_encode($sign_data));
  77. $info['pingjia_qrcode'] = $this->introimage(json_encode($pingjia_data));
  78. $this->assign('row',$info);
  79. return $this->view->fetch();
  80. }
  81. //生成邀请码二维码图片
  82. private function introimage($data) {
  83. $params['text'] = $data;
  84. $qrcode_service = \addons\qrcode\library\Service::qrcode($params);
  85. $qrcodePath = ROOT_PATH . 'public/uploads/trainqrcode/'.date('Ymd');
  86. if (!is_dir($qrcodePath)) {
  87. @mkdir($qrcodePath);
  88. }
  89. $filename = md5($data) . '.png';
  90. if (is_really_writable($qrcodePath)) {
  91. $filePath = $qrcodePath .'/'. $filename;
  92. $qrcode_service->writeFile($filePath);
  93. }
  94. return request()->domain().'/uploads/trainqrcode/'.date('Ymd') .'/'. $filename;
  95. }
  96. }