getList($where); $result = array(); if ($data) { foreach ($data as $k => $v) { $result[$k]['title'] = $v['name']; $result[$k]['total'] = -1; $result[$k]['status'] = 1; $result[$k]['num'] = $v['buy_num']; $result[$k]['price'] = $v['cash'] . '元'; $result[$k]['cdate'] = date('Y-m-d H:i:s', $v['cdate']); } } return $result; } # 保存信息 public function up($uid, $info_id, $num = 1) { $where['uid'] = $uid; $where['info_id'] = $info_id; $info = Dever::db('user/ticket')->one($where); if (!$info) { $where['num'] = $num; $where['total'] = $num; return Dever::db('user/ticket')->insert($where); } else { $update['where_id'] = $info['id']; $update['num'] = $num; $update['total'] = $num; Dever::db('user/ticket')->add($update); return $info['id']; } } # 保存说明信息 public function save($uid, $id, $desc) { $where['uid'] = $uid; $where['id'] = $id; $info = Dever::db('user/ticket')->one($where); if ($info) { $update['where_id'] = $id; $update['desc'] = $desc; Dever::db('user/ticket')->update($update); } } # 获取数量 public function num($uid, $info_id = false) { $where['uid'] = $uid; if ($info_id) { $where['info_id'] = $info_id; } $num = Dever::db('user/ticket')->num($where); if ($num) { return $num['num'] ? $num['num'] : 0; } return 0; } # 验证是否购买 public function check($uid, $info_id) { $where['uid'] = $uid; $where['info_id'] = $info_id; $info = Dever::db('user/ticket')->one($where); return $info; } # 发起支付 public function action($parent_uid, $uid, $buy_id, $object_id, $system_source, $refer = '') { if (!$uid) { Dever::alert('错误的用户信息'); } $buy = Dever::db('collection/buy')->one($buy_id); if (!$buy) { Dever::alert('购买失败'); } $info = Dever::db('collection/info')->one($buy['info_id']); if (!$info) { Dever::alert('购买失败'); } $cate = Dever::db('collection/cate')->one($info['cate_id']); if (!$cate) { Dever::alert('购买失败'); } $order_data['uid'] = $uid; $order_data['status'] = 1; $order_data['cate_id'] = $cate['id']; $order_data['info_id'] = $info['id']; $order_data['buy_id'] = $buy['id']; $order_data['buy_num'] = $buy['num']; $order_data['name'] = Dever::load("collection/lib/buy.getName", $buy); $order_data['cash'] = Dever::load("collection/lib/buy.getPrice", $buy); $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; } if ($object_id) { $order_data['object_id'] = $object_id; } $id = Dever::db('user/ticket_order')->insert($order_data); if (!$id) { Dever::alert('支付失败'); } $param = array ( 'project_id' => 2, '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 'ticket_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/ticket_order')->one(array('order_id' => $order_id, 'time' => time())); if ($order && $order['status'] == 1) { if ($status == 2) { # 更新持有门票数量 $ticket_id = $this->up($order['uid'], $order['info_id'], $order['buy_num']); if ($ticket_id) { # 更新拥有合集数量 Dever::load('user/lib/collection')->up($ticket_id, $order['uid'], $order['uid'], $order['info_id'], $order['cate_id'], 1); # 加入门票榜单 Dever::load('collection/lib/ranking')->up($order['uid'], $order['info_id'], 1, $order['buy_num']); } # 更新购买数 $total = Dever::db('user/ticket')->total(array('info_id' => $order['info_id'])); Dever::db('collection/info')->update(array('num_buy' => $total['total'], 'where_id' => $order['info_id'])); # 增加积分 if ($order['parent_uid'] > 0) { $uid = $order['parent_uid'] . '_' . $order['uid']; } else { $uid = $order['uid']; } Dever::score($uid, 'buy_ticket', '购买门票', 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/ticket_order')->update($update); } return 'ok'; } # 生成订单号 public function getOrderId() { $where['order_id'] = Dever::order('T'); $state = Dever::db('user/ticket_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; } } }