"> </a> <a> <h3 class="F14 FN"><?php echo $order['project_name']; ?> </h3> </a> <p>门店:<span class="F11"><?php echo $shop; ?> </span></p> <strong class="FN colorH">预约时间: <?php echo DateUtil::buildDateTime($order['appointment_day'], $order['appointment_start_time']); ?> </strong> <strong class="add FN colorH">美容师:<?php echo $order['beautician_name']; ?> </strong> <i class="order_list_i"> </i> </div> </dt> <dd> <a class="colorW pay-click">马上支付</a> <i class="colorH">总金额:<strong class="F18 colorR">¥<?php echo number_format($order['total_fee'], 2); ?>
/** * 微信支付后的异步回调 */ public function notice() { $weixin = new WeixinPayUtil(); //通知微信 $notice = $weixin->notifyData(); // 签名成功, 返回数组, 否则返回xml数据 if (!is_array($notice) || !isset($notice['transaction_id'])) { exit($notice); } //签名成功,处理数据 /** * 返回的数据 * 'appid' => string 'wxf5b5e87a6a0fde94' (length=18) * 'bank_type' => string 'CFT' (length=3) * 'fee_type' => string 'CNY' (length=3) * 'is_subscribe' => string 'N' (length=1) * 'mch_id' => string '10000097' (length=8) * 'nonce_str' => string 'dz8nirk7gmxhhxn38zgib28yx14ul2gf' (length=32) * 'openid' => string 'ozoKAt-MmA74zs7MBafCix6Dg8o0' (length=28) * 'out_trade_no' => string 'wxf5b5e87a6a0fde941409708791' (length=28) * 'result_code' => string 'SUCCESS' (length=7) * 'return_code' => string 'SUCCESS' (length=7) * 'sign' => string 'EDACA525F6C675337B2DAC25B7145028' (length=32) * 'sub_mch_id' => string '10000097' (length=8) * 'time_end' => string '20140903094659' (length=14) * 'total_fee' => string '1' (length=1) * 'trade_type' => string 'NATIVE' (length=6) * 'transaction_id' => string '1004400737201409030005091526' (length=28) //微信支付单号 */ // $notice = array( // 'out_trade_no' => '201512271710391206225994', // 'transaction_id' => '1004400737201409030005091526' // ); $orderNo = $notice['out_trade_no']; $wxOrderNo = $notice['transaction_id']; $openId = $notice['openid']; $orderModel = new OrderModel(); // 获得订单 $orders = $orderModel->orders(array('order_no' => $orderNo)); if (!$orders || !$orders[0]) { exit($weixin->notifyFailure()); } // 判断是否已经支付 $order = $orders[0]; if ($order['order_sign'] == OrderModel::ORDER_PAYED) { exit($weixin->notifyPayed()); } // 更新订单信息 $this->db->trans_start(); $orderModel->payed($orderNo, $wxOrderNo); // 更新积分 $customerModel = new CustomerModel(); $score = $order['total_fee']; $customer = $customerModel->readOne($openId); if ($customer) { $customerModel->addCredits($openId, $score); } // 事物完成 $this->db->trans_complete(); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); exit($weixin->notifyFailure()); } else { $this->db->trans_commit(); // 获得access token $weixinUtil = new WeixinUtil(); $token = $weixinUtil->getToken(); if ($token) { //foreach ($orders as $order) { $orderNo = $order['order_no']; $appointmentDay = DateUtil::buildDateTime($order['appointment_day'], $order['appointment_start_time']); $shops = (new ShopModel())->getAllShops(); $shop = $shops[$order['shop_id']]; $beautician = (new BeauticianModel())->readOne($order['beautician_id']); $beauticianName = $beautician['name']; $project = (new CurdUtil(new OrderProjectModel()))->readOne(array('order_id' => $order['order_id'])); $projectName = $project['project_name']; // 计算总积分 $totalCredits = $customer['credits'] + $score; // 发送模板消息 // $orderNo, $appointmentDay, $shop, $beautician, $projectName $weixinUtil->sendOrderMessage($orderNo, $appointmentDay, $shop, $beauticianName, $projectName, $openId, $token, $totalCredits); //} } exit($weixin->notifySuccess()); } }
public function appointment() { $params = RequestUtil::postParams(); $userName = urldecode($params['user_name']); if (empty($userName)) { $this->message('联系人不能为空!'); } $phoneNumber = $params['phone_number']; if (empty($phoneNumber)) { $this->message('手机号不能为空!'); } $appointmentDay = $params['appointment_day']; $appointmentTime = $params['appointment_times']; $today = date('Y-m-d'); if ($appointmentDay < $today) { $this->message('错误的预约日期!'); } // 检查时间 $appointmentTime = explode(',', urldecode($appointmentTime)); if (!$appointmentTime || count($appointmentTime) < 1) { $this->message('错误的预约时间!'); } // 只有30分钟的项目 if (count($appointmentTime) == 1) { array_push($appointmentTime, $appointmentTime[0]); } // 只保留头和尾的两个数据 $startTime = array_shift($appointmentTime); $endTime = array_pop($appointmentTime); if ($endTime < $startTime) { $this->message('错误的预约时间!'); } // 预约时间是否小于当前时间 $now = date('Y-m-d H:i'); if (DateUtil::buildDateTime($appointmentDay, $startTime) < $now) { $this->message('错误的预约开始时间!'); } if (DateUtil::buildDateTime($appointmentDay, $endTime) < $now) { $this->message('错误的预约结束时间!'); } $beauticianId = $params['beautician_id']; // 判断相同的时间是否已经被预约 $findHasPayedAppointTimeWhere = array('appointment_day' => $appointmentDay, 'appointment_start_time' => $startTime, 'order_status' => OrderModel::ORDER_PAYED, 'beautician_id' => $beauticianId); $findOrder = (new CurdUtil(new OrderModel()))->readOne($findHasPayedAppointTimeWhere); if ($findOrder) { $this->message('此时间段已被预约!'); } unset($findOrder); $findHasPayedAppointTimeWhere['order_status'] = OfflineOrderModel::ORDER_WAIT; $findOrder = (new CurdUtil(new OfflineOrderModel()))->readOne($findHasPayedAppointTimeWhere); if ($findOrder) { $this->message('此时间段已被预约!'); } // 没有问题 $data = array('project_id' => $params['project_id'], 'project_name' => $params['project_name'], 'use_time' => $params['use_time'], 'shop_id' => $params['shop_id'], 'beautician_id' => $beauticianId, 'appointment_day' => $appointmentDay, 'appointment_start_time' => $startTime, 'appointment_end_time' => $endTime, 'user_name' => $userName, 'phone_number' => $phoneNumber, 'create_time' => DateUtil::now()); if ((new CurdUtil(new OfflineOrderModel()))->create($data)) { $this->message('线下预约成功!', 'offlineOrder/index'); } else { $this->message('线下预约失败!'); } }
/** * 下单 * @param $shopId * @param $beauticianId * @param $appointmentDay * @param $appointmentTime * @param $userName * @param $phoneNumber */ public function order($shopId, $beauticianId, $appointmentDay, $appointmentTime, $userName, $phoneNumber) { $openId = (new WeixinUtil())->getOpenId(); if (!$openId) { $this->message('错误的授权'); } if (!(new ShopModel())->isValidShopId($shopId)) { $this->message('门店信息错误,请检查!'); } // 检查美容师 if (!(new BeauticianModel())->isValidBeautician($beauticianId)) { $this->message('美容师信息错误,请检查!'); } $userName = urldecode($userName); // 检查用户 $userName = trim(strip_tags($userName)); if (empty($userName)) { $this->message('联系人不能为空,请检查!'); } if (!preg_match('~^1\\d{10}$~', $phoneNumber)) { $this->message('手机号错误,请检查!'); } // 检查日期,日期为今天或者以后 $today = date('Y-m-d'); if ($appointmentDay < $today) { $this->message('错误的预约日期!'); } // 检查时间 $appointmentTime = explode(',', urldecode($appointmentTime)); if (!$appointmentTime || count($appointmentTime) < 1) { $this->message('错误的预约时间!'); } // 只有30分钟的项目 if (count($appointmentTime) == 1) { array_push($appointmentTime, $appointmentTime[0]); } // 只保留头和尾的两个数据 $startTime = array_shift($appointmentTime); $endTime = array_pop($appointmentTime); if ($endTime < $startTime) { $this->message('错误的预约时间!'); } // 预约时间是否小于当前时间 $now = date('Y-m-d H:i'); if (DateUtil::buildDateTime($appointmentDay, $startTime) < $now) { $this->message('错误的预约开始时间!'); } if (DateUtil::buildDateTime($appointmentDay, $endTime) < $now) { $this->message('错误的预约结束时间!'); } // 结束时间 + 30分钟为真正的结束时间 //$timeStamp = DateUtil::buildDateTime($appointmentDay, $endTime); //$timeStamp += 1800; //$endTime = date('H:i', $timeStamp); // 处理优惠 $couponId = $this->input->get('coupon_id', true) + 0; $couponCode = $this->input->get('coupon_code', true) + 0; $customerCouponModel = new CustomerCouponModel(); $couponCodeModel = new CouponCodeModel(); $today = date('Y-m-d'); if ($couponId) { $couponCode = ''; $coupon = $customerCouponModel->readOneById($couponId); // 判断是否能使用 if ($coupon['is_use'] == 1) { $this->message('选择的优惠券已被使用!'); } // 是否到领取时间 if ($today < $coupon['start_time']) { $this->message('优惠券未到使用时间!'); } if ($today > $coupon['expire_time']) { $this->message('优惠券已到期!'); } } else { if ($couponCode) { $couponId = ''; $queryCouponCode = $couponCodeModel->readOneByCode($couponCode); if (!$queryCouponCode) { $this->message('优惠码不存在!'); } // 是否到使用时间 if ($today < $queryCouponCode['start_time']) { $this->message('优惠码未到使用时间!'); } // 是有已过期 if ($today > $queryCouponCode['expire_time']) { $this->message('优惠码已到期!'); } } else { } } //**********处理下单************// $projectId = (new CartUtil())->cart(); if (empty($projectId) || $projectId <= 0) { $this->message('预约项目为空!'); } if ((new ProjectPropertyModel())->projectOnlyForNewUser($projectId, $openId)) { $this->message('此美容项目只针对新用户!'); } $orderProjectModel = new OrderProjectModel(); // 获得购物车的项目 $project = (new ProjectModel())->readOne($projectId); // 判断订单金额是否可以使用优惠券 $totalFee = $originalTotalFee = $project['price']; if ($couponId && $project['can_use_coupon']) { if ($totalFee < $coupon['use_rule']) { $this->message('当前订单金额不足' . $coupon['use_rule'] . '元,不能使用此优惠券'); } } else { if ($couponCode && $project['can_use_coupon_code']) { if ($totalFee < $queryCouponCode['use_rule']) { $this->message('当前订单金额不足' . $queryCouponCode['use_rule'] . '元,不能使用此优惠码'); } } else { } } // 生成订单号, 有重复订单号则重新生成,直到不重复为止 $orderNo = StringUtil::generateOrderNo(); $orderModel = new OrderModel(); while ((new CurdUtil($orderModel))->readOne(array('order_no' => $orderNo))) { $orderNo = StringUtil::generateOrderNo(); } // 优惠 if ($couponId && $project['can_use_coupon']) { // 使用优惠码, 抵消金额 $totalFee -= $coupon['counteract_amount']; } else { if ($couponCode && $project['can_use_coupon_code']) { $totalFee *= $queryCouponCode['discount']; } else { } } // 订单数据 $orderData = array('order_no' => $orderNo, 'shop_id' => $shopId, 'create_time' => DateUtil::now(), 'original_total_fee' => $originalTotalFee, 'total_fee' => $totalFee, 'open_id' => $openId, 'order_status' => OrderModel::ORDER_NOT_PAY, 'beautician_id' => $beauticianId, 'appointment_day' => $appointmentDay, 'appointment_start_time' => $startTime, 'appointment_end_time' => $endTime, 'user_name' => $userName, 'phone_number' => $phoneNumber, 'use_coupon_id' => $couponId, 'use_coupon_code' => $couponCode); // 事务开始 $this->db->trans_start(); // 设置优惠券已使用 if ($couponId && $project['can_use_coupon']) { $customerCouponModel->useCoupon($couponId, $openId); } else { if ($couponCode && $project['can_use_coupon_code']) { $couponCodeModel->addUseTimes($couponCode); } else { } } $insertOrderNo = (new CurdUtil($orderModel))->create($orderData); if ($insertOrderNo) { $orderProjectData = array('order_id' => $insertOrderNo, 'project_id' => $project['project_id'], 'project_use_time' => $project['use_time'], 'project_price' => $project['price'], 'create_time' => DateUtil::now(), 'project_name' => $project['project_name'], 'project_cover' => $project['project_cover']); } else { $this->message('提交订单失败,请重试!'); } (new CurdUtil($orderProjectModel))->create($orderProjectData); $this->db->trans_complete(); if ($this->db->trans_status() === FALSE) { $this->db->trans_rollback(); $this->message('提交订单失败,请重试!'); } else { $this->db->trans_commit(); // 清空购物车 (new CartUtil())->emptyCart(); // 跳到 订单显示 ResponseUtil::redirect(UrlUtil::createUrl('order/pay/' . $orderNo)); } }