/** * 取消订单 * @param $orderId */ public function cancelOrder($orderId) { $openId = (new WeixinUtil())->getOpenId(); if (!$openId) { ResponseUtil::failure('未授权访问!'); } if (!$orderId) { ResponseUtil::failure('没有订单'); } $orderId += 0; $orderModel = new OrderModel(); // 获得订单 $order = $orderModel->readOne($orderId); if (!$order) { ResponseUtil::failure('取消订单失败!'); } // 获得积分ID $couponId = $order['use_coupon_id']; if ($couponId) { (new CustomerCouponModel())->refundCoupon($couponId, $openId); } //取消订单 if ((new CurdUtil(new OrderModel()))->update(array('order_id' => $orderId, 'open_id' => $openId), array('order_status' => OrderModel::ORDER_CANCEL))) { ResponseUtil::executeSuccess('订单取消成功!'); } else { ResponseUtil::failure('取消订单失败!'); } }
/** * 取消订单 * @param string $order_id */ public function CancelOrder($order_id = '') { if (!$order_id) { $this->message('订单ID不能为空!'); } $orderModel = new OrderModel(); // 获得订单 $order = $orderModel->readOne($order_id); if (!$order) { ResponseUtil::failure('取消订单失败!'); } // 获得积分ID $couponId = $order['use_coupon_id']; if ($couponId) { (new CustomerCouponModel())->refundCoupon($couponId, $order['open_id']); } if ((new CurdUtil($this->orderModel))->update(array('order_id' => $order_id), array('order_status' => OrderModel::ORDER_CANCEL, 'complete_time' => DateUtil::now()))) { $this->message('订单已取消!'); } else { $this->message('处理失败!'); } }
/** * 获得有效的预约时间 * 首先查询 指定日期 美容师休息表, 获得休息时间 * 再查询 指定日期 美容师 已接受预定的 时间 * * @param $beautician_id 美容师ID * @param $day 查询日期 */ public function getValidAppointmentTime($beautician_id, $day) { if (!$beautician_id || !$day) { ResponseUtil::failure('参数错误!'); } $today = date('Y-m-d'); if ($day < $today) { ResponseUtil::failure('错误的预约时间!'); } // 查询美容师 $beautician = (new BeauticianModel())->readOne($beautician_id); if (!$beautician) { ResponseUtil::failure('美容师不存在!'); } // 查询休息时间 $beauticianRest = (new CurdUtil(new BeauticianRestModel()))->readAll('beautician_rest_id desc', array('beautician_id' => $beautician_id, 'disabled' => 0, 'rest_day' => $day)); // 获得工作时间 $workTime = new WorkTimeUtil(); list($dayStart, $dayEnd) = $workTime->explode($workTime->getAllDay()); // 指定日期的所有预约时间段 $appointmentTimes = DateUtil::generateAppointmentTime($day, $dayStart, $dayEnd); // 美容师制定日期休息时间段 // 当值为0时, 说明不能预约 if ($beauticianRest) { foreach ($beauticianRest as $_beauticianRest) { $beauticianRestAppointmentTimes = DateUtil::generateAppointmentTime($day, $_beauticianRest['start_time'], $_beauticianRest['end_time']); foreach ($appointmentTimes as $k => $time) { if (array_key_exists($k, $beauticianRestAppointmentTimes)) { $appointmentTimes[$k] = 0; } } } } // 获得制定日期已经预约的时间段,订单状态为已支付 $payedOrders = (new OrderModel())->getOrderByBeauticianIdAndAppointmentDay($beautician_id, $day); if ($payedOrders) { foreach ($payedOrders as $payedOrder) { $orderAppointmentTime = DateUtil::generateAppointmentTime($payedOrder['appointment_day'], $payedOrder['appointment_start_time'], $payedOrder['appointment_end_time']); foreach ($appointmentTimes as $k => $time) { if (array_key_exists($k, $orderAppointmentTime)) { $appointmentTimes[$k] = 0; } } } } // 小于当前时间不能预约 if ($today == $day) { $now = date('H:i'); foreach ($appointmentTimes as $k => $time) { if ($k < $now) { $appointmentTimes[$k] = 0; } } } // 查询线下预约 $offlineOrders = (new OfflineOrderModel())->getOrderByBeauticianIdAndAppointmentDay($beautician_id, $day); if ($offlineOrders) { foreach ($offlineOrders as $offlineOrder) { $orderAppointmentTime = DateUtil::generateAppointmentTime($offlineOrder['appointment_day'], $offlineOrder['appointment_start_time'], $offlineOrder['appointment_end_time']); foreach ($appointmentTimes as $k => $time) { if (array_key_exists($k, $orderAppointmentTime)) { $appointmentTimes[$k] = 0; } } } } $beauticianWorkTime = (new WorkTimeUtil())->beauticianWorkTime; $week = DateUtil::calcDayInWeek($day); $workTimeType = $beauticianWorkTime[$beautician_id][$week]; // 判断早班,晚班 if ($workTimeType == BeauticianModel::ALL_DAY) { } elseif ($workTimeType == BeauticianModel::MORNING_SHIFT) { $morningShiftTimes = $workTime->explode($workTime->getMorningShift()); $workAppointmentTime = DateUtil::generateAppointmentTime($day, $morningShiftTimes[0], $morningShiftTimes[1]); foreach ($appointmentTimes as $k => $time) { if (!array_key_exists($k, $workAppointmentTime)) { $appointmentTimes[$k] = 0; } } } elseif ($workTimeType == BeauticianModel::NIGHT_SHIFT) { $nightShiftTimes = $workTime->explode($workTime->getNightShift()); $workAppointmentTime = DateUtil::generateAppointmentTime($day, $nightShiftTimes[0], $nightShiftTimes[1]); foreach ($appointmentTimes as $k => $time) { if (!array_key_exists($k, $workAppointmentTime)) { $appointmentTimes[$k] = 0; } } } elseif ($workTimeType == BeauticianModel::MIDDAY_SHIFT) { $middayShiftTimes = $workTime->explode($workTime->getMiddayShift()); $workAppointmentTime = DateUtil::generateAppointmentTime($day, $middayShiftTimes[0], $middayShiftTimes[1]); foreach ($appointmentTimes as $k => $time) { if (!array_key_exists($k, $workAppointmentTime)) { $appointmentTimes[$k] = 0; } } } elseif ($workTimeType == BeauticianModel::REST_SHIFT) { foreach ($appointmentTimes as $k => $time) { $appointmentTimes[$k] = 0; } } else { } // 渲染视图 $render = $this->load->view('frontend/appointment/appointmentTimes', array('appointmentTimes' => $appointmentTimes), true); ResponseUtil::executeSuccess('成功', $render); }
public function getExchangeGoods($exchangeGoodsId) { $openId = (new WeixinUtil())->getOpenId(); if (!$openId) { ResponseUtil::failure('错误的授权!'); } // 查询是否已经领取优惠券 if ((new CustomerExchangeGoodsModel())->readOne($exchangeGoodsId, $openId)) { ResponseUtil::failure('您已经兑换了此商品!'); } $exchangeGoods = (new ExchangeGoodsModel())->readOne($exchangeGoodsId); // 剩余数量为0 if ($exchangeGoods['remain_number'] <= 0) { ResponseUtil::failure('商品已经兑换完!'); } $today = date('Y-m-d'); // 是否到领取时间 if ($today < $exchangeGoods['start_time']) { ResponseUtil::failure('商品未到兑换时间!'); } if ($today > $exchangeGoods['expire_time']) { ResponseUtil::failure('商品已过兑换时间!'); } // 判断积分 $customerModel = new CustomerModel(); $customer = $customerModel->readOne($openId); if ($exchangeGoods['exchange_credits'] > $customer['credits']) { ResponseUtil::failure('积分不足,兑换商品失败!'); } $userName = $this->input->post('contact_name', true); $phoneNumber = $this->input->post('contact_phone', true); $userName = urldecode($userName); // 检查用户 $userName = trim(strip_tags($userName)); if (empty($userName)) { ResponseUtil::failure('联系人不能为空,请检查!'); } if (!preg_match('~^1\\d{10}$~', $phoneNumber)) { ResponseUtil::failure('手机号错误,请检查!'); } $this->db->trans_start(); // 领取 $data = array('exchange_goods_id' => $exchangeGoodsId, 'open_id' => $openId, 'is_get' => 0, 'contact_name' => $userName, 'contact_phone' => $phoneNumber, 'exchange_time' => DateUtil::now()); $customerExchangeGoodsId = (new CustomerExchangeGoodsModel())->create($data); if ($customerExchangeGoodsId) { (new ExchangeGoodsModel())->subExchangeGoodsNumber($exchangeGoodsId); } // 积分 $customerModel->subCredits($openId, $exchangeGoods['exchange_credits']); $this->db->trans_complete(); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); ResponseUtil::failure('兑换商品失败!'); } else { $this->db->trans_commit(); ResponseUtil::executeSuccess('兑换商品成功!'); } }