/** * 生成订单 */ public function action_paymoney() { $this->template->pageTitle = '订单支付'; $info = explode(',', base64_decode(trim($this->getQuery('t')))); if (!empty($info)) { $upgrade = new Upgrade($this->auth, (int) $info[0], (int) $info[1]); try { $upgrade->check_place(); } catch (Exception $e) { $this->show_message('创建订单失败:' . $e->getMessage()); } $this->template->payPrice = $payPrice = ceil($upgrade->calculate()->getMoney()); // 订单金额 $this->template->getGroupPrice = $getGroupPrice = $upgrade->getGroupPrice(); // 获取升级组需要金额 if ($payPrice < 1) { $links[] = array('text' => '返回付费中心', 'href' => '/pay/upgrade'); $this->show_message('抱歉,所在用户组无法升级。。。', 0, $links); } $this->template->group = $upgrade->getGroup(); switch ($info[0]) { default: $gift = ''; break; } $this->template->gift = $gift; if ($info[1] == 12) { $unit = "1年"; } else { $unit = $info[1] . "个月"; } $this->template->unit = $unit; # 计算付款后到期时间 if ($this->auth['rank'] == $info[0]) { $expire = time() - $this->auth['expire_time']; if ($expire > 604800) { $will_exceed = date('Y-m-d', strtotime(date('Y-m-d H:i:s') . ' + ' . $info[1] . ' ' . 'month') - 604800); } else { $will_exceed = date('Y-m-d', strtotime(date('Y-m-d H:i:s', $this->auth['expire_time']) . ' + ' . $info[1] . ' ' . 'month')); } } else { $will_exceed = date('Y-m-d', strtotime('+' . $info[1] . ' month ')); } $this->template->will_exceed = $will_exceed; $this->template->order_id = $order_id = $upgrade->generateOrderSn(); $data = array('uid' => $this->auth['uid'], 'dest_group' => $info[0], 'save_time' => date('Y-m-d H:i:s'), 'fee' => $payPrice, 'current_group' => $this->auth['rank'], 'orderno' => $order_id, 'consume_type' => 1, 'will_exceed' => $will_exceed, 'month' => $info[1]); # 创建订单 DB::insert('imgup_upgrade', array_keys($data))->values(array_values($data))->execute(); try { $order_id = (int) $order_id; $info = $data; $adapter = $this->template->adapter = 'alipay'; if ($info['uid'] != $this->auth['uid']) { throw new Exception('您不能查看别人的订单。'); } $payConf = $this->template->payConf = Payment::get_all(); // 支付方式 $adapter = 'alipay'; if ($payConf->{$adapter}->online) { // 在线支付 $title = $this->auth['username'] . '购买外链吧相册服务'; $body = $this->auth['username'] . '于' . date('Y年m月d日') . '购买外链吧网络相册服务,订单号:' . $info['orderno']; $payment = Payment::create('alipay', $payConf->{$adapter}->config); $payment->set_id($info['orderno'])->set_subject($title)->set_body($body)->set_amount($info['fee'])->set_key($payConf->{$adapter}->pay_key); if (!$payment->is_valid()) { throw new Exception($payment->get_message()); } $this->template->payment = $payment; } } catch (Exception $e) { $this->show_message('订单支付失败:' . $e->getMessage()); } } else { $this->request->redirect('/pay/upgrade'); } }
/** * 升级用户 */ public function action_upgrade() { $uid = (int) $this->getQuery('uid'); $user = ORM::factory('user'); $this->template->orderInfo = DB::select('u.*', 'g.group_name')->from(array('imgup_upgrade', 'u'))->join(array('imgup_group', 'g'))->on('g.id', '=', 'u.dest_group')->where('uid', '=', $uid)->order_by('u.id', 'DESC')->fetch_all(); $this->template->userInfo = $userInfo = $user->getInfo($uid); $this->template->group = DB::select('g.*')->from(array('imgup_group', 'g'))->execute()->as_array(); if ($this->isPost()) { $uid = (int) $this->getPost('uid'); $groupId = (int) $this->getPost('group'); $time = (int) $this->getPost('time'); $status = (int) $this->getPost('status'); if ($status) { $time = $time * 12; } $userInfo = DB::select()->from('users')->where('uid', '=', $uid)->execute()->current(); $upgrade = new Upgrade($userInfo, $groupId, $time); $payPrice = $upgrade->calculate()->getMoney(); // 订单金额 //$data = array($uid, $groupId, date('Y-m-d H:i:s'), ceil($payPrice), $userInfo['rank'], $upgrade->generateOrderSn(), 1, $time); $data = array('uid' => $uid, 'dest_group' => $groupId, 'save_time' => date('Y-m-d H:i:s'), 'fee' => ceil($payPrice), 'current_group' => $userInfo['rank'], 'orderno' => $upgrade->generateOrderSn(), 'consume_type' => 1, 'trade_no' => trim($this->getPost('trade_no')), 'month' => $time); # 创建订单 $row = DB::insert('imgup_upgrade', array_keys($data))->values(array_values($data))->execute(); $this->request->redirect('/admin/user/upgrade?uid=' . $uid); } }