Exemple #1
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');
 }
Exemple #2
0
 public function get($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($_GET);
     $cid = $validator->required()->validate('cid');
     $queryCreateDate = $validator->digits()->validate('d');
     $queryUpdateDate = $validator->digits()->validate('ud');
     // 参数有错误
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 不能同时为空
     if (empty($queryCreateDate) && empty($queryUpdateDate)) {
         goto out_fail;
     }
     if (!empty($queryCreateDate)) {
         // 参数检查,格式只能为 20120304 或者 2012030410
         $dateStrLen = strlen($queryCreateDate);
         if (8 != $dateStrLen && 10 != $dateStrLen) {
             goto out_fail;
         }
     }
     if (!empty($queryUpdateDate)) {
         // 参数检查,格式只能为 20120304 或者 2012030410
         $dateStrLen = strlen($queryUpdateDate);
         if (8 != $dateStrLen && 10 != $dateStrLen) {
             goto out_fail;
         }
     }
     enableSmartyCache(true, 60);
     //缓存1分钟,防止访问很频繁从而变成对网站的攻击
     $smartyCacheId = 'YiqifaCps|' . md5(json_encode(QueryOrder::$extraQueryCond) . '_' . $cid . '_' . $queryCreateDate . '_' . $queryUpdateDate);
     // 判断是否有缓存
     if ($smarty->isCached('yiqifacps_empty.tpl', $smartyCacheId)) {
         goto out_display;
     }
     $txtOutput = '';
     // 构造查询条件
     $condArray = array();
     $condArray[] = array('orf.utm_source = ? or (orf.login_type = ? and orf.utm_source is null)', 'YIQIFACPS', 'qqlogin');
     // add_time 查询
     if (!empty($queryCreateDate)) {
         $startTime = 0;
         $endTime = 0;
         if (strlen($queryCreateDate) == 8) {
             $startTime = strtotime($queryCreateDate);
             $endTime = $startTime + 24 * 60 * 60;
         }
         if (strlen($queryCreateDate) == 10) {
             $datePart = substr($queryCreateDate, 0, 8);
             $hourPart = substr($queryCreateDate, 8, 2);
             $startTime = strtotime($datePart . " " . $hourPart . ":00:00");
             $endTime = $startTime + 60 * 60;
         }
         $condArray[] = array('oi.add_time >= ? and oi.add_time < ?', $startTime, $endTime);
     }
     // update_time 查询
     if (!empty($queryUpdateDate)) {
         $startTime = 0;
         $endTime = 0;
         if (strlen($queryUpdateDate) == 8) {
             $startTime = strtotime($queryUpdateDate);
             $endTime = $startTime + 24 * 60 * 60;
         }
         if (strlen($queryUpdateDate) == 10) {
             $datePart = substr($queryUpdateDate, 0, 8);
             $hourPart = substr($queryUpdateDate, 8, 2);
             $startTime = strtotime($datePart . " " . $hourPart . ":00:00");
             $endTime = $startTime + 60 * 60;
         }
         $condArray[] = array('oi.update_time >= ? and oi.update_time < ?', $startTime, $endTime);
     }
     /**
      * 加入额外的查询条件
      */
     if (!empty(QueryOrder::$extraQueryCond)) {
         $condArray[] = QueryOrder::$extraQueryCond;
     }
     // 查询订单,每次最多 2000 条数据,防止拖死系统
     $orderReferService = new OrderReferService();
     $orderReferInfoArray = $orderReferService->fetchOrderReferInfo($condArray, array('order' => 'oi.order_id asc'), 0, 2000);
     // 过滤 cid,只留下需要查询的 cid 数据,同时收集 order_id 用于查询 order_goods 信息
     $cidOrderReferInfoArray = array();
     $orderIdArray = array();
     foreach ($orderReferInfoArray as $orderReferInfoItem) {
         $referParamArray = json_decode($orderReferInfoItem['refer_param'], true);
         if (!empty($referParamArray['cid']) && $referParamArray['cid'] != $cid) {
             //不是要查询的订单,跳过
             continue;
             // ==== 为了测试临时注释的代码
         }
         $cidOrderReferInfoArray[] = $orderReferInfoItem;
         $orderIdArray[] = $orderReferInfoItem['order_id'];
     }
     unset($orderReferInfoArray);
     //清除旧数据
     $orderReferInfoArray = $cidOrderReferInfoArray;
     unset($cidOrderReferInfoArray);
     //清除临时数据
     if (empty($orderReferInfoArray)) {
         // 没有数据,跳出
         goto out;
     }
     $orderGoodsArray = $orderReferService->_fetchArray('order_goods', '*', array(array(QueryBuilder::buildInCondition('order_id', $orderIdArray))), array('order' => 'order_id asc, rec_id asc'), 0, 10000);
     //最多查询 10000 条记录,防止拖死系统
     // 建立 order_id --> array( order_goods ) 的反查表
     $orderIdToOrderGoodsArray = array();
     foreach ($orderGoodsArray as $orderGoodsItem) {
         if (!isset($orderIdToOrderGoodsArray[$orderGoodsItem['order_id']])) {
             $orderIdToOrderGoodsArray[$orderGoodsItem['order_id']] = array();
         }
         $orderIdToOrderGoodsArray[$orderGoodsItem['order_id']][] = $orderGoodsItem;
     }
     // 根据订单构建 CPS 返回记录
     foreach ($orderReferInfoArray as $orderReferItem) {
         if (isset($orderIdToOrderGoodsArray[$orderReferItem['order_id']])) {
             $txtOutput .= $this->getOrderTxt($orderReferItem, $orderIdToOrderGoodsArray[$orderReferItem['order_id']]);
         }
     }
     out:
     $smarty->assign('outputContent', $txtOutput);
     out_display:
     //成功从这里返回
     header('Content-Type:text/plain;charset=utf-8');
     header("Cache-Control: no-cache, must-revalidate");
     // HTTP/1.1 //查询信息
     $smarty->display('yiqifacps_empty.tpl', $smartyCacheId);
     return;
     out_fail:
     // 失败从这里返回
     echo "paramters error";
 }
