Beispiel #1
0
 /**
  * 更新或者新建一个快递公司
  *
  * @param $f3
  */
 public function Edit($f3)
 {
     // 权限检查
     $this->requirePrivilege('manage_misc_express_edit');
     global $smarty;
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $meta_id = $validator->digits()->validate('meta_id');
     $meta_id = $meta_id ?: 0;
     //  加载 快递信息
     $expressService = new ExpressService();
     $expressInfo = $expressService->loadMetaById($meta_id);
     if (Request::isRequestGet()) {
         goto out_assign;
     }
     // 安全性检查
     if ($meta_id > 0) {
         if ($expressInfo->isEmpty() || ExpressService::META_TYPE != $expressInfo->meta_type) {
             $this->addFlashMessage('非法ID[' . $meta_id . ']');
             goto out;
         }
     }
     unset($validator);
     $validator = new Validator($f3->get('POST'));
     $inputArray = array();
     $inputArray['meta_type'] = ExpressService::META_TYPE;
     $inputArray['meta_name'] = $validator->required()->validate('meta_name');
     $inputArray['meta_ename'] = $validator->required()->validate('meta_ename');
     $inputArray['meta_sort_order'] = $validator->digits()->validate('meta_sort_order');
     $inputArray['meta_status'] = $validator->digits()->validate('meta_status');
     $inputArray['meta_desc'] = $validator->validate('meta_desc');
     if (!$this->validate($validator)) {
         goto out;
     }
     // 保存
     $expressInfo->copyFrom($inputArray);
     $expressInfo->save();
     $this->addFlashMessage('快递信息保存成功');
     // POST 成功从这里退出
     RouteHelper::reRoute($this, RouteHelper::makeUrl('/Misc/Express/Edit', array('meta_id' => $expressInfo->meta_id), true));
     return;
     out_assign:
     $smarty->assign($expressInfo->toArray());
     out:
     $smarty->display('misc_express_edit.tpl');
 }
Beispiel #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);
 }
Beispiel #3
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);
 }