下面定位到这$orderGoodsResult =(new OrderGoodsModel())->saveAll($newResult);就一直加不进去数据
来源:12-7 利用MySQL事务创建订单-支持减库存操作
qq_醉生梦死_16
2020-07-15
控制层:public function save() {
$addressId = input(“param.address_id”, 0, “intval”);
ids=input("param.ids","","trim");if(!ids = input("param.ids", "", "trim");
if(!ids=input("param.ids","","trim");if(!ids) {
// 参数适配
KaTeX parse error: Expected 'EOF', got '}' at position 52: …rim");
}̲
if(!addressId || !$ids) {
return Show::error(“参数错误”);
}
$data = [
"ids" => $ids,
"address_id" => $addressId,
"user_id" => $this->userId,
];
try {
$result = (new Order())->save($data);
}catch (\Exception $e) {
return Show::error($e->getMessage());
}
if(!$result) {
return Show::error("提交订单失败,请稍候重试");
}
return Show::success($result);
}
bis层: public function save($data){
//拿到一个订单号
$workId = rand(1,1023);
orderId=Snowflake::getInstance()−>setWorkId(orderId = Snowflake::getInstance()->setWorkId(orderId=Snowflake::getInstance()−>setWorkId(workId)->id();
//获取购物车数据, =》 redis
$cartObj = new Cart();
$result = $cartObj->lists($data['user_id'],$data['ids']);
if(!$result){
return false;
}
$newResult = array_map(function ($v) use($orderId){
$v['sku_id'] = $v['id'];
unset($v['id']);
$v['order_id'] = $orderId;
return $v;
},$result);
dump($newResult);
$price = array_sum(array_column($result,"total_price"));
$orderData =[
"user_id" => $data['user_id'],
"order_id" => $orderId,
"total_price" => $price,
"address_id" => $data['address_id'],
];
$this->model->startTrans();
try{
//新增 order
$id = $this->add($orderData);
if(!$id){
return 0;
}
//新增order_goods
echo 0;
$orderGoodsResult =(new OrderGoodsModel())->saveAll($newResult);
echo 1;
dump($orderGoodsResult);
//goods_sku 更新
$skuRes = (new GoodsSku())->updateStock($result);
echo 2;
dump($skuRes);
//goods 更新
//删除购物车里面所有的商品
$this->model->commit();
return true;
}catch (\Exception $e){
$this->model->rollback();
return false;
}
}
输出一直是这样的:0{“status”:0,“message”:“提交订单失败,请稍候重试”,“result”:[]}
2回答
-
qq_醉生梦死_16
提问者
2020-07-16
知道了,怎样这个错误记录添加到日志文件里面
012020-07-16 -
keryz
2020-07-15
你好,同学,你这样,看看有没有什么错误信息?
try {
//代码
} catch (\Exception $e) {
echo $e->getMessage();die;
}------ 来自singwa助教
022020-07-15
相似问题