コード例 #1
0
ファイル: Pay.php プロジェクト: jackycgq/bzfshop
 public function post($f3)
 {
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1, true, '订单ID非法')->validate('order_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $validator = new Validator($f3->get('POST'));
     $payGatewayType = $validator->required('必须选择一种支付方式')->validate('pay_gateway_type');
     $surplus = Money::toStorage($validator->float('余额格式错误')->min(0, true, '余额格式错误')->validate('surplus'));
     $bonusSn = $validator->validate('bonus_sn');
     // 客服信息
     $orderInfoKefuInfo = array();
     $orderInfoKefuInfo['kefu_user_id'] = abs(intval($validator->digits()->validate('kefu_user_id')));
     $orderInfoKefuInfo['kefu_user_rate'] = abs(intval($validator->digits()->validate('kefu_user_rate')));
     $orderInfoKefuInfo['kefu_user_comment'] = $validator->validate('kefu_user_comment');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得用户信息
     $userInfo = AuthHelper::getAuthUser();
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($userInfo['user_id']);
     // 支付某一个特定的订单需要把订单加载到临时购物车里面
     $orderBasicService = new OrderBasicService();
     // 检查权限
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id);
     if ($orderInfo->isEmpty() || $userInfo['user_id'] != $orderInfo['user_id'] || OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
         $this->addFlashMessage('订单ID非法');
         goto out_fail;
     }
     // 更新客服信息
     if ($orderInfoKefuInfo['kefu_user_id'] > 0) {
         $adminUserService = new AdminUserService();
         $adminUser = $adminUserService->loadAdminById($orderInfoKefuInfo['kefu_user_id']);
         if (!$adminUser->isEmpty()) {
             $orderInfoKefuInfo['kefu_user_name'] = $adminUser['user_name'];
         } else {
             $orderInfoKefuInfo['kefu_user_id'] = 0;
             $orderInfoKefuInfo['kefu_user_name'] = null;
         }
         unset($adminUser);
         unset($adminUserService);
     } else {
         $orderInfoKefuInfo['kefu_user_id'] = 0;
         $orderInfoKefuInfo['kefu_user_name'] = null;
     }
     $orderInfo->copyFrom($orderInfoKefuInfo);
     $orderInfo->save();
     $cartBasicService = new CartBasicService();
     // 加载订单到购物车里
     if (!$cartBasicService->loadFromOrderInfo($order_id)) {
         $this->addFlashMessage('订单加载失败');
         goto out_fail;
     }
     $cartContext =& $cartBasicService->getCartContextRef();
     if ($cartContext->isEmpty()) {
         $this->addFlashMessage('订单为空,不能支付');
         goto out_fail;
     }
     // 做第一次购物车计算,需要计算原始订单的金额,后面红包使用的时候有最低订单金额限制
     $cartBasicService->calcOrderPrice();
     if (!empty($surplus) || !empty($bonusSn)) {
         if (null != $surplus && $surplus > 0 && $surplus <= $userInfo['user_money']) {
             // 设置余额支付金额,余额不能超过用户已经有的钱
             $cartContext->setValue('surplus', $surplus);
         }
         // 设置红包支付
         if (!empty($bonusSn)) {
             $bonusService = new Bonus();
             //检查红包是否可以使用
             $bonus = $bonusService->fetchUsableBonusBySn($userInfo['user_id'], $cartContext->getValue('order_amount'), $bonusSn);
             if (empty($bonus)) {
                 $this->addFlashMessage('红包' . $bonusSn . '不能使用');
                 goto out_fail;
             }
             // 设置红包的使用
             $cartContext->setValue('bonus_id', $bonus['bonus_id']);
             $cartContext->setValue('bonus', $bonus['type_money']);
         }
     }
     // 做第二次购物车计算,需要计算使用了余额或者红包
     $cartBasicService->calcOrderPayment();
     // 更新订单信息
     $orderInfo = $cartBasicService->saveOrder($userInfo['user_id'], '买家:' . $userInfo['user_name']);
     if (!$orderInfo || $orderInfo->isEmpty()) {
         //订单创建失败,报错
         $this->addFlashMessage('更新订单信息失败,请联系客服');
         goto out_my_order_detail;
     }
     // 如果购物车里面有错误消息,我们需要显示它
     if ($cartContext->hasError()) {
         $this->addFlashMessageArray($cartContext->getAndClearErrorMessageArray());
         goto out_my_order_cart;
     }
     // 如果订单金额为 0 ,使用 credit 支付网关
     if ($orderInfo['order_amount'] <= 0) {
         $payGatewayType = 'credit';
     }
     $order_id = $orderInfo['order_id'];
     // 解析参数,我们允许写成 tenpay_cmbchina  代表财付通、招商银行
     $payGatewayParamArray = explode('_', $payGatewayType);
     // 获取支付网关
     $payGateway = PaymentGatewayHelper::getPaymentGateway($payGatewayParamArray[0]);
     // 根据参数做初始化
     if (!$payGateway->init($payGatewayParamArray)) {
         $this->addFlashMessage('支付网关' . $payGatewayType . '初始化失败');
         goto out_my_order_detail;
     }
     $payRequestUrl = $payGateway->getRequestUrl($order_id, RouteHelper::makeUrl('/Payment/PaymentReturn/' . $payGateway->getGatewayType(), null, false, true), RouteHelper::makeUrl('/Payment/PaymentNotify/' . $payGateway->getGatewayType(), null, false, true));
     //notifyUrl
     if (empty($payRequestUrl)) {
         $this->addFlashMessage('系统错误:无法生成支付链接');
         goto out_my_order_detail;
     }
     // 记录支付日志
     printLog('[orderId:' . $order_id . ']' . $payRequestUrl, 'PAYMENT', Base::INFO);
     // 跳转支付
     RouteHelper::reRoute($this, $payRequestUrl);
     return;
     out_my_order_cart:
     //失败从这里退出
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/My/Order/Cart', array('order_id' => $order_id), true));
     return;
     out_my_order_detail:
     //失败从这里退出
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/My/Order/Detail', array('order_id' => $order_id), true));
     return;
     out_fail:
     //失败从这里退出
     RouteHelper::reRoute($this, '/My/Order');
 }
