Example #1
0
 /**
  * 批量上传快递单号,必须上传配货单
  *
  * @param $f3
  */
 public function Upload($f3)
 {
     $recIdColumnIndex = 5;
     // 子订单 ID 列号
     $shippingIdColumnIndex = 23;
     // 快递公司 ID 列号
     $shippingNoColumnIndex = 24;
     // 快递单号列
     if (empty($_FILES) || !array_key_exists('uploadfile', $_FILES)) {
         $this->addFlashMessage('没有上传文件');
         goto out;
     }
     if ($_FILES['uploadfile']['error'] > 0) {
         $this->addFlashMessage('上传文件错误:' . $_FILES['uploadfile']['error']);
         goto out;
     }
     // 解析上传的文件名
     $pathInfoArray = pathinfo($_FILES['uploadfile']['name']);
     $fileExt = strtolower($pathInfoArray['extension']);
     if ('xls' != $fileExt) {
         $this->addFlashMessage('文件格式错误,必须是 Excel xls 文件');
         goto out;
     }
     $targetFile = $f3->get('TEMP') . time() . $fileExt;
     move_uploaded_file($_FILES['uploadfile']['tmp_name'], $targetFile);
     require_once PROTECTED_PATH . '/Vendor/PHPExcel/Settings.php';
     // 设置Excel缓存,防止数据太多拖死了程序
     \PHPExcel_Settings::setCacheStorageMethod(\PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp);
     try {
         $objPHPExcel = \PHPExcel_IOFactory::load($targetFile);
     } catch (\Exception $e) {
         $this->addFlashMessage('上传的文件格式错误,请注意不要修改批量下载订单文件的格式');
         goto out;
     }
     // 取得快递公司列表
     $expressService = new ExpressService();
     $expressArray = $expressService->fetchExpressArray();
     // 构建 shipping_id --> express 的反查表
     $shippingIdExpressArray = array();
     foreach ($expressArray as $expressItem) {
         $shippingIdExpressArray[$expressItem['meta_id']] = $expressItem;
     }
     unset($expressArray);
     unset($expressService);
     // 释放内存
     $activeSheet = $objPHPExcel->setActiveSheetIndex(0);
     $maxRow = $activeSheet->getHighestRow();
     $expressSetCount = 0;
     // 成功设置计数
     // 当前登录用户
     $authSupplierUser = AuthHelper::getAuthUser();
     $orderBasicService = new OrderBasicService();
     // 一行一行的读取数据
     for ($currentRow = 1; $currentRow <= $maxRow; $currentRow++) {
         // 取得子订单 ID
         $recIdStr = trim($activeSheet->getCellByColumnAndRow($recIdColumnIndex, $currentRow)->getValue());
         if (!ctype_digit($recIdStr)) {
             // 如果不全是数字,说明这列不对
             continue;
         }
         $orderGoods = $orderBasicService->loadOrderGoodsById(intval($recIdStr));
         if ($orderGoods->isEmpty() || OrderGoodsService::OGS_PAY != $orderGoods->order_goods_status || $orderGoods['suppliers_id'] != $authSupplierUser['suppliers_id']) {
             $this->addFlashMessage('子订单[' . $recIdStr . ']非法');
             continue;
         }
         //取得快递公司 ID 设置
         $shippingIdStr = trim($activeSheet->getCellByColumnAndRow($shippingIdColumnIndex, $currentRow)->getValue());
         if (!ctype_digit($shippingIdStr) || intval($shippingIdStr) <= 0) {
             $this->addFlashMessage('子订单[' . $recIdStr . '] 对应的 快递ID 错误');
             continue;
         }
         $shipping_id = intval($shippingIdStr);
         if (!isset($shippingIdExpressArray[$shipping_id])) {
             $this->addFlashMessage('子订单[' . $recIdStr . '] 对应的 快递ID[' . $shipping_id . '] 非法');
             continue;
         }
         if ($orderGoods->shipping_id > 0) {
             $this->addFlashMessage('子订单[' . $recIdStr . '] 覆盖了之前已有的快递信息 [' . $orderGoods->shipping_name . ':' . $orderGoods->shipping_no . ']');
         }
         //取得快递单号
         $shippingNoStr = trim($activeSheet->getCellByColumnAndRow($shippingNoColumnIndex, $currentRow)->getValue());
         //设置快递信息
         $orderGoods->shipping_id = $shipping_id;
         $orderGoods->shipping_name = $shippingIdExpressArray[$shipping_id]['meta_name'];
         $orderGoods->shipping_no = $shippingNoStr;
         $orderGoods->save();
         $expressSetCount++;
         // 更新 order_info 的 update_time 字段
         $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id'], 1);
         //缓存1秒
         $orderInfo->update_time = Time::gmTime();
         $orderInfo->save();
         // 添加订单操作日志
         $action_note = '' . $shipping_id . ',' . $shippingIdExpressArray[$shipping_id]['meta_name'] . ',' . $shippingNoStr;
         $orderActionService = new OrderActionService();
         $orderActionService->logOrderAction($orderGoods['order_id'], $orderGoods['rec_id'], $orderInfo['order_status'], $orderInfo['pay_status'], $orderGoods['order_goods_status'], $action_note, '供货商:[' . $authSupplierUser['suppliers_id'] . ']' . $authSupplierUser['suppliers_name'], 0, $orderInfo['shipping_status']);
     }
     $this->addFlashMessage('一共更新了 ' . $expressSetCount . ' 个快递信息');
     out:
     // 删除上传文件
     if (!empty($targetFile)) {
         @unlink($targetFile);
     }
     // 回到批量下载界面
     RouteHelper::reRoute($this, '/Order/Excel');
 }
