Ejemplo n.º 1
0
 /**
  * 取得一个订单的输出 Txt
  *
  *
  */
 private function getOrderTxt($orderReferInfo, $orderGoodsArray)
 {
     $retTxt = '';
     $orderGoodsNameStr = '';
     $coupon = $orderReferInfo['surplus'] + $orderReferInfo['bonus'];
     // 商品总价
     $orderAmount = $orderReferInfo['goods_amount'] - $orderReferInfo['discount'] - $orderReferInfo['extra_discount'] - $orderReferInfo['refund'];
     // 商品总的额外退款金额
     $orderExtraRefund = 0;
     // 订单状态
     $orderStatus = 'refund';
     switch ($orderReferInfo['pay_status']) {
         case OrderBasicService::PS_UNPAYED:
             $orderStatus = 'unpay';
             break;
         case OrderBasicService::PS_PAYED:
             $orderStatus = 'pay';
             break;
         default:
             $orderStatus = 'refund';
     }
     // 对订单中每个商品单独计算
     foreach ($orderGoodsArray as $orderGoodsItem) {
         $orderGoodsNameStr .= '{(' . $orderGoodsItem['goods_id'] . ')' . $orderGoodsItem['goods_name'] . '[' . $orderGoodsItem['goods_number'] . ' 件]},';
         if (OrderGoodsService::OGS_UNPAY != $orderGoodsItem['order_goods_status'] && OrderGoodsService::OGS_PAY != $orderGoodsItem['order_goods_status']) {
             // 有一个 order_goods 是退款状态,整个订单就是退款状态
             $orderStatus = 'refund';
         }
         // 累计额外退款的总金额
         $orderExtraRefund += $orderGoodsItem['extra_refund'];
     }
     $orderGoodsNameStr = str_replace('|', '_', $orderGoodsNameStr);
     $orderGoodsNameStr = mb_substr($orderGoodsNameStr, 0, 240);
     $referParamArray = json_decode($orderReferInfo['refer_param'], true);
     // CPS 应付总价
     $orderAmountOfCps = $orderAmount - $coupon - $orderExtraRefund;
     $orderAmountOfCps = $orderAmountOfCps > 0 ? $orderAmountOfCps : 0;
     // QQ订单要多输出一条记录
     if ('qqlogin' == $orderReferInfo['login_type']) {
         // 取得QQ登陆用户的信息
         static $userBasicService = null;
         if (null == $userBasicService) {
             $userBasicService = new UserBasicService();
         }
         $userInfo = $userBasicService->loadUserById($orderReferInfo['user_id']);
         //取得 QQ 用户的 openId ,QQ登陆的用户 sns_login 例子  qq:476BA0B2332440759D485548637DFCDD
         $qqUserOpenId = $userInfo->sns_login;
         $qqUserOpenId = substr($qqUserOpenId, strpos($qqUserOpenId, ':') + 1);
         //输出 QQ 登陆的记录
         $retTxt .= $referParamArray['wi'] . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['add_time'])) . "||" . $orderReferInfo['order_id'] . "||" . Money::toSmartyDisplay($orderAmountOfCps) . "||" . $orderGoodsNameStr . "||" . $orderStatus . "||" . $orderStatus . "||alipay" . "||" . Money::toSmartyDisplay($orderReferInfo['shipping_fee']) . "||" . Money::toSmartyDisplay($coupon) . "||0" . "||" . $qqUserOpenId . "||" . 'bangzhufu' . "||" . 'qqlogin003' . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['update_time'])) . "\n";
     }
     if ('YIQIFACPS' != $orderReferInfo['utm_source']) {
         // 不是亿起发的订单
         goto out;
     }
     //输出 亿起发 的订单记录
     $retTxt .= $referParamArray['wi'] . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['add_time'])) . "||" . $orderReferInfo['order_id'] . "||" . Money::toSmartyDisplay($orderAmountOfCps) . "||" . $orderGoodsNameStr . "||" . $orderStatus . "||" . $orderStatus . "||alipay" . "||" . Money::toSmartyDisplay($orderReferInfo['shipping_fee']) . "||" . Money::toSmartyDisplay($coupon) . "||0" . "||" . "||" . "||" . "||" . date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderReferInfo['update_time'])) . "\n";
     out:
     return $retTxt;
 }
