protected function _detail($id)
 {
     $delay_issue_id = I('get.delay', 0, 'intval');
     $delay_issue_id && $this->_delay($id, $delay_issue_id);
     $model = new \Loan\Model\OrderModel();
     $this->meta_title = '订单详情';
     $detail = $order = M('loan_order')->find($id) or $this->error('找不到此订单信息!');
     // 操作日志
     $log = M('loan_order_log')->where('order_id=' . $id)->order('id ASC')->select();
     foreach ($log as $key => $vo) {
         $log[$key]['status_text'] = isset($this->_status[$vo['status']]) ? $this->_status[$vo['status']] : '未知';
     }
     $detail['log'] = $log;
     $campus_list = M('university_campus')->getField('id, concat(university_name,name) name');
     // 订单电子合同
     $contract = M('loan_order_contract')->where(['order_id' => $id])->find();
     int_to_string($contract, ['status' => [0 => '等待生成', 1 => '正在生成', 2 => '已生成', 3 => '生成失败']]);
     if ($contract['is_check_success'] < 1) {
         $contract['status_text'] = '等待审核';
     }
     $this->assign('contract', $contract);
     // 字段翻译
     int_to_string($detail, ['type' => $this->_type, 'source' => ['', '网站', '客户端'], 'status' => $this->_status, 'city_id' => M('common_region')->getField('id,name'), 'campus_id' => array_column($campus_list, 'name', 'id'), 'payee_account_type' => $model->payee_account_type_config]);
     // 是否允许关闭
     $detail['allow_close'] = $model->allowClose($detail, true);
     // 判断是否允许编辑(审核通过前)
     $detail['allowEditBase'] = $model->allowUpdate($order);
     // 是否弹出关闭确认框:该用户已经付有首付/还款,点击确认继续关闭订单,并请人工处理相关款项。
     $detail['close_confirm'] = in_array($detail['status'], [$model::STATUS_DELIVERY, $model::STATUS_REPAY]) || $detail['status'] == $model::STATUS_CHECK_SUCCESS && $detail['first_money'] > 0 || M('loan_order_finance')->where(['order_id' => $order['id']])->getField('is_first_money_paid') > 0;
     // 订单及模型变量
     $this->assign('order', $detail);
     $this->assign('detail', $detail);
     $this->assign('orderModel', $model);
     // 账单
     $bill = M('loan_bill')->where(['order_id' => $id])->order('issue ASC')->select();
     int_to_string($bill, ['status' => ['待还款', '还款待确认', '已还款', '已关闭']]);
     $this->assign('_bill', $bill);
     // 是否允许取消提前部分期数还款
     $allow_cancel_replay_part = in_array($detail['status'], [$model::STATUS_DELIVERY, $model::STATUS_REPAY]) && strpos(M('loan_order_log')->where(['order_id' => $detail['id']])->order('id desc')->getField('action'), '提前部分') === 0 || $detail['status'] == $model::STATUS_FINISH_SUCCESS && M('loan_order_log')->where(['order_id' => $detail['id'], 'action' => ['like', '提前全部%期还款']])->count() > 0;
     $this->assign('allow_cancel_replay_part', $allow_cancel_replay_part);
     // 是否允许取消自定义还款
     $allow_cancel_replay_custom = $detail['status'] == $model::STATUS_FINISH_SUCCESS && M('loan_order_log')->where(['order_id' => $detail['id'], 'action' => '提前全部还款'])->count();
     $this->assign('allow_cancel_replay_custom', $allow_cancel_replay_custom);
     // 物流信息
     $delivery = M('loan_order_delivery')->find($id);
     $this->assign('delivery', $delivery);
     $this->assign('_express', M('common_express')->where('status=1')->order('sort_weight desc,name')->getField('id,name'));
     // 此用户未完成订单数
     $unfinish = $model->where(['uid' => $detail['uid'], 'id' => ['neq', $detail['id']], 'status' => ['not in', [$model::STATUS_CLOSED, $model::STATUS_FINISH_SUCCESS]]])->count();
     $this->assign('user_total_order_unfinish', $unfinish);
     // 催收记录
     $dun = M('loan_bill_dun')->where(['order_id' => $detail['id']])->order('dun_date desc')->select();
     $this->assign('_dun', $dun);
     // 红包信息
     $red_packet = M('loan_order_red_packet')->where(['order_id' => $detail['id']])->find();
     if ($red_packet) {
         $red_packet += get_user($red_packet['uid']);
         int_to_string($red_packet, ['status' => ['0' => '待订单完成', '1' => '发完成', '2' => '已关闭']]);
     }
     $this->assign('allow_red_packet', !$red_packet && !in_array($detail['status'], [$model::STATUS_CLOSED, $model::STATUS_FINISH_SUCCESS]));
     $this->assign('red_packet', $red_packet);
     // 认证资料
     $this->assign('user_contract', M('loan_user_contract')->find($detail['uid']));
     $auth_data = D('Loan/UserContract')->getAuth($detail['uid']);
     // 使用水印
     $auth_data = array_map(function ($item) {
         $item['origin_url'] = $item['url'];
         if ($item['url_watermark']) {
             $item['url'] = $item['url_watermark'];
         }
         return $item;
     }, $auth_data);
     $this->assign('_user_auth', $auth_data);
     // 签约材料
     $auth = M('loan_order_auth')->where(['order_id' => $detail['id']])->order('auth_sort')->select();
     $auth = array_column($auth, null, 'auth_id');
     $auth_data = [];
     $config_auth = M('loan_config_auth')->where('type=2 and status=1')->order('sort')->select();
     foreach ($config_auth as $vo) {
         if (isset($auth[$vo['id']])) {
             $auth_data[] = $auth[$vo['id']];
             unset($auth[$vo['id']]);
         } else {
             $auth_data[] = ['auth_id' => $vo['id'], 'auth_name' => $vo['name'], 'auth_sort' => $vo['sort'], 'created' => 0, 'url' => '', 'url_watermark' => ''];
         }
     }
     $auth_data = array_merge($auth, $auth_data);
     // 使用水印
     $auth_data = array_map(function ($item) {
         $item['origin_url'] = $item['url'];
         if ($item['url_watermark']) {
             $item['url'] = $item['url_watermark'];
         }
         return $item;
     }, $auth_data);
     $this->assign('_auth', $auth_data);
     // 校园专员
     $salesman = [];
     // 特派
     $salesman_order = M('loan_order_salesman')->alias('s')->join('zj_loan_salesman u on u.uid=s.uid')->where(['order_id' => $detail['id']])->join('zj_user user on user.uid=s.uid')->field('u.*,user.realname,s.status order_salesman_status')->select();
     foreach ($salesman_order as $vo) {
         $vo['is_first'] = 1;
         $salesman[$vo['uid']] = $vo;
     }
     // 城市或校区
     $salesman_campus = M('loan_salesman')->alias('s')->where(['s.status' => 1, 's.uid' => ['exp', ' in (select uid from zj_loan_salesman_scope where city_id=' . $order['city_id'] . ' or campus_id=' . $order['campus_id'] . ')']])->join('zj_user user on user.uid=s.uid')->field('s.*,user.realname')->select();
     foreach ($salesman_campus as $vo) {
         $vo['is_first'] = 0;
         $vo['order_salesman_status'] = 0;
         if (!isset($salesman[$vo['uid']])) {
             $salesman[$vo['uid']] = $vo;
         }
     }
     int_to_string($salesman, ['type_id' => M('loan_salesman_type')->getField('id,name')]);
     $this->assign('_salesman', $salesman);
     // 财务信息
     $finance = M('loan_order_finance')->where(['order_id' => $detail['id']])->find();
     if ($finance) {
         int_to_string($finance, ['lend_status' => ['未打款', '打款中', '已打款', '打款失败']]);
     }
     int_to_string($finance, ['payee_user_type' => ['未设定', '对公', '对私'], 'payee_bank_type' => ['未设定', '行内', '跨行']]);
     $this->assign('finance', $finance);
     // 判断是否允许更新财务收款信息
     $this->assign('finance_is_allow_update', check_auth('loan/order/financeUpdate') && $order['type'] != 3 && $finance['lend_status'] != 2);
     // 备注信息
     $this->assign('_remark', M('loan_order_remark')->where(['order_id' => $detail['id']])->order('id')->select());
     // 来源
     $source = M('loan_order_source')->where(['order_id' => $detail['id']])->find();
     $source && int_to_string($source, ['type' => ['', '网站', '安卓客户端', '苹果客户端', '微信']]);
     $this->assign('source', $source);
     // 判断是否有权限签约
     $this->assign('other', M('loan_order_other')->find($id));
     if (in_array($detail['status'], [$model::STATUS_UNCHECK, $model::STATUS_UNCONTRACT])) {
         if (check_auth('Loan/Order/checkAuth') || check_auth('Loan/Order/checkAuthAdv')) {
             M('loan_order_other')->save(['order_id' => $detail['id'], 'last_auth_checker_uid' => $this->_user['uid'], 'last_auth_checker_uname' => $this->_user['uname'], 'last_auth_checker_updated' => time()]);
         }
     }
     // 自营商品的商家信息
     if ($detail['goods_id'] > 0) {
         $this->assign('seller', M('loan_shop_goods_seller')->where(['goods_id' => $detail['goods_id']])->find());
     }
     // 业务员信息
     $this->assign('salesman', $detail['salesman_uid'] > 0 ? M('user')->find($detail['salesman_uid']) : null);
     // 是否允许还款
     $this->assign('allow_repay', in_array($detail['status'], $model->allowRepayStatus(1)));
     // 读取历史放款信息
     if (check_auth('loan/order/financeUpdate')) {
         $_finance_payfee = M('loan_system_order_finance')->where($detail['goods_id'] > 0 ? ['goods_id' => $detail['goods_id']] : ['title' => ['like', '%' . $detail['title'] . '%']])->limit(100)->order('id desc')->select();
         int_to_string($_finance_payfee, ['payee_user_type' => ['未设定', '对公', '对私'], 'payee_bank_type' => ['未设定', '行内', '跨行']]);
         $this->assign('_finance_payfee', $_finance_payfee);
     }
     // 读取商铺信息
     $companyModel = new \Loan\Model\CompanyModel();
     $company = $companyModel->find($detail['company_id']);
     int_to_string($company, ['type' => $companyModel->getType()]);
     $this->assign('company', $company);
     // 显示详情
     $this->display('detail');
     exit;
 }