コード例 #2
0
ファイル: Cart.php プロジェクト: jackycgq/bzfshop
 public function post($f3)
 {
     // 这里操作加入购物车
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $goods_id = $validator->required('商品id不能为空')->digits('商品id非法')->min(1, true, '商品id非法')->validate('goods_id');
     $goodsChooseSpecListStr = $validator->validate('goods_choose_speclist');
     $goodsChooseBuyCount = $validator->required('商品最少购买 1 件')->digits('商品最少购买 1 件')->min(1, true, '商品最少购买 1 件')->validate('goods_choose_buycount');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 查询商品信息
     $goodsBasicService = new GoodsBasicService();
     $goodsInfo = $goodsBasicService->loadGoodsById($goods_id);
     // 商品不存在,不允许显示等
     if ($goodsInfo->isEmpty() || !$goodsInfo->is_on_sale || !Utils::isTagExist(PluginHelper::SYSTEM_MOBILE, $goodsInfo['system_tag_list'])) {
         $this->addFlashMessage('商品不存在或者不能购买');
         goto out_fail;
     }
     $cartBasicService = new CartBasicService();
     // 购物车服务
     $cartBasicService->loadFromStorage();
     // 恢复购物车中已有的数据
     $cartContext =& $cartBasicService->getCartContextRef();
     // 取得 cartContext
     // 商品多组合选择
     if (!empty($goodsChooseSpecListStr)) {
         // 检查商品 Spec 是否合法
         $goodsSpecService = new GoodsSpecService();
         $goodsSpecService->initWithJson($goodsInfo['goods_spec']);
         $goodsSpecDataArray = $goodsSpecService->getGoodsSpecDataArray($goodsChooseSpecListStr);
         if (!$goodsSpecDataArray) {
             $this->addFlashMessage('商品选择[' . $goodsChooseSpecListStr . ']非法');
             goto out_fail;
         }
         // 检查商品库存
         if ($goodsChooseBuyCount > @$goodsSpecDataArray['goods_number']) {
             $this->addFlashMessage($goodsChooseSpecListStr . '库存不足,只剩 ' . @$goodsSpecDataArray['goods_number'] . ' 件');
             goto out_fail;
         }
         // 商品加入到购物车
         $cartContext->addGoods($goods_id, $goodsChooseBuyCount, $goodsChooseSpecListStr, @$goodsSpecDataArray['goods_sn']);
     } else {
         // 检查库存
         if ($goodsChooseBuyCount > $goodsInfo['goods_number']) {
             $this->addFlashMessage('库存不足,剩余 ' . $goodsInfo['goods_number'] . ' 件');
             goto out_fail;
         }
         // 普通简单选择,加入购物车
         $cartContext->addGoods($goods_id, $goodsChooseBuyCount);
     }
     $cartBasicService->syncStorage();
     // 保存购物车的数据
     out:
     Ajax::header();
     echo Ajax::buildResult(null, null, null);
     return;
     out_fail:
     // 失败,返回出错信息
     $errorMessage = implode('|', $this->flashMessageArray);
     Ajax::header();
     echo Ajax::buildResult(-1, $errorMessage, null);
 }