Example #2
0
 /**
  * 设置订单的信息,注意:这个方法里面糅合了很多功能,通过 action="xxxx" 来区分
  *
  * @param $f3
  */
 public function Update($f3)
 {
     // 验证 action
     $validator = new Validator($f3->get('GET'));
     $action = $validator->required()->oneOf(array('set_extra_discount', 'set_suppliers_price', 'set_shipping_no', 'set_memo', 'set_refund', 'set_extra_refund'), '非法操作')->validate('action');
     if (!$this->validate($validator)) {
         goto out;
     }
     // 验证提交上来的参数
     $validator = new Validator($f3->get('POST'));
     $updateValueArray = array();
     $rec_id = $validator->required()->digits()->min(1)->validate('rec_id');
     // 针对不同的 action  做不同的验证
     switch ($action) {
         case 'set_extra_discount':
             // 权限检查
             $this->requirePrivilege('manage_order_goods_update_set_extra_discount');
             $updateValueArray['extra_discount'] = Money::toStorage($validator->validate('extra_discount'));
             $updateValueArray['extra_discount_note'] = $validator->required()->validate('extra_discount_note');
             break;
         case 'set_suppliers_price':
             // 权限检查
             $this->requirePrivilege('manage_order_goods_update_set_suppliers_price');
             $updateValueArray['suppliers_price'] = Money::toStorage($validator->validate('suppliers_price'));
             $updateValueArray['suppliers_shipping_fee'] = Money::toStorage($validator->validate('suppliers_shipping_fee'));
             break;
         case 'set_shipping_no':
             // 权限检查
             $this->requirePrivilege('manage_order_goods_update_set_shipping_no');
             $updateValueArray['shipping_id'] = $validator->digits()->min(1)->validate('shipping_id');
             $updateValueArray['shipping_no'] = $validator->validate('shipping_no');
             break;
         case 'set_memo':
             // 权限检查
             $this->requirePrivilege('manage_order_goods_update_set_memo');
             $updateValueArray['memo'] = $validator->validate('memo');
             break;
         case 'set_refund':
             // 权限检查
             $this->requirePrivilege('manage_order_goods_update_set_refund');
             $updateValueArray['refund'] = Money::toStorage($validator->validate('refund'));
             $updateValueArray['refund_note'] = $validator->required()->validate('refund_note');
             $updateValueArray['refund_time'] = Time::gmTime();
             $updateValueArray['suppliers_refund'] = Money::toStorage($validator->validate('suppliers_refund'));
             $updateValueArray['suppliers_refund_note'] = $validator->required()->validate('suppliers_refund_note');
             break;
         case 'set_extra_refund':
             // 权限检查
             $this->requirePrivilege('manage_order_goods_update_set_extra_refund');
             $updateValueArray['extra_refund'] = Money::toStorage($validator->validate('extra_refund'));
             $updateValueArray['extra_refund_note'] = $validator->required()->validate('extra_refund_note');
             $updateValueArray['extra_refund_time'] = Time::gmTime();
             break;
         default:
             // 非法的 action
             goto out;
     }
     if (!$this->validate($validator)) {
         goto out;
     }
     // 取 order_goods
     $orderBasicService = new OrderBasicService();
     $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id);
     if ($orderGoods->isEmpty()) {
         $this->addFlashMessage('非法订单');
         goto out_fail;
     }
     // 取得 orderInfo
     $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id']);
     // 针对不同的 action  做额外不同的工作
     $action_note = '';
     switch ($action) {
         case 'set_extra_discount':
             // 商品只有是未付款状态才可以设置额外优惠
             if (OrderGoodsService::OGS_UNPAY != $orderGoods['order_goods_status']) {
                 $this->addFlashMessage('只有未付款订单才可以给予额外优惠');
                 goto out;
             }
             // 额外优惠允许的最大金额
             $allowExtraDiscount = $orderGoods['goods_price'] + $orderGoods['shipping_fee'] - $orderGoods['discount'];
             $maxExtraDiscount = intval($allowExtraDiscount * $f3->get('sysConfig[max_order_goods_extra_discount_rate]'));
             $maxExtraDiscount = max($maxExtraDiscount, $f3->get('sysConfig[max_order_goods_extra_discount_value]'));
             $maxExtraDiscount = min($maxExtraDiscount, $allowExtraDiscount);
             // 额外优惠不能超过商品本身的金额
             if ($updateValueArray['extra_discount'] > $maxExtraDiscount) {
                 $this->addFlashMessage('额外优惠不能超过商品总金额 ' . $maxExtraDiscount);
                 goto out;
             }
             // 设置额外余额,需要重新计算 order_info 中的值
             $diffDiscount = 0;
             if ($orderGoods->extra_discount != $updateValueArray['extra_discount']) {
                 $diffDiscount = $updateValueArray['extra_discount'] - $orderGoods->extra_discount;
             }
             $orderInfo->extra_discount += $diffDiscount;
             $orderInfo->order_amount -= $diffDiscount;
             $action_note .= '额外优惠:' . Money::toSmartyDisplay($updateValueArray['extra_discount']) . ",";
             $action_note .= '优惠说明:' . $updateValueArray['extra_discount_note'] . "\n";
             break;
         case 'set_suppliers_price':
             $action_note .= '供货价:' . Money::toSmartyDisplay($updateValueArray['suppliers_price']) . ",";
             $action_note .= '供货快递费:' . Money::toSmartyDisplay($updateValueArray['suppliers_shipping_fee']) . "\n";
             break;
         case 'set_shipping_no':
             if ($updateValueArray['shipping_id'] > 0) {
                 //取得快递信息
                 $expressService = new ExpressService();
                 $expressInfo = $expressService->loadMetaById($updateValueArray['shipping_id']);
                 if ($expressInfo->isEmpty() || ExpressService::META_TYPE != $expressInfo['meta_type']) {
                     $this->addFlashMessage('快递ID非法');
                     goto out;
                 }
                 $updateValueArray['shipping_name'] = $expressInfo['meta_name'];
             } else {
                 $updateValueArray['shipping_name'] = null;
             }
             $action_note .= '快递公司:' . $updateValueArray['shipping_name'] . "\n";
             $action_note .= '快递单号:' . $updateValueArray['shipping_no'] . "\n";
             break;
         case 'set_memo':
             $action_note .= '客服备注:' . $updateValueArray['memo'] . "\n";
             break;
         case 'set_refund':
             // 检查订单状态
             if (!in_array($orderGoods['order_goods_status'], array(OrderGoodsService::OGS_PAY, OrderGoodsService::OGS_ASKREFUND))) {
                 $this->addFlashMessage('订单状态非法,不能退款');
                 goto out;
             }
             if ($orderGoods['settle_id'] > 0) {
                 $this->addFlashMessage('已经结算的订单不能退款');
                 goto out;
             }
             // 订单设置为 申请退款
             $updateValueArray['order_goods_status'] = OrderGoodsService::OGS_ASKREFUND;
             // 同步更新 order_info 中的 refund 字段
             $diffRefund = 0;
             if ($orderGoods->refund != $updateValueArray['refund']) {
                 $diffRefund = $updateValueArray['refund'] - $orderGoods->refund;
             }
             $orderInfo->refund += $diffRefund;
             // 检查金额,对一些常见错误提出警告
             if (0 == $updateValueArray['refund']) {
                 $this->addFlashMessage('警告:你确定给顾客退款金额设置为 ' . Money::toSmartyDisplay($updateValueArray['refund']) . ' ?');
             }
             if (0 == $updateValueArray['suppliers_refund']) {
                 $this->addFlashMessage('警告:你确定供货商给我们退款金额为 ' . Money::toSmartyDisplay($updateValueArray['refund']) . ' ?');
             }
             if ($updateValueArray['refund'] <= $updateValueArray['suppliers_refund']) {
                 $this->addFlashMessage('警告:给顾客退款金额 &lt;= 供货商给我们的退款金额');
             }
             // 日志信息记录
             $action_note .= '申请退款' . "\n";
             $action_note .= '顾客金额:' . Money::toSmartyDisplay($updateValueArray['refund']) . ",";
             $action_note .= '顾客说明:' . $updateValueArray['refund_note'] . "\n";
             $action_note .= '供货商金额:' . Money::toSmartyDisplay($updateValueArray['suppliers_refund']) . ",";
             $action_note .= '供货商说明:' . $updateValueArray['suppliers_refund_note'] . "\n";
             break;
         case 'set_extra_refund':
             // 检查订单状态
             if (OrderGoodsService::OGS_UNPAY == $orderGoods['order_goods_status']) {
                 $this->addFlashMessage('订单状态非法,不能退款');
                 goto out;
             }
             $action_note .= '额外退款:' . Money::toSmartyDisplay($updateValueArray['extra_refund']) . ",";
             $action_note .= '退款说明:' . $updateValueArray['extra_refund_note'] . "\n";
             break;
         default:
             // 非法的 action
             goto out;
     }
     // 更新订单信息
     $orderGoods->copyFrom($updateValueArray);
     $orderGoods->update_time = Time::gmTime();
     $orderGoods->save();
     // 更新 order_info 的 update_time 字段
     $orderInfo->update_time = Time::gmTime();
     $orderInfo->save();
     // 添加订单操作日志
     $authAdminUser = AuthHelper::getAuthUser();
     $orderActionService = new OrderActionService();
     $orderActionService->logOrderAction($orderGoods['order_id'], $orderGoods['rec_id'], $orderInfo['order_status'], $orderInfo['pay_status'], $orderGoods['order_goods_status'], $action_note, $authAdminUser['user_name'], 0, $orderInfo['shipping_status']);
     $this->addFlashMessage('订单信息保存成功');
     out:
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Order/Goods/Detail', array('rec_id' => $rec_id), true));
     return;
     out_fail:
     // 失败从这里退出
     RouteHelper::reRoute($this, '/Order/Goods/Search', false);
 }
