From f5b4c6c14a0a84588540a9a89893d5d78f59ef3c Mon Sep 17 00:00:00 2001 From: lccsw <1127794702@qq.com> Date: Mon, 13 Dec 2021 16:07:30 +0800 Subject: [PATCH] edit-api-order_process --- admin/controllers/receiver/Orders.php | 8 +- api/controllers/plan/Temp.php | 36 +++++ api/controllers/wxapp/liche/Contract.php | 10 +- api/controllers/wxapp/licheb/Cusorder.php | 73 ++++++++- api/controllers/wxapp/licheb/Idcard.php | 56 +++---- api/controllers/wxapp/licheb/Protocol.php | 4 +- common/libraries/receiver/Orders_entity.php | 144 ++++++++++++++---- .../receiver/order/Receiver_orders_model.php | 4 +- common/services/apporder/Payment_service.php | 49 +++--- 9 files changed, 288 insertions(+), 96 deletions(-) diff --git a/admin/controllers/receiver/Orders.php b/admin/controllers/receiver/Orders.php index 47bd7201..7bbe13ca 100644 --- a/admin/controllers/receiver/Orders.php +++ b/admin/controllers/receiver/Orders.php @@ -66,6 +66,7 @@ class Orders extends HD_Controller } else if ($key == 3) { $t1 = 'lc_receiver_order_bills'; $order_model = $this->order_bills_model; + $where_c["$t1.status>"] = 0; } else if ($key == 4) { $t1 = 'lc_receiver_order_agents'; $order_model = $this->order_agents_model; @@ -467,10 +468,14 @@ class Orders extends HD_Controller if (!$finance_id || !$price_loan || !$update['num']) { return $this->show_json(SYS_CODE_FAIL, '请填写完整信息!'); } - $order_row = $this->orders_model->get(['id' => $row['o_id']], 'money_json'); + $order_row = $this->orders_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->orders_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_entity->check_finish_v2($order_row['id'],$userinfo); } elseif ($params['status'] == 3) { //完成按揭 if (!$row['lend_file']) { return $this->show_json(SYS_CODE_FAIL, '请先上传按揭放款函!'); @@ -681,6 +686,7 @@ class Orders extends HD_Controller $update['ins_img'] = json_encode($imgs, JSON_UNESCAPED_UNICODE); } if ($agent) { + $agent['status'] <0 && $update['status'] = 0; $result = $this->order_agents_model->update($update, ['id' => $agent['id']]); } else { $update['o_id'] = $row['id']; diff --git a/api/controllers/plan/Temp.php b/api/controllers/plan/Temp.php index a968bf07..563bfda1 100644 --- a/api/controllers/plan/Temp.php +++ b/api/controllers/plan/Temp.php @@ -238,4 +238,40 @@ class Temp extends HD_Controller echo 'finish'; } } + + //创建支付订单 + public function c_payorder(){ + $this->load->model('receiver/order/receiver_orders_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'); + + $params = $this->input->get(); + $params['page'] = intval($params['page']); + $params['size'] = intval($params['size']); + !$params['size'] && $params['size'] = 10; + !$params['page'] && $params['page'] = 1; + + $where = [ + 'status>' => 0, + 'status<' => 3, + 'biz_id !=' => 1 + ]; + $params['id'] && $where['id'] = $params['id']; + $rows = $this->receiver_orders_model->select($where,'id asc',$params['page'],$params['size']); + if($rows){ + $data = []; + foreach($rows as $key=>$val){ + $userinfo = $this->app_liche_users_model->get(['mobile'=>$val['mobile']]); + $result = $this->orders_entity->check_finish_v2($val['id'],$userinfo); + $data[] = [ + 'id' => $val['id'], + 'result' => $result, + ]; + } + echo json_encode($data,JSON_UNESCAPED_UNICODE); + }else{ + echo 'finish'; + } + } } diff --git a/api/controllers/wxapp/liche/Contract.php b/api/controllers/wxapp/liche/Contract.php index ab9ac418..7b494c1b 100644 --- a/api/controllers/wxapp/liche/Contract.php +++ b/api/controllers/wxapp/liche/Contract.php @@ -108,7 +108,7 @@ class Contract extends Wxapp{ $img = $this->input_param('img'); $row = $this->contracts_model->get(['type'=>$type,'o_id'=>$id]); - $order = $this->orders_model->get(['id'=>$id],'brand_id,mobile,biz_id,ifentrust,srv_ids,info_json'); + $order = $this->orders_model->get(['id'=>$id],'brand_id,mobile,biz_id,ifentrust,srv_ids,info_json,payway'); if(!$row['file'] || !$img){ throw new Exception('参数错误', API_CODE_INVILD_PARAM); } @@ -167,6 +167,7 @@ class Contract extends Wxapp{ if(!$order['srv_ids']){ $userinfo = $this->app_user_model->get(['mobile'=>$order['mobile']]); $this->orders_entity->sign_after_v2($id,$userinfo); + $order['payway'] && $this->orders_entity->check_finish_v2($id,$userinfo); } $redis->delete($cache_key); throw new Exception('签名成功', API_CODE_SUCCESS); @@ -195,6 +196,7 @@ class Contract extends Wxapp{ if($result){ $userinfo = $this->app_user_model->get(['mobile'=>$order['mobile']]); $this->orders_entity->sign_after_v2($id,$userinfo); + $order['payway'] && $this->orders_entity->check_finish_v2($id,$userinfo); $redis->delete($cache_key); throw new Exception('签名成功', API_CODE_SUCCESS); }else{ @@ -222,11 +224,11 @@ class Contract extends Wxapp{ if($this->app_liche_orders_model->count(['o_id'=>$id,'status'=>1,'type'=>3])){ //尾款已支付 $this->ckcars_model->update(['status'=>3],['o_id'=>$id]); $this->orders_model->update(['status'=>3],['id'=>$id]); + if(!$this->bills_model->count(['o_id'=>$id])){ + $this->bills_model->add(['o_id'=>$id,'c_time'=>time()]); + } }else{ $this->ckcars_model->update(['status'=>2],['o_id'=>$id]); - //生成支付订单 - $userinfo = $this->app_user_model->get(['mobile'=>$order['mobile']]); - $this->orders_entity->check_finish_v2($id,$userinfo); } $redis->delete($cache_key); throw new Exception('签名成功', API_CODE_SUCCESS); diff --git a/api/controllers/wxapp/licheb/Cusorder.php b/api/controllers/wxapp/licheb/Cusorder.php index 03253e32..e14c4827 100644 --- a/api/controllers/wxapp/licheb/Cusorder.php +++ b/api/controllers/wxapp/licheb/Cusorder.php @@ -25,6 +25,7 @@ class Cusorder extends Wxapp{ $this->load->model('receiver/order/receiver_order_deliverys_model','order_deliverys_model'); $this->load->model('receiver/order/receiver_order_ckcars_model','order_ckcars_model'); $this->load->model('receiver/order/receiver_order_contracts_model','order_contracts_model'); + $this->load->model('receiver/order/receiver_order_agents_model', 'order_agents_model'); $this->load->model('receiver/receiver_fine_model'); $this->load->model('receiver/receiver_services_model','services_model'); @@ -197,7 +198,7 @@ class Cusorder extends Wxapp{ $orders_entity = new Orders_entity(); $money_json = [ 'price_car' => $car_row['price_car'], - 'price_book' => $car_row['price_book'], + 'price_book' => $deposit ? $deposit : 0, 'price_insure' => $car_row['price_insure'], 'price_fine' => $car_row['price_fine'], 'price_discount' =>$disc_money ? $disc_money : 0, @@ -469,7 +470,7 @@ class Cusorder extends Wxapp{ //开票信息 $bill_status = 0; $bill_data = []; - if($row['status']>=3){ + if($row['status']>0){ $bill = $this->order_bills_model->get(['o_id'=>$row['id']]); if($bill){ $bill_data = [ @@ -496,6 +497,38 @@ class Cusorder extends Wxapp{ if($row['status']==5&&in_array($delivery['status'],[0,1])){ $ckcar_status = 1; } + $agent_data = []; + $agent_status = 0; + if($row['status']>0){//获取资料 + $agents_row = $this->order_agents_model->get(['o_id'=>$row['id']],'car_img,jsondata,ins_img'); + $agent_jsondata = json_decode($agents_row['jsondata'],true); + $agent_data['register_img'] = []; + if($agent_jsondata['register_img']){ + $agent_data['register_img'] = [ + 'src' => $agent_jsondata['register_img'] ? build_qiniu_image_url($agent_jsondata['register_img']) : '', + 'value' => $agent_jsondata['register_img'], + ]; + } + $agent_data['car_img'] = []; + if($agents_row['car_img']){ + $agent_data['car_img'] = [ + 'src' => $agents_row['car_img'] ? build_qiniu_image_url($agents_row['car_img']) : '', + 'value' => $agents_row['car_img'], + ]; + } + $ins_img_arr = []; + if($agents_row['ins_img']){ + $ins_img = json_decode($agents_row['ins_img'],true); + foreach($ins_img as $key=>$val){ + $ins_img_arr[] = [ + 'src' => build_qiniu_image_url($val), + 'value' => $val + ]; + } + } + $agent_data['ins_img'] = $ins_img_arr; + $agent_status = $row['status'] >5 ? 2 : 1; + } $data = [ 'id' => $id, 'name' => $row['name'], @@ -511,6 +544,8 @@ class Cusorder extends Wxapp{ 'bill_data' => $bill_data, 'ckcar_status' => $ckcar_status, 'ckcar_data' => $ckcar_data, + 'agent_status' => $agent_status, + 'agent_data' => $agent_data, 'pack_id' => $row['pack_id'], 'brand_id' => $row['brand_id'], 'car_id' => $row['s_id'], @@ -557,10 +592,36 @@ class Cusorder extends Wxapp{ ]; $result = $this->order_deliverys_model->update($update,['id'=>$row['id']]); if($result){ - //$this->orders_model->update(['status'=>6],['id'=>$row['o_id']]); - ////完成分销 - //$this->load->library('entity/deal_entity',['app_id'=>1]); - //$this->deal_entity->deal_log_finish($row['o_id']); + throw new Exception('修改成功', API_CODE_SUCCESS); + }else{ + throw new Exception('修改失败', ERR_PARAMS_ERROR); + } + } + //资料上传 + protected function put_cdata(){ + $oid = $this->input_param('id'); + $img = $this->input_param('img'); + $type = $this->input_param('type'); + $row = $this->orders_model->get(['id'=>$oid]); + if(!$row || !is_array($img)){ + throw new Exception('参数错误', ERR_PARAMS_ERROR); + } + $agents_row = $this->order_agents_model->get(['o_id'=>$oid]); + if(!$agents_row){ + $this->order_agents_model->add(['o_id'=>$oid,'c_time'=>time(),'status'=>-1]); + } + $jsondata = $agents_row ? json_decode($agents_row['jsondata'],true) : ''; + if($type==1){ //登记证 + $jsondata['register_img'] = $img ? $img[0] : ''; + $update['jsondata'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE); + }elseif($type==2){//行驶证 + $update['car_img'] = $img ? $img[0] : ''; + }else{ //保险单 + $img = $img ? $img : []; + $update['ins_img'] = json_encode($img,JSON_UNESCAPED_UNICODE); + } + $result = $this->order_agents_model->update($update,['o_id'=>$oid]); + if($result){ throw new Exception('修改成功', API_CODE_SUCCESS); }else{ throw new Exception('修改失败', ERR_PARAMS_ERROR); diff --git a/api/controllers/wxapp/licheb/Idcard.php b/api/controllers/wxapp/licheb/Idcard.php index 9c96c85e..bdf0d517 100644 --- a/api/controllers/wxapp/licheb/Idcard.php +++ b/api/controllers/wxapp/licheb/Idcard.php @@ -53,38 +53,42 @@ class Idcard extends Wxapp{ $jsondata['business_licence']['data'] = $result['data']; $update = [ 'business_licence' => $business_licence, - 'status' => 1 ]; }else{ //购车主体个人 - if(!$cardidA || !$cardidB){ + if(!$cardidA && !$cardidB){ throw new Exception('参数错误', ERR_PARAMS_ERROR); } - $full_cardidA = build_qiniu_image_url($cardidA); - $this->load->library('TcOrc'); - $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; - } + if($cardidA){ + $full_cardidA = build_qiniu_image_url($cardidA); + $this->load->library('TcOrc'); + $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']; + $userinfo = $result['data']; - //校验订单客户和身份证姓名 - $row_order = $this->orders_model->get(['id' => $row['o_id']]); - if($userinfo['Name'] != $row_order['name']){ - throw new Exception('身份证姓名与客户不一致', ERR_PARAMS_ERROR); + //校验订单客户和身份证姓名 + $row_order = $this->orders_model->get(['id' => $row['o_id']]); + if($userinfo['Name'] != $row_order['name']){ + $res_data['code'] = API_CODE_ORC_FAIL; + $res_data['data'] = [ + ['caridA' => false,'errmsg'=>'身份证姓名与客户不一致'], + ['caridB' => true,'errmsg'=>''], + ]; + return $res_data; + } + $jsondata['cardidA']['data'] = $userinfo; + $update['cardidA'] = $cardidA; + }else{ + $update['cardidB'] = $cardidB; } - $jsondata['cardidA']['data'] = $userinfo; - $update = [ - 'cardidA' => $cardidA, - 'cardidB' => $cardidB, - 'status' => 1 - ]; } $jsondata && $update['jsondata'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE); @@ -95,7 +99,7 @@ class Idcard extends Wxapp{ $order_jsondata['c_credit'] = $jsondata['business_licence']['data']['RegNum']; $this->orders_model->update(['info_json'=>json_encode($order_jsondata,JSON_UNESCAPED_UNICODE)],['id'=>$row['o_id']]); }else{ - $this->orders_entity->up_info($row['o_id'],$userinfo); + $cardidA && $this->orders_entity->up_info($row['o_id'],$userinfo); } throw new Exception('修改成功', API_CODE_SUCCESS); }else{ @@ -134,7 +138,6 @@ class Idcard extends Wxapp{ 'o_id' => $oid, 'business_licence' => $business_licence, 'c_time' => time(), - 'status' => 1 ]; }else{ if(!$cardidA || !$cardidB){ @@ -162,7 +165,6 @@ class Idcard extends Wxapp{ 'cardidA' => $cardidA, 'cardidB' => $cardidB, 'c_time' => time(), - 'status' => 1 ]; } $jsondata && $add_data['jsondata'] = json_encode($jsondata,JSON_UNESCAPED_UNICODE); diff --git a/api/controllers/wxapp/licheb/Protocol.php b/api/controllers/wxapp/licheb/Protocol.php index de9f7d5c..56c10ae9 100644 --- a/api/controllers/wxapp/licheb/Protocol.php +++ b/api/controllers/wxapp/licheb/Protocol.php @@ -302,9 +302,7 @@ class Protocol extends CI_Controller{ $old_incor = $attr_rows[$opt_row['incor_id']] ? $attr_rows[$opt_row['incor_id']][0]['title'] : ''; $new_car = "{$brand['name']}{$series['name']}{$version}{$cor}(内饰{$incor})"; $old_car = "{$old_brand['name']}{$old_series['name']}{$old_version}{$old_cor}(内饰{$old_incor})"; - $logs[0] = "购买车型由 {$old_car} 变更为 {$new_car} -
车辆单价:{$price} 元 数量:1
-
车辆总价:{$price}元,{$b_price}
"; + $logs[0] = "购买车型由 {$old_car} 变更为 {$new_car}"; } if($diff_price){ $old_price = number_format($opt_row['price'],2); diff --git a/common/libraries/receiver/Orders_entity.php b/common/libraries/receiver/Orders_entity.php index 663da746..61d49df8 100644 --- a/common/libraries/receiver/Orders_entity.php +++ b/common/libraries/receiver/Orders_entity.php @@ -11,6 +11,7 @@ class Orders_entity{ const API_ADMIN_IMG = 'https://img.liche.cn/liche/2021/08/7725fc9ab0dc0ba1/f3c84cf3b805bac4.png'; //api 客服二维码 const API_PAY_IMG = 'https://img.liche.cn/liche/1634022931.png'; //api 意向金跳转支付二维码 const API_CREATE_PAY_IMG = 'https://img.liche.cn/liche/2021/11/65b34b962f5f06b3/62e7d28d77bfe404.png'; //api 狸车我的页面 + const ODER_ID = 527; //订单id大于100之后定金都到销售公司 private $ci; private $order_row; @@ -93,17 +94,18 @@ class Orders_entity{ if(!$pay_money){//未支付意向订单设置删除 $this->ci->app_liche_orders_model->update(['status'=>-1],['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 = $this->order_row['deposit'] - $pay_money['total_price']; + $need_pay_money = $money_json['price_book'] - $pay_money['total_price']; if($need_pay_money > 0 && !$deposit_count){ $this->ci->signs_model->update(['status'=>1],['o_id'=>$this->order_row['id']]); $srv_money = $this->order_srv_money($oid); //获取门店信息 $biz = $this->ci->biz_model->get(['id'=>$this->order_row['biz_id']],'company_id,srv_company_id'); - if($srv_money < $this->order_row['deposit'] || $pay_money){ //服务费小于支付定金或有意向金订单 给销售公司 + if($srv_money < $money_json['price_book'] || $pay_money || $oid > self::ODER_ID){ //服务费小于支付定金或有意向金订单 给销售公司 id大于100之后定金都到销售公司 $company = $this->ci->sys_company_model->get(['id'=>$biz['company_id']],'wx_mchid'); $mch_id = $company['wx_mchid']; - }else{ + }else{ //以后废除 $mch_id = self::SRV_MCH_ID; if($biz['srv_company_id']){ $company = $this->ci->sys_company_model->get(['id'=>$biz['srv_company_id']],'wx_mchid'); @@ -381,9 +383,10 @@ class Orders_entity{ //确认车辆完成创建两个支付订单 public function check_finish_v2($oid,$userinfo){ + $this->ci->load->helper('order'); $uid = $userinfo['id'] ? $userinfo['id'] : 0; $this->order_row = $this->ci->orders_model->get(['id'=>$oid]); - $p_row = $this->ci->app_liche_orders_model->get(['pid'=>0,'o_id'=>$oid,"(uid={$uid} or entrust_uid={$uid})"=>null,'status>='=>0],'id'); //父订单 + $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; } @@ -402,35 +405,48 @@ class Orders_entity{ $company = $this->ci->sys_company_model->get(['id'=>$biz['company_id']]); $srv_company = $this->ci->sys_company_model->get(['id'=>$biz['srv_company_id']]); - $pay_money = $this->ci->app_liche_orders_model->get(['o_id'=>$oid,"(uid={$uid} or entrust_uid={$uid})"=>null,'type'=>4,'status'=>1,'o_id!='=>253]); //已支付意向金订单 + $pay_money = $this->ci->app_liche_orders_model->get(['o_id'=>$oid,'type'=>4,'status'=>1,'o_id!='=>253]); //已支付意向金订单 $srv_money = $this->order_srv_money($oid); //服务费 $money_json = json_decode($this->order_row['money_json'],true); $money_json['price_discount'] && $money_json['price_car'] = $money_json['price_car'] - $money_json['price_discount']; - if($this->order_row['payway']){ //全款 - if($srv_money < $this->order_row['deposit'] || $pay_money){ //服务费小于定金 - $to_srv_price = $srv_money; - $to_com_price = $money_json['price_car'] - $this->order_row['deposit']; - $to_com_price = $to_com_price>0 ? $to_com_price : 0; - }else{ - $to_com_price = $money_json['price_car']; //给销售公司金额 裸车价格 - $to_srv_price = $srv_money - $this->order_row['deposit']; //给服务公司金额 裸车价格+服务费-给销售公司金额-定金 - $to_srv_price = $to_srv_price>0 ? $to_srv_price : 0; + if(!$this->order_row['payway'] && !$money_json['price_loan']){//贷款未填写首付 + return false; + } + if($oid > self::ODER_ID){ + $to_srv_price = $srv_money; + if($this->order_row['payway']){ //全款 + $to_com_price = $money_json['price_car'] - $money_json['price_book']; + }else{ //分期 + $to_com_price = $money_json['price_car']-$money_json['price_loan'] - $money_json['price_book']; } - }else{ //分期 - if($srv_money < $this->order_row['deposit'] || $pay_money){ //服务费小于定金 - $to_srv_price = $srv_money; - $to_com_price = $money_json['price_car']-$money_json['price_loan'] - $this->order_row['deposit']; - $to_com_price = $to_com_price>0 ? $to_com_price : 0; - }else{ - $to_com_price = $money_json['price_car']-$money_json['price_loan']; //给销售公司金额 - $to_srv_price = $srv_money - $this->order_row['deposit']; //给服务公司的金额 服务费-定金 - $to_srv_price = $to_srv_price>0 ? $to_srv_price : 0; + $to_com_price = $to_com_price>0 ? $to_com_price : 0; + }else{ //以后废除 + if($this->order_row['payway']){ //全款 + if($srv_money < $money_json['price_book'] || $pay_money){ //服务费小于定金 + $to_srv_price = $srv_money; + $to_com_price = $money_json['price_car'] - $money_json['price_book']; + $to_com_price = $to_com_price>0 ? $to_com_price : 0; + }else{ + $to_com_price = $money_json['price_car']; //给销售公司金额 裸车价格 + $to_srv_price = $srv_money - $money_json['price_book']; //给服务公司金额 裸车价格+服务费-给销售公司金额-定金 + $to_srv_price = $to_srv_price>0 ? $to_srv_price : 0; + } + }else{ //分期 + if($srv_money < $money_json['price_book'] || $pay_money){ //服务费小于定金 + $to_srv_price = $srv_money; + $to_com_price = $money_json['price_car']-$money_json['price_loan'] - $money_json['price_book']; + $to_com_price = $to_com_price>0 ? $to_com_price : 0; + }else{ + $to_com_price = $money_json['price_car']-$money_json['price_loan']; //给销售公司金额 + $to_srv_price = $srv_money - $money_json['price_book']; //给服务公司的金额 服务费-定金 + $to_srv_price = $to_srv_price>0 ? $to_srv_price : 0; + } } } $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,"(uid={$uid} or entrust_uid={$uid})"=>null,'status>='=>0])){ + 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[] = [ @@ -450,7 +466,7 @@ class Orders_entity{ 'c_time' => time() ]; } - if($to_com_price>0 && !$this->ci->app_liche_orders_model->count(['o_id'=>$this->order_row['id'],'type'=>3,"(uid={$uid} or entrust_uid={$uid})"=>null,'status>='=>0])){ + 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[] = [ @@ -507,7 +523,6 @@ class Orders_entity{ $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){ - $srv_money = $this->order_srv_money($oid); //获取门店信息 $biz = $this->ci->biz_model->get(['id'=>$this->order_row['biz_id']],'company_id,srv_company_id'); $company = $this->ci->sys_company_model->get(['id'=>$biz['company_id']],'wx_mchid'); @@ -604,13 +619,18 @@ class Orders_entity{ $this->ci->signs_model->update(['status'=>0],['id'=>$sign_row['id']]); $this->ci->orders_model->update(['status'=>0],['id'=>$row['id']]); //未签合同删除旧合同文件并且删除未支付订单 - $this->ci->app_liche_orders_model->delete(['o_id'=>$row['id'],'status'=>0,'pid!='=>0]); + $this->ci->app_liche_orders_model->delete(['o_id'=>$row['id'],'status'=>0,'pid!='=>0,'type!='=>3]); } }else{ if($sign_row){ //未签合同删除旧合同文件并且删除未支付订单 $this->ci->receiver_order_contracts_model->delete(['o_id'=>$row['id']]); - $this->ci->app_liche_orders_model->delete(['o_id'=>$row['id'],'status'=>0,'pid!='=>0]); $this->ci->signs_model->update(['status'=>0],['o_id'=>$row['id']]); + //全部未支付删除所有订单 + if(!$this->ci->app_liche_orders_model->count(['o_id'=>$row['id'],'status'=>1])){ + $this->ci->app_liche_orders_model->delete(['o_id'=>$row['id'],'status'=>0]); + }else{ + $this->ci->app_liche_orders_model->delete(['o_id'=>$row['id'],'status'=>0,'pid!='=>0]); + } }else{ $this->ci->signs_model->add(['o_id'=>$row['id'],'c_time'=>time()]); } @@ -646,11 +666,69 @@ class Orders_entity{ $this->ci->receiver_order_loans_model->add(['o_id'=>$oid,'c_time'=>time()]); } } - $ck_row = $this->ci->receiver_order_ckcars_model->get(['o_id'=>$oid]); - if($ck_row['status'] == 2){ //车辆确认 - $this->ci->load->model('app/liche/app_liche_users_model'); - $userinfo = $this->ci->app_liche_users_model->get(['mobile'=>$this->order_row['mobile']]); - $this->check_finish_v2($oid,$userinfo); + $money_json = json_decode($this->order_row['money_json'],true); + $money_json['price_discount'] && $money_json['price_car'] = $money_json['price_car'] - $money_json['price_discount']; + $p_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'pid'=>0,'status>='=>0]); + //获取门店信息 + $biz = $this->ci->biz_model->get(['id'=>$this->order_row['biz_id']],'company_id,srv_company_id'); + $company = $this->ci->sys_company_model->get(['id'=>$biz['company_id']]); + $srv_company = $this->ci->sys_company_model->get(['id'=>$biz['srv_company_id']]); + + //重新生成购车订单 + $srv_money = $this->order_srv_money($oid); + $old_srv_money = $this->ci->app_liche_orders_model->sum('total_price',['o_id'=>$oid,'status'=>1,'type'=>2]); + if($srv_money>$old_srv_money['total_price'] && $srv_money){ //多出服务费 + $order_type = 2; + $add_data[] = [ + 'o_id' => $this->order_row['id'], + 'uid' => $p_row['uid'], + 'entrust_uid' => $p_row['entrust_uid'], + 'sid' => create_order_no(350200,'liche',1,$order_type), + 'mch_id' => $srv_company ? $srv_company['wx_mchid'] : self::SRV_MCH_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' => $srv_money-$old_srv_money['total_price'], + 'type' => $order_type, + 'c_time' => time() + ]; + } + if($this->order_row['payway']){ //全款 + $to_com_price = $money_json['price_car'] - $money_json['price_book']; //车价-定金 + }else{ //分期 + $to_com_price = $money_json['price_car']-$money_json['price_loan'] - $money_json['price_book']; //车价-贷款首付-定金 + } + $to_com_price = $to_com_price>0 ? $to_com_price : 0; + $old_last_money = $this->ci->app_liche_orders_model->sum('total_price',['o_id'=>$oid,'type'=>3,'pid'=>$p_row['id']]); //尾款订单 + if($to_com_price>$old_last_money['total_price']){ //尾款高出 + $last_row = $this->ci->app_liche_orders_model->get(['o_id'=>$oid,'type'=>3,'pid'=>$p_row['id']]);//尾款父订单 + if($last_row){ + $this->ci->app_liche_orders_model->update(['status'=>0,'total_price'=>$to_com_price],['id'=>$last_row['id']]); + }else{ + $order_type = 3; + $add_data[] = [ + 'o_id' => $this->order_row['id'], + 'uid' => $p_row['uid'], + 'entrust_uid' => $p_row['entrust_uid'], + 'sid' => create_order_no(350200,'liche',1,$order_type), + 'mch_id' => $company['wx_mchid'], + '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() + ]; + } + } + if($add_data){ + $this->ci->app_liche_orders_model->add_batch($add_data); } return $res; } diff --git a/common/models/receiver/order/Receiver_orders_model.php b/common/models/receiver/order/Receiver_orders_model.php index 0776aafa..ded2b5bd 100644 --- a/common/models/receiver/order/Receiver_orders_model.php +++ b/common/models/receiver/order/Receiver_orders_model.php @@ -34,8 +34,8 @@ class Receiver_orders_model extends HD_Model 'menu_list' => array(0 => '审核中', 1 => '已通过', 2 => '等待放款', 3 => '按揭完成'), 'menu_default' => 0); $status_ary[2] = array('name' => '车辆分配', 'show' => true, 'list' => array(0 => '车辆分配中', 1 => '用户未签名', 2 => '尾款未支付', 3 => '已确定'), 'menu_list' => array(0 => '车辆分配中', 1 => '用户未签名', 2 => '尾款未支付'), 'menu_default' => 0); - $status_ary[3] = array('name' => '开票相关', 'show' => true, 'list' => array(0=> '待申请', 1 => '待开票', 2 => '已开票'), - 'menu_list' => array(1 => '待开票' ,0 => '待申请', 2 => '已开票'), 'menu_default' => 0); + $status_ary[3] = array('name' => '开票相关', 'show' => true, 'list' => array(1 => '待开票', 2 => '已开票'), + 'menu_list' => array(1 => '待开票' , 2 => '已开票'), 'menu_default' => 0); $status_ary[4] = array('name' => '代办服务', 'show' => true, 'list' => array(0 => '代办中', 1 => '已完成代办'), 'menu_list' => array(0 => '代办中'), 'menu_default' => 0); $status_ary[5] = array('name' => '交付车辆', 'show' => true, 'list' => array(0 => '待销售确认', 1 => '销售已确认', 2 => '用户已签约'), diff --git a/common/services/apporder/Payment_service.php b/common/services/apporder/Payment_service.php index f2a4b649..6089069a 100644 --- a/common/services/apporder/Payment_service.php +++ b/common/services/apporder/Payment_service.php @@ -23,6 +23,7 @@ class Payment_service extends HD_Service{ $this->load->model('receiver/order/receiver_order_signs_model','order_signs_model'); $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'); } @@ -155,6 +156,12 @@ class Payment_service extends HD_Service{ //更新订单状态 $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; @@ -183,17 +190,6 @@ class Payment_service extends HD_Service{ } break; case 2: //服务费 - $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){ - return array('code'=>1,'msg'=>'操作成功'); - }else{ - return array('code'=>0,'msg'=>'更新失败'); - } - break; case 3: //尾款 $upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s')); $pay_price && $upd['pay_price'] = $pay_price; @@ -201,21 +197,34 @@ class Payment_service extends HD_Service{ $pay_time && $upd['pay_time'] = $pay_time; $res = $this->app_liche_orders_model->update($upd,array('id'=>$order['id'])); if($res){ - //判断是否尾款支付完成 - $is_pay = $this->app_liche_orders_model->sum('total_price',['status'=>1,'pid'=>$order['pid']]); //已支付金额 - $p_row = $this->app_liche_orders_model->get(['id'=>$order['pid']]); - if($is_pay['total_price']>=$p_row['total_price']){ - $this->app_liche_orders_model->update(['status'=>1,'pay_time'=>date('Y-m-d H:i:s')],['id'=>$p_row['id']]); - //更新订单状态 - $row = $this->orders_model->get(['id'=>$order['o_id']]); - if($row){ + $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'],'c_time'=>time()]); + $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'=>'更新失败');