コード例 #3
0
ファイル: index.php プロジェクト: jackycgq/bzfshop
// 根据环境变量的不同,加载对应的环境变量设置,开发环境和生产环境的配置显然是不一样的
$f3->config(PROTECTED_PATH . '/Config/mobile-' . $f3->get('sysConfig[env]') . '.cfg');
// 设置工作时区
if ($f3->get('sysConfig[time_zone]')) {
    date_default_timezone_set($f3->get('sysConfig[time_zone]'));
}
// 设置 session 在多个子域名之间共享
if ($f3->get('sysConfig[cookie_domain]')) {
    $f3->set('JAR.domain', $f3->get('sysConfig[cookie_domain]'));
}
// 设置网站唯一的 key,防止通用模块之间的冲突
RouteHelper::$uniqueKey = 'MOBILE';
OrderBasicService::$orderSnPrefix = 'MB';
ReferHelper::$orderReferStorageKey = 'BZFOrderRefer';
// 记录系统订单来源
CartBasicService::$cartSystemId = \Core\Plugin\PluginHelper::SYSTEM_MOBILE;
// 把几个网站的 key 设置成一样,配合 sysConfig[cookie_domain] 设置,就可以实现几个网站 统一登陆
AuthHelper::$uniqueKey = 'BZFAUTH';
// ------------ 2. 初始化 云服务引擎,云服务引擎会设置好我们的运行环境,包括 可写目录 等 ------------
CloudHelper::initCloudEnv(PluginHelper::SYSTEM_MOBILE);
// ---------------------------------------- 3. 开启系统日志 --------------------------------------
$todayDateStr = \Core\Helper\Utility\Time::localTimeStr('Y-m-d');
$todayDateArray = explode('-', $todayDateStr);
// 设置一个 fileLogger 方便查看所有的日志输出,按照 年/月/年-月-日.log 输出
$fileLogger = new \Core\Log\File($todayDateArray[0] . '/' . $todayDateArray[1] . '/' . implode('-', $todayDateArray) . '.mobile.log');
// 我们不打印 DEBUG 级别的日志,不然数据量太大了
$fileLogger->levelAllow = array(\Core\Log\Base::CRITICAL, \Core\Log\Base::ERROR, \Core\Log\Base::WARN, \Core\Log\Base::NOTICE, \Core\Log\Base::INFO);
$logger->addLogger($fileLogger);
unset($fileLogger);
// 设置支付日志,我们需要把所有的支付都记录到支付日志中方便以后查询,按照日期分目录存储
$fileLogger = new \Core\Log\File('PAYMENT/' . $todayDateArray[0] . '/' . $todayDateArray[1] . '/' . implode('-', $todayDateArray) . '.payment.log');
コード例 #4
0
ファイル: Show.php プロジェクト: jackycgq/bzfshop
 /**
  * 清空整个购物车
  */
 public function Clear()
 {
     $cartBasicService = new CartBasicService();
     $cartBasicService->clearStorage();
     RouteHelper::reRoute($this, '/Cart/Show');
 }
