/** * 输出还款html代码 * * @param string $order_id 订单编号 * @param number $issue 期号,0表示支付首付,其它表示指定账单,仅配合month=1使用 * @param number $month 还款月份,0表示一次性还清,其它表示还款的期数 */ public function alipay($order_id, $issue = 0, $month = 1) { // 获取并验证订单 $user = get_user() or $this->error('请先登录!', '/login'); $orderModel = new \Loan\Model\OrderModel(); $billModel = new \Loan\Model\BillModel(); $order = $orderModel->field('status,first_money,is_allow_prepayment')->where(['uid' => $user['uid'], 'id' => $order_id])->find() or $this->error('找不到此订单信息!'); $issue = intval($issue); $month = intval($month); if ($month == 1) { if ($issue == 0) { // 正常支付首付 $order['status'] == $orderModel::STATUS_UNPAY or $this->error('此订单状态当前不允许支付首付!'); $subject = '指尖分期-支付首付'; $money = $order['first_money']; } else { // 正常支付指定账单 if ($order['status'] == $orderModel::STATUS_UNPAY) { $this->error('请先支付首付!'); } in_array($order['status'], $orderModel->allowRepayStatus()) or $this->error('当前订单状态不允许执行还款!'); // 获取并验证账单信息 $bill = M('loan_bill')->field('issue,money_total,return_money,status')->where(['order_id' => $order_id, 'issue' => $issue])->find() or $this->error('找不到此账单信息!'); $bill['status'] == 0 or $this->error('此账单当前不为待付款状态!'); $bill['money_total'] > 0 or $this->error('此账单无需支付!'); $subject = '指尖分期-' . "支付第{$issue}期"; $money = $bill['money_total'] - $bill['return_money']; } } elseif ($month == 0) { // 一次性还清 $subject = '指尖分期-' . "一次性还款"; $repay = $billModel->getRepay($order_id) or $this->error($billModel->getError()); $money = $repay['money_total']; } elseif ($month > 1) { // 提前还$month期 $subject = '指尖分期-' . "提前还{$month}期"; $repay = $billModel->getRepay($order_id, $month) or $this->error($billModel->getError()); $money = $repay['money_total']; } else { $this->error('还款期数异常!'); } $alipayModel = M('loan_pay_alipay'); $pay_id = $alipayModel->add(['created' => time(), 'order_id' => $order_id, 'issue' => $issue, 'month' => $month, 'money' => $money, 'is_notify' => 0, 'is_action' => 0]); // 确认生成支付表单 $body = '订单号:' . $order_id; $notify_url = U('/pay/alipay_notify/' . $pay_id, null, true, $_SERVER['HTTP_HOST']); $return_url = U('/pay/alipay_return/' . $pay_id, null, true, $_SERVER['HTTP_HOST']); $show_url = U('/user/order/' . $order_id . '@fenqi'); $alipay = new \Common\Util\Alipay\Alipay(); header('Location: ' . $alipay->pay($notify_url, $return_url, $order_id . '-' . $pay_id, $subject, $body, $show_url, $money)); }
public function repay($order_id = 0, $issue = 0, $prepayment = '') { $uid = $this->_user['uid']; $orderModel = new OrderModel(); $billModel = new \Loan\Model\BillModel(); $order = $orderModel->where(['uid' => $uid, 'id' => $order_id])->find() or $this->error('找不到订单信息!'); $bill = M('loan_bill')->where(['order_id' => $order_id, 'issue' => $issue])->find() or $this->error('找不到此账单!'); if (time() >= strtotime('-1 month', $bill['return_limit_time']) && in_array($bill['status'], [0, 1]) && $order['last_bill_issue'] < $issue) { $this->error('请先还清之前的账单'); } if ($prepayment) { $ahead = $issue - $order['last_bill_issue'] + 1; } else { $ahead = 1; } $this->assign('repay_info', $prepayment ? $billModel->getRepay($order_id, $ahead) : $bill); $this->assign('ahead', $ahead); $this->assign('order', $order); $this->assign('bill', $bill); $this->assign('prepayment', $prepayment); if (I('confirm') == 1) { $this->display('repay_normal'); } $this->display(); }
public function get_repay($order_id, $month) { $billModel = new \Loan\Model\BillModel(); echo json_encode($billModel->getRepay($order_id, $month)); }