From 881f31d2efbad7f6d0edae49c1463acac6751345 Mon Sep 17 00:00:00 2001 From: lccsw <1127794702@qq.com> Date: Fri, 6 Aug 2021 16:55:05 +0800 Subject: [PATCH] edit-liche-enroll --- api/controllers/wxapp/app/Payment.php | 3 + api/controllers/wxapp/liche/Aptinfo.php | 12 +- api/controllers/wxapp/liche/Car.php | 92 +++++++++---- api/controllers/wxapp/liche/Order.php | 20 ++- api/controllers/wxapp/licheb/Protocol.php | 122 +++++++++--------- .../models/apporder/Order_purchase_model.php | 13 ++ sql/receiver/clue.sql | 1 + 7 files changed, 171 insertions(+), 92 deletions(-) diff --git a/api/controllers/wxapp/app/Payment.php b/api/controllers/wxapp/app/Payment.php index ad601b46..0b7e35cb 100644 --- a/api/controllers/wxapp/app/Payment.php +++ b/api/controllers/wxapp/app/Payment.php @@ -28,6 +28,9 @@ class Payment extends Wxapp{ if($row['status']>1){ throw new Exception('订单已支付', API_CODE_FAIL); } + if($row['status']=1 && !$row['status_detail']!=11){ + throw new Exception('订单已过期', API_CODE_FAIL); + } if($row['total_price']>0){ $url = http_host_com('api'); diff --git a/api/controllers/wxapp/liche/Aptinfo.php b/api/controllers/wxapp/liche/Aptinfo.php index 02891501..25b1d0eb 100644 --- a/api/controllers/wxapp/liche/Aptinfo.php +++ b/api/controllers/wxapp/liche/Aptinfo.php @@ -127,8 +127,15 @@ class Aptinfo extends Wxapp{ $recommend_id = intval($this->input_param('cf_uid')); //来源用户id $series_row = $this->auto_series_model->get(['id'=>$series_id]); - if($this->clues_model->count(['cf_id'=>$cf_id,'cf_uid'=>$uid,'app_id'=>$this->app_id,'status'=>0])){ - throw new Exception('您已预约', API_CODE_SUCCESS); + $row = $this->clues_model->get(['cf_id'=>$cf_id,'cf_uid'=>$uid,'app_id'=>$this->app_id,'status'=>0]); + if($row){ + $update = [ + 'en_time' => date('Y-m-d H:i:s') + ]; + $series_row['brand_id'] && $update['brand_id'] = $series_row['brand_id']; + $series_row['id'] && $update['s_id'] = $series_row['id']; + $this->clues_model->update($update,['id'=>$row['id']]); + throw new Exception('预约成功', API_CODE_SUCCESS); } $jsondata['info'] = [ @@ -145,6 +152,7 @@ class Aptinfo extends Wxapp{ 'if_driver' => 1, 'cf_platform' => $cf_platform, 'jsondata' => json_encode($jsondata,JSON_UNESCAPED_UNICODE), + 'en_time' => date('Y-m-d H:i:s'), 'c_time' => time() ]; diff --git a/api/controllers/wxapp/liche/Car.php b/api/controllers/wxapp/liche/Car.php index 9f35664d..07f141cb 100644 --- a/api/controllers/wxapp/liche/Car.php +++ b/api/controllers/wxapp/liche/Car.php @@ -73,15 +73,13 @@ class Car extends Wxapp{ $this->load->model('apporder/order_purchase_model'); $cf_id = 2; + $price = 5000; $uid = $this->session['uid']; $s_id = $this->input_param('id'); //车系id $c_id = intval($this->input_param('c_id')); //颜色属性id $v_id = intval($this->input_param('v_id')); //车型属性id $recommend_id = intval($this->input_param('cf_uid')); //来源用户id - - if($this->clues_model->count(['cf_id'=>$cf_id,'cf_uid'=>$uid,'status'=>0])){ - throw new Exception('您已订购', API_CODE_INVILD_PARAM); - } + $row = $this->auto_series_model-> get(['id'=>$s_id]); if(!$row){ throw new Exception('参数错误', API_CODE_INVILD_PARAM); @@ -105,6 +103,40 @@ class Car extends Wxapp{ 'color' => $color, 'version' => $version ]; + $clues = $this->clues_model->get(['cf_id'=>$cf_id,'cf_uid'=>$uid,'status'=>0]); + if($clues){ + $update = [ + 's_id' => $row['id'], + 'en_time' => date('Y-m-d H:i:s'), + 'jsondata' => json_encode($jsondata,JSON_UNESCAPED_UNICODE) + ]; + $this->clues_model->update($update,['id'=>$clues['id']]); + //不存在已支付订单重新创建支付订单 + $where = [ + 'app_id' => $this->app_id, + 'type' => 3, + '(status>1 or (status=1 and status_detail=11))' =>null, + 'app_uid' => $this->session['uid'], + 'cf_id' => $clues['id'] + ]; + if(!$this->order_purchase_model->count($where)){ + $sid = create_order_no(350200, $this->app_key); + $color['jsondata']['img'] &&$jsondata['cover'] = $color['jsondata']['img']; + + $params = [ + 'sid' => $sid, + 'item_id' => $row['id'], + 'item_title' => $b_row['name'].$row['name'], + 'price' => $price, + 'jsondata' => $jsondata, + 'cf_id' => $clues['id'] + ]; + $order_id = $this->add_purchase_order($params); + $this->clues_model->update(['out_id'=>$order_id],['id'=>$clues['id']]); + return ['sid'=>$sid]; + } + throw new Exception('订购成功', API_CODE_SUCCESS); + } $add_data = [ 'brand_id' => $row['brand_id'], 's_id' => $row['id'], @@ -115,6 +147,7 @@ class Car extends Wxapp{ 'app_id' => $this->app_id, 'cf_platform' => $cf_platform, 'jsondata' => json_encode($jsondata,JSON_UNESCAPED_UNICODE), + 'en_time' => date('Y-m-d H:i:s'), 'c_time' => time() ]; $recommend_id && $add_data['recommend_id'] = $recommend_id; @@ -122,31 +155,18 @@ class Car extends Wxapp{ if(!$id){ throw new Exception('提交失败', API_CODE_INVILD_PARAM); } - $price = 5000; $sid = create_order_no(350200, $this->app_key); - if($color['jsondata']['img']){ - $jsondata['cover'] = $color['jsondata']['img']; - } - $add_data = [ - 'app_id' => $this->app_id, - 'app_uid' => $this->session['uid'], + $color['jsondata']['img'] &&$jsondata['cover'] = $color['jsondata']['img']; + + $params = [ 'sid' => $sid, 'item_id' => $row['id'], 'item_title' => $b_row['name'].$row['name'], - 'item_num' => 1, - 'type' => 3, - 'item_price' => $price, - 'total_price' => $price, - 'uname' => $this->session['nickname'], - 'mobile' => $this->session['mobile'], - 'payway' => 1, - 'status' => 1, - 'status_detail' => 11, - 'jsondata' => json_encode($jsondata,JSON_UNESCAPED_UNICODE), - 'c_time' => time(), + 'price' => $price, + 'jsondata' => $jsondata, 'cf_id' => $id ]; - $order_id = $this->order_purchase_model->add($add_data); + $order_id = $this->add_purchase_order($params); if(!$order_id){ throw new Exception('创建订单失败', API_CODE_INVILD_PARAM); } @@ -165,4 +185,30 @@ class Car extends Wxapp{ $data['sid'] = $sid; return $data; } + + //创建消费订单 + private function add_purchase_order($params){ + $add_data = [ + 'app_id' => $this->app_id, + 'app_uid' => $this->session['uid'], + 'sid' => $params['sid'], + 'item_id' => $params['item_id'], + 'item_title' => $params['item_title'], + 'item_num' => 1, + 'type' => 3, + 'item_price' => $params['price'], + 'total_price' => $params['price'], + 'uname' => $this->session['nickname'], + 'mobile' => $this->session['mobile'], + 'payway' => 1, + 'status' => 1, + 'status_detail' => 11, + 'expire_time' => time()+5*60, + 'c_time' => time(), + 'cf_id' => $params['cf_id'] + ]; + $params['jsondata'] && $add_data['jsondata'] = json_encode($params['jsondata'],JSON_UNESCAPED_UNICODE); + $order_id = $this->order_purchase_model->add($add_data); + return $order_id; + } } diff --git a/api/controllers/wxapp/liche/Order.php b/api/controllers/wxapp/liche/Order.php index aa83e702..c5133dd6 100644 --- a/api/controllers/wxapp/liche/Order.php +++ b/api/controllers/wxapp/liche/Order.php @@ -34,7 +34,7 @@ class Order extends Wxapp{ if($type){ $where['status'] = $type; } - $fileds = 'id,sid,item_title,total_price,jsondata,status'; + $fileds = 'id,sid,item_title,total_price,jsondata,status,status_detail'; $rows = $this->order_purchase_model->select($where,'id desc',$page,$size,$fileds); $total = $this->order_purchase_model->count($where); $list = []; @@ -49,11 +49,19 @@ class Order extends Wxapp{ 'color' => '#ccc' ]; }else{ //未支付 - $status = 1; - $btn = [ - 'text' => '去支付', - 'color' => '#1a1a1a' - ]; + if($val['status']=1 && $val['status_detail']!=11){ + $status = 2; + $btn = [ + 'text' => '已过期', + 'color' => '#ccc' + ]; + }else{ + $status = 1; + $btn = [ + 'text' => '去支付', + 'color' => '#1a1a1a' + ]; + } } $list[] = [ 'id' => $val['id'], diff --git a/api/controllers/wxapp/licheb/Protocol.php b/api/controllers/wxapp/licheb/Protocol.php index 759b50c3..661dd1b1 100644 --- a/api/controllers/wxapp/licheb/Protocol.php +++ b/api/controllers/wxapp/licheb/Protocol.php @@ -24,21 +24,21 @@ class Protocol extends CI_Controller{ //整车合同 public function car(){ $wxapp = $this->input->get('wxapp'); - $id = $this->input->get('id'); - $row = $this->orders_model->get(['id'=>$id]); - $contract = $this->contracts_model->get(['o_id'=>$id,'type'=>0]); - if($row){ - $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); - $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name'); - $car_json = json_decode($row['car_json'],true); - $color = isset($car_json['color']) ? $car_json['color']['title'] : ''; - $version = isset($car_json['version']) ? $car_json['version']['title'] : ''; - $row['brand_name'] = $brand['name'].$series['name'].' '.$version; - $row['color'] = $color; - } - $row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); - $row['price_rmb'] = num_to_rmb($row['price']); - $row['cid'] = $contract['cid']; + //$id = $this->input->get('id'); + //$row = $this->orders_model->get(['id'=>$id]); + //$contract = $this->contracts_model->get(['o_id'=>$id,'type'=>0]); + //if($row){ + // $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); + // $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name'); + // $car_json = json_decode($row['car_json'],true); + // $color = isset($car_json['color']) ? $car_json['color']['title'] : ''; + // $version = isset($car_json['version']) ? $car_json['version']['title'] : ''; + // $row['brand_name'] = $brand['name'].$series['name'].' '.$version; + // $row['color'] = $color; + //} + //$row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); + //$row['price_rmb'] = num_to_rmb($row['price']); + //$row['cid'] = $contract['cid']; $folder = $wxapp ? 'protocol' : 'html2pdf'; $this->load->view("wxapp/licheb/{$folder}/car",$row); } @@ -46,31 +46,31 @@ class Protocol extends CI_Controller{ //代理合同 public function agent(){ $wxapp = $this->input->get('wxapp'); - $id = $this->input->get('id'); - $row = $this->orders_model->get(['id'=>$id]); - $contract = $this->contracts_model->get(['o_id'=>$id,'type'=>1]); - $row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); - $row['cid'] = $contract['cid']; + //$id = $this->input->get('id'); + //$row = $this->orders_model->get(['id'=>$id]); + //$contract = $this->contracts_model->get(['o_id'=>$id,'type'=>1]); + //$row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); + //$row['cid'] = $contract['cid']; $folder = $wxapp ? 'protocol' : 'html2pdf'; $this->load->view("wxapp/licheb/{$folder}/agent",$row); } //车辆信息确认单 public function car_ck(){ $wxapp = $this->input->get('wxapp'); - $id = $this->input->get('id'); - $row = $this->orders_model->get(['id'=>$id]); - if($row){ - $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); - $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name'); - $car_json = json_decode($row['car_json'],true); - $version = isset($car_json['version']) ? $car_json['version']['title'] : ''; - $row['brand_name'] = $brand['name'].$series['name'].' '.$version; - } - $contract = $this->contracts_model->get(['o_id'=>$id,'type'=>2]); - $items = $this->items_model->get(['id'=>$row['item_id']],'vin'); - $row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); - $row['cid'] = $contract['cid']; - $row['vin'] = $items['vin']; + //$id = $this->input->get('id'); + //$row = $this->orders_model->get(['id'=>$id]); + //if($row){ + // $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); + // $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name'); + // $car_json = json_decode($row['car_json'],true); + // $version = isset($car_json['version']) ? $car_json['version']['title'] : ''; + // $row['brand_name'] = $brand['name'].$series['name'].' '.$version; + //} + //$contract = $this->contracts_model->get(['o_id'=>$id,'type'=>2]); + //$items = $this->items_model->get(['id'=>$row['item_id']],'vin'); + //$row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); + //$row['cid'] = $contract['cid']; + //$row['vin'] = $items['vin']; $folder = $wxapp ? 'protocol' : 'html2pdf'; $this->load->view("wxapp/licheb/{$folder}/car_ck",$row); } @@ -78,34 +78,34 @@ class Protocol extends CI_Controller{ public function car_fh(){ $this->load->model('app/licheb/app_licheb_users_model'); $wxapp = $this->input->get('wxapp'); - $id = $this->input->get('id'); + //$id = $this->input->get('id'); - $row = $this->orders_model->get(['id'=>$id]); - $agent = $this->agents_model->get(['o_id'=>$id]); - $contract = $this->contracts_model->get(['o_id'=>$id,'type'=>3]); - $items = $this->items_model->get(['id'=>$row['item_id']],'vin'); - if($row){ - //贷款 - if(!$row['payway']){ - $row['loan'] = $this->loans_model->get(['o_id'=>$id]); - } - $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); - $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name'); - $car_json = json_decode($row['car_json'],true); - $info_json = json_decode($row['info_json'],true); - $color = isset($car_json['color']) ? $car_json['color']['title'] : ''; - $version = isset($car_json['version']) ? $car_json['version']['title'] : ''; - $row['brand_name'] = $brand['name'].$series['name'].' '.$version; - $row['color'] = $color; - $row['cardid'] = $info_json['cardid']; - //获取销售 - $admin = $this->app_licheb_users_model->get(['id'=>$row['admin_id']],'uname'); - $row['uname'] = $admin['uname']; - } - $row['agent'] = $agent; - $row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); - $row['cid'] = $contract['cid']; - $row['vin'] = $items['vin']; + //$row = $this->orders_model->get(['id'=>$id]); + //$agent = $this->agents_model->get(['o_id'=>$id]); + //$contract = $this->contracts_model->get(['o_id'=>$id,'type'=>3]); + //$items = $this->items_model->get(['id'=>$row['item_id']],'vin'); + //if($row){ + // //贷款 + // if(!$row['payway']){ + // $row['loan'] = $this->loans_model->get(['o_id'=>$id]); + // } + // $brand = $this->auto_brand_model->get(['id'=>$row['brand_id']],'name'); + // $series = $this->auto_series_model->get(['id'=>$row['s_id']],'name'); + // $car_json = json_decode($row['car_json'],true); + // $info_json = json_decode($row['info_json'],true); + // $color = isset($car_json['color']) ? $car_json['color']['title'] : ''; + // $version = isset($car_json['version']) ? $car_json['version']['title'] : ''; + // $row['brand_name'] = $brand['name'].$series['name'].' '.$version; + // $row['color'] = $color; + // $row['cardid'] = $info_json['cardid']; + // //获取销售 + // $admin = $this->app_licheb_users_model->get(['id'=>$row['admin_id']],'uname'); + // $row['uname'] = $admin['uname']; + //} + //$row['agent'] = $agent; + //$row['day'] = $contract ? date('Y年m月d日',$contract['c_time']):date('Y年m月d日'); + //$row['cid'] = $contract['cid']; + //$row['vin'] = $items['vin']; $folder = $wxapp ? 'protocol' : 'html2pdf'; $this->load->view("wxapp/licheb/{$folder}/car_fh",$row); } diff --git a/common/models/apporder/Order_purchase_model.php b/common/models/apporder/Order_purchase_model.php index b03ec555..833ee9a0 100644 --- a/common/models/apporder/Order_purchase_model.php +++ b/common/models/apporder/Order_purchase_model.php @@ -13,4 +13,17 @@ class Order_purchase_model extends HD_Model parent::__construct($this->table_name, 'default'); } + /** + * Notes:根据订单状态值补充更详细的状态信息 + * Created on: 2019/7/13 14:52 + * Created by: dengbw + * @return array + */ + public function statusDetailAry() + { + return array('1' => array("11" => '待支付', "12" => '超时未支付', "13" => '已取消'), + '2' => array(), + '3' => array() + ); + } } diff --git a/sql/receiver/clue.sql b/sql/receiver/clue.sql index e77681be..2f777edc 100644 --- a/sql/receiver/clue.sql +++ b/sql/receiver/clue.sql @@ -25,6 +25,7 @@ create table lc_receiver_clues ( primary key (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='线索池'; alter table lc_receiver_clues add recommend_id int(10) not null default 0 comment '推荐用id' after cf_id; +alter table lc_receiver_clues add en_time timestamp not null default '0000-00-00 00:00:00' comment '最后报名时间'; -- ---------------------------- -- Title:线索操作日志表