public function update_order_finance($id, $order_id = 0) { // 获取商铺的财务信息 $company = $this->find($id); if (!$company) { $this->error = '找不到此商铺信息!'; return false; } // 获取目标订单 if ($order_id <= 0) { // 获取商铺所关联的待审核订单 $orderModel = new \Loan\Model\OrderModel(); $order_ids = $orderModel->where(['company_id' => $id, 'status' => ['in', [$orderModel::STATUS_UNCONTRACT, $orderModel::STATUS_UNCHECK]]])->getField('id', true); } else { $order_ids = [$order_id]; } if (!$order_ids) { return true; } foreach ($order_ids as $order_id) { // 判断财务打款状态 $finance = M('loan_order_finance')->where(['order_id' => $order_id])->find(); if (!$finance) { return $this->_error('找不到此订单财务记录!'); } if ($finance['lend_status'] != 0) { return $this->_error('财务已打款,禁止修改商家信息!'); } if ($finance['is_allow_lend'] != 0) { return $this->_error('财务已同意打款,禁止修改商家信息!'); } M('loan_order_finance')->where(['order_id' => $order_id])->save(['payee_account' => $company['payee_account'], 'payee_name' => $company['payee_name'], 'payee_bank' => $company['payee_bank'], 'payee_bank_id' => $company['payee_bank_id'], 'payee_user_type' => $company['payee_user_type'], 'payee_bank_type' => $company['payee_bank_type']]); } return true; }
public function __construct() { parent::__construct(); $orderModel = new \Loan\Model\OrderModel(); $this->_field_text_map['order_type'] = $this->_order_type = $orderModel->getType(); $this->_field_text_map['status'] = $this->_status = $orderModel->getStatus(); }
public function __construct() { parent::__construct(); $orderModel = new \Loan\Model\OrderModel(); $this->_type = $orderModel->getType(); $this->_status = $orderModel->getStatus(); }
protected function _detail($uid) { $model = M()->table('zj_user_red_packet r')->join('zj_user u on u.uid=r.uid'); $user = $model->where(['r.uid' => $uid])->find() or $this->error('找不到此用户信息!'); $this->assign('user', $user); // 未完成记录 $orderModel = new \Loan\Model\OrderModel(); $model = M()->table('zj_loan_order_red_packet r')->join('zj_loan_order o on o.id=r.order_id'); $order = $model->field('r.*,o.status order_status')->where(['r.uid' => $uid])->order('r.created desc')->select(); int_to_string($order, ['order_status' => $orderModel->getStatus(), 'status' => ['0' => '待完成', '1' => '已完成', '2' => '已关闭']]); $this->assign('_order', $order); // 红包记录 $log = M('user_red_packet_log')->where(['uid' => $uid])->order('created desc')->select(); int_to_string($log, ['action' => ['1' => '订单完成', '2' => '提现']]); $this->assign('_log', $log); // 提现记录 $withdraw = M('user_red_packet_withdraw')->where(['uid' => $uid])->order('created desc')->select(); int_to_string($withdraw, ['status' => ['0' => '待审核', '1' => '审核通过', '2' => '已关闭']]); $this->assign('_withdraw', $withdraw); $this->meta_title = '红包详情'; $this->display('detail'); }
public function checkout() { $id = I('id', 0, 'intval'); $money_student = I('money_student', 0, 'float'); $money_company = I('money_company', 0, 'float'); $money_service = I('money_service', 0, 'float'); $type = I('type'); $jobModel = new \Job\Model\PayModel(); if ($type == 'company') { $ret = $jobModel->checkout($id, $money_student, $money_company, $money_service); $ret or $this->error($jobModel->getError()); // 结算成功后,立即执行自动还款 $join = M('job_join')->find($id) or $this->error('找不到此参与信息!'); $orderModel = new \Loan\Model\OrderModel(); $ret = $orderModel->autoRepay($join['uid'], $money_student); $ret ? $this->success() : $this->error('结算成功,但自动分期还款失败:' . $jobModel->getError()); } elseif ($type == 'student') { $ret = $jobModel->checkoutStudent($id, $money_student, $money_company, $money_service); $ret ? $this->success() : $this->error($jobModel->getError()); } else { $this->error('未知请求类型!'); } }
public function index() { $orderModel = new \Loan\Model\OrderModel(); // 所属位置:校区或城市 $where_location = ' ( campus_id in (select campus_id from zj_loan_salesman_scope where uid=' . $this->_user['uid'] . ')'; $where_location .= ' OR city_id in (select city_id from zj_loan_salesman_scope where uid=' . $this->_user['uid'] . ') )'; // 特派订单 $where_salesman = ' id in (select order_id from zj_loan_order_salesman where uid=' . $this->_user['uid'] . ')'; if ($this->_salesman['type_id'] == 1) { $where_base = $where_salesman . ' and created >= ' . strtotime('-3 day'); } else { if ($this->_salesman['type_id'] == 2) { $where_base = $where_salesman . ' and created >= ' . strtotime('-7 day'); } else { if ($this->_salesman['type_id'] == 3) { $where_base = $where_salesman; } else { $where_base = $where_location . ' and created >= ' . strtotime('-30 day'); } } } // 可抢单列表 $this->assign('total_unsales', $orderModel->where(['status' => ['in', [$orderModel::STATUS_UNCONTRACT, $orderModel::STATUS_UNCHECK]], 'id' => ['exp', ' not in (select order_id from zj_loan_order_salesman)'], '_string' => $where_location])->count()); // 所有特派订单 $this->assign('total_all', $orderModel->where($where_base)->count()); // 未审核通过 $this->assign('total_uncheck', ['my' => $orderModel->where(['check_status' => 0, 'status' => ['neq', $orderModel::STATUS_CLOSED]])->where($where_base . ' and id in (select order_id from zj_loan_order_salesman where uid=' . $this->_user['uid'] . ' and status=0) ')->count(), 'apply' => $orderModel->where(['check_status' => 0, 'status' => ['neq', $orderModel::STATUS_CLOSED]])->where($where_base . ' and id in (select order_id from zj_loan_order_salesman where uid=' . $this->_user['uid'] . ' and status=1)')->count(), 'failure' => $orderModel->where(['status' => $orderModel::STATUS_CHECK_FAILURE])->where($where_base)->count()]); // 已审核,等待首付 $this->assign('total_unpay', $orderModel->where(['status' => $orderModel::STATUS_UNPAY])->where($where_base)->count()); // 未放款总数 $this->assign('total_unlend', $orderModel->where(['check_status' => 1, 'lend_status' => 0, 'status' => ['neq', $orderModel::STATUS_CLOSED]])->where($this->_salesman['type_id'] == 4 ? $where_location : $where_salesman)->count()); // 已放款总数 $this->assign('total_lended', $orderModel->where(['check_status' => 1, 'lend_status' => ['neq', 0]])->where($where_base)->count()); $this->assign('total_close', $orderModel->where(['status' => $orderModel::STATUS_CLOSED])->where($where_base)->count()); $this->display(); }
public function _excel() { $where = $this->_getWhere(); $model = M()->table('zj_loan_order_salesman s')->join('zj_loan_order o on o.id=s.order_id'); $model->join('zj_user u on u.uid=s.uid'); $model->join('zj_university_campus c on c.id=o.campus_id'); $fields = 's.*,o.seller_name,o.realname order_realname,o.created,o.status,o.loan_money,o.type,o.title,o.realname,o.seller_name,u.realname,u.mobile,c.city,c.university_name,c.name campus_name'; $list = $model->where($where)->order('lend_time')->field($fields)->select(); $orderModel = new \Loan\Model\OrderModel(); int_to_string($list, ['type' => $orderModel->getType(), 'status' => $orderModel->getStatus()]); foreach ($list as $key => $vo) { $list[$key]['created'] = time_format($vo['created']); $list[$key]['lend_time'] = time_format($vo['lend_time']); } excel('业绩数据', $list, ['城市' => 'city', '类型' => 'type_text', '学校' => 'university_name', '校区' => 'campus_name', '订单号' => 'order_id', '放款时间' => 'lend_time', '下单时间' => 'created', '学生姓名' => 'order_realname', '订单标题' => 'title', '订单状态' => 'status_text', '贷款金额' => 'loan_money', '业务员姓名' => 'realname', '业务员手机号' => 'mobile', '商家店名' => 'seller_name']); }
public function check_failure_apply() { $model = new \Loan\Model\OrderModel(); $order = $this->_order(); $model->checkFailureApply($order['id']) or ajax_error($model->getError()); ajax_success(); }
/** * 自动还款(从个人钱包扣款) * * @param int $uid 用户编号 * @param number $money 最大还款金额,默认为null,表示返回总共所需还款金额 * * @return 实际还款金额 */ public function autoRepay($uid, $money = null, $trade_no = '') { $orderModel = new \Loan\Model\OrderModel(); $where_order_status = implode(',', $orderModel->allowRepayStatus(true)); $where_order = 'is_support_job=1 and uid =' . intval($uid) . ' and status in (' . $where_order_status . ')'; $bills = $this->where(['order_id' => ['exp', ' in ( select id from zj_loan_order where ' . $where_order . ')'], 'issue' => ['gt', 0], 'status' => 0])->order('return_limit_time ASC')->select(); // 返回总共所需的金额 if ($money === null) { $money = 0; foreach ($bills as $bill) { $money += $bill['money_total'] - $bill['return_money']; } return $money; } $total_pay_money = 0; $money_remain = $money; // 处理订单 foreach ($bills as $bill) { if ($money_remain <= 0) { break; } // 验证统计字段是否正常 if (bccomp($bill['money_total'], $bill['money_principal'] + $bill['money_fee'] + $bill['money_delay'], 2) != 0) { system_warn('检测到账单money_total字段异常!'); continue; } $pay_money = min($money_remain, $bill['money_total'] - $bill['return_money']); $ret = $this->repay($bill['order_id'], $bill['issue'], $pay_money, 3, $trade_no); if (!$ret) { system_warn('自动还款失败:' . $this->error); continue; } $money_remain -= $pay_money; $total_pay_money += $pay_money; } return $total_pay_money; }
protected function _paySuccess($pay_id, $money, $alipay_trade_no) { // 验证是否重复操作 $payRow = M('loan_pay_alipay')->find($pay_id); if (!$payRow) { return '此交易记录不存在!'; } if ($payRow['is_action'] > 0) { return true; } if (bccomp($money, $payRow['money'], 2) != 0) { return '支付金额与记录不符!'; } if (!M('loan_pay_alipay')->where(['id' => $pay_id, 'is_action' => $payRow['is_action']])->setField('is_action', 1)) { return true; } $orderModel = new \Loan\Model\OrderModel(); $billModel = new \Loan\Model\BillModel(); $order_id = $payRow['order_id']; $month = $payRow['month']; $issue = $payRow['issue']; $money = $payRow['money']; $order = $orderModel->field('status')->where(['id' => $order_id])->field('status')->find(); if (!$order) { return '订单信息不存在!'; } if ($month == 1) { if ($issue == 0) { // 正常支付首付 if ($order['status'] == $orderModel::STATUS_CHECK_SUCCESS) { return true; } if ($orderModel->firstPay($order_id, 1, $alipay_trade_no)) { return true; } else { return $orderModel->getError(); } } else { // 正常支付指定账单 $bill = M('loan_bill')->field('issue,money_total,status')->where(['order_id' => $order_id, 'issue' => $issue])->find(); if (!$bill) { return '找不到此账单信息!'; } // 判断是否已经支付 if ($bill['status'] == 2) { return true; } if ($billModel->repay($order_id, $issue, $money, 1, $alipay_trade_no)) { return true; } else { return $billModel->getError(); } } } elseif ($month < 0) { return '未知month参数:' . $month; } else { if (!$billModel->repayAll($order_id, $month, $money, 1, $alipay_trade_no)) { return $billModel->getError(); } } return true; }
public function order() { if (I('post.month', 0, 'intval') > 0) { $userModel = new \Common\Model\UserModel(); $userModel->verifyCode(I('post.mobile'), I('post.verify_code')) or $this->error($userModel->getError()); } $goods = $this->_goods(); $this->assign('goods', $goods); $first_money = I('first_money', 0, 'floatval'); $month = I('month', 0, 'intval'); $quantity = I('quantity', 1, 'intval'); $remark = I('remark'); $payee_account_type = I('payee_account_type', 0, 'intval'); $payee_account = I('account'); $orderModel = new \Loan\Model\OrderModel(); $order_id = $orderModel->addGoods($this->_user['uid'], $goods['id'], $quantity, $first_money, $month, $goods['property_remark'], $remark, $payee_account_type, $payee_account); $order_id or $this->error($orderModel->getError()); if (IS_AJAX) { $this->ajaxReturn(array('status' => 1, 'order_id' => $order_id)); } else { if ($month) { $this->assign('order_id', $order_id); $this->success('下单成功,请等待工作人员审核。', '/user/order', 3); } else { $this->redirect('/pay/alipay/' . $order_id); } } }
public function repay() { $this->meta_title = '还款记录'; $where = $where_created = []; $start = I('get.start', date('Y-m-01', strtotime('-1 month'))); if ($start) { $where_created[] = ['egt', strtotime($start . ' 00:00:00')]; } $end = I('get.end'); if ($end) { $where_created[] = ['elt', strtotime($end . ' 23:59:59')]; } if ($where_created) { $where['p.created'] = $where_created; } $realname = I('get.realname'); if ($realname) { $where['o.realname'] = $realname; } // 初始化搜索 $status = I('get.status', -1, 'intval'); if ($status >= 0) { $where['_string'] = $status > 0 ? 'b.status=2' : 'b.status<>2'; } $_status = ['-1' => '所有状态', '0' => '还款中', '1' => '已还款']; $this->assign('_status', $_status); $this->assign('_status_name', $_status[$status]); $model = M()->table('zj_loan_bill_pay p')->join('zj_loan_bill b on b.order_id=p.order_id and b.issue=p.issue')->join('zj_loan_order o on o.id=b.order_id')->field('o.title,o.type,p.created,p.money,o.realname,p.issue,b.money_principal,b.money_fee,b.money_delay,b.money_total,b.return_money,b.return_limit_time,b.status bill_status')->where($where); $_model = clone $model; $page = new \Think\Page($_model->count(), 20, (array) I('request.')); I('get.export') || $model->limit($page->firstRow . ',' . $page->listRows); $list = $model->order('created DESC')->select(); $orderModel = new \Loan\Model\OrderModel(); int_to_string($list, ['type' => $orderModel->getStatus()]); $this->assign('_page', $page->show()); $this->assign('start', $start); $this->assign('list', $list); if (I('get.export')) { $end = $end ?: date('Y-m-d'); if ($realname) { $realname .= '的'; } $this->exportAsExcel("{$start} 至 {$end} {$realname}还款记录({$_status[$status]}).xlsx", $list); } else { $this->display(); } }
public function updateCompany() { $orderModel = new \Loan\Model\OrderModel(); $orderModel->updateCompany(I('order_id'), I('company_id')) or $this->error($orderModel->getError()); $this->success('更新商铺成功!'); }
public function offline() { $goods_id = I('goods_id'); if (IS_POST) { $this->verify(); $uid = $this->_user['uid']; $first_money = I('first_money'); $month = I('month'); $remark = I('remark'); $orderModel = new \Loan\Model\OrderModel(); $order_id = $orderModel->addOffline($uid, $goods_id, $first_money, $month, $remark); $order_id or $this->error($orderModel->getError()); $this->assign('order_id', $order_id); $this->display('success'); exit; } $model = M()->table('zj_loan_company_goods g')->join('zj_loan_company c on c.id=g.company_id'); $goods = $model->field('g.id,g.title,g.pic,g.price,c.name')->where(['g.id' => $goods_id])->find() or $this->error('找不到此商品信息!'); $this->assign('goods', $goods); $rate = D('Loan/shop_goods')->getFeeRate('offline') or $this->error('无法读取服务费率!'); $this->assign('rate', $rate); $this->display('offline_qr'); }
public function checkFailure($id, $reason = '') { // 获取记录 $contract = $this->find($id); if (!$contract) { $this->error = '认证尚未提交!'; return false; } // 判断状态 if ($contract['status'] != 0) { $this->error = '当前状态不为待审核!'; return false; } $this->where('uid=' . $contract['uid'] . ' and status=0')->save(['status' => 2, 'failure_reason' => $reason]); // 发送推送消息 $this->_push($contract['mobile'], '您的认证审核不通过!', '原因:' . $reason); // 通知订单业务 $orderModel = new \Loan\Model\OrderModel(); $orderModel->checkUserFailure($contract['uid'], $reason); return true; }