edit-liche-create_pay_order
This commit is contained in:
@@ -8,10 +8,4 @@ class Welcome extends CI_Controller {
|
||||
$this->load->view('welcome_message');
|
||||
}
|
||||
|
||||
public function test(){
|
||||
$this->load->library('TcOrc');
|
||||
$img = '';
|
||||
$result = $this->tcorc->BizLicense($img);
|
||||
print_r($result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,biz_id,ifentrust,srv_ids,info_json');
|
||||
$order = $this->orders_model->get(['id'=>$id],'brand_id,mobile,biz_id,ifentrust,srv_ids,info_json');
|
||||
if(!$row['file'] || !$img){
|
||||
throw new Exception('参数错误', API_CODE_INVILD_PARAM);
|
||||
}
|
||||
@@ -165,7 +165,8 @@ class Contract extends Wxapp{
|
||||
$result = $this->contracts_model->update($update,['id'=>$row['id']]);
|
||||
if($result){
|
||||
if(!$order['srv_ids']){
|
||||
$this->orders_entity->sign_after_v2($id,$this->session);
|
||||
$userinfo = $this->app_user_model->get(['mobile'=>$order['mobile']]);
|
||||
$this->orders_entity->sign_after_v2($id,$userinfo);
|
||||
}
|
||||
$redis->delete($cache_key);
|
||||
throw new Exception('签名成功', API_CODE_SUCCESS);
|
||||
@@ -192,7 +193,8 @@ class Contract extends Wxapp{
|
||||
];
|
||||
$result = $this->contracts_model->update($update,['id'=>$row['id']]);
|
||||
if($result){
|
||||
$this->orders_entity->sign_after_v2($id,$this->session);
|
||||
$userinfo = $this->app_user_model->get(['mobile'=>$order['mobile']]);
|
||||
$this->orders_entity->sign_after_v2($id,$userinfo);
|
||||
$redis->delete($cache_key);
|
||||
throw new Exception('签名成功', API_CODE_SUCCESS);
|
||||
}else{
|
||||
@@ -223,7 +225,8 @@ class Contract extends Wxapp{
|
||||
}else{
|
||||
$this->ckcars_model->update(['status'=>2],['o_id'=>$id]);
|
||||
//生成支付订单
|
||||
$this->orders_entity->check_finish_v2($id,$this->session);
|
||||
$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);
|
||||
|
||||
@@ -123,7 +123,7 @@ class Order extends Wxapp{
|
||||
|
||||
$list = [];
|
||||
$where = [
|
||||
'uid' => $uid,
|
||||
"(uid = {$uid} or entrust_uid={$uid})" => null,
|
||||
'pid' => 0,
|
||||
'status>=' => 0
|
||||
];
|
||||
|
||||
@@ -22,6 +22,8 @@ class Pay extends Wxapp{
|
||||
$this->load->model('biz/biz_model');
|
||||
$this->load->model("sys/sys_company_model");
|
||||
|
||||
$this->load->library('receiver/orders_entity');
|
||||
|
||||
$this->uid = $this->session['uid'];
|
||||
}
|
||||
|
||||
@@ -29,7 +31,7 @@ class Pay extends Wxapp{
|
||||
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']]);
|
||||
$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);
|
||||
@@ -38,13 +40,13 @@ class Pay extends Wxapp{
|
||||
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'=>0]);
|
||||
$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'],'uid'=>$this->uid,'type'=>4,'status'=>0]);
|
||||
$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);
|
||||
}
|
||||
@@ -53,7 +55,7 @@ class Pay extends Wxapp{
|
||||
$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']]); //已支付金额
|
||||
$is_pay = $this->app_liche_orders_model->sum('total_price',['status'=>1,'pid'=>$row['id']]); //已支付金额
|
||||
$need_pay = $row['total_price'] - $is_pay['total_price']; //需支付金额
|
||||
if($need_pay<=0){
|
||||
throw new Exception('订单已支付完成无需支付'.$need_pay, API_CODE_FAIL);
|
||||
@@ -65,7 +67,7 @@ class Pay extends Wxapp{
|
||||
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]); //金额相同未支付订单
|
||||
$sub_order = $this->app_liche_orders_model->get(['total_price'=>$total,'pid'=>$row['id'],'status'=>0]); //金额相同未支付订单
|
||||
if(!$sub_order){
|
||||
$sid = create_order_no(350200,'liche',1,$row['type']);
|
||||
$sub_data = [
|
||||
@@ -83,6 +85,8 @@ class Pay extends Wxapp{
|
||||
'type' => 3,
|
||||
'c_time' => time()
|
||||
];
|
||||
$entrust_user = $this->orders_entity->entrust_user($row['o_id']);
|
||||
$entrust_user['id'] && $sub_data['entrust_uid'] = $entrust_user['uid'];
|
||||
$res = $this->app_liche_orders_model->add($sub_data);
|
||||
if(!$res){
|
||||
throw new Exception('创建订单失败', API_CODE_FAIL);
|
||||
|
||||
@@ -84,15 +84,16 @@ class Orders_entity{
|
||||
* @param $userinfo array 小程序用户信息
|
||||
*/
|
||||
public function sign_after_v2($oid,$userinfo){
|
||||
$uid = $userinfo['id'] ? $userinfo['id'] : 0;
|
||||
$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]); //已支付意向金订单
|
||||
$pay_money = $this->ci->app_liche_orders_model->get(['o_id'=>$oid,'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]);
|
||||
$this->ci->app_liche_orders_model->update(['status'=>-1],['o_id'=>$oid,'type'=>4,'status'=>0]);
|
||||
}
|
||||
$deposit_count = $this->ci->app_liche_orders_model->count(['o_id'=>$oid,'uid'=>$userinfo['uid'],'type'=>1,'status'=>1]); //定金已支付
|
||||
$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'];
|
||||
if($need_pay_money > 0 && !$deposit_count){
|
||||
$this->ci->signs_model->update(['status'=>1],['o_id'=>$this->order_row['id']]);
|
||||
@@ -109,12 +110,13 @@ class Orders_entity{
|
||||
$company['wx_mchid'] && $mch_id = $company['wx_mchid'];
|
||||
}
|
||||
}
|
||||
$p_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'uid'=>$userinfo['id'],'pid'=>0,'status>='=>0]);
|
||||
$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'],
|
||||
'uid' => $userinfo['id'],
|
||||
'uid' => $uid,
|
||||
'sid' => $sid,
|
||||
'pid' => 0,
|
||||
'brand_id' => $this->order_row['brand_id'],
|
||||
@@ -124,17 +126,18 @@ class Orders_entity{
|
||||
'incor_id' => $this->order_row['incor_id'],
|
||||
'c_time' => time()
|
||||
];
|
||||
$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'];
|
||||
}
|
||||
$res = false;
|
||||
$sub_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'uid'=>$userinfo['id'],'type'=>1,'status>='=>0]);
|
||||
$sub_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['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'],
|
||||
'uid' => $uid,
|
||||
'sid' => $sid,
|
||||
'mch_id' => $mch_id,
|
||||
'pid' => $pid,
|
||||
@@ -147,6 +150,7 @@ class Orders_entity{
|
||||
'total_price' => $need_pay_money,
|
||||
'c_time' => time()
|
||||
];
|
||||
$entrust_user['id'] && $sub_data['entrust_uid'] = $entrust_user['id'];
|
||||
$res = $this->ci->app_liche_orders_model->add($sub_data);
|
||||
}
|
||||
}else{
|
||||
@@ -377,8 +381,9 @@ class Orders_entity{
|
||||
|
||||
//确认车辆完成创建两个支付订单
|
||||
public function check_finish_v2($oid,$userinfo){
|
||||
$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'=>$userinfo['id'],'status>='=>0],'id'); //父订单
|
||||
$p_row = $this->ci->app_liche_orders_model->get(['pid'=>0,'o_id'=>$oid,"(uid={$uid} or entrust_uid={$uid})"=>null,'status>='=>0],'id'); //父订单
|
||||
if(!$this->order_row || !$p_row){
|
||||
return false;
|
||||
}
|
||||
@@ -397,7 +402,7 @@ 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'=>$userinfo['id'],'type'=>4,'status'=>1,'o_id!='=>253]); //已支付意向金订单
|
||||
$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]); //已支付意向金订单
|
||||
|
||||
$srv_money = $this->order_srv_money($oid); //服务费
|
||||
$money_json = json_decode($this->order_row['money_json'],true);
|
||||
@@ -424,12 +429,14 @@ class Orders_entity{
|
||||
}
|
||||
}
|
||||
$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])){
|
||||
$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])){
|
||||
$order_type = 2;
|
||||
$sid = create_order_no(350200,'liche',1,$order_type);
|
||||
$add_data[] = [
|
||||
'o_id' => $this->order_row['id'],
|
||||
'uid' => $userinfo['id'],
|
||||
'uid' => $uid,
|
||||
'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0,
|
||||
'sid' => $sid,
|
||||
'mch_id' => $srv_company ? $srv_company['wx_mchid'] : self::SRV_MCH_ID,
|
||||
'pid' => $p_row['id'],
|
||||
@@ -443,12 +450,13 @@ 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'=>$userinfo['id'],'status>='=>0])){
|
||||
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])){
|
||||
$order_type = 3;
|
||||
$sid = create_order_no(350200,'liche',1,$order_type);
|
||||
$add_data[] = [
|
||||
'o_id' => $this->order_row['id'],
|
||||
'uid' => $userinfo['id'],
|
||||
'uid' => $uid,
|
||||
'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0,
|
||||
'sid' => $sid,
|
||||
'mch_id' => $company['wx_mchid'],
|
||||
'pid' => $p_row['id'],
|
||||
@@ -474,13 +482,15 @@ class Orders_entity{
|
||||
if(!$this->order_row){
|
||||
return false;
|
||||
}
|
||||
!$userinfo && $userinfo['id'] = 0;
|
||||
$p_row = $this->ci->app_liche_orders_model->get(['o_id'=>$this->order_row['id'],'uid'=>$userinfo['id'],'pid'=>0,'status>='=>0]);
|
||||
$uid = $userinfo['id'] ? $userinfo['id'] : 0;
|
||||
$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'],
|
||||
'uid' => $userinfo['id'],
|
||||
'uid' => $uid,
|
||||
'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0,
|
||||
'sid' => $sid,
|
||||
'pid' => 0,
|
||||
'brand_id' => $this->order_row['brand_id'],
|
||||
@@ -495,7 +505,7 @@ class Orders_entity{
|
||||
$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]);
|
||||
$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);
|
||||
//获取门店信息
|
||||
@@ -505,7 +515,8 @@ class Orders_entity{
|
||||
$sid = create_order_no(350200,'liche',1,4);
|
||||
$sub_data = [
|
||||
'o_id' => $this->order_row['id'],
|
||||
'uid' => $userinfo['id'],
|
||||
'uid' => $uid,
|
||||
'entrust_uid' => $entrust_user['id'] ? $entrust_user['id'] : 0,
|
||||
'sid' => $sid,
|
||||
'mch_id' => $mch_id,
|
||||
'pid' => $pid,
|
||||
@@ -664,6 +675,26 @@ class Orders_entity{
|
||||
}
|
||||
return $recevable_price;
|
||||
}
|
||||
/**
|
||||
* 获取委托代理用户信息
|
||||
* @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->orders_model->get(['id'=>$oid]);
|
||||
if(!$this->order_row){
|
||||
return [];
|
||||
}
|
||||
$info_json = json_decode($this->order_row['info_json'],true);
|
||||
if($this->order_row['ifentrust'] && $info_json['entrust_mobile']){
|
||||
$user = $this->ci->app_liche_users_model->get(['mobile'=>$info_json['entrust_mobile']]);
|
||||
return $user;
|
||||
}else{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user