修改小程序4s店确定订单流程、后台增加cps金额、修改审核补贴扣除商家cps金额
This commit is contained in:
@@ -167,4 +167,19 @@ class Product extends BaseController
|
||||
$this->autoProduct->update($update, ['id' => $params['id']]);
|
||||
$this->return_response();
|
||||
}
|
||||
/**
|
||||
* 修改CPS金额
|
||||
*/
|
||||
public function cps_put()
|
||||
{
|
||||
$params = $this->input_param();
|
||||
if (!$this->autoProduct->get(['id' => $params['id']])) {
|
||||
$this->return_json('参数错误');
|
||||
}
|
||||
$update = [
|
||||
'cpsMoney' => $params['cpsMoney'] ?: 0,
|
||||
];
|
||||
$this->autoProduct->update($update, ['id' => $params['id']]);
|
||||
$this->return_response();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,22 +220,27 @@ class Cusorder extends Wxapp
|
||||
//修改订单状态
|
||||
protected function put_status()
|
||||
{
|
||||
$biz = $this->get_biz_info();
|
||||
$id = $this->input_param('id');
|
||||
$status = $this->input_param('status');
|
||||
$row = $this->orders_model->get(['id' => $id]);
|
||||
$data_row = $this->receiver_order_datas_model->get(['o_id' => $id]);
|
||||
if (!$row || !$status) throw new Exception('参数错误', ERR_PARAMS_ERROR);
|
||||
if ($status == 1) { //下定信息确认无误 判断:合同、付款凭证、身份证、权益书必须上传
|
||||
if (!$data_row['contract_img']) throw new Exception('合同未上传', ERR_PARAMS_ERROR);
|
||||
if (!$data_row['cardida'] && !$row['main_type']) throw new Exception('身份证未上传', ERR_PARAMS_ERROR);
|
||||
if (!$data_row['bill_img'] && $row['main_type']) throw new Exception('营业执照未上传', ERR_PARAMS_ERROR);
|
||||
if (!$data_row['pay_img']) throw new Exception('付款凭证未上传', ERR_PARAMS_ERROR);
|
||||
//if (!$data_row['equity_ck_img']) throw new Exception('权益书未上传', ERR_PARAMS_ERROR);
|
||||
} elseif ($status == 2) { //开票信息确认无误:判断 发票 必须上传
|
||||
if (!$data_row['bill_img']) throw new Exception('发票未上传', ERR_PARAMS_ERROR);
|
||||
} elseif ($status == 3) {//车辆交付信息: 判断 行驶证、保单 必须上传
|
||||
if (!$data_row['car_img']) throw new Exception('行驶证未上传', ERR_PARAMS_ERROR);
|
||||
if (!$data_row['insurance_img']) throw new Exception('保单未上传', ERR_PARAMS_ERROR);
|
||||
if ($biz['type'] != Biz_model::BIZ_TYPE_4s) { //不是4s店铺
|
||||
if ($status == 1) { //下定信息确认无误 判断:合同、付款凭证、身份证、权益书必须上传
|
||||
if (!$data_row['contract_img']) throw new Exception('合同未上传', ERR_PARAMS_ERROR);
|
||||
if (!$data_row['cardida'] && !$row['main_type']) throw new Exception('身份证未上传', ERR_PARAMS_ERROR);
|
||||
if (!$data_row['bill_img'] && $row['main_type']) throw new Exception('营业执照未上传', ERR_PARAMS_ERROR);
|
||||
if (!$data_row['pay_img']) throw new Exception('付款凭证未上传', ERR_PARAMS_ERROR);
|
||||
//if (!$data_row['equity_ck_img']) throw new Exception('权益书未上传', ERR_PARAMS_ERROR);
|
||||
} elseif ($status == 2) { //开票信息确认无误:判断 发票 必须上传
|
||||
if (!$data_row['bill_img']) throw new Exception('发票未上传', ERR_PARAMS_ERROR);
|
||||
} elseif ($status == 3) {//车辆交付信息: 判断 行驶证、保单 必须上传
|
||||
if (!$data_row['car_img']) throw new Exception('行驶证未上传', ERR_PARAMS_ERROR);
|
||||
if (!$data_row['insurance_img']) throw new Exception('保单未上传', ERR_PARAMS_ERROR);
|
||||
}
|
||||
}else{
|
||||
$status = 3;
|
||||
}
|
||||
$update = ['status' => $status];
|
||||
if ($status == 3) {
|
||||
@@ -554,6 +559,8 @@ class Cusorder extends Wxapp
|
||||
$car_data['车型'] = $car['name'];
|
||||
$row['color'] && $car_data['车身颜色'] = $row['color'];
|
||||
$row['in_color'] && $car_data['内饰颜色'] = $row['in_color'];
|
||||
$bt_cn_array = [0 => '下定信息确认无误', 1 => '发票信息确认无误', 2 => '交付信息确认无误'];
|
||||
$bt_cn = $bt_cn_array[$row['status']];
|
||||
if ($biz['type'] != Biz_model::BIZ_TYPE_4s) {
|
||||
$row['delry_time'] != '0000-00-00 00:00:00' && $car_data['期望交付时间'] = date('Y-m-d', strtotime($row['delry_time']));
|
||||
$money_json['confirm_amount'] && $car_data['定金'] = $money_json['confirm_amount'];
|
||||
@@ -568,8 +575,9 @@ class Cusorder extends Wxapp
|
||||
if ($row['if_num']) {
|
||||
$car_data['上牌费'] = $money_json['register_amount'] ? $money_json['register_amount'] : 0;
|
||||
}
|
||||
}else{
|
||||
$bt_cn = '确认订单';
|
||||
}
|
||||
$bt_cn_array = [0 => '下定信息确认无误', 1 => '发票信息确认无误', 2 => '交付信息确认无误'];
|
||||
$data = [
|
||||
'id' => $id,
|
||||
'name' => $row['name'],
|
||||
@@ -584,7 +592,7 @@ class Cusorder extends Wxapp
|
||||
'color' => $row['color'],
|
||||
'in_color' => $row['in_color'],
|
||||
'status' => $row['status'],
|
||||
'bt_cn' => $bt_cn_array[$row['status']],
|
||||
'bt_cn' => $bt_cn,
|
||||
'car_data' => $car_data,
|
||||
'if_num' => $row['if_num'],
|
||||
'if_insure' => $row['if_insure'],
|
||||
|
||||
@@ -664,11 +664,11 @@ class User extends Wxapp
|
||||
$bizId = $this->get_biz_id();
|
||||
$bizAccount = new BizAccount();
|
||||
$account = $bizAccount->getAccountBizId($bizId);
|
||||
$menu[] = [
|
||||
'title' => '核销记录',
|
||||
'icon' => 'https://img.liche.cn/lichebao/menu-2.png',
|
||||
'url' => '/pages/customer/score/exchange'
|
||||
];
|
||||
// $menu[] = [
|
||||
// 'title' => '核销记录',
|
||||
// 'icon' => 'https://img.liche.cn/lichebao/menu-2.png',
|
||||
// 'url' => '/pages/customer/score/exchange'
|
||||
// ];
|
||||
$menu[] = [
|
||||
'title' => '积分余额',
|
||||
'icon' => 'https://img.liche.cn/lichebao/menu-1.png',
|
||||
|
||||
@@ -19,6 +19,7 @@ class AutoProductEntity
|
||||
public $orderCommission;
|
||||
public $updateTime;
|
||||
public $createTime;
|
||||
public $cpsMoney;
|
||||
|
||||
//扩展信息
|
||||
public $guide_price; //指导价
|
||||
|
||||
@@ -14,10 +14,13 @@ class ReceiverOrderSubsidyEntity
|
||||
public $ifcheck;
|
||||
public $checkTime;
|
||||
public $status;
|
||||
public $couponId;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$ci = &get_instance();
|
||||
$ci->load->helper('string');
|
||||
$ci->load->model('agent/auto_product_coupon_model');
|
||||
$ci->load->model('agent/auto_product_model');
|
||||
$ci->load->model('agent/receiver_order_subsidy_model');
|
||||
$ci->load->model('agent/pingan/pingan_users_cmmssn_model');
|
||||
@@ -26,13 +29,25 @@ class ReceiverOrderSubsidyEntity
|
||||
$ci->load->model('agent/organization/organization_model');
|
||||
$ci->load->model('receiver/order/receiver_orders_model');
|
||||
$ci->load->model('receiver/receiver_clues_model');
|
||||
$ci->load->model('biz/biz_account_model', 'account_model');
|
||||
$ci->load->model('biz/biz_accountLog_model', 'accountlog_model');
|
||||
$ci->receiver_orders_model->set_db('ssdb');
|
||||
$ci->receiver_clues_model->set_db('ssdb');
|
||||
$ci->account_model->set_db('ssdb');
|
||||
$ci->accountlog_model->set_db('ssdb');
|
||||
}
|
||||
|
||||
/**
|
||||
* 补贴审核
|
||||
* @param $status
|
||||
* @param $reason
|
||||
* @return MyResponse
|
||||
*/
|
||||
public function ifCheckSubsidy($status, $reason = '')
|
||||
{
|
||||
$ci = &get_instance();
|
||||
$ci->receiver_order_subsidy_model->db->trans_begin();
|
||||
$ci->account_model->db->trans_begin();
|
||||
try {
|
||||
$data = [
|
||||
'ifcheck' => $status ? Receiver_order_subsidy_model::IF_CHECK_YES : Receiver_order_subsidy_model::IF_CHECK_NO_PASS,
|
||||
@@ -42,17 +57,88 @@ class ReceiverOrderSubsidyEntity
|
||||
throw new Exception("请输入审核未通过原因");
|
||||
}
|
||||
$reason && $data['reason'] = $reason;
|
||||
if ($data['ifcheck'] == Receiver_order_subsidy_model::IF_CHECK_YES) { //判断订单是否完成
|
||||
$order = $ci->receiver_orders_model->get(['id' => $this->orderId]);
|
||||
if ($order['status'] != 3) {
|
||||
throw new Exception("门店未确认");
|
||||
}
|
||||
}
|
||||
$result = $ci->receiver_order_subsidy_model->update($data, ['id' => $this->id]);
|
||||
if (!$result) {
|
||||
throw new Exception("保存失败");
|
||||
}
|
||||
if ($data['ifcheck'] == Receiver_order_subsidy_model::IF_CHECK_YES) { //分佣
|
||||
// $this->cmmssn();
|
||||
//订单设置已完成
|
||||
$ci->receiver_orders_model->update(['status' => 3], ['id' => $this->orderId]);
|
||||
if ($data['ifcheck'] == Receiver_order_subsidy_model::IF_CHECK_YES) { //审核通过扣除商家CPS金额
|
||||
$result = $this->productCps();
|
||||
if (!$result->isSuccess()) {
|
||||
throw new Exception("扣除商家金额失败");
|
||||
}
|
||||
}
|
||||
$ci->receiver_order_subsidy_model->db->trans_commit();
|
||||
$ci->account_model->db->trans_commit();
|
||||
return new MyResponse(EXIT_SUCCESS, '保存成功');
|
||||
} catch (Exception $e) {
|
||||
$ci->receiver_order_subsidy_model->db->trans_rollback();
|
||||
$ci->account_model->db->trans_rollback();
|
||||
return new MyResponse(EXIT_ERROR, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MyResponse
|
||||
*/
|
||||
public function productCps()
|
||||
{
|
||||
$log_path = "product_biz_cps.log";
|
||||
$ci = &get_instance();
|
||||
$ci->load->library('bizAccount');
|
||||
try {
|
||||
$productCoupon = $ci->auto_product_coupon_model->get(['id' => $this->couponId]);
|
||||
$product = $ci->auto_product_model->get(['id' => $productCoupon['product_id']]);
|
||||
if (!$product) {
|
||||
throw new Exception("产品不存在");
|
||||
}
|
||||
$money = $product['cpsMoney'];
|
||||
if ($money <= 0) {
|
||||
debug_log("产品CPS金额:" . $money, $log_path);
|
||||
return new MyResponse(EXIT_SUCCESS, '保存成功');
|
||||
}
|
||||
$bizAccount = new BizAccount();
|
||||
$account = $bizAccount->getAccountBizId($this->bizId, true);
|
||||
$leftMoney = $account['money_left'] - $money;
|
||||
$upData = [
|
||||
"money_left = money_left-$money" => null
|
||||
];
|
||||
$where = [
|
||||
"id" => $account['id']
|
||||
];
|
||||
$upAccount = $ci->account_model->update($upData, $where);
|
||||
if (!(!is_bool($upAccount) && $upAccount)) {
|
||||
debug_log("扣除金额失败" . $ci->account_model->db->last_query(), $log_path);
|
||||
throw new Exception('扣除金额失败');
|
||||
}
|
||||
$ck = md5(time() . random_string() . $this->bizId
|
||||
);
|
||||
$logData = [
|
||||
'account_id' => $account['id'],
|
||||
'trade_type' => BizAccount::TRADE_TYPE_USE,
|
||||
'money_type' => BizAccount::MONEY_TYPE_ORDER,
|
||||
'money_out' => $money,
|
||||
'money_left' => $leftMoney,
|
||||
'ck' => $ck,
|
||||
'descrip' => '解锁线索',
|
||||
'c_time' => time(),
|
||||
'jsondata' => json_encode([]),
|
||||
'target_id' => $product['id'],
|
||||
'comm_status' => Biz_accountLog_model::COMM_STATUS_NOT,
|
||||
];
|
||||
$ret = $ci->accountlog_model->add($logData);
|
||||
if (!$ret) {
|
||||
throw new Exception('写入交易日志失败');
|
||||
}
|
||||
debug_log("扣除商家金额成功", $log_path);
|
||||
return new MyResponse(EXIT_SUCCESS, '保存成功');
|
||||
} catch (Exception $e) {
|
||||
debug_log($e->getMessage(), $log_path);
|
||||
return new MyResponse(EXIT_ERROR, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,6 +364,12 @@ class Receiver_customers_model extends HD_Model
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 线索扣除商家金额
|
||||
* @param $cluesId
|
||||
* @param $bizId
|
||||
* @return MyResponse
|
||||
*/
|
||||
public function deductBizMoney($cluesId, $bizId)
|
||||
{
|
||||
$this->load->helper('string');
|
||||
@@ -403,11 +409,11 @@ class Receiver_customers_model extends HD_Model
|
||||
"money_left = money_left-$bizMoney" => null
|
||||
];
|
||||
$where = [
|
||||
"money_left >= " => $bizMoney
|
||||
"money_left >= " => $bizMoney,
|
||||
"id" => $account['id']
|
||||
];
|
||||
$upAccount = $this->account_model->update($upData, $where);
|
||||
if (!(!is_bool($upAccount) && $upAccount)) {
|
||||
var_dump($this->account_model->db->last_query());
|
||||
debug_log("扣除金额失败" . $this->account_model->db->last_query(), $log_path, $log_dir);
|
||||
throw new Exception('余额不足', 0);
|
||||
}
|
||||
@@ -417,7 +423,7 @@ class Receiver_customers_model extends HD_Model
|
||||
'trade_type' => BizAccount::TRADE_TYPE_USE,
|
||||
'money_type' => BizAccount::MONEY_TYPE_CLUES,
|
||||
'money_out' => $bizMoney,
|
||||
'money_left' => $leftMoney,
|
||||
'money_left' => $leftMoney - $bizMoney,
|
||||
'ck' => $ck,
|
||||
'descrip' => '解锁线索',
|
||||
'c_time' => time(),
|
||||
|
||||
Reference in New Issue
Block a user