Exemple #3
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');
 }
Exemple #4
0
 /**
  * 把购物车中的信息保存到数据库订单中,如果订单已经存在,则更新订单数据,
  * 注意:这个方法必须在购物车计算完成之后调用,否则无法正确保存计算之后的数据
  *
  * @return mixed 失败返回 false,成功返回订单记录
  *
  * @param int    $userId   用户的数字 ID
  * @param string $username 用户名
  */
 public function saveOrder($userId, $username)
 {
     // 参数验证
     $validator = new Validator(array('userId' => $userId));
     $userId = $validator->required()->digits()->min(1)->validate('userId');
     $this->validate($validator);
     $orderBasicService = new OrderBasicService();
     $orderId = isset($this->cartContext->orderInfo) ? $this->cartContext->orderInfo['order_id'] : null;
     // 不允许创建空订单
     if (!$orderId && $this->cartContext->isEmpty()) {
         return false;
     }
     // 是否需要新建订单
     $isNewOrder = false;
     //检查这个 order_info 是否合法
     if ($orderId) {
         $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
         // 不存在的 order_info 或者 已经付款了的订单不能再用了
         if ($orderInfo->isEmpty() || OrderBasicService::PS_UNPAYED != $orderInfo->pay_status) {
             $orderId = null;
             $isNewOrder = true;
         }
     } else {
         $isNewOrder = true;
     }
     // 创建 order_info 记录
     $orderInfoArray = $this->cartContext->orderInfoValue;
     $orderInfoArray['user_id'] = $userId;
     $orderInfoArray['order_status'] = OrderBasicService::OS_UNCONFIRMED;
     $orderInfoArray['pay_status'] = OrderBasicService::PS_UNPAYED;
     if (!$orderId) {
         // 新订单,生成 add_time 和 order_sn
         $orderInfoArray['add_time'] = Time::gmTime();
         $orderInfoArray['order_sn'] = OrderBasicService::generateOrderSn();
         $orderInfoArray['system_id'] = Cart::$cartSystemId;
         // 记录订单来自于哪个系统
     } elseif ($this->cartContext->isOrderAmountChange()) {
         // 去支付网关支付,如果订单金额发生变化都需要重新生成一次 order_sn ,因为订单金额如果发生变化,支付网关会拒绝支付
         $orderInfoArray['order_sn'] = OrderBasicService::generateOrderSn();
     } else {
         // do nothing
     }
     // 我们需要数据库事务的保障
     $dbEngine = DataMapper::getDbEngine();
     $dbEngine->begin();
     // 记录余额支付
     $oldSurplus = $this->cartContext->orderInfo ? $this->cartContext->orderInfo['surplus'] : 0;
     $newSurplus = $this->cartContext->getValue('surplus') > 0 ? $this->cartContext->getValue('surplus') : 0;
     // 记录使用红包
     $oldBonusId = $this->cartContext->orderInfo ? $this->cartContext->orderInfo['bonus_id'] : 0;
     $newBonusId = $this->cartContext->getValue('bonus_id') > 0 ? $this->cartContext->getValue('bonus_id') : 0;
     // 创建订单或者更新 order_info
     $orderInfo = $orderBasicService->saveOrderInfo($orderId, $orderInfoArray);
     // 创建订单失败,返回 false
     if ($orderInfo->isEmpty()) {
         goto out_fail;
     }
     // 处理余额支付
     if ($oldSurplus != $newSurplus) {
         // 前后发生了支付余额的改变
         $accountLog = new AccountLog();
         if ($oldSurplus > 0) {
             // 把之前的余额退还
             $accountLog->logChange($userId, $oldSurplus, 0, 0, 0, '退还余额,订单:' . $orderInfo['order_id'], AccountLog::ACT_OTHER);
         }
         if ($newSurplus > 0) {
             // 使用余额
             $accountLog->logChange($userId, -1 * $newSurplus, 0, 0, 0, '使用余额,订单:' . $orderInfo['order_id'], AccountLog::ACT_OTHER);
         }
         // 由于修改了用户信息,需要 reload 用户数据
         AuthHelper::reloadAuthUser();
     }
     // 处理红包支付
     if ($oldBonusId != $newBonusId) {
         // 红包支付前后发生了变化
         $bonusService = new Bonus();
         if ($oldBonusId > 0) {
             //退还之前使用的红包
             $bonusService->unUseBonus($oldBonusId);
         }
         if ($newBonusId > 0) {
             // 使用新的红包
             $bonusService->useBonus($newBonusId, $orderInfo['order_id']);
         }
     }
     // 创建 orderRefer 对象,记录订单的来源
     $orderReferService = new OrderReferService();
     $orderRefer = $orderReferService->loadOrderReferByOrderId($orderInfo['order_id']);
     // order_refer 记录创建一次之后就不会再修改了
     if ($orderRefer->isEmpty()) {
         // 新的 order_refer 记录,设置 order_id 值
         $orderRefer->order_id = $orderInfo['order_id'];
         $orderRefer->create_time = Time::gmTime();
         $orderRefer->login_type = AuthHelper::getLoginType();
         global $f3;
         $orderReferArray = ReferHelper::parseOrderRefer($f3);
         if (!empty($orderReferArray)) {
             unset($orderReferArray['refer_id']);
             //清除掉危险字段
             unset($orderReferArray['order_id']);
             //清除掉危险字段
             $orderRefer->copyFrom($orderReferArray);
         }
         $orderRefer->save();
         // 保存 order_refer 记录
     }
     // 取得数据库中已经存在的 order_goods 列表
     $dbOrderGoodsArray = array();
     if ($orderId > 0) {
         $dbOrderGoodsArray = $orderBasicService->fetchOrderGoodsArray($orderId);
     }
     $stillExistOrderGoodsIdArray = array();
     // 在购物车中仍然存在的 orderGoods 对象
     // 创建 orderInfo 对应的 order_goods 对象
     foreach ($this->cartContext->orderGoodsArray as $orderGoodsItem) {
         $orderGoodsValueArray = array();
         $orderGoodsValueArray['order_id'] = $orderInfo['order_id'];
         //从 goods 中复制属性
         $orderGoodsValueArray['goods_id'] = $orderGoodsItem->goods['goods_id'];
         $orderGoodsValueArray['goods_admin_user_id'] = $orderGoodsItem->goods['admin_user_id'];
         $orderGoodsValueArray['goods_admin_user_name'] = $orderGoodsItem->goods['admin_user_name'];
         $orderGoodsValueArray['goods_name'] = $orderGoodsItem->goods['goods_name_short'];
         $orderGoodsValueArray['goods_sn'] = $orderGoodsItem->goods['goods_sn'];
         $orderGoodsValueArray['warehouse'] = $orderGoodsItem->goods['warehouse'];
         $orderGoodsValueArray['shelf'] = $orderGoodsItem->goods['shelf'];
         $orderGoodsValueArray['market_price'] = $orderGoodsItem->goods['market_price'];
         $orderGoodsValueArray['shop_price'] = $orderGoodsItem->goods['shop_price'];
         $orderGoodsValueArray['shipping_fee'] = $orderGoodsItem->goods['shipping_fee'];
         $orderGoodsValueArray['is_real'] = $orderGoodsItem->goods['is_real'];
         $orderGoodsValueArray['extension_code'] = $orderGoodsItem->goods['extension_code'];
         $orderGoodsValueArray['suppliers_id'] = $orderGoodsItem->goods['suppliers_id'];
         $orderGoodsValueArray['suppliers_price'] = $orderGoodsItem->goods['suppliers_price'];
         $orderGoodsValueArray['suppliers_shipping_fee'] = $orderGoodsItem->goods['suppliers_shipping_fee'];
         // 合并一些因为计算而覆盖的值
         $orderGoodsValueArray = array_merge($orderGoodsValueArray, $orderGoodsItem->orderGoodsValue);
         $orderGoodsId = null;
         if (!$isNewOrder && $orderGoodsItem->orderGoods) {
             // 如果不是新订单,并且已经存在的 order_goods,做更新
             $orderGoodsId = $orderGoodsItem->orderGoods['rec_id'];
             $stillExistOrderGoodsIdArray[] = $orderGoodsId;
         } else {
             // 新建的 order_goods,我们需要取得它的 CPS 信息,CPS 信息只在一开始加入,后面不会再被修改了
             $cpsArray = ReferHelper::getCpsParam($orderRefer, $orderInfo, $orderGoodsValueArray);
             if (!empty($cpsArray)) {
                 $orderGoodsValueArray['cps_rate'] = isset($cpsArray['cps_rate']) ? $cpsArray['cps_rate'] : 0;
                 $orderGoodsValueArray['cps_fix_fee'] = isset($cpsArray['cps_fix_fee']) ? $cpsArray['cps_fix_fee'] : 0;
             }
         }
         $orderGoods = $orderBasicService->saveOrderGoods($orderGoodsId, $orderInfo['order_id'], $orderGoodsValueArray);
         if ($orderGoods->isEmpty()) {
             //创建失败
             goto out_fail;
         }
     }
     // 删除已经被用户删除的 order_goods
     foreach ($dbOrderGoodsArray as $dbOrderGoodsItem) {
         // 这个 order_goods 已经不存在了,删除它
         if (!in_array($dbOrderGoodsItem['rec_id'], $stillExistOrderGoodsIdArray)) {
             $orderBasicService->removeOrderGoods($dbOrderGoodsItem['rec_id']);
         }
     }
     // 记录订单操作日志
     $orderActionService = new OrderActionService();
     $orderActionService->logOrderAction($orderInfo['order_id'], 0, OrderBasicService::OS_UNCONFIRMED, OrderBasicService::PS_UNPAYED, OrderGoodsService::OGS_UNPAY, '订单创建或更新', $username, 0, 0);
     $dbEngine->commit();
     return $orderInfo;
     // 返回创建的订单
     out_fail:
     $dbEngine->rollback();
     return false;
 }
Exemple #5
0
 /**
  * 对订单的 order_refer 信息做通知
  *
  * @param $f3
  * @param $order_id
  */
 public static function notifyOrderRefer($f3, $order_id)
 {
     $orderReferService = new Refer();
     $orderRefer = $orderReferService->loadOrderReferByOrderId($order_id);
     foreach (static::$IReferArray as $IReferItem) {
         $IReferItem->notifyOrderRefer($f3, $orderRefer);
     }
 }