Files
2025-07-27 12:22:34 +08:00

175 lines
8.6 KiB
PHP

<?php
/**
* 订单
*/
class Orders_entity
{
private $ci;
public function __construct()
{
$this->ci = &get_instance();
$this->ci->load->model('receiver/receiver_customers_model', 'customers_model');
$this->ci->load->model('receiver/order/receiver_orders_model', 'orders_model');
$this->ci->load->model('receiver/order/receiver_order_datas_model');
$this->ci->load->model('auto/auto_cars_model');
$this->ci->load->model('receiver/receiver_customer_sign_model', 'sign_model');
$this->ci->load->model('receiver/receiver_clues_cfrom_model', 'clues_cfrom_model');
$this->ci->load->model('receiver/receiver_clues_model', 'clues_model');
$this->ci->load->library('carHome');
}
/**
* 订单数据提交汽车之家
* @param $oid
* @return array|void
*/
public function post_auto($oid)
{
$order_row = $this->ci->orders_model->get(['id' => $oid]);
$customer_row = $this->ci->customers_model->get(['id' => $order_row['customer_id']]);
$car_row = $this->ci->auto_cars_model->get(['id' => $order_row['car_id']]);
$order_data = $this->ci->receiver_order_datas_model->get(['o_id' => $order_row['id']]);
$sign_row = $this->ci->sign_model->get(['customer_id' => $order_row['customer_id'], 'status' => 1]);
if (!$order_row) {
return ['code' => 0, 'msg' => '订单不存在'];
}
$map_cfrom2 = $this->ci->clues_cfrom_model->get(array('id' => $customer_row['of2_id']));
$map_cfrom = $this->ci->clues_cfrom_model->get(array('id' => $map_cfrom2['pid']));
$money_json = json_decode($order_row['money_json'], true);
$post_data = [
'buyerType' => $order_row['main_type'] ? 2 : 1,
'buyerName' => $order_row['name'],
'buyerPhone' => $order_row['mobile'],
'specId' => intval($car_row['id']),
'outOrderId' => $order_row['sid'],
'outLeadId' => $customer_row['cid'],
'outOrderCreateTime' => date('Y-m-d H:i:s', $order_row['c_time']),
'registerCityId' => $customer_row['city_id'],
];
$order_row['auto_order_id'] && $post_data['autohomeOrderId'] = $order_row['auto_order_id'];
$money_json['invoice_amount'] && $post_data['invoiceAmount'] = floatval($money_json['invoice_amount']);
if ($order_row['if_num']) { //是否上牌
$post_data['isRegisterInStore'] = 1;
$money_json['register_amount'] && $post_data['registerAmount'] = floatval($money_json['register_amount']);
}
$post_data['isInsured'] = $order_row['if_insure'] ? 1 : 0;
if (!$order_row['payway']) { //贷款
$post_data['downpaymentType'] = intval($order_row['downpayment_type']);
$post_data['isLoan'] = 1;
$money_json['loan_amount'] && $post_data['loanAmount'] = floatval($money_json['loan_amount']);
$money_json['loan_periods'] && $post_data['loanPeriods'] = intval($money_json['loan_periods']);
$money_json['monthly_payment'] && $post_data['monthlyPayment'] = floatval($money_json['monthly_payment']);
}
// $post_data['carryCarDate'] = '2024-06-02';
/*付款时间去订单下定时间*/
$post_data['order_time'] != '0000-00-00 00:00:00' && $post_data['payDate'] = date('Y-m-d', strtotime($post_data['order_time']));
$contract_imgs = $this->changeImgs($order_data['contract_img']);
$contract_imgs && $post_data['contractImg'] = $contract_imgs;
$order_data['bill_img'] && $post_data['invoiceImg'] = build_qiniu_image_url($order_data['bill_img']);
$order_data['pay_img'] && $post_data['payImg'] = build_qiniu_image_url($order_data['pay_img']);
$order_row['color'] && $post_data['outColor'] = $order_row['color'];
$order_row['in_color'] && $post_data['inColor'] = $order_row['in_color'];
$post_data['deliveryDate'] = date('Y-m-d', strtotime($order_row['delry_time']));
$money_json['confirm_amount'] && $post_data['confirmAmount'] = floatval($money_json['confirm_amount']);
$money_json['discount_amount'] && $post_data['discountAmount'] = floatval($money_json['discount_amount']);
// $data['isLocalInvoice'] = 0;
$post_data['idCardNo'] = $order_row['card_id'];
$order_data['car_img'] && $post_data['carDocumentImg'] = build_qiniu_image_url($order_data['car_img']);
$insuranceImg = []; //保险图片
$order_data['insurance_img'] && $insuranceImg[] = build_qiniu_image_url($order_data['insurance_img']);
$order_data['business_img'] && $insuranceImg[] = build_qiniu_image_url($order_data['business_img']);
$insuranceImg && $post_data['insuranceImg'] = implode(',', $insuranceImg);
$order_data['delivery_ck_img'] && $post_data['deliveryPhoto'] = build_qiniu_image_url($order_data['delivery_ck_img']);
$equity_ck_img = $this->changeImgs($order_data['equity_ck_img']);
$equity_ck_img && $post_data['priceRightsConfirmDoc'] = $equity_ck_img;
$post_data['leadStairSource'] = $map_cfrom['title'] ?: ''; //线索⼀级来源
$post_data['leadSecondSource'] = $map_cfrom2['title'] ?: ''; //线索⼆级来源
$post_data['leadTime'] = date('Y-m-d H:i:s', $customer_row['c_time']); //线索时间
$customer_row['province_id'] && $post_data['leadProvinceCode'] = intval($customer_row['province_id']); //线索所在省份
$customer_row['city_id'] && $post_data['leadCityCode'] = intval($customer_row['city_id']); //线索所在城市
$customer_row['county_id'] && $post_data['leadDistrictCode'] = intval($customer_row['county_id']); //线索所在区县
$sign_data = []; //签到数据
if ($sign_row) {
$sign_data['signinId'] = $sign_row['sid'];
$sign_data['signinTime'] = date('Y-m-d H:i:s', $sign_row['c_time']);
$sign_data['signinGdLongitude'] = floatval($sign_row['lng']);
$sign_data['signinGdLatitude'] = floatval($sign_row['lat']);
$sign_data['storeGdLongitude'] = floatval($sign_row['biz_lng']);
$sign_data['storeGdLatitude'] = floatval($sign_row['biz_lat']);
$sign_data['storeLinearDistance'] = floatval($sign_row['distance']);
}
$sign_data && $post_data['signinList'] = [$sign_data];
$req = $this->ci->carhome->saveOrder($post_data, $order_row['id']);
if ($req['code']) {
$auto_order_id = $req['data']['autohomeOrderId'];
$auto_order_id && $this->ci->orders_model->update(['auto_order_id' => $auto_order_id], ['id' => $order_row['id']]);
return ['code' => 1, 'msg' => '提交成功'];
} else {
return ['code' => 0, 'msg' => $req['msg']];
}
}
// 图片转完整链接
private function changeImgs($img)
{
$img_arr = $img ? explode(',', $img) : [];
$req = [];
if ($img_arr) {
foreach ($img_arr as $item) {
$req[] = build_qiniu_image_url($item);
}
}
return implode(',', $req);
}
/**
* 订单id获取优惠券
* @param $id
* @return string
*/
public function getOrderCoupon($orderId)
{
$this->ci->load->model('agent/auto_user_coupon_model', 'user_coupon');
$this->ci->user_coupon->set_db('agentdb');
$coupon = "";
$order_row = $this->ci->orders_model->get(['id' => $orderId]);
$order_row['clue_id'] && $clues_row = $this->ci->clues_model->get(['id' => $order_row['clue_id']]);
if ($clues_row) {
$where = [
'productId' => $clues_row['out_id'],
'userId' => $clues_row['cf_uid']
];
$couponRows = $this->ci->user_coupon->select($where, 'id desc', 1, 1);
$couponRows && $coupon = $couponRows[0];
}
return $coupon;
}
/**
* 获取核销信息
* @param $orderId
* @return array
*/
public function getDestroy($orderId)
{
$destroy_show = [
'is_show' => false, //是否显示核销按钮
'text' => '', //核销状态 0未核销 1已核销
'status' => 0
];
$coupon = $this->getOrderCoupon($orderId);
if ($coupon) {
if (in_array($coupon['status'], [Auto_user_coupon_model::STATUS_NOT_USED, Auto_user_coupon_model::STATUS_USED])) {
$destroy_show['is_show'] = true;
$destroy_show['status'] = $coupon['status'];
$destroy_show['text'] = $coupon['status'] ? '已核销' : '同意核销';
}
}
return $destroy_show;
}
}
?>