ActivityQrcode.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. if($title = input('phone')) $where[] = ['f.phone','like','%'.$title.'%'];
  31. $query = $this->_query($this->table)->alias('f')
  32. ->field('f.*,t.title act_title')
  33. ->leftJoin('activity t','t.id=f.act_id')
  34. ->where($where)
  35. ->order('f.id asc')->page();
  36. }
  37. /**
  38. * 添加
  39. * @auth true
  40. * @menu true
  41. * @throws \think\Exception
  42. * @throws \think\db\exception\DataNotFoundException
  43. * @throws \think\db\exception\ModelNotFoundException
  44. * @throws \think\exception\DbException
  45. * @throws \think\exception\PDOException
  46. */
  47. public function add()
  48. {
  49. $this->title = '添加';
  50. $this->_form($this->table, 'form');
  51. }
  52. /**
  53. * 编辑
  54. * @auth true
  55. * @menu true
  56. * @throws \think\Exception
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\ModelNotFoundException
  59. * @throws \think\exception\DbException
  60. * @throws \think\exception\PDOException
  61. */
  62. public function edit()
  63. {
  64. $this->title = '编辑';
  65. $this->_form($this->table, 'form');
  66. }
  67. /**
  68. * 删除
  69. * @auth true
  70. * @throws \think\Exception
  71. * @throws \think\exception\PDOException
  72. */
  73. public function del()
  74. {
  75. $this->_save($this->table, ['is_deleted' => '1']);
  76. }
  77. protected function _form_filter(&$data)
  78. {
  79. $phone = input('phone');
  80. $user_id = User::where('phone|email',$phone)->value('id');
  81. if(!$user_id)$this->error('用户不存在');
  82. $data['user_id'] = $user_id;
  83. $data['qrcode'] = create_qrcode($data['act_id'],$user_id,$module = 'activity');
  84. }
  85. }