Seat.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace User\Lib;
  3. use Dever;
  4. class Seat
  5. {
  6. # 获取座位信息
  7. public function get($uid, $info_id, $parent_page_id, $page_id, $times_id, $day, $content_id, $index, $hall)
  8. {
  9. //$where['uid'] = $uid;
  10. $where['info_id'] = $info_id;
  11. $where['times_id'] = $times_id;
  12. $where['content_id'] = $content_id;
  13. if ($day && $day > 0) {
  14. $where['day'] = $day;
  15. } else {
  16. $where['day'] = -1;
  17. }
  18. $where['hall'] = $hall;
  19. $my = Dever::db('user/seat')->getMyData($where);
  20. $data = array();
  21. if ($my) {
  22. foreach ($my as $k => $v) {
  23. $key = $v['hall'] . '_' . $v['seat_row'] . '_' . $v['seat_column'];
  24. $v['user'] = Dever::load('user/lib/info')->get($v['uid'], $info_id);
  25. $data[$key] = $v;
  26. }
  27. }
  28. $id = $info_id . '#' . $hall;
  29. $type = 'seat_' . $info_id . '_' . $times_id . '_' . $content_id . '_' . $day . '_' . $hall;
  30. $data['seat'] = $this->getAll($id, $type, $hall, $data);
  31. return $data;
  32. }
  33. # 选取座位
  34. public function save($uid, $info_id, $parent_page_id, $page_id, $times_id, $day, $content_id, $index, $seat)
  35. {
  36. $seat = explode(',', $seat);
  37. # 先检查是否被购买了
  38. $where['info_id'] = $info_id;
  39. $where['times_id'] = $times_id;
  40. $where['content_id'] = $content_id;
  41. if ($day && $day > 0) {
  42. $where['day'] = $day;
  43. } else {
  44. $where['day'] = -1;
  45. }
  46. foreach ($seat as $k => $v) {
  47. $v = Dever::decode($v);
  48. $v = explode('#', $v);
  49. $where['hall'] = $v[1];
  50. $where['seat_row'] = $v[2];
  51. $where['seat_column'] = $v[3];
  52. $info = Dever::db('user/seat')->one($where);
  53. if (!$info) {
  54. $where['uid'] = $uid;
  55. Dever::db('user/seat')->insert($where);
  56. }
  57. }
  58. return true;
  59. }
  60. # 获取默认所有座位
  61. public function getAll($id, $type, $hall, $my)
  62. {
  63. # 5行
  64. $row = 8;
  65. # 15列
  66. $column = 15;
  67. # x轴初始位置
  68. $x = 24;
  69. # y轴初始位置
  70. $y = 3;
  71. $data = array();
  72. for($i = 1; $i <= $row ; $i++) {
  73. $x = 24;
  74. for($j = 1; $j <= $column ; $j++) {
  75. $key = $hall . '_' . $i . '_' . $j;
  76. $info = array
  77. (
  78. 'YCoord' => $y,
  79. 'XCoord' => $x,
  80. 'SeatCode' => Dever::encode($id . '#' . $i.'#' . $j),
  81. 'RowNum' => $i,
  82. 'Tips' => $type,
  83. 'ColumnNum' => $j,
  84. 'Status' => 0,
  85. 'User' => array(),
  86. 'Id' => 0,
  87. );
  88. if (isset($my[$key])) {
  89. $info['Status'] = 2;
  90. $info['User'] = $my[$key]['user'];
  91. $info['Id'] = $my[$key]['id'];
  92. }
  93. $data[] = $info;
  94. $x--;
  95. }
  96. $y++;
  97. }
  98. return $data;
  99. }
  100. }