Seat.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\AdminBaseController;
  4. use app\common\model\SeatApplyModel;
  5. use app\common\model\SeatModel;
  6. use app\common\service\QrcodeService;
  7. use app\common\validate\SeatValidate;
  8. use think\exception\ValidateException;
  9. class Seat extends AdminBaseController
  10. {
  11. /**
  12. * 列表
  13. */
  14. public function index()
  15. {
  16. return view('',[
  17. 'status_list' => SeatModel::STATUS,
  18. ]);
  19. }
  20. public function listSeat()
  21. {
  22. $map = $this->dealEqualInput(['status']);
  23. $list = SeatModel::where($map)->limit(input('limit'))->page(input('page'))->append(['status_text'])->select();
  24. $count = SeatModel::where($map)->count();
  25. if ($count == 0) {
  26. ajax_return(1, '未查询到数据');
  27. }
  28. list_return($list, $count);
  29. }
  30. /**
  31. * 编辑
  32. */
  33. public function seatForm()
  34. {
  35. $id = input('id/d, 0');
  36. $info = SeatModel::find($id);
  37. return view('', [
  38. 'info' => $info,
  39. 'status_list' => SeatModel::STATUS,
  40. 'seat_list' => empty($info['seat_list']) ? '[]' : json_encode($info['seat_list']),
  41. ]);
  42. }
  43. public function editSeat()
  44. {
  45. $data = input('post.');
  46. try {
  47. validate(SeatValidate::class)->check($data);
  48. } catch (ValidateException $e) {
  49. ajax_return(1, $e->getError());
  50. }
  51. $data['total'] = array_sum($data['seat_list']);
  52. if (empty($data['id'])) {
  53. SeatModel::create($data);
  54. } else {
  55. SeatModel::update($data, ['id' => $data['id']]);
  56. }
  57. ajax_return();
  58. }
  59. public function delSeat()
  60. {
  61. $id = input('id/d');
  62. $check = SeatApplyModel::where('seat_id', $id)->find();
  63. if (!empty($check)) {
  64. ajax_return(1, '已有投票的活动无法删除!');
  65. }
  66. SeatModel::destroy($id);
  67. ajax_return();
  68. }
  69. /**
  70. * 二维码
  71. */
  72. public function qrcodeSeat()
  73. {
  74. $id = input('id/d', 0);
  75. $file_name = "/seat_{$id}.png";
  76. $link = url('/mobile/seat/apply') . '?id=' . $id;
  77. $file_url = QrcodeService::getQrcode($file_name, $link, 600);
  78. ajax_return(0, '', $file_url);
  79. }
  80. /**
  81. * 座位明细
  82. */
  83. public function apply()
  84. {
  85. return view('', [
  86. 'id' => input('id/d', 0),
  87. ]);
  88. }
  89. public function listApply()
  90. {
  91. $map = $this->dealEqualInput(['seat_id']);
  92. $list = SeatApplyModel::where($map)->limit(input('limit'))->page(input('page'))->select();
  93. $count = SeatApplyModel::where($map)->count();
  94. if ($count == 0) {
  95. ajax_return(1, '未查询到数据');
  96. }
  97. list_return($list, $count);
  98. }
  99. public function exportApply()
  100. {
  101. $map = $this->dealEqualInput(['seat_id']);
  102. $list = SeatApplyModel::where($map)->select();
  103. $xlsCell = [
  104. ['name', '姓名'],
  105. ['mobile', '手机号'],
  106. ['no', '号数'],
  107. ['seat', '座位'],
  108. ['create_time', '选座时间'],
  109. ];
  110. export_exl("座位明细表", $xlsCell, $list, ['mobile', 'no']);
  111. }
  112. }