Files
liche/admin/controllers/receiver/Orders.php
T

464 lines
19 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Orders extends HD_Controller{
public function __construct(){
parent::__construct();
$this->load->model('receiver/order/receiver_orders_model','orders_model');
$this->load->model('receiver/order/receiver_order_signs_model','order_signs_model');
$this->load->model('receiver/order/receiver_order_loans_model','order_loans_model');
$this->load->model('receiver/order/receiver_order_ckcars_model','order_ckcars_model');
$this->load->model('receiver/order/receiver_order_bills_model','order_bills_model');
$this->load->model('receiver/order/receiver_order_agents_model','order_agents_model');
$this->load->model('receiver/order/receiver_order_deliverys_model','order_deliverys_model');
$this->load->model('receiver/order/receiver_order_contracts_model','order_contracts_model');
$this->load->model('receiver/receiver_customers_model','customers_model');
$this->load->model('auto/auto_series_model');
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_attr_model');
$this->load->model('auto/auto_finance_model');
$this->load->model('sys/sys_finance_model');
}
public function index(){
}
public function lists(){
}
public function get(){
$status_arr = $this->order_signs_model->get_status();
$id = $this->input->get('id');
$row = $this->orders_model->get(['id'=>$id]);
$sign = $this->order_signs_model->get(['o_id'=>$row['id']],'status');
$customers = $this->customers_model->get(['id'=>$row['rid']],'cf_title');
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '订单不存在!');
}
$money_json = json_decode($row['money_json'],true);
$row['info_json'] = json_decode($row['info_json'],true);
$row['status'] = intval($row['status']);
$row['price'] = number_format($row['price'],2);
$row['deposit'] = number_format($row['deposit'],2);
$row['c_time'] = date('Y-m-d',$row['c_time']);
$row['sign_status_name'] = $status_arr[$sign['status']];
$row['cf_title'] = $customers['cf_title'];
$row['payway'] = intval($row['payway']);
$row['item_id'] = intval($row['item_id']);
$row['cardid'] = $row['info_json']['cardid'] ? $row['info_json']['cardid'] : $row['info_json']['c_cardid'];
$row['address'] = $row['info_json']['c_address'] ? $row['info_json']['c_address'] : '';
//获取车信息
$brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name');
$serie = $this->auto_series_model->get(['id'=>$row['s_id']],'name');
$row['brand_name'] = $brand['name'];
$row['s_name'] = $serie['name'];
$attr_arr = [$row['v_id'],$row['cor_id'],$row['incor_id']];
$attr = $this->auto_attr_model->get_map_by_ids($attr_arr,'id,title');
$row['v_name'] = isset($attr[$row['v_id']]) ? $attr[$row['v_id']][0]['title']:'';
$row['cor_name'] = isset($attr[$row['cor_id']]) ? $attr[$row['cor_id']][0]['title']:'';
$row['incor_name'] = isset($attr[$row['incor_id']]) ? $attr[$row['incor_id']][0]['title']:'';
//获取选择车辆vin
if($row['item_id']){
$this->load->model('items/items_model', 'mdItems');
$row_goods = $this->mdItems->get(array('id' => $row['item_id']));
$row['vin'] = $row_goods['vin'];
}
//获取贷款信息
if(!$row['payway'] && $row['status']>0){
$auto_finance_row = $this->auto_finance_model->get(['id'=>$row['finance_id']],'fin_id,num');
$finance_row = $this->sys_finance_model->get(['id'=>$auto_finance_row['fin_id']],'title');
$loan = $this->order_loans_model->get(['o_id'=>$row['id']]);
$loan['status'] = intval($loan['status']);
$loan['title'] = $finance_row['title'];
$loan['num'] = $auto_finance_row['num'];
$loan['loan_pay'] = number_format($money_json['price_car']-$money_json['first_pay'],2);
$loan['first_pay'] = number_format($money_json['first_pay'],2);
$loan['notify_file'] = $loan['notify_file'] ? build_qiniu_image_url($loan['notify_file']) : '';
$loan['lend_file'] = $loan['lend_file'] ? build_qiniu_image_url($loan['lend_file']) : '';
$row['loan_info'] = $loan;
}
//获取开票
$bill = $this->order_bills_model->get(['o_id'=>$row['id']],'status,file,cardidA,cardidB');
$bill['file'] = $bill['file'] ? build_qiniu_image_url($bill['file']) : '';
$bill['cardidA'] = $bill['cardidA'] ? build_qiniu_image_url($bill['cardidA']) : '';
$bill['cardidB'] = $bill['cardidB'] ? build_qiniu_image_url($bill['cardidB']) : '';
$bill['status'] = intval($bill['status']);
$row['bill'] = $bill;
//获取合同文件
$contracts = $this->order_contracts_model->select(['o_id'=>$row['id'],'status'=>1],'','','','type,file,status');
$contract_data = [];
if($contracts){
foreach($contracts as $key=>$val){
$contract_data[$val['type']] = [
'type' => $val['type'],
'status_name' => $val['status']?'已签约':'未签约'
];
}
}
$row['contract_data'] = $contract_data;
//获取销售员
if($row['admin_id']){
$this->load->model('app/licheb/app_licheb_users_model', 'licheb_users_model');
$this->load->model("biz/biz_model");
$row_admin = $this->licheb_users_model->get(array('id' => $row['admin_id']));
$biz_id = $row_admin['biz_id'];
$row_biz = array();
if($biz_id){
$row_biz = $this->biz_model->get(array('id' => $biz_id));
}
$admin_name = $row_admin ? "{$row_biz['biz_name']} {$row_admin['uname']}":"";
$row['admin_name'] = $admin_name;
}
//获取代办信息
$agent = $this->order_agents_model->get(['o_id'=>$row['id']]);
$imgs = [];
$car_imgs = [];
if($agent){
$agent['if_ins'] = intval($agent['if_ins']);
$agent['ins_time'] = $agent['ins_time'] != '0000-00-00 00:00:00' ? date('Y-m-d',strtotime($agent['ins_time'])):'';
if($agent['car_img']){
$file_name = substr($agent['car_img'], strrpos($agent['car_img'], '/')+1);
$car_imgs[] = array(
'src' => build_qiniu_image_url($agent['car_img']),
'value' => $agent['car_img'],
'title' => $file_name
);
}
if($agent['ins_img']){
$ins_img = json_decode($agent['ins_img']);
foreach($ins_img as $val){
$file_name = substr($val, strrpos($val, '/')+1);
$imgs[] = [
'src' => build_qiniu_image_url($val),
'value' => $val,
'title' => $file_name
];
}
}
}else{
$agent['if_ins'] = 0;
$agent['car_img_src'] = '';
$agent['car_img'] = '';
}
$row['agent'] = $agent;
$row['bx_imgs'] = $imgs;
$row['car_imgs'] = $car_imgs;
$info = $row;
$this->data['info'] = $info;
$this->data['_title'] = '订单详情';
return $this->show_view('receiver/orders/get', true);
}
//添加单条数据
public function add(){
}
//编辑单条数据
public function edit(){
}
//删除单条数据
public function del(){
}
//批量操作(默认修改状态)
public function batch(){
}
//导出数据列表
public function export(){
}
//修改分期
public function edit_loan(){
$params = $this->input->post();
$file = $_FILES['file'];
$row = $this->order_loans_model->get(['o_id'=>$params['id']]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$update = [];
if($file){ //上传按揭通知函
$path = FCPATH.'temp/';
if (!file_exists($path)){
$oldumask = umask(0);
mkdir($path, 0777, true);
umask($oldumask);
}
$file_name = md5($file['name'] . uniqid()) . '.'.end(explode('.',$file['name']));
$tmp = $path.$file_name;
move_uploaded_file($file['tmp_name'], $tmp);
if (!filesize($tmp)) {
return $this->show_json(SYS_CODE_FAIL, '上传文件失败!');
}
$this->load->library('qiniu');
$res= $this->qiniu->save($file_name, file_get_contents($tmp));
unlink($tmp);
if (!$res) {
return $this->show_json(SYS_CODE_FAIL, '上传文件失败!');
}
$size = getimagesize($res['url']);
if($params['type']){
$update['lend_file'] = $res['file'];
}else{
$update['notify_file'] = $res['file'];
}
$this->data['file_url'] = build_qiniu_image_url($res['file']);
}
strlen($params['status']) && $update['status'] = $params['status'];
$result = $this->order_loans_model->update($update,['id'=>$row['id']]);
if($result && $params['status']==1){ //设置完成按揭
$this->orders_model->update(['status'=>2],['id'=>$row['o_id']]);
$ckcar = $this->order_ckcars_model->get(['o_id'=>$row['o_id']]);
$replace = [
'o_id' => $row['o_id'],
'status' => 0,
'c_time' => time()
];
$ckcar && $replace['id'] = $ckcar['id'];
$this->order_ckcars_model->replace($replace);
}
return $result ? $this->show_json(SYS_CODE_SUCCESS,'保存成功') : $this->show_json(SYS_CODE_FAIL,'保存失败');
}
public function edit_item(){
$this->load->model("items/items_model");
$id = $this->input->post('id');
$item_id = $this->input->post('item_id');
$row = $this->orders_model->get(['id'=>$id]);
$ckcars = $this->order_ckcars_model->get(['o_id'=>$id]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
if(!$item_id) return $this->show_json(SYS_CODE_FAIL, '请选择车辆!');
if($row['status']>=3){
return $this->show_json(SYS_CODE_FAIL, '用户已确,不能修改!');
}
$res = $this->orders_model->update(['item_id'=>$item_id],['id'=>$id]);
if(!$res){
return $this->show_json(SYS_CODE_FAIL,'保存失败');
}
if($row['item_id'] && $row['item_id']!=$item_id){
$this->items_model->update(['status'=>1],['id'=>$row['item_id']]);
}
$this->items_model->update(['status'=>2],['id'=>$item_id]);
if(!$ckcars){
$add_data = [
'o_id' => $id,
'status' => 1,
'c_time' => time()
];
$result = $this->order_ckcars_model->add($add_data);
}else{
$result = $this->order_ckcars_model->update(['status'=>1],['id'=>$ckcars['id']]);
}
if($result){
return $this->show_json(SYS_CODE_SUCCESS,'保存成功');
}else{
return $this->show_json(SYS_CODE_FAIL,'保存失败');
}
}
//查看发票信息
public function get_bill(){
$oid = $this->input->get('oid');
$row = $this->orders_model->get(['id'=>$oid]);
$bill = $this->order_bills_model->get(['o_id'=>$oid]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
if(!$bill){
$add_data = [
'o_id' => $row['id'],
'c_time' => time()
];
$bill['id'] = $this->order_bills_model->add($add_data);
}
$bill['src_file'] = $bill['file'] ? build_qiniu_image_url($bill['file']):'';
$this->data['bill'] = $bill;
return $this->show_view('receiver/orders/get_bill');
}
//编辑发表信息
public function edit_bill(){
$id = $this->input->post('id');
$money = $this->input->post('money');
$file = $this->input->post('file');
$money && $update['money'] = $money;
$file && $update['file'] = $file;
$result = $this->order_bills_model->update($update,['id'=>$id]);
if($result){
//更新开票时间
$row = $this->order_bills_model->get(['id'=>$id]);
$row_order = $this->orders_model->get(array('id' => $row['o_id']));
if($row_order){
$this->load->model('items/items_model');
$upd = array('bill_time' => date('Y-m-d H:i:s'));
$where = array('id' => $row_order['item_id']);
$ret = $this->items_model->update($upd, $where);
}
return $this->show_json(SYS_CODE_SUCCESS,'保存成功');
}else{
return $this->show_json(SYS_CODE_FAIL,'保存失败');
}
}
//确定交款
public function edit_jk(){
$oid = $this->input->post('oid');
$row = $this->orders_model->get(['id'=>$oid]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
if($row['status']!=3){
return $this->show_json(SYS_CODE_FAIL,'修改失败,该订单不处于开票阶段');
}
$bill = $this->order_bills_model->get(['o_id'=>$oid]);
if(!$bill['file'] || !$bill['money']){
return $this->show_json(SYS_CODE_FAIL, '未上传开票文件或未填写到账金额!');
}
if(!$bill['cardidA']){
return $this->show_json(SYS_CODE_FAIL, '未上传用户身份证!');
}
$result = $this->order_bills_model->update(['status'=>1],['o_id'=>$oid]);
$this->orders_model->update(['status'=>4],['id'=>$bill['o_id']]);
if(!$this->order_agents_model->get(['o_id'=>$oid])){
$this->order_agents_model->add(['o_id'=>$oid,'c_time'=>time]);
}
return $this->show_json(SYS_CODE_SUCCESS,'保存成功');
}
//保存代办服务
public function edit_agent(){
$params = $this->input->post();
$row = $this->orders_model->get(['id'=>$params['oid']]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$agent = $this->order_agents_model->get(['o_id'=>$row['id']]);
$update = [];
$params['car_num'] && $update['car_num'] = $params['car_num'];
$params['e_time'] && $update['ins_time'] = date('Y-m-d H:i:s',strtotime($params['e_time']));
$params['car_img'] && $update['car_img'] = $params['car_img'];
$update['if_ins'] = $params['if_ins'] ? 1:0;
if($params['bx_imgs']){
$imgs = explode(',',$params['bx_imgs']);
$update['ins_img'] = json_encode($imgs,JSON_UNESCAPED_UNICODE);
}
if($agent){
$result = $this->order_agents_model->update($update,['id'=>$agent['id']]);
}else{
$update['o_id'] = $row['id'];
$update['c_time'] = time();
$result = $this->order_agents_model->add($update);
}
if($result){
return $this->show_json(SYS_CODE_SUCCESS,'保存成功');
}else{
return $this->show_json(SYS_CODE_FAIL,'保存失败');
}
}
//确定代办
public function edit_agentfh(){
$oid = $this->input->post('oid');
$row = $this->orders_model->get(['id'=>$oid]);
if(!$row){
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
if($row['status']!=4){
return $this->show_json(SYS_CODE_FAIL,'修改失败,该订单不处于代办阶段');
}
$this->order_agents_model->update(['status'=>1],['o_id'=>$oid]);
$this->orders_model->update(['status'=>5],['id'=>$oid]);
if(!$this->order_deliverys_model->count(['o_id'=>$oid])){
$this->order_deliverys_model->add(['o_id'=>$oid,'c_time'=>time]);
}
return $this->show_json(SYS_CODE_SUCCESS,'保存成功');
}
//获取合同图片
public function get_cimgs(){
$type = $this->input->get('type');
$oid = $this->input->get('oid');
$row = $this->order_contracts_model->get(['type'=>$type,'o_id'=>$oid]);
$info['title'] = '相册标题';
$info['id'] = '222';
$info['start'] = 0;
$data = [];
if($row){
$imgs = json_decode($row['imgs'],true);
foreach($imgs as $key => $val){
$data[] = [
'alt' => '图片名',
'pid' => $key,
'src' => build_qiniu_image_url($val),
'thumb' => build_qiniu_image_url($val)
];
}
}
$info['data'] = $data;
$this->data['info'] = $info;
return $this->show_json(SYS_CODE_SUCCESS,'保存成功');
}
//更新金额至json
public function get_update_money(){
$page = $this->input->get('page');
$size = $this->input->get('size');
$lk = $this->input->get('lk');
!$page && $page = 1;
!$size && $size = 10;
$where = [];
if($lk){
$rows = $this->orders_model->select($where,'id desc',$page,$size,'id,money_json');
print_r($rows);exit;
}
$rows = $this->orders_model->select($where,'id desc',$page,$size);
if($rows){
$this->load->model('auto/auto_cars_model');
$this->load->model("biz/biz_model");
$this->load->model('sys/sys_city_model');
foreach($rows as $key => $val){
$car_row = $this->auto_cars_model->get(['brand_id'=>$val['brand_id'],'s_id'=>$val['s_id'],'v_id'=>$val['v_id'],'cor_id'=>$val['cor_id'],'incor_id'=>$val['incor_id']]);
//获取金额json数据
$money_json = [
'price_car' => $car_row['price_car'],
'price_book' => $car_row['price_book'],
'price_insure' => $car_row['price_insure'],
'price_fine' => $car_row['price_fine'],
];
//获取挂牌价
if($val['brand_id']==3){ //狸车品牌写死挂牌费用0.01 测试用
$money_json['fee_carno'] = 0.01;
}else{
$biz = $this->biz_model->get(['id'=>$val['biz_id']],'company_id,city_id');
$city = $this->sys_city_model->get(['city_id'=>$biz['city_id']],'fee_carno');
$money_json['fee_carno'] = $city['fee_carno'];
}
if(!$val['payway']){ //分期
$money_json['price_finance'] = $car_row['price_finance'];
$money_json['first_pay'] = $car_row['first_pay'];
$money_json['month_pay'] = $car_row['month_pay'];
}
$update = [
'money_json' => json_encode($money_json,JSON_UNESCAPED_UNICODE)
];
$this->orders_model->update($update,['id'=>$val['id']]);
}
echo "do f";
}else{
echo "finish";
}
}
}