diff --git a/admin/controllers/Img.php b/admin/controllers/Img.php new file mode 100644 index 00000000..ae257e2e --- /dev/null +++ b/admin/controllers/Img.php @@ -0,0 +1,31 @@ +input->get('imgs'); + $arr_imgs = explode(',',base64_decode($b64_imgs)); + $lists = []; + if($arr_imgs){ + foreach ($arr_imgs as $item) { + $lists[] = [ + 'alt' => '', + 'pid' => '', + 'src' => build_qiniu_image_url($item), + 'thumb' => build_qiniu_image_url($item) + ]; + } + } + $data['lists'] = $lists; + $data['_title'] = '大图'; + return $this->load->view('img', $data); + } + + public function imgs(){ + $data = '/liche/0f48c61017285abc0cff63f59ea5a25f.jpg,/liche/be842659e04f9b5b7bf3f9ab1459c611.jpg'; + echo base64_encode($data); + } +} diff --git a/admin/controllers/Upload.php b/admin/controllers/Upload.php index 35e5f81a..386d4c98 100755 --- a/admin/controllers/Upload.php +++ b/admin/controllers/Upload.php @@ -47,12 +47,14 @@ class Upload extends CI_Controller $types = $this->input->get('type'); $uptype = $this->input->get('uptype'); $source = $this->input->get('source'); + $field = $this->input->get('field'); $data['mode'] = $mode ? $mode : '1'; $data['types'] = $types; $data['uptype'] = $uptype ? $uptype : 'qiniu'; $data['mimes'] = $this->file_mime($data['types']); $data['source'] = $source ? $source : ''; + $data['field'] = $field ? $field : 'file'; $this->load->view('uploadpdf', $data); } @@ -145,4 +147,4 @@ class Upload extends CI_Controller return join(',', array_unique($mime)); } -} \ No newline at end of file +} diff --git a/admin/controllers/auto/Attr.php b/admin/controllers/auto/Attr.php index 915a7ff8..c00a2387 100644 --- a/admin/controllers/auto/Attr.php +++ b/admin/controllers/auto/Attr.php @@ -169,11 +169,11 @@ class Attr extends HD_Controller{ * @return bool */ function json_lists(){ - $s_id = $this->input->post('s_id'); - $status = $this->input->post('status'); - $type = $this->input->post('type'); - $page = $this->input->post('page'); - $size = $this->input->post('size'); + $s_id = $this->input->get_post('s_id'); + $status = $this->input->get_post('status'); + $type = $this->input->get_post('type'); + $page = $this->input->get_post('page'); + $size = $this->input->get_post('size'); $where = array(); $s_id && $where['s_id'] = $s_id; diff --git a/admin/controllers/auto/Business.php b/admin/controllers/auto/Business.php new file mode 100644 index 00000000..dc095a2f --- /dev/null +++ b/admin/controllers/auto/Business.php @@ -0,0 +1,399 @@ +load->model('auto/auto_brand_model'); + $this->load->model('auto/auto_series_model'); + $this->load->model('auto/auto_attr_model'); + $this->load->model('auto/auto_cars_model'); + $this->load->model('auto/auto_business_model'); + } + + public function index() + { + $params = $this->input->get(); + + $where = array(); + if($params['brand_id']){ + $where['brand_id'] = $params['brand_id']; + } else{ + $params['brand_id'] = ''; + } + + if($params['s_id']){ + $where['s_id'] = $params['s_id']; + } else{ + $params['s_id'] = ''; + } + if($params['v_id']){ + $where['v_id'] = $params['v_id']; + } else{ + $params['V_id'] = ''; + } + if(strlen($params['status']) > 0){ + $where['status'] = $params['status']; + } else { + $params['status'] = ''; + } + if($params['city_id']){ + $where['city_id'] = $params['city_id']; + } else{ + $params['city_id'] = ''; + } + if($params['year']){ + $where['year'] = $params['year']; + }elseif(!isset($params['year'])){ + $where['year'] = $params['year'] = date('Y'); + } + if($params['month']){ + $where['month'] = $params['month']; + }elseif(!isset($params['month'])){ + $where['month'] = $params['month'] = intval(date('m')); + } + $page = $params['page']; + $page = !$page ? 1 : $page; + $size = $params['size']; + $size = !$size ? 20 : $size; + + //获取品牌map + $where_brand = array('status > -1' => null); + $map_brand = $this->auto_brand_model->map('id', 'name', $where_brand, 'id desc', 0 , 0, 'id, name'); + //状态 + $statusAry = array('0' => '关闭', '1' => '开启'); + + $total = $this->auto_business_model->count($where); + $lists = array(); + if($total){ + $orderby = 'id desc'; + $select = '*'; + $rows = $this->auto_business_model->select($where, $orderby, $page, $size, $select); + if($rows){ + $s_ids = array_unique(array_column($rows,'s_id')); + $attr_ids = array_unique(array_column($rows,'v_id')); + $city_ids = array_unique(array_column($rows,'city_id')); + //获取车系列表 + $map_sery = array(); + if($s_ids){ + $str_ids = implode(',', $s_ids); + $where_sery = array("id in ({$str_ids})" => null); + $map_sery = $this->auto_series_model->map('id', 'name', $where_sery, 'id desc', 0, 0, 'id,name'); + } + $map_attr = array(); + if($attr_ids){ + $str_ids = implode(',', $attr_ids); + $where_attr = array("id in ({$str_ids})" => null); + $map_attr = $this->auto_attr_model->map('id', 'title', $where_attr, 'id desc', 0 , 0, 'id, title, type'); + } + if($city_ids){ + $str_ids = implode(',', $city_ids); + $where_city = array("city_id in ({$str_ids})" => null); + $map_city = $this->sys_city_model->map('city_id', 'name', $where_city, 'id desc', 0 , 0, 'city_id, name'); + } + //属性按'车型-车身颜色-内饰颜色'排序 + foreach($rows as $v){ + $title = "{$map_brand[$v['brand_id']]} {$map_sery[$v['s_id']]} {$map_attr[$v['v_id']]}"; + $city_cn = $map_city[$v['city_id']]; + $month = date('Y-m',strtotime("{$v['year']}-{$v['month']}")); + $lists[] = array( + 'id' => $v['id'], + 'title' => $title, + 'status' => $v['status'], + 'price_car' => $v['price_car'] > 0 ? $v['price_car'] : '0.00', + 'price_floor' => $v['price_floor'] > 0 ? $v['price_floor'] : '0.00', + 'price_coplus' => $v['price_coplus'] > 0 ? $v['price_coplus'] : '0.00', + 'price_color' => $v['price_color'] > 0 ? $v['price_color'] : '0.00', + 'profix_car' => $v['profix_car'], + 'profix_insure' => $v['profix_insure'], + 'profix_carno' => $v['profix_carno'], + 'profix_loan' => $v['profix_loan'], + 'city_cn'=> $city_cn, + 'month' => $month, + 's_effect_time' => $v['s_effect_time'] ? date('Y-m-d',$v['s_effect_time']) : '', + 'effect_status' => $v['if_effect'] ? '生效中' : '未生效', + ); + } + } + } + + $this->data['params'] = $params; + $this->data['lists'] = $lists; + $this->data['statusAry'] = $statusAry; + $this->data['brandAry'] = $map_brand; + $this->data['cityAry'] = $this->sys_city_model->select(['status'=>1],'id desc',0,0,'city_id,name'); + $this->data['yearAry'] = $this->auto_business_model->year(); + $this->data['monthAry'] = $this->auto_business_model->month(); + $this->data['_title'] = '商务政策管理'; + $this->show_view('auto/business/lists',true); + } + + public function lists() + { + // TODO: Implement lists() method. + } + + public function get() + { + $id = $this->input->get('id'); + $map_brand = $this->auto_brand_model->map('id', 'name', ['status>'=>-1], 'id desc', 0 , 0, 'id, name'); + $city_rows = $this->sys_city_model->select(['status'=>1],'id desc',0,0,'city_id,name'); + $row = $this->auto_business_model->get(['id'=>$id]); + if($id && $row){ + $info = [ + 'id' => $row['id'], + 'city_id' => $row['city_id'], + 'brand_id' => $row['brand_id'], + 's_id' => $row['s_id'], + 'v_id' => $row['v_id'], + 'price_car' => $row['price_car'], + 'price_floor' => $row['price_floor'], + 'price_color' => $row['price_color'], + 'price_coplus' => $row['price_coplus'], + 'profix_car' => $row['profix_car'], + 'profix_carno' => $row['profix_carno'], + 'profix_insure' => $row['profix_insure'], + 'profix_loan' => $row['profix_loan'], + 'delivery_day' => $row['delivery_day'], + 'date' => date('Y-m',strtotime("{$row['year']}-{$row['month']}")), + 'year' => $row['year'], + 'month' => intval($row['month']), + 'colors' => json_decode($row['colors'],true), + 's_effect_time' => $row['s_effect_time'] ? date('Y-m-d',$row['s_effect_time']) : '', + 'action' => 'auto/business/edit', + ]; + if($this->input->get('type')=='copy'){ //复制 + $info['month'] = intval(date('m')); + $info['action'] = 'auto/business/add'; + $info['s_effect_time'] = date('Y-m-d'); + } + }else{ + $info = [ + 'city_id' => '', + 'brand_id' => '', + 's_id' => '', + 'v_id' => '', + 'price_car' => 0.00, + 'price_floor' => 0.00, + 'price_color' => 0.00, + 'price_coplus' => 0.00, + 'profix_car' => 0.00, + 'profix_carno' => 0.00, + 'profix_insure' => 0.00, + 'profix_loan' => 0.00, + 'delivery_day' => 0, + 'action' => 'auto/business/add', + 'year' => date('Y'), + 'month' => intval(date('m')), + 's_effect_time' => date('Y-m-d'), + 'colors' => [] + ]; + } + $this->data['info'] = $info; + $this->data['brandAry'] = $map_brand; + $this->data['city_rows'] = $city_rows; + $this->data['yearAry'] = $this->auto_business_model->year(); + $this->data['monthAry'] = $this->auto_business_model->month(); + $this->data['_title'] = '添加'; + $this->show_view('auto/business/get'); + } + + public function add() + { + $info = $this->input->post('info'); + $res = $this->valid_data($info); + if(!$res['code']){ + return $this->show_json(SYS_CODE_FAIL,$res['msg']); + } + $year = $info['year']; + $month = intval($info['month']); + $where = [ + 'brand_id' => $info['brand_id'], + 's_id' => $info['s_id'], + 'v_id' => $info['v_id'], + 'city_id' => $info['city_id'], + 'year' => $year, + 'month' => $month, + 'status>='=>0 + ]; + if($this->auto_business_model->get($where)){ + return ['code'=>0,'msg'=>'数据已存在']; + } + $data = [ + 'brand_id' => $info['brand_id'], + 's_id' => $info['s_id'], + 'v_id' => $info['v_id'], + 'city_id' => $info['city_id'], + 'year' => $year, + 'month' => $month, + 'status' => 1, + 'c_time' => time() + ]; + $info['price_car'] && $data['price_car'] = $info['price_car']; + $info['price_floor'] && $data['price_floor'] = $info['price_floor']; + $info['price_coplus'] && $data['price_coplus'] = $info['price_coplus']; + $info['price_color'] && $data['price_color'] = $info['price_color']; + $info['profix_car'] && $data['profix_car'] = $info['profix_car']; + $info['profix_carno'] && $data['profix_carno'] = $info['profix_carno']; + $info['profix_insure'] && $data['profix_insure'] = $info['profix_insure']; + $info['profix_loan'] && $data['profix_loan'] = $info['profix_loan']; + $info['colors'] && $data['colors'] = json_encode($info['colors'],JSON_UNESCAPED_UNICODE); + $info['s_effect_time'] && $data['s_effect_time'] = strtotime($info['s_effect_time']); + $info['delivery_day'] && $data['delivery_day'] = $info['delivery_day']; + if(time()>$data['s_effect_time']){ + $data['if_effect'] = 1; + } + $this->auto_business_model->add($data); + return $this->show_json(SYS_CODE_SUCCESS, '添加成功'); + } + + public function edit() + { + $info = $this->input->post('info'); + if(!$this->auto_business_model->get(['id'=>$info['id']])){ + return $this->show_json(SYS_CODE_FAIL,'参数错误'); + } + $res = $this->valid_data($info); + if(!$res['code']){ + return $this->show_json(SYS_CODE_FAIL,$res['msg']); + } + $year = $info['year']; + $month = intval($info['month']); + $where = [ + 'brand_id' => $info['brand_id'], + 's_id' => $info['s_id'], + 'v_id' => $info['v_id'], + 'city_id' => $info['city_id'], + 'year' => $year, + 'month' => $month, + 'status>='=>0, + 'id !=' => $info['id'] + ]; + if($this->auto_business_model->get($where)){ + return ['code'=>0,'msg'=>'数据已存在']; + } + $data = [ + 'city_id' => $info['city_id'], + 'brand_id' => $info['brand_id'], + 's_id' => $info['s_id'], + 'v_id' => $info['v_id'], + 'year' => $year, + 'month' => $month, + ]; + $info['price_car'] && $data['price_car'] = $info['price_car']; + $info['price_floor'] && $data['price_floor'] = $info['price_floor']; + $info['price_coplus'] && $data['price_coplus'] = $info['price_coplus']; + $info['price_color'] && $data['price_color'] = $info['price_color']; + $info['profix_car'] && $data['profix_car'] = $info['profix_car']; + $info['profix_carno'] && $data['profix_carno'] = $info['profix_carno']; + $info['profix_insure'] && $data['profix_insure'] = $info['profix_insure']; + $info['profix_loan'] && $data['profix_loan'] = $info['profix_loan']; + $info['colors'] && $data['colors'] = json_encode($info['colors'],JSON_UNESCAPED_UNICODE); + $info['s_effect_time'] && $data['s_effect_time'] = strtotime($info['s_effect_time']); + $info['delivery_day'] && $data['delivery_day'] = $info['delivery_day']; + if(time()>$data['s_effect_time']){ + $data['if_effect'] = 1; + } + $this->auto_business_model->update($data,['id'=>$info['id']]); + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + + public function del() + { + // TODO: Implement del() method. + } + + public function batch() + { + // TODO: Implement batch() method. + } + + public function export() + { + // TODO: Implement export() method. + } + function edit_status(){ + $id = $this->input->post('id'); + $field = $this->input->post('field'); + $value = $this->input->post('value'); + $status = $this->input->post('status'); + + if('status' == $field){ + $status = $value; + } + + $upd = array('status' => $status); + + if(is_numeric($id)){ + $where = array('id' => $id); + } else { + $where = array("id in ({$id})" => null); + } + + $ret = $this->auto_business_model->update($upd, $where); + if(!$ret){ + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + + function add_copy(){ + $id = $this->input->post('id'); + $row = $this->auto_business_model->get(['id'=>$id]); + if(!$row){ + return $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $year = date('Y'); + $month = date('m'); + $where = [ + 'brand_id' => $row['brand_id'], + 's_id' => $row['s_id'], + 'v_id' => $row['v_id'], + 'city_id' => $row['city_id'], + 'year' => $year, + 'month' => $month, + 'status>='=>0 + ]; + if($this->auto_business_model->get($where)){ + return $this->show_json(SYS_CODE_FAIL, '本月该数据已存在'); + } + $data = [ + 'city_id' => $row['city_id'], + 'brand_id' => $row['brand_id'], + 's_id' => $row['s_id'], + 'v_id' => $row['v_id'], + 'year' => $year, + 'month' => $month, + 'status' => 1, + 'c_time' => time() + ]; + $row['price_car'] && $data['price_car'] = $row['price_car']; + $row['price_floor'] && $data['price_floor'] = $row['price_floor']; + $row['price_coplus'] && $data['price_coplus'] = $row['price_coplus']; + $row['price_color'] && $data['price_color'] = $row['price_color']; + $this->auto_business_model->add($data); + return $this->show_json(SYS_CODE_SUCCESS, '添加成功'); + } + private function valid_data($info){ + if(!$info['brand_id']){ + return ['code'=>0,'msg'=>'请选择品牌']; + } + if(!$info['s_id']){ + return ['code'=>0,'msg'=>'请选择车系']; + } + if(!$info['v_id']){ + return ['code'=>0,'msg'=>'请选择车型']; + } + if(!$info['city_id']){ + return ['code'=>0,'msg'=>'请选择城市']; + } + return ['code'=>1,'msg'=>'验证成功']; + } +} diff --git a/admin/controllers/auto/Cars.php b/admin/controllers/auto/Cars.php index 972eb05d..6c952448 100644 --- a/admin/controllers/auto/Cars.php +++ b/admin/controllers/auto/Cars.php @@ -325,11 +325,11 @@ class Cars extends HD_Controller{ * @return bool */ function json_get(){ - $brand_id = $this->input->post('brand_id'); - $s_id = $this->input->post('s_id'); - $v_id = $this->input->post('v_id'); - $cor_id = $this->input->post('cor_id'); - $incor_id = $this->input->post('incor_id'); + $brand_id = $this->input->get_post('brand_id'); + $s_id = $this->input->get_post('s_id'); + $v_id = $this->input->get_post('v_id'); + $cor_id = $this->input->get_post('cor_id'); + $incor_id = $this->input->get_post('incor_id'); $where = array( 'status' => 1, @@ -339,12 +339,12 @@ class Cars extends HD_Controller{ ); $row = $this->auto_cars_model->get($where); - $data = array( - 'id' => $row['id'], - 'price_car' => $row['price_car'] - ); +// $data = array( +// 'id' => $row['id'], +// 'price_car' => $row['price_car'] +// ); - $this->data = $data; + $this->data = $row; return $this->show_json(SYS_CODE_SUCCESS); } diff --git a/admin/controllers/auto/Series.php b/admin/controllers/auto/Series.php index 5b60bc21..670617ec 100644 --- a/admin/controllers/auto/Series.php +++ b/admin/controllers/auto/Series.php @@ -66,9 +66,9 @@ class Series extends HD_Controller{ * @return bool */ public function json_lists(){ - $brand_id = $this->input->post('brand_id'); - $page = $this->input->post('page'); - $size = $this->input->post('size'); + $brand_id = $this->input->get_post('brand_id'); + $page = $this->input->get_post('page'); + $size = $this->input->get_post('size'); $where = array('status > -1' => null); $brand_id && $where['brand_id'] = $brand_id; diff --git a/admin/controllers/biz/Settle.php b/admin/controllers/biz/Settle.php new file mode 100644 index 00000000..dd218a1a --- /dev/null +++ b/admin/controllers/biz/Settle.php @@ -0,0 +1,443 @@ + ['liche' => 0.25 , 'partner' => 0.75], + 2 => ['liche' => 0.35 , 'partner' => 0.65], + ]; + + public function __construct() + { + parent::__construct(); + $this->load->model('auto/auto_brand_model'); + $this->load->model('auto/auto_series_model'); + $this->load->model('auto/auto_attr_model'); + $this->load->model('auto/auto_business_model'); + + $this->load->model('items/items_model'); + + $this->load->model('biz/biz_model'); + $this->load->model('biz/biz_settle_model'); + $this->load->model('biz/biz_settle_static_model'); + $this->load->model('biz/biz_info_model'); + } + + public function index() + { + $this->lists(); + } + + public function lists() + { + $params = $this->input->get(); + + $where = array(); + $t1 = 'lc_biz_settle'; + $t2 = 'lc_receiver_orders_v2'; + + if($params['biz_id']){ + $where["$t1.biz_id"] = $params['biz_id']; + } else{ + $params['biz_id'] = ''; + } + + if($params['brand_id']){ + $where["$t2.brand_id"] = $params['brand_id']; + } else{ + $params['brand_id'] = ''; + } + + if($params['s_id']){ + $where["$t2.s_id"] = $params['s_id']; + } else{ + $params['s_id'] = ''; + } + if($params['v_id']){ + $where["$t2.v_id"] = $params['v_id']; + } else{ + $params['v_id'] = ''; + } + if($params['year']){ + $where['year'] = $params['year']; + }elseif(!isset($params['year'])){ + $where['year'] = $params['year'] = date('Y'); + } + if($params['month']){ + $where['month'] = $params['month']; + }elseif(!isset($params['month'])){ + $where['month'] = $params['month'] = intval(date('m')); + } + $page = $params['page']; + $page = !$page ? 1 : $page; + $size = $params['size']; + $size = !$size ? 20 : $size; + + //获取品牌map + $where_brand = array('status > -1' => null); + $map_brand = $this->auto_brand_model->map('id', 'name', $where_brand, 'id desc', 0 , 0, 'id, name'); + + $total = $this->biz_settle_model->selectOrders($where, '', '', '',1); + $lists = array(); + if($total){ + $orderby = "$t1.id desc"; + $select = "$t1.*,$t2.sid,$t2.name,$t2.mobile,$t2.s_id,$t2.v_id,$t2.brand_id,$t2.cor_id,$t2.item_id"; + $rows = $this->biz_settle_model->selectOrders($where, $orderby, $page, $size,0, $select); + if($rows){ + $s_ids = array_unique(array_filter(array_column($rows,'s_id'))); + $cor_ids = array_unique(array_filter(array_column($rows,'cor_id'))); + $v_ids = array_unique(array_filter(array_column($rows,'v_id'))); + $attr_ids = array_merge($cor_ids,$v_ids); + $item_ids = array_unique(array_filter(array_column($rows,'item_id'))); + //获取车系列表 + $map_sery = array(); + if($s_ids){ + $str_ids = implode(',', $s_ids); + $where_sery = array("id in ({$str_ids})" => null); + $map_sery = $this->auto_series_model->map('id', 'name', $where_sery, 'id desc', 0, 0, 'id,name'); + } + $map_attr = array(); + if($attr_ids){ + $str_ids = implode(',', $attr_ids); + $where_attr = array("id in ({$str_ids})" => null); + $map_attr = $this->auto_attr_model->map('id', 'title', $where_attr, 'id desc', 0 , 0, 'id, title, type'); + } + $biz_ids = array_unique(array_column($rows,'biz_id')); + $map_biz = []; + if($biz_ids){ + $biz_ids = implode(',',array_filter($biz_ids)); + $where_biz = ["id in ({$biz_ids})" => null]; + $map_biz = $this->biz_model->map('id', 'biz_name', $where_biz, '', 0, 0, 'id,biz_name'); + } + $map_item = []; + if($item_ids){ + $str_item_ids = implode(',',$item_ids); + $where_item = ["id in ({$str_item_ids})" => null]; + $map_item = $this->items_model->map('id', 'vin', $where_item, '', 0, 0, 'id,vin'); + } + foreach($rows as $v){ + $title = "{$map_brand[$v['brand_id']]} {$map_sery[$v['s_id']]} {$map_attr[$v['v_id']]} {$map_attr[$v['cor_id']]}"; + $month = date('Y-m',strtotime("{$v['year']}-{$v['month']}")); + $lists[] = array( + 'id' => $v['id'], + 'o_id' => $v['o_id'], + 'title' => $title, + 'biz_name' => $map_biz[$v['biz_id']], + 'profix_car' => $v['profix_car'], + 'profix_insure' => $v['profix_insure'], + 'profix_carno' => $v['profix_carno'], + 'profix_loan' => $v['profix_loan'], + 'price_trucking' => $v['price_trucking'], + 'name' => $v['name'], + 'mobile' => $v['mobile'], + 'sid' => $v['sid'], + 'month' => $month, + 'vin' => $map_item[$v['item_id']] + ); + } + } + } + + $this->data['params'] = $params; + $this->data['lists'] = $lists; + $this->data['brandAry'] = $map_brand; + $this->data['yearAry'] = $this->auto_business_model->year(); + $this->data['monthAry'] = $this->auto_business_model->month(); + $this->data['pager'] = array('count' => ceil($total / $size), 'curr' => $page,'totle'=>$total); + $this->data['_title'] = '商家结算管理'; + $this->show_view('biz/settle/lists',true); + } + + public function get(){ + } + + public function add(){ + + } + + public function edit() + { + } + + public function del() + { + } + + public function batch() + { + + } + + public function export() + { + $biz_id = $this->input->get('id'); + $month = $this->input->get('month'); + $year = date('Y'); + !$month && $month = intval(date('m')); + $where = [ + 'biz_id' => $biz_id, + 'year' => $year, + 'month' => $month + ]; + $type_arr = $this->biz_settle_static_model->other_price_type(); + $biz = $this->biz_model->get(['id'=>$biz_id],'biz_name'); + $row = $this->biz_settle_static_model->get($where); + $sheet_data = []; + if($row){ + $sheet_data[] = [ + '门店','单车总毛利','税后单车总毛利','水平业务总毛利', + '店面租金','水电费','店长工资','店员工资', + '抽成','拖车费','其它费用','总利润', + '狸车分润','合伙人分润','时间']; + $row['month_str'] = date('Y-m',strtotime("{$row['year']}-{$row['month']}")); + $row['total_need'] = $row['rent'] + $row['wat_ele'] + $row['manager_wage'] + $row['employee_wage'] + $row['commission'] + $row['price_trucking']; + $row['price_ml'] = $row['price_total'] - $row['total_need']; + $other_price = ''; + $other_json = json_decode($row['price_other'],true); + if($other_json){ + foreach($other_json as $key=>$val){ + $type_cn = $type_arr[$val['type']]; + $other_price .= $val['name'].$val['money']."({$type_cn})\n"; + } + } + $sheet_data[] = [ + $biz['biz_name'], + $row['profix_car'], + $row['profix_car_after'], + $row['price_all'], + $row['rent'], + $row['wat_ele'], + $row['manager_wage'], + $row['employee_wage'], + $row['commission'], + $row['price_trucking'], + $other_price, + $row['price_ml'], + $row['profix_liche'], + $row['profix_partner'], + $row['month_str'] + ]; + } + $t1 = 'lc_biz_settle'; + $t2 = 'lc_receiver_orders_v2'; + $where = [ + "{$t1}.biz_id" => $biz_id, + "{$t1}.year" => $year, + "{$t1}.month" => $month + ]; + $orderby = "$t1.id desc"; + $select = "$t1.*,$t2.sid,$t2.name,$t2.mobile,$t2.s_id,$t2.v_id,$t2.brand_id,$t2.cor_id,$t2.item_id"; + $all_rows = $this->biz_settle_model->selectOrders($where, $orderby, 0, 0,0, $select); + $sheet_data2 = []; + if($all_rows){ + $sheet_data2[] = ['门店','订单信息','品牌车型','车架号','单车利润','保险利润','贷款利润','挂牌利润','拖车费','时间']; + $s_ids = array_unique(array_filter(array_column($all_rows,'s_id'))); + $cor_ids = array_unique(array_filter(array_column($all_rows,'cor_id'))); + $v_ids = array_unique(array_filter(array_column($all_rows,'v_id'))); + $attr_ids = array_merge($cor_ids,$v_ids); + $item_ids = array_unique(array_filter(array_column($all_rows,'item_id'))); + //获取车系列表 + $map_sery = array(); + if($s_ids){ + $str_ids = implode(',', $s_ids); + $where_sery = array("id in ({$str_ids})" => null); + $map_sery = $this->auto_series_model->map('id', 'name', $where_sery, 'id desc', 0, 0, 'id,name'); + } + $map_attr = array(); + if($attr_ids){ + $str_ids = implode(',', $attr_ids); + $where_attr = array("id in ({$str_ids})" => null); + $map_attr = $this->auto_attr_model->map('id', 'title', $where_attr, 'id desc', 0 , 0, 'id, title, type'); + } + $map_item = []; + if($item_ids){ + $str_item_ids = implode(',',$item_ids); + $where_item = ["id in ({$str_item_ids})" => null]; + $map_item = $this->items_model->map('id', 'vin', $where_item, '', 0, 0, 'id,vin'); + } + foreach($all_rows as $v){ + $title = "{$map_brand[$v['brand_id']]} {$map_sery[$v['s_id']]} {$map_attr[$v['v_id']]} {$map_attr[$v['cor_id']]}"; + $vin = $map_item[$v['item_id']]; + $month_str = date('Y-m',strtotime("{$v['year']}-{$v['month']}")); + $sheet_data2[] = array( + $biz['biz_name'], + "{$v['name']} {$v['mobile']}", + $title, + $vin, + $v['profix_car'], + $v['profix_insure'], + $v['profix_loan'], + $v['profix_carno'], + $v['price_trucking'], + $month_str, + ); + } + } + $cells = array('A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z'); + $obpe = new PHPExcel(); + if($sheet_data){ + $obpe->setactivesheetindex(0); + foreach($sheet_data as $key=>$val){ + foreach($val as $k2=>$v2){ + $cell = $cells[$k2]; + $k = $key+1; + $obpe->getactivesheet()->setcellvalue("{$cell}{$k}", $v2); + } + } + } + if($sheet_data2){ + //创建一个新的工作空间(sheet) + $obpe->createSheet(); + $obpe->setactivesheetindex(1); + foreach($sheet_data2 as $key=>$val){ + foreach($val as $k2=>$v2){ + $cell = $cells[$k2]; + $k = $key+1; + $obpe->getactivesheet()->setcellvalue("{$cell}{$k}", $v2); + } + } + } + + $filename = $biz['biz_name']."_{$year}年{$month}月_结算表"; + + header("Pragma: public"); + header("Expires: 0"); + header("Cache-Control:must-revalidate, post-check=0, pre-check=0"); + header("Content-Type:application/force-download"); + header("Content-Type:application/vnd.ms-execl"); + header("Content-Type:application/octet-stream"); + header("Content-Type:application/download");; + header('Content-Disposition:attachment;filename='. $filename .'.xlsx'); + header("Content-Transfer-Encoding:binary"); + + $writer = PHPExcel_IOFactory::createWriter($obpe, 'Excel2007'); + $writer->save('php://output'); + } + //统计合计 + public function lists_static(){ + $params = $this->input->get(); + + $where = []; + if($params['year']){ + $where['year'] = $params['year']; + }elseif(!isset($params['year'])){ + $where['year'] = $params['year'] = date('Y'); + } + if($params['month']){ + $where['month'] = $params['month']; + }elseif(!isset($params['month'])){ + $where['month'] = $params['month'] = intval(date('m')); + } + if($params['id']){ + $where['biz_id'] = $params['id']; + } + $page = $params['page']; + $page = !$page ? 1 : $page; + $size = $params['size']; + $size = !$size ? 20 : $size; + + $total = $this->biz_settle_static_model->count($where); + $lists = array(); + if($total){ + $orderby = 'id desc'; + $select = '*'; + $rows = $this->biz_settle_static_model->select($where, $orderby, $page, $size, $select); + if($rows){ + $biz_ids = array_unique(array_column($rows,'biz_id')); + $map_biz = []; + if($biz_ids){ + $biz_ids = implode(',',$biz_ids); + $where_biz = ["id in ({$biz_ids})" => null]; + $map_biz = $this->biz_model->map('id', 'biz_name', $where_biz, '', 0, 0, 'id,biz_name'); + } + //属性按'车型-车身颜色-内饰颜色'排序 + foreach($rows as $v){ + $temp = $v; + $temp['biz_name'] = $map_biz[$v['biz_id']]; + $temp['month_str'] = date('Y-m',strtotime("{$v['year']}-{$v['month']}")); + $temp['price_other'] = $v['price_other'] ? json_decode($v['price_other']) : []; + $temp['total_need'] = $v['rent'] + $v['wat_ele'] + $v['manager_wage'] + $v['employee_wage'] + $v['commission'] + $v['price_trucking']; + $temp['price_ml'] = $v['price_total'] - $temp['total_need']; + $lists[] = $temp; + } + } + } + $this->data['params'] = $params; + $this->data['lists'] = $lists; + $this->data['yearAry'] = $this->auto_business_model->year(); + $this->data['monthAry'] = $this->auto_business_model->month(); + $this->data['type_arr'] = $this->biz_settle_static_model->other_price_type(); + $this->data['pager'] = array('count' => ceil($total / $size), 'curr' => $page,'totle'=>$total); + $this->data['_title'] = '商家结算管理'; + $this->show_view('biz/settle/lists_static',true); + + } + + //重新统计 + public function edit_static(){ + $id = $this->input->post('id'); + $row = $this->biz_settle_static_model->get(['id'=>$id]); + if(!$row){ + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $all_other = 0; //共同承担其它费用 + $liche_other = 0; //狸车承担其它费用 + $partner_other = 0; //合伙人承担其它费用 + $price_other = json_decode($row['price_other'],true); + if($price_other){ + foreach($price_other as $item){ + if($item['type']==2){ + $partner_other += $item['money']; + }elseif($item['type']==1){ + $liche_other += $item['money']; + }else{ + $all_other += $item['money']; + } + } + } + $biz_info = $this->biz_info_model->get(['biz_id'=>$row['biz_id']]); + $type_config = $this->biz_type[$biz_info['type']]; + $price_need = $row['rent'] + $row['wat_ele'] + $row['employee_wage'] + $row['manager_wage'] + $row['commission'] + $row['price_trucking']; + $price_ml = $row['price_total'] - $price_need - $all_other; + $update['profix_liche'] = $price_ml*$type_config['liche']-$liche_other; + $update['profix_partner'] = $price_ml*$type_config['partner']-$partner_other; + $this->biz_settle_static_model->update($update,['id'=>$row['id']]); + + return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); + } + + public function add_price(){ + $id = $this->input->get_post('id'); + $row = $this->biz_settle_static_model->get(['id'=>$id]); + if(!$row){ + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + if($this->input->method()=='post'){ + $lists = $this->input->post('lists'); + if(!is_array($lists)){ + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $price_other = []; + foreach($lists as $key=>$val){ + if($val['money']){ + $price_other[] = [ + 'name' => $val['name'], + 'money' => $val['money'], + 'type' => $val['type'] ? $val['type'] : 0 + ]; + } + } + $up_data['price_other'] = json_encode($price_other,JSON_UNESCAPED_UNICODE); + $this->biz_settle_static_model->update($up_data,['id'=>$id]); + return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); + } + $lists = $row['price_other'] ? json_decode($row['price_other']) : []; + $this->data['id'] = $id; + $this->data['lists'] = $lists; + $this->data['type_arr'] = $this->biz_settle_static_model->other_price_type(); + $this->show_view('biz/settle/add'); + } +} diff --git a/admin/controllers/biz/store/Store.php b/admin/controllers/biz/store/Store.php index 23ae87aa..0fd9fbaf 100755 --- a/admin/controllers/biz/store/Store.php +++ b/admin/controllers/biz/store/Store.php @@ -18,7 +18,10 @@ class Store extends HD_Controller $this->load->helper('image_helper'); $this->load->model("biz/biz_model"); $this->load->model("biz/biz_tagdata_model"); + $this->load->model("biz/biz_info_model"); + $this->load->model("biz/biz_trucking_model"); $this->load->model('app/licheb/app_licheb_users_model', 'mdLichebUsers'); + $this->load->model('auto/auto_brand_model'); $this->load->model("biz/biz_brand_model", 'bizBrand'); $this->load->model('area_model'); @@ -105,6 +108,7 @@ class Store extends HD_Controller $v['brand_name'] = $brand['brand_name']; $v['c_time'] = date('Y-m-d H:i:s', $v['c_time']); $v['type_name'] = $typeAry[$v['type']]; + $v['type'] = $v['type']; $bizlists[] = $v; } @@ -163,6 +167,7 @@ class Store extends HD_Controller if ($id) { $biz = $this->biz_model->get(array('id' => $id, 'status>-1' => null)); + if (!$biz || empty($biz)) { return $this->show_json(SYS_CODE_FAIL, '店铺不存在!'); } @@ -216,7 +221,8 @@ class Store extends HD_Controller 'province_id' => '350', 'type' => 0, 'company_id' => 0, - 'auto_brands' => array() + 'auto_brands' => array(), + 'car_brand_id' => 0 );//默认福建城市 $this->data['biz'] = $biz; } @@ -262,6 +268,11 @@ class Store extends HD_Controller $biz['type'] = intval($this->input->post('type', true)); $biz['company_id'] = intval($this->input->post('company_id', true)); $biz['srv_company_id'] = intval($this->input->post('srv_company_id', true)); + $biz['car_brand_id'] = intval($this->input->post('car_brand_id',true)); + + if ($biz['type']==1 && !$biz['car_brand_id']){ + return $this->show_json(SYS_CODE_FAIL, '请选择车型品牌'); + } $auto_brands = $this->input->post('auto_brands'); if ($auto_brands) { @@ -329,7 +340,11 @@ class Store extends HD_Controller $biz['type'] = intval($this->input->post('type', true)); $biz['company_id'] = intval($this->input->post('company_id', true)); $biz['srv_company_id'] = intval($this->input->post('srv_company_id', true)); + $biz['car_brand_id'] = intval($this->input->post('car_brand_id',true)); + if ($biz['type']==1 && !$biz['car_brand_id']){ + return $this->show_json(SYS_CODE_FAIL, '请选择车型品牌'); + } //上传头像 $biz['headimg'] = $this->input->post('headimg'); @@ -997,5 +1012,96 @@ class Store extends HD_Controller end: return array($status, $data, $msg); } + + public function get_info(){ + $biz_id = $this->input->get('id'); + if(!$this->biz_model->get(['id'=>$biz_id])){ + return $this->show_json(SYS_CODE_FAIL, '店铺不存在!'); + } + $base_info = $this->biz_info_model->get(['biz_id'=>$biz_id]); + if(!$base_info){ + $this->biz_info_model->add(['biz_id'=>$biz_id,'c_time'=>time()]); + $base_info = $this->biz_info_model->get(['biz_id'=>$biz_id]); + } + $info = [ + 'id' => $base_info['id'], + 'biz_id' => $base_info['biz_id'], + 'name' => $base_info['name'], + 'mobile' => $base_info['mobile'], + 'margin' => $base_info['margin'], + 'area' => $base_info['area'], + 'rent' => $base_info['rent'], + 'wat_ele' => $base_info['wat_ele'], + 'employee_wage' => $base_info['employee_wage'], + 'manager_wage' => $base_info['manager_wage'], + 'commission' => $base_info['commission'], + 's_time' => $base_info['s_time'] ? date('Y-m-d',$base_info['s_time']) : '', + 'e_time' => $base_info['e_time'] ? date('Y-m-d',$base_info['e_time']) : '', + 'type' => $base_info['type'], + ]; + $brands = []; + $b_rows = $this->biz_trucking_model->select(['biz_id'=>$base_info['biz_id'],'status'=>1],'','','','auto_b_id,money'); + if($b_rows){ + $auto_b_ids = array_column($b_rows,'auto_b_id'); + $auto_b_ids = $auto_b_ids ? implode(',',$auto_b_ids) : 0; + $where["id in ($auto_b_ids)"] = null; + $auto_rows = $this->auto_brand_model->map('id','name',$where,'','','','id,name'); + foreach($b_rows as $key=>$val){ + $brands[] = [ + 'id' => $val['auto_b_id'], + 'name' => $auto_rows[$val['auto_b_id']], + 'money' => $val['money'] + ]; + } + } + $this->data['type_arr'] = [1=>'扩展',2=>'新增']; + $this->data['brands'] = $brands; + $this->data['info'] = $info; + $this->data['_title'] = '编辑门店基本信息'; + $this->show_view('biz/store/get_info', true); + } + public function edit_info(){ + $info = $this->input->post('info'); + $brands = $this->input->post('brands'); + if(!$this->biz_info_model->get(['id'=>$info['id']])){ + return $this->show_json(SYS_CODE_FAIL, '错数错误!'); + } + $up_data = [ + 'name' => $info['name'], + 'mobile' => $info['mobile'], + 'margin' => $info['margin'], + 'area' => $info['area'], + 'rent' => $info['rent'], + 'wat_ele' => $info['wat_ele'], + 'employee_wage' => $info['employee_wage'], + 'manager_wage' => $info['manager_wage'], + 'commission' => $info['commission'], + 's_time' => $info['s_time'] ? strtotime($info['s_time']) : 0, + 'e_time' => $info['e_time'] ? strtotime($info['e_time']) : 0, + 'type' => $info['type'], + ]; + $this->biz_info_model->update($up_data,['id'=>$info['id']]); + $b_ids = array_column($brands,'id'); + if($b_ids){ + $b_ids = implode(',',$b_ids); + $this->biz_trucking_model->update(['status'=>-1],["auto_b_id not in ({$b_ids})"=>null,'biz_id'=>$info['biz_id']]); + foreach($brands as $key=>$val){ + $s_row = $this->biz_trucking_model->get(['biz_id'=>$info['biz_id'],'auto_b_id'=>$val['id']]); + $data = [ + 'money' => $val['money'], + 'status' => 1 + ]; + if($s_row){ + $this->biz_trucking_model->update($data,['id'=>$s_row['id']]); + }else{ + $data['biz_id'] = $info['biz_id']; + $data['auto_b_id'] = $val['id']; + $data['c_time'] = time(); + $this->biz_trucking_model->add($data); + } + } + } + return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); + } } diff --git a/admin/controllers/receiver/orderv2/Orders.php b/admin/controllers/receiver/orderv2/Orders.php new file mode 100644 index 00000000..abe75840 --- /dev/null +++ b/admin/controllers/receiver/orderv2/Orders.php @@ -0,0 +1,827 @@ +load->model('receiver/order/receiver_orders_v2_model'); + $this->load->model('receiver/order/receiver_order_status_model'); + $this->load->model('receiver/order/receiver_order_datas_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'); + $this->load->model('sys/sys_company_model'); + $this->load->model('app/liche/app_liche_orders_model'); + $this->load->model('app/app_checkdata_model'); + + $this->load->library('receiver/orders_entity'); + $this->load->library('receiver/orders_v2_entity'); + $this->load->library('receiver/orders_status_entity'); + $this->load->library('receiver/order_datas_entity'); + $this->load->library('Ordersv2List'); + $this->load->library('qyrobot'); + } + + public function index() + { + $this->lists(); + } + + public function lists() + { + $params = $this->input->get(); + $statusAry = $this->receiver_order_status_model->statusAry(); + $status_arr = array(); + $t1 = 'lc_receiver_orders_v2'; + $t2 = 'lc_receiver_order_status'; + foreach ($statusAry as $key => $value) { + if (!$value['show']) { + continue; + } + $cate = $where = array(); + $where = ["$t1.status<>" => -1]; + if(is_product()){ + $where["{$t1}.brand_id<>3"] = null;//狸车品牌不显示 + $where["{$t1}.biz_id<>1"] = null;//biz_id=1不显示 + } + if ($value['list']) { + foreach ($value['list'] as $key2 => $value2) { + if($key2){ + $where_s = []; + $key==1 && $where_s["{$t1}.payway"] = 0;//分期 + if($key2){ + $where_s["{$t2}.pid_status"] = $value['pid_status']; + $up_key = $key2+1; + $where_s["{$t2}.status in ({$key2},{$up_key})"] = null; + } + $where_s = array_merge($where,$where_s); + $count2 = $this->receiver_orders_v2_model->selectOrders($where_s,'','', '', 1); + }else{ + $where_s = [ + "id not in (select o_id from lc_receiver_order_status where pid_status={$value['pid_status']} and status=1)" => null + ]; + $key==1 && $where_s['payway'] = 0; + $where_s = array_merge($where,$where_s); + $count2 = $this->receiver_orders_v2_model->count($where_s); + } + $cate[] = array("id" => $key2, "name" => $value2, "count" => $count2); + } + } + $status_arr[] = array("id" => $key, "name" => $value['name'], "cate" => $cate, "count" => 0); + } + $where = ["{$t1}.status<>" => -1]; + if(is_product()){ + $where["{$t1}.brand_id<>"] = 3;//狸车品牌不显示 + $where["{$t1}.biz_id<>"] = 1;//biz_id=1不显示 + } + $params['status_pid'] == 5 && $params['status'] = 1; + $params['count_all'] = $this->receiver_orders_v2_model->count($where);//全部 + $params['list_type'] = 'all'; + $result = $this->ordersv2list->lists($params['status_pid'], $params); + $this->data = $result; + $this->data['status_arr'] = $status_arr; + return $this->show_view($result['view'], true); + } + + public function get() + { + $id = $this->input->get('id'); + + $row = $this->receiver_orders_v2_model->get(['id' => $id]); + $customers = $this->customers_model->get(['id' => $row['customer_id']], 'cf_title'); + if (!$row) { + return $this->show_json(SYS_CODE_FAIL, '订单不存在!'); + } + $money_json = json_decode($row['money_json'], true); + $deposit = $money_json['price_book']; + $jsondata = $row['jsondata'] ? json_decode($row['jsondata'], true) : array(); + $row['price_discount'] = $money_json['price_discount']; + //售价详细信息 + $sale_detail = "指导价:".number_format($money_json['price_car'],2); + $money_json['price_discount'] && $sale_detail .= ',优惠金额:'.number_format($money_json['price_discount'],2); + $money_json['price_color'] && $sale_detail .= ',颜色加价:'.number_format($money_json['price_color'],2); + $money_json['price_coplus'] && $sale_detail .= ',公司加价:'.number_format($money_json['price_coplus'],2); + $row['sale_detail'] = $sale_detail; + $sale_price = $this->orders_v2_entity->total_price($row['id']); + $row['sale_price'] = number_format($sale_price, 2); + $row['info_json'] = json_decode($row['info_json'], true); + $row['status'] = intval($row['status']); + $row['price'] = number_format($money_json['price_car'], 2); + $row['deposit'] = number_format($deposit, 2); + $row['c_time'] = date('Y-m-d', $row['c_time']); + $row['cf_title'] = $customers['cf_title']; + $row['payway'] = intval($row['payway']); + $row['item_id'] = intval($row['item_id']); + $row['cardid'] = $row['info_json']['c_cardid'] ? $row['info_json']['c_cardid'] :''; + $row['address'] = $row['info_json']['c_address'] ? $row['info_json']['c_address'] : ''; + $row['owner_cardid'] = $row['info_json']['c_owner_cardid'] ? $row['info_json']['c_owner_cardid'] : ''; + $row['credit'] = $row['info_json']['c_credit'] ? $row['info_json']['c_credit'] : ''; + $row['company'] = $row['info_json']['c_company'] ? $row['info_json']['c_company'] : ''; + $row['note'] = $jsondata['note'] ? $jsondata['note'] : ''; + //获取车信息 + $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']; + } + $row['delry_time'] = $row['delry_time'] != '0000-00-00 00:00:00' + ? str_replace(" 00:00:00", "", $row['delry_time']) : ''; + //获取车辆服务费 + $srv_info = $this->orders_v2_entity->order_srv_money($row['id'], 2); + $srv_info['total'] = number_format($srv_info['total'], 2); + $srv_detail = ""; + if ($srv_info['list']) { + foreach ($srv_info['list'] as $key => $val) { + $d = $srv_detail ? ',' : ''; + $srv_detail .= $d . $val['title'] . ":" . number_format($val['money'], 2); + } + } + $srv_info['detail'] = $srv_detail; + $row['srv_info'] = $srv_info; + //获取贷款信息 + if (!$row['payway']) { + $loan = $this->order_loans_model->get(['o_id' => $row['id']]); + + $loan['notify_file'] = $loan['notify_file'] ? build_qiniu_image_url($loan['notify_file']) : ''; + $loan['notify_file_name'] = $loan['notify_file'] ? end(explode('/', $loan['notify_file'])) : ''; + $loan['lend_file'] = $loan['lend_file'] ? build_qiniu_image_url($loan['lend_file']) : ''; + $loan['lend_file_name'] = $loan['lend_file'] ? end(explode('/', $loan['lend_file'])) : ''; + + $loan['finance_rows'] = $this->sys_finance_model->select(['status' => 1], '', 0, 0, 'id,title'); + $loan['price_loan'] = $money_json['price_loan'] ? $money_json['price_loan'] : ''; + $loan['first_pay'] = 0; + if ($money_json['price_loan']) { + $loan['first_pay'] = $sale_price - $money_json['price_loan']; + } + !$loan['num'] && $loan['num'] = 12; + $loan['loan_time'] = $loan['loan_time'] != '0000-00-00 00:00:00' ? date('Y-m-d', strtotime($loan['loan_time'])) : ''; + $status_array = $this->receiver_order_status_model->select(['o_id'=>$row['id'],'pid_status'=>1],'','','id,status'); + $loan['status_array'] = array_column($status_array,'status'); + $row['loan_info'] = $loan; + } + //获取审核资料信息 + $img_data = $this->receiver_order_datas_model->get(['o_id'=>$row['id'],'status>='=>0]); + $row['imgs_status'] = $this->order_datas_entity->data_ckinfo($img_data,$row['main_type']); + + //获取开票 + $bill = $this->order_bills_model->get(['o_id' => $row['id']], 'status,file'); + $bill_status = $this->receiver_order_status_model->get(['o_id'=>$row['id'],'pid_status'=>3,'status'=>1]); //是否已开票 + $bill['file'] = $bill['file'] ? build_qiniu_image_url($bill['file']) : ''; + $bill['file_type'] = $bill['file'] && strstr($bill['file'], '.pdf') ? 'pdf' : 'img'; + $bill['cardidA'] = $img_data['cardida']; + $bill['cardidB'] = $img_data['cardidb']; + $bill['business_licence'] = $img_data['business_licence']; + $bill['status'] = $bill_status ? 1 : 0; + $row_goods['company_id'] && $item_company = $this->sys_company_model->get(['id'=>$row_goods['company_id']],'id,short'); + if(!$item_company){ + $item_html = '车辆归属未选择'; + }else{ + $item_html = "车辆公司归属【{$item_company['short']}】"; + } + $pay_order = $this->app_liche_orders_model->get(['type'=>3,'status'=>1,'o_id'=>$row['id']],'mch_id'); + $pay_order && $pay_compay = $this->sys_company_model->get(['wx_mchid' => $pay_order['mch_id']],'id,short'); + $pay_html = ''; + if($pay_compay){ + $ck_html = $pay_compay['id'] == $item_company['id'] ? '一致' : '不一致'; + $pay_html = "与尾款收款公司【{$pay_compay['short']}】 {$ck_html}"; + } + $bill['warning'] = $item_html. $pay_html; + $row['bill'] = $bill; + //获取合同文件 + $contracts = $this->order_contracts_model->select(['o_id' => $row['id'], 'status' => 1], '', '', '', 'id,type,file,status'); + $contract_data = []; + if ($contracts) { + foreach ($contracts as $key => $val) { + $contract_data[$val['type']] = [ + 'type' => $val['type'], + 'status' => $val['status'], +// 'src' => http_host_com('api').'/'.$val['file'], + 'src' => http_host_com('api').'/wxapp/licheb/protocol/pdf_img?id='.$val['id'], + ]; + } + } + $row['contract_data'] = $contract_data; + + //获取销售员 + if ($row['sale_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['sale_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; + } + $info = $row; + $this->data['info'] = $info; + + $this->data['_title'] = '订单详情'; + return $this->show_view('receiver/orderv2/get/index', true); + } + + //添加单条数据 + public function add() + { + } + + //编辑单条数据 + public function edit() + { + $params = $this->input->post(); + if (!$params['id']) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + $result = ''; + if ($params['type'] == 1) {//修改备注 + $re = $this->receiver_orders_v2_model->get(['id' => $params['id']]); + $jsondata = json_decode($re['jsondata'], true); + $jsondata['note'] = $params['note']; + $upd = array('jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)); + $result = $this->receiver_orders_v2_model->update($upd, ['id' => $params['id']]); + } else if ($params['type'] == 2) {//修改营业执照 + if (!$params['business_licence']) { + return $this->show_json(SYS_CODE_FAIL, '请上传营业执照'); + } + if (!$this->order_bills_model->get(['o_id' => $params['id']])) { + $this->order_bills_model->add(['o_id' => $params['id'], 'c_time' => time()]); + } + $result = $this->order_bills_model->update(array('business_licence' => $params['business_licence']), ['o_id' => $params['id']]); + } + if ($result) { + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } else { + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + } + + /** + * 更新身份证信息 + * @return bool + */ + function edit_cardID() + { + $o_id = $this->input->post('o_id'); + $cardidA = $this->input->post('cardidA'); + $cardidB = $this->input->post('cardidB'); + if (!$this->receiver_order_datas_model->get(['o_id' => $o_id])) { + $this->order_bills_model->add(['o_id' => $o_id, 'c_time' => time()]); + } + if (!$cardidA || !$cardidB) { + return $this->show_json(SYS_CODE_FAIL, '请上传身份证照片'); + } + + $this->load->library('TcOrc'); + $cardidA_src = build_qiniu_image_url($cardidA); + $result = $this->tcorc->IdentityCard($cardidA_src); + if (!$result['code']) { + return $this->show_json(SYS_CODE_FAIL, '身份证校验不通过'); + } else { + //校验姓名 + $uname = $result['data']['Name']; + $row_order = $this->receiver_orders_v2_model->get(['id' => $o_id]); + if ($uname != $row_order['name']) { + return $this->show_json(SYS_CODE_FAIL, '身份证姓名与客户不一致'); + } + } + + $upd = array( + 'cardidA' => $cardidA, + 'cardidB' => $cardidB, + 'status' => 1 + ); + $result = $this->order_bills_model->update($upd, ['o_id' => $o_id]); + if ($result) { + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } else { + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + } + + //删除单条数据 + public function del() + { + + } + + //批量操作(默认修改状态) + public function batch() + { + + } + + //导出数据列表 + public function export() + { + $params = $this->input->get(); + $params['page'] = 1; + $params['size'] = 10000; + $indexs = []; + if ($params['export_type']) { + $result = $this->orderslist->export_data($params['status_pid'], $params); + $fileName = '保险明细'; + $data = $result['data']; + $indexs = $result['indexs']; + } else { + $fieldAry = $this->orderslist->get_fields($params['status_pid'], 1); + foreach ($fieldAry as $key => $value) { + $indexs[$key] = $value['title']; + } + $result = $this->orderslist->lists($params['status_pid'], $params); + $fileName = $result['_title']; + foreach ($result['lists'] as $key => $value) { + $temp = array(); + foreach ($fieldAry as $key2 => $value2) { + $temp[$key2] = $value[$key2]; + } + $data[] = $temp; + } + array_unshift($data, $indexs); + } + $this->load->library('excel'); + return $this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis')); + } + + //修改分期 + public function edit_loan() + { + $params = $this->input->post(); + $info = $params['info']; + $oid = $params['id'] ? $params['id'] : $info['id']; + $file = $_FILES['file']; + $row = $this->order_loans_model->get(['o_id' => $oid]); + if (!$row) { + $this->order_loans_model->add(['o_id' => $oid, 'c_time' => time()]); + $row = $this->order_loans_model->get(['o_id' => $oid]); + } + $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, '上传文件失败!'); + } + 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']; + if ($params['status'] == 1) { //等待放款 + $finance_id = $info['finance_id']; + $price_loan = $info['loan_info']['price_loan']; + if (!$row['notify_file']) { + return $this->show_json(SYS_CODE_FAIL, '请先上传按揭通知函!'); + } + if (!$finance_id || !$price_loan) { + return $this->show_json(SYS_CODE_FAIL, '请填写完整信息!'); + } + $order_row = $this->receiver_orders_v2_model->get(['id' => $row['o_id']], 'id,mobile,money_json'); + $money_json = json_decode($order_row['money_json'], true); + $money_json['price_loan'] = $price_loan; + $this->receiver_orders_v2_model->update(['finance_id' => $finance_id, 'money_json' => json_encode($money_json, JSON_UNESCAPED_UNICODE)], ['id' => $row['o_id']]); + //生成购车订单 + $this->load->model('app/liche/app_liche_users_model'); + $userinfo = $this->app_liche_users_model->get(['mobile'=>$order_row['mobile']]); + $this->orders_v2_entity->add_order($order_row['id'],$userinfo['id']); + $result = $this->orders_status_entity->set_status($oid,1,1); + }elseif($params['status'] == 2){ //完成按揭 + $loan_time = $info['loan_info']['loan_time']; + if (!$loan_time) { + return $this->show_json(SYS_CODE_FAIL, '请选择放款时间!'); + } + if (!$row['lend_file']) { + return $this->show_json(SYS_CODE_FAIL, '请先上传按揭放款函!'); + } + $update['loan_time'] = date('Y-m-d H:i:s', strtotime($loan_time)); + $result = $this->orders_status_entity->set_status($oid,1,2); + } + if($update){ + $result = $this->order_loans_model->update($update, ['id' => $row['id']]); + } + 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->receiver_orders_v2_model->get(['id' => $id]); + if (!$row) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); + } + if (!$item_id) return $this->show_json(SYS_CODE_FAIL, '请选择车辆!'); + + if ($this->receiver_order_status_model->get(['o_id'=>$id,'pid_status'=>3,'status'=>1])) { + return $this->show_json(SYS_CODE_FAIL, '已开票,不能修改!'); + } + $res = $this->receiver_orders_v2_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']]); + } + $result = $this->items_model->update(['status' => 2], ['id' => $item_id]); + + if ($result) { + $this->orders_status_entity->set_status($id,2,1); + } + 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->receiver_orders_v2_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']) : ''; + $bill['bill_time'] = $row['bill_time'] != '0000-00-00 00:00:00' ? $row['bill_time'] : ''; + $this->data['bill'] = $bill; + return $this->show_view('receiver/orderv2/get/get_bill'); + } + + //编辑发票信息 + public function edit_bill() + { + $id = $this->input->post('id'); + $file = $this->input->post('value'); + $row_order = $this->receiver_orders_v2_model->get(array('id' => $id)); + if(!$file || !$row_order){ + return $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $row = $this->order_bills_model->get(['o_id' => $row_order['id']]); + if(!$row){ + $this->order_bills_model->add(['c_time'=>time(),'o_id'=>$row_order['id']]); + } + $update['file'] = $file; + $result = $this->order_bills_model->update($update, ['o_id' => $row_order['id']]); + if ($result) { + //更新开票时间 + $this->load->model('items/items_model'); + $bill_time = date('Y-m-d H:i:s'); + $upd = array('bill_time' => $bill_time); + $where = array('id' => $row_order['item_id']); + $ret = $this->items_model->update($upd, $where); + if ($ret) { //添加开票日志 + $this->load->library('entity/items_entity'); + $re_i = $this->items_model->get(['id' => $row_order['item_id']]); + $params = array('item_id' => $row_order['item_id'], 'type' => 3, 'uid' => $this->uid, 'uname' => $this->username + , 'com_time' => $bill_time, 'biz_id' => $re_i['biz_id'], 'addr_id' => $re_i['addr_id']); + $this->items_entity->add_log($params); + } + $this->receiver_orders_v2_model->update(['bill_time' => $bill_time], ['id' => $row_order['id']]); + $this->orders_status_entity->set_status($row_order['id'],3,1); + 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->receiver_orders_v2_model->get(['id' => $oid]); + if (!$row) { + 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, '未上传开票文件或未填写到账金额!'); + } + $where = [ + 'o_id' => $oid, + 'status' => 1, + 'pay_price>' => 0 + ]; + $sum = $this->app_liche_orders_model->sum('total_price', $where); //已收金额 + $need_price = $this->orders_v2_entity->recevable_price($oid); //应收金额 + if ($sum['total_price'] < $need_price) { + return $this->show_json(SYS_CODE_FAIL, '修改失败,已收金额小于应收金额!'); + } + $this->order_bills_model->update(['status' => 2], ['o_id' => $oid]); + $this->orders_status_entity->set_status($oid,3,1); + 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, '保存成功'); + } + + //支付列表 + public function get_paylog() + { + $params = $this->input->get(); + if ($params['d_type'] == 'ajax') { + $page = $params['page'] = $params['page'] ? intval($params['page']) : 1; + $size = $params['size'] = $params['size'] ? intval($params['size']) : 10; + $list = []; + $where = [ + 'o_id' => $params['id'], + 'status' => 1, + 'pay_price>' => 0 + ]; + $count = $this->app_liche_orders_model->count($where); + if ($count) { + $rows = $this->app_liche_orders_model->select($where, 'id desc', $page, $size, 'id,total_price,type,pay_time,mch_id,descrip,status,pid,img,admin_id'); + $type_arr = $this->app_liche_orders_model->get_type_arr(); + foreach ($rows as $item) { + $company = ''; + if ($item['mch_id']) { + $company = $this->sys_company_model->get(['wx_mchid' => $item['mch_id']], 'short'); + } + $opt_name = '用户'; + if($item['admin_id']){ + $admin_user = $this->sys_admin_model->get(array('id' => $item['admin_id']),'username'); + $opt_name = $admin_user['username']; + } + $list[] = [ + 'id'=> $item['id'], + 'money' => $item['total_price'], + 'type_cn' => $type_arr[$item['type']], + 'pay_time' => $item['pay_time'], + 'company' => $company ? $company['short'] : '', + 'opt_name' => $opt_name, + 'descrip' => $item['descrip'], + 'img' => $item['img'] ? build_qiniu_image_url($item['img']) : '', + ]; + } + } + $sum = $this->app_liche_orders_model->sum('total_price', ['o_id'=>$params['id'],'status'=>1,'pay_price>'=>0]); + $this->data['pay_price'] = $sum['total_price']; + $this->data['need_price'] = $this->orders_v2_entity->recevable_price($params['id']); + $this->data['list'] = $list; + $hasNext = ceil($count / $size) > $page ? 1 : 0; + $this->data['commonPage'] = array('page' => $page, 'pageLimit' => $size, 'pageCount' => $count, 'hasNext' => $hasNext); + return $this->show_json(SYS_CODE_SUCCESS, '操作成功'); + } + $this->data['id'] = $this->input->get('id'); + return $this->show_view('receiver/orderv2/get/paylog'); + } + + //添加支付日志 + public function add_paylog() + { + $id = $this->input->get_post('id'); + $row = $this->receiver_orders_v2_model->get(['id' => $id]); + $srv_price = $this->orders_v2_entity->order_srv_money($row['id']); + $need_price = $this->orders_v2_entity->recevable_price($row['id']); + $car_price = $need_price-$srv_price; + if ($this->input->method() == 'post') { + $money = $this->input->post('money'); + $pay_time = $this->input->post('pay_time'); + $wx_mchid = $this->input->post('wx_mchid'); + $descrip = $this->input->post('descrip'); + $type = $this->input->post('type'); + $img = $this->input->post('img'); + if (!$money || !$pay_time || !$row || !$wx_mchid) { + return $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $p_row = $this->app_liche_orders_model->get(['pid'=>0,'o_id'=>$row['id']]); + $last_p_row = $this->app_liche_orders_model->get(['o_id'=>$row['id'],'type'=>3,'pid'=>$p_row['id'],'status>='=>0]); //尾款父订单 + + if($type==6){ //尾款 + if($money>$car_price){ + return $this->show_json(SYS_CODE_FAIL, '车款金额错误'); + } + $this->app_liche_orders_model->update(['status'=>-1],['o_id'=>$row['id'],'status'=>0,'type'=>1]); //定金更新成无效订单 + if(!$this->app_liche_orders_model->count(['pid'=>$last_p_row['id'],'type'=>3,'status'=>1])){ + $this->app_liche_orders_model->update(['status'=>-1],['o_id'=>$row['id'],'type'=>3]); //尾款更新成无效订单 + } + }else{ //服务费 + if($money>$srv_price){ + return $this->show_json(SYS_CODE_FAIL, '服务费金额错误'); + } + $this->app_liche_orders_model->update(['status'=>-1],['o_id'=>$row['id'],'type'=>2,'status'=>0]); //未支付更新成无效订单 + } + $this->load->helper('order'); + $sid = create_order_no(350200, 'liche', 1, $type); + $data = [ + 'o_id' => $row['id'], + 'sid' => $sid, + 'pid' => $p_row['id'], + 'mch_id' => $wx_mchid, + 'admin_id' => $this->uid, + 'brand_id' => $row['brand_id'], + 's_id' => $row['s_id'], + 'v_id' => $row['v_id'], + 'cor_id' => $row['cor_id'], + 'incor_id' => $row['incor_id'], + 'total_price' => $money, + 'pay_price' => $money, + 'type' => $type, + 'status' => 1, + 'pay_time' => date('Y-m-d H:i:s',strtotime($pay_time)), + 'c_time' => time() + ]; + $p_row['uid'] && $data['uid'] = $p_row['uid']; + $p_row['entrust_uid'] && $data['entrust_uid'] = $p_row['entrust_uid']; + $img && $data['img'] = $img; + $descrip && $data['descrip'] = $descrip; + $this->app_liche_orders_model->add($data); + if($this->app_liche_orders_model->count(['status'=>1,'o_id'=>$row['id']])==1 && $money>=100){ //企业微信推送 + $this->qyrobot->deposit_notify_v2($row['id']); + } + $where = [ + 'status'=>1, + 'o_id'=>$row['id'], + 'pid>'=>0 + ]; + $last_p_row && $where['id <>'] = $last_p_row['id']; + $is_pay = $this->app_liche_orders_model->sum('total_price',$where); //已支付金额 + if($need_price && $is_pay['total_price']>=$need_price){ //完成支付 + $last_p_row && $this->app_liche_orders_model->update(['status'=>1],['id'=>$last_p_row['id']]);//完成未支付尾款 + $this->orders_status_entity->set_status($row['id'],0,1); + } + if(!$this->order_contracts_model->count(['o_id'=>$row['id']])){ //生成合同 + $url = http_host_com('api').'/pdfapi/add_pdf?oid='.$row['id']; + $pdf_res = file_get_contents($url); + } + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + } + + $companys = $this->sys_company_model->select(['status' => 1, 'wx_mchid!=' => ''], 'id desc', '', '', 'id,wx_mchid,short'); + $type = []; + $srv_price >0 && $type[] = ['id'=>2,'name'=>'服务费']; + $type[] = ['id'=>6,'name'=>'车款']; + $this->data['type'] = $type; + $this->data['companys'] = $companys; + $this->data['id'] = $this->input->get('id'); + return $this->show_view('receiver/orderv2/get/add_paylog'); + } + //取消配车 + public function edit_ckcar(){ + $this->load->model('items/items_model'); + $id = $this->input->post('id'); + $row = $this->receiver_orders_v2_model->get(['id'=>$id]); + if(!$row || !$row['item_id']){ + return $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + if ($this->receiver_order_status_model->get(['o_id'=>$id,'pid_status'=>3,'status'=>1])) { + return $this->show_json(SYS_CODE_FAIL, '订单已开票,不能修改!'); + } + $res = $this->receiver_orders_v2_model->update(['item_id'=>0],['id'=>$row['id']]); + if($res){ + $this->items_model->update(['status' => 1,'bill_time'=>'0000-00-00 00:00:00'], ['id' => $row['item_id']]); + $this->receiver_order_status_model->delete(['o_id'=>$id,'pid_status'=>2,'status'=>1]); + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + }else{ + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + } + + //修改图片 + public function edit_imgs(){ + $id = $this->input->post('id'); + $field = $this->input->post('filed'); + $value = $this->input->post('value'); + $row = $this->receiver_orders_v2_model->get(['id'=>$id]); + if(!$row){ + return $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $re_data = $this->receiver_order_datas_model->get(['o_id'=>$id]); + if(!$re_data){ + $re_data_id = $this->eceiver_order_datas_model->add(['c_time'=>time(),'o_id'=>$id]); + }else{ + $re_data_id = $re_data['id']; + } + if($field=='ins_img' || $field=='other_img'){ + $val_arr = json_decode($row[$field],true); + $val_arr[] = $value; + $value = json_encode($val_arr,JSON_UNESCAPED_UNICODE); + } + $update = [ + $field => $value + ]; + $res = $this->receiver_order_datas_model->update($update,['id'=>$re_data_id]); + if($res){ + $this->orders_status_entity->set_status($id,6,1); + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + }else{ + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + } + + public function edit_ckimg(){ + $type = $this->input->post('type'); + $ifcheck = $this->input->post('ifcheck'); + $o_id = $this->input->post('id'); + $img_data = $this->receiver_order_datas_model->get(['o_id'=>$o_id]); + if(!$img_data){ + return $this->show_json(SYS_CODE_FAIL, '参数错误'); + } + $ck_row = $this->app_checkdata_model->get(['cf_id'=>$img_data['id'],'app_id'=>2,'type'=>$type]); + if($ck_row){ + $update = [ + 'ifcheck' => $ifcheck ? 1 : -1, + ]; + $res = $this->app_checkdata_model->update($update,['id'=>$ck_row['id']]); + }else{ + $add_data = [ + 'cf_id' => $img_data['id'], + 'app_id' => 2, + 'type' => $type, + 'datatype' => 'img', + 'ifcheck' => $ifcheck ? 1 : -1, + 'c_time' => time() + ]; + $res = $this->app_checkdata_model->add($add_data); + } + if($res){ + $count = $this->app_checkdata_model->count(['ifcheck'=>1,'cf_id'=>$img_data['id'],'datatype'=>'img']); + if($count==5){ + $this->orders_status_entity->set_status($img_data['o_id'],6,2); + } + return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); + }else{ + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } + } + + public function test(){ + $o_id = 10062; + $res = $this->orders_v2_entity->create_pdf($o_id); + print_r($res); + } +} diff --git a/admin/controllers/sys/Company.php b/admin/controllers/sys/Company.php index 0e230b42..345388e1 100644 --- a/admin/controllers/sys/Company.php +++ b/admin/controllers/sys/Company.php @@ -42,13 +42,17 @@ class Company extends HD_Controller{ $size = !$size ? 20 : $size; $statusAry = $this->company_model->status_ary(); + $typeAry = $this->company_model->type_ary(); $count = $this->company_model->count($where); $lists = array(); if($count){ $orderby = 'id desc'; - $select = 'id, title, short, status'; + $select = 'id, title, short, status, city_id,type'; $rows = $this->company_model->select($where, $orderby, $page, $size, $select); + $city_ids = array_column($rows,'city_id') ? implode(',',array_column($rows,'city_id')) : ''; + $city_lists = []; + $city_ids && $city_lists = $this->sys_city_model->map('city_id','name',["city_id in ({$city_ids})"=>null],'','','','city_id,name'); foreach($rows as $k => $v){ $lists[] = array( 'id' => $v['id'], @@ -56,6 +60,8 @@ class Company extends HD_Controller{ 'short' => $v['short'], 'status' => $v['status'], 'status_name' => $statusAry[$v['status']], + 'type_name' => $typeAry[$v['type']], + 'city_name' => $city_lists[$v['city_id']] ? $city_lists[$v['city_id']] : '', ); } } @@ -81,6 +87,8 @@ class Company extends HD_Controller{ 'img_seal' => $row['img_seal'], 'img_seal_url' => $row['img_seal'] ? build_qiniu_image_url($row['img_seal']) : '', 'status' => $row['status'], + 'city_id' => $row['city_id'] ? $row['city_id'] : '', + 'type' => $row['type'] ); $action = '/sys/company/edit'; $title = '编辑公司'; @@ -91,14 +99,19 @@ class Company extends HD_Controller{ 'credit_code' => '', 'wx_mchid' => '', 'status' => 0, + 'city_id' => '', + 'type' => 0 ); $action = '/sys/company/add'; $title = '新增公司'; } + $city_lists = $this->sys_city_model->select(['status'=>1],'id desc','','','city_id,name'); + $this->data['city_lists'] = $city_lists; $this->data['info'] = $info; $this->data['action'] = $action; $this->data['statusAry'] = $this->company_model->status_ary(); + $this->data['typeAry'] = $this->company_model->type_ary(); $this->data['_title'] = $title; $this->show_view('sys/company/get'); } @@ -113,20 +126,25 @@ class Company extends HD_Controller{ if(!$short){ return $this->show_json(SYS_CODE_FAIL, '请输入公司简称'); } - - $where = array("title like '{$title}'" => null); - $count = $this->company_model->count($where); - if($count>0){ - return $this->show_json(SYS_CODE_FAIL, '公司已存在'); + if(!$info['city_id']){ + return $this->show_json(SYS_CODE_FAIL, '请选择城市'); } +// $where = array("title like '{$title}'" => null); +// $count = $this->company_model->count($where); +// if($count>0){ +// return $this->show_json(SYS_CODE_FAIL, '公司已存在'); +// } + $add = array( 'title' => $title, 'short' => $short, 'credit_code' => $info['credit_code'] ? $info['credit_code'] : '', 'wx_mchid' => $info['wx_mchid'] ? $info['wx_mchid'] : '', 'img_seal' => $info['img_seal'] ? $info['img_seal'] : '', - 'status' => intval($info['status']) + 'status' => intval($info['status']), + 'city_id' => $info['city_id'], + 'type' => intval($info['type']) ); $id = $this->company_model->add($add); @@ -148,20 +166,25 @@ class Company extends HD_Controller{ if(!$short){ return $this->show_json(SYS_CODE_FAIL, '请输入公司简称'); } - - $where = array("title like '{$title}'" => null, "id<>{$info['id']}" => null); - $count = $this->company_model->count($where); - if($count>0){ - return $this->show_json(SYS_CODE_FAIL, '公司已存在'); + if(!$info['city_id']){ + return $this->show_json(SYS_CODE_FAIL, '请选择城市'); } +// $where = array("title like '{$title}'" => null, "id<>{$info['id']}" => null); +// $count = $this->company_model->count($where); +// if($count>0){ +// return $this->show_json(SYS_CODE_FAIL, '公司已存在'); +// } + $upd = array( 'title' => $title, 'short' => $short ? $short : '', 'credit_code' => $info['credit_code'] ? $info['credit_code'] : '', 'wx_mchid' => $info['wx_mchid'] ? $info['wx_mchid'] : '', 'img_seal' => $info['img_seal'] ? $info['img_seal'] : '', - 'status' => intval($info['status']) + 'status' => intval($info['status']), + 'city_id' => $info['city_id'], + 'type' => intval($info['type']) ); $ret = $this->company_model->update($upd, array('id' => $info['id'])); diff --git a/admin/libraries/Ordersv2List.php b/admin/libraries/Ordersv2List.php new file mode 100644 index 00000000..f533b445 --- /dev/null +++ b/admin/libraries/Ordersv2List.php @@ -0,0 +1,386 @@ + '客户姓名', 'mobile' => '客户手机号', 'sid' => '订单号'); + private $paywayAry = array(0 => '贷款', 1 => '全款'); + private $t1 = 'lc_receiver_orders_v2'; + private $t2 = 'lc_receiver_order_status'; + + public function __construct() + { + $this->ci = &get_instance(); + $this->ci->load->model('receiver/order/receiver_orders_v2_model', 'mdOrders'); + $this->ci->load->model('receiver/order/receiver_order_status_model'); + $this->ci->load->model('receiver/order/receiver_order_agents_model', 'order_agents_model'); + $this->ci->load->model('app/licheb/app_licheb_users_model', 'mdLichebUsers'); + $this->ci->load->model('receiver/receiver_customers_model', 'mdCustomers'); + $this->ci->load->model('receiver/receiver_clues_cfrom_model', 'mdCluesCfrom'); + $this->ci->load->model("biz/biz_model"); + $this->ci->load->model('auto/auto_series_model'); + $this->ci->load->model('auto/auto_brand_model'); + $this->ci->load->model('auto/auto_attr_model'); + + $this->ci->load->library('receiver/orders_v2_entity'); + $this->ci->load->library('receiver/orders_status_entity'); + } + + public function lists($status_pid, $params = array()) + { +// $result = $show_info = array(); + !$params['qdjl_id'] && $params['qdjl_id'] = ''; + !$params['cf_title'] && $params['cf_title'] = ''; + !$params['cf_clues'] && $params['cf_clues'] = ''; + !strlen($params['payway']) && $params['payway'] = ''; + !$params['biz_type'] && $params['biz_type'] = ''; + $fieldAry = $this->get_fields($status_pid); + $show_info['cfTitleAry'] = $this->ci->mdCustomers->get_sdata('cfrom');//来源类型 + $show_info['cfCluesAry'] = $this->ci->mdCustomers->get_sdata('cfrom_clues');//线下来源 + $show_info['paywayAry'] = $this->paywayAry;//付款方式 + $show_info['bizTypeAry'] = $this->ci->biz_model->type_ary();//门店类型 + //渠道经理 + $show_info['qdjl_lists'] = $this->ci->mdLichebUsers->select(array('group_id' => 4, 'status' => 1, 'biz_id<>' => '0') + , 'id desc', 0, 0, 'id,uname as name'); + $result = $this->orders($params); + $result['show_info'] = $show_info; + $result['fieldAry'] = $fieldAry; + return $result; + } + + /** + * Notes:全部订单 + * Created on: 2021/9/18 15:13 + * Created by: dengbw + * @param array $params + * @return array + */ + private function orders($params = array()) + { + $page = $params['page'] = $params['page'] ? intval($params['page']) : 1; + $size = $params['size'] = $params['size'] ? intval($params['size']) : 20; + $status_arr = $this->ci->receiver_order_status_model->statusAry(); + $order_status_cn = $this->ci->mdOrders->get_status(); + $view_type = 'orders'; + $where = ["{$this->t1}.status>=" => 0]; + $_title = '全部订单'; + $view = 'receiver/orderv2/lists'; + $params['status_pid']==1 && $where["{$this->t1}.payway"] = 0; +// if(strlen($params['status_pid']) && $params['status']){ +// $where["{$this->t2}.pid_status"] = $params['status_pid']; +// $where["{$this->t2}.status"] = $params['status']; +// } + if(is_product()){ + $where["{$this->t1}.biz_id<>"] = 1; + } + if ($_SESSION['admin_info']['biz_id']) { + $biz_ids = implode(',', $_SESSION['admin_info']['biz_id']); + $where["{$this->t1}.biz_id in ($biz_ids)"] = null; + } + if ($params['biz_type']) { + $where["{$this->t1}.biz_id in (select id from lc_biz where type = " . $params['biz_type'] . ' and status=1)'] = null; + } + if ($params['cf_title'] || $params['cf_clues'] || $params['cfrom_id'] || $params['cfrom_id2']) { + $where_c = 'status>=0'; + if ($params['cfrom_id'] == 24) { + $where_c .= ' and cf_id = 24'; + $params['cfrom_id2'] && $where_c .= ' and t_id = ' . $params['cfrom_id2']; + } else { + if ($params['cfrom_id2']) { + $where_c .= ' and cf_id = ' . $params['cfrom_id2']; + } else if ($params['cfrom_id']) { + $cf_rows = $this->ci->mdCluesCfrom->select(['pid' => $params['cfrom_id']], '', '', '', 'id'); + $cf_ids = array_column($cf_rows, 'id'); + $cf_ids[] = $params['cfrom_id']; + $cf_str_ids = implode(',', array_filter($cf_ids)); + $cf_str_ids && $where_c .= " and cf_id in ({$cf_str_ids})"; + } + } + $params['cf_title'] && $where_c .= ' and cf_title = "' . $params['cf_title'] . '"'; + $params['cf_clues'] && $where_c .= ' and cf_clues = "' . $params['cf_clues'] . '"'; + $where["{$this->t1}.customer_id in (select id from lc_receiver_customers where " . $where_c . ')'] = null; + } + if (strlen($params['payway'])) { + $where["{$this->t1}.payway"] = $params['payway']; + } + if ($params['qdjl_id']) {//渠道经理 + $where["{$this->t1}.biz_id in(select biz_id from lc_app_licheb_channel_biz where uid={$params['qdjl_id']})"] = null; + } + if ($params['title']) { + $where["{$this->t1}.{$params['search_tp']} like '%{$params['title']}%'"] = null; + } + //创建时间 + if ($params['c_time']) { + $c_time = explode(' ~ ', $params['c_time']); + if ($c_time[0]) { + $where["{$this->t1}.c_time >="] = strtotime($c_time[0] . ' 00:00:00'); + } + if ($c_time[1]) { + $where["{$this->t1}.c_time <="] = strtotime($c_time[1] . ' 23:59:59'); + } + } + //开票时间 + if ($params['bill_time']) { + $bill_time = explode(' ~ ', $params['bill_time']); + if ($bill_time[0]) { + $where["{$this->t1}.bill_time >="] = $bill_time[0] . ' 00:00:00'; + } + if ($bill_time[1]) { + $where["{$this->t1}.bill_time <="] = $bill_time[1] . ' 23:59:59'; + } + } + if ($params['brand_id']) {//品牌 + $where["{$this->t1}.brand_id"] = $params['brand_id']; + } else { + if(is_product()){ + $where["{$this->t1}.brand_id<>"] = 3;//狸车品牌不显示 + } + $params['brand_id'] = ''; + } + if ($params['s_id']) {//车系 + $where["{$this->t1}.s_id"] = $params['s_id']; + } else { + $params['s_id'] = ''; + } + if ($params['v_id']) {//车型 + $where["{$this->t1}.v_id"] = $params['v_id']; + } else { + $params['v_id'] = ''; + } + if ($params['cor_id']) {//车身颜色 + $where["{$this->t1}.cor_id"] = $params['cor_id']; + } else { + $params['cor_id'] = ''; + } + //销售员筛选 + if ($params['admin_id']) { + $where["{$this->t1}.admin_id"] = $params['admin_id']; + } else { + if ($params['biz_id_admin']) {//指定店铺所有销售员 + $where["{$this->t1}.biz_id"] = $params['biz_id_admin']; + } else { + //指定城市的所有门店 + $where_biz = array(); + if ($params['county_id_admin']) { + $where_biz['county_id'] = $params['county_id_admin']; + } else if ($params['city_id_admin']) { + $where_biz['city_id'] = $params['city_id_admin']; + } + if ($where_biz) { + $where_biz['status>-1'] = null; + $rows_biz = $this->ci->biz_model->select($where_biz, 'id desc', 0, 0, 'id'); + if ($rows_biz) { + $str_ids = implode(',', array_column($rows_biz, 'id')); + $where["{$this->t1}.biz_id in({$str_ids})"] = null; + } else { + $where["{$this->t1}.biz_id"] = -1; + } + } + } + !$params['city_id_admin'] && $params['city_id_admin'] = ''; + !$params['county_id_admin'] && $params['county_id_admin'] = ''; + !$params['biz_id_admin'] && $params['biz_id_admin'] = ''; + $params['admin_id'] = ''; + } + if($params['vin']){ + $where = ["{$this->t1}.status>=" => 0]; + $where["{$this->t1}.item_id in(select id from lc_items where vin like '%{$params['vin']}%')"] = null; + } + $fileds = "{$this->t1}.id,{$this->t1}.name,{$this->t1}.mobile,{$this->t1}.brand_id,{$this->t1}.s_id,{$this->t1}.v_id, + {$this->t1}.cor_id,{$this->t1}.incor_id,{$this->t1}.money_json,{$this->t1}.payway,{$this->t1}.status,{$this->t1}.c_time, + {$this->t1}.biz_id,{$this->t1}.bill_time,{$this->t1}.customer_id,{$this->t1}.owner_name,{$this->t1}.owner_mobile,{$this->t1}.main_type,{$this->t1}.info_json"; + if(strlen($params['status_pid']) && $params['status']){ + $where["{$this->t2}.pid_status"] = $params['status_pid']; + $up_key = $params['status']+1; + $where["{$this->t2}.status in ({$params['status']},{$up_key})"] = null; + $count = $this->ci->mdOrders->selectOrders($where,'', '', '', 1); + $rows = $this->ci->mdOrders->selectOrders($where, "c_time desc", $page, $size, '',$fileds); + }else{ + if(strlen($params['status'])){ + $where["id not in (select o_id from lc_receiver_order_status where pid_status={$params['status_pid']} and status=1)"] = null; + } + $count = $this->ci->mdOrders->count($where); + $rows = $this->ci->mdOrders->select($where, "c_time desc", $page, $size,$fileds); + } + $lists = []; + if ($count) { + //客户来源 + $str_rids = implode(',', array_unique(array_column($rows, 'customer_id'))); + !$str_rids && $str_rids = 0; + $customers = $this->ci->mdCustomers->map('id', '', array("id in({$str_rids})" => null),'','','','id,cf_title,cf_clues,cf_id'); + $cfroms = []; + if($customers){ + foreach($customers as $key=>$val){ + $cf_id_arr[] = $val[0]['cf_id']; + } + //获取来源 + $cfroms = $this->ci->mdCluesCfrom->get_map_by_ids($cf_id_arr, 'id,title'); + } + //门店 + $str_biz_ids = implode(',', array_unique(array_column($rows, 'biz_id'))); + !$str_biz_ids && $str_biz_ids = 0; + $bizs = $this->ci->biz_model->map('id', 'biz_name', array("id in({$str_biz_ids})" => null)); + //品牌车型 + $brand_arr = array_unique(array_column($rows, 'brand_id')); + $brands = $this->ci->auto_brand_model->get_map_by_ids($brand_arr, 'id,name'); + //车系车型 + $series_arr = array_unique(array_column($rows, 's_id')); + $series = $this->ci->auto_series_model->get_map_by_ids($series_arr, 'id,name'); + //获取属性 + $v_arr = array_unique(array_column($rows, 'v_id')); + $cor_arr = array_unique(array_column($rows, 'cor_id')); + $incor_arr = array_unique(array_column($rows, 'incor_id')); + $attr_arr = array_merge($v_arr, $cor_arr, $incor_arr); + $attr = $this->ci->auto_attr_model->get_map_by_ids($attr_arr, 'id,title'); + foreach ($rows as $key => $val) { + $money_json = json_decode($val['money_json'],true); + $info_json = json_decode($val['info_json'],true); + $fields = array(); + $brand_name = isset($brands[$val['brand_id']]) ? $brands[$val['brand_id']][0]['name'] : ''; + $series_name = isset($series[$val['s_id']]) ? $series[$val['s_id']][0]['name'] : ''; + $v_name = isset($attr[$val['v_id']]) ? $attr[$val['v_id']][0]['title'] : ''; + $cor_name = isset($attr[$val['cor_id']]) ? $attr[$val['cor_id']][0]['title'] : ''; + $fields['o_id'] = $val['id']; + $fields['bill_time'] = $val['bill_time']; + $fields['mobile'] = $val['mobile']; + if(Orders_v2_entity::V2_START_ID<$val['id']){ + if($val['main_type']){ + $name = $info_json['c_company']; + $mobile = $val['mobile']; + }else{ + $name = $val['owner_name']; + $mobile = $val['owner_mobile']; + } + $open_url = '/receiver/orderv2/orders/get?id='; + $fields['name'] = $size > 1000 ? $$name + : '' . $name . '
' . $mobile . '
'; + + }else{ + $open_url = '/receiver/orders/get?id='; + $o_tp = '(旧订单)'; + $fields['name'] = $size > 1000 ? $val['name'] + : '' . $val['name']. $o_tp . '
' . $val['mobile'] . '
'; + } + $fields['car_name'] = "{$brand_name}-{$series_name}-{$v_name}-{$cor_name}"; + $fields['price'] = number_format($money_json['price_car'], 2); + $fields['payway_name'] = $this->paywayAry[$val['payway']]; + $fields['incor_name'] = isset($attr[$val['incor_id']]) ? $attr[$val['incor_id']][0]['title'] : ''; + if(strlen($params['status_pid']) && $params['status_pid']!=5){ + $fields['status_name'] = $this->ci->orders_status_entity->last_status_cn($val['id'],$params['status_pid']); + }else{ + $fields['status_name'] = $order_status_cn[$val['status']]; + } + $fields['biz_name'] = $bizs[$val['biz_id']]; + $fields['c_time'] = date('Y-m-d H:i:s', $val['c_time']); + $fields['cf_title'] = $customers[$val['rid']][0]['cf_title']; + $fields['cf_clues'] = $customers[$val['rid']][0]['cf_clues']; + $fields['cf_name'] = $cfroms[$customers[$val['rid']][0]['cf_id']][0]['title']; + $lists[] = $fields; + } + } + $pager = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count); + $_title = $size > 1000 ? $_title : $_title . '列表'; + $view_type != 'orders' && $status_arr = []; + return array('lists' => $lists, 'pager' => $pager, 'params' => $params, 'status_arr' => $status_arr + , 'searchTpAry' => $this->searchTpAry, 'view' => $view, 'view_type' => $view_type, '_title' => $_title); + } + + /** + * Notes:获取字段 + * Created on: 2021/10/29 15:38 + * Created by: dengbw + * @param $status_pid + * @param int $export + * @return array + */ + public function get_fields($status_pid, $export = 0) + { + $fields1 = $fields2 = []; + if ($export) { + $fields1['name'] = ['title' => '客户姓名']; + $fields1['mobile'] = ['title' => '客户电话']; + } else { + $fields1['name'] = ['title' => '客户', 'width' => '14%']; + } + if (strlen($status_pid) && $status_pid == 0) { + $fields2 = ['car_name' => ['title' => '车辆', 'width' => '22%'], + 'biz_name' => ['title' => '门店', 'width' => '10%'], 'price' => ['title' => '合同价', 'width' => '7%'], + 'payway_name' => ['title' => '付款', 'width' => '5%'],'admin_name' => ['title' => '销售员', 'width' => '7%'], + 'cf_title' => ['title' => '来源类型', 'width' => '8%'],'cf_name' => ['title' => '来源','width' => '10%'], + 'status_name' => ['title' => '合同状态', 'width' => '7%'], 'order_time' => ['title' => '下定时间', 'width' => '12%']]; + $fields = array_merge($fields1, $fields2); + } else if ($status_pid == 1) { + $fields2 = ['title' => ['title' => '分期产品', 'width' => '15%'], + 'price_loan' => ['title' => '贷款金额', 'width' => '10%'], 'c_time' => ['title' => '分期时间', 'width' => '7%'], + 'cf_title' => ['title' => '来源类型', 'width' => '10%'], 'cf_name' => ['title' => '来源','width' => '10%'], + 'status_name' => ['title' => '状态', 'width' => '10%']]; + $fields = array_merge($fields1, $fields2); + } else if ($status_pid == 2 || $status_pid == 3 || $status_pid == 4 || $status_pid == 5) { + $fields2 = ['car_name' => ['title' => '车辆', 'width' => '27%'], + 'biz_name' => ['title' => '门店', 'width' => '12%'], 'price' => ['title' => '车辆平台价', 'width' => '9%'], + 'payway_name' => ['title' => '付款方式', 'width' => '8%'], + 'cf_title' => ['title' => '来源类型', 'width' => '9%'], 'cf_name' => ['title' => '来源','width' => '10%'], + 'status_name' => ['title' => '状态', 'width' => '9%']]; + $status_pid==4 && $fields2['u_time'] = ['title'=>'更新时间','width'=>'9%']; + $fields = array_merge($fields1, $fields2); + } else { + $fields2 = ['car_name' => ['title' => '车辆', 'width' => '27%'], + 'biz_name' => ['title' => '门店', 'width' => '12%'], 'price' => ['title' => '车辆平台价', 'width' => '9%'], + 'payway_name' => ['title' => '付款方式', 'width' => '8%'], + 'cf_title' => ['title' => '来源类型', 'width' => '9%'], 'cf_name' => ['title' => '来源','width' => '10%'], + 'status_name' => ['title' => '状态', 'width' => '9%'], + 'c_time' => ['title' => '订单时间', 'width' => '9%']]; + $fields = array_merge($fields1, $fields2); + } + return $fields; + } + /* + * 导出数据 + */ + public function export_data($pid,$params){ + $indexs = [ + 'name' => '客户姓名', + 'mobile' => '手机号', + 'c_time' => '订单时间', + 'bill_time' => '开票时间', + 'if_ins_db' => '是否代办', + 'company' => '保险公司', + 'business_risk' => '商业险金额', + 'ins_risk' => '交强险金额' + ]; + $result = $this->lists($pid, $params); + foreach ($result['lists'] as $key => $value) { + $temp = [ + 'name' => $value['name'], + 'mobile' => $value['mobile'], + 'c_time' => $value['c_time'], + 'if_ins_db' => '', + 'company' => '', + 'business_risk' => '', + 'ins_risk' => '' + ]; + $temp['bill_time'] = $value['bill_time'] != '0000-00-00 00:00:00' ? $value['bill_time'] : ''; + $agent = $this->ci->order_agents_model->get(['o_id' => $value['o_id']],'jsondata'); + if($agent){ + $agent_jsondata = $agent['jsondata'] ? json_decode($agent['jsondata'], true) : ''; + if (isset($agent_jsondata['if_ins_db']) && $agent_jsondata['if_ins_db']) { + $temp['if_ins_db'] = '是'; + isset($agent_jsondata['company']) && $temp['company'] = $agent_jsondata['company']; + isset($agent_jsondata['ins_risk']) && $temp['ins_risk'] = $agent_jsondata['ins_risk']; + isset($agent_jsondata['business_risk']) && $temp['business_risk'] = $agent_jsondata['business_risk']; + }else{ + $temp['if_ins_db'] = '否'; + } + } + $data[] = $temp; + } + array_unshift($data, $indexs); + return ['data'=>$data,'indexs'=>$indexs]; + } + +} + +?> diff --git a/admin/views/auto/business/get.php b/admin/views/auto/business/get.php new file mode 100644 index 00000000..1925492d --- /dev/null +++ b/admin/views/auto/business/get.php @@ -0,0 +1,300 @@ + +
+
+
+ +
+ + + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+ +
+ +
+ + +
+
+ +
+ +
+ + +
+
+ +
+ +
+ + + +
+
+
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+
+
+
+ diff --git a/admin/views/auto/business/lists.php b/admin/views/auto/business/lists.php new file mode 100644 index 00000000..812cf267 --- /dev/null +++ b/admin/views/auto/business/lists.php @@ -0,0 +1,307 @@ + +
+
+ +
+
+
共有条数据
+ + + + + + + + + + + + + + + + + + + + + +
+ + ID + 裸车报价车辆底价单车利润保险利润贷款利润挂牌利润城市时间生效时间是否生效操作
+
+
+
+ +
+ +
+
+
+ +
+
+
+ + diff --git a/admin/views/biz/settle/add.php b/admin/views/biz/settle/add.php new file mode 100644 index 00000000..a3786105 --- /dev/null +++ b/admin/views/biz/settle/add.php @@ -0,0 +1,73 @@ +
+
+ + +
+ +
+
+ 保存 +
+
+
+ diff --git a/admin/views/biz/settle/lists.php b/admin/views/biz/settle/lists.php new file mode 100644 index 00000000..d1f41b90 --- /dev/null +++ b/admin/views/biz/settle/lists.php @@ -0,0 +1,248 @@ +
+
+ +
+
+ + + + + + + + + + + + + + + + + +
+ ID + 门店订单信息单车利润保险利润贷款利润挂牌利润拖车费时间
+
+
+
+ +
+
+
+ + diff --git a/admin/views/biz/settle/lists_static.php b/admin/views/biz/settle/lists_static.php new file mode 100644 index 00000000..896b5c49 --- /dev/null +++ b/admin/views/biz/settle/lists_static.php @@ -0,0 +1,138 @@ +
+
+
+
+ + + + + + + + + + + + + + + + + + + +
+ ID + 门店单车总毛利税后单车总毛利水平业务总毛利门店费用其它费用总利润分润时间操作
+
+
+
+ +
+
+
+ + diff --git a/admin/views/biz/store/edit.php b/admin/views/biz/store/edit.php index 59116743..d1de7c42 100755 --- a/admin/views/biz/store/edit.php +++ b/admin/views/biz/store/edit.php @@ -283,6 +283,18 @@ +
diff --git a/admin/views/biz/store/get_info.php b/admin/views/biz/store/get_info.php new file mode 100644 index 00000000..061c3230 --- /dev/null +++ b/admin/views/biz/store/get_info.php @@ -0,0 +1,307 @@ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+
+ +
+ + +
+
+
+
+ +
+
+ +
+ + + diff --git a/admin/views/biz/store/lists.php b/admin/views/biz/store/lists.php index bdc4c357..5c6ed53a 100755 --- a/admin/views/biz/store/lists.php +++ b/admin/views/biz/store/lists.php @@ -153,6 +153,12 @@ + + 基本信息 + 结算统计 + 概况 + + \ No newline at end of file diff --git a/admin/views/receiver/orderv2/get/add_paylog.php b/admin/views/receiver/orderv2/get/add_paylog.php new file mode 100644 index 00000000..d7b482b3 --- /dev/null +++ b/admin/views/receiver/orderv2/get/add_paylog.php @@ -0,0 +1,77 @@ +
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ + + + +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+
+ + diff --git a/admin/views/receiver/orderv2/get/agentinfo.php b/admin/views/receiver/orderv2/get/agentinfo.php new file mode 100644 index 00000000..7023e262 --- /dev/null +++ b/admin/views/receiver/orderv2/get/agentinfo.php @@ -0,0 +1,175 @@ +
diff --git a/admin/views/receiver/orderv2/get/ckinfo.php b/admin/views/receiver/orderv2/get/ckinfo.php new file mode 100644 index 00000000..3c3c4fec --- /dev/null +++ b/admin/views/receiver/orderv2/get/ckinfo.php @@ -0,0 +1,251 @@ +
+
+ 资料审核 + + +
+
+
+

+ 营业执照: +

+ +
+
+

+ 身份证: + +

+ +
+
+

国补资料:

+ +
+
+
+

+ 保单: + +

+ +
+
+
+
+

+ 交车合照: + +

+ +
+
+
+ diff --git a/admin/views/receiver/orderv2/get/get_bill.php b/admin/views/receiver/orderv2/get/get_bill.php new file mode 100644 index 00000000..a2cae2a2 --- /dev/null +++ b/admin/views/receiver/orderv2/get/get_bill.php @@ -0,0 +1,94 @@ +
+ +
+ +
+ +
+
+ +
+ + +
+
+ +
+ +
+ + +
+
+
+ +
+ +
+ {{info.bill_time}} +
+
+ +
+
+ +
+
+
+ diff --git a/admin/views/receiver/orderv2/get/index.php b/admin/views/receiver/orderv2/get/index.php new file mode 100644 index 00000000..7ec88854 --- /dev/null +++ b/admin/views/receiver/orderv2/get/index.php @@ -0,0 +1,656 @@ + +
+
+ +
+
+ 基本信息 + {{info.sid}} + + +
+
+
+
+ +
+ +
+
+ +
+ +
+ +
+
+
+
+
+ +
+
+ 客户信息 + + +
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ + + +
+
+
+ + + +
+
+ 合同信息 + + +
+
+
+ +
+
+
+ +
+
+ 发票信息 + + +
+
+
+
+ +
+
+ + +
+
+
+
+ + + + +
+
+ diff --git a/admin/views/receiver/orderv2/get/lists.php b/admin/views/receiver/orderv2/get/lists.php new file mode 100644 index 00000000..75f38a11 --- /dev/null +++ b/admin/views/receiver/orderv2/get/lists.php @@ -0,0 +1,612 @@ + + + +
+ + +
+
+ 个订单 +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
客户车辆门店车辆平台价付款方式来源类型来源状态订单时间
+ (线上)
+ (线下) +
+
+
+
+
+
+ +
+
+
+ diff --git a/admin/views/receiver/orderv2/get/loaninfo.php b/admin/views/receiver/orderv2/get/loaninfo.php new file mode 100644 index 00000000..f8fa8dbe --- /dev/null +++ b/admin/views/receiver/orderv2/get/loaninfo.php @@ -0,0 +1,106 @@ +
+
+ 分期明细 + + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+ +
+ + +
+ +
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+
+
+
+ + + + +
+ +
+
+
+
diff --git a/admin/views/receiver/orderv2/get/oinfo.php b/admin/views/receiver/orderv2/get/oinfo.php new file mode 100644 index 00000000..66ad2c8a --- /dev/null +++ b/admin/views/receiver/orderv2/get/oinfo.php @@ -0,0 +1,233 @@ +
+
+ 订单明细 + + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+ +
+ + 保存备注 +
+
+
+
+
+ diff --git a/admin/views/receiver/orderv2/get/paylog.php b/admin/views/receiver/orderv2/get/paylog.php new file mode 100644 index 00000000..2c51999c --- /dev/null +++ b/admin/views/receiver/orderv2/get/paylog.php @@ -0,0 +1,96 @@ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
付款金额类型收款公司操作人备注支付截图付款时间
{{item.money}}{{item.type_cn}}{{item.company}}{{item.opt_name}}{{item.descrip}} + + {{item.pay_time}}
+
+ 第{{page.page}}页(每页{{page.pageLimit}}条,共{{page.pageCount}}条) + +
+
应收总额:{{need_price}},已收总额:{{pay_price}}  
+
+
+ + diff --git a/admin/views/receiver/orderv2/lists.php b/admin/views/receiver/orderv2/lists.php new file mode 100644 index 00000000..163850df --- /dev/null +++ b/admin/views/receiver/orderv2/lists.php @@ -0,0 +1,614 @@ + + + +
+ + +
+
+ 个订单 +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
客户车辆门店车辆平台价付款方式来源类型来源状态订单时间
+ (线上)
+ (线下) +
+
+
+
+
+
+ +
+
+
+ diff --git a/admin/views/sys/company/get.php b/admin/views/sys/company/get.php index 0913755a..688fa36c 100644 --- a/admin/views/sys/company/get.php +++ b/admin/views/sys/company/get.php @@ -28,6 +28,23 @@
+
+ +
+ +
+
+
+ +
+ +
+
@@ -49,12 +66,15 @@ data: { info:{}, statusAry:[], - action:'' + typeAry:[], + action:'', + city_lists:, }, mounted:function(){ var vm = this; vm.info = ; vm.statusAry = ; + vm.typeAry = ; vm.action = ''; }, methods:{ diff --git a/admin/views/sys/company/lists.php b/admin/views/sys/company/lists.php index 7812c0e2..929df639 100644 --- a/admin/views/sys/company/lists.php +++ b/admin/views/sys/company/lists.php @@ -33,6 +33,8 @@ ID 公司名称 公司简称 + 城市 + 公司类型 状态 操作 @@ -42,6 +44,8 @@ {{v.id}} {{v.title}} {{v.short}} + {{v.city_name}} + {{v.type_name}} {{v.status_name}} input->get('oid'); + $this->load->library('receiver/orders_v2_entity'); + if($o_id){ + $res = $this->orders_v2_entity->create_pdf($o_id); + die(json_encode($res,JSON_UNESCAPED_UNICODE)); + } + } } diff --git a/api/controllers/Welcome.php b/api/controllers/Welcome.php index 48a8e25f..e372e8f2 100755 --- a/api/controllers/Welcome.php +++ b/api/controllers/Welcome.php @@ -1,4 +1,6 @@ load->view('welcome_message'); } + public function test(){ + } } diff --git a/api/controllers/plan/Biz.php b/api/controllers/plan/Biz.php new file mode 100644 index 00000000..49a0fbc5 --- /dev/null +++ b/api/controllers/plan/Biz.php @@ -0,0 +1,159 @@ + ['liche' => 0.25 , 'partner' => 0.75], + 2 => ['liche' => 0.35 , 'partner' => 0.65], + ]; + + public function __construct() + { + parent::__construct(); + $this->load->model('receiver/order/receiver_orders_v2_model','orders_model'); + $this->load->model('auto/auto_business_model'); + $this->load->model('biz/biz_model'); + $this->load->model('biz/biz_info_model'); + $this->load->model('biz/biz_settle_model'); + $this->load->model('biz/biz_settle_static_model'); + $this->load->model('biz/biz_trucking_model'); + } + + public function settle(){ + $size = $this->input->get('size'); + !$size && $size = 5; + + $t1 = 'lc_receiver_order_status'; + $t2 = 'lc_receiver_orders_v2'; + $t3 = 'lc_biz_settle'; + $t4 = 'lc_biz'; + + $fields = "$t2.*,$t4.city_id"; + $where = [ + "$t1.pid_status" => 5, + "$t1.status" => 1, + "$t2.status>=" => 0, + "$t3.id is null" => null, + "$t4.type" => 2 + ]; + + $this->db->from("$t1"); + $this->db->join("$t2", "$t2.id=$t1.o_id",'left'); + $this->db->join("$t3", "$t3.o_id=$t1.o_id",'left'); + $this->db->join("$t4", "$t4.id=$t2.biz_id",'left'); + + $this->db->select($fields); + $this->db->where($where); + $this->db->order_by("$t2.id ASC"); + $this->db->limit($size); + $rows = $this->db->get()->result_array(); + if($rows){ + foreach($rows as $key=>$val){ + //获取创建订单当月商务政策 + $b_where = [ + 'city_id ' => $val['city_id'], + 'brand_id' => $val['brand_id'], + 's_id' => $val['s_id'], + 'v_id' => $val['v_id'], + 'status' => 1 + ]; + $b_where['year'] = date('Y',$val['c_time']); + $b_where['month'] = intval(date('m',$val['c_time'])); + $b_row_one = $this->auto_business_model->get($b_where); + //获取开票日期商务政策 + $b_row_two = $b_row_one; + if(date('Y-m',strtotime($val['bill_time']))!=date('Y-m',$val['c_time'])) { + $b_where['year'] = date('Y',strtotime($val['bill_time'])); + $b_where['month'] = intval(date('m',strtotime($val['bill_time']))); + $b_row_two = $this->auto_business_model->get($b_where); + } + $truck_row = $this->biz_trucking_model->get(['auto_b_id'=>$val['brand_id'],'biz_id'=>$val['biz_id'],'status'=>1]); + $price_trucking = $truck_row['money'] ? $truck_row['money'] : 0; + $add_data = [ + 'biz_id' => $val['biz_id'], + 'o_id' => $val['id'], + 'profix_car' => $b_row_one['profix_car'] ? $b_row_one['profix_car'] : 0, + 'profix_insure' => $b_row_two['profix_insure'] ? $b_row_two['profix_insure'] : 0, + 'profix_loan' => $b_row_two['profix_loan'] ? $b_row_two['profix_loan'] : 0, + 'profix_carno' => $b_row_two['profix_carno'] ? $b_row_two['profix_carno'] : 0, + 'price_trucking' => $price_trucking, + 'year' => date('Y'), + 'month' => intval(date('m')), + 'c_time' => time() + ]; + $this->biz_settle_model->add($add_data); + } + }else{ + echo 'finish'; + } + } + + //统计前一个月利润 + public function merage(){ + $size = $this->input->get('size'); + !$size && $size = 5; + + $t1 = 'lc_biz_settle'; + $t2 = 'lc_biz_settle_static'; + + $fields = "$t1.*"; + $where = [ + "$t1.year" => date('Y',strtotime("last month")), + //"$t1.month" => date('m',strtotime('last month')), + "$t1.month" => date('m'), + "$t2.id is null" => null + ]; + + $this->db->from("$t1"); + $this->db->join("$t2", "$t2.biz_id=$t1.biz_id",'left'); + + $this->db->select($fields); + $this->db->where($where); + $this->db->group_by("$t1.biz_id"); + $this->db->limit($size); + $rows = $this->db->get()->result_array(); + if($rows){ + foreach($rows as $key=>$val){ + $where = [ + 'biz_id' => $val['biz_id'], + 'year' => $val['year'], + 'month' => $val['month'] + ]; + if(!$this->biz_settle_static_model->get($where)){ + $biz = $this->biz_model->get(['id'=>$val['biz_id']]); + $biz_info = $this->biz_info_model->get(['biz_id'=>$val['biz_id']]); + $total_car = $this->biz_settle_model->count($where); + $sum_car = $this->biz_settle_model->sum('profix_car',$where); + $sum_insure = $this->biz_settle_model->sum('profix_insure',$where); + $sum_loan = $this->biz_settle_model->sum('profix_loan',$where); + $sum_carno = $this->biz_settle_model->sum('profix_carno',$where); + $price_all = $sum_insn['profix_insure']+$sum_loan['profix_loan']+$sum_carno['profix_carno']; + $sum_trucking = $this->biz_settle_model->sum('price_trucking',$where); + $data = [ + 'biz_id' => $val['biz_id'], + 'profix_car' => $sum_car['profix_car'], + 'profix_car_after' => sprintf("%.2f",$sum_car['profix_car']/1.13), + 'price_all' => $price_all, + 'price_trucking' => $sum_trucking['price_trucking'], + 'rent' => $biz_info['rent'], + 'wat_ele' => $biz_info['wat_ele'], + 'employee_wage' => $biz_info['employee_wage'], + 'manager_wage' => $biz_info['manager_wage'], + 'commission' => $biz_info['commission'] * $total_car, + 'year' => $val['year'], + 'month' => $val['month'], + 'c_time' => time() + ]; + $data['price_total'] = $data['price_all']+$data['profix_car_after']; + $type_config = $this->biz_type[$biz_info['type']]; + $price_need = $data['price_total'] - $data['rent'] - $data['wat_ele'] - $data['employee_wage'] - $data['manager_wage'] - $data['commission'] - $data['price_trucking']; + $data['profix_liche'] = $price_need*$type_config['liche']; + $data['profix_partner'] = $price_need*$type_config['partner']; + $this->biz_settle_static_model->add($data); + } + } + }else{ + echo 'finish'; + } + } +} diff --git a/api/controllers/plan/Liche.php b/api/controllers/plan/Liche.php new file mode 100644 index 00000000..b7ccd32d --- /dev/null +++ b/api/controllers/plan/Liche.php @@ -0,0 +1,73 @@ +load->model('receiver/order/receiver_order_contracts_model'); + $this->load->model('receiver/order/receiver_orders_v2_model'); + + $this->load->library('receiver/orders_v2_entity'); + } + + //获取未签名pdf + public function un_sign_pdf(){ + $row = $this->receiver_order_contracts_model->get(['o_id>='=>Orders_v2_entity::V2_START_ID,'flag'=>0,'file !='=>'','status'=>1]); + $receiver = $this->receiver_orders_v2_model->get(['id' => $row['o_id']]); + if(file_exists(FCPATH.$row['file']) && $receiver){ + $companys = $this->orders_v2_entity->get_biz_mchid($receiver['biz_id']); + $url = http_host_com(); + $width = 130; + $s_img = build_qiniu_image_url($companys['company']['img_seal']); + if($row['type']==1){ + $page = 2; + $height = 380; + $s_img = build_qiniu_image_url($companys['srv_company']['img_seal']); + }elseif ($row['type']==3){ + $page = 1; + $height = 620; + } else{ + $page = 3; + $height = 160; + } + $data = [ + 'id' => $row['id'], + 'o_id' => $row['o_id'], + 's_page' => $page, + 'width' => $width, + 'height' => $height, + 's_img' => $s_img, + 'file_url' => $url.'/'.$row['file'] + ]; + die(json_encode($data,JSON_UNESCAPED_UNICODE)); + }else{ + $this->receiver_order_contracts_model->update(['flag'=>1],['id'=>$row['id']]); + } + } + + //覆盖pdf文件 + public function up_pdf(){ + $id = $this->input->post('id'); + $row = $this->receiver_order_contracts_model->get(['id'=>$id,'flag'=>0]); + if($row){ + $file_path_arr = explode('/',$row['file']); +// $file_name = array_pop($file_path_arr); +// $file_name = 'test.pdf'; +// $file_path = implode('/',$file_path_arr); +// $res = move_uploaded_file($_FILES['file']['tmp_name'],FCPATH.$file_path.'/'.$file_name); + move_uploaded_file($_FILES['file']['tmp_name'],FCPATH.$row['file']); + $res = $this->receiver_order_contracts_model->update(['flag'=>1],['id'=>$row['id']]); + if($res){ + $data = [ + 'code' => 1, + 'msg' => '保存成功' + ]; + die(json_encode($data,JSON_UNESCAPED_UNICODE)); + } + } + } +} \ No newline at end of file diff --git a/api/controllers/plan/Order.php b/api/controllers/plan/Order.php new file mode 100644 index 00000000..0b868ca4 --- /dev/null +++ b/api/controllers/plan/Order.php @@ -0,0 +1,101 @@ +load->model('receiver/order/receiver_orders_model'); + $this->load->model('receiver/order/receiver_orders_v2_model'); + } + + public function index(){ + $size = $this->input->get('size'); + !$size && $size = 5; + + $t1 = 'lc_receiver_orders'; + $t2 = 'lc_receiver_orders_v2'; + + $fields = "$t1.*"; + $where = [ + "$t1.status>=" => 0, + "$t2.id is null" => null + ]; + + $this->db->from("$t1"); + $this->db->join("$t2", "$t2.id=$t1.id",'left'); + + $this->db->select($fields); + $this->db->where($where); + $this->db->order_by("$t1.id asc"); + $this->db->limit($size); + $rows = $this->db->get()->result_array(); + if($rows){ + foreach($rows as $key=>$val){ + echo "执行old_id:{$val['id']}
"; + if($val['status']==7){ + $status = 2; + }elseif($val['status']==6){ + $status = 1; + }else{ + $status = 0; + } + $money_json = json_decode($val['money_json'],true); + !$money_json['price_book'] && $money_json['price_book'] = $val['deposit']; + $data = [ + 'id' => $val['id'], + 'sid' => $val['sid'], + 'clue_id' => $val['clue_id'], + 'customer_id' => $val['rid'], + 'name' => $val['name'], + 'mobile' => $val['mobile'], + 'main_type' => $val['main_type'], + 'payway' => $val['payway'], + 'finance_id' => $val['finance_id'], + 'srv_ids' => $val['srv_ids'], + 'fines' => $val['fine_ids'], + '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'], + 'item_id' => $val['item_id'], + 'biz_id' => $val['biz_id'], + 'sale_id' => $val['admin_id'], + 'info_json' => $val['info_json'], + 'car_json' => $val['car_json'], + 'money_json' => $val['money_json'], + 'jsondata' => $val['jsondata'], + 'delry_time' => $val['delry_time'], + 'order_time' => $val['order_time'], + 'bill_time' => $val['bill_time'], + 'c_time' => $val['c_time'], + 'u_time' => $val['u_time'], + 'status' => $status + ]; + $res = $this->receiver_orders_v2_model->add($data); + if($res){ + echo "执行成功:{$val['id']}
"; + }else{ + echo "执行失败:{$val['id']}
"; + } + } + + $where = [ + "$t1.status>=" => 0, + "$t2.id is null" => null + ]; + + $this->db->from("$t1"); + $this->db->join("$t2", "$t2.id=$t1.id",'left'); + + $this->db->select($fields); + $this->db->where($where); + $res = $this->db->count_all_results(); + echo "剩余:{$res}
"; + } + } + +} diff --git a/api/controllers/plan/Plan.php b/api/controllers/plan/Plan.php index ced06a9d..9162fbbf 100644 --- a/api/controllers/plan/Plan.php +++ b/api/controllers/plan/Plan.php @@ -33,7 +33,8 @@ class Plan extends CI_Controller $plan[] = array('url' => base_url(array('plan', 'licheb', 'customer_level')), 'interval' => 1);//更新客户等级 $plan[] = array('url' => base_url(array('plan', 'licheb', 'visit_sales_sms')), 'interval' => 1);//给销售发送待回访短信 $plan[] = array('url' => base_url(array('plan', 'licheb', 'customer_manager_sms')), 'interval' => 1);//给店长发送待分配短信 - $plan[] = array('url' => base_url(array('plan', 'licheb', 'inventory_log')), 'interval' => 5);//更新车辆调拨状态 + + $plan[] = array('url' => base_url(array('plan', 'biz', 'settle')), 'interval' => 1); $this->plan = $plan; } diff --git a/api/controllers/wxapp/Wxapp.php b/api/controllers/wxapp/Wxapp.php index 4ff75e30..9ab520f0 100644 --- a/api/controllers/wxapp/Wxapp.php +++ b/api/controllers/wxapp/Wxapp.php @@ -521,4 +521,9 @@ abstract class Wxapp extends HD_Controller{ } return $h5_host; } + + //获取当前门店id + protected function get_biz_id(){ + return $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); + } } diff --git a/api/controllers/wxapp/app/Business.php b/api/controllers/wxapp/app/Business.php new file mode 100644 index 00000000..626850fe --- /dev/null +++ b/api/controllers/wxapp/app/Business.php @@ -0,0 +1,79 @@ +login_white = array();//登录白名单 + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg =array();//授权微信信息 + $this->load->model('auto/auto_cars_model'); + $this->load->model('auto/auto_business_model'); + $this->load->model("biz/biz_model"); + } + + protected function get(){ + $biz_id = $this->get_biz_id(); + $s_id = $this->input_param('car_id'); + $v_id = $this->input_param('v_id'); + $color_id = $this->input_param('color_id'); + $main_type = $this->input_param('main_type'); + $biz = $this->biz_model->get(['id'=>$biz_id],'city_id'); + $city_id = $biz['city_id']; + $where = [ + 's_id'=>$s_id, + 'v_id'=>$v_id, + 'status'=>1, + 'if_effect'=>1, + 'city_id'=>$city_id, + 'year' => date('Y'), + 'month' => intval(date('m')) + ]; + $row = $this->auto_business_model->get($where); + if(!$row){ + throw new Exception('当前地区不支持销售该车型', API_CODE_FAIL); + } + $car['price_car'] = $row['price_car']; + $car['price_floor'] = $row['price_floor']; + $dis_money = $car['price_car'] - $car['price_floor']; + + $where_car = array( + 's_id'=>$s_id, + 'v_id' => $v_id, + ); + $v_id!=113 && $where_car['status'] = 1;//哪吒 U 2021款Pro400巡航版 不判断状态 + $c_row = $this->auto_cars_model->get($where_car,'',$city_id); + $dis_fine_money = $c_row['price_fine_floor']>0 && $c_row['price_fine']-$c_row['price_fine_floor']>0 ? $c_row['price_fine']-$c_row['price_fine_floor'] : 0; + + $dis_money_list = [500,1000,2000]; + $dis_fine_money_list = [500,1000,1500]; + $deposit_list = [2000,3000,5000]; + $color_arr = json_decode($row['colors'],true); + $price_color = in_array($color_id,$color_arr) ? $row['price_color'] : 0; + $price_coplus = $main_type ? $row['price_coplus'] : 0; + + $data = [ + 'id' => $row['id'], + 'price' => $car['price_car'] ? floatval($car['price_car']) : 0, + 'dis_money' => $dis_money, + 'dis_money_list' => $dis_money_list, + 'fine_money' => floatval($car['price_fine']), + 'dis_fine_money' => $dis_fine_money, + 'dis_fine_money_list' => $dis_fine_money_list, + 'deposit_list' => $deposit_list, + 'price_color' => floatval($price_color), + 'price_coplus' => floatval($price_coplus) + ]; + return $data; + + } +} diff --git a/api/controllers/wxapp/app/Series.php b/api/controllers/wxapp/app/Series.php index 6ee9bdbb..ab42c0d3 100644 --- a/api/controllers/wxapp/app/Series.php +++ b/api/controllers/wxapp/app/Series.php @@ -62,6 +62,7 @@ class Series extends Wxapp{ $auto_brands = $jsondata['auto_brands'] ? $jsondata['auto_brands'] : [0]; $str_brands = implode(',',$auto_brands); + !$str_brands && $str_brands = 0; $where["id in ($str_brands)"] = null; } $count = $this->auto_brand_model->count($where); @@ -100,7 +101,6 @@ class Series extends Wxapp{ if($rows){ $first = []; $brand_arr = array_unique(array_column($rows,'brand_id')); - $brands = []; $brand_ids = implode(',',$brand_arr); if($brand_ids){ $where = [ @@ -130,8 +130,6 @@ class Series extends Wxapp{ $type = $this->input_param('type'); $page = $this->input_param('page'); $size = $this->input_param('size'); - $v_id = $this->input_param('v_id'); - $cor_id = $this->input_param('color_id'); !$page && $page = 0; !$size && $size = 0; @@ -209,13 +207,20 @@ class Series extends Wxapp{ throw new Exception('当前车型暂无库存', ERR_PARAMS_ERROR); } $dis_fine_money = $car['price_fine_floor']>0 && $car['price_fine']-$car['price_fine_floor']>0 ? $car['price_fine']-$car['price_fine_floor'] : 0; + $dis_fine_money_list = [500,1000,1500]; + $dis_money = $car['price_car'] - $car['price_floor']; + $dis_money_list = [500,1000,2000]; $data = [ 'price' => $car['price_car'] ? floatval($car['price_car']) : 0, 'deposit' => $car['price_book'] ? floatval($car['price_book']) : 0, - 'dis_money' => $car['price_car'] - $car['price_floor'], + 'dis_money' => $dis_money, + 'dis_money_list' => $dis_money_list, 'fine_money' => floatval($car['price_fine']), 'dis_fine_money' => $dis_fine_money, + 'dis_fine_money_list' => $dis_fine_money_list, + 'deposit_list' => [2000,3000,5000], ]; return $data; } + } diff --git a/api/controllers/wxapp/liche/Order.php b/api/controllers/wxapp/liche/Order.php index 0bfe8234..cfebd2f5 100644 --- a/api/controllers/wxapp/liche/Order.php +++ b/api/controllers/wxapp/liche/Order.php @@ -22,12 +22,17 @@ class Order extends Wxapp{ $this->uid = $this->session['uid']; $this->load->model('apporder/order_purchase_model'); $this->load->model('receiver/order/receiver_orders_model'); + $this->load->model('receiver/order/receiver_orders_v2_model'); + $this->load->model('receiver/order/receiver_order_contracts_model'); + $this->load->model('receiver/order/receiver_order_status_model'); + $this->load->model('receiver/order/receiver_order_deliverys_model','order_deliverys_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('app/liche/app_liche_orders_model'); + $this->load->library('receiver/orders_v2_entity'); } /** @@ -132,7 +137,7 @@ class Order extends Wxapp{ $oid && $where['o_id'] = $oid; $total = $this->app_liche_orders_model->count($where); if($total){ - $fileds = 'id,o_id,sid,brand_id,s_id,v_id,cor_id,incor_id'; + $fileds = 'id,o_id,sid,brand_id,s_id,v_id,cor_id,incor_id,c_time'; $rows = $this->app_liche_orders_model->select($where,'id desc',$page,$size,$fileds); //品牌车型 $brand_arr = array_unique(array_column($rows,'brand_id')); @@ -148,9 +153,19 @@ class Order extends Wxapp{ $attrs = $this->auto_attr_model->get_map_by_ids($attr_id_arr,'id,title,jsondata'); $type_arr = $this->app_liche_orders_model->get_type_arr(); + $contract_type_arr = $this->receiver_order_contracts_model->get_types(1); foreach($rows as $key=>$val){ - $order = $this->receiver_orders_model->get(['id'=>$val['o_id']],'payway,price,brand_id,s_id,v_id,cor_id,money_json'); - $money_json = json_decode($order['money_json'],true); + $owner_name = ''; + if($val['o_id']>=Orders_v2_entity::V2_START_ID){ + $order = $this->receiver_orders_v2_model->get(['id'=>$val['o_id']],'owner_name,main_type,id,payway,brand_id,s_id,sid,v_id,cor_id,money_json,info_json'); + $info_json = json_decode($order['info_json'],true); + $owner_name = $order['main_type'] ? $info_json['c_company'] : $order['owner_name']; + $total_price = $this->orders_v2_entity->total_price($order['id']); + }else{ + $order = $this->receiver_orders_model->get(['id'=>$val['o_id']],'id,payway,price,brand_id,s_id,sid,v_id,cor_id,money_json'); + $money_json = json_decode($order['money_json'],true); + $total_price = $money_json['price_discount'] ? $money_json['price_car'] - $money_json['price_discount'] : $money_json['price_car']; + } $select_car = false; if($order['brand_id'] && $order['s_id'] && $order['cor_id']){ $select_car = true; @@ -182,29 +197,64 @@ class Order extends Wxapp{ if($v['type']==3){ $last_orders = []; $last_rows = $this->app_liche_orders_model->select(['pid'=>$v['id'],'status'=>1],'id asc',0,0,'total_price,pay_time'); + $pay_price = 0; //已支付金额 foreach($last_rows as $v2){ + $pay_price += $v2['total_price']; $last_orders[] = [ 'price' => $v2['total_price'], 'pay_time' => $v2['pay_time'], - 'pay_cn' => $v2['total_price'] == $v['total_price'] ? '全部支付' : '部分支付' + 'pay_cn' => '支付' ]; } - $is_pay = $this->app_liche_orders_model->sum('total_price',['status'=>1,'uid'=>$uid,'pid'=>$v['id']]); //已支付金额 - $setValue['no_pay_price'] = $v['total_price'] - $is_pay['total_price']; + $setValue['no_pay_price'] = $v['total_price'] - $pay_price; $setValue['sub_order'] = $last_orders; } $sub_order[] = $setValue; } } + $agree = $this->receiver_order_contracts_model->count(['o_id'=>$val['o_id'],'status'=>1]) ? true : false; + $contract_list = []; + if($agree){ + $contracts = $this->receiver_order_contracts_model->select(['o_id'=>$val['o_id'],'status'=>1],'','','','id,type,file'); + foreach ($contracts as $item) { + $contract_list[] = [ + 'title' => $contract_type_arr[$item['type']], + 'url' => http_host_com('api').'/wxapp/licheb/protocol/pdf_img?id='.$item['id'] + ]; + } + } + $ckcar_status = false; + $agent_ck = $this->receiver_order_status_model->count(['o_id'=>$val['o_id'],'status'=>1,'pid_status'=>4]); + $user_ck = $this->receiver_order_status_model->count(['o_id'=>$val['o_id'],'status'=>2,'pid_status'=>4]); + if($agent_ck && !$user_ck){ + $ckcar_status = true; + } + //获取随车信息 + $delivery = $this->order_deliverys_model->get(['o_id'=>$val['o_id']],'status,info,tool,remark'); + $ckcar_data = [ + 'info' => $delivery['info'] ? explode(',',$delivery['info']) : [], + 'tool' => $delivery['tool'] ? explode(',',$delivery['tool']) : [], + 'remark' => $delivery['remark'] ? $delivery['remark'] : '' + ]; $list[] = [ + 'oid' => $order['id'], 'title' => $brand_name.$serie_name, + 'owner_name' => $owner_name, 'cover' => $cover, - 'price' => $money_json['price_discount'] ? $money_json['price_car'] - $money_json['price_discount'] : $money_json['price_car'], - 'sid' => $val['sid'], + 'price' => $total_price, + 'sid' => $order['sid'], 'payway' => $order['payway'], 'type' => $select_car, 'info' => $info, 'sub_order' => $sub_order, + 'agree' => $agree, + 'ckcar_status' => $ckcar_status, //是否显示确认车辆 + 'version' => $attrs[$val['v_id']] ? $attrs[$val['v_id']][0]['title'] : '', + 'color' => $attrs[$val['cor_id']] ? $attrs[$val['cor_id']][0]['title'] : '', + 'in_color' => $attrs[$val['incor_id']] ? $attrs[$val['incor_id']][0]['title'].'内饰' : '', + 'contract_list' => $contract_list, + 'ckcar_data' => $ckcar_data, + 'c_time' => date('Y-m-d H:i:s',$val['c_time']) ]; } } diff --git a/api/controllers/wxapp/liche/Pay.php b/api/controllers/wxapp/liche/Pay.php index aa410c94..2eb094f0 100644 --- a/api/controllers/wxapp/liche/Pay.php +++ b/api/controllers/wxapp/liche/Pay.php @@ -17,21 +17,90 @@ class Pay extends Wxapp{ $this->load->model('app/liche/app_liche_orders_model'); $this->load->model('receiver/order/receiver_orders_model','orders_model'); + $this->load->model('receiver/order/receiver_orders_v2_model'); + $this->load->model('auto/auto_brand_model'); $this->load->model('auto/auto_series_model'); + $this->load->model('auto/auto_attr_model'); + $this->load->model('biz/biz_model'); $this->load->model("sys/sys_company_model"); $this->load->library('receiver/orders_entity'); + $this->load->library('receiver/orders_v2_entity'); $this->uid = $this->session['uid']; } + //获取订单信息 + public function get_order(){ + $sid = $this->input_param('sid'); + $row = $this->app_liche_orders_model->get(['sid'=>$sid,'pid>'=>0]); + if(!$row){ + throw new Exception('订单不存在', API_CODE_FAIL); + } + $order_type = $this->app_liche_orders_model->get_type_arr(); + $order_info = []; + $price = $row['total_price']; + $pay_status = $row['status'] ? true:false; + if($row['type']!=4){ + $order = $this->receiver_orders_v2_model->get(['id'=>$row['o_id']]); + $money_json = json_decode($order['money_json'],true); + //品牌车型 + $brands = $this->auto_brand_model->get(['id'=>$order['brand_id']],'id,name'); + //车系车型 + $series = $this->auto_series_model->get(['id'=>$order['s_id']],'id,name','id,name'); + $brand_name = $brands['name'] ? $brands['name'] : ''; + $serie_name = $series['name'] ? $series['name'] : ''; + //获取车辆属性 + $attr_id_arr = [ + $order['v_id'], $order['cor_id'], $order['incor_id'] + ]; + $attrs = $this->auto_attr_model->get_map_by_ids($attr_id_arr,'id,title,jsondata'); + $cover = ''; + if($attrs[$order['cor_id']]){ + $jsondata = json_decode($attrs[$order['cor_id']][0]['jsondata'],true); + $cover = build_qiniu_image_url($jsondata['img']); + } + $order_info = [ + 'title' => $brand_name.$serie_name, + 'cover' => $cover, + 'price' => $money_json['price_discount'] ? $money_json['price_car'] - $money_json['price_discount'] : $money_json['price_car'], + 'version' => $attrs[$order['v_id']] ? $attrs[$order['v_id']][0]['title'] : '', + 'color' => $attrs[$order['cor_id']] ? $attrs[$order['cor_id']][0]['title'] : '', + 'in_color' => $attrs[$order['incor_id']] ? $attrs[$order['incor_id']][0]['title'] : '', + ]; + } + if($row['type']==3){ //尾款 + $is_pay = $this->app_liche_orders_model->sum('total_price',['status'=>1,'pid'=>$row['id']]); //已支付尾款金额 + $price = $row['total_price'] - $is_pay['total_price']; + if($price<=0){ + $price = $row['total_price']; + $pay_status = true; + } + } + $data = [ + 'nickname' => $this->session['nickname'], + 'headimg' => $this->session['headimg'], + 'text' => '我在狸车平台上相中了一款好车,需要你帮忙付款,感恩~', + 'type' => $row['type'], + 'type_cn' => $order_type[$row['type']], + 'price' => $price, + 'pay_status' => $pay_status, + 'order_info' => $order_info + ]; + return $data; + } //支付 public function put(){ $sid = $this->input_param('sid'); $price = $this->input_param('price'); - $row = $this->app_liche_orders_model->get(['sid'=>$sid,"(uid={$this->uid} or entrust_uid={$this->uid})"=>null]); + $type = $this->input_param('type'); + if($type){ //代付 + $row = $this->app_liche_orders_model->get(['sid'=>$sid]); + }else{ + $row = $this->app_liche_orders_model->get(['sid'=>$sid,"(uid={$this->uid} or entrust_uid={$this->uid})"=>null]); + } $type_arr = $this->app_liche_orders_model->get_type_arr(); if(!$row){ throw new Exception('订单不存在', API_CODE_FAIL); @@ -39,16 +108,18 @@ class Pay extends Wxapp{ if($row['status']==1){ throw new Exception('订单已支付', API_CODE_FAIL); } - if($row['type']==3){ //判断服务费是否支付 - $srv_pay = $this->app_liche_orders_model->count(['o_id'=>$row['o_id'],'type'=>2,'status'=>0]); - if($srv_pay){ - throw new Exception('请先支付委托服务费', API_CODE_FAIL); + if($row['o_id']<=Orders_v2_entity::V2_START_ID) { + if ($row['type'] == 3) { //判断服务费是否支付 + $srv_pay = $this->app_liche_orders_model->count(['o_id' => $row['o_id'], 'type' => 2, 'status' => 0]); + if ($srv_pay) { + throw new Exception('请先支付委托服务费', API_CODE_FAIL); + } } - } - if($row['type']==1){ //判断是否存在未支付意向金 - $inten_pay = $this->app_liche_orders_model->count(['o_id'=>$row['o_id'],'type'=>4,'status'=>0]); - if($inten_pay){ - throw new Exception('请先支付意向金', API_CODE_FAIL); + if ($row['type'] == 1) { //判断是否存在未支付意向金 + $inten_pay = $this->app_liche_orders_model->count(['o_id' => $row['o_id'], 'type' => 4, 'status' => 0]); + if ($inten_pay) { + throw new Exception('请先支付意向金', API_CODE_FAIL); + } } } if($row['total_price']>0){ @@ -73,7 +144,8 @@ class Pay extends Wxapp{ $sub_data = [ 'o_id' => $row['o_id'], 'sid' => $sid, - 'uid' => $this->uid, + 'uid' => $row['uid'], + 'pay_uid' => $this->uid, 'mch_id' => $row['mch_id'], 'pid' => $row['id'], 'brand_id' => $row['brand_id'], @@ -82,11 +154,10 @@ class Pay extends Wxapp{ 'cor_id' => $row['cor_id'], 'incor_id' => $row['incor_id'], 'total_price' => $total, + 'entrust_uid' => $row['entrust_uid'], 'type' => 3, 'c_time' => time() ]; - $entrust_user = $this->orders_entity->entrust_user($row['o_id']); - $entrust_user['id'] && $sub_data['entrust_uid'] = $entrust_user['id']; $res = $this->app_liche_orders_model->add($sub_data); if(!$res){ throw new Exception('创建订单失败', API_CODE_FAIL); @@ -101,11 +172,18 @@ class Pay extends Wxapp{ if($this->uid<=10){ $total = 0.01; } - $order_row = $this->orders_model->get(['id'=>$row['o_id']],'name,brand_id,s_id,biz_id'); + if($row['id']>=Orders_v2_entity::V2_START_ID){ + $order_row = $this->receiver_orders_v2_model->get(['id'=>$row['o_id']],'name,brand_id,s_id,biz_id'); + }else{ + $order_row = $this->orders_model->get(['id'=>$row['o_id']],'name,brand_id,s_id,biz_id'); + } $brand_row = $this->auto_brand_model->get(['id'=>$order_row['brand_id']],'name'); $s_row = $this->auto_series_model->get(['id'=>$order_row['s_id']],'name'); $biz_row = $this->biz_model->get(['id'=>$order_row['biz_id']],'biz_name,company_id'); $company_row = $this->sys_company_model->get(['id'=>$biz_row['company_id']],'short'); + if($row['id']>=Orders_v2_entity::V2_START_ID){ + $company_row = $this->sys_company_model->get(['id'=>$row['company_id']],'short'); + } $type_name = $type_arr[$row['type']]; $description = "{$brand_row['name']}{$s_row['name']}-{$order_row['name']}-{$biz_row['biz_name']}-{$type_name}-{$company_row['short']}"; $this->config->load('wxpay'); diff --git a/api/controllers/wxapp/liche/Protocol.php b/api/controllers/wxapp/liche/Protocol.php index 74b76311..b50c1263 100644 --- a/api/controllers/wxapp/liche/Protocol.php +++ b/api/controllers/wxapp/liche/Protocol.php @@ -14,8 +14,20 @@ class Protocol extends Wxapp{ function __construct($inputs, $app_key){ parent::__construct($inputs, $app_key); - $this->login_white = 'all';//登录白名单 + $this->login_white = ['get'];//登录白名单 + $this->load->model('receiver/order/receiver_orders_v2_model'); + $this->load->model('receiver/receiver_services_model','services_model'); + $this->load->model('receiver/order/receiver_order_contracts_model'); + $this->load->model('receiver/order/receiver_order_deliverys_model','deliverys_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("items/items_model"); + + $this->load->library('receiver/orders_v2_entity'); + $this->load->library('receiver/orders_status_entity'); + $this->load->library('pdftk'); } /** @@ -36,4 +48,225 @@ class Protocol extends Wxapp{ $data['content'] = $content; return $data; } + + /** + * 获取支付同意html内容 + */ + protected function get_html(){ + $oid = $this->input_param('oid'); + $type = $this->input_param('type'); + if($type==1){ + return $this->ck_html($oid); + } + $row = $this->receiver_orders_v2_model->get(['id'=>$oid]); + if(!$row ){ + throw new Exception('参数错误', API_CODE_INVILD_PARAM); + } + $fill_info = $this->orders_v2_entity->pdf_data($row); + $car_html = "
汽车购买协议
+
+
编号【{$row['sid']}】
+
本《汽车购买协议》(“本协议”),由您(“狸车用户”)与下述签署本协议的狸车销售公司或其关联公司 (以下统称“狸车公司”),于本协议附件一所载明的协议签署日签署。
+
依据《中华人民共和国民法典》及有关法律的规定,就您购买车辆所涉事宜,双方在诚实守信、平等自愿的基础上,经充分协商,达成交易文件,供双方予以遵守。
+
价格支付
+
您需在签署本协议时向狸车公司支付所定车辆应付的定金。如您在本协议签署前已就购买汽车事宜向狸车公司支付了意向金,则您已支付意向金将按本条前述约定自动转为定金,超出定金金额的剩余意向金(如有)自动构成尾款的一部分。如您拒绝向狸车公司支付剩余汽车价款或在接到狸车公司通知后在指定时间内未支付剩余汽车价款,狸车公司无需另行通知您且已收取的认购定金将不予返还。
+
虽有前述规定,双方均同意,汽车交付前,若因非主观过错出现了无法预见的重大变故,直接导致无法继续履行本协议,经您与狸车公司协商一致后,可解除本协议且已收取的定金及意向金中超出定金金额的款项(如有)将进行退还。
+
配置变更
+
定金支付后,车型配置方案将不可更改,同时您确认狸车公司可以立即配车。但经双方协商一致且狸车公司书面同意后,您可以变更本协议附件中的相关内容,双方将按变更后的约定继续履行本协议。
+
车辆交付
+
狸车公司预计将于定金支付后的 {$fill_info['give_time']} 日向您交付汽车。(该时间仅供参考,实际交付时间可能根据车辆配置、提车城市等因素提前或延后)。狸车公司收到尾款后向您交付汽车,并随同汽车一并向您交付与汽车相关的《保修保养手册》、《用户手册》等文件(“随车文件”)以及车辆钥匙、充电枪等物品(“随车工具”)。
+
补贴约定
+
鉴于新能源汽车购车补贴在您购车时已作扣除,为便于狸车公司能够从相关主管部门获得该等补贴或保障狸车公司在无法获得该等补贴时权益不受损害,您应按照狸车公司不时要求的必要行动以及提供狸车公司不时要求的信息和文件。另外,鉴于国家和地方关于新能源汽车购车补贴的法律法规及政策可能不时发生变化,狸车公司会在其发生变化的同时相应调整实际购车总价、尾款;因此,您最终需支付的实际购车总价、尾款应以交付通知中列明的金额为准。
+
适用法律
+
本协议应受中华人民共和国法律管辖并据其进行解释。因本协议引起的以及与本协议有关的一切争议,首先应由双方通过友好协商解决。如果双方未能通过协商解决该等争议,则任何一方有权向狸车公司所在地有管辖权的人民法院提起诉讼。如需仲裁,双方另行协商签订相关补充条款。
+
协议生效
+
本协议的所有附件构成本协议不可分割的一部分。本协议自您点击确认“我已阅读并同意”或双方签字、盖章且狸车公司收到您支付的定金后立即生效。
+
狸车用户:
+
+
签署:{$fill_info['name']}
+
日期:{$fill_info['now_day']}
+
+
狸车公司:
+
+
签署:{$fill_info['companys']['company']['title']}
+
日期:{$fill_info['now_day']}
+
+
编号【{$row['sid']}】
+
附件一 订单信息
+
车主姓名:{$fill_info['owner_name']}
+
联系电话:{$fill_info['owner_mobile']}
+
证件类型:{$fill_info['identify_type']}
+
证件号码:{$fill_info['identify']}
+
联系地址:{$fill_info['address']}
+
车辆型号:{$fill_info['version']}
+
车身颜色:{$fill_info['color']}
+
内饰颜色:{$fill_info['incolor']}
+
车辆价格
+
售价(元):{$fill_info['price_car']}
+
折扣(元):{$fill_info['price_discount']}
+
实际支付(元):{$fill_info['recevable_price']}
+
其中,
+
1.定金(元):{$fill_info['price_book']}
+
2.整车尾款(元):{$fill_info['last_price']}
+
"; + $list[] = [ + 'title' => '购车协议', + 'url' => '', + 'content' => $car_html + ]; + if($row['srv_ids']){ + $service_str = implode('
',$fill_info['services']); + $agent_html = "
委托服务协议
+
+
编号【{$row['sid']}】
+
本《委托服务协议》(“本协议”),由您(“狸车用户”)与下述签署本协议的狸车服务公司或其关联公司 (以下统称“狸车公司”),于本协议附件一所载明的协议签署日签署。
+
依据《中华人民共和国民法典》及有关法律的规定,您为节省时间和精力,就甲乙双方《汽车购买协议》标的的车辆,自愿委托狸车公司办理下列委托事项,并达成如下协议:
+
价格支付
+
您需在签署本协议后车辆交付前向狸车公司支付所委托事项应付的金额。其中,保险费用由您直接支付给保险公司。
+
委托事项变更
+
经双方协商一致且狸车公司书面同意后,您可以变更本协议附件中的相关内容,双方将按变更后的约定继续履行本协议。
+
适用法律
+
本协议应受中华人民共和国法律管辖并据其进行解释。因本协议引起的以及与本协议有关的一切争议,首先应由双方通过友好协商解决。如果双方未能通过协商解决该等争议,则任何一方有权向狸车公司所在地有管辖权的人民法院提起诉讼。如需仲裁,双方另行协商签订相关补充条款。
+
协议生效
+
本协议的所有附件构成本协议不可分割的一部分。本协议自您点击确认“我已阅读并同意”或双方签字、盖章且狸车公司收到您支付的定金后立即生效。
+
狸车用户:
+
+
签署:{$fill_info['name']}
+
日期:{$fill_info['now_day']}
+
+
狸车公司:
+
+
签署:{$fill_info['companys']['srv_company']['title']}
+
日期:{$fill_info['now_day']}
+
+
编号【{$row['sid']}】
+
附件一 委托上牌约定
+
车牌选号时,均由狸车公司电话通知您,因您未能及时选号等其它原因,狸车公司有权代理决定并不对最终选号结果负责;若为自选号牌,狸车公司可配合您上牌,但不对最终选号结果负责。
+
您委托狸车公司代办车辆挂牌服务时,您应事先办妥机动车车辆保险,投保险种包括但不限于车辆损失险和第三者责任险。狸车公司在代办服务过程中造成车辆毁损、灭失的,您应当先向保险公司索赔,保险条款及费用以保险公司合同为准,赔付不足部分由狸车公司予以修复或赔偿。
+ +
编号【{$row['sid']}】
+
附件二 委托服务信息
+
委托人姓名:{$fill_info['owner_name']}
+
联系电话:{$fill_info['owner_mobile']}
+
委托项目(元):
+
{$service_str}
+
"; + $list[] = [ + 'title' => '服务协议', + 'url' => '', + 'content' => $agent_html + ]; + } + $data = [ + 'list' => $list + ]; + return $data; + } + + /** + * 同意条款 + */ + protected function post(){ + $oid = $this->input_param('oid'); + $row = $this->receiver_orders_v2_model->get(['id'=>$oid]); + if(!$row ){ + throw new Exception('参数错误', API_CODE_INVILD_PARAM); + } + $res = $this->orders_v2_entity->create_pdf($row['id']); + if($res['code']){ + throw new Exception('操作成功', API_CODE_SUCCESS); + }else{ + throw new Exception($res['msg'], API_CODE_FAIL); + } + + } + + protected function post_ckcar(){ + $oid = $this->input_param('oid'); + $row = $this->receiver_orders_v2_model->get(['id'=>$oid]); + if(!$row ){ + throw new Exception('参数错误', API_CODE_INVILD_PARAM); + } + if($this->receiver_order_contracts_model->count(['o_id'=>$oid,'status'=>1,'type'=>3])){ + throw new Exception('操作成功', API_CODE_SUCCESS); + } + $fill_info = $this->orders_v2_entity->pdf_data($row,1); + $fill_data = [ + 'sid' => $row['sid'], + 'date' => $fill_info['now_day'], + 'company' => $fill_info['companys']['company']['title'], + 'name' => $fill_info['name'], + 'version' => $fill_info['version'], + 'color' => $fill_info['color'], + 'incolor' => $fill_info['incolor'], + 'vin' => $fill_info['vin'], + 'info' => $fill_info['delivery']['info'], + 'tool' => $fill_info['delivery']['tool'], + ]; + $pdf_path = 'pdf/ck_tpl.pdf'; + $save_path = "pdf/{$row['sid']}/ck.pdf"; + $req = $this->pdftk->esign_fill_pdf($pdf_path,$save_path,$fill_data); + if(!$req['code']){ + throw new Exception($req['msg'], API_CODE_FAIL); + } + $add_data = [ + 'o_id' => $row['id'], + 'cid' => 0, + 'file' => $req['data']['file_path'] ? $req['data']['file_path'] : '', + 'type' => 3, + 'status' => 1, + 'c_time' => time() + ]; + $res = $this->receiver_order_contracts_model->add($add_data); + if($res){ + $this->orders_status_entity->set_status($row['id'],4,2); + $this->orders_status_entity->set_status($row['id'],5,1); + $this->receiver_orders_v2_model->update(['status'=>1],['id'=>$row['id']]); + throw new Exception('操作成功', API_CODE_SUCCESS); + }else{ + throw new Exception('保存失败', API_CODE_FAIL); + } + } + private function ck_html($oid){ + $row = $this->receiver_orders_v2_model->get(['id'=>$oid]); + if(!$row ){ + throw new Exception('参数错误', API_CODE_INVILD_PARAM); + } + $fill_info = $this->orders_v2_entity->pdf_data($row,1); + $car_html = "
汽车交付确认单
+
+
编号【{$row['sid']}】
+
本《汽车交付确认单》(“本确认单”),由您(“狸车用户”)与下述签署本协议的狸车销售公司或其关联公司 (以下统称“狸车公司”),于本协议附件一所载明的协议签署日签署。
+
狸车公司已向您做了详细的车辆介绍,介绍的内容包含但不限于车辆外部、行李箱、发动机舱、座椅、驾驶位置及各类仪表及显示屏介绍。
+
您经过验收,确认附件所述所有事项,所购车辆符合购车合同约定并已于交付日期收到该车辆。
+
狸车用户:
+
+
签署:{$fill_info['name']}
+
日期:{$fill_info['now_day']}
+
+
狸车公司:
+
+
签署:{$fill_info['companys']['company']['title']}
+
日期:{$fill_info['now_day']}
+
+
编号【{$row['sid']}】
+
附件一 交付信息
+
车辆型号:{$fill_info['version']}
+
车身颜色:{$fill_info['color']}
+
内饰颜色:{$fill_info['incolor']}
+
车架号:{$fill_info['vim']}
+
随车资料:{$fill_info['delivery']['info']}
+
随车工具:{$fill_info['delivery']['tool']}
+
"; + $list[] = [ + 'title' => '购车协议', + 'url' => '', + 'content' => $car_html + ]; + $data = [ + 'list' => $list + ]; + return $data; + } + } diff --git a/api/controllers/wxapp/liche/User.php b/api/controllers/wxapp/liche/User.php index 23db4516..3cfb6b17 100644 --- a/api/controllers/wxapp/liche/User.php +++ b/api/controllers/wxapp/liche/User.php @@ -206,9 +206,24 @@ class User extends Wxapp{ protected function get_my(){ $this->load->library('liche/progressopt'); $mobile = $this->session['mobile']; - + $where = [ + + ]; + $this->app_liche_orders_model->count($where); + $where = [ + "(uid = {$this->session['uid']} or entrust_uid={$this->session['uid']})" => null, + 'pid' => 0, + 'status>=' => 0, + 'type <>' => 5 + ]; + $un_pay = $this->app_liche_orders_model->count($where); $about = [ - ['title'=>'购车订单','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-5.png','url'=>'/pages/mine/carOrder/index'], + [ + 'title'=>'购车订单', + 'icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-5.png', + 'url'=>'/pages/mine/carOrder/index', + 'have_new' => $un_pay ? true : false + ], ['title'=>'我的爱车','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-1.png','url'=>'/pages/mine/myCar/index'], ['title'=>'联系小狸','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-3.png'], ]; diff --git a/api/controllers/wxapp/liche/Wxnotify_v3.php b/api/controllers/wxapp/liche/Wxnotify_v3.php index ce998b44..01642cf6 100644 --- a/api/controllers/wxapp/liche/Wxnotify_v3.php +++ b/api/controllers/wxapp/liche/Wxnotify_v3.php @@ -21,6 +21,8 @@ class Wxnotify_v3 extends CI_Controller{ $this->load->model('app/liche/app_liche_orders_model'); $this->load->model('receiver/order/receiver_orders_model'); + $this->load->library('receiver/orders_v2_entity'); + $this->load->library('qyrobot'); $input = file_get_contents('php://input'); debug_log("[info] ". __FUNCTION__ . "# input:" . $input, $this->log_file,$this->log_dir); @@ -110,26 +112,50 @@ class Wxnotify_v3 extends CI_Controller{ debug_log("[error] ". __FUNCTION__ . ":支付失败,sid={$sid},app_id=", $this->log_file,$this->log_dir); }else{ //支付成功 $this->load->service('apporder/payment_service', array('app_id' => $this->app_id)); - $result = $this->payment_service->after_pay_liche($sid,$result['data']['amount']['payer_total']/100); - if($result['code']){ + if($order['o_id']>=Orders_v2_entity::V2_START_ID){ $is_ts = false; - if($order['type']==1){ //定金 + if(!$this->app_liche_orders_model->count(['status'=>1,'o_id'=>$order['o_id']])){ $is_ts = true; - }elseif($order['type']==4){ //意向金 - $receiver_order = $this->receiver_orders_model->get(['id'=>$order['o_id']]); - if($receiver_order['deposit'] == $order['total_price']){ - $is_ts = true; + } + $this->load->model('app/liche/app_liche_users_model'); + $pay_user = $this->app_liche_users_model->get(['openid'=>$result['data']['payer']['sub_openid']]); + $result = $this->payment_service->after_pay_liche_v2($sid,$result['data']['amount']['payer_total']/100,$pay_user['uid']); + if($result['code']){ + $log = [ + 'money' => $result_data['data']['amount']['payer_total'], + 'is_ts' => $is_ts + ]; + debug_log("[info] ". __FUNCTION__ . ": ".json_encode($log,JSON_UNESCAPED_UNICODE), $this->log_file,$this->log_dir); + if($result_data['data']['amount']['payer_total']>=10000 && $is_ts){ + $robot_res = $this->qyrobot->deposit_notify_v2($order['o_id']); + debug_log("[info] ". __FUNCTION__ . ":推送企业微信群 ".json_encode($robot_res,JSON_UNESCAPED_UNICODE), $this->log_file,$this->log_dir); } + debug_log("[success] ". __FUNCTION__ . ":操作成功", $this->log_file,$this->log_dir); + }else{ + debug_log("[error] ". __FUNCTION__ . ":".$result['msg'], $this->log_file,$this->log_dir); } - if($is_ts && $result_data['data']['amount']['payer_total']>=10000){ //支付定金和意向金推送企业微信群 - $this->load->library('qyrobot'); - $robot_res = $this->qyrobot->deposit_notify($order['o_id']); - debug_log("[info] ". __FUNCTION__ . ":推送企业微信群 ".json_encode($robot_res,JSON_UNESCAPED_UNICODE), $this->log_file,$this->log_dir); + }else{ + $result = $this->payment_service->after_pay_liche($sid,$result['data']['amount']['payer_total']/100); + if($result['code']){ + $is_ts = false; + if($order['type']==1){ //定金 + $is_ts = true; + }elseif($order['type']==4){ //意向金 + $receiver_order = $this->receiver_orders_model->get(['id'=>$order['o_id']]); + if($receiver_order['deposit'] == $order['total_price']){ + $is_ts = true; + } + } + if($is_ts && $result_data['data']['amount']['payer_total']>=10000){ //支付定金和意向金推送企业微信群 + $robot_res = $this->qyrobot->deposit_notify($order['o_id']); + debug_log("[info] ". __FUNCTION__ . ":推送企业微信群 ".json_encode($robot_res,JSON_UNESCAPED_UNICODE), $this->log_file,$this->log_dir); + } + debug_log("[success] ". __FUNCTION__ . ":操作成功", $this->log_file,$this->log_dir); + }else{ + debug_log("[error] ". __FUNCTION__ . ":".$result['msg'], $this->log_file,$this->log_dir); } - debug_log("[success] ". __FUNCTION__ . ":操作成功", $this->log_file,$this->log_dir); - }else{ - debug_log("[error] ". __FUNCTION__ . ":".$result['msg'], $this->log_file,$this->log_dir); - } + } + } debug_log("[finish] ". __FUNCTION__ . ": sid:".$sid, $this->log_file,$this->log_dir); }else{ diff --git a/api/controllers/wxapp/licheb/Cusorder.php b/api/controllers/wxapp/licheb/Cusorder.php index a11182f9..81500804 100644 --- a/api/controllers/wxapp/licheb/Cusorder.php +++ b/api/controllers/wxapp/licheb/Cusorder.php @@ -44,6 +44,7 @@ class Cusorder extends Wxapp{ $this->load->model('sys/sys_finance_model'); $this->load->library('receiver/orders_entity'); + $this->load->library('receiver/orders_v2_entity'); $this->load->library('receiver/customers_entity'); } @@ -561,6 +562,7 @@ class Cusorder extends Wxapp{ } //确认交付 protected function put_ckcar(){ + $this->load->library('receiver/orders_status_entity'); $id = $this->input_param('id'); $remark = $this->input_param('remark'); $info = $this->input_param('info'); @@ -569,7 +571,34 @@ class Cusorder extends Wxapp{ throw new Exception('参数错误', ERR_PARAMS_ERROR); } $row = $this->order_deliverys_model->get(['o_id'=>$id]); - if($row['status']>1){ + if($id>=Orders_v2_entity::V2_START_ID){ + if(!$row){ + $row['id'] = $this->order_deliverys_model->add(['o_id'=>$id,'c_time'=>time()]); + } + $this->load->model('receiver/order/receiver_orders_v2_model'); + $this->load->model('receiver/order/receiver_order_datas_model'); + $order_row = $this->receiver_orders_v2_model->get(['id'=>$id]); + if(!$order_row['payway'] && !$this->orders_status_entity->get_finish($id,1,2)){ + throw new Exception('按揭放款尚未确认', ERR_PARAMS_ERROR); + } + $order_data = $this->receiver_order_datas_model->get(['o_id'=>$id]); + if($order_row['main_type']){ //公司 + if(!$order_data['business_licence']){ + throw new Exception('请先上传公司营业执照', ERR_PARAMS_ERROR); + } + }else{ //个人 + if(!$order_data['cardida'] || !$order_data['cardidb']){ + throw new Exception('请先上传身份证正反面', ERR_PARAMS_ERROR); + } + } + if(!$order_data['car_img']){ + throw new Exception('请先上传行驶证', ERR_PARAMS_ERROR); + } + if(!$order_data['ins_img']){ + throw new Exception('请先上传保单', ERR_PARAMS_ERROR); + } + } + if($row['status']>1 && $row['o_id']order_deliverys_model->update($update,['id'=>$row['id']]); if($result){ + if($id>=Orders_v2_entity::V2_START_ID){ + $this->orders_status_entity->set_status($id,4,1); + } throw new Exception('修改成功', API_CODE_SUCCESS); }else{ throw new Exception('修改失败', ERR_PARAMS_ERROR); diff --git a/api/controllers/wxapp/licheb/CusorderV2.php b/api/controllers/wxapp/licheb/CusorderV2.php new file mode 100644 index 00000000..3ea96f9a --- /dev/null +++ b/api/controllers/wxapp/licheb/CusorderV2.php @@ -0,0 +1,775 @@ +login_white = array();//登录白名单 + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg =array();//授权微信信息 + + $this->load->model('receiver/receiver_customers_model','customers_model'); + $this->load->model('receiver/order/receiver_orders_model'); + $this->load->model('receiver/order/receiver_orders_v2_model','orders_model'); + $this->load->model('receiver/order/receiver_order_datas_model'); + $this->load->model('receiver/order/receiver_order_status_model'); + $this->load->model('receiver/order/receiver_order_deliverys_model','order_deliverys_model'); + $this->load->model('receiver/order/receiver_order_loans_model', 'order_loans_model'); + + $this->load->model('auto/auto_series_model'); + $this->load->model('auto/auto_attr_model'); + $this->load->model('auto/auto_cars_model'); + $this->load->model('auto/auto_business_model'); + + $this->load->model("biz/biz_model"); + $this->load->model('sys/sys_finance_model'); + $this->load->model('sys/sys_city_model'); + + $this->load->model('app/liche/app_liche_users_model'); + $this->load->model('app/liche/app_liche_orders_model'); + + $this->load->library('receiver/orders_entity'); + $this->load->library('receiver/orders_v2_entity'); + $this->load->library('receiver/customers_entity'); + $this->load->library('receiver/order_datas_entity'); + $this->load->library('receiver/orders_status_entity'); + $this->biz_id = $this->get_biz_id(); + } + + protected function get(){ + $id = $this->input_param('id'); + if($id){ + return $this->detail($id); + }else{ + return $this->lists(); + } + } + + //创建订单 + protected function post(){ + $cus_id = $this->input_param('cus_id'); + $car_id = $this->input_param('car_id'); + $color_id = $this->input_param('color_id'); + $incolor_id = $this->input_param('incolor_id'); + $v_id = $this->input_param('v_id'); + $deposit = $this->input_param('deposit'); + $payway = $this->input_param('payway'); + $main_type = $this->input_param('main_type'); + $name = trim($this->input_param('name')); + $mobile = trim($this->input_param('mobile')); + $cardid = trim($this->input_param('cardid')); + $owner_name = trim($this->input_param('owner_name')); + $owner_mobile = trim($this->input_param('owner_mobile')); + $owner_cardid = trim($this->input_param('owner_cardid')); + $company = $this->input_param('company'); + $c_credit = $this->input_param('credit'); + $delry_time = $this->input_param('delry_time'); + $finance_id = $this->input_param('finance_id'); + $inten_money = floatval($this->input_param('inten_money'));//意向金 + $disc_money = floatval($this->input_param('disc_money'));//优惠金额 + $disc_fine_money = floatval($this->input_param('disc_fine_money'));//精品优惠金额 + $if_fine = $this->input_param('if_fine'); + $srv_arr = $this->input_param('srv_arr'); + $fines = $this->input_param('fines'); + $address = $this->input_param('address'); + $business_id = $this->input_param('business_id'); //商务政策id + + $row = $this->customers_model->get(['id'=>$cus_id]); + $series_row = $this->auto_series_model->get(['id'=>$car_id]); + $business_row = $this->auto_business_model->get(['id'=>$business_id]); + if(!$row || !$series_row ||!$delry_time || !$name || !$mobile || !$business_row || !$deposit){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + if($main_type){//公司 + if(!$company || !$c_credit){ + throw new Exception('请填写公司信息', ERR_PARAMS_ERROR); + } + }else{ //个人 + if(!$cardid || !$owner_name || !$owner_mobile || !$owner_cardid){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + } + if($deposit<2000){ + throw new Exception('定金不得少于2000', ERR_PARAMS_ERROR); + } + if($inten_money > $deposit){ + throw new Exception('意向金不得高于定金', ERR_PARAMS_ERROR); + } + $biz = $this->biz_model->get(['id'=>$row['biz_id']],'city_id,type'); + + $car_row = $this->auto_cars_model->get(['brand_id'=>$series_row['brand_id'],'s_id'=>$series_row['id'],'v_id'=>$v_id],'',$biz['city_id']); + if(!$car_row){ + throw new Exception('参数错误', API_CODE_FAIL); + } + $can_dis_money = $business_row['price_car'] - $business_row['price_floor']; //可优惠金额 + if($can_dis_money>0){ + if($disc_money && $business_row['price_floor'] > $business_row['price_car']-$disc_money){ + throw new Exception('车辆售价不得低于车辆底价,请重新填写优惠信息', API_CODE_FAIL); + } + }else{ + if($disc_money) throw new Exception('当前车型没有优惠额度', API_CODE_FAIL); + } + if(!$payway && $finance_id){ //分期 + $finance_row = $this->sys_finance_model->get(['id'=>$finance_id,'status'=>1]); + if(!$finance_row){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + } + + $data = [ + 'clue_id' => $cus_id, + 'sid' => create_order_no(350200,$this->app_key), + 'customer_id' => $row['id'], + 'name' => $name ? $name : $row['name'], + 'mobile' => $mobile ? $mobile : $row['mobile'], + 'biz_id' => $this->biz_id, + 'brand_id' => $series_row['brand_id'], + 's_id' => $series_row['id'], + 'v_id' => $v_id, + 'cor_id' => $color_id, + 'incor_id' => $incolor_id, + 'sale_id' => $this->session['uid'], + 'c_time' => time() + ]; + $owner_name && $data['owner_name'] = $owner_name; + $owner_mobile && $data['owner_mobile'] = $owner_mobile; + $row['rid'] && $data['clue_id'] = $row['rid']; + $payway && $data['payway'] = 1; + $if_fine && $data['if_fine'] = 1; + $main_type && $data['main_type'] = 1; + $delry_time && $data['delry_time'] = $delry_time; + $fines && $data['fines'] = json_encode($fines,JSON_UNESCAPED_UNICODE); + $info_json = []; + $address && $info_json['c_address'] = $address; + $cardid && $info_json['c_cardid'] = $cardid; + $owner_cardid && $info_json['c_owner_cardid'] = $owner_cardid; + $c_credit && $info_json['c_credit'] = $c_credit; + $company && $info_json['c_company'] = $company; + $business_id && $info_json['business_id'] = $business_id; + $info_json && $data['info_json'] = json_encode($info_json,JSON_UNESCAPED_UNICODE); + $finance_row && $data['finance_id'] = $finance_row['id']; + + //获取金额json数据 + $orders_entity = new orders_v2_entity(); + $color_arr = json_decode($business_row['colors'],true); + $price_color = in_array($color_id,$color_arr) ? $business_row['price_color'] : 0; + $price_coplus = $main_type ? $business_row['price_coplus'] : 0; + + $money_json = [ + 'price_car' => $business_row['price_car'], + 'price_book' => $deposit ? $deposit : 0, + 'price_insure' => $car_row['price_insure'], + 'price_fine' => $car_row['price_fine'], + 'price_discount' =>$disc_money ? $disc_money : 0, + 'price_intention' => $inten_money ? $inten_money : 0, + 'price_finance' => $series_row['brand_id'] == 4 ? $orders_entity::PRICE_FINANCE_NZ : $orders_entity::PRICE_FINANCE, + 'price_fine_discount' => $disc_fine_money ? $disc_fine_money : 0, + 'price_fine_select' => 0, + 'price_color' => $price_color, + 'price_coplus' => $price_coplus, + ]; + if($srv_arr){ + foreach ($srv_arr as $item) { + $money_json[$item['key']] = $item['price']; + $item['id'] == 1 && $data['if_insure'] = 1; + $item['id'] == 2 && $data['if_num'] = 1; + } + } + $data['srv_ids'] = $srv_arr ? json_encode($srv_arr,JSON_UNESCAPED_UNICODE) : ""; + if($fines){ + foreach ($fines as $item) { + if($item['price']){ + $money_json['price_fine_select'] += $item['price']; + } + } + } + $data['car_json'] = $data['money_json'] = json_encode($money_json,JSON_UNESCAPED_UNICODE); + $o_id = $this->orders_model->add($data); + if($o_id){ + //意向金订单 + $userinfo = $this->app_liche_users_model->get(['mobile'=>$mobile],'id'); + if($inten_money){ + $this->orders_v2_entity->c_intention($o_id,$userinfo['id'],$inten_money); + } + $this->orders_v2_entity->add_book_order($o_id,$userinfo['id']); + if($payway){ //全款服务费和尾款订单 + $this->orders_v2_entity->add_order($o_id,$userinfo['id']); + } + //更新客户下单时间 + $this->customers_model->update(array('order_time' => date('Y-m-d H:i:s')),['id'=>$cus_id]); + $this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], "新增订单"); + + return ['id'=>$o_id,'admin_img' => $orders_entity::API_ADMIN_IMG,'pay_img'=>$orders_entity::API_CREATE_PAY_IMG]; + }else{ + throw new Exception('创建失败', ERR_PARAMS_ERROR); + } + } + //创建意向金订单 + protected function post_inten(){ + $cus_id = $this->input_param('cus_id'); + $name = $this->input_param('name'); + $mobile = $this->input_param('mobile'); + $cardid = $this->input_param('cardid'); + $owner_name = $this->input_param('owner_name'); + $owner_mobile = $this->input_param('owner_mobile'); + $owner_cardid = $this->input_param('owner_cardid'); + $main_type = $this->input_param('main_type'); + $company = $this->input_param('company'); + $c_credit = $this->input_param('credit'); + + $inten_money = floatval($this->input_param('inten_money'));//意向金 + + if(!$name || !$mobile|| !$inten_money){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + if($main_type){ + if(!$company || !$c_credit){ + throw new Exception('请填写公司信息', ERR_PARAMS_ERROR); + } + }else{ + if( !$cardid || !$owner_name || !$owner_mobile || !$owner_cardid){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + } + $row = $this->customers_model->get(['id'=>$cus_id]); + if($inten_money > 2000){ + throw new Exception('意向金不得高于2000', ERR_PARAMS_ERROR); + } + $data = [ + 'customer_id' => $cus_id, + 'sid' => create_order_no(350200,$this->app_key), + 'name' => $name ? $name : $row['name'], + 'mobile' => $mobile ? $mobile : $row['mobile'], + 'biz_id' => $this->biz_id, + 'sale_id' => $this->session['uid'], + 'c_time' => time() + ]; + $main_type && $data['main_type'] = 1; + $owner_name && $data['owner_name'] = $owner_name; + $owner_mobile && $data['owner_mobile'] = $owner_mobile; + $info_json = []; + $cardid && $info_json['c_cardid'] = $cardid; + $owner_cardid && $info_json['c_owner_cardid'] = $owner_cardid; + $company && $info_json['c_company'] = $company; + $c_credit && $info_json['c_credit'] = $c_credit; + $info_json && $data['info_json'] = json_encode($info_json,JSON_UNESCAPED_UNICODE); + //获取挂牌价 + $biz = $this->biz_model->get(['id'=>$row['biz_id']],'city_id'); + + $city = $this->sys_city_model->get(['city_id'=>$biz['city_id']],'fee_carno'); + $money_json['fee_carno'] = $city['fee_carno']; + $money_json['price_intention'] = $inten_money ? $inten_money : 0; + $data['money_json'] = json_encode($money_json,JSON_UNESCAPED_UNICODE); + + $row['rid'] && $data['clue_id'] = $row['rid']; + $o_id = $this->orders_model->add($data); + if(!$o_id){ + throw new Exception('创建失败', ERR_PARAMS_ERROR); + } + + //更新客户下单时间 + $this->customers_model->update(array('order_time' => date('Y-m-d H:i:s')),['id'=>$cus_id]); + $this->customers_entity->add_log($cus_id, $this->session['uid'], $this->session['uname'], "新增订单"); + + //意向金订单 + $orders_entity = new orders_v2_entity(); + if($inten_money){ + $userinfo = $this->app_liche_users_model->get(['mobile'=>$data['mobile']],'id'); + $orders_entity->c_intention($o_id,$userinfo['id'],$inten_money); + } + return ['id'=>$o_id,'admin_img' => $orders_entity::API_ADMIN_IMG,'pay_img'=>$orders_entity::API_CREATE_PAY_IMG]; + } + + //修改订单信息 + protected function put(){ + $id = $this->input_param('id'); + $car_id = $this->input_param('car_id'); + $color_id = $this->input_param('color_id'); + $incolor_id = $this->input_param('incolor_id'); + $v_id = $this->input_param('v_id'); + $payway = $this->input_param('payway'); + $main_type = $this->input_param('main_type'); + $delry_time = $this->input_param('delry_time'); + $finance_id = $this->input_param('finance_id'); + $deposit = $this->input_param('deposit'); + $disc_money = floatval($this->input_param('disc_money'));//优惠金额 + $disc_fine_money = floatval($this->input_param('disc_fine_money'));//精品优惠金额 + $if_fine = $this->input_param('if_fine'); + $srv_arr = $this->input_param('srv_arr'); + $fines = $this->input_param('fines'); + $business_id = $this->input_param('business_id'); //商务政策id + + $row = $this->orders_model->get(['id'=>$id]); + $series_row = $this->auto_series_model->get(['id'=>$car_id]); + $biz = $this->biz_model->get(['id'=>$row['biz_id']],'type,city_id'); + $car_row = $this->auto_cars_model->get(['brand_id'=>$series_row['brand_id'],'s_id'=>$series_row['id'],'v_id'=>$v_id],'',$biz['city_id']); + $business_row = $this->auto_business_model->get(['id'=>$business_id]); + if(!$row || !$series_row || !$car_row || !$business_row){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + if($deposit<2000){ + throw new Exception('定金不得少于2000', ERR_PARAMS_ERROR); + } + $can_dis_money = $car_row['price_car'] - $car_row['price_floor']; //可优惠金额 + if($can_dis_money>0){ + if($disc_money && $car_row['price_floor'] > $car_row['price_car']-$disc_money){ + throw new Exception('车辆售价不得低于车辆底价,请重新填写优惠信息', API_CODE_FAIL); + } + }else{ + if($disc_money) throw new Exception('当前车型没有优惠额度', API_CODE_FAIL); + } + if(!$payway && $finance_id){ //分期 + $finance_row = $this->sys_finance_model->get(['id'=>$finance_id,'status'=>1]); + if(!$finance_row){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + } + + $data = [ + 'brand_id' => $series_row['brand_id'], + 's_id' => $series_row['id'], + 'v_id' => $v_id, + 'cor_id' => $color_id, + 'incor_id' => $incolor_id, + 'payway' => $payway ? 1 : 0, + 'srv_ids' => json_encode($srv_arr,JSON_UNESCAPED_UNICODE), + 'if_insure' => 0, + 'if_num' => 0 + ]; + $main_type && $data['main_type'] = 1; + $delry_time && $data['delry_time'] = $delry_time; + $finance_row && $data['finance_id'] = $finance_row['id']; + $data['if_fine'] = $if_fine ? 1:0; + $fines && $data['fines'] = json_encode($fines,JSON_UNESCAPED_UNICODE); + + $color_arr = json_decode($business_row['colors'],true); + //获取金额json数据 + $money_json = json_decode($row['money_json'],true); + $data['car_json'] = json_encode($money_json,JSON_UNESCAPED_UNICODE); + $money_json['price_car'] = $car_row['price_car']; + $money_json['price_book'] = $deposit; + $money_json['price_insure'] = $car_row['price_insure']; + $money_json['price_fine'] = $car_row['price_fine']; + $money_json['price_discount'] = $disc_money; + $money_json['price_fine_discount'] = $disc_fine_money; + $money_json['price_finance'] = $series_row['brand_id'] == 4 ? Orders_v2_entity::PRICE_FINANCE_NZ : Orders_v2_entity::PRICE_FINANCE; + $money_json['price_color'] = in_array($color_id,$color_arr) ? $business_row['price_color'] : 0; + $money_json['price_coplus'] = $main_type ? $business_row['price_coplus'] : 0; + //获取挂牌价 + if($srv_arr){ + foreach ($srv_arr as $item) { + $money_json[$item['key']] = $item['price']; + $item['id'] == 1 && $data['if_insure'] = 1; + $item['id'] == 2 && $data['if_num'] = 1; + } + } + $data['srv_ids'] = $srv_arr ? json_encode($srv_arr,JSON_UNESCAPED_UNICODE) : ""; + if($fines){ + $money_json['price_fine_select'] = 0; + foreach ($fines as $item) { + if($item['price']){ + $money_json['price_fine_select'] += $item['price']; + } + } + } + $data['money_json'] = json_encode($money_json,JSON_UNESCAPED_UNICODE); + $info_json = json_decode($row['info_json'],true); + $info_json['business_id'] = $business_id; + $data['info_json'] = json_encode($info_json,JSON_UNESCAPED_UNICODE); + $result = $this->orders_model->update($data,['id'=>$row['id']]); + if($result){ + $this->orders_v2_entity->edit_order($data,$row); + throw new Exception('修改成功', API_CODE_SUCCESS); + }else{ + throw new Exception('修改失败', ERR_PARAMS_ERROR); + } + } + + private function detail($id){ + $row = $this->orders_model->get(['id'=>$id]); + if(!$row){ + throw new Exception('订单不存在', ERR_PARAMS_ERROR); + } + $orders_entity = new Orders_v2_entity(); + + $money_json = json_decode($row['money_json'],true); + $info_json = json_decode($row['info_json'],true); + + $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); + $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name'); + $color = $this->auto_attr_model->get(['id'=>$row['cor_id']],'title'); + $version = $this->auto_attr_model->get(['id'=>$row['v_id']],'title'); + $color = $color ? $color['title'] : ''; + $version = $version ? $version['title'] : ''; + + $car_data = []; + if($row['brand_id'] && $row['s_id'] && $row['v_id']){ + $car_data['车辆名称'] = $brand['name'].$series['name']; + $car_data['车辆名称'] = $brand['name'].$series['name']; + $car_data['车辆级别'] = $version; + $car_data['车身颜色'] = $color; + $car_data['平台售价'] = $money_json['price_car']; + $money_json['price_coplus'] && $car_data['公司加价'] = $money_json['price_coplus']; + $money_json['price_color'] && $car_data['颜色加价'] = $money_json['price_color']; + $car_data['定金'] = $money_json['price_book']; + $car_price_list = []; + $money_json['price_discount'] && $car_price_list['优惠'] = $money_json['price_discount']; + $car_data['最终售价'] =[ + 'list' => $car_price_list, + 'value' => $orders_entity->total_price($row['id']) + ]; + //服务费 + $srv_data = $orders_entity->order_srv_money($row['id'],1); + if($srv_data['total']>0){ + $car_data['委托代办']['value'] = $srv_data['total']; + foreach($srv_data['list'] as $val){ + $car_data['委托代办']['list'][$val['title']] = $val['money']; + } + if($row['fines']){ + $fines = json_decode($row['fines'],true); + $fines_list = []; + foreach ($fines as $item) { + $fines_list['list'][$item['txt']] = $item['price']; + } + $fines_list['value'] = $money_json['price_fine_select'] ? $money_json['price_fine_select'] : 0.00; + $car_data['委托代办']['list']['精品选装'] = $fines_list; + } + } + } + if(!$row['payway'] && $row['brand_id']){ + $finance_row = $this->sys_finance_model->get(['id'=>$row['finance_id']],'title'); + $car_data['按揭信息'] = $finance_row['title'] ? $finance_row['title']: ''; + } + //是否存在意向金订单 + $inten_row = $this->app_liche_orders_model->get(['o_id'=>$row['id'],'type'=>4,'status>='=>0]); + $pay_status = 0; + $inten_money = 0; + if($inten_row && $inten_row['status']==0){ + $pay_status = 1; + } + if($inten_row['status']==1){//已支付意向金 + $inten_money = floatval($inten_row['total_price']); + } + + $data = [ + 'id' => $id, + 'name' => $row['name'], + 'mobile' => mobile_asterisk($row['mobile']), + 'admin_img' => $orders_entity::API_ADMIN_IMG, + 'payway' => $row['brand_id'] ? $row['payway'] : '', + 'car_data' => $car_data, + 'pay_status' => $pay_status, + 'pay_img' => $orders_entity::API_PAY_IMG, + 'pack_id' => $row['pack_id'], + 'brand_id' => $row['brand_id'], + 'car_id' => $row['s_id'], + 'v_id' => $row['v_id'], + 'color_id' => $row['cor_id'], + 'incolor_id' => $row['incor_id'], + 'delry_time' => $row['delry_time']!='0000-00-00 00:00:00' ? date('Y-m-d',strtotime($row['delry_time'])):'', + 'finance_id' => !$row['payway'] ? $row['finance_id'] : '', + 'deposit' => $money_json['price_book'] ? $money_json['price_book'] : 0, + 'disc_money' => $money_json['price_discount'] ? $money_json['price_discount'] : '', + 'disc_fine_money' => $money_json['price_fine_discount'] ? $money_json['price_fine_discount'] : 0, + 'srv_arr' => $row['srv_ids'] ? json_decode($row['srv_ids'],true) : [], + 'cus_id' => $row['customer_id'], + 'status' => $row['status'], + 'my_img' => $orders_entity::API_CREATE_PAY_IMG, + 'if_fine' => $row['if_fine'] ? 1 : 0, + 'main_type' => intval($row['main_type']), + 'fines' => $row['fines'] ? json_decode($row['fines'],true) : [], + 'address' => $info_json['c_address'] ? $info_json['c_address'] : '' + ]; + if($row['main_type']){ + $info_json['c_credit'] && $data['credit'] = $info_json['c_credit']; + $info_json['c_company'] && $data['company'] = $info_json['c_company']; + }else{ + $data['owner_name'] = $row['owner_name']; + $data['owner_mobile'] = $row['owner_mobile']; + $data['owner_cardid'] = $info_json['c_owner_cardid']; + } + $data['cardid'] = $info_json['c_cardid']; + $inten_money && $data['inten_money'] = $inten_money; + //选择随车物品 + $ckcar_status = 0; + if($this->receiver_order_status_model->count(['o_id'=>$row['id'],'pid_status'=>3,'status'=>1]) && !$this->receiver_order_status_model->count(['o_id'=>$row['id'],'pid_status'=>4,'status'=>1])){ + $ckcar_status = 1; + } + $delivery = $this->order_deliverys_model->get(['o_id'=>$row['id']],'status,info,tool,remark'); + $ckcar_data = [ + 'info' => $delivery['info'] ? explode(',',$delivery['info']) : [], + 'tool' => $delivery['tool'] ? explode(',',$delivery['tool']) : [], + 'remark' => $delivery['remark'] ? $delivery['remark'] : '' + ]; + $data['ckcar_status'] = $ckcar_status; + $data['ckcar_data'] = $ckcar_data; + $price_book = $this->app_liche_orders_model->count(['o_id'=>$row['id'],'type'=>1,'status'=>1]); //定金是否支付 + $data['price_book_status'] = $price_book ? true : false; + $price_srv = $this->app_liche_orders_model->count(['o_id'=>$row['id'],'type'=>2,'status'=>1]); //服务费是否支付 + $data['price_srv_status'] = $price_srv ? true : false; + $price_last = $this->app_liche_orders_model->count(['o_id'=>$row['id'],'type'=>3,'status'=>1]); //尾款是否支付 + $data['price_last_status'] = $price_last ? true : false; + $data['edit_status'] = $price_last ? 0 : 1; + $data['loan_status'] = true; + + $loan_row = $this->order_loans_model->get(['o_id'=>$row['id']]); + $data['notify_file'] = [ + 'src' => $loan_row['notify_file'] ? build_qiniu_image_url($loan_row['notify_file']) : '', + 'value' => $loan_row['notify_file'] ? $loan_row['notify_file'] : '' + ]; + $data['lend_file'] = [ + 'src' => $loan_row['lend_file'] ? build_qiniu_image_url($loan_row['lend_file']) : '', + 'value' => $loan_row['lend_file'] ? $loan_row['lend_file'] : '' + ]; + $data['price_loan'] = $money_json['price_loan'] ? $money_json['price_loan'] : 0.00; + return $data; + } + + private function lists(){ + $group_id = $this->session['group_id']; + $uid = $this->session['uid']; + $keyword = $this->input_param('keyword'); + $status = $this->input_param('status'); + $page = $this->input_param('page'); + $size = $this->input_param('size'); + + !$page && $page = 1; + !$size && $size = 10; + + $where = [ + 'status>=' => 0, + 'biz_id' => $this->biz_id, + ]; + + $group_id == 1 && $where['sale_id'] = $uid;//销售 + if($group_id == 4 && $this->biz_id!=1){ + $where['brand_id!='] = 3; //渠道经理过滤 + } + + if($keyword){ + $where["(name='{$keyword}' or mobile='{$keyword}')"] = null; + } + if($status == 11 ){ //进行中 + $where['status'] = 0; + }elseif($status == 12 ){ //已完成 + $where['status'] = 1; + }else{ + strlen($status) && $where['status'] = $status; + } + $fileds = 'id,name,mobile,brand_id,s_id,v_id,cor_id,incor_id,payway,status,c_time,money_json,if_num'; + $count = $this->orders_model->count($where); + $lists = []; + if($count){ + $rows = $this->orders_model->select($where,'id desc',$page,$size,$fileds); + //品牌车型 + $brand_arr = array_unique(array_column($rows,'brand_id')); + $brands = $this->auto_brand_model->get_map_by_ids($brand_arr,'id,name'); + //车系车型 + $series_arr = array_unique(array_column($rows,'s_id')); + $series = $this->auto_series_model->get_map_by_ids($series_arr,'id,name'); + + //获取车辆属性 + $version_arr = array_unique(array_column($rows,'v_id')); + $color_arr = array_unique(array_column($rows,'cor_id')); + $attrs_arr = array_merge($version_arr,$color_arr); + $attrs = $this->auto_attr_model->get_map_by_ids($attrs_arr,'id,title'); + //旧订单数据 + $old_rows = []; + $old_ids = array_unique(array_column($rows,'id')); + if($old_ids){ + $ids_str = implode(',',$old_ids); + $where = [ + "id in ({$ids_str})" => null, + ]; + $old_rows = $this->receiver_orders_model->map('id','status',$where,'','','','id,status'); + } + + //获取订单资料 + $order_datas = $this->receiver_order_datas_model->get_map_by_oids(array_column($rows,'id'),'id,o_id,cardida,business_licence,car_img,register_img,ins_img,other_img'); + $status_arr = $this->orders_model->get_status(); + $old_status_arr = $this->receiver_orders_model->get_status(); + foreach($rows as $key=>$val){ + if($val['id']>=Orders_v2_entity::V2_START_ID){ + $money_json = json_decode($val['money_json'],true); + if($val['brand_id']){ //已选择车型 + $brand_name = isset($brands[$val['brand_id']]) ? $brands[$val['brand_id']][0]['name'] : ''; + $serie_name = isset($series[$val['s_id']]) ? $series[$val['s_id']][0]['name'] : ''; + $color = isset($attrs[$val['cor_id']]) ? $attrs[$val['cor_id']][0]['title'] : ''; + $version = isset($attrs[$val['v_id']]) ? $attrs[$val['v_id']][0]['title'] : ''; + $title = "{$brand_name}{$serie_name}-{$color}-{$version}"; + + $img_status = $this->order_datas_entity->data_status($order_datas[$val['id']][0]); + $ck_user_status = $this->receiver_order_status_model->count(['o_id'=>$val['id'],'pid_status'=>4,'status'=>2]); //用户已确认 + $ck_admin_status = $this->receiver_order_status_model->count(['o_id'=>$val['id'],'pid_status'=>4,'status'=>1]); //顾问确认已确认 + $ck_status = [ + ['value'=>'顾问确认','selected'=>$ck_admin_status?true:false], + ['value'=>'用户确认','selected'=>$ck_user_status?true:false] + ]; + + $other_data = [ + '品牌车型' => ['type'=> 'text','value'=>$title,'bg_color'=>''], + '付款方式' => ['type'=> 'text','value'=>$val['payway']?'全款':'分期','bg_color'=>''], + ]; + $book_is_pay = $this->app_liche_orders_model->get(['o_id'=>$val['id'],'type'=>1]); //定金 + $p_row = $this->app_liche_orders_model->get(['o_id'=>$val['id'],'pid'=>0],'id'); //父订单 + $last_row = $this->app_liche_orders_model->get(['o_id'=>$val['id'],'pid'=>$p_row['id'],'type'=>3],'id'); //尾款订单 + //除去尾款已支付金额 + $total_pay = $this->app_liche_orders_model->sum('total_price',['pid'=>$p_row['id'],'o_id'=>$val['id'],'status'=>1,'id!='=>$last_row['id']]); + //已支付尾款 + $last_pay = $this->app_liche_orders_model->sum('total_price',['pid'=>$last_row['id'],'status'=>1]); + $is_pay_price = $total_pay['total_price'] + $last_pay['total_price']; + $need_pay = $this->orders_v2_entity->recevable_price($val['id'],false); //需要支付车款 + $need_last_pay = $need_pay - $money_json['price_book']; + if($book_is_pay){ + $book_is_pay_text = $book_is_pay['status'] ? '已支付':'未支付'; + $price_book_text = $money_json['price_book']."($book_is_pay_text)"; + $other_data['定金金额'] = ['type'=> 'text','value'=>$price_book_text,'bg_color'=>'']; + } + $last_is_pay_text = $is_pay_price == $need_pay ? '已支付':'未支付'; + $last_text = $need_last_pay."($last_is_pay_text)"; + $other_data['尾款金额'] = ['type'=> 'text','value'=>$last_text,'bg_color'=>'']; + + if($book_is_pay['status'] || $this->app_liche_orders_model->count(['o_id'=>$val['id'],'type'=>6,'status'=>1])){ + if(!$val['payway']){ + $other_data['分期办理'] = ['type'=> 'text','value'=>$this->orders_status_entity->status_cn($val['id'],1),'bg_color'=>'']; + } + $other_data['车辆分配'] = ['type'=> 'text','value'=>$this->orders_status_entity->status_cn($val['id'],2),'bg_color'=>'']; + $other_data['发票'] = ['type'=> 'text','value'=>$this->orders_status_entity->status_cn($val['id'],3),'bg_color'=>'']; + $other_data['身份证'] = ['type'=> 'text','value'=>$img_status['cardida']['text'],'bg_color'=>$img_status['cardida']['color']]; + $other_data['登记证'] = ['type'=> 'text','value'=>$img_status['register_img']['text'],'bg_color'=>$img_status['register_img']['color']]; + $other_data['行驶证'] = ['type'=> 'text','value'=>$img_status['car_img']['text'],'bg_color'=>$img_status['car_img']['color']]; + $other_data['保单'] = ['type'=> 'text','value'=>$img_status['ins_img']['text'],'bg_color'=>$img_status['ins_img']['color']]; + $other_data['交车合照'] = ['type'=> 'text','value'=>$img_status['other_img']['text'],'bg_color'=>$img_status['other_img']['color']]; + $other_data['交付'] = ['type'=> 'checkbox','value'=>'','lists' => $ck_status,'bg_color'=>'']; + } + $other_data['订单日期'] = ['type'=> 'text','value'=>date('Y-m-d',$val['c_time']),'bg_color'=>'']; + }else{ + $price_intention = $money_json['price_intention'] ? $money_json['price_intention'] : ''; + $other_data = [ + '意向金' => ['type'=> 'text','value'=> $price_intention,'bg_color'=>''], + '订单日期' => ['type'=> 'text','value'=>date('Y-m-d',$val['c_time']),'bg_color'=>''], + ]; + } + $lists[] = [ + 'id' => $val['id'], + 'name' => $val['name'], + 'mobile' => mobile_asterisk($val['mobile']), + 'status_name' => $status_arr[$val['status']], + 'other_data' => $other_data, + ]; + }else{//旧订单 + $status = $old_rows[$val['id']] ? $old_rows[$val['id']] : 0; + $money_json = json_decode($val['money_json'],true); + if($val['brand_id']){ //已选择车型 + $brand_name = isset($brands[$val['brand_id']]) ? $brands[$val['brand_id']][0]['name'] : ''; + $serie_name = isset($series[$val['s_id']]) ? $series[$val['s_id']][0]['name'] : ''; + $color = isset($attrs[$val['cor_id']]) ? $attrs[$val['cor_id']][0]['title'] : ''; + $version = isset($attrs[$val['v_id']]) ? $attrs[$val['v_id']][0]['title'] : ''; + //是否需要代办 + $srv_arr = explode(',',$val['srv_ids']); + $db_title = in_array(2,$srv_arr) ? '需要' : ''; + + $other_data = [ + '品牌车型' => "{$brand_name}{$serie_name}-{$color}-{$version}", + '付款方式' => $val['payway']?'全款':'分期', + '代办车牌' => $db_title, + '定金金额' => $money_json['price_book'], + '订单日期' => date('Y-m-d',$val['c_time']), + ]; + }else{ + $other_data = [ + '意向金' => $money_json['price_intention'] ? $money_json['price_intention'] : '', + '订单日期' => date('Y-m-d',$val['c_time']), + ]; + } + $lists[] = [ + 'id' => $val['id'], + 'name' => $val['name'], + 'mobile' => mobile_asterisk($val['mobile']), + 'status_name' => $old_status_arr[$status], + 'other_data' => $other_data, + 'remark' => $this->orders_entity->get_remark($status) + ]; + } + } + } + $data = [ + 'list' => $lists, + 'total' => $count + ]; + return $data; + } + //订单列表头部 + protected function get_tabs(){ + $lists = [ + ['key' =>11 ,'name' => '进行中'], + ['key' =>12 ,'name' => '已完成'], + ]; + return $lists; + } + + //修改用户基本信息 + protected function put_info(){ + $id = $this->input_param('id'); + $owner_name = trim($this->input_param('owner_name')); + $owner_mobile = trim($this->input_param('owner_mobile')); + $owner_cardid = trim($this->input_param('owner_cardid')); + $company = $this->input_param('company'); + $c_credit = $this->input_param('credit'); + $address = $this->input_param('address'); + + $row = $this->orders_model->get(['id'=>$id]); + if(!$row){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + $data = []; + $owner_name && $data['owner_name'] = $owner_name; + $owner_mobile && $data['owner_mobile'] = $owner_mobile; + $info_json = json_decode($row['info_json'],true); + $owner_cardid && $info_json['c_owner_cardid'] = $owner_cardid; + $c_credit && $info_json['c_credit'] = $c_credit; + $company && $info_json['c_company'] = $company; + $address && $info_json['c_address'] = $address; + $info_json && $data['info_json'] = json_encode($info_json,JSON_UNESCAPED_UNICODE); + $result = $this->orders_model->update($data,['id'=>$row['id']]); + if($result){ + if($this->receiver_order_contracts_model->count(['o_id'=>$row['id'],'type in (0,1)'=>null])){ + $this->receiver_order_contracts_model->delete(['o_id'=>$row['id'],'type in (0,1)'=>null]); + } + throw new Exception('修改成功', API_CODE_SUCCESS); + }else{ + throw new Exception('修改失败', ERR_PARAMS_ERROR); + } + } + + protected function put_status(){ + $id = $this->input_param('id'); + $row = $this->orders_model->get(['id'=>$id]); + if(!$row){ + throw new Exception('订单不存在', ERR_PARAMS_ERROR); + } + $is_pay = $this->app_liche_orders_model->count(['o_id'=>$row['id'],'status'=>1]); + if($is_pay){ + throw new Exception('修改失败', ERR_PARAMS_ERROR); + } + $result = $this->orders_model->update(['status'=>-1],['id'=>$row['id']]); + if($result){ + $this->app_liche_orders_model->update(['status'=>-1],['o_id'=>$row['id']]); + throw new Exception('修改成功', API_CODE_SUCCESS); + }else{ + throw new Exception('修改失败', ERR_PARAMS_ERROR); + } + } +} diff --git a/api/controllers/wxapp/licheb/Cusorderdata.php b/api/controllers/wxapp/licheb/Cusorderdata.php new file mode 100644 index 00000000..8fcea47e --- /dev/null +++ b/api/controllers/wxapp/licheb/Cusorderdata.php @@ -0,0 +1,192 @@ +login_white = array();//登录白名单 + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg =array();//授权微信信息 + + $this->load->model('receiver/order/receiver_orders_v2_model','orders_model'); + $this->load->model('receiver/order/receiver_order_status_model'); + $this->load->model('receiver/order/receiver_order_datas_model'); + + $this->load->library('receiver/orders_status_entity'); + $this->load->library('TcOrc'); + } + + protected function get(){ + $id = $this->input_param('id'); + $row = $this->receiver_order_status_model->get(['o_id'=>$id,'status'=>1,'pid_status'=>0]); + $data = []; + if($row){ + $data['img_status'] = 1; + $row_data = $this->receiver_order_datas_model->get(['o_id'=>$id]); + $cardidb = $cardida = $business_licence = $register_img = $car_img = []; + if($row_data['car_img']){ + $car_img = [ + 'value' => $row_data['car_img'], + 'img' => build_qiniu_image_url($row_data['car_img']) + ]; + } + if($row_data['register_img']){ + $register_img = [ + 'value' => $row_data['register_img'], + 'img' => build_qiniu_image_url($row_data['register_img']) + ]; + } + $data['imgs'] = [ + 'cardida' => [], + 'cardidb' => [], + 'business_licence' => [], + 'car_img' => $car_img, + 'register_img' => $register_img, + 'ins_img' => [], + 'other_img' => [] + ]; + + if($row['main_type']){ + if($row_data['business_licence']){ + $business_licence = [ + 'value' => $row_data['business_licence'], + 'img' => build_qiniu_image_url($row_data['business_licence']) + ]; + } + $data['imgs']['business_licence'] = $business_licence; + }else{ + if($row_data['cardida']){ + $cardida = [ + 'value' => $row_data['cardida'], + 'img' => build_qiniu_image_url($row_data['cardida']) + ]; + } + if($row_data['cardidb']){ + $cardidb = [ + 'value' => $row_data['cardidb'], + 'img' => build_qiniu_image_url($row_data['cardidb']) + ]; + } + $data['imgs']['cardida'] = $cardida; + $data['imgs']['cardidb'] = $cardidb; + } + if($row_data['ins_img']){ + $ins_img = json_decode($row_data['ins_img'],true); + $imgs = []; + foreach ($ins_img as $item) { + $imgs[] = [ + 'value' => $item, + 'img' => build_qiniu_image_url($item) + ]; + } + $data['imgs']['ins_img'] = $imgs; + } + if($row_data['other_img']){ + $other_img = json_decode($row_data['other_img'],true); + $imgs = []; + foreach ($other_img as $item) { + $imgs[] = [ + 'value' => $item, + 'img' => build_qiniu_image_url($item) + ]; + } + $data['imgs']['other_img'] = $imgs; + } + if($row_data['bill_img']){ //开票 + $imgs = []; + $data['imgs']['bill_img'] = $imgs; + } + }else{ + $data['img_status'] = 0; + + } + return $data; + } + + protected function put(){ + $id = $this->input_param('id'); + $row = $this->orders_model->get(['id'=>$id]); + if(!$row){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + if(!$this->receiver_order_datas_model->get(['o_id'=>$id])){ + $this->receiver_order_datas_model->add(['o_id'=>$id]); + } + $cardida = $this->input_param('cardida'); + $cardidb = $this->input_param('cardidb'); + $car_img = $this->input_param('car_img'); + $register_img = $this->input_param('register_img'); + $business_licence = $this->input_param('business_licence'); + $ins_imgs = $this->input_param('ins_imgs'); + $other_imgs = $this->input_param('other_imgs'); + $update = []; + if($cardida){ + $full_cardida = build_qiniu_image_url($cardida); + $result = $this->tcorc->IdentityCard($full_cardida); + if(!$result['code']){ + $res_data['code'] = API_CODE_ORC_FAIL; + $res_data['data'] = [ + ['caridA' => false,'errmsg'=>$result['msg']], + ['caridB' => true,'errmsg'=>''], + ]; + return $res_data; + } + $userinfo = $result['data']; + + //校验订单客户和身份证姓名 + if($userinfo['Name'] != $row['owner_name']){ + $res_data['code'] = API_CODE_ORC_FAIL; + $res_data['data'] = [ + ['caridA' => false,'errmsg'=>'身份证姓名与客户不一致'], + ['caridB' => true,'errmsg'=>''], + ]; + return $res_data; + } + $update['cardida'] = $cardida; + }elseif ($business_licence){ + $full_business_licence = build_qiniu_image_url($business_licence); + $result = $this->tcorc->BizLicense($full_business_licence); + if(!$result['code']){ + $res_data['code'] = API_CODE_ORC_FAIL; + $res_data['data'] = [ + ['business_licence' => false,'errmsg'=>$result['msg']], + ]; + return $res_data; + } + $update['business_licence'] = $business_licence; + }elseif($ins_imgs || $other_imgs){ + $file_name = $ins_imgs ? 'ins_img' : 'other_img'; + $imgs = $ins_imgs ? $ins_imgs : $other_imgs; + $update[$file_name] = json_encode($imgs,JSON_UNESCAPED_UNICODE); + }else{ + if($cardidb){ + $key = 'cardidb'; + $img = $cardidb; + } + if($car_img){ + $key = 'car_img'; + $img = $car_img; + } + if($register_img){ + $key = 'register_img'; + $img = $register_img; + } + $key && $update[$key] = $img; + } + $res = $this->receiver_order_datas_model->update($update,['o_id'=>$id]); + if($res){ + $this->orders_status_entity->set_status($id,0,1); + throw new Exception('修改成功', API_CODE_SUCCESS); + }else{ + throw new Exception('修改失败', ERR_PARAMS_ERROR); + } + } +} \ No newline at end of file diff --git a/api/controllers/wxapp/licheb/Loan.php b/api/controllers/wxapp/licheb/Loan.php index 82845734..a2915ad5 100644 --- a/api/controllers/wxapp/licheb/Loan.php +++ b/api/controllers/wxapp/licheb/Loan.php @@ -17,89 +17,66 @@ class Loan extends Wxapp{ $this->check_status = array();//用户状态校验 $this->check_mobile = array();//需要手机号 $this->check_headimg =array();//授权微信信息 - $this->load->model('receiver/order/receiver_order_loans_model','order_loans_model'); - $this->load->model('receiver/order/receiver_orders_model','orders_model'); - $this->load->model('auto/auto_cars_model'); + $this->load->model('app/liche/app_liche_users_model'); + $this->load->model('app/liche/app_liche_orders_model'); + + $this->load->model('receiver/order/receiver_orders_v2_model'); + $this->load->model('receiver/order/receiver_order_loans_model', 'order_loans_model'); + + $this->load->library('receiver/orders_v2_entity'); + $this->load->library('receiver/orders_status_entity'); } protected function get(){ - $oid = $this->input_param('oid'); - - $row = $this->orders_model->get(['id'=>$oid]); - $where_car = array( - 's_id'=>$row['s_id'], - 'v_id' => $row['v_id'], - ); - $car = $this->auto_cars_model->get($where_car,'first_pay'); - $money = $car['first_pay'] ? $car['first_pay'] * 36 : 0; - $banks = [ - '易鑫金融' - ]; - $years = [ - 36 - ]; - $data = [ - 'banks' => $banks, - 'years' => $years, - 'first_price' => $money - ]; - return $data; } protected function post(){ - $oid = $this->input_param('oid'); - $bank = $this->input_param('bank'); - $year = $this->input_param('year'); - $money = $this->input_param('money'); - $loan = $this->order_loans_model->count(['o_id'=>$oid]); - if($loan){ - throw new Exception('创建失败', ERR_PARAMS_ERROR); - } - $row = $this->orders_model->get(['id'=>$oid]); - if(!$row || !$bank || !$year || !$money){ - throw new Exception('参数错误', ERR_PARAMS_ERROR); - } - $add_data = [ - 'o_id' => $oid, - 'title' => $bank, - 'year' => $year, - 'first_price' => $money - ]; - $l_id = $this->order_loans_model->add($add_data); - if($l_id){ - $data = [ - 'id' => $l_id, - 'bank' => $bank, - 'year' => $year, - 'money' => $money - ]; - return $data; - }else{ - throw new Exception('创建失败', ERR_PARAMS_ERROR); - } + } protected function put(){ - $id = $this->input_param('id'); - $bank = $this->input_param('bank'); - $year = $this->input_param('year'); - $money = $this->input_param('money'); + $oid = $this->input_param('o_id'); + $finance_id = $this->input_param('finance_id'); + $notify_file = $this->input_param('notify_file'); + $lend_file = $this->input_param('lend_file'); + $price_loan = $this->input_param('price_loan'); - $row = $this->order_loans_model->get(['id'=>$id]); + + $order_row = $this->receiver_orders_v2_model->get(['id' => $oid], 'id,mobile,money_json,payway'); + $row = $this->order_loans_model->get(['o_id' => $oid]); + if(!$finance_id || !$notify_file || !$price_loan || !$order_row || $order_row['payway']){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } if(!$row){ - throw new Exception('数据不存在', ERR_PARAMS_ERROR); + $row['id'] = $this->order_loans_model->add(['c_time'=>time(),'o_id'=>$oid]); } - $update = [ - 'title' => $bank, - 'year' => $year, - 'first_price' => $money - ]; + $price_last = $this->app_liche_orders_model->get(['o_id'=>$oid,'type'=>3,'status'=>1]); //尾款是否支付 + $last_pay = $this->app_liche_orders_model->count(['o_id'=>$oid,'pid'=>$price_last['id'],'status'=>1]); //存在已支付尾款 - $result = $this->order_loans_model->update($update,['id'=>$id]); - if($result){ - throw new Exception('修改成功', API_CODE_SUCCESS); - }else{ - throw new Exception('修改失败', ERR_PARAMS_ERROR); + if($last_pay){ + if($lend_file){ + $update['lend_file'] = $lend_file; + $this->order_loans_model->update($update, ['id' => $row['id']]); + throw new Exception('保存成功', API_CODE_SUCCESS); + }else{ + throw new Exception('当前状态不可修改', API_CODE_FAIL); + } } + + $money_json = json_decode($order_row['money_json'], true); + $money_json['price_loan'] = $price_loan; + $this->receiver_orders_v2_model->update(['finance_id' => $finance_id, 'money_json' => json_encode($money_json, JSON_UNESCAPED_UNICODE)], ['id' => $order_row['id']]); + //删除未支付订单 + $this->app_liche_orders_model->delete(['o_id'=>$row['o_id'],'status'=>0,'pid!='=>0,'type!='=>1]); + //生成购车订单 + $userinfo = $this->app_liche_users_model->get(['mobile'=>$order_row['mobile']]); + $this->orders_v2_entity->add_order($order_row['id'],$userinfo['id']); + $this->orders_status_entity->set_status($oid,1,1); + $update = [ + 'notify_file' => $notify_file + ]; + $lend_file && $update['lend_file'] = $lend_file; + $update && $result = $this->order_loans_model->update($update, ['id' => $row['id']]); + throw new Exception('保存成功', API_CODE_SUCCESS); } } diff --git a/api/controllers/wxapp/licheb/Protocol.php b/api/controllers/wxapp/licheb/Protocol.php index d6ddd270..268e9c2d 100644 --- a/api/controllers/wxapp/licheb/Protocol.php +++ b/api/controllers/wxapp/licheb/Protocol.php @@ -13,6 +13,7 @@ class Protocol extends CI_Controller{ public function __construct(){ parent::__construct(); $this->load->model('receiver/order/receiver_orders_model','orders_model'); + $this->load->model('receiver/order/receiver_orders_v2_model'); $this->load->model('receiver/order/receiver_order_contracts_model','contracts_model'); $this->load->model('receiver/order/receiver_order_agents_model','agents_model'); $this->load->model('receiver/order/receiver_order_loans_model','loans_model'); @@ -33,6 +34,7 @@ class Protocol extends CI_Controller{ $this->load->model("sys/sys_company_model"); $this->load->model("items/items_model"); $this->load->model('app/liche/app_liche_orders_model'); + $this->load->library('receiver/orders_v2_entity'); $wxapp = $this->input->get('wxapp'); $this->folder = $wxapp ? 'protocol' : 'html2pdf'; @@ -377,4 +379,70 @@ class Protocol extends CI_Controller{ $row['cid'] = $contract['cid']; $this->load->view("wxapp/licheb/{$this->folder}/agent_sp",$row); } + + public function pdf_img(){ + $this->load->library('receiver/sign_entity'); + $id = $this->input->get('id'); + $row = $this->contracts_model->get(['id'=>$id]); + $order = $this->receiver_orders_v2_model->get(['id'=>$row['o_id']]); + $show_imgs = []; + if($row['file']){ + if(!$row['imgs']){ + $this->load->library('pdf'); + $pdf_url = http_host_com('api').'/'.$row['file']; + $imgs = $this->pdf->pdf2img($pdf_url); + if($imgs){ + if(!$row['flag']){ + $companys = $this->orders_v2_entity->get_biz_mchid($order['biz_id']); + $img_seal = build_qiniu_image_url($companys['company']['img_seal']); + $width = 325; + if($row['type']==1){ + $sign_img = $imgs[1]; + $img_seal = build_qiniu_image_url($companys['srv_company']['img_seal']); + $res = $this->sign_entity->merge_img($sign_img,$img_seal,$width,950); + $imgs[1] = http_host_com('api').'/'.$res; + }elseif($row['type']==3){ + $sign_img = $imgs[0]; + $res = $this->sign_entity->merge_img($sign_img,$img_seal,$width,1550); + $imgs[0] = http_host_com('api').'/'.$res; + } else{ //购车协议 + $sign_img = $imgs[2]; + $res = $this->sign_entity->merge_img($sign_img,$img_seal,$width,400); + $imgs[2] = http_host_com('api').'/'.$res; + } + } + $imgs = $this->up_qiniu($imgs,$res); + $update['imgs'] = json_encode($imgs,JSON_UNESCAPED_UNICODE); + foreach ($imgs as $item) { + $show_imgs[] = build_qiniu_image_url($item); + } + $this->contracts_model->update($update,['id'=>$row['id']]); + } + }else{ + $imgs = json_decode($row['imgs'],true); + foreach ($imgs as $item) { + $show_imgs[] = build_qiniu_image_url($item); + } + } + } + $data['imgs'] = $show_imgs; + $this->load->view("wxapp/licheb/pdf_img",$data); + } + + //图片上传七牛 + private function up_qiniu($imgs,$file){ + $this->load->library('qiniu'); + //上传七牛并保存 + foreach($imgs as $key=>$val){ + $file_name = md5($val).'.jpg'; + $result = $this->qiniu->fetch($val,$file_name); + if($result){ + $imgs[$key] = $result['file']; + if (strpos($val, $file) !== false) { + @unlink(FCPATH.$file); + } + } + } + return $imgs; + } } diff --git a/api/controllers/wxapp/licheb/Services.php b/api/controllers/wxapp/licheb/Services.php index 64d17ce8..a7c94911 100644 --- a/api/controllers/wxapp/licheb/Services.php +++ b/api/controllers/wxapp/licheb/Services.php @@ -64,10 +64,22 @@ class Services extends Wxapp{ $rows = $this->services_model->select($where,'','','','id,title,field_name'); foreach($rows as $key=>$val){ $field_arr = explode('.',$val['field_name']); + $price = $price_arr[$field_arr[1]] && $field_arr[1]!='price_insure' ? $price_arr[$field_arr[1]] : 0; + if($val['price_insure']=='fee_carno'){ + $price_list = [1000,1200,1600]; + }elseif ($val['price_insure']=='price_finance'){ + $price_list = [1000,1500,2000]; + }else{ + $price_list = $price>0 ? [$price,$price+200,$price+400] : []; + } + $list[] = [ 'id' => $val['id'], 'title' => $val['title'], - 'price' => $price_arr[$field_arr[1]] && $field_arr[1]!='price_insure' ? $price_arr[$field_arr[1]] : 0 + 'key' => $field_arr[1], + 'text' => $field_arr[1] == 'price_insure' ? '由保险公司收取' : '', + 'price' => $price, + 'price_list' => $price_list ]; } } diff --git a/api/views/wxapp/licheb/pdf_img.php b/api/views/wxapp/licheb/pdf_img.php new file mode 100644 index 00000000..66aa9d70 --- /dev/null +++ b/api/views/wxapp/licheb/pdf_img.php @@ -0,0 +1,18 @@ + + + + + + + 服务协议 + + + + +# + + + \ No newline at end of file diff --git a/common/helpers/comm_helper.php b/common/helpers/comm_helper.php index 07418da0..6279cba7 100644 --- a/common/helpers/comm_helper.php +++ b/common/helpers/comm_helper.php @@ -1138,3 +1138,17 @@ if (!function_exists('myTrim')) { return $str; } } + +/** + * 判断是否正式环境 + */ +if (!function_exists('is_product')) { + function is_product() + { + if (false !== strpos($_SERVER['HTTP_HOST'], 'dev') || false !== strpos($_SERVER['HTTP_HOST'], 'test')) { //dev 测试 + return false; + } else { // 正式 + return true; + } + } +} diff --git a/common/libraries/Pdftk.php b/common/libraries/Pdftk.php new file mode 100644 index 00000000..4da7dd80 --- /dev/null +++ b/common/libraries/Pdftk.php @@ -0,0 +1,131 @@ +is_dev = true; + $this->dev_api_url = 'https://liche-api-dev.xiaoyu.com/'; + } + } + + /** + * pdf文件表单域填充 + * @param $pdf_path string pdf文件地址 + * @param $save_path string 填充后文件保存路径 + * @param $fill_data array 填充域对应内容['field'=>'text'] + * @return array + */ + public function fill_pdf($pdf_path,$save_path,$fill_data){ + $pdf_path = FCPATH.$pdf_path; + $save_path = FCPATH.$save_path; + if($this->is_dev){ + $ci = & get_instance(); + $ci->load->library('mycurl'); + $file_name = str_replace(FCPATH,"",$pdf_path); + $p_data = [ + 'file_url' => $this->dev_api_url.$file_name, + 'fill_data' => json_encode($fill_data) + ]; + $result = $ci->mycurl->httpPost($this->api_url.'pdfapi/fill_pdf',$p_data); + $resdata = json_decode($result,true); + $opt = false; + $data = []; + if($resdata['code'] && $resdata['data']['file_path']){ + $save_path_arr = explode('/',$save_path); + array_pop($save_path_arr); + $tmp_path = implode('/',$save_path_arr); + if (!file_exists($tmp_path)) { + $oldumask = umask(0); + mkdir($tmp_path, 0777, true); + umask($oldumask); + } + $arrContextOptions = [ + "ssl" => [ + "verify_peer"=>false, + "verify_peer_name"=>false, + ], + + ]; + $file = file_get_contents($resdata['data']['file_path'],false,stream_context_create($arrContextOptions)); + file_put_contents($save_path, $file); + if(file_exists($save_path)){ + $opt = true; + $data['file_path'] = str_replace(FCPATH,'',$save_path); + } + } + if($opt){ + return ['code'=>1,'msg'=>'保存成功','data' => $data]; + }else{ + return ['code'=>0,'msg'=>'保存失败']; + } + }else{ + $pdf = new Pdf($pdf_path); + $result = $pdf->fillForm($fill_data)->needAppearances()->saveAs($save_path); + if ($result === false) { + return ['code'=>0,'msg'=>$pdf->getError()]; + }else{ + $data['file_path'] = $save_path; + return ['code'=>1,'msg'=>'保存成功',$data]; + } + + } + } + + /** + * e签宝填充pdf表单域 + * @param $pdf_path + * @param $save_path + * @param $fill_data + * @return array + */ + public function esign_fill_pdf($pdf_path,$save_path,$fill_data){ + $pdf_path = FCPATH.$pdf_path; + $save_path = FCPATH.$save_path; + require_once COMMPATH."/third_party/esign/eSignOpenAPI.php"; + try { + $sign = new \tech\core\eSign(); + $iRet = $sign->init(); + if (0 !== $iRet) { + dir('初始化失败'); + return ['code' => 0 ,'msg' => '初始化失败']; + } + $tmpFile=array( + 'srcFileUrl' =>$pdf_path, + 'dstFileUrl' => '' + ); + $ret = $sign->createFromTemplate($tmpFile,true,$fill_data,true); + if($ret['errCode']!==0){ + return ['code' => 0 ,'msg' => $ret['msg']]; + } + $save_path_arr = explode('/',$save_path); + array_pop($save_path_arr); + $tmp_path = implode('/',$save_path_arr); + if (!file_exists($tmp_path)) { + $oldumask = umask(0); + mkdir($tmp_path, 0777, true); + umask($oldumask); + } + file_put_contents($save_path, base64_decode($ret['stream']), true); + if(file_exists($save_path)){ + $data['file_path'] = str_replace(FCPATH,'',$save_path); + return ['code' => 1 ,'msg'=>'保存成功','data' => $data]; + }else{ + return ['code' => 0 ,'msg' => '保存失败']; + } + } catch (Exception $e) { + return ['code' => 0 ,'msg' => '初始化出错:'.$e->getMessage()]; + } + } +} diff --git a/common/libraries/Qyrobot.php b/common/libraries/Qyrobot.php index 2b8c3923..1b2c72cf 100644 --- a/common/libraries/Qyrobot.php +++ b/common/libraries/Qyrobot.php @@ -107,4 +107,90 @@ class Qyrobot{ $result = json_decode($res,true); return $result; } + + /** + * 支付后推送消息 + * @param $oid + * @return mixed + */ + public function deposit_notify_v2($oid){ + $this->ci->load->model('receiver/order/receiver_orders_v2_model'); + $this->ci->load->model("biz/biz_model"); + $this->ci->load->model('area_model'); + $this->ci->load->model('auto/auto_brand_model'); + $this->ci->load->model('auto/auto_series_model'); + $this->ci->load->model('auto/auto_attr_model'); + + $this->ci->load->model('app/liche/app_liche_orders_model'); + $this->ci->load->model('app/liche/app_liche_orders_model'); + $this->ci->load->model('app/licheb/app_licheb_users_model'); + $this->ci->load->model('app/licheb/app_licheb_channel_biz_model'); + + $order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); + if(!$order_row){ + return false; + } + $biz_row = $this->ci->biz_model->get(['id'=>$order_row['biz_id']]); + if($biz_row['type']==3){ + $channel_users = $this->ci->app_licheb_channel_biz_model->select(['biz_id'=>$biz_row['id']],'','','','uid'); + $user_ids = array_column($channel_users,'uid'); + $user_ids_str = implode(',',$user_ids); + $user_info = ''; + if($user_ids_str && $user_ids){ + $where = [ + 'group_id' => 4, + 'status' => 1, + "id in ($user_ids_str)" => null + ]; + $users = $this->ci->app_licheb_users_model->select($where,'id desc',1,10,'uname,biz_id'); //渠道经理 + if($users){ + $user_info = implode(' ',array_column($users,'uname')); + }else{ //获取城市 + $city_row = $this->ci->area_model->get(['city_id'=>$biz_row['city_id']]); + $user_info = $city_row['city_name']; + } + } + $biz_info = "{$user_info}渠道 {$biz_row['biz_name']}"; + }else{ + $user = $this->ci->app_licheb_users_model->get(['id'=>$order_row['admin_id']],'uname'); //获取销售员 + $biz_info = "{$biz_row['biz_name']} {$user['uname']}"; + } + $brand_row = $this->ci->auto_brand_model->get(['id'=>$order_row['brand_id']],'name'); + $series_row = $this->ci->auto_series_model->get(['id'=>$order_row['s_id']],'name'); + $attr_arr = [$order_row['v_id'], $order_row['cor_id']]; + $attr = $this->ci->auto_attr_model->get_map_by_ids($attr_arr, 'id,title'); + $v_name = isset($attr[$order_row['v_id']]) ? $attr[$order_row['v_id']][0]['title'] : ''; + $cor_name = isset($attr[$order_row['cor_id']]) ? $attr[$order_row['cor_id']][0]['title'] : ''; + $car_info = "{$brand_row['name']} {$series_row['name']} {$v_name} {$cor_name}"; + + $min_price = 100; + $today_s_time = date('Y-m-d 00:00:00'); + $sql = "select count(*) as total from (select min(pay_time) as pay_time,min(pay_price) as pay_price from lc_app_liche_orders + where o_id>=10000 and status=1 and pid!=0 and pay_time!='0000-00-00 00:00:00' group by o_id order by o_id desc)a + where pay_price>{$min_price} and pay_time>='{$today_s_time}'"; + $today_query = $this->ci->db->query($sql)->row_array(); + $month_s_time = date('Y-m-01 00:00:00'); + $sql = "select count(*) as total from (select min(pay_time) as pay_time,min(pay_price) as pay_price from lc_app_liche_orders + where o_id>=10000 and status=1 and pid!=0 and pay_time!='0000-00-00 00:00:00' group by o_id order by o_id desc)a + where pay_price>{$min_price} and pay_time>='{$month_s_time}'"; + $month_query = $this->ci->db->query($sql)->row_array(); + $today_count = $today_query['total']; + $month_count = $month_query['total']; + + $url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='.$this->key; + $this->ci->load->library('mycurl'); + $data = [ + 'msgtype' => 'markdown', + 'markdown' => [ + 'content' => "🎉🎉🎉 **喜讯** 🎉🎉🎉 \n + 恭喜 {$biz_info} 成交 {$car_info} 一台。\n + >本日累计成交: {$today_count} 单 + >本月累计成交: {$month_count} 单\n + ### 狸车加油,冲冲冲!💪🏻💪🏻💪🏻" + ] + ]; + $res = $this->ci->mycurl->httpPost($url,$data,'is_json'); + $result = json_decode($res,true); + return $result; + } } diff --git a/common/libraries/receiver/Order_datas_entity.php b/common/libraries/receiver/Order_datas_entity.php new file mode 100644 index 00000000..10c394a0 --- /dev/null +++ b/common/libraries/receiver/Order_datas_entity.php @@ -0,0 +1,108 @@ +ci = & get_instance(); + $this->ci->load->model('receiver/order/receiver_order_datas_model'); + $this->ci->load->model('app/app_checkdata_model'); + } + + public function data_status($o_data){ + $result = [ + 'cardida' => ['text'=>'未传','type'=>1,'color'=>self::COLOR_UN_UPLOAD], //身份证 + 'register_img' => ['text'=>'未传','type'=>2,'color'=>self::COLOR_UN_UPLOAD], //登记证 + 'car_img' => ['text'=>'未传','type'=>3,'color'=>self::COLOR_UN_UPLOAD], //行驶证 + 'ins_img' => ['text'=>'未传','type'=>4,'color'=>self::COLOR_UN_UPLOAD], //保单证 + 'other_img' => ['text'=>'未传','type'=>5,'color'=>self::COLOR_UN_UPLOAD], //交车合照 + ]; +// $where = ['cf_id'=>$o_data['id'],'app_id'=>2,'type in (1,2,3,4,5)'=>null,'datatype'=>'img']; +// $check_data = $this->ci->app_checkdata_model->map('type','',$where,'','','','id,cf_id,type,ifcheck'); + foreach ($result as $key=>$item) { + if($o_data[$key]){ + $result[$key]['text'] = '已传'; + $result[$key]['color'] = self::COLOR_IS_UPLOAD; +// if($check_data[$item['type']][0]['ifcheck']==1){ +// $result[$key]['text'] = '已通过'; +// $result[$key]['color'] = self::COLOR_CHECK; +// } +// if($check_data[$item['type']][0]['ifcheck']==-1){ +// $result[$key]['text'] = '未通过'; +// $result[$key]['color'] = self::COLOR_UN_CHECK; +// } + } + } + return $result; + } + + //获取图片审核状态 + public function data_ckinfo($o_data,$main_type=0){ + if($main_type){ + $result = [ + 'business_licence' => ['text'=>'营业执照','type'=>1,'up_status'=>0,'status'=>0,'status_cn'=>'未审核','imgs' => []], //身份证 + 'register_img' => ['text'=>'登记证','type'=>2,'up_status'=>0,'status'=>0,'status_cn'=>'未审核','imgs' => []], //登记证 + 'car_img' => ['text'=>'行驶证','type'=>3,'up_status'=>0,'status'=>0,'status_cn'=>'未审核','imgs'=>[]], //行驶证 + 'ins_img' => ['text'=>'保单证','type'=>4,'up_status'=>0,'status'=>0,'status_cn'=>'未审核','imgs'=>[]], //保单证 + 'other_img' => ['text'=>'交车合照','type'=>5,'up_status'=>0,'status'=>0,'status_cn'=>'未审核','imgs'=>[]], //交车合照 + ]; + }else{ + $result = [ + 'cardida' => ['text'=>'身份证正反面','type'=>1,'up_status'=>0,'status'=>0,'status_cn'=>'未审核','imgs' => []], //身份证 + 'register_img' => ['text'=>'登记证','type'=>2,'up_status'=>0,'status'=>0,'status_cn'=>'未审核','imgs' => []], //登记证 + 'car_img' => ['text'=>'行驶证','type'=>3,'up_status'=>0,'status'=>0,'status_cn'=>'未审核','imgs'=>[]], //行驶证 + 'ins_img' => ['text'=>'保单证','type'=>4,'up_status'=>0,'status'=>0,'status_cn'=>'未审核','imgs'=>[]], //保单证 + 'other_img' => ['text'=>'交车合照','type'=>5,'up_status'=>0,'status'=>0,'status_cn'=>'未审核','imgs'=>[]], //交车合照 + ]; + } + $where = [ + 'cf_id'=>$o_data['id'], + 'app_id'=>2, + 'type in (1,2,3,4,5)'=>null, + 'datatype'=>'img' + ]; + $check_data = $this->ci->app_checkdata_model->map('type','',$where,'','','','id,cf_id,type,ifcheck'); + foreach ($result as $key=>$item) { + if($o_data[$key]){ + $result[$key]['up_status'] = 1; + $ifcheck = $check_data[$item['type']][0]['ifcheck']; + $imgs = []; + if($key=='ins_img'||$key=='other_img'){ + $img_data = json_decode($o_data[$key],true); + foreach ($img_data as $v) { + $imgs[] = build_qiniu_image_url($v); + } + }else{ + $imgs[] = build_qiniu_image_url($o_data[$key]); + if($key=='cardida' && $o_data['cardidb']){ + $imgs[] = build_qiniu_image_url($o_data['cardidb']); + } + } + $result[$key]['imgs'] = $imgs; + if($ifcheck==1){ + $result[$key]['status_cn'] = '已通过'; + $result[$key]['status'] = 1; + }elseif($ifcheck==-1){ + $result[$key]['status_cn'] = '未通过'; + $result[$key]['status'] = -1; + }else{ + $result[$key]['status_cn'] = '未审核'; + $result[$key]['status'] = 0; + } + } + } + return $result; + } + +} diff --git a/common/libraries/receiver/Orders_status_entity.php b/common/libraries/receiver/Orders_status_entity.php new file mode 100644 index 00000000..7f5354c6 --- /dev/null +++ b/common/libraries/receiver/Orders_status_entity.php @@ -0,0 +1,105 @@ +ci = & get_instance(); + $this->ci->load->model('receiver/order/receiver_order_status_model'); + } + + /** + * 完成状态 + * @param $oid + * @param $pid_status + * @param $status + * @return bool + */ + public function set_status($oid,$pid_status,$status){ + $row = $this->ci->receiver_order_status_model->get(['o_id' => $oid,'pid_status'=>$pid_status,'status'=>$status]); + if($row){ + return False; + } + $data = [ + 'o_id' => $oid, + 'pid_status' => $pid_status, + 'status' => $status, + 'c_time' => time() + ]; + $res = $this->ci->receiver_order_status_model->add($data); + return $res; + } + + /** + * 获取主状未完成 + * @param $o_id + * @param $pid_status + * @return string + */ + public function status_cn($o_id,$pid_status){ + $status_cn = ''; + $status_arr = $this->ci->receiver_order_status_model->get_status(); + $sub_status = $status_arr[$pid_status]; + if($sub_status){ + $key = count($sub_status); + for ($key;$key>=0;$key--){ + if(!$key && !$this->ci->receiver_order_status_model->count(['o_id'=>$o_id,'pid_status'=>$pid_status,'status'=>$key])){ //0时 + $status_cn = $sub_status[$key]; + break; + }else{ + if($this->ci->receiver_order_status_model->count(['o_id'=>$o_id,'pid_status'=>$pid_status,'status'=>$key])){ + $status_cn = $sub_status[$key]; + break; + } + } + } + } + return $status_cn; + } + + /** + * 判断否个状态是否全部完成 + * @param $o_id + * @param $pid_status + * @param $status + * @return bool + */ + public function get_finish($o_id,$pid_status,$status){ + $count = $this->ci->receiver_order_status_model->count(['o_id'=>$o_id,'pid_status'=>$pid_status,'status'=>$status]); + if($count){ + return true; + }else{ + return false; + } + } + + /** + * 获取订单最新子状态 + * @param $oid 订单id + * @param $pid_status 主状态id + * @return string + */ + public function last_status_cn($oid,$pid_status){ + $where=[ + 'o_id' => $oid, + 'pid_status' => $pid_status + ]; + $row = $this->ci->receiver_order_status_model->get($where,"id,max(status) as last_status"); + $status_arr = $this->ci->receiver_order_status_model->get_status(); + if($row['id']){ + if($status_arr[$pid_status][$row['last_status']]){ + return $status_arr[$pid_status][$row['last_status']]; + }else{ + return array_pop($status_arr[$pid_status]); + } + }else{ + return $status_arr[$pid_status][0]; + } + } +} \ No newline at end of file diff --git a/common/libraries/receiver/Orders_v2_entity.php b/common/libraries/receiver/Orders_v2_entity.php new file mode 100644 index 00000000..103d0dd4 --- /dev/null +++ b/common/libraries/receiver/Orders_v2_entity.php @@ -0,0 +1,633 @@ +ci = & get_instance(); + $this->ci->load->model('receiver/receiver_customers_model','customers_model'); + + $this->ci->load->model('receiver/order/receiver_orders_v2_model'); + $this->ci->load->model('receiver/order/receiver_order_signs_model','signs_model'); + $this->ci->load->model('receiver/order/receiver_order_deliverys_model','deliverys_model'); + $this->ci->load->model('receiver/order/receiver_order_contracts_model'); + + $this->ci->load->model('receiver/receiver_service_package_model','package_model'); + $this->ci->load->model('receiver/receiver_services_model','services_model'); + + $this->ci->load->model('sys/sys_city_model'); + $this->ci->load->model("sys/sys_company_model"); + + $this->ci->load->model('apporder/order_purchase_model'); + $this->ci->load->model('auto/auto_brand_model'); + $this->ci->load->model('auto/auto_series_model'); + $this->ci->load->model('auto/auto_attr_model'); + $this->ci->load->model("items/items_model"); + + $this->ci->load->model("biz/biz_model"); + $this->ci->load->model('app/liche/app_liche_orders_model'); + } + + //创建意向金订单 + public function c_intention($oid,$uid,$money){ + $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); + if(!$this->order_row){ + return false; + } + $p_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],"(uid={$uid} or entrust_uid={$uid})"=>null,'pid'=>0,'status>='=>0]); + $entrust_user = $this->entrust_user($oid); + if(!$p_row){ + $sid = create_order_no(350200,'liche',1,0); + $add_data = [ + 'o_id' => $this->order_row['id'], + 'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0, + 'sid' => $sid, + 'pid' => 0, + 'brand_id' => $this->order_row['brand_id'], + 's_id' => $this->order_row['s_id'], + 'v_id' => $this->order_row['v_id'], + 'cor_id' => $this->order_row['cor_id'], + 'incor_id' => $this->order_row['incor_id'], + 'c_time' => time() + ]; + $uid && $add_data['uid'] = $uid; + $pid = $this->ci->app_liche_orders_model->add($add_data); + }else{ + $pid = $p_row['id']; + } + $res = false; + $sub_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],"(uid={$uid} or entrust_uid={$uid})"=>null,'type'=>4,'status>='=>0]); + if($pid && !$sub_row){ + //获取微信商户号 + $companys = $this->get_biz_mchid($this->order_row['biz_id']); + $sid = create_order_no(350200,'liche',1,4); + $sub_data = [ + 'o_id' => $this->order_row['id'], + 'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0, + 'sid' => $sid, + 'mch_id' => $companys['company']['wx_mchid'], + 'company_id' => $companys['company']['id'], + 'pid' => $pid, + 'type' => 4, + 'brand_id' => $this->order_row['brand_id'], + 's_id' => $this->order_row['s_id'], + 'v_id' => $this->order_row['v_id'], + 'cor_id' => $this->order_row['cor_id'], + 'incor_id' => $this->order_row['incor_id'], + 'total_price' => $money, + 'c_time' => time() + ]; + $uid && $sub_data['uid'] = $uid; + $res = $this->ci->app_liche_orders_model->add($sub_data); + } + return $res; + } + /** + * 获取商家微信商户号 + * @param $biz_id int 商家id + * @return array ['company'=>[],'srv_company'=>[]] + */ + public function get_biz_mchid($biz_id){ + $biz = $this->ci->biz_model->get(['id'=>$biz_id],'type,city_id,company_id,srv_company_id,car_brand_id'); + $filed = 'id,wx_mchid,title,short,credit_code,wx_mchid,img_seal'; + if(in_array($biz['type'],[1])){ //品牌店 + $where = [ + "id in ({$biz['company_id']},{$biz['srv_company_id']})" => null + ]; + $companys = $this->ci->sys_company_model->map('wx_mchid','',$where,'','','',$filed); + $company = $companys[$biz['company_id']][0]; + $srv_company = $companys[$biz['srv_company_id']][0]; + }else{ //其它店铺 + $brand_biz = $this->ci->biz_model->get(['city_id'=>$biz['city_id'],'type'=>1,'status'=>1,'car_brand_id'=>$biz['car_brand_id']],'type,city_id,company_id,srv_company_id'); + if($brand_biz){ + $where = [ + "id in ({$biz['company_id']},{$biz['srv_company_id']})" => null + ]; + $companys = $this->ci->sys_company_model->map('wx_mchid','',$where,'','','',$filed); + $company = $companys[$biz['company_id']][0]; + $srv_company = $companys[$biz['srv_company_id']][0]; + } + } + if(!$company){ //获取城市销售公司 + $company = $this->ci->sys_company_model->get(['city_id'=>$biz['city_id'],'type'=>1],$filed); + } + if(!$srv_company){ //获取城市服务公司 + $srv_company = $this->ci->sys_company_model->get(['city_id'=>$biz['city_id'],'type'=>0],$filed); + } + $data = [ + 'company' => $company, + 'srv_company' => $srv_company + ]; + return $data; + } + /** + * 获取代办人用户信息 + * @param $oid int 订单id + * @return array + */ + public function entrust_user($oid){ + $this->ci->load->model('app/liche/app_liche_users_model'); + + !$this->order_row && $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); + if(!$this->order_row){ + return []; + } + $user = $this->ci->app_liche_users_model->get(['mobile'=>$this->order_row['owner_mobile']]); + return $user; + } + /** + * 获取订单服务费 + * @param $oid int 订单id + * @param $res_type string 返回数据格式 + * @return int + */ + public function order_srv_money($oid,$res_type = ''){ + if(!$this->order_row){ + $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); + } + $money_json = json_decode($this->order_row['money_json'],true); + $srv_price = 0; + $list = []; //明细 + $services = json_decode($this->order_row['srv_ids'],true); + + if($services){ + $srv_ids = array_column($services,'id'); + $ids = implode(',',$srv_ids); + if($srv_ids){ + $where["id in ($ids)"] = null; + $rows = $this->ci->services_model->map('id','title',$where,'','','','id,title'); + } + foreach($services as $key=>$val){ + if($val['key']!='price_insure'){ //保险费不收 + $srv_price += $money_json[$val['key']]; + $list[] = [ + 'title' => $rows[$val['id']], + 'money' => $money_json[$val['key']] + ]; + } + if($val['key']=='price_insure' && $res_type==1){ + $list[] = [ + 'title' => $rows[$val['id']], + 'money' => '由保险公司收取' + ]; + } + } + } + if($this->order_row['if_fine']){ //选择精品包 + $fine_price = $money_json['price_fine']; + if($money_json['price_fine_discount']){ //优惠精品价格 + $fine_price = $fine_price - $money_json['price_fine_discount']; + } + $srv_price += $fine_price; + $list[] = [ + 'title' => '精品尊享包', + 'money' => $fine_price + ]; + } + if($this->order_row['fines']){ + $price_fine_select = $money_json['price_fine_select'] ? $money_json['price_fine_select'] : 0; + $list[] = [ + 'title' => '精品选装', + 'money' => $price_fine_select, + ]; + $srv_price += $price_fine_select; + } + $result['total'] = $srv_price; + $result['list'] = $list; + return $res_type ? $result:$srv_price; + } + + /** + * 生成定金订单 + * @param $oid int 订单id + * @param $uid int 小程序用户id + * @return bool + */ + public function add_book_order($oid,$uid){ + $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); + if(!$this->order_row){ + return false; + } + $pay_money = $this->ci->app_liche_orders_model->get(['o_id'=>$oid,'type'=>4,'status>='=>0]); //意向金订单 + + $money_json = json_decode($this->order_row['money_json'],true); + $deposit_count = $this->ci->app_liche_orders_model->count(['o_id'=>$oid,'type'=>1,'status'=>1]); //定金已支付 + $need_pay_money = $money_json['price_book'] - $pay_money['total_price']; + $res = false; + if($need_pay_money > 0 && !$deposit_count){ + $entrust_user = $this->entrust_user($this->order_row['id']); + $p_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'pid'=>0,'status>='=>0]); + if(!$p_row){ + $sid = create_order_no(350200,'liche',1,0); + $add_data = [ + 'o_id' => $this->order_row['id'], + 'sid' => $sid, + 'pid' => 0, + 'brand_id' => $this->order_row['brand_id'], + 's_id' => $this->order_row['s_id'], + 'v_id' => $this->order_row['v_id'], + 'cor_id' => $this->order_row['cor_id'], + 'incor_id' => $this->order_row['incor_id'], + 'c_time' => time() + ]; + $uid && $add_data['uid'] = $uid; + $entrust_user['id'] && $add_data['entrust_uid'] = $entrust_user['id']; + $pid = $this->ci->app_liche_orders_model->add($add_data); + }else{ + $pid = $p_row['id']; + } + $sub_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'type'=>1,'status>='=>0]); + if($pid && !$sub_row){ + //获取微信商户号 + $companys = $this->get_biz_mchid($this->order_row['biz_id']); + $sid = create_order_no(350200,'liche',1,1); + $sub_data = [ + 'o_id' => $this->order_row['id'], + 'sid' => $sid, + 'mch_id' => $companys['company']['wx_mchid'], + 'company_id' => $companys['company']['id'], + 'pid' => $pid, + 'type' => 1, + 'brand_id' => $this->order_row['brand_id'], + 's_id' => $this->order_row['s_id'], + 'v_id' => $this->order_row['v_id'], + 'cor_id' => $this->order_row['cor_id'], + 'incor_id' => $this->order_row['incor_id'], + 'total_price' => $need_pay_money, + 'c_time' => time() + ]; + $entrust_user['id'] && $sub_data['entrust_uid'] = $entrust_user['id']; + $uid && $sub_data['uid'] = $uid; + $res = $this->ci->app_liche_orders_model->add($sub_data); + } + } + return $res; + } + + /** + * 创建服务费和尾款 + * @param $oid + * @param $uid + * @return bool + */ + public function add_order($oid,$uid){ + $this->ci->load->helper('order'); + $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); + $p_row = $this->ci->app_liche_orders_model->get(['pid'=>0,'o_id'=>$oid,'status>='=>0],'id'); //父订单 + if(!$this->order_row || !$p_row){ + return false; + } + + //获取微信商户号 + $companys = $this->get_biz_mchid($this->order_row['biz_id']); + + $srv_money = $this->order_srv_money($oid); //服务费 + $money_json = json_decode($this->order_row['money_json'],true); + $total_price = $this->total_price($oid); + if(!$this->order_row['payway'] && !$money_json['price_loan']){//贷款未填写首付 + return false; + } + $to_srv_price = $srv_money; + if($this->order_row['payway']){ //全款 + $to_com_price = $total_price - $money_json['price_book']; + }else{ //分期 + $to_com_price = $total_price-$money_json['price_loan'] - $money_json['price_book']; + } + $to_com_price = $to_com_price>0 ? $to_com_price : 0; + $last_order = $this->ci->app_liche_orders_model->get(['status>='=>0,'type'=>3,'o_id'=>$oid]); + if($last_order){ //存在尾款订单 + if($last_order['total_price']!=$to_com_price && $to_com_price>0){ + $this->ci->app_liche_orders_model->update(['total_price'=>$to_com_price,'status'=>0],['id'=>$last_order['id']]); + } + return true; + } + $add_data = []; + $entrust_user = $this->entrust_user($oid); + if($to_srv_price>0 && !$this->ci->app_liche_orders_model->count(['o_id'=>$this->order_row['id'],'type'=>2,'status>='=>0])){ + $order_type = 2; + $sid = create_order_no(350200,'liche',1,$order_type); + $add_data[] = [ + 'o_id' => $this->order_row['id'], + 'uid' => $uid ? $uid : 0, + 'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0, + 'sid' => $sid, + 'mch_id' => $companys['srv_company']['wx_mchid'], + 'company_id' => $companys['srv_company']['id'], + 'pid' => $p_row['id'], + 'brand_id' => $this->order_row['brand_id'], + 's_id' => $this->order_row['s_id'], + 'v_id' => $this->order_row['v_id'], + 'cor_id' => $this->order_row['cor_id'], + 'incor_id' => $this->order_row['incor_id'], + 'total_price' => $to_srv_price, + 'type' => $order_type, + 'c_time' => time() + ]; + } + if($to_com_price>0 && !$this->ci->app_liche_orders_model->count(['o_id'=>$this->order_row['id'],'type'=>3,'status>='=>0])){ + $order_type = 3; + $sid = create_order_no(350200,'liche',1,$order_type); + $add_data[] = [ + 'o_id' => $this->order_row['id'], + 'uid' => $uid ? $uid : 0, + 'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0, + 'sid' => $sid, + 'mch_id' => $companys['company']['wx_mchid'], + 'company_id' => $companys['company']['id'], + 'pid' => $p_row['id'], + 'brand_id' => $this->order_row['brand_id'], + 's_id' => $this->order_row['s_id'], + 'v_id' => $this->order_row['v_id'], + 'cor_id' => $this->order_row['cor_id'], + 'incor_id' => $this->order_row['incor_id'], + 'total_price' => $to_com_price, + 'type' => $order_type, + 'c_time' => time() + ]; + } + $result = false; + if($add_data){ + $result = $this->ci->app_liche_orders_model->add_batch($add_data); + } + return $result; + } + + + /** + * 计算订单应收金额 + * @param $oid int 订单id + * @param $srv_price boolean 是否包含服务费 + * @return float + */ + public function recevable_price($oid,$srv_price=true){ + $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); + if(!$this->order_row){ + return false; + } + $money_json = json_decode($this->order_row['money_json'],true); + $total_price = $this->total_price($oid); + if($srv_price){ + $srv_money = $this->order_srv_money($oid); + $recevable_price = $total_price + $srv_money; + }else{ + $recevable_price = $total_price; + } + + if(!$this->order_row['payway']){ //分期 + $recevable_price -= $money_json['price_loan']; + } + return $recevable_price; + } + + /** + * 计算订单总售价 + * @param $oid int 订单id + * @return float + */ + public function total_price($oid){ + $order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid],'money_json'); + if(!$order_row){ + return false; + } + $money_json = json_decode($order_row['money_json'],true); + $total_price = $money_json['price_car']; + if($money_json['price_discount']){ + $total_price -= $money_json['price_discount']; + } + if($money_json['price_color']){ + $total_price += $money_json['price_color']; + } + if($money_json['price_coplus']){ + $total_price += $money_json['price_coplus']; + } + return $total_price ? $total_price : 0; + } + + /** + * 修改完订单信息后操作 + * @param array() $new_data 修改后的数据 + * @param array() $row 修改前数据 + */ + public function edit_order($new_data,$row){ + //更新购车订单车辆信息 + $up_data = [ + 'brand_id' => $new_data['brand_id'], + 's_id' => $new_data['s_id'], + 'v_id' => $new_data['v_id'], + 'cor_id' => $new_data['cor_id'], + 'incor_id' => $new_data['incor_id'], + ]; + $this->ci->app_liche_orders_model->update($up_data,['o_id'=>$row['id']]); + //删除未支付订单 + $this->ci->app_liche_orders_model->delete(['o_id'=>$row['id'],'status'=>0,'pid!='=>0]); + $userinfo = $this->ci->app_liche_users_model->get(['mobile'=>$new_data['mobile']],'id'); + if(!$this->ci->app_liche_orders_model->count(['o_id'=>$row['id'],'type'=>1,'status'=>1])){ //不存在订单订单 + $this->add_book_order($row['id'],$userinfo['id']); + } + $this->add_order($row['id'],$userinfo['id']); + //合同重新生成 + if($this->ci->receiver_order_contracts_model->count(['o_id'=>$row['id'],'type in (0,1)'=>null])){ + $this->ci->receiver_order_contracts_model->delete(['o_id'=>$row['id'],'type in (0,1)'=>null]); + } + } + + /** + * 生成pdf文件 + * @param $oid + * @throws Exception + */ + public function create_pdf($oid){ + $this->order_row = $this->ci->receiver_orders_v2_model->get(['id'=>$oid]); + if(!$this->order_row ){ + return ['code'=>0,'msg'=>'参数错误']; + } + if($this->ci->receiver_order_contracts_model->count(['o_id'=>$oid,'status'=>1])){ + return ['code'=>1,'msg'=>'操作成功']; + } + $fill_info = $this->pdf_data($this->order_row); + $fill_data = [ + 'sid' => $this->order_row['sid'], + 'give_time' => $fill_info['give_time'], + 'date' => $fill_info['now_day'], + 'company' => $fill_info['companys']['company']['title'], + 'name' => $fill_info['name'], + 'owner_name' => $fill_info['owner_name'], + 'owner_mobile' => $fill_info['owner_mobile'], + 'identify_type' => $fill_info['identify_type'], + 'identify' => $fill_info['identify'], + 'address' => $fill_info['address'], + 'version' => $fill_info['version'], + 'color' => $fill_info['color'], + 'incolor' => $fill_info['incolor'], + 'price_car' => $fill_info['price_car'], + 'price_discount' => $fill_info['price_discount'], + 'price_finance' => $fill_info['price_finance'], + 'recevable_price' => $fill_info['recevable_price'], + 'price_book' => $fill_info['price_book'], + 'last_price' => $fill_info['last_price'], + ]; + $pdf_path = 'pdf/car_tpl.pdf'; + $save_path = "pdf/{$this->order_row['sid']}/car.pdf"; + $this->ci->load->library('pdftk'); + $req = $this->ci->pdftk->esign_fill_pdf($pdf_path,$save_path,$fill_data); + if(!$req['code']){ + return ['code'=>0,'msg'=>$req['msg']]; + } + $add_data[] = [ + 'o_id' => $this->order_row['id'], + 'cid' => 0, + 'file' => $req['data']['file_path'] ? $req['data']['file_path'] : '', + 'type' => 0, + 'status' => 1, + 'c_time' => time() + ]; + if($this->order_row['srv_ids']){ + $fill_data = [ + 'sid' => $this->order_row['sid'], + 'date' => $fill_info['now_day'], + 'company' => $fill_info['companys']['srv_company']['title'], + 'name' => $fill_info['name'], + 'mobile' => $this->order_row['owner_mobile'], + 'service_str' => implode(' +',$fill_info['services']), + ]; + $pdf_path = 'pdf/agent_tpl.pdf'; + $save_path = "pdf/{$this->order_row['sid']}/service.pdf"; + $res = $this->ci->pdftk->esign_fill_pdf($pdf_path,$save_path,$fill_data); + if($res['code']){ + $add_data[] = [ + 'o_id' => $this->order_row['id'], + 'cid' => 0, + 'file' => $res['data']['file_path'] ? $res['data']['file_path'] : '', + 'type' => 1, + 'status' => 1, + 'c_time' => time() + ]; + } + } + $res = $this->ci->receiver_order_contracts_model->add_batch($add_data); + if($res){ + return ['code'=>1,'msg'=>'操作成功']; + }else{ + return ['code'=>0,'msg'=>'操作失败']; + } + } + + /** + * 获取填充内容 + * @param $row + * @param $type + * @return mixed + */ + public function pdf_data($row,$type=0){ + if(!$row){ + return false; + } + $this->ci->load->model('auto/auto_business_model'); + $info_json = json_decode($row['info_json'],true); + $business_id = $info_json['business_id'] ? $info_json['business_id'] : 0; + $data = []; + + //车辆信息 + $money_json = json_decode($row['money_json'],true); + $money_json['price_discount'] && $row['price'] = $row['price'] - $money_json['price_discount']; + $brand = $this->ci->auto_brand_model->get(['id'=>$row['brand_id']],'name'); + $series = $this->ci->auto_series_model->get(['id'=>$row['s_id']],'name'); + $version = $this->ci->auto_attr_model->get(['id'=>$row['v_id']],'title'); + $color = $this->ci->auto_attr_model->get(['id'=>$row['cor_id']],'title'); + $incolor = $this->ci->auto_attr_model->get(['id'=>$row['incor_id']],'title'); + $_version = $version['title'] ? $version['title'] : ''; + $data['version'] = "{$brand['name']} {$series['name']} $_version"; + $data['color'] = $color['title'] ? $color['title'] : ''; + $data['incolor'] = $incolor['title'] ? $incolor['title'] : ''; + $business_row = $this->ci->auto_business_model->get(['id'=>$business_id]); + if($business_row){ + $data['give_time'] = $business_row['delivery_day']; + }else{ + if($row['s_id']==24) { //零跑T03 + $data['give_time'] = 60; + }elseif($row['s_id']==25) { //零跑C11 + $data['give_time'] = 120; + }else{ //其它车型 + $data['give_time'] = 45; + } + } + $data['price_car'] = number_format($money_json['price_car']+$money_json['price_color']+$money_json['price_coplus'],2); + $data['price_discount'] = number_format($money_json['price_discount'],2); + $data['price_book'] = number_format($money_json['price_book'],2); + $data['recevable_price'] = number_format($this->total_price($row['id']),2); + $data['last_price'] = number_format($this->total_price($row['id']) - $money_json['price_book'],2); + $data['address'] = $info_json['c_address'] ? $info_json['c_address'] : ''; + $data['name'] = $row['name']; + if($row['main_type']){ + $data['identify_type'] = '营业执照' ; + $data['identify'] = $info_json['c_credit']; + $data['owner_name'] = $info_json['c_company']; + $data['owner_mobile'] = $row['mobile']; + }else{ + $data['identify_type'] = '身份证'; + $data['identify'] = $info_json['c_owner_cardid']; + $data['owner_name'] = $row['owner_name']; + $data['owner_mobile'] = $row['owner_mobile']; + } + + $data['now_day'] = date('Y-m-d'); + $data['companys'] = $this->get_biz_mchid($row['biz_id']); + if($type==1){ + $items = $this->ci->items_model->get(['id'=>$row['item_id']],'vin'); + $delivery = $this->ci->deliverys_model->get(['o_id'=>$row['id']],'info,tool,remark'); + $data['vin'] = $items['vin']; + $data['delivery'] = $delivery; + } + if(!$type){ + $services = []; + $srv_arr = json_decode($row['srv_ids'],true); + $srv_ids = array_column($srv_arr,'id'); + $srv_ids_str = implode(',',$srv_ids); + if($row['srv_ids'] && $srv_ids_str){ + $service_rows = $this->ci->services_model->select(["id in ({$srv_ids_str})"=>null],'','','','id,title,field_name'); + foreach($service_rows as $key=>$val){ + $field_arr = explode('.',$val['field_name']); + if(isset($money_json[$field_arr[1]])){ //保险费不收 + $money = $field_arr[1]=='price_insure' ? '由保险公司收取' : $money_json[$field_arr[1]]; + is_numeric($money) && $money = number_format($money,2); + $services[] = $val['title'].': '.$money; + } + } + } + if($row['if_fine']){ //选择精品包 + $fine_price = $money_json['price_fine_discount'] ? $money_json['price_fine'] - $money_json['price_fine_discount'] : $money_json['price_fine']; + $services[] = '精品尊享包: '.number_format($fine_price,2); + } + if($row['fines']){ + $fines = json_decode($row['fines'],true); + $split = $fine_title_price = $fine_title = ''; + foreach($fines as $key=>$val){ + $fine_title = $fine_title.$split.$val['txt'].$split; + $price = number_format($val['price'],2); + $fine_title_price = $fine_title_price.$split."{$val['txt']}:{$price}"; + $split = ' '; + } + $services[] = '精品选装: '.number_format($money_json['price_fine_select'],2)."($fine_title_price)"; + } + $srv_price = $this->order_srv_money($row['id']); + $services[] = '实际支付(元): '.number_format($srv_price,2); + $data['services'] = $services; + } + return $data; + } +} diff --git a/common/libraries/receiver/Sign_entity.php b/common/libraries/receiver/Sign_entity.php index 58488ec6..c17cfb8d 100644 --- a/common/libraries/receiver/Sign_entity.php +++ b/common/libraries/receiver/Sign_entity.php @@ -62,6 +62,46 @@ class Sign_entity{ }else{ return false; } - } + } + /** + * 合并图片 + * @param $origin_url string 原始图片 + * @param $user_file string 需要合并图片 + * @param $width int x坐标 + * @param $height int y坐标 + * @param string $s_path string 图片保存地址 + * @return bool|mixed string 返回合成后图片地址 + * @throws Exception + */ + public function merge_img($origin_url,$user_file,$width,$height,$s_path='' ){ + $arrContextOptions=array( + "ssl"=>array( + "verify_peer"=>false, + "verify_peer_name"=>false, + ), + ); + //临时保存签名图片 + if (!file_exists(FCPATH.'/temp')){ + $oldumask = umask(0); + mkdir(FCPATH.'/temp', 0777, true); + umask($oldumask); + } + $file_name = time().rand(1,9999999); + !$s_path && $s_path = FCPATH.'temp/'.md5('sign'.$file_name).'.jpg'; + + $yhdata = file_get_contents($user_file,false,stream_context_create($arrContextOptions)); + $yh_image = Image::fromData($yhdata)->cropResize(200,200)->rotate(90); + + + //原始签名文件 + $data = file_get_contents($origin_url,false,stream_context_create($arrContextOptions)); + $imgobj = Image::fromData($data); + $imgobj->merge($yh_image,$width,$height)->save($s_path); + if(file_exists($s_path)){ + return str_replace(FCPATH,'',$s_path); + }else{ + return false; + } + } } diff --git a/common/models/app/App_checkdata_model.php b/common/models/app/App_checkdata_model.php new file mode 100644 index 00000000..19ed15dd --- /dev/null +++ b/common/models/app/App_checkdata_model.php @@ -0,0 +1,19 @@ +table_name, 'default'); + } + +} diff --git a/common/models/app/liche/App_liche_orders_model.php b/common/models/app/liche/App_liche_orders_model.php index b4d4956b..9ded4135 100644 --- a/common/models/app/liche/App_liche_orders_model.php +++ b/common/models/app/liche/App_liche_orders_model.php @@ -9,7 +9,7 @@ defined('BASEPATH') OR exit('No direct script access allowed'); class App_liche_orders_model extends HD_Model{ private $table_name = 'lc_app_liche_orders'; - private $type_arr = [ 1 => '定金', 2 => '委托服务费' , 3 => '尾款' ,4 => '意向金' ,5 => '后台添加']; + private $type_arr = [ 1 => '定金', 2 => '委托服务费' , 3 => '尾款' ,4 => '意向金' ,5 => '后台添加',6 => '车款']; public function __construct() { diff --git a/common/models/auto/Auto_business_model.php b/common/models/auto/Auto_business_model.php new file mode 100644 index 00000000..10bd25fe --- /dev/null +++ b/common/models/auto/Auto_business_model.php @@ -0,0 +1,25 @@ +table_name, 'default'); + } + + public function year(){ + return [2022,2023,2024,2025,2026]; + } + public function month(){ + return [1,2,3,4,5,6,7,8,9,10,11,12]; + } +} diff --git a/common/models/auto/Auto_cars_model.php b/common/models/auto/Auto_cars_model.php index cba7d2e7..55738591 100644 --- a/common/models/auto/Auto_cars_model.php +++ b/common/models/auto/Auto_cars_model.php @@ -93,8 +93,8 @@ class Auto_cars_model extends HD_Model{ $this->db->order_by($order); } if ($page) { - $offset = ($page - 1) * $page_size; - $limit = $page_size; + $offset = ($page - 1) * $size; + $limit = $size; } else { $offset = null; $limit = null; diff --git a/common/models/auto/Auto_series_model.php b/common/models/auto/Auto_series_model.php index d9711abc..0b5d3902 100644 --- a/common/models/auto/Auto_series_model.php +++ b/common/models/auto/Auto_series_model.php @@ -55,8 +55,8 @@ class Auto_series_model extends HD_Model{ $this->db->order_by($order); } if ($page) { - $offset = ($page - 1) * $page_size; - $limit = $page_size; + $offset = ($page - 1) * $size; + $limit = $size; } else { $offset = null; $limit = null; diff --git a/common/models/biz/Biz_info_model.php b/common/models/biz/Biz_info_model.php new file mode 100644 index 00000000..bc359d6f --- /dev/null +++ b/common/models/biz/Biz_info_model.php @@ -0,0 +1,13 @@ +table_name, 'default'); + } + +} diff --git a/common/models/biz/Biz_settle_model.php b/common/models/biz/Biz_settle_model.php new file mode 100644 index 00000000..c956e3ac --- /dev/null +++ b/common/models/biz/Biz_settle_model.php @@ -0,0 +1,38 @@ +table_name, 'default'); + } + + public function selectOrders($where = array(), $order = '', $page = 0, $page_size = 20, $count = 0,$fileds="lc_biz_settle.*") + { + $this->db->distinct()->select($fileds); + $this->db->from('lc_biz_settle'); + $this->db->join('lc_receiver_orders_v2', 'lc_receiver_orders_v2.id = lc_biz_settle.o_id','left'); + if ($where) { + $this->db->where($where); + } + if ($count) { + $res = $this->db->count_all_results(); + return $res ? $res : 0; + } + if ($order) { + $this->db->order_by($order); + } + if ($page) { + $offset = ($page - 1) * $page_size; + $limit = $page_size; + } else { + $offset = null; + $limit = null; + } + $this->db->limit($limit, $offset); + return $this->db->get()->result_array(); + } +} diff --git a/common/models/biz/Biz_settle_static_model.php b/common/models/biz/Biz_settle_static_model.php new file mode 100644 index 00000000..b75d5523 --- /dev/null +++ b/common/models/biz/Biz_settle_static_model.php @@ -0,0 +1,22 @@ +table_name, 'default'); + } + + //其它费用类型 + public function other_price_type(){ + $array = [ + 0 => '共同承担', + 1 => '狸车承担', + 2 => '合伙人承担' + ]; + return $array; + } +} diff --git a/common/models/biz/Biz_trucking_model.php b/common/models/biz/Biz_trucking_model.php new file mode 100644 index 00000000..8f2f0849 --- /dev/null +++ b/common/models/biz/Biz_trucking_model.php @@ -0,0 +1,13 @@ +table_name, 'default'); + } + +} diff --git a/common/models/receiver/order/Receiver_order_contracts_model.php b/common/models/receiver/order/Receiver_order_contracts_model.php index 46fb353d..65510587 100644 --- a/common/models/receiver/order/Receiver_order_contracts_model.php +++ b/common/models/receiver/order/Receiver_order_contracts_model.php @@ -14,12 +14,14 @@ class Receiver_order_contracts_model extends HD_Model private $type_arr = [ 0 => '整车合同',1 => '代理协议',2 => '车辆信息确定',3 => '交接信息', 4 => '合同补充协议', 5 => '委托服务补充协议']; + private $type_arr_new = [ 0 => '购车协议',1 => '服务协议',3=>'车辆确认']; + public function __construct() { parent::__construct($this->table_name, 'default'); } - public function get_types(){ - return $this->type_arr; + public function get_types($new = 0){ + return $new ? $this->type_arr_new : $this->type_arr; } } diff --git a/common/models/receiver/order/Receiver_order_datas_model.php b/common/models/receiver/order/Receiver_order_datas_model.php new file mode 100644 index 00000000..e24f4def --- /dev/null +++ b/common/models/receiver/order/Receiver_order_datas_model.php @@ -0,0 +1,48 @@ + '未上传', 1 => '已上传', 2 => '已审核', -1 => '审核不通过']; + + public function __construct() + { + parent::__construct($this->table_name, 'default'); + } + + public function get_ifcheck_cn() + { + return $this->ifcheck; + } + + /** + * Notes:根据id获取数据 + * Created on: 2021/7/15 17:27 + * @param $ids + * @param string $fileds + * @return array + */ + public function get_map_by_oids($oids, $fileds = '') + { + $rows = []; + $oids = array_filter($oids); + if ($oids) { + $cf_ids = implode(',', $oids); + $where = [ + "o_id in ($cf_ids)" => null + ]; + $rows = $this->map('o_id', '', $where, '', '', '', $fileds); + } + return $rows; + } + +} diff --git a/common/models/receiver/order/Receiver_order_status_model.php b/common/models/receiver/order/Receiver_order_status_model.php new file mode 100644 index 00000000..d296b9d6 --- /dev/null +++ b/common/models/receiver/order/Receiver_order_status_model.php @@ -0,0 +1,65 @@ + [0 => '待付款', 1 => '已付款'], //付款 + 1 => [0 => '分期办理中', 1 => '等待放款',2 => '完成按揭'], //分期 + 2 => [0 => '待分配', 1 => '已配车' ], //配车 + 3 => [0 => '待开票', 1 => '已开票'], //开票 + 4 => [0 => '待销售确认', 1 => '销售已确认',2 => '用户已确认'],//车辆交付 + 5 => [1 => '已完成'], //完成 +// 6 => [0 => '资料未上传', 1 => '国补审核', 2 => '已审核'] + ]; + + public function __construct() + { + parent::__construct($this->table_name, 'default'); + } + + /** + * Notes:订单状态 + * Created on: 2021/9/15 10:25 + * Created by: dengbw + * @param $status + * @return array + */ + public function statusAry($status = '') + { + $status_ary[0] = array('name' => '付款', 'show' => true, 'list' => array(0 => '未付款', 1 => '已付款'), + 'menu_list' => array(0 => '未付款', 1 => '已付款'), 'menu_default' => 0,'pid_status'=>0); + $status_ary[1] = array('name' => '分期办理', 'show' => true, 'list' => array(0 => '分期办理中', 1 => '等待放款' , 2 => '完成按揭'), + 'menu_list' => array(0 => '分期办理中', 1 => '等待放款' , 2 => '完成按揭'), 'menu_default' => 0,'pid_status'=>1); + $status_ary[2] = array('name' => '车辆分配', 'show' => true, 'list' => array(0 => '车辆分配中', 1 => '已配车'), + 'menu_list' => array(0 => '待分配', 1 => '已配车'), 'menu_default' => 0,'pid_status'=>2); + $status_ary[3] = array('name' => '开票相关', 'show' => true, 'list' => array(0 => '待开票', 1 => '已开票'), + 'menu_list' => array(0 => '待开票' , 1 => '已开票'), 'menu_default' => 0,'pid_status'=>3); + $status_ary[4] = array('name' => '交付车辆', 'show' => true, 'list' => array(0 => '待销售确认', 1 => '销售已确认', 2 => '用户已确认'), + 'menu_list' => array(0 => '待销售确认', 1 => '销售已确认', 2 => '用户已确认'), 'menu_default' => 0,'pid_status'=>4); + $status_ary[5] = array('name' => '交易完成', 'show' => true, 'list' => array(), 'menu_list' => array(),'pid_status'=>5); +// $status_ary[6] = array('name' => '资料审核', 'show' => true, 'list' => array(0 => '资料未上传', 1 => '国补审核中', 2 => '已审核'), +// 'menu_list' => array(0 => '资料未上传', 1 => '国补审核中', 2 => '已审核'), 'menu_default' => 0); + if (strlen($status)) { + $return_status = $status_ary[$status]; + } else { + $return_status = $status_ary; + } + return $return_status; + } + + public function get_status() + { + return $this->status_arr; + } + +} diff --git a/common/models/receiver/order/Receiver_orders_v2_model.php b/common/models/receiver/order/Receiver_orders_v2_model.php new file mode 100644 index 00000000..a28d5189 --- /dev/null +++ b/common/models/receiver/order/Receiver_orders_v2_model.php @@ -0,0 +1,54 @@ + '进行中', 1 => '已完成']; + + public function __construct() + { + parent::__construct($this->table_name, 'default'); + } + + public function get_status() + { + return $this->status_arr; + } + + public function selectOrders($where = array(), $order = '', $page = 0, $page_size = 20, $count = 0,$fileds="lc_receiver_orders_v2.*") + { + $this->db->select($fileds.",count(lc_receiver_order_status.status) as total"); + $this->db->from('lc_receiver_orders_v2'); + $this->db->join('lc_receiver_order_status', 'lc_receiver_order_status.o_id = lc_receiver_orders_v2.id','left'); + if ($where) { + $this->db->where($where); + } + $this->db->group_by('lc_receiver_order_status.o_id'); + $this->db->having('total = 1'); + if ($count) { + $res = $this->db->count_all_results(); + return $res ? $res : 0; + } + if ($order) { + $this->db->order_by($order); + } + if ($page) { + $offset = ($page - 1) * $page_size; + $limit = $page_size; + } else { + $offset = null; + $limit = null; + } + $this->db->limit($limit, $offset); + return $this->db->get()->result_array(); + } +} diff --git a/common/models/sys/Sys_company_model.php b/common/models/sys/Sys_company_model.php index 913252ec..4517d1e3 100644 --- a/common/models/sys/Sys_company_model.php +++ b/common/models/sys/Sys_company_model.php @@ -25,4 +25,13 @@ class Sys_company_model extends HD_Model return $statusAry; } + /** + * 类型 + * @return array + */ + function type_ary(){ + $typeAry = array(/*'-1' => '删除',*/ '0' => '服务公司', '1' => '销售公司'); + + return $typeAry; + } } \ No newline at end of file diff --git a/common/services/apporder/Payment_service.php b/common/services/apporder/Payment_service.php index 6089069a..5e6e4ea1 100644 --- a/common/services/apporder/Payment_service.php +++ b/common/services/apporder/Payment_service.php @@ -24,6 +24,7 @@ class Payment_service extends HD_Service{ $this->load->model('receiver/order/receiver_order_bills_model','bills_model'); $this->load->model('receiver/order/receiver_order_ckcars_model','ckcars_model'); $this->load->model('receiver/order/receiver_order_agents_model', 'order_agents_model'); + $this->load->model('receiver/order/receiver_orders_v2_model'); } @@ -134,120 +135,174 @@ class Payment_service extends HD_Service{ * @param date $pay_time 支付时间 */ public function after_pay_liche($sid,$pay_price = '',$descrip='',$pay_time=''){ - if($sid){ - debug_log("[start] ". __FUNCTION__ . ": sid:".$sid, $this->log_file); - $order = $this->app_liche_orders_model->get(array('sid'=>$sid)); - if(!$order){ - debug_log("[error] ". __FUNCTION__ . ":{$sid}_订单不存在", $this->log_file); - return array('code'=>0,'msg'=>'订单不存在'); - } - if($order['status']>0){ - debug_log("[error] ". __FUNCTION__ . ":{$sid}_订单已支付", $this->log_file); - return array('code'=>0,'msg'=>'订单已支付'); - } + debug_log("[start] ". __FUNCTION__ . ": sid:".$sid, $this->log_file); + $order = $this->app_liche_orders_model->get(array('sid'=>$sid)); + if(!$order){ + debug_log("[error] ". __FUNCTION__ . ":{$sid}_订单不存在", $this->log_file); + return array('code'=>0,'msg'=>'订单不存在'); + } + if($order['status']>0){ + debug_log("[error] ". __FUNCTION__ . ":{$sid}_订单已支付", $this->log_file); + return array('code'=>0,'msg'=>'订单已支付'); + } + switch ($order['type']){ + case 1: //定金 + $upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s')); + $pay_price && $upd['pay_price'] = $pay_price; + $descrip && $upd['descrip'] = $descrip; + $pay_time && $upd['pay_time'] = $pay_time; + $res = $this->app_liche_orders_model->update($upd,array('id'=>$order['id'])); + if($res) { + //更新订单状态 + $row = $this->orders_model->get(['id' => $order['o_id']]); + if ($row) { + if(!$this->bills_model->count(['o_id'=>$row['id']])){ + $this->bills_model->add(['o_id'=>$row['id'],'c_time'=>time]); + } + if(!$this->order_agents_model->count(['o_id'=>$row['id']])){ + $this->order_agents_model->add(['o_id'=>$row['id'],'status'=>-1,'c_time'=>time]); + } + $this->order_signs_model->update(['status' => 2], ['o_id' => $row['id']]); + if ($row['payway']) {//全款 + $status = 2; + $this->load->model('receiver/order/receiver_order_ckcars_model', 'next_model'); + } else { + $status = 1; + $this->load->model('receiver/order/receiver_order_loans_model', 'next_model'); + } + $next_row = $this->next_model->get(['o_id'=>$row['id']]); + $order_update = [ + 'status' => $status, + ]; + $row['order_time'] == '0000-00-00 00:00:00' && $order_update['order_time'] = date('Y-m-d H:i:s'); + $this->orders_model->update($order_update, ['id' => $row['id']]); + if(!$next_row){ + $add_data = [ + 'o_id' => $row['id'], + 'c_time' => time() + ]; + $this->next_model->add($add_data); + } + } + return array('code'=>1,'msg'=>'操作成功'); + }else{ + return array('code'=>0,'msg'=>'更新失败'); + } + break; + case 2: //服务费 + case 3: //尾款 + $upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s')); + $pay_price && $upd['pay_price'] = $pay_price; + $descrip && $upd['descrip'] = $descrip; + $pay_time && $upd['pay_time'] = $pay_time; + $res = $this->app_liche_orders_model->update($upd,array('id'=>$order['id'])); + if($res){ + $p_row = $this->app_liche_orders_model->get(['o_id'=>$order['o_id'],'pid'=>0,'status>='=>0]); + $last_p_row = $this->app_liche_orders_model->get(['o_id'=>$order['o_id'],'type'=>3,'pid'=>$p_row['id'],'status>='=>0]); //尾款父订单 + $where = [ + 'status'=>1, + 'o_id'=>$order['o_id'], + 'pid>'=>0 + ]; + $last_p_row && $where['id <>'] = $last_p_row['id']; + $is_pay = $this->app_liche_orders_model->sum('total_price',$where); //已支付金额 + $this->load->library('receiver/orders_entity'); + $need_pay_money = $this->orders_entity->recevable_price($order['o_id']); + if($is_pay['total_price']>=$need_pay_money){ //完成支付 + $ckcar_row = $this->ckcars_model->get(['o_id'=>$order['o_id']],'status'); + $row = $this->orders_model->get(['id'=>$order['o_id']],'id,status'); + if($row['status']==2 && $ckcar_row['status']==2){ + $this->ckcars_model->update(['status'=>3],['o_id'=>$row['id']]); + $this->orders_model->update(['status'=>3],['id'=>$row['id']]); + if(!$this->bills_model->count(['o_id'=>$row['id']])){ + $this->bills_model->add(['o_id'=>$row['id'],'status'=>1,'c_time'=>time()]); + }else{ + $this->bills_model->update(['status'=>1],['o_id'=>$row['id']]); + } + } + } + $last_is_pay = $this->app_liche_orders_model->sum('total_price',['status'=>1,'pid'=>$last_p_row['id']]); //已支付尾款 + if($last_is_pay['total_price']>=$last_p_row['total_price']){ + $this->app_liche_orders_model->update(['status'=>1,'pay_time'=>date('Y-m-d H:i:s')],['id'=>$last_p_row['id']]); + } + return array('code'=>1,'msg'=>'操作成功'); + }else{ + return array('code'=>0,'msg'=>'更新失败'); + } + break; + case 4: //意向金 + $upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s')); + $pay_price && $upd['pay_price'] = $pay_price; + $descrip && $upd['descrip'] = $descrip; + $pay_time && $upd['pay_time'] = $pay_time; + $res = $this->app_liche_orders_model->update($upd,array('id'=>$order['id'])); + if($res) { + //更新订单下定时间 + $this->orders_model->update(['order_time' => date('Y-m-d H:i:s')], ['id' => $order['o_id']]); + return array('code'=>1,'msg'=>'操作成功'); + }else{ + return array('code'=>0,'msg'=>'更新失败'); + } + break; + default: + debug_log("[error] ". __FUNCTION__ . ":{$order['type']}_未知商品类型", $this->log_file); + return array('code'=>0,'msg'=>'未知商品类型'); + } + } + + public function after_pay_liche_v2($sid,$pay_price = '',$pay_uid=''){ + debug_log("[start] ". __FUNCTION__ . ": sid:".$sid, $this->log_file); + $order = $this->app_liche_orders_model->get(array('sid'=>$sid)); + if(!$order){ + debug_log("[error] ". __FUNCTION__ . ":{$sid}_订单不存在", $this->log_file); + return array('code'=>0,'msg'=>'订单不存在'); + } + if($order['status']>0){ + debug_log("[error] ". __FUNCTION__ . ":{$sid}_订单已支付", $this->log_file); + return array('code'=>0,'msg'=>'订单已支付'); + } + $upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s')); + $pay_price && $upd['pay_price'] = $pay_price; + $pay_uid && $upd['pay_uid'] = $pay_uid; + $res = $this->app_liche_orders_model->update($upd,array('id'=>$order['id'])); + if($res) { + $p_row = $this->app_liche_orders_model->get(['o_id'=>$order['o_id'],'pid'=>0,'status>='=>0]); + $last_p_row = $this->app_liche_orders_model->get(['o_id'=>$order['o_id'],'type'=>3,'pid'=>$p_row['id'],'status>='=>0]); //尾款父订单 switch ($order['type']){ case 1: //定金 - $upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s')); - $pay_price && $upd['pay_price'] = $pay_price; - $descrip && $upd['descrip'] = $descrip; - $pay_time && $upd['pay_time'] = $pay_time; - $res = $this->app_liche_orders_model->update($upd,array('id'=>$order['id'])); - if($res) { - //更新订单状态 - $row = $this->orders_model->get(['id' => $order['o_id']]); - if ($row) { - if(!$this->bills_model->count(['o_id'=>$row['id']])){ - $this->bills_model->add(['o_id'=>$row['id'],'c_time'=>time]); - } - if(!$this->order_agents_model->count(['o_id'=>$row['id']])){ - $this->order_agents_model->add(['o_id'=>$row['id'],'status'=>-1,'c_time'=>time]); - } - $this->order_signs_model->update(['status' => 2], ['o_id' => $row['id']]); - if ($row['payway']) {//全款 - $status = 2; - $this->load->model('receiver/order/receiver_order_ckcars_model', 'next_model'); - } else { - $status = 1; - $this->load->model('receiver/order/receiver_order_loans_model', 'next_model'); - } - $next_row = $this->next_model->get(['o_id'=>$row['id']]); - $order_update = [ - 'status' => $status, - ]; - $row['order_time'] == '0000-00-00 00:00:00' && $order_update['order_time'] = date('Y-m-d H:i:s'); - $this->orders_model->update($order_update, ['id' => $row['id']]); - if(!$next_row){ - $add_data = [ - 'o_id' => $row['id'], - 'c_time' => time() - ]; - $this->next_model->add($add_data); - } - } - return array('code'=>1,'msg'=>'操作成功'); - }else{ - return array('code'=>0,'msg'=>'更新失败'); + $row = $this->receiver_orders_v2_model->get(['id' => $order['o_id']]); + if($row['order_time'] == '0000-00-00 00:00:00'){ + $this->receiver_orders_v2_model->update(['order_time' => date('Y-m-d H:i:s')], ['id' => $row['id']]); } break; - case 2: //服务费 - case 3: //尾款 - $upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s')); - $pay_price && $upd['pay_price'] = $pay_price; - $descrip && $upd['descrip'] = $descrip; - $pay_time && $upd['pay_time'] = $pay_time; - $res = $this->app_liche_orders_model->update($upd,array('id'=>$order['id'])); - if($res){ - $p_row = $this->app_liche_orders_model->get(['o_id'=>$order['o_id'],'pid'=>0,'status>='=>0]); - $last_p_row = $this->app_liche_orders_model->get(['o_id'=>$order['o_id'],'type'=>3,'pid'=>$p_row['id'],'status>='=>0]); //尾款父订单 - $where = [ - 'status'=>1, - 'o_id'=>$order['o_id'], - 'pid>'=>0 - ]; - $last_p_row && $where['id <>'] = $last_p_row['id']; - $is_pay = $this->app_liche_orders_model->sum('total_price',$where); //已支付金额 - $this->load->library('receiver/orders_entity'); - $need_pay_money = $this->orders_entity->recevable_price($order['o_id']); - if($is_pay['total_price']>=$need_pay_money){ //完成支付 - $ckcar_row = $this->ckcars_model->get(['o_id'=>$order['o_id']],'status'); - $row = $this->orders_model->get(['id'=>$order['o_id']],'id,status'); - if($row['status']==2 && $ckcar_row['status']==2){ - $this->ckcars_model->update(['status'=>3],['o_id'=>$row['id']]); - $this->orders_model->update(['status'=>3],['id'=>$row['id']]); - if(!$this->bills_model->count(['o_id'=>$row['id']])){ - $this->bills_model->add(['o_id'=>$row['id'],'status'=>1,'c_time'=>time()]); - }else{ - $this->bills_model->update(['status'=>1],['o_id'=>$row['id']]); - } - } - } - $last_is_pay = $this->app_liche_orders_model->sum('total_price',['status'=>1,'pid'=>$last_p_row['id']]); //已支付尾款 - if($last_is_pay['total_price']>=$last_p_row['total_price']){ - $this->app_liche_orders_model->update(['status'=>1,'pay_time'=>date('Y-m-d H:i:s')],['id'=>$last_p_row['id']]); - } - return array('code'=>1,'msg'=>'操作成功'); - }else{ - return array('code'=>0,'msg'=>'更新失败'); + case 3: + $last_is_pay = $this->app_liche_orders_model->sum('total_price',['status'=>1,'pid'=>$last_p_row['id']]); //已支付尾款 + if($last_is_pay['total_price']>=$last_p_row['total_price']){ + $this->app_liche_orders_model->update(['status'=>1,'pay_time'=>date('Y-m-d H:i:s')],['id'=>$last_p_row['id']]); } break; - case 4: //意向金 - $upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s')); - $pay_price && $upd['pay_price'] = $pay_price; - $descrip && $upd['descrip'] = $descrip; - $pay_time && $upd['pay_time'] = $pay_time; - $res = $this->app_liche_orders_model->update($upd,array('id'=>$order['id'])); - if($res) { - //更新订单下定时间 - $this->orders_model->update(['order_time' => date('Y-m-d H:i:s')], ['id' => $order['o_id']]); - return array('code'=>1,'msg'=>'操作成功'); - }else{ - return array('code'=>0,'msg'=>'更新失败'); - } + case 4: + //更新订单下定时间 + $this->receiver_orders_v2_model->update(['order_time' => date('Y-m-d H:i:s')], ['id' => $order['o_id']]); break; default: - debug_log("[error] ". __FUNCTION__ . ":{$order['type']}_未知商品类型", $this->log_file); - return array('code'=>0,'msg'=>'未知商品类型'); } + $where = [ + 'status'=>1, + 'o_id'=>$order['o_id'], + 'pid>'=>0 + ]; + $last_p_row && $where['id <>'] = $last_p_row['id']; + $is_pay = $this->app_liche_orders_model->sum('total_price',$where); //已支付金额 + $this->load->library('receiver/orders_v2_entity'); + $need_pay_money = $this->orders_v2_entity->recevable_price($order['o_id']); + if($need_pay_money && $is_pay['total_price']>=$need_pay_money){ //完成支付 + $this->load->library('receiver/orders_status_entity'); + $this->orders_status_entity->set_status($order['o_id'],0,1); + } + return array('code'=>1,'msg'=>'操作成功'); + }else{ + return array('code'=>0,'msg'=>'更新失败'); } } } diff --git a/common/third_party/esign/comm/initConfig.php b/common/third_party/esign/comm/initConfig.php index 67ce8d8a..7233906c 100755 --- a/common/third_party/esign/comm/initConfig.php +++ b/common/third_party/esign/comm/initConfig.php @@ -50,9 +50,9 @@ return array( 'retry' => 3, /* 本地java服务 */ -// 'java_server' => 'http://192.168.0.16:8080'//28 -// 'java_server' => 'http://117.25.145.143:8080', - 'java_server' => '116.62.153.124:9999',//ali + 'java_server' => 'http://127.0.0.1:8080' +// 'java_server' => 'http://39.103.130.218:8080', +// 'java_server' => '116.62.153.124:9999',//ali ); diff --git a/sql/app/app.sql b/sql/app/app.sql index 6b44ba8f..b1557aad 100644 --- a/sql/app/app.sql +++ b/sql/app/app.sql @@ -135,3 +135,23 @@ create table lc_app_deal_apply ( u_time timestamp not null default current_timestamp on update current_timestamp comment '更新时间', primary key (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='分销-申请表'; + +-- ---------------------------- +-- Title:审核数据 +-- Author:lcc +-- Table:lc_app_checkdata +-- --------------------------- +create table lc_app_checkdata ( + id int(10) unsigned not null auto_increment comment '自增id', + cf_id int(10) unsigned not null default '0' comment '来源id,详见haodian项目app.sql', + app_id int(10) unsigned not null default '0' comment '应用id', + type int(10) unsigned not null default '0' comment '审核类型,详见haodian项目app.sql', + datatype char(10) not null default '0' comment '数据类型 img video', + dataurl char(200) not null default '' comment '资源地址', + ifcheck tinyint(1) not null default '0' comment '审核状态,-1审核未通过,0未审核,1审核通过', + descrip text not null comment '描述', + jsondata text not null comment '附加字段', + c_time int(10) unsigned not null default '0' comment '创建时间', + u_time timestamp not null default current_timestamp on update current_timestamp, + primary key (id) +) engine=innodb default charset=utf8mb4 collate=utf8mb4_0900_ai_ci comment='审核数据' diff --git a/sql/app/liche.sql b/sql/app/liche.sql index be5ba766..f98499b5 100644 --- a/sql/app/liche.sql +++ b/sql/app/liche.sql @@ -67,30 +67,37 @@ create table lc_app_liche_udata ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='狸车用户数据表'; alter table lc_app_liche_udata add app_uid int(10) unsigned not null default 0 comment '用户id' after cf_id; + -- ---------------------------- -- Title:用户购车订单 -- Author:lcc -- Table:lc_app_liche_orders -- --------------------------- +drop table if exists lc_app_liche_orders; create table lc_app_liche_orders ( - id int(10) unsigned not null auto_increment comment '自增id', - o_id int(10) unsigned not null default '0' comment '订单表id', - uid int(10) unsigned not null default '0' comment '用户id', - sid varchar(32) not null default '' comment '订单号', - mch_id varchar(30) not null default '' comment '支付商户号', - pid int(10) unsigned not null default '0' comment '父订单id', - brand_id int(10) not null default '0' comment '品牌id', - s_id int(10) unsigned not null default '0' comment '车系id', - v_id int(10) unsigned not null default '0' comment '车型号', - cor_id int(10) not null default '0' comment '车身颜色id', - incor_id int(10) unsigned not null default '0' comment '内饰颜色id', - total_price decimal(12,2) not null default '0.00' comment '订单价格', - pay_price decimal(12,2) not null default '0.00' comment '实付金额', - type tinyint(2) unsigned not null default '0' comment '订单类型 1定金 2服务费 3尾款 4意向金 5后台添加', - status tinyint(1) not null default '0' comment '支付状态 0未支付 1已支付', - pay_time timestamp not null default '0000-00-00 00:00:00' comment '付款时间', - c_time int(10) unsigned not null default '0' comment '创建时间', - u_time timestamp null default current_timestamp on update current_timestamp, - primary key (id) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户购车订单'; -alter table lc_app_liche_orders add descrip varchar(255) not null default '' comment '备注/描述' after pay_price; + id int(10) unsigned not null auto_increment comment '自增id', + o_id int(10) unsigned not null default '0' comment '订单表id', + uid int(10) unsigned not null default '0' comment '用户id', + entrust_uid int(10) not null default '0' comment '委托人用户id', + pay_uid int(10) not null default '0' comment '付款人用户id', + sid varchar(32) not null default '' comment '订单号', + mch_id varchar(30) not null default '' comment '支付商户号', + pid int(10) unsigned not null default '0' comment '父订单id', + brand_id int(10) not null default '0' comment '品牌id', + s_id int(10) unsigned not null default '0' comment '车系id', + v_id int(10) unsigned not null default '0' comment '车型号', + cor_id int(10) not null default '0' comment '车身颜色id', + incor_id int(10) unsigned not null default '0' comment '内饰颜色id', + company_id int(11) not null default '0' comment '公司id', + total_price decimal(12,2) not null default '0.00' comment '订单价格', + pay_price decimal(12,2) not null default '0.00' comment '实付金额', + descrip varchar(255) not null default '' comment '备注/描述', + type tinyint(2) unsigned not null default '0' comment '订单类型 1定金 2服务费 3尾款 4意向金 5后台添加', + status tinyint(1) not null default '0' comment '支付状态 0未支付 1已支付', + pay_time timestamp not null default '0000-00-00 00:00:00' comment '付款时间', + c_time int(10) unsigned not null default '0' comment '创建时间', + u_time timestamp null default current_timestamp on update current_timestamp, + primary key (id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='用户购车订单' +alter table lc_app_liche_orders add img varchar(100) not null default '' comment '支付截图' after descrip; +alter table lc_app_liche_orders add admin_id int(10) not null default 0 comment '管理员id' after uid; diff --git a/sql/biz.sql b/sql/biz.sql index 893f4f95..4b8dd9de 100644 --- a/sql/biz.sql +++ b/sql/biz.sql @@ -30,7 +30,8 @@ create table lc_biz ( alter table lc_biz add column type tinyint(1) not null default 0 comment '类型:1-合伙店,2-加盟店,3-代理店' after floor; alter table lc_biz add column company_id int not null default 0 comment '公司ID' after type; alter table lc_biz add column jsondata json null comment '其他数据' after company_id; -alter table lc_biz add srv_company_id int(11) not null default 0 comment '收服务费公司ID' after company_id; +alter table lc_biz add srv_company_id int(10) not null default 0 comment '收服务费公司ID' after company_id; +alter table lc_biz add car_brand_id int(10) not null default 0 comment '车辆品牌' after type; -- ---------------------------- -- Title:品牌表 diff --git a/sql/receiver/order.sql b/sql/receiver/order.sql index 71b346ec..88e42c43 100644 --- a/sql/receiver/order.sql +++ b/sql/receiver/order.sql @@ -161,7 +161,7 @@ create table lc_receiver_order_signs ( -- Table:lc_receiver_orders --- jsondata if_fine 是否选择精品尊享包 -- info_json entrust_name 代办人姓名 entrust_idcard 代办人身份证 name 姓名 sex 性别 nation 民族 birth 出生日期 address 家庭地址 cardid 身份证 c_address 创建时输入的地址 c_cardid 创建时输入的身份证 --- money_json price_car 裸车价 price_book 定金 price_insure 保险价格 price_fine 精品报价 price_finance 金融报价 price_loan贷款金额 price_discount优惠金额 price_intention意向金 price_fine_discount精品优惠金额 +-- money_json price_car 裸车价 price_book 定金 price_insure 保险价格 price_fine 精品报价 price_finance 金融报价 price_loan贷款金额 price_discount优惠金额 price_intention意向金 price_fine_discount精品优惠金额 price_fine_select精品选装总金额 -- --------------------------- drop table if exists lc_receiver_orders; create table lc_receiver_orders ( diff --git a/sql/sys.sql b/sql/sys.sql index 26f9c814..c6b33921 100644 --- a/sql/sys.sql +++ b/sql/sys.sql @@ -206,6 +206,8 @@ create table lc_sys_company ( alter table lc_sys_company add column credit_code varchar(18) not null default '' comment '统一社会信用代码' after short; alter table lc_sys_company add column wx_mchid varchar(10) not null default '' comment '微信商户号' after credit_code; alter table lc_sys_company add column img_seal varchar(128) not null default '' comment '公章' after wx_mchid; +alter table lc_sys_company add column city_id int(10) unsigned not null default '0' comment '城市id' after wx_mchid; +alter table lc_sys_company add column type tinyint(1) not null default 0 comment '公司类型(0服务公司 1销售公司)' after status; diff --git a/www/api/pdf/agent_tpl.pdf b/www/api/pdf/agent_tpl.pdf new file mode 100644 index 00000000..d6b986b3 Binary files /dev/null and b/www/api/pdf/agent_tpl.pdf differ diff --git a/www/api/pdf/car_tpl.pdf b/www/api/pdf/car_tpl.pdf new file mode 100644 index 00000000..b503c97d Binary files /dev/null and b/www/api/pdf/car_tpl.pdf differ diff --git a/www/api/pdf/ck_tpl.pdf b/www/api/pdf/ck_tpl.pdf new file mode 100644 index 00000000..46dd7cdd Binary files /dev/null and b/www/api/pdf/ck_tpl.pdf differ