123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- <?php
- namespace User\Lib;
- use Dever;
- class Seat
- {
- # 获取座位信息
- public function get($uid, $info_id, $parent_page_id, $page_id, $times_id, $day, $content_id, $index, $hall)
- {
- $data = array();
- //$where['uid'] = $uid;
- $where['info_id'] = $info_id;
- $where['content_id'] = $content_id;
- # 只要买过座位,在哪都可以看,但是只能在座位上发言
- $data['disabled'] = true;
- $state = Dever::db('user/seat')->one($where);
- if ($state) {
- $data['disabled'] = false;
- }
- $where['times_id'] = $times_id;
- if ($day && $day > 0) {
- $where['day'] = $day;
- } else {
- $where['day'] = -1;
- }
- $where['hall'] = $hall;
- $my = Dever::db('user/seat')->getMyData($where);
- if ($my) {
- foreach ($my as $k => $v) {
- $key = $v['hall'] . '_' . $v['seat_row'] . '_' . $v['seat_column'];
- $v['user'] = Dever::load('user/lib/info')->get($v['uid'], $info_id);
- $data[$key] = $v;
- }
- }
- $id = $info_id . '#' . $hall;
- $type = 'seat_' . $info_id . '_' . $times_id . '_' . $content_id . '_' . $day . '_' . $hall;
- $data['seat'] = $this->getAll($id, $type, $hall, $data);
- return $data;
- }
- # 选取座位
- public function save($uid, $info_id, $parent_page_id, $page_id, $times_id, $day, $content_id, $index, $seat)
- {
- $seat = explode(',', $seat);
- # 先检查是否被购买了
- $where['info_id'] = $info_id;
- $where['times_id'] = $times_id;
- $where['content_id'] = $content_id;
- if ($day && $day > 0) {
- $where['day'] = $day;
- } else {
- $where['day'] = -1;
- }
- foreach ($seat as $k => $v) {
- $v = Dever::decode($v);
- $v = explode('#', $v);
- $where['hall'] = $v[1];
- $where['seat_row'] = $v[2];
- $where['seat_column'] = $v[3];
- $info = Dever::db('user/seat')->one($where);
- if (!$info) {
- $where['uid'] = $uid;
- Dever::db('user/seat')->insert($where);
- }
- }
- return true;
- }
- # 获取默认所有座位
- public function getAll($id, $type, $hall, $my)
- {
- # 5行
- $row = 8;
- # 15列
- $column = 15;
- # x轴初始位置
- $x = 24;
- # y轴初始位置
- $y = 3;
- $data = array();
- for($i = 1; $i <= $row ; $i++) {
- $x = 24;
- for($j = 1; $j <= $column ; $j++) {
- $key = $hall . '_' . $i . '_' . $j;
- $info = array
- (
- 'YCoord' => $y,
- 'XCoord' => $x,
- 'SeatCode' => Dever::encode($id . '#' . $i.'#' . $j),
- 'RowNum' => $i,
- 'Tips' => $type,
- 'ColumnNum' => $j,
- 'Status' => 0,
- 'User' => array(),
- 'Id' => 0,
- );
- if (isset($my[$key])) {
- $info['Status'] = 2;
- $info['User'] = $my[$key]['user'];
- $info['Id'] = $my[$key]['id'];
- }
- $data[] = $info;
- $x--;
- }
- $y++;
- }
- return $data;
- }
- # 发起支付
- public function action($parent_uid, $uid, $info_id, $parent_page_id, $page_id, $times_id, $day, $content_id, $index, $seat, $price, $system_source, $refer = '')
- {
- if (!$uid) {
- Dever::alert('错误的用户信息');
- }
- $info = Dever::db('collection/info')->one($info_id);
- if (!$info) {
- Dever::alert('购买失败');
- }
- $cate = Dever::db('collection/cate')->one($info['cate_id']);
- if (!$cate) {
- Dever::alert('购买失败');
- }
- $tmp = explode(',', $seat);
- $num = count($tmp);
- $where['info_id'] = $info_id;
- $where['content_id'] = $content_id;
- $state = Dever::db('user/seat')->one($where);
- if (!$state) {
- $num = $num - 1;
- }
-
- $order_data['uid'] = $uid;
- $order_data['status'] = 1;
- $order_data['info_id'] = $info_id;
- $order_data['parent_page_id'] = $parent_page_id;
- $order_data['page_id'] = $page_id;
- $order_data['times_id'] = $times_id;
- $order_data['day'] = $day;
- $order_data['content_id'] = $content_id;
- $order_data['index'] = $index;
- $order_data['seat'] = $seat;
- $order_data['name'] = '购买座位:' . $seat;
- $order_data['cash'] = $price * $num;
- $order_data['price'] = $price;
- $order_data['num'] = $num;
-
- $order_data['system_source'] = $system_source;
- $order_data['order_id'] = $this->getOrderId();
- if (!$parent_uid && Dever::project('invite')) {
- $parent = Dever::load('invite/api')->getParent($uid, 1);
- if ($parent) {
- $parent_uid = $parent['uid'];
- }
- }
-
- if ($parent_uid) {
- $order_data['parent_uid'] = $parent_uid;
- }
- $id = Dever::db('user/seat_order')->insert($order_data);
- if (!$id) {
- Dever::alert('支付失败');
- }
- if ($num <= 0) {
- # 免费赠送一个座位
- $param['pay_order_id'] = $order_data['order_id'];
- $param['pay_status'] = 2;
- $param['pay_msg'] = '免费';
- $this->success($param);
- return array('type' => 'free');
- }
- $param = array
- (
- 'project_id' => 3,
- 'channel_id' => $cate['pay_channel'],
- 'system_source' => $system_source,
- 'uid' => $uid,
- 'name' => $order_data['name'],
- 'cash' => $order_data['cash'],
- 'product_id' => $info['id'],
- 'order_id' => $order_data['order_id'],
- 'refer' => $refer,
- );
- $receipt = Dever::input('receipt');
- if ($receipt) {
- $param['receipt'] = $receipt;
- }
- $result = Dever::load('pay/api.pay', $param);
- return $result;
- }
- # 支付成功回调 安全加密 设置token
- public function success_secure_api_token()
- {
- $project_id = Dever::input('pay_project_id');
- $info = Dever::db('pay/project')->one($project_id);
- if ($info) {
- return $info['key'];
- }
- return 'seat_dever_2020';
- }
- # 支付成功回调 安全加密
- public function success_secure_api($param = array())
- {
- $this->success($param);
- }
- # 支付成功回调
- public function success($param = array())
- {
- $send = $param ? $param : Dever::preInput('pay_');
- $order_id = $send['pay_order_id'];
- $status = $send['pay_status'];
- $msg = $send['pay_msg'];
- $order = Dever::db('user/seat_order')->one(array('order_id' => $order_id, 'time' => time()));
- if ($order && $order['status'] == 1) {
- if ($status == 2) {
- $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']);
- # 增加积分
- if ($order['parent_uid'] > 0) {
- $uid = $order['parent_uid'] . '_' . $order['uid'];
- } else {
- $uid = $order['uid'];
- }
- Dever::score($uid, 'buy_seat', '购买座位', false, false, false, 'collection/info', $order['info_id']);
- # 发消息
- if (Dever::project('message')) {
- Dever::load('message/lib/data')->push(-1, $order['uid'], '购买提醒', '购买座位成功', 1);
- }
- }
- $update['status'] = $status;
- $update['where_id'] = $order['id'];
- Dever::db('user/seat_order')->update($update);
- }
- return 'ok';
- }
- # 生成订单号
- public function getOrderId()
- {
- $where['order_id'] = Dever::order('T');
- $state = Dever::db('user/seat_order')->one($where);
- if (!$state) {
- return $where['order_id'];
- } else {
- return $this->getOrderId();
- }
- }
- public function getOrderIdAndId($order_id, $id)
- {
- if ($order_id) {
- return $order_id . '/' . $id;
- } else {
- return '无' . '/' . $id;
- }
- }
- }
|