1.本地生活支付新增订单接口

This commit is contained in:
xucong 2024-09-16 15:40:03 +08:00
parent db14e7596f
commit 75c48275c9
2 changed files with 52 additions and 0 deletions

@ -273,4 +273,20 @@ class LocalStore extends Api
$data = LocalStoreLogic::record($page, $size, $this->user_id);
return JsonServer::success('查询成功', $data);
}
//下单购买商品
public function submitLocalOrder(){
$post = $this->request->post();
$user_id = $this->user_id;
$data = LocalStoreLogic::submitOrder($post,$user_id);
if($data === -1){
return JsonServer::success('库存不足');
}
return JsonServer::success('下单成功', $data);
}
// 订单详情
public function localOrderDetails(){
$post = $this->request->post();
$data = LocalStoreLogic::orderDetails($post);
return JsonServer::success('查询成功', $data);
}
}

@ -153,4 +153,40 @@ class LocalStoreLogic extends Logic
'more' => $more,
];
}
public function submitOrder($post,$user_id){
$goods_msg = Db::name("local_store_goods")->where("id",$post['goods_id'])->find();
if($goods_msg['is_multiple_spec']>0){
$goods_sku_msg = Db::name("local_store_goods_item")->where("id",$post['item_id'])->find();
if($goods_sku_msg['stock']<$post['goods_num']){
return -1;
}
$data['goods_total_price'] = round($goods_sku_msg['price']*$post['goods_num'],2);
Db::name("local_store_goods_item")
->where("id",$post['item_id'])
->dec("stock",$post['goods_num'])
->update();
}else{
$data['goods_total_price'] = round($goods_msg['price']*$post['goods_num'],2);
}
$data['lstore_id'] = $post['lstore_id'];
$data['goods_id'] = $post['goods_id'];
$data['goods_num'] = $post['goods_num'];
$data['user_id'] = $user_id;
$data['dtime'] = date("Y-m-d H:i:s");
$res = Db::name("local_goods_order")->insertGetId($data);
$result['lsg_order_id'] = $res;
return $result;
}
public function orderDetails($post){
$result = Db::name("local_goods_order")->where("lsg_order_id",$post['lsg_order_id'])->find();
$goods = Db::name("local_store_goods")->where("id",$result['goods_id'])->find();
$result['goods_msg'] = $goods;
$item = Db::name("local_store_goods_item")->where("id",$result['item_id'])->find();
$result['sku_msg'] = $item;
$local = Db::name("local_store")->field("shopName,shopLogo")->where("lstore_id",$result['lstore_id'])->find();
$result['local_msg'] = $local;
return $result;
}
}