Ejemplo n.º 2
0
 public function getOrderReferNotifyUrl($f3, $orderRefer)
 {
     if (!('YIQIFACPS' == $orderRefer->utm_source || 'qqlogin' == $orderRefer->login_type && empty($orderRefer->utm_source))) {
         // 不是亿起发的订单,或者不是QQ登陆订单
         return null;
     }
     $notifyUrlArray = array();
     // 取得记录的 亿起发 参数
     $referParamArray = json_decode($orderRefer->refer_param, true);
     // 取得订单信息
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($orderRefer->order_id);
     // 取得订单商品详情
     $orderGoodsArray = $orderBasicService->fetchOrderGoodsArray($orderRefer->order_id);
     // 计算佣金
     $orderGoodsNameStr = '';
     $coupon = $orderInfo->surplus + $orderInfo->bonus;
     // 商品总价
     $orderAmount = $orderInfo->goods_amount - $orderInfo->discount - $orderInfo->extra_discount - $orderInfo->refund;
     // 商品总的额外退款金额
     $orderExtraRefund = 0;
     // 对订单中每个商品单独计算
     foreach ($orderGoodsArray as $orderGoodsItem) {
         $orderGoodsNameStr .= '{(' . $orderGoodsItem['goods_id'] . ')' . $orderGoodsItem['goods_name'] . '[' . $orderGoodsItem['goods_number'] . ' 件]},';
         // 累计额外退款的总金额
         $orderExtraRefund += $orderGoodsItem['extra_refund'];
     }
     // CPS 应付总价
     $orderAmountOfCps = $orderAmount - $coupon - $orderExtraRefund;
     $orderAmountOfCps = $orderAmountOfCps > 0 ? $orderAmountOfCps : 0;
     $orderGoodsNameStr = str_replace('|', '_', $orderGoodsNameStr);
     $orderGoodsNameStr = mb_substr($orderGoodsNameStr, 0, 240);
     // 推送QQ登陆订单
     if ('qqlogin' == $orderRefer->login_type) {
         // 取得QQ登陆用户的信息
         $userBasicService = new UserBasicService();
         $userInfo = $userBasicService->loadUserById($orderInfo->user_id);
         //取得 QQ 用户的 openId ,QQ登陆的用户 sns_login 例子  qq:476BA0B2332440759D485548637DFCDD
         $qqUserOpenId = $userInfo->sns_login;
         $qqUserOpenId = substr($qqUserOpenId, strpos($qqUserOpenId, ':') + 1);
         // QQ 登陆需要额外推单
         $param = "cid=6406" . "&wid=435983" . "&qqoid=" . $qqUserOpenId . "&qqmid=bangzhufu" . "&ct=qqlogin003" . "&on=" . $orderInfo->order_id . "&ta=1" . "&dt=" . YiqifaCpsRefer::$notifyParamDt . "&pp=" . Money::toSmartyDisplay($orderAmountOfCps) . "&sd=" . urlencode(date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderInfo->add_time))) . "&os=pay" . "&ps=pay" . "&pw=alipay" . "&far=" . Money::toSmartyDisplay($orderInfo->shipping_fee) . "&fav=" . Money::toSmartyDisplay($coupon) . "&fac=0" . "&encoding=utf-8";
         // QQ 登陆订单推送
         $notifyUrlArray[] = YiqifaCpsRefer::yiqifaNotifyGateway . $param;
     }
     if ('YIQIFACPS' != $orderRefer->utm_source) {
         // 不是亿起发的订单
         goto out;
     }
     // 亿起发 正常 CPS 推单
     $param = "cid=" . $referParamArray['cid'] . "&wi=" . $referParamArray['wi'] . "&on=" . $orderInfo->order_id . "&ta=1" . "&pna=" . urlencode($orderGoodsNameStr) . "&dt=" . YiqifaCpsRefer::$notifyParamDt . "&pp=" . Money::toSmartyDisplay($orderAmountOfCps) . "&sd=" . urlencode(date("Y-m-d H:i:s", Time::gmTimeToLocalTime($orderInfo->add_time))) . "&os=pay" . "&ps=pay" . "&pw=alipay" . "&far=" . Money::toSmartyDisplay($orderInfo->shipping_fee) . "&fav=" . Money::toSmartyDisplay($coupon) . "&fac=0" . "&encoding=utf-8";
     // 亿起发订单推送
     $notifyUrlArray[] = YiqifaCpsRefer::yiqifaNotifyGateway . $param;
     out:
     return $notifyUrlArray;
 }
