Exemple #1
0
 /**
  * 标记订单已经支付
  *
  * @param int    $orderId 订单数字ID
  * @param int    $payId   支付类型,比如 4 代表财付通,5代表支付宝
  * @param string $payType 支付类型,比如 alipay, tenpay
  * @param string $payNo   支付方返回的交易编号,比如支付宝返回的交易号
  */
 public function markOrderInfoPay($orderId, $payId, $payType, $payNo, $note = '', $username = '******')
 {
     global $logger;
     // 参数验证
     $validator = new Validator(array('orderId' => $orderId, 'payId' => $payId));
     $orderId = $validator->required()->digits()->min(1)->validate('orderId');
     $payId = $validator->required()->digits()->min(1)->validate('payId');
     $this->validate($validator);
     // 订单操作,需要保证事务
     $dbEngine = DataMapper::getDbEngine();
     try {
         $dbEngine->begin();
         // 更新 order_info
         $orderBasicService = new Order();
         $orderInfo = $orderBasicService->loadOrderInfoById($orderId);
         if ($orderInfo->isEmpty()) {
             $logger->addLogInfo(\Core\Log\Base::ERROR, 'PAYMENT', __CLASS__ . '-' . __FUNCTION__ . ' invalid order_id [' . $orderId . ']');
             throw new \InvalidArgumentException('invalid order_id [' . $orderId . ']');
         }
         $currentGmTime = Time::gmTime();
         $orderInfo->order_status = Order::OS_CONFIRMED;
         $orderInfo->pay_status = Order::PS_PAYED;
         $orderInfo->update_time = $currentGmTime;
         $orderInfo->confirm_time = $currentGmTime;
         $orderInfo->pay_time = $currentGmTime;
         $orderInfo->pay_id = $payId;
         $orderInfo->pay_type = $payType;
         $orderInfo->pay_no = $payNo;
         $orderInfo->money_paid = $orderInfo->order_amount;
         $orderInfo->save();
         // 更新 order_goods
         $orderGoodsService = new Goods();
         $orderGoodsService->markOrderGoodsPay($orderInfo);
         if (empty($note)) {
             $note = '[' . $payType . ']付款确认';
         }
         //记录订单操作日志
         $orderActionService = new Action();
         $orderActionService->logOrderAction($orderId, 0, Order::OS_CONFIRMED, Order::PS_PAYED, Goods::OGS_PAY, $note, $username, 0, $orderInfo['shipping_status']);
         // 提交事务
         $dbEngine->commit();
         // 记录成功日志
         $logger->addLogInfo(\Core\Log\Base::INFO, 'PAYMENT', __CLASS__ . '-' . __FUNCTION__ . ' success order_id [' . $orderId . ']');
     } catch (Exception $e) {
         // 记录异常日志
         $logger->addLogInfo(\Core\Log\Base::ERROR, 'PAYMENT', print_r($e->getTrace(), true));
         $dbEngine->rollback();
     }
     // 由于商品库存发生变化,我们需要清除商品缓存,显示新的库存
     // 注意: 这个操作绝对不能在前面的 Transaction 中操作,防止对数据库性能造成巨大影响
     $orderGoodsArray = $orderBasicService->fetchOrderGoodsArray($orderId);
     $goodsIdArray = array();
     foreach ($orderGoodsArray as $orderGoodsItem) {
         $goodsIdArray[] = $orderGoodsItem['goods_id'];
     }
     $goodsIdArray = array_unique($goodsIdArray);
     foreach ($goodsIdArray as $goodsId) {
         // 清除商品的缓存,确保库存数据显示是正确的
         ClearHelper::clearGoodsCacheById($goodsId);
     }
 }
Exemple #2
0
 /**
  * 列出结算对应的订单明细
  *
  * @param $f3
  */
 public function ListOrderGoods($f3)
 {
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $settle_id = $validator->required('结算ID非法')->digits('结算ID非法')->min(1, true, '结算ID非法')->validate('settle_id');
     $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_fail;
     }
     // 做权限检查
     $authSupplierUser = AuthHelper::getAuthUser();
     $orderSettleService = new OrderSettleService();
     $orderSettle = $orderSettleService->loadOrderSettleBySettleId($settle_id);
     if ($orderSettle->isEmpty() || $authSupplierUser['suppliers_id'] !== $orderSettle['suppliers_id']) {
         $this->addFlashMessage('结算ID非法');
         goto out_fail;
     }
     $orderGoodsService = new OrderGoodsService();
     $totalCount = $orderGoodsService->countOrderGoodsArray(array(array('settle_id = ?', $settle_id)));
     if ($totalCount <= 0) {
         // 没订单,可以直接退出了
         goto out;
     }
     // 页数超过最大值,返回结算列表
     if ($pageNo * $pageSize >= $totalCount) {
         goto out_fail;
     }
     $orderGoodsArray = $orderGoodsService->fetchOrderGoodsArray(array(array('settle_id = ?', $settle_id)), $pageNo * $pageSize, $pageSize);
     // 转换状态显示
     foreach ($orderGoodsArray as &$orderGoodsItem) {
         $orderGoodsItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsItem['order_goods_status']];
     }
     unset($orderGoodsItem);
     // 给模板赋值
     $smarty->assign('totalCount', $totalCount);
     $smarty->assign('pageNo', $pageNo);
     $smarty->assign('pageSize', $pageSize);
     $smarty->assign('orderGoodsArray', $orderGoodsArray);
     out:
     $smarty->display('order_settle_listordergoods.tpl');
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Order/Settle/ListSettle');
 }
