/** * 更新订单商品接口 * 单价,数量,总价 */ public function updateGoods($order_id, $goods_id) { $oid = (int) $order_id; $gid = (int) $goods_id; if ($oid <= 0 || $gid <= 0) { $this->error('参数非法'); } $model = new OrderGoodsModel(); $data = I('post.'); if (false === $model->myUpdate($data)) { $this->error($model->getError()); } $this->success('更新成功', cookie(C('CURRENT_URL_NAME'))); }
/** * 删除订单内的某个商品 * @param int $order_id * @param int $goods_id * @return boolean */ public function delGoods($order_id, $goods_id) { // 检测订单是否存在 $order = $this->where('`id`=' . $order_id)->find(); if (empty($order)) { $this->error = '订单不存在'; return false; } $this->startTrans(); $og_M = new OrderGoodsModel(); $new_amount = $og_M->myDel($order_id, $goods_id); if (false === $new_amount) { $this->error = '订单的总价计算错误'; $this->rollback(); return false; } if (false === $this->where('id=' . $order_id)->setField('amount', $new_amount)) { $this->error = '订单的总价更新失败'; $this->rollback(); return false; } $this->commit(); return true; }