Ejemplo n.º 3
0
 public function post($f3)
 {
     global $smarty;
     // 首先做参数合法性验证
     $validator = new Validator($f3->get('POST'));
     $input = array();
     $input['oldpassword'] = $validator->validate('oldpassword');
     $input['password'] = $validator->validate('password');
     $input['email'] = $validator->validate('email');
     $input['mobile_phone'] = $validator->digits('手机号格式不对')->validate('mobile_phone');
     // 用户打算修改密码
     if (!Utils::isBlank($input['password'])) {
         $validator->required('必须提供旧密码才能修改密码')->validate('oldpassword');
     }
     // 提供的旧密码,但是新密码为空
     if (!Utils::isBlank($input['oldpassword'])) {
         $validator->required('新密码不能为空')->validate('password');
     }
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     $userInfo = AuthHelper::getAuthUser();
     $userService = new UserService();
     $user = $userService->loadUserById($userInfo['user_id']);
     if (!$user) {
         // 非法用户,应该让它自动登陆出去
         $this->addFlashMessage('非法登陆用户');
         RouteHelper::reRoute($this, '/User/Logout', false);
     }
     // 用户打算修改密码,但是旧密码不对
     if (!empty($input['password']) && !$userService->verifyPassword($userInfo['user_id'], $input['oldpassword'])) {
         $this->addFlashMessage('旧密码不对');
         goto out_fail;
     }
     // 更新数据
     unset($input['oldpassword']);
     $userService->updateUser($user, $input);
     // 更新认证记录
     AuthHelper::removeAuthUser();
     AuthHelper::saveAuthUser($user->toArray());
     $this->addFlashMessage('资料更新成功');
     RouteHelper::reRoute($this, '/My/Profile');
     return;
     // 这里正常返回
     out_fail:
     // 失败返回
     $smarty->display('my_profile.tpl', 'post');
 }
Ejemplo n.º 4
0
 public function get($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $pageNo = $validator->digits()->min(0)->validate('pageNo');
     $pageSize = $validator->digits()->min(0)->validate('pageSize');
     // 设置缺省值
     $pageNo = isset($pageNo) && $pageNo > 0 ? $pageNo : 0;
     $pageSize = isset($pageSize) && $pageSize > 0 ? $pageSize : 10;
     if (!$this->validate($validator)) {
         goto out_display;
     }
     $userInfo = AuthHelper::getAuthUser();
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($userInfo['user_id']);
     // 用户总共有资金余额
     $smarty->assign('userMoney', $userInfo['user_money']);
     $accountLog = new AccountLogService();
     // 用户总共有多少account_log
     $totalCount = $accountLog->countUserMoneyArray($userInfo['user_id'], 10);
     //缓存 10 秒钟
     if ($totalCount <= 0) {
         // 没资金变动记录,可以直接退出了
         goto out_display;
     }
     $smarty->assign('totalCount', $totalCount);
     // 页数超过最大值,返回第一页
     if ($pageNo * $pageSize >= $totalCount) {
         RouteHelper::reRoute($this, '/My/Money');
     }
     // 传递分页的变量
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     // account_log 列表
     $accountLogArray = $accountLog->fetchUserMoneyArray($userInfo['user_id'], $pageNo * $pageSize, $pageSize, 10);
     //缓存 10 秒钟
     foreach ($accountLogArray as &$accountLogItem) {
         $accountLogItem['change_type_desc'] = AccountLogService::$changeTypeDesc[$accountLogItem['change_type']];
     }
     unset($accountLogItem);
     $smarty->assign('accountLogArray', $accountLogArray);
     out_display:
     $smarty->display('my_money.tpl', 'get');
 }