Exemple #3
0
 /**
  *
  * 批量下载订单
  *
  */
 public function Download($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_order_excel_download');
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     //表单查询
     $formQuery = array();
     $formQuery['suppliers_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('suppliers_id');
     $formQuery['goods_id'] = $validator->digits()->min(1)->filter('ValidatorIntValue')->validate('goods_id');
     if (empty($formQuery['suppliers_id']) && empty($formQuery['goods_id'])) {
         $this->addFlashMessage('供货商ID 和 商品ID 不能同时为空');
         goto out_fail;
     }
     //付款时间
     $payTimeStartStr = $validator->validate('pay_time_start');
     $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null;
     $payTimeEndStr = $validator->validate('pay_time_end');
     $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null;
     $formQuery['pay_time'] = array($payTimeStart, $payTimeEnd);
     //额外退款,时间
     $extraRefundTimeStartStr = $validator->validate('extra_refund_time_start');
     $extraRefundTimeStart = Time::gmStrToTime($extraRefundTimeStartStr) ?: null;
     $extraRefundTimeEndStr = $validator->validate('extra_refund_time_end');
     $extraRefundTimeEnd = Time::gmStrToTime($extraRefundTimeEndStr) ?: null;
     $formQuery['extra_refund_time'] = array($extraRefundTimeStart, $extraRefundTimeEnd);
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     if (Utils::isBlank($formQuery['suppliers_id']) || (Utils::isBlank($payTimeStart) || Utils::isBlank($payTimeEnd)) && (Utils::isBlank($extraRefundTimeStart) || Utils::isBlank($extraRefundTimeEnd))) {
         $this->addFlashMessage('按照供货商下载订单必须提供时间段参数');
         goto out_fail;
     }
     $condArray = array();
     $condArray[] = array('oi.order_id = og.order_id');
     $condArray[] = array('order_goods_status > 0');
     // 表单查询
     $condArray = array_merge($condArray, QueryBuilder::buildQueryCondArray($formQuery));
     $orderGoodsService = new OrderGoodsService();
     $orderGoodsArray = $orderGoodsService->_fetchArray(array('order_info' => 'oi', 'order_goods' => 'og'), 'og.*, oi.add_time, oi.pay_time, oi.consignee, oi.mobile, oi.tel, oi.zipcode, oi.postscript, oi.address', $condArray, array('order' => 'oi.order_id asc, og.rec_id asc, og.goods_id asc'), 0, $f3->get('sysConfig[max_query_record_count]'), 0);
     //最多限制 max_query_record_count 条记录
     // 转换显示格式
     foreach ($orderGoodsArray as &$orderGoodsItem) {
         $orderGoodsItem['add_time'] = Time::gmTimeToLocalTimeStr($orderGoodsItem['add_time'], 'Y-m-d H:i:s');
         $orderGoodsItem['pay_time'] = Time::gmTimeToLocalTimeStr($orderGoodsItem['pay_time'], 'Y-m-d H:i:s');
         $orderGoodsItem['extra_refund_time'] = Time::gmTimeToLocalTimeStr($orderGoodsItem['extra_refund_time'], 'Y-m-d H:i:s');
         $orderGoodsItem['suppliers_total_price'] = $orderGoodsItem['suppliers_price'] * $orderGoodsItem['goods_number'];
         $orderGoodsItem['order_goods_status_desc'] = OrderGoodsService::$orderGoodsStatusDesc[$orderGoodsItem['order_goods_status']];
     }
     unset($orderGoodsItem);
     require_once PROTECTED_PATH . '/Vendor/PHPExcel/Settings.php';
     // 设置Excel缓存,防止数据太多拖死了程序
     \PHPExcel_Settings::setCacheStorageMethod(\PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp);
     // 导出为 Excel 格式
     $objPHPExcel = new \PHPExcel();
     // 设置工作 sheet
     $objPHPExcel->setActiveSheetIndex(0);
     $activeSheet = $objPHPExcel->getActiveSheet();
     // 取得快递公司列表
     $expressService = new ExpressService();
     $expressArray = $expressService->fetchExpressArray();
     //输出快递公司参考表
     $this->outputExpressArray($activeSheet, $expressArray);
     //释放内存
     unset($expressArray);
     unset($expressService);
     // 格式化数据
     $rowIndex = 1;
     $lastOrderId = 0;
     $orderGoodsArraySize = count($orderGoodsArray);
     // 输出头部信息
     $this->outputHeaderRow($activeSheet, $rowIndex);
     $rowIndex++;
     // 换行
     for ($orderGoodsIndex = 0; $orderGoodsIndex < $orderGoodsArraySize; $orderGoodsIndex++) {
         // 取得这行数据
         $orderGoodsItem = $orderGoodsArray[$orderGoodsIndex];
         if ($lastOrderId != $orderGoodsItem['order_id']) {
             $lastOrderId = $orderGoodsItem['order_id'];
             // 不同的订单,需要特殊处理
             $rowIndex += 2;
             // 跳过 2 行
         }
         // 输出数据
         //$this->outputDataRow($activeSheet, $rowIndex, $orderGoodsItem, array('goods_name', 'goods_id'));
         $this->outputDataRow($activeSheet, $rowIndex, $orderGoodsItem);
         $rowIndex++;
         // 换行
     }
     $fileName = '订单下载_' . $formQuery['goods_id'] . '_' . Time::gmTimeToLocalTimeStr($payTimeStart, 'Y-m-d_H-i-s') . '__' . Time::gmTimeToLocalTimeStr($payTimeEnd, 'Y-m-d_H-i-s');
     // 输出为 Excel5 格式
     $objWriter = new \PHPExcel_Writer_Excel5($objPHPExcel);
     header('Content-Type: application/vnd.ms-excel');
     if (strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
         header('Content-Disposition: attachment; filename="' . urlencode($fileName) . '.xls"');
     } else {
         header('Content-Disposition: attachment; filename="' . $fileName . '.xls"');
     }
     header('Cache-Control: max-age=0');
     $objWriter->save('php://output');
     //输出到浏览器
     die;
     out_fail:
     // 失败,打印错误消息
     $flashMessageArray = $this->flashMessageArray;
     foreach ($flashMessageArray as $flashMessage) {
         echo $flashMessage . '<br />';
     }
 }
Exemple #4
0
 public function ListOrderGoodsSupplierIdName($f3)
 {
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     //表单查询
     $formQuery = array();
     // 是否这个列表是用于供货商订单结算
     $supplierForSettle = $validator->validate('supplier_for_settle');
     //付款时间
     $payTimeStartStr = $validator->required()->validate('pay_time_start');
     $payTimeStart = Time::gmStrToTime($payTimeStartStr) ?: null;
     $payTimeEndStr = $validator->required()->validate('pay_time_end');
     $payTimeEnd = Time::gmStrToTime($payTimeEndStr) ?: null;
     $formQuery['pay_time'] = array($payTimeStart, $payTimeEnd);
     //额外退款时间
     $extraRefundTimeStartStr = $validator->required()->validate('extra_refund_time_start');
     $extraRefundTimeStart = Time::gmStrToTime($extraRefundTimeStartStr) ?: null;
     $extraRefundTimeEndStr = $validator->required()->validate('extra_refund_time_end');
     $extraRefundTimeEnd = Time::gmStrToTime($extraRefundTimeEndStr) ?: null;
     $formQuery['extra_refund_time'] = array($extraRefundTimeStart, $extraRefundTimeEnd);
     if (!($payTimeStart && $payTimeEnd) && !($extraRefundTimeStart && $extraRefundTimeEnd)) {
         goto out_fail;
     }
     // 取得供货商 id
     $condArray = array();
     $condArray[] = array('oi.order_id = og.order_id');
     // 这个列表是用于供货商订单结算,只取得需要结算的供货商
     if (!empty($supplierForSettle)) {
         //只有付款了订单才显示
         $condArray[] = array('order_goods_status > 0');
         //只有发货了订单才需要结算
         $condArray[] = array('og.shipping_id > 0');
         //商家结算过了就不要显示出来了
         $condArray[] = array('settle_id = 0');
     }
     // 表单查询
     $condArray = array_merge($condArray, QueryBuilder::buildQueryCondArray($formQuery));
     $orderGoodsService = new OrderGoodsService();
     $queryArray = $orderGoodsService->_fetchArray(array('order_info' => 'oi', 'order_goods' => 'og'), 'distinct(og.suppliers_id)', $condArray, array('order' => 'suppliers_id desc'), 0, $f3->get('sysConfig[max_query_record_count]'), 0);
     //最多限制 max_query_record_count 条记录
     // 取得供货商 id 列表
     $supplierIdArray = array();
     foreach ($queryArray as $queryItem) {
         $supplierIdArray[] = $queryItem['suppliers_id'];
     }
     if (empty($supplierIdArray)) {
         // 没有数据,退出
         goto out_fail;
     }
     // 取得供货商信息
     $userSupplierService = new UserSupplierService();
     $queryArray = $userSupplierService->fetchSupplierArrayBySupplierIdArray($supplierIdArray);
     $supplierArray = array();
     foreach ($queryArray as $queryItem) {
         $supplierItem = array();
         $supplierItem['suppliers_id'] = $queryItem['suppliers_id'];
         $supplierItem['suppliers_account'] = $queryItem['suppliers_account'];
         $supplierItem['suppliers_name'] = $queryItem['suppliers_name'];
         $supplierArray[] = $supplierItem;
     }
     // 正常从这里返回
     Ajax::header();
     echo Ajax::buildResult(null, null, $supplierArray);
     return;
     out_fail:
     Ajax::header();
     echo Ajax::buildResult(null, null, array());
 }