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; } } }