Exemplo n.º 1
0
 public function exchangeGoods()
 {
     $weixinUtil = new WeixinUtil();
     // 验证是否已授权
     $weixinUtil->authorize("exchange/coupon");
     $openId = $weixinUtil->getOpenId();
     $products = (new ExchangeGoodsModel())->getAllExchangeGoods();
     $shops = (new ShopModel())->getAllShopAddress();
     $lastOrder = (new OrderModel())->getLastOrder($openId);
     $this->view('exchange/exchangeGoods', array('products' => $products, 'shops' => $shops, 'lastOrder' => $lastOrder));
 }
Exemplo n.º 2
0
 /**
  * 展示预约页面
  * 选择美容师与预约时间
  * 此处要验证授权
  *
  * @param $shopId 店铺ID
  */
 public function index($shopId)
 {
     $weixinUtil = new WeixinUtil();
     // 验证是否已授权
     $weixinUtil->authorize("appointment/index/{$shopId}");
     // 获得预约项目
     $projectId = (new CartUtil())->cart();
     $projectId += 0;
     if (!$projectId) {
         $this->message('预约项目不存在!');
     }
     $openId = $weixinUtil->getOpenId();
     if ((new ProjectPropertyModel())->projectOnlyForNewUser($projectId, $openId)) {
         $this->message('此美容项目只针对新用户!');
     }
     //是否已经选择了店铺,并且店铺是有效的
     $shops = (new ShopModel())->getAllShops();
     if (is_numeric($shopId) && array_key_exists($shopId, $shops)) {
         // 获得项目信息
         $project = (new ProjectModel())->readOne($projectId);
         if (!$project) {
             $this->message('预约项目不存在!');
         }
         // 跳转到 选择 美容师
         $beauticians = (new BeauticianModel())->getAllBeauticians();
         $lastOrder = (new OrderModel())->getLastOrder($openId);
         $days = DateUtil::buildDays();
         $coupons = array();
         if ($project['can_use_coupon']) {
             // 查询优惠券
             $coupons = (new CustomerCouponModel())->getCustomerNotUseCouponList($openId);
         }
         $this->load->view('frontend/appointment/beautician', array('beauticians' => $beauticians, 'project' => $project, 'shopId' => $shopId, 'days' => $days, 'lastOrder' => $lastOrder, 'coupons' => $coupons));
     } else {
         // 跳转到选择店铺
         $returnUrl = urlencode(UrlUtil::createUrl('appointment/index'));
         ResponseUtil::redirect(UrlUtil::createUrl("shop/index?returnUrl={$returnUrl}"));
     }
 }
Exemplo n.º 3
0
 public function order($offset = 0)
 {
     $orderStatus = $this->input->get('type') + 0;
     $weixinUtil = new WeixinUtil();
     $weixinUtil->authorize("userCenter/order/{$offset}/{$orderStatus}");
     $openId = $weixinUtil->getOpenId();
     $orderModel = new OrderModel();
     // 获得订单信息
     $where = array('open_id' => $openId);
     if ($orderStatus) {
         $where['order_status'] = $orderStatus;
     }
     $orders = $orderModel->getUserOrders($openId, $orderStatus, $offset);
     $orderCounts = $orderModel->getUserOrderCounts($openId, $orderStatus);
     if (isset($orderCounts[0])) {
         $orderCounts = array_pop($orderCounts);
     }
     $orderCounts = isset($orderCounts['rowCounts']) ? $orderCounts['rowCounts'] : 0;
     $pages = (new PaginationUtil($orderCounts, 'user-center'))->pagination();
     $shopModel = new ShopModel();
     $shops = $shopModel->getAllShops();
     $shopAddress = $shopModel->getAllShopAddress();
     $this->view('userCenter/order', array('pages' => $pages, 'orders' => $orders, 'orderStatus' => $orderStatus, 'shops' => $shops, 'offset' => $offset, 'shopAddress' => $shopAddress));
 }
Exemplo n.º 4
0
 /**
  * 微信支付后的异步回调
  */
 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());
     }
 }