public function Edit($f3) { // 权限检查 $this->requirePrivilege('manage_goods_comment_edit'); global $smarty; // 参数验证 $validator = new Validator($f3->get('GET')); $comment_id = $validator->digits()->min(1)->validate('comment_id'); if (!$comment_id) { $comment_id = 0; } $goodsCommentService = new GoodsCommentService(); $goodsComment = $goodsCommentService->loadGoodsCommentById($comment_id); if (!$f3->get('POST')) { // 没有 post ,只是普通的显示 goto out_display; } // 新建商品评论 if (0 == $comment_id) { $this->requirePrivilege('manage_goods_comment_create'); $goodsComment->create_time = Time::gmTime(); $goodsComment->comment_time = Time::gmTime(); } unset($validator); $validator = new Validator($f3->get('POST')); $goodsComment->goods_id = $validator->digits()->filter('ValidatorIntValue')->validate('goods_id'); $goodsComment->goods_price = Money::toStorage($validator->validate('goods_price')); $goodsComment->goods_number = $validator->required()->digits()->filter('ValidatorIntValue')->validate('goods_number'); $goodsComment->goods_attr = $validator->validate('goods_attr'); $goodsComment->is_show = $validator->digits()->filter('ValidatorIntValue')->validate('is_show'); $goodsComment->user_name = $validator->required()->validate('user_name'); $goodsComment->comment_time = Time::gmStrToTime($validator->required()->validate('comment_time')); $goodsComment->comment = $validator->validate('comment'); $goodsComment->comment_rate = $validator->digits()->filter('ValidatorIntValue')->validate('comment_rate'); $goodsComment->reply = $validator->validate('reply'); if (!$this->validate($validator)) { goto out_display; } if (!empty($goodsComment->reply)) { $goodsComment->reply_time = Time::gmTime(); } // 更新管理员信息 $authAdminUser = AuthHelper::getAuthUser(); $goodsComment->admin_user_id = $authAdminUser['user_id']; $goodsComment->admin_user_name = $authAdminUser['user_name']; $goodsComment->save(); if (0 == $comment_id) { $this->addFlashMessage('新建商品评论成功'); } else { $this->addFlashMessage('更新商品评论成功'); } out_display: //给 smarty 模板赋值 $smarty->assign($goodsComment->toArray()); $smarty->display('goods_comment_edit.tpl'); return; out_fail: // 失败从这里退出 RouteHelper::reRoute($this, '/Goods/Comment/ListComment'); }
/** * 标记 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(); } } }