Ejemplo n.º 5
0
 /**
  * 显示订单详情
  */
 public function Detail($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_order_goods_detail');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $rec_id = $validator->required()->digits()->min(1)->validate('rec_id');
     if (!$this->validate($validator)) {
         goto out_display;
     }
     // 取 order_goods
     $orderBasicService = new OrderBasicService();
     $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id);
     if ($orderGoods->isEmpty() || $orderGoods['order_id'] <= 0) {
         $this->addFlashMessage('订单ID非法');
         goto out_display;
     }
     // 转换状态显示
     $orderGoods['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoods['order_goods_status']];
     // 额外优惠允许的最大金额
     $allowExtraDiscount = $orderGoods['goods_price'] + $orderGoods['shipping_fee'] - $orderGoods['discount'];
     $maxExtraDiscount = round($allowExtraDiscount * $f3->get('sysConfig[max_order_goods_extra_discount_rate]'), 2);
     $maxExtraDiscount = max($maxExtraDiscount, $f3->get('sysConfig[max_order_goods_extra_discount_value]'));
     $maxExtraDiscount = min($maxExtraDiscount, $allowExtraDiscount);
     // 退款允许退的最大金额
     $maxRefund = $orderGoods['goods_price'] + $orderGoods['shipping_fee'] - $orderGoods['discount'] - $orderGoods['extra_discount'];
     // 取商品信息
     $goodsBasicService = new GoodsBasicService();
     $goods = $goodsBasicService->loadGoodsById($orderGoods['goods_id'], 300);
     // 缓存 300 秒
     // 取 order_info
     $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id']);
     if ($orderInfo->isEmpty()) {
         $this->addFlashMessage('订单ID非法');
         goto out_display;
     }
     $orderInfo['order_status_desc'] = OrderBasicService::$orderStatusDesc[$orderInfo['order_status']];
     $orderInfo['pay_status_desc'] = OrderBasicService::$payStatusDesc[$orderInfo['pay_status']];
     // 取订单来源信息
     $orderReferService = new OrderReferService();
     $orderRefer = $orderReferService->loadOrderReferByOrderId($orderInfo['order_id'], 300);
     //缓存5分钟
     // 取用户账户
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($orderInfo['user_id']);
     // 取得订单的操作日志
     $orderActionService = new OrderActionService();
     $orderLogArray = $orderActionService->fetchOrderLogArray($orderGoods['order_id'], $orderGoods['rec_id']);
     // 状态字段转换成可以显示的字符串
     foreach ($orderLogArray as &$orderLog) {
         $orderLog['order_status'] = OrderBasicService::$orderStatusDesc[$orderLog['order_status']];
         $orderLog['pay_status'] = OrderBasicService::$payStatusDesc[$orderLog['pay_status']];
         $orderLog['order_goods_status'] = OrderGoodsService::$orderGoodsStatusDesc[$orderLog['order_goods_status']];
         $orderLog['action_note'] = nl2br($orderLog['action_note']);
     }
     unset($orderLog);
     // 查询供货商信息
     $supplierUserService = new SupplierUserService();
     $supplierInfo = $supplierUserService->loadSupplierById($orderGoods['suppliers_id']);
     // 给模板赋值
     $smarty->assign('orderGoods', $orderGoods);
     $smarty->assign('goods', $goods);
     $smarty->assign('maxExtraDiscount', $maxExtraDiscount);
     $smarty->assign('maxRefund', $maxRefund);
     $smarty->assign('orderInfo', $orderInfo);
     $smarty->assign('orderRefer', $orderRefer);
     $smarty->assign('userInfo', $userInfo);
     $smarty->assign('supplierInfo', $supplierInfo);
     $smarty->assign('orderLogArray', $orderLogArray);
     out_display:
     $smarty->display('order_goods_detail.tpl');
 }
