Seat.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. $data = array();
  10. //$where['uid'] = $uid;
  11. $where['info_id'] = $info_id;
  12. $where['content_id'] = $content_id;
  13. # 只要买过座位,在哪都可以看,但是只能在座位上发言
  14. $data['disabled'] = true;
  15. $state = Dever::db('user/seat')->one($where);
  16. if ($state) {
  17. $data['disabled'] = false;
  18. }
  19. $where['times_id'] = $times_id;
  20. if ($day && $day > 0) {
  21. $where['day'] = $day;
  22. } else {
  23. $where['day'] = -1;
  24. }
  25. $where['hall'] = $hall;
  26. $my = Dever::db('user/seat')->getMyData($where);
  27. if ($my) {
  28. foreach ($my as $k => $v) {
  29. $key = $v['hall'] . '_' . $v['seat_row'] . '_' . $v['seat_column'];
  30. $v['user'] = Dever::load('user/lib/info')->get($v['uid'], $info_id);
  31. $data[$key] = $v;
  32. }
  33. }
  34. $id = $info_id . '#' . $hall;
  35. $type = 'seat_' . $info_id . '_' . $times_id . '_' . $content_id . '_' . $day . '_' . $hall;
  36. $data['seat'] = $this->getAll($id, $type, $hall, $data);
  37. return $data;
  38. }
  39. # 选取座位
  40. public function save($uid, $info_id, $parent_page_id, $page_id, $times_id, $day, $content_id, $index, $seat)
  41. {
  42. $seat = explode(',', $seat);
  43. # 先检查是否被购买了
  44. $where['info_id'] = $info_id;
  45. $where['times_id'] = $times_id;
  46. $where['content_id'] = $content_id;
  47. if ($day && $day > 0) {
  48. $where['day'] = $day;
  49. } else {
  50. $where['day'] = -1;
  51. }
  52. foreach ($seat as $k => $v) {
  53. $v = Dever::decode($v);
  54. $v = explode('#', $v);
  55. $where['hall'] = $v[1];
  56. $where['seat_row'] = $v[2];
  57. $where['seat_column'] = $v[3];
  58. $info = Dever::db('user/seat')->one($where);
  59. if (!$info) {
  60. $where['uid'] = $uid;
  61. Dever::db('user/seat')->insert($where);
  62. }
  63. }
  64. return true;
  65. }
  66. # 获取默认所有座位
  67. public function getAll($id, $type, $hall, $my)
  68. {
  69. # 5行
  70. $row = 8;
  71. # 15列
  72. $column = 15;
  73. # x轴初始位置
  74. $x = 24;
  75. # y轴初始位置
  76. $y = 3;
  77. $data = array();
  78. for($i = 1; $i <= $row ; $i++) {
  79. $x = 24;
  80. for($j = 1; $j <= $column ; $j++) {
  81. $key = $hall . '_' . $i . '_' . $j;
  82. $info = array
  83. (
  84. 'YCoord' => $y,
  85. 'XCoord' => $x,
  86. 'SeatCode' => Dever::encode($id . '#' . $i.'#' . $j),
  87. 'RowNum' => $i,
  88. 'Tips' => $type,
  89. 'ColumnNum' => $j,
  90. 'Status' => 0,
  91. 'User' => array(),
  92. 'Id' => 0,
  93. );
  94. if (isset($my[$key])) {
  95. $info['Status'] = 2;
  96. $info['User'] = $my[$key]['user'];
  97. $info['Id'] = $my[$key]['id'];
  98. }
  99. $data[] = $info;
  100. $x--;
  101. }
  102. $y++;
  103. }
  104. return $data;
  105. }
  106. # 发起支付
  107. public function action($parent_uid, $uid, $info_id, $parent_page_id, $page_id, $times_id, $day, $content_id, $index, $seat, $price, $system_source, $refer = '')
  108. {
  109. if (!$uid) {
  110. Dever::alert('错误的用户信息');
  111. }
  112. $info = Dever::db('collection/info')->one($info_id);
  113. if (!$info) {
  114. Dever::alert('购买失败');
  115. }
  116. $cate = Dever::db('collection/cate')->one($info['cate_id']);
  117. if (!$cate) {
  118. Dever::alert('购买失败');
  119. }
  120. $tmp = explode(',', $seat);
  121. $num = count($tmp);
  122. $where['info_id'] = $info_id;
  123. $where['content_id'] = $content_id;
  124. $state = Dever::db('user/seat')->one($where);
  125. if (!$state) {
  126. $num = $num - 1;
  127. }
  128. $order_data['uid'] = $uid;
  129. $order_data['status'] = 1;
  130. $order_data['info_id'] = $info_id;
  131. $order_data['parent_page_id'] = $parent_page_id;
  132. $order_data['page_id'] = $page_id;
  133. $order_data['times_id'] = $times_id;
  134. $order_data['day'] = $day;
  135. $order_data['content_id'] = $content_id;
  136. $order_data['index'] = $index;
  137. $order_data['seat'] = $seat;
  138. $order_data['name'] = '购买座位:' . $seat;
  139. $order_data['cash'] = $price * $num;
  140. $order_data['price'] = $price;
  141. $order_data['num'] = $num;
  142. $order_data['system_source'] = $system_source;
  143. $order_data['order_id'] = $this->getOrderId();
  144. if (!$parent_uid && Dever::project('invite')) {
  145. $parent = Dever::load('invite/api')->getParent($uid, 1);
  146. if ($parent) {
  147. $parent_uid = $parent['uid'];
  148. }
  149. }
  150. if ($parent_uid) {
  151. $order_data['parent_uid'] = $parent_uid;
  152. }
  153. $id = Dever::db('user/seat_order')->insert($order_data);
  154. if (!$id) {
  155. Dever::alert('支付失败');
  156. }
  157. if ($num <= 0) {
  158. # 免费赠送一个座位
  159. $param['pay_order_id'] = $order_data['order_id'];
  160. $param['pay_status'] = 2;
  161. $param['pay_msg'] = '免费';
  162. $this->success($param);
  163. return array('type' => 'free');
  164. }
  165. $param = array
  166. (
  167. 'project_id' => 3,
  168. 'channel_id' => $cate['pay_channel'],
  169. 'system_source' => $system_source,
  170. 'uid' => $uid,
  171. 'name' => $order_data['name'],
  172. 'cash' => $order_data['cash'],
  173. 'product_id' => $info['id'],
  174. 'order_id' => $order_data['order_id'],
  175. 'refer' => $refer,
  176. );
  177. $receipt = Dever::input('receipt');
  178. if ($receipt) {
  179. $param['receipt'] = $receipt;
  180. }
  181. $result = Dever::load('pay/api.pay', $param);
  182. return $result;
  183. }
  184. # 支付成功回调 安全加密 设置token
  185. public function success_secure_api_token()
  186. {
  187. $project_id = Dever::input('pay_project_id');
  188. $info = Dever::db('pay/project')->one($project_id);
  189. if ($info) {
  190. return $info['key'];
  191. }
  192. return 'seat_dever_2020';
  193. }
  194. # 支付成功回调 安全加密
  195. public function success_secure_api($param = array())
  196. {
  197. $this->success($param);
  198. }
  199. # 支付成功回调
  200. public function success($param = array())
  201. {
  202. $send = $param ? $param : Dever::preInput('pay_');
  203. $order_id = $send['pay_order_id'];
  204. $status = $send['pay_status'];
  205. $msg = $send['pay_msg'];
  206. $order = Dever::db('user/seat_order')->one(array('order_id' => $order_id, 'time' => time()));
  207. if ($order && $order['status'] == 1) {
  208. if ($status == 2) {
  209. $this->save($order['uid'], $order['info_id'], $order['parent_page_id'], $order['page_id'], $order['times_id'], $order['day'], $order['content_id'], $order['index'], $order['seat']);
  210. # 增加积分
  211. if ($order['parent_uid'] > 0) {
  212. $uid = $order['parent_uid'] . '_' . $order['uid'];
  213. } else {
  214. $uid = $order['uid'];
  215. }
  216. Dever::score($uid, 'buy_seat', '购买座位', false, false, false, 'collection/info', $order['info_id']);
  217. # 发消息
  218. if (Dever::project('message')) {
  219. Dever::load('message/lib/data')->push(-1, $order['uid'], '购买提醒', '购买座位成功', 1);
  220. }
  221. }
  222. $update['status'] = $status;
  223. $update['where_id'] = $order['id'];
  224. Dever::db('user/seat_order')->update($update);
  225. }
  226. return 'ok';
  227. }
  228. # 生成订单号
  229. public function getOrderId()
  230. {
  231. $where['order_id'] = Dever::order('T');
  232. $state = Dever::db('user/seat_order')->one($where);
  233. if (!$state) {
  234. return $where['order_id'];
  235. } else {
  236. return $this->getOrderId();
  237. }
  238. }
  239. public function getOrderIdAndId($order_id, $id)
  240. {
  241. if ($order_id) {
  242. return $order_id . '/' . $id;
  243. } else {
  244. return '无' . '/' . $id;
  245. }
  246. }
  247. }