コード例 #5
0
ファイル: Order.php プロジェクト: jackycgq/bzfshop
 /**
  * 把订单加载到购物车
  */
 public function Cart($f3)
 {
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1, true, '订单ID非法')->validate('order_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $userInfo = AuthHelper::getAuthUser();
     // 查询订单
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id, 10);
     // 缓存 10 秒钟
     if ($orderInfo->isEmpty() || $userInfo['user_id'] != $orderInfo['user_id'] || OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status'] || !$this->verifyOrderSystem($orderInfo)) {
         $this->addFlashMessage('订单ID非法');
         goto out_fail;
     }
     //加载订单
     $cartBasicService = new CartBasicService();
     // 加载订单到购物车里
     if (!$cartBasicService->loadFromOrderInfo($order_id)) {
         $this->addFlashMessage('订单加载失败');
         goto out_fail;
     }
     $cartContext =& $cartBasicService->getCartContextRef();
     if ($cartContext->isEmpty()) {
         $this->addFlashMessage('订单为空,不能支付');
         goto out_fail;
     }
     // 保存购物车
     $cartBasicService->syncStorage();
     RouteHelper::reRoute($this, '/Cart/Show');
     return;
     // 成功从这里返回
     out_fail:
     // 从这里退出
     RouteHelper::reRoute($this, '/My/Order');
 }
コード例 #6
0
ファイル: Pay.php プロジェクト: jackycgq/bzfshop
 public function post($f3)
 {
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1, true, '订单ID非法')->validate('order_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $validator = new Validator($f3->get('POST'));
     $payGatewayType = $validator->required('必须选择一种支付方式')->validate('pay_gateway_type');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取得用户信息
     $userInfo = AuthHelper::getAuthUser();
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($userInfo['user_id']);
     // 支付某一个特定的订单需要把订单加载到临时购物车里面
     $orderBasicService = new OrderBasicService();
     // 检查权限
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id);
     if ($orderInfo->isEmpty() || $userInfo['user_id'] != $orderInfo['user_id'] || OrderBasicService::OS_UNCONFIRMED != $orderInfo['order_status']) {
         $this->addFlashMessage('订单ID非法');
         goto out_fail;
     }
     $cartBasicService = new CartBasicService();
     // 加载订单到购物车里
     if (!$cartBasicService->loadFromOrderInfo($order_id)) {
         $this->addFlashMessage('订单加载失败');
         goto out_fail;
     }
     $cartContext =& $cartBasicService->getCartContextRef();
     if ($cartContext->isEmpty()) {
         $this->addFlashMessage('订单为空,不能支付');
         goto out_fail;
     }
     // 做第一次购物车计算,需要计算原始订单的金额,后面红包使用的时候有最低订单金额限制
     $cartBasicService->calcOrderPrice();
     // 计算支付金额
     $cartBasicService->calcOrderPayment();
     // 如果购物车里面有错误消息,我们需要显示它
     if ($cartContext->hasError()) {
         $this->addFlashMessageArray($cartContext->getAndClearErrorMessageArray());
         goto out_fail;
     }
     // 更新订单信息
     $orderInfo = $cartBasicService->saveOrder($userInfo['user_id'], '买家:' . $userInfo['user_name']);
     if (!$orderInfo || $orderInfo->isEmpty()) {
         //订单创建失败,报错
         $this->addFlashMessage('更新订单信息失败,请联系客服');
         goto out_fail;
     }
     // 如果订单金额为 0 ,使用 credit 支付网关
     if ($orderInfo['order_amount'] <= 0) {
         $payGatewayType = 'credit';
     }
     $order_id = $orderInfo['order_id'];
     // 解析参数,我们允许写成 tenpay_cmbchina  代表财付通、招商银行
     $payGatewayParamArray = explode('_', $payGatewayType);
     // 获取支付网关
     $payGateway = PaymentGatewayHelper::getPaymentGateway($payGatewayParamArray[0]);
     // 根据参数做初始化
     if (!$payGateway->init($payGatewayParamArray)) {
         $this->addFlashMessage('支付网关' . $payGatewayType . '初始化失败');
         goto out_fail;
     }
     $payRequestUrl = $payGateway->getRequestUrl($order_id, RouteHelper::makeUrl('/Payment/PaymentReturn/' . $payGateway->getGatewayType(), null, false, true), RouteHelper::makeUrl('/Payment/PaymentNotify/' . $payGateway->getGatewayType(), null, false, true));
     //notifyUrl
     if (empty($payRequestUrl)) {
         $this->addFlashMessage('系统错误:无法生成支付链接');
         goto out_fail;
     }
     // 记录支付日志
     printLog('[orderId:' . $order_id . ']' . $payRequestUrl, 'PAYMENT', Base::INFO);
     // 跳转去支付
     header('Location:' . $payRequestUrl);
     return;
     out_fail:
     //失败从这里退出
     RouteHelper::reRoute($this, '/My/Order');
 }