Ejemplo n.º 6
0
 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');
 }
Ejemplo n.º 7
0
 /**
  * 订单详情
  */
 public function Detail($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_order_order_detail');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $order_id = $validator->required('订单ID非法')->digits('订单ID非法')->min(1)->validate('order_id');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 查询订单
     $orderBasicService = new OrderBasicService();
     $orderInfo = $orderBasicService->loadOrderInfoById($order_id);
     if ($orderInfo->isEmpty()) {
         $this->addFlashMessage('订单ID非法');
         goto out_fail;
     }
     $orderInfo['order_status_desc'] = OrderBasicService::$orderStatusDesc[$orderInfo['order_status']];
     $orderInfo['pay_status_desc'] = OrderBasicService::$payStatusDesc[$orderInfo['pay_status']];
     $orderGoodsArray = $orderBasicService->fetchOrderGoodsArray($order_id);
     // 转换状态显示
     foreach ($orderGoodsArray as &$orderGoodsItem) {
         $orderGoodsItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsItem['order_goods_status']];
     }
     unset($orderGoodsItem);
     // 取订单来源信息
     $orderReferService = new OrderReferService();
     $orderRefer = $orderReferService->loadOrderReferByOrderId($orderInfo['order_id'], 300);
     //缓存5分钟
     // 取用户账户
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($orderInfo['user_id']);
     // 取得订单的操作日志
     $orderActionService = new OrderActionService();
     $orderLogArray = $orderActionService->fetchOrderLogArray($order_id, 0);
     // 状态字段转换成可以显示的字符串
     foreach ($orderLogArray as &$orderLog) {
         $orderLog['order_status'] = OrderBasicService::$orderStatusDesc[$orderLog['order_status']];
         $orderLog['pay_status'] = OrderBasicService::$payStatusDesc[$orderLog['pay_status']];
         $orderLog['order_goods_status'] = OrderGoodsService::$orderGoodsStatusDesc[$orderLog['order_goods_status']];
         $orderLog['action_note'] = nl2br($orderLog['action_note']);
     }
     unset($orderLog);
     // 给模板赋值
     $smarty->assign('orderInfo', $orderInfo);
     $smarty->assign('orderRefer', $orderRefer);
     $smarty->assign('userInfo', $userInfo);
     $smarty->assign('orderGoodsArray', $orderGoodsArray);
     $smarty->assign('orderLogArray', $orderLogArray);
     $smarty->display('order_order_detail.tpl');
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Order/Order/Search');
 }
Ejemplo n.º 8
0
 /**
  * 重新加载用户信息
  */
 public static function reloadAuthUser()
 {
     $authUser = Auth::getAuthUser();
     if (empty($authUser) || !isset($authUser['user_id']) || empty($authUser['user_id'])) {
         return;
     }
     $basicUserService = new UserBasicService();
     $user = $basicUserService->loadUserById($authUser['user_id']);
     if ($user->isEmpty()) {
         return;
     }
     Auth::saveAuthUser($user->toArray());
 }
