示例#1
0
 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');
 }
示例#2
0
 /**
  * 订单商品评价
  *
  * @param $f3
  */
 public function GoodsComment($f3)
 {
     global $smarty;
     $errorMessage = '';
     // 参数验证
     $validator = new Validator($f3->get('GET'));
     $rec_id = $validator->required()->digits()->min(1)->validate('rec_id');
     if (!$this->validate($validator)) {
         $errorMessage = '订单ID非法';
         goto out_fail;
     }
     $orderBasicService = new OrderBasicService();
     // 查询 order_goods
     $orderGoods = $orderBasicService->loadOrderGoodsById($rec_id, 10);
     // 缓存 10 秒钟
     if ($orderGoods->isEmpty()) {
         $errorMessage = '订单ID非法';
         goto out_fail;
     }
     // 查询 order_info
     $orderInfo = $orderBasicService->loadOrderInfoById($orderGoods['order_id'], 10);
     // 缓存 10 秒钟
     // 权限检查,用户只能查看自己的订单
     $userInfo = AuthHelper::getAuthUser();
     if ($orderInfo->isEmpty() || $userInfo['user_id'] != $orderInfo['user_id'] || !$this->verifyOrderSystem($orderInfo)) {
         $errorMessage = '订单ID非法';
         goto out_fail;
     }
     // 加载订单评论
     $goodsCommentService = new GoodsCommentService();
     $goodsComment = $goodsCommentService->loadGoodsCommentByOrderGoodsRecId($rec_id, 1);
     // 缓存1秒
     if ($goodsComment->isEmpty() || $goodsComment['user_id'] != $userInfo['user_id']) {
         $errorMessage = '无法评论此订单';
         goto out_fail;
     }
     // post 请求
     if (Request::isRequestPost()) {
         goto do_post;
     }
     // 赋值评论信息
     $smarty->assign('goodsComment', $goodsComment->toArray());
     out_fail:
     // GET 从这里退出
     $smarty->assign('errorMessage', $errorMessage);
     $smarty->display('my_order_goodscomment.tpl');
     return;
     do_post:
     // 这里处理 post 请求
     // 用户评论缺省不显示,需要等管理员审核通过才能显示
     $goodsComment->is_show = 0;
     $goodsComment->comment_time = Time::gmTime();
     // 过滤用户提交的数据
     unset($validator);
     $validator = new Validator($f3->get('POST'));
     $goodsComment->comment_rate = $validator->filter('ValidatorIntValue')->validate('comment_rate');
     $goodsComment->comment = $validator->validate('comment');
     $goodsComment->save();
     $this->addFlashMessage('评论发表成功,请等待管理员审核通过才能显示');
     // 回到前面的页面
     RouteHelper::reRoute($this, RouteHelper::getRefer(), false);
 }
示例#3
0
 /**
  * 标记 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();
         }
     }
 }