コード例 #7
0
ファイル: bootstrap.php プロジェクト: jackycgq/bzfshop
// 根据环境变量的不同,加载对应的环境变量设置,开发环境和生产环境的配置显然是不一样的
$f3->config(PROTECTED_PATH . '/Config/shop-' . $f3->get('sysConfig[env]') . '.cfg');
// 设置工作时区
if ($f3->get('sysConfig[time_zone]')) {
    date_default_timezone_set($f3->get('sysConfig[time_zone]'));
}
// 设置 session 在多个子域名之间共享
if ($f3->get('sysConfig[cookie_domain]')) {
    $f3->set('JAR.domain', $f3->get('sysConfig[cookie_domain]'));
}
// 设置网站唯一的 key,防止通用模块之间的冲突
RouteHelper::$uniqueKey = 'BZFRouteHelper';
OrderBasicService::$orderSnPrefix = 'SB';
ReferHelper::$orderReferStorageKey = 'BZFOrderRefer';
// 记录系统订单来源
CartBasicService::$cartSystemId = PluginHelper::SYSTEM_SHOP;
// 把几个网站的 key 设置成一样,配合 sysConfig[cookie_domain] 设置,就可以实现几个网站 统一登陆
AuthHelper::$uniqueKey = 'BZFAUTH';
// ------------ 2. 初始化 云服务引擎,云服务引擎会设置好我们的运行环境,包括 可写目录 等 ------------
CloudHelper::initCloudEnv(PluginHelper::SYSTEM_SHOP);
// ---------------------------------------- 3. 开启系统日志 --------------------------------------
$todayDateStr = \Core\Helper\Utility\Time::localTimeStr('Y-m-d');
$todayDateArray = explode('-', $todayDateStr);
// 设置一个 fileLogger 方便查看所有的日志输出,按照 年/月/年-月-日.log 输出
$fileLogger = new \Core\Log\File($todayDateArray[0] . '/' . $todayDateArray[1] . '/' . implode('-', $todayDateArray) . '.shop.log');
// 我们不打印 DEBUG 级别的日志,不然数据量太大了
$fileLogger->levelAllow = array(\Core\Log\Base::CRITICAL, \Core\Log\Base::ERROR, \Core\Log\Base::WARN, \Core\Log\Base::NOTICE, \Core\Log\Base::INFO);
$logger->addLogger($fileLogger);
unset($fileLogger);
// 设置支付日志,我们需要把所有的支付都记录到支付日志中方便以后查询,按照日期分目录存储
$fileLogger = new \Core\Log\File('PAYMENT/' . $todayDateArray[0] . '/' . $todayDateArray[1] . '/' . implode('-', $todayDateArray) . '.payment.log');