116 lines
4.5 KiB
PHP
116 lines
4.5 KiB
PHP
<?php
|
|
defined('WXAPP_APP') or exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
|
|
|
class CusorderDestroy extends Wxapp
|
|
{
|
|
private $biz_id;
|
|
|
|
function __construct($inputs, $app_key)
|
|
{
|
|
parent::__construct($inputs, $app_key);
|
|
|
|
$this->login_white = array();//登录白名单
|
|
$this->check_status = array();//用户状态校验
|
|
$this->check_mobile = array();//需要手机号
|
|
$this->check_headimg = array();//授权微信信息
|
|
$this->biz_id = $this->get_biz_id();
|
|
$this->load->model('agent/auto_user_coupon_model', 'user_coupon');
|
|
$this->load->model('agent/auto_product_coupon_model', 'product_coupon');
|
|
$this->user_coupon->set_db('agentdb');
|
|
$this->product_coupon->set_db('agentdb');
|
|
$this->load->model('receiver/order/receiver_orders_model', 'orders_model');
|
|
$this->load->library('receiver/orders_entity');
|
|
}
|
|
|
|
public function get()
|
|
{
|
|
$page = $this->input_param('page');
|
|
$size = $this->input_param('size');
|
|
$startDate = $this->input_param('startDate');
|
|
$endDate = $this->input_param('endDate');
|
|
!$page && $page = 1;
|
|
!$size && $size = 20;
|
|
$where = [
|
|
'bizId' => $this->biz_id,
|
|
'status' => Auto_user_coupon_model::STATUS_USED
|
|
];
|
|
if ($startDate) {
|
|
$where['useTime >='] = $startDate;
|
|
}
|
|
if ($endDate) {
|
|
$where['useTime <='] = $endDate;
|
|
}
|
|
$count = $this->user_coupon->count($where);
|
|
$lists = [];
|
|
if ($count) {
|
|
$rows = $this->user_coupon->select($where, 'useTime desc', $page, $size);
|
|
foreach ($rows as $key => $val) {
|
|
$order = $this->orders_model->get(['id' => $val['orderId']]);
|
|
$type_cn = '超级车补专项补贴';
|
|
$length = mb_strlen($type_cn);
|
|
$lists[] = [
|
|
'id' => $val['id'],
|
|
'order_id' => $order['id'] ?: '',
|
|
'order_sid' => $order['sid'] ?: '',
|
|
'name' => $order['name'] ?: '',
|
|
'mobile' => $order['mobile'] ?: '',
|
|
'points' => 0,
|
|
'type_cn' => mb_substr($type_cn, 0, $length - 2),
|
|
'red_type_cn' => mb_substr($type_cn, -2),
|
|
'timeStart' => date('Y-m-d', strtotime($val['timeStart'])),
|
|
'timeEnd' => date('Y-m-d', strtotime($val['timeEnd'])),
|
|
'price' => intval($val['price']),
|
|
'use_time' => $val['useTime']
|
|
];
|
|
}
|
|
}
|
|
return ['list' => $lists, 'total' => $count];
|
|
}
|
|
|
|
protected function post()
|
|
{
|
|
$order_id = $this->input_param('id');
|
|
$sid = $this->input_param('sid');
|
|
if ($sid) {
|
|
$coupon = $this->user_coupon->get(['sid' => $sid]);
|
|
if (!$order_id) {
|
|
throw new Exception('购车订单不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
} else {
|
|
$coupon = $this->orders_entity->getOrderCoupon($order_id);
|
|
}
|
|
if (!$coupon) {
|
|
throw new Exception('优惠券不存在', ERR_PARAMS_ERROR);
|
|
}
|
|
$timeStart = strtotime($coupon['timeStart']);
|
|
$timeEnd = strtotime($coupon['timeEnd']);
|
|
if (time() <= $timeStart) {
|
|
throw new Exception('当前优惠券不可用', API_CODE_FAIL);
|
|
}
|
|
if ($coupon['status'] == Auto_user_coupon_model::STATUS_USED) {
|
|
throw new Exception('优惠券已使用', API_CODE_FAIL);
|
|
}
|
|
if (time() > $timeEnd || $coupon['status'] == Auto_user_coupon_model::STATUS_EXPIRED) {
|
|
throw new Exception('优惠券已过期', API_CODE_FAIL);
|
|
}
|
|
if ($coupon['status'] != Auto_user_coupon_model::STATUS_NOT_USED) {
|
|
throw new Exception('当前优惠券不可核销', API_CODE_FAIL);
|
|
}
|
|
$update = [
|
|
'bizId' => $this->biz_id,
|
|
'useTime' => date('Y-m-d H:i:s', time()),
|
|
'status' => Auto_user_coupon_model::STATUS_USED,
|
|
'orderId' => $order_id
|
|
];
|
|
$result = $this->user_coupon->update($update, ['id' => $coupon['id']]);
|
|
if (!is_numeric($result)) {
|
|
throw new Exception('核销失败', API_CODE_FAIL);
|
|
}
|
|
//更新订单状态
|
|
$this->orders_model->update(['status' => 3], ['id' => $order_id]);
|
|
//接下去分佣
|
|
throw new Exception('核销成功', API_CODE_SUCCESS);
|
|
}
|
|
|
|
} |