Ejemplo n.º 9
0
 /**
  * 标记 order_goods 记录为已经支付状态
  *
  * @param $orderId
  */
 public function markOrderGoodsPay($orderInfo)
 {
     // 参数验证
     $validator = new Validator(array('orderId' => $orderInfo['order_id']));
     $orderId = $validator->required()->digits()->min(1)->validate('orderId');
     $this->validate($validator);
     // 设置 order_goods 的状态
     $sql = 'update ' . DataMapper::tableName('order_goods') . ' set order_goods_status = ' . Goods::OGS_PAY . ', update_time = ' . Time::gmTime() . ' where order_id = ? ';
     $dbEngine = DataMapper::getDbEngine();
     $dbEngine->exec($sql, $orderId);
     $goodsCommentService = new GoodsCommentService();
     $userBasicService = new UserBasicSerivce();
     $userInfo = $userBasicService->loadUserById($orderInfo['user_id']);
     $orderBasicService = new OrderBasicService();
     $orderGoodsArray = $orderBasicService->fetchOrderGoodsArray($orderId);
     foreach ($orderGoodsArray as $orderGoodsItem) {
         // 更新商品的销售数量
         $this->updateGoodsUserPayCount($orderGoodsItem['goods_id'], $orderGoodsItem['goods_number']);
         // 更新商品的库存
         $this->updateGoodsGoodsNumber($orderGoodsItem['goods_id'], $orderGoodsItem['goods_attr'], $orderGoodsItem['goods_number']);
         // 添加一个 goods_comment 记录
         if (!$goodsCommentService->isOrderGoodsCommentExist($orderGoodsItem['rec_id'])) {
             $goodsComment = $goodsCommentService->loadGoodsCommentById(0);
             $goodsComment->create_time = Time::gmTime();
             $goodsComment->rec_id = $orderGoodsItem['rec_id'];
             $goodsComment->goods_id = $orderGoodsItem['goods_id'];
             $goodsComment->goods_price = $orderGoodsItem['goods_price'];
             $goodsComment->goods_number = $orderGoodsItem['goods_number'];
             $goodsComment->goods_attr = $orderGoodsItem['goods_attr'];
             $goodsComment->comment_rate = 5;
             // 用户不评论,我们默认为好评,显示
             $goodsComment->is_show = 1;
             // 用户不评论,我们默认为好评,显示
             $goodsComment->user_id = $userInfo['user_id'];
             $goodsComment->user_name = $userInfo['user_name'];
             $goodsComment->save();
         }
     }
 }
Ejemplo n.º 10
0
 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');
 }
Ejemplo n.º 11
0
 /**
  * 给用户余额充值
  * @param $f3
  */
 public function Charge($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_account_user_charge');
     $validator = new Validator($f3->get('POST'));
     $user_id = $validator->required()->digits()->validate('user_id');
     $chargeMoney = Money::toStorage($validator->validate('chargeMoney'));
     $chargeMoneyDesc = $validator->validate('chargeMoneyDesc');
     if (!$this->validate($validator)) {
         goto out;
     }
     if (0 == $chargeMoney) {
         $this->addFlashMessage('充值为0,不操作');
         goto out;
     }
     // 加载用户信息
     $userBasicService = new UserBasicService();
     $userInfo = $userBasicService->loadUserById($user_id);
     if ($userInfo->isEmpty()) {
         $this->addFlashMessage('用户ID非法[' . $user_id . ']');
         goto out;
     }
     // 当前操作的管理员
     $authAdminUser = AuthHelper::getAuthUser();
     // 给用户充值
     $accountLog = new AccountLog();
     $accountLog->logChange($user_id, $chargeMoney, 0, 0, 0, '管理员[' . $authAdminUser['user_name'] . ']充值[' . Money::toSmartyDisplay($chargeMoney) . ']元' . "\n" . $chargeMoneyDesc, $chargeMoney > 0 ? AccountLog::ACT_SAVING : AccountLog::ACT_DRAWING, $authAdminUser['user_id']);
     $this->addFlashMessage('充值 [' . Money::toSmartyDisplay($chargeMoney) . '] 元成功');
     out:
     RouteHelper::reRoute($this, RouteHelper::getRefer(), false);
 }