ActivityQrcode.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace app\operate\controller;
  3. use app\common\model\User;
  4. use library\Controller;
  5. use think\Db;
  6. /**
  7. * 活动推荐码
  8. * Class ActivityQrcode
  9. * @package app\operate\controller
  10. */
  11. class ActivityQrcode extends Controller
  12. {
  13. protected $table = 'ActivityQrcode';
  14. /**
  15. * 列表
  16. * @auth true
  17. * @menu true
  18. * @throws \think\Exception
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. * @throws \think\exception\DbException
  22. * @throws \think\exception\PDOException
  23. */
  24. public function index()
  25. {
  26. $this->title = '列表';
  27. $where = [];
  28. $act_id = input('act_id');
  29. $where[] = ['f.is_deleted','=',0];
  30. $where[] = ['f.act_id','=',$act_id];
  31. if($title = input('phone')) $where[] = ['f.phone','like','%'.$title.'%'];
  32. $query = $this->_query($this->table)->alias('f')
  33. ->field('f.*,t.title act_title')
  34. ->leftJoin('activity t','t.id=f.act_id')
  35. ->where($where)
  36. ->order('f.id asc')->page();
  37. }
  38. public function _index_page_filter(&$data)
  39. {
  40. foreach ($data as &$v) {
  41. $v['detail_url'] = 'https://'.$_SERVER['HTTP_HOST']."/dist/#/activity-detail?id=".$v['act_id'].'&tg='.$v['tg_param'];
  42. }
  43. }
  44. /**
  45. * 添加
  46. * @auth true
  47. * @menu true
  48. * @throws \think\Exception
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. * @throws \think\exception\DbException
  52. * @throws \think\exception\PDOException
  53. */
  54. public function add()
  55. {
  56. $this->title = '添加';
  57. $this->_form($this->table, 'form');
  58. }
  59. /**
  60. * 编辑
  61. * @auth true
  62. * @menu true
  63. * @throws \think\Exception
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\ModelNotFoundException
  66. * @throws \think\exception\DbException
  67. * @throws \think\exception\PDOException
  68. */
  69. public function edit()
  70. {
  71. $this->title = '编辑';
  72. $this->_form($this->table, 'form');
  73. }
  74. /**
  75. * 删除
  76. * @auth true
  77. * @throws \think\Exception
  78. * @throws \think\exception\PDOException
  79. */
  80. public function del()
  81. {
  82. $this->_save($this->table, ['is_deleted' => '1']);
  83. }
  84. /**
  85. * 批量删除
  86. * @auth true
  87. * @throws \think\Exception
  88. * @throws \think\exception\PDOException
  89. */
  90. public function remove()
  91. {
  92. $this->_save($this->table, ['is_deleted' => '1']);
  93. }
  94. protected function _form_filter(&$data)
  95. {
  96. if($this->request->isPost())
  97. {
  98. $phone = input('phone');
  99. $user_id = User::where('phone|email',$phone)->value('id');
  100. if(!$user_id)$this->error('用户不存在');
  101. $data['user_id'] = $user_id;
  102. $data['qrcode'] = create_qrcode($data['act_id'],$user_id,'activity');
  103. $data['tg_param'] = $data['act_id'].'_'.$user_id;
  104. }
  105. }
  106. }