Files
liche/common/services/apporder/Payment_service.php
T
2021-07-22 10:01:41 +08:00

91 lines
4.0 KiB
PHP

<?php
/**
* Created by vim
* User: lcc
* Date: 2021/3/25
* Time: 16:57
*/
class Payment_service extends HD_Service{
public function __construct($params){
parent::__construct();
if($params['app_id']){
$this->app_id = $params['app_id'];
}
$this->log_file = __CLASS__."_app_id_".$this->app_id.'.log';
$this->load->model('apporder/order_purchase_model', 'purchase_model');
}
/**
* 支付后逻辑
* @param string $sid
* @param float $pay_price 订单真实支付金额
*/
public function after_pay($sid,$pay_price = ''){
if($sid){
debug_log("[start] ". __FUNCTION__ . ": sid:".$sid, $this->log_file);
$order = $this->purchase_model->get(array('sid'=>$sid,'app_id'=>$this->app_id,'status'=>1));
if(!$order){
debug_log("[error] ". __FUNCTION__ . ":{$sid}_订单不存在", $this->log_file);
return array('code'=>0,'msg'=>'订单不存在');
}
if(!$order['status']>1){
debug_log("[error] ". __FUNCTION__ . ":{$sid}_订单已支付", $this->log_file);
return array('code'=>0,'msg'=>'订单已支付');
}
switch ($order['type']){
case 1: //实物商品
break;
case 2: //虚拟物品
break;
case 3: //活动订单
$upd = array('status'=>2,'status_detail'=>21,'pay_time'=>date('Y-m-d H:i:s'));
$pay_price && $upd['pay_price'] = $pay_price;
$res = $this->purchase_model->update($upd,array('id'=>$order['id']));
if($res){
return array('code'=>1,'msg'=>'操作成功');
}else{
return array('code'=>0,'msg'=>'更新失败');
}
break;
case 4: //定金
$upd = array('status'=>2,'status_detail'=>21,'pay_time'=>date('Y-m-d H:i:s'));
$pay_price && $upd['pay_price'] = $pay_price;
$res = $this->purchase_model->update($upd,array('id'=>$order['id']));
if($res){
//更新订单状态
$this->load->model('receiver/order/receiver_orders_model','orders_model');
$this->load->model('receiver/order/receiver_order_signs_model','order_signs_model');
$row = $this->orders_model->get(['id'=>$order['item_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;
default:
debug_log("[error] ". __FUNCTION__ . ":{$item['type']}_未知商品类型", $this->log_file);
return array('code'=>0,'msg'=>'未知商品类型');
}
}
}
}