Beispiel #2
0
 public function updateCompany($order_id, $company_id)
 {
     $companyModel = new \Loan\Model\CompanyModel();
     // 将商铺的打款信息同步到待审核订单中
     if (!$companyModel->update_order_finance($company_id, $order_id)) {
         return $this->_error($companyModel->getError());
     }
     // 更新此订单的所属商铺
     $this->where(['id' => $order_id])->setField('company_id', $company_id);
     $companyModel->where(['id' => $company_id])->save(['total_order' => ['exp', '(select count(1) from zj_loan_order where company_id=zj_loan_company.id)']]);
     // 给商家发送短信(临时)
     $order = $this->find($order_id);
     if ($order && $order['status'] != self::STATUS_CLOSED && $order['check_status'] == 1) {
         $company = M()->table('zj_loan_order o')->join('zj_loan_company c on c.id=o.company_id')->where(['o.id' => $order_id])->field('c.telephone')->find();
         if ($company && strlen($company['telephone']) == 11) {
             $msg = '订单已被金融处理为通过签约:' . $order['title'] . ',' . $order_id . ',' . $order['realname'];
             sms($company['telephone'], $msg, '指尖分期');
         }
     }
     return true;
 }
 protected function _check_success($model, $where)
 {
     $model = new \Loan\Model\CompanyModel();
     $model->check_success($where['id'][1]) or $this->error($model->getError());
     $this->success();
 }