edit-liche-orders

This commit is contained in:
lccsw
2021-09-22 21:14:23 +08:00
parent fb3f64b3eb
commit 6e8543119e
11 changed files with 675 additions and 21 deletions
+2 -2
View File
@@ -180,7 +180,7 @@ class Contract extends Wxapp{
$result = $this->contracts_model->update($update,['id'=>$row['id']]);
if($result){
$this->load->library('receiver/orders_entity');
$this->orders_entity->sign_after($id,$this->app_id,$this->session);
$this->orders_entity->sign_after_v2($id,$this->session);
$redis->delete($cache_key);
throw new Exception('签名成功', API_CODE_SUCCESS);
}else{
@@ -207,7 +207,7 @@ class Contract extends Wxapp{
$this->ckcars_model->update(['status'=>2],['o_id'=>$id]);
//生成支付订单
$this->load->library('receiver/orders_entity');
$this->orders_entity->check_finish($id,$this->app_id,$this->session);
$this->orders_entity->check_finish_v2($id,$this->session);
$redis->delete($cache_key);
throw new Exception('签名成功', API_CODE_SUCCESS);
}else{
+98
View File
@@ -22,6 +22,12 @@ 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('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');
}
/**
@@ -107,4 +113,96 @@ class Order extends Wxapp{
}
return $data;
}
//购车订单
protected function get_cars(){
$uid = $this->session['uid'];
$page = $this->input_param('page');
$size = $this->input_param('size');
!$page && $page = 1;
!$size && $size = 10;
$list = [];
$where = [
'uid' => $uid,
'pid' => 0,
'status>=' => 0
];
$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';
$rows = $this->app_liche_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');
//获取车辆属性
$v_id_arr = array_column($rows,'v_id');
$cor_id_arr = array_column($rows,'cor_id');
$incor_id_arr = array_column($rows,'incor_id');
$attr_id_arr = array_unique(array_merge($v_id_arr,$cor_id_arr,$incor_id_arr));
$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();
foreach($rows as $key=>$val){
$brand_name = $brands[$val['brand_id']] ? $brands[$val['brand_id']][0]['name'] : '';
$serie_name = $series[$val['s_id']] ? $series[$val['s_id']][0]['name'] : '';
$order = $this->receiver_orders_model->get(['id'=>$val['o_id']],'payway,price');
$info['车辆级别'] = $attrs[$val['v_id']] ? $attrs[$val['v_id']][0]['title'] : '';
$info['车身颜色'] = $attrs[$val['cor_id']] ? $attrs[$val['cor_id']][0]['title'] : '';
$info['内饰颜色'] = $attrs[$val['incor_id']] ? $attrs[$val['incor_id']][0]['title'] : '';
$cover = '';
if($attrs[$val['cor_id']]){
$jsondata = json_decode($attrs[$val['cor_id']][0]['jsondata'],true);
$cover = build_qiniu_image_url($jsondata['img']);
}
//获取子订单
$sub_rows = $this->app_liche_orders_model->select(['pid'=>$val['id'],'status>='=>0],'id asc',0,0,'id,sid,total_price,pay_time,type,status');
$sub_order = [];
if($sub_rows){
foreach($sub_rows as $k => $v){
$setValue = [
'sid' => $v['sid'],
'price' => $v['total_price'],
'type_cn' => $type_arr[$v['type']],
'status' => $v['status'],
'type' => $v['type'],
'pay_time' => $v['pay_time'],
];
//尾款子订单
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');
foreach($last_rows as $v2){
$last_orders[] = [
'price' => $v2['total_price'],
'pay_time' => $v2['pay_time'],
'pay_cn' => $v2['total_price'] == $v['total_price'] ? '全部支付' : '部分支付'
];
}
$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['sub_order'] = $last_orders;
}
$sub_order[] = $setValue;
}
}
$list[] = [
'title' => $brand_name.$serie_name,
'cover' => $cover,
'price' => $order['price'],
'sid' => $val['sid'],
'payway' => $order['payway'],
'info' => $info,
'sub_order' => $sub_order
];
}
}
$data = [
'list' => $list,
'total' => $total
];
return $data;
}
}
+142
View File
@@ -0,0 +1,142 @@
<?php
defined('WXAPP_APP') OR exit('No direct script access allowed');
/**
* Created by vim
* User: lcc
* Desc: 支付接口
* Date: 2021/06/29
* Time: 19:47
*/
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
require_once COMMPATH.'libraries/WechatPayV3.php';
class Pay extends Wxapp{
public function __construct($inputs, $app_key){
parent::__construct($inputs, $app_key);
$this->load->model('app/liche/app_liche_orders_model');
$this->load->model('receiver/order/receiver_orders_model','orders_model');
$this->load->model('auto/auto_brand_model');
$this->load->model('auto/auto_series_model');
$this->load->model('biz/biz_model');
$this->uid = $this->session['uid'];
}
//支付
public function put(){
$sid = $this->input_param('sid');
$price = $this->input_param('price');
$row = $this->app_liche_orders_model->get(['sid'=>$sid,'uid'=>$this->session['uid']]);
$type_arr = $this->app_liche_orders_model->get_type_arr();
if(!$row){
throw new Exception('订单不存在', API_CODE_FAIL);
}
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'],'uid'=>$this->uid,'type'=>2,'status'=>1]);
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'],'uid'=>$this->uid,'type'=>4,'status'=>0]);
if($inten_pay){
throw new Exception('请先支付意向金', API_CODE_FAIL);
}
}
if($row['total_price']>0){
$url = http_host_com('api');
$notify_url = $url."/wxapp/{$this->app_key}/wxnotify_v3/v2";
if($row['type']==3){ //尾款多笔支付
$is_pay = $this->app_liche_orders_model->sum('total_price',['status'=>1,'uid'=>$this->uid,'pid'=>$row['id']]); //已支付金额
$need_pay = $row['total_price'] - $is_pay['total_price']; //需支付金额
if($need_pay<=0){
throw new Exception('订单已支付完成无需支付'.$need_pay, API_CODE_FAIL);
}
if($price>$need_pay){
throw new Exception('输入金额有误,你最高只需支付'.$need_pay, API_CODE_FAIL);
}
$total = $price ? $price : $need_pay;
$sub_order = $this->app_liche_orders_model->get(['total_price'=>$total,'uid'=>$this->uid,'pid'=>$row['id'],'status'=>0]); //金额相同未支付订单
if(!$sub_order){
$sid = create_order_no(350200,'liche',1,$row['type']);
$sub_data = [
'o_id' => $row['o_id'],
'sid' => $sid,
'uid' => $this->uid,
'mch_id' => $row['mch_id'],
'pid' => $row['id'],
'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' => $total,
'type' => 3,
'c_time' => time()
];
$res = $this->app_liche_orders_model->add($sub_data);
if(!$res){
throw new Exception('创建订单失败', API_CODE_FAIL);
}
$sub_order['sid'] = $sid;
}
$out_trade_no = $sub_order['sid'];
}else{
$total = $row['total_price'];
$out_trade_no = $row['sid'];
}
if($this->uid<=10){
$total = 0.01;
}
$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');
$type_name = $type_arr[$row['type']];
$description = "{$brand_row['name']}{$s_row['name']}-{$order_row['name']}-{$biz_row['biz_name']}-{$type_name}";
$this->config->load('wxpay');
$wx_config = $this->config->item('default');
$params = [
'merchantId' => $wx_config['mchid'],
'merchantSerialNumber' => $wx_config['merchantSerialNumber'],
'merchantPrivateKey' => $wx_config['merchantPrivateKey'],
'wechatpayCertificate' => $wx_config['wechatpayCertificate'],
];
$WechatPayV3 = new WechatPayV3($params);
$json = [
'sp_appid' => $wx_config['appid'],
'sp_mchid' => $wx_config['mchid'],
'sub_appid' => $wx_config['sub_appid'],
'sub_mchid' => $row['mch_id'],
'description' => $description,
'out_trade_no' => $out_trade_no,
'notify_url' => $notify_url,
'settle_info' => [
'profit_sharing' => false
],
'amount' => [
'total' => $total*100,
],
'payer' => [
'sub_openid' => $this->session['openid']
],
];
$noncestr = getNonceStr(20);
$resq = $WechatPayV3->unifiedOrder($json,$json['sub_appid'],$noncestr);
if(!$resq['code']){
debug_log("[下单失败]:" . $resq['msg'], 'underorder.log','wxpay');
throw new Exception('微信下单失败', API_CODE_FAIL);
}
$result = $resq['data'];
}else{
$this->load->service('apporder/payment_service', array('app_id' => $this->app_id));
$result = $this->payment_service->after_pay_liche($sid);
}
return $result;
}
}
+3 -2
View File
@@ -298,7 +298,7 @@ class User extends Wxapp{
}else{
$state = 2;
}
$progressOpt = ['title'=> '交定金','url'=>'/pages/order/index?typeId=1'];
$progressOpt = ['title'=> '交定金','url'=>'/pages/mine/carOrder/index'];
}else{ //已交定金
$state = 1;
}
@@ -310,7 +310,7 @@ class User extends Wxapp{
$state = 2;
if($ckcar_row['status']==2){ //未支付
$title = $row['payway'] ? '去支付尾款' : '去支付首付';
$progressOpt = ['title'=> $title,'url'=>'/pages/order/index'];
$progressOpt = ['title'=> $title,'url'=>'/pages/mine/carOrder/index'];
}else{
$progressOpt = ['title'=> '确认车辆','url'=>'/pages/mine/signContract/queRen?id='.$row['id']];
}
@@ -344,6 +344,7 @@ class User extends Wxapp{
}
}
$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-1.png','url'=>'/pages/mine/myCar/index'],
['title'=>'联系小狸','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-3.png'],
];
@@ -18,6 +18,7 @@ class Wxnotify_v3 extends CI_Controller{
parent::__construct();
$this->load->model('app/app_wxpaylog_model', 'wxpaylog_model');
$this->load->model('apporder/order_purchase_model','purchase_model');
$this->load->model('app/liche/app_liche_orders_model');
$input = file_get_contents('php://input');
debug_log("[info] ". __FUNCTION__ . "# input:" . $input, $this->log_file,$this->log_dir);
@@ -74,4 +75,54 @@ class Wxnotify_v3 extends CI_Controller{
echo json_encode(['code'=>'SUCCESS','message'=>'成功'],JSON_UNESCAPED_UNICODE);
}
//购车订单支付回调
public function v2(){
$client = new GuzzleHttp\Client();
try {
$resp = $client->request('POST', $this->desc_url, ['form_params' => $this->notify_data]);
$result = json_decode($resp->getBody(),true);
if(!$result['code']){ //解密失败
debug_log("[error] ". __FUNCTION__ . "# 解密失败:" . $resp->getBody(), $this->log_file,$this->log_dir);
}else{
debug_log("[info] ". __FUNCTION__ . "# 解密成功:" . $resp->getBody(), $this->log_file,$this->log_dir);
$sid = $result['data']['out_trade_no'];
if($sid){
debug_log("[start] ". __FUNCTION__ . ": sid:".$sid, $this->log_file,$this->log_dir);
$order = $this->app_liche_orders_model->get(array('sid'=>$sid));
if(!$order){
debug_log("[error] ". __FUNCTION__ . ":{$sid}_订单不存在", $this->log_file,$this->log_dir);
}
//执行失败
$add = array(
'app_id' => $this->app_id,
'sid' => $sid?$sid:0,
'trade_no' => $result['data']['transaction_id'],
'notify_param' => json_encode($result['data'],JSON_UNESCAPED_UNICODE)
);
$ret = $this->wxpaylog_model->add($add);
if(!$ret){
debug_log("[error] ". __FUNCTION__ . ": sql:".$this->wxpaylog_model->db->last_query(), $this->log_file,$this->log_dir);
}
if($result['data']['trade_state'] != 'SUCCESS'){ //支付失败
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']){
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{
debug_log("[finish] ". __FUNCTION__ . ": 参数错误:".json_encode($result,JSON_UNESCAPED_UNICODE), $this->log_file,$this->log_dir);
}
}
} catch (RequestException $e) {
debug_log("[error] ". __FUNCTION__ . "# 请求失败:" . $e->getResponse(), $this->log_file,$this->log_dir);
}
echo json_encode(['code'=>'SUCCESS','message'=>'成功'],JSON_UNESCAPED_UNICODE);
}
}
+20 -4
View File
@@ -72,16 +72,25 @@ class Cusorder extends Wxapp{
$cardid = $this->input_param('cardid');
$delry_time = $this->input_param('delry_time');
$fin_nums_id = $this->input_param('fin_nums_id');
$inten_money = floatval($this->input_param('inten_money'));//意向金
$row = $this->customers_model->get(['id'=>$cus_id]);
$series_row = $this->auto_series_model->get(['id'=>$car_id]);
if(!$price || !$deposit){
throw new Exception('车辆价格参数未配置', ERR_PARAMS_ERROR);
}
if(!$row || !$series_row || !$cardid || !$address ||!$delry_time){
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
if($inten_money > $deposit){
throw new Exception('意向金大于定金', ERR_PARAMS_ERROR);
}
//判断是否存在未完成流程
$omobile = $mobile ? $mobile : $row['mobile'];
if($this->orders_model->get_step($omobile)){
throw new Exception('该手机号用户存在未完成订单', API_CODE_FAIL);
$o_order = $this->orders_model->get_step($omobile);
if($o_order){
$this->orders_model->update(['status'=>-1],['id'=>$o_order['id']]);
// throw new Exception('该手机号用户存在未完成订单', API_CODE_FAIL);
}
$car_row = $this->auto_cars_model->get(['brand_id'=>$series_row['brand_id'],'s_id'=>$series_row['id'],'v_id'=>$v_id,'cor_id'=>$color_id,'incor_id'=>$incolor_id]);
if(!$car_row){
@@ -180,6 +189,13 @@ class Cusorder extends Wxapp{
'c_time' => time()
];
$this->order_signs_model->add($sign_data);
//意向金订单
if($inten_money){
$this->load->library('receiver/orders_entity');
$this->load->model('app/liche/app_liche_users_model');
$userinfo = $this->app_liche_users_model->get(['mobile'=>$mobile]);
$this->orders_entity->c_intention($o_id,$userinfo,$inten_money);
}
return ['id'=>$o_id];
}else{
throw new Exception('创建失败', ERR_PARAMS_ERROR);
@@ -417,8 +433,8 @@ class Cusorder extends Wxapp{
if($result){
$this->orders_model->update(['status'=>6],['id'=>$row['o_id']]);
//完成支付订单
$this->load->library('receiver/orders_entity');
$this->orders_entity->finish_after($row['o_id'],1);
//$this->load->library('receiver/orders_entity');
//$this->orders_entity->finish_after($row['o_id'],1);
throw new Exception('修改成功', API_CODE_SUCCESS);
}else{
throw new Exception('修改失败', ERR_PARAMS_ERROR);
+15 -5
View File
@@ -28,6 +28,7 @@ class Protocol extends CI_Controller{
$this->load->model("sys/sys_company_model");
$this->load->model("items/items_model");
$this->load->model('apporder/order_purchase_model','purchase_model');
$this->load->model('app/liche/app_liche_orders_model');
}
//整车合同
@@ -157,13 +158,22 @@ class Protocol extends CI_Controller{
$biz = $this->biz_model->get(['id'=>$row['biz_id']]);
$company = $this->sys_company_model->get(['id'=>$biz['company_id']]);
$row['company'] = $company;
$p_row = $this->app_liche_orders_model->get(['o_id'=>$row['id'],'pid'=>0,'status>='=>0],'id');
$where = [
'item_id' => $row['id'],
'app_id' => 1,
'status>' => 1
'o_id' => $row['id'],
'status' => 1,
'type in (1,2,4)' => null
];
$pay = $this->purchase_model->sum('total_price',$where);
$row['pay_price'] = $pay['total_price'];
$pay = $this->app_liche_orders_model->sum('total_price',$where);
//尾款
$where = [
'o_id' => $row['id'],
'status' => 1,
'type' => 3,
'pid!=' => $p_row['id']
];
$last_pay = $this->app_liche_orders_model->sum('total_price',$where);
$row['pay_price'] = $pay['total_price'] + $last_pay['total_price'];
$this->load->library('receiver/orders_entity');
$total_price = $this->orders_entity->order_srv_money($row['id']);
}
+237 -3
View File
@@ -29,6 +29,7 @@ class Orders_entity{
$this->ci->load->model('auto/auto_cars_model');
$this->ci->load->model("biz/biz_model");
$this->ci->load->model('app/liche/app_liche_orders_model');
}
/*
@@ -77,7 +78,7 @@ class Orders_entity{
}
$customers = $this->ci->customers_model->get(['id'=>$this->order_row['rid']],'rid');
$ifpay = false;
$ifpay = $this->ci->order_purchase_model->count(['status>'=>1,'item_id'=>$oid,'app_id',$app_id,'app_uid'=>$userinfo['uid']]);
$ifpay = $this->ci->order_purchase_model->count(['status>'=>1,'item_id'=>$oid,'app_id'=>$app_id,'app_uid'=>$userinfo['uid']]);
if($customers['rid'] && !$ifpay){ //判断线索是否支付定金
$ifpay = $this->ci->order_purchase_model->count(['type'=>3,'status'=>2,'cf_id'=>$customers['rid'],'app_id'=>$app_id,'app_uid'=>$userinfo['uid']]);
}
@@ -97,7 +98,7 @@ class Orders_entity{
$this->ci->next_model->add(['o_id'=>$this->order_row['id'],'c_time'=>time()]);
}
}else{
$res = $this->ci->orders_model->update(['status'=>2],['id'=>$row['id']]);
$res = $this->ci->orders_model->update(['status'=>2],['id'=>$this->order_row['id']]);
}
}else{
$this->ci->signs_model->update(['status'=>1],['o_id'=>$this->order_row['id']]);
@@ -113,6 +114,95 @@ class Orders_entity{
$res = $this->c_order($mch_id,$this->order_row,$app_id,$userinfo);
}
return $res;
}
/**
* 签完成协议后操作
* @param $oid int 订单id
* @param $userinfo array 小程序用户信息
*/
public function sign_after_v2($oid,$userinfo){
$this->order_row = $this->ci->orders_model->get(['id'=>$oid]);
if(!$this->order_row){
return false;
}
$pay_money = $this->ci->app_liche_orders_model->get(['o_id'=>$oid,'uid'=>$userinfo['uid'],'type'=>4,'status'=>1]); //已支付意向金订单
if(!$pay_money){//未支付意向订单设置删除
$this->ci->app_liche_orders_model->update(['status'=>-1],['o_id'=>$oid,'uid'=>$userinfo['uid'],'type'=>4,'status'=>0]);
}
$need_pay_money = $this->order_row['deposit'] - $pay_money['total_price'];
if($need_pay_money > 0){
$this->ci->signs_model->update(['status'=>1],['o_id'=>$this->order_row['id']]);
$srv_money = $this->order_srv_money($oid);
if($srv_money < $this->order_row['deposit']){ //服务费小于定金 给销售公司
//获取门店信息
$biz = $this->ci->biz_model->get(['id'=>$this->order_row['biz_id']],'company_id');
$company = $this->ci->sys_company_model->get(['id'=>$biz['company_id']],'wx_mchid');
$mch_id = $company['wx_mchid'];
}else{
$mch_id = self::SRV_MCH_ID;
}
$p_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'uid'=>$userinfo['id'],'pid'=>0,'status>='=>0]);
if(!$p_row){
$sid = create_order_no(350200,'liche',1,0);
$add_data = [
'o_id' => $this->order_row['id'],
'uid' => $userinfo['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()
];
$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'=>$userinfo['id'],'type'=>1,'status>='=>0]);
if($pid && !$sub_row){
$sid = create_order_no(350200,'liche',1,1);
$sub_data = [
'o_id' => $this->order_row['id'],
'uid' => $userinfo['id'],
'sid' => $sid,
'mch_id' => $mch_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()
];
$res = $this->ci->app_liche_orders_model->add($sub_data);
}
}else{
if($pay_money['status']){
$this->ci->signs_model->update(['status'=>2],['o_id'=>$oid]);
if($this->order_row['payway']){//全款
$status = 2;
$this->ci->load->model('receiver/order/receiver_order_ckcars_model','next_model');
}else{
$status = 1;
$this->ci->load->model('receiver/order/receiver_order_loans_model','next_model');
}
//判断下一步是否存在
if(!$this->ci->next_model->get(['o_id'=>$this->order_row['id']])){
$res = $this->ci->orders_model->update(['status'=>$status],['id'=>$this->order_row['id']]);
if($res){
$this->ci->next_model->add(['o_id'=>$this->order_row['id'],'c_time'=>time()]);
}
}else{
$res = $this->ci->orders_model->update(['status'=>2],['id'=>$this->order_row['id']]);
}
}
}
return $res;
}
/**
* 创建定金消费订单
@@ -307,7 +397,7 @@ class Orders_entity{
}else{ //分期
if($srv_money < $this->order_row['deposit']){ //服务费小于定金
$to_srv_price = $srv_money;
$to_com_price = $money_json['first_pay'] - $this->order['deposit'];
$to_com_price = $money_json['first_pay'] - $this->order_row['deposit'];
$to_com_price = $to_com_price>0 ? $to_com_price : 0;
}else{
$to_com_price = $money_json['first_pay']; //给销售公司金额
@@ -400,6 +490,150 @@ class Orders_entity{
}
return $srv_price;
}
//确认车辆完成创建两个支付订单
public function check_finish_v2($oid,$userinfo){
$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'=>$userinfo['id'],'status>='=>0],'id'); //父订单
if(!$this->order_row || !$p_row){
return false;
}
$car_json = json_decode($this->order_row['car_json'],true);
$color = isset($car_json['color']) ? $car_json['color'] : '';
$jsondata['car'] = $car_json;
if($color['jsondata']['img']){
$jsondata['cover'] = $color['jsondata']['img'];
}
//获取门店信息
$biz = $this->ci->biz_model->get(['id'=>$this->order_row['biz_id']],'company_id');
$company = $this->ci->sys_company_model->get(['id'=>$biz['company_id']]);
$srv_money = $this->order_srv_money($oid); //服务费
$money_json = json_decode($this->order_row['money_json'],true);
if($this->order_row['payway']){ //全款
if($srv_money < $this->order_row['deposit']){ //服务费小于定金
$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;
}
}else{ //分期
if($srv_money < $this->order_row['deposit']){ //服务费小于定金
$to_srv_price = $srv_money;
$to_com_price = $money_json['first_pay'] - $this->order_row['deposit'];
$to_com_price = $to_com_price>0 ? $to_com_price : 0;
}else{
$to_com_price = $money_json['first_pay']; //给销售公司金额
$to_srv_price = $srv_money - $this->order_row['deposit']; //给服务公司的金额 服务费-定金
$to_srv_price = $to_srv_price>0 ? $to_srv_price : 0;
}
}
$add_data = [];
if($to_srv_price>0 && !$this->ci->app_liche_orders_model->count(['o_id'=>$this->order_row['id'],'type'=>2,'uid'=>$userinfo['id'],'status>='=>0])){
$order_type = 2;
$sid = create_order_no(350200,'liche',1,$order_type);
$add_data[] = [
'o_id' => $this->order_row['id'],
'uid' => $userinfo['id'],
'sid' => $sid,
'mch_id' => 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' => $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,'uid'=>$userinfo['id'],'status>='=>0])){
$order_type = 3;
$sid = create_order_no(350200,'liche',1,$order_type);
$add_data[] = [
'o_id' => $this->order_row['id'],
'uid' => $userinfo['id'],
'sid' => $sid,
'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()
];
}
$result = false;
if($add_data){
$result = $this->ci->app_liche_orders_model->add_batch($add_data);
}
return $result;
}
//创建意向金订单
public function c_intention($oid,$userinfo,$money){
$this->order_row = $this->ci->orders_model->get(['id'=>$oid]);
if(!$this->order_row || !$userinfo){
return false;
}
$p_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'uid'=>$userinfo['id'],'pid'=>0,'status>='=>0]);
if(!$p_row){
$sid = create_order_no(350200,'liche',1,0);
$add_data = [
'o_id' => $this->order_row['id'],
'uid' => $userinfo['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()
];
$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'=>$userinfo['id'],'type'=>4,'status>='=>0]);
if($pid && !$sub_row){
$srv_money = $this->order_srv_money($oid);
if($srv_money < $this->order_row['deposit']){ //服务费小于定金 给销售公司
//获取门店信息
$biz = $this->ci->biz_model->get(['id'=>$this->order_row['biz_id']],'company_id');
$company = $this->ci->sys_company_model->get(['id'=>$biz['company_id']],'wx_mchid');
$mch_id = $company['wx_mchid'];
}else{
$mch_id = self::SRV_MCH_ID;
}
$sid = create_order_no(350200,'liche',1,4);
$sub_data = [
'o_id' => $this->order_row['id'],
'uid' => $userinfo['id'],
'sid' => $sid,
'mch_id' => $mch_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()
];
$res = $this->ci->app_liche_orders_model->add($sub_data);
}
return $res;
}
}
?>
@@ -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 => '尾款'];
private $type_arr = [ 1 => '定金', 2 => '委托服务费' , 3 => '尾款' ,4 => '意向金'];
public function __construct()
{
@@ -63,7 +63,8 @@ class Receiver_orders_model extends HD_Model
//];
$where = [
"$t1.mobile" => $mobile,
"$t1.status<" => 6
"$t1.status<" => 6,
"$t1.status>=" => 0
];
$this->db->where($where);
$this->db->order_by("$t1.id desc");
@@ -97,8 +98,8 @@ class Receiver_orders_model extends HD_Model
$this->db->order_by("$t1.id desc");
if ($page) {
$offset = ($page - 1) * $page_size;
$limit = $page_size;
$offset = ($page - 1) * $size;
$limit = $size;
} else {
$offset = null;
$limit = null;
+102 -1
View File
@@ -14,6 +14,8 @@ class Payment_service extends HD_Service{
}
$this->log_file = __CLASS__."_app_id_".$this->app_id.'.log';
$this->load->model('apporder/order_purchase_model', 'purchase_model');
$this->load->model('app/liche/app_liche_orders_model');
$this->load->model('receiver/receiver_clues_model','clues_model');
$this->load->model('receiver/receiver_customers_model','customers_model');
@@ -118,7 +120,106 @@ class Payment_service extends HD_Service{
}
break;
default:
debug_log("[error] ". __FUNCTION__ . ":{$item['type']}_未知商品类型", $this->log_file);
debug_log("[error] ". __FUNCTION__ . ":{$order['type']}_未知商品类型", $this->log_file);
return array('code'=>0,'msg'=>'未知商品类型');
}
}
}
/**
* 支付后逻辑
* @param string $sid
* @param float $pay_price 订单真实支付金额
*/
public function after_pay_liche($sid,$pay_price = ''){
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'=>'订单已支付');
}
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;
$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 ($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');
}
$res = $this->orders_model->update(['status' => $status], ['id' => $row['id']]);
$this->order_signs_model->update(['status' => 2], ['o_id' => $row['id']]);
if ($res) {
$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: //服务费
$upd = array('status'=>1,'pay_time'=>date('Y-m-d H:i:s'));
$pay_price && $upd['pay_price'] = $pay_price;
$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;
$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,'uid'=>$order['uid'],'pid'=>$order['pid']]); //已支付金额
$p_row = $this->app_liche_orders_model->get(['uid'=>$order['uid'],'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){
$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()]);
}
}
}
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;
$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;
default:
debug_log("[error] ". __FUNCTION__ . ":{$order['type']}_未知商品类型", $this->log_file);
return array('code'=>0,'msg'=>'未知商品类型');
}
}