Example #3
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);
     }
 }
Example #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;
 }
Example #5
0
 /**
  * 设置订单为 退款中 状态
  *
  * 即:确认已经收到用户的退货了,告知财务这个订单可以给用户退款了
  *
  * @param $f3
  */
 public function SetRefund($f3)
 {
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $rec_id = $validator->required()->digits()->min(1)->validate('rec_id');
     if (!$this->validate($validator)) {
         goto out;
     }
     // 取得当前供货商
     $authSupplierUser = AuthHelper::getAuthUser();
     $orderBasicService = new OrderBasicService();
     $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id);
     if ($orderGoods->isEmpty() || OrderGoodsService::OGS_ASKREFUND != $orderGoods->order_goods_status || $orderGoods['suppliers_id'] != $authSupplierUser['suppliers_id']) {
         $this->addFlashMessage('订单ID非法');
         goto out;
     }
     $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id']);
     if ($orderInfo->isEmpty() || $orderInfo->pay_status != OrderBasicService::PS_PAYED) {
         $this->addFlashMessage('订单ID非法');
         goto out;
     }
     // 设置订单状态为  退款中
     $orderGoods->order_goods_status = OrderGoodsService::OGS_REFUNDING;
     $orderGoods->save();
     // 更新 order_info 的 update_time 字段
     $orderInfo->update_time = Time::gmTime();
     $orderInfo->save();
     $action_note = '设置为退款中' . "\n";
     $action_note .= '操作人:[' . $authSupplierUser['suppliers_id'] . ']' . $authSupplierUser['suppliers_name'] . "\n";
     // 添加订单操作日志
     $orderActionService = new OrderActionService();
     $orderActionService->logOrderAction($orderGoods['order_id'], $orderGoods['rec_id'], $orderInfo['order_status'], $orderInfo['pay_status'], $orderGoods['order_goods_status'], $action_note, $authSupplierUser['suppliers_name'], 0, $orderInfo['shipping_status']);
     $this->addFlashMessage('订单状态设置为[退款中]');
     out:
     RouteHelper::reRoute($this, RouteHelper::getRefer(), false);
 }
Example #6
0
 /**
  * 设置订单的快递信息
  *
  * @param $f3
  */
 public function ajaxUpdate($f3)
 {
     // 参数验证
     $validator = new Validator($f3->get('POST'));
     $rec_id = $validator->required('子订单ID不能为空')->digits('子订单ID必须是数字')->min(1)->validate('rec_id');
     $shipping_id = $validator->digits('快递ID必须是数字')->min(1)->validate('shipping_id');
     $shipping_no = $validator->validate('shipping_no');
     if (!$this->validate($validator)) {
         goto out_fail;
     }
     // 取 order_goods
     $orderBasicService = new OrderBasicService();
     $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id);
     if ($orderGoods->isEmpty()) {
         $this->addFlashMessage('非法订单');
         goto out_fail;
     }
     // 权限检查
     $authSupplierUser = AuthHelper::getAuthUser();
     if ($orderGoods['suppliers_id'] !== $authSupplierUser['suppliers_id']) {
         $this->addFlashMessage('非法订单');
         goto out_fail;
     }
     // 取得快递名
     if ($shipping_id > 0) {
         //取得快递信息
         $expressService = new ExpressService();
         $expressInfo = $expressService->loadMetaById($shipping_id);
         if ($expressInfo->isEmpty() || ExpressService::META_TYPE != $expressInfo['meta_type']) {
             $this->addFlashMessage('快递ID非法');
             goto out_fail;
         }
         $shipping_name = $expressInfo['meta_name'];
     } else {
         $shipping_name = null;
     }
     // 更新快递信息
     $orderGoods->shipping_id = $shipping_id;
     $orderGoods->shipping_name = $shipping_name;
     $orderGoods->shipping_no = $shipping_no;
     $orderGoods->save();
     // 更新 order_info 的 update_time 字段
     $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id']);
     $orderInfo->update_time = Time::gmTime();
     $orderInfo->save();
     // 添加订单操作日志
     if ($shipping_id > 0) {
         $action_note = '' . $shipping_id . ',' . $shipping_name . ',' . $shipping_no;
     } else {
         $action_note = '删除快递信息';
     }
     $orderActionService = new OrderActionService();
     $orderActionService->logOrderAction($orderGoods['order_id'], $orderGoods['rec_id'], $orderInfo['order_status'], $orderInfo['pay_status'], $orderGoods['order_goods_status'], $action_note, '供货商:[' . $authSupplierUser['suppliers_id'] . ']' . $authSupplierUser['suppliers_name'], 0, $orderInfo['shipping_status']);
     Ajax::header();
     echo Ajax::buildResult(null, null, null);
     return;
     // 成功从这里返回
     out_fail:
     // 失败从这里退出
     Ajax::header();
     $errorMessage = '';
     foreach ($this->flashMessageArray as $messageItem) {
         $errorMessage .= $messageItem . ',';
     }
     echo Ajax::buildResult(-1, $errorMessage, null);
 }
Example #7
0
 /**
  * 拒绝退款请求
  *
  * @param $f3
  */
 public function Refuse($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_order_refund_confirm');
     // 参数验证
     $validator = new Validator($f3->get('POST'));
     $rec_id = $validator->required()->digits()->min(1)->validate('rec_id');
     $refund_finish_note = $validator->required()->validate('refund_finish_note');
     if (!$this->validate($validator)) {
         goto out;
     }
     $orderBasicService = new OrderBasicService();
     $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id);
     if ($orderGoods->isEmpty() || OrderGoodsService::OGS_REFUNDING != $orderGoods->order_goods_status) {
         $this->addFlashMessage('订单ID非法');
         goto out;
     }
     $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id']);
     if ($orderInfo->isEmpty() || $orderInfo->pay_status != OrderBasicService::PS_PAYED) {
         $this->addFlashMessage('订单ID非法');
         goto out;
     }
     // 标记订单为 付款
     $orderGoods->order_goods_status = OrderGoodsService::OGS_PAY;
     // 清除退款记录
     $orderGoods->refund = 0;
     // 我们给顾客退款
     $orderGoods->refund_time = 0;
     $orderGoods->refund_finish_time = Time::gmTime();
     $orderGoods->refund_finish_note = $refund_finish_note;
     $orderGoods->suppliers_refund = 0;
     // 供货商给我们退款
     $orderGoods->save();
     // 更新 order_info 的 update_time 字段
     $orderInfo->update_time = Time::gmTime();
     $orderInfo->save();
     $authAdminUser = AuthHelper::getAuthUser();
     $action_note = '拒绝退款' . "\n";
     $action_note .= '操作人:[' . $authAdminUser['user_id'] . ']' . $authAdminUser['user_name'] . "\n";
     $action_note .= '备注:' . $refund_finish_note . "\n";
     // 添加订单操作日志
     $orderActionService = new OrderActionService();
     $orderActionService->logOrderAction($orderGoods['order_id'], $orderGoods['rec_id'], $orderInfo['order_status'], $orderInfo['pay_status'], $orderGoods['order_goods_status'], $action_note, $authAdminUser['user_name'], 0, $orderInfo['shipping_status']);
     $this->addFlashMessage('拒绝退款成功');
     out:
     RouteHelper::reRoute($this, RouteHelper::getRefer(), false);
 }