Commit 75e480d6 by 肖康

Merge branch 'dev/ver/1.0.0' of http://git.ichunt.net/semour/semour_web into dev/ver/1.0.0

parents 5a56ae7e 3ae16414
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Api; namespace App\Http\Controllers\Api;
use App\Http\ApiHelper\ApiCode;
use App\Http\Requests\UserRegister; use App\Http\Requests\UserRegister;
use App\Http\Services\CartService; use App\Http\Services\CartService;
use App\Http\Services\InquiryService; use App\Http\Services\InquiryService;
...@@ -41,8 +42,8 @@ class OrderApiController extends Controller ...@@ -41,8 +42,8 @@ class OrderApiController extends Controller
'shipping_address_id', 'shipping_address_id',
]); ]);
$result = OrderService::addOrder($data, $request->user->id); $order_id = OrderService::addOrder($data, $request->user->id);
return !$result ? $this->setError('Add order failed , please contact administrator'):$this->setSuccess('Add order success'); return !$order_id ? $this->setError('Add order failed , please contact administrator'):$this->setSuccessData($order_id,0,ApiCode::API_CODE_SUCCESS,'Add order success');
} }
//订单列表 //订单列表
......
...@@ -127,11 +127,26 @@ class OrderService ...@@ -127,11 +127,26 @@ class OrderService
$goods_id = $v['goods_id']; $goods_id = $v['goods_id'];
$skuInfo = $goodsInfoArr[$goods_id]; //sku详情 $skuInfo = $goodsInfoArr[$goods_id]; //sku详情
$cartInfo = CartModel::where(["user_id"=>$user_id,"goods_id"=>(string)$goods_id,"status"=>1])->first(); $cartInfo = CartModel::where(["user_id"=>$user_id,"goods_id"=>(string)$goods_id,"status"=>1])->first();
$buy_number = $v["buy_number"]; $buy_number = $v["buy_number"];
$buy_price = $v["buy_price"]; $buy_price = $v["buy_price"];
$orderAmount += round($buy_number*$buy_price,2); $orderAmount += round($buy_number*$buy_price,2);
$standard_brand = data_get($skuInfo,"standard_brand"); $standard_brand = data_get($skuInfo,"standard_brand");
#查询英文品牌缩写
$brandName = $skuInfo["brand_name"];
$standard_brand_id = \Arr::get($standard_brand,"standard_brand_id",0);
$standardBrandInfo = $redis->hget("standard_brand",$standard_brand_id);
if ($standardBrandInfo){
$standardBrandInfoArr = json_decode($standardBrandInfo,true);
#深贸商城的品牌字段需展示该SKU对应基石标准品牌列表的英文简称,无则取英文名称、都无则取品牌名称
if ($standardBrandInfoArr["brand_short_name_en"]){
$brandName = $standardBrandInfoArr["brand_short_name_en"];
}else if ($standardBrandInfoArr["brand_name_en"]){
$brandName = $standardBrandInfoArr["brand_name_en"];
}
}
//订单明细 //订单明细
$orderItems[] = [ $orderItems[] = [
"order_id"=>$order_id, //订单ID "order_id"=>$order_id, //订单ID
...@@ -139,17 +154,17 @@ class OrderService ...@@ -139,17 +154,17 @@ class OrderService
"goods_id"=>$goods_id, //商品ID "goods_id"=>$goods_id, //商品ID
"supplier_id"=>\Arr::get($skuInfo,"supplier_id",0), //供应商ID(=company_id) "supplier_id"=>\Arr::get($skuInfo,"supplier_id",0), //供应商ID(=company_id)
"brand_id"=>$skuInfo["brand_id"], //品牌ID "brand_id"=>$skuInfo["brand_id"], //品牌ID
"standard_brand_id"=>\Arr::get($standard_brand,"standard_brand_id",0), //标准品牌ID "standard_brand_id"=>$standard_brand_id, //标准品牌ID
"goods_name"=>\Arr::get($skuInfo,"goods_name",0), //型号 "goods_name"=>\Arr::get($skuInfo,"goods_name",0), //型号
"class_id2"=>\Arr::get($skuInfo,"class_id2",0), //商品二级分类id "class_id2"=>\Arr::get($skuInfo,"class_id2",0), //商品二级分类id
"batch"=>\Arr::get($skuInfo,"batch_sn",0), //批次 "batch"=>\Arr::get($skuInfo,"batch_sn",0), //批次
"class_id2_name"=>"", //商品二级分类名称 "class_id2_name"=>"", //商品二级分类名称
"supplier_name"=>\Arr::get($skuInfo,"supplier_name",0), //供应商名(=company_name) "supplier_name"=>\Arr::get($skuInfo,"supplier_name",0), //供应商名(=company_name)
"brand_name"=>\Arr::get($skuInfo,"brand_name",0), //品牌名 "brand_name"=>$brandName, //品牌名
"standard_brand_name"=>\Arr::get($standard_brand,"brand_name",""), //标准品牌 "standard_brand_name"=>\Arr::get($standard_brand,"brand_name",""), //标准品牌
"goods_type"=>2, //商品类型 联营:1专卖 2联营 自营 :3自营 4寄售 5第三方仓库 "goods_type"=>2, //商品类型 联营:1专卖 2联营 自营 :3自营 4寄售 5第三方仓库
"goods_number"=>$buy_number, //购买数量 "goods_number"=>$buy_number, //购买数量
"goods_price"=>\Arr::get($skuInfo,"buy_price",0), //商品单价 "goods_price"=>$buy_price, //商品单价
"goods_unit"=>"pcs", //商品单位 "goods_unit"=>"pcs", //商品单位
"delivery_time"=>\Arr::get($skuInfo,"hk_delivery_time",""), //交货时间 "delivery_time"=>\Arr::get($skuInfo,"hk_delivery_time",""), //交货时间
"canal"=>\Arr::get($skuInfo,"canal",""), //渠道标签 "canal"=>\Arr::get($skuInfo,"canal",""), //渠道标签
...@@ -166,14 +181,15 @@ class OrderService ...@@ -166,14 +181,15 @@ class OrderService
"remarks"=>$v["remark"], //客户备注 "remarks"=>$v["remark"], //客户备注
]; ];
#扣减购物车库存 if ($cartInfo){
$temp["status"] = $v["buy_number"] > 0 ? CartModel::status_yes:CartModel::status_no; #扣减购物车库存
$temp["status"] = $v["buy_number"] > 0 ? CartModel::status_yes:CartModel::status_no;
$temp["create_time"] = time(); $temp["create_time"] = time();
$temp["update_time"] = time(); $temp["update_time"] = time();
$cartUpdate = CartModel::where("cart_id",$cartInfo["cart_id"])->update($temp); $cartUpdate = CartModel::where("cart_id",$cartInfo["cart_id"])->update($temp);
if (!$cartUpdate){ if (!$cartUpdate){
throw new InvalidRequestException("error:update cart"); throw new InvalidRequestException("error:update cart");
}
} }
} }
...@@ -203,7 +219,7 @@ class OrderService ...@@ -203,7 +219,7 @@ class OrderService
$con->commit(); $con->commit();
return true; return $order_id;
}catch (\Exception $e){ }catch (\Exception $e){
$con->rollback(); $con->rollback();
throw new InvalidRequestException($e->getMessage().$e->getFile().$e->getLine()); throw new InvalidRequestException($e->getMessage().$e->getFile().$e->getLine());
...@@ -299,7 +315,7 @@ class OrderService ...@@ -299,7 +315,7 @@ class OrderService
"shipping"=>\Arr::get($priceArr,3,0), //运费 "shipping"=>\Arr::get($priceArr,3,0), //运费
"payment_surcharge"=>\Arr::get($priceArr,5,0), //支付手续费 "payment_surcharge"=>\Arr::get($priceArr,5,0), //支付手续费
"merchandise_total"=>$merchandise_total, //商品总额 "merchandise_total"=>$merchandise_total, //商品总额
"sub_total"=>$v["order_amount"], //小计 "sub_total"=>OrderPriceModel::getOrderSubTotal($order_id), //小计
"create_time"=>date('Y-m-d H:i:s', $v['create_time']), //下单时间 "create_time"=>date('Y-m-d H:i:s', $v['create_time']), //下单时间
"over_time"=> $v["status"] == OrderModel::status_waiting_pay ? date('Y-m-d H:i:s', $v['create_time']+48*3600):"", //截止时间 "over_time"=> $v["status"] == OrderModel::status_waiting_pay ? date('Y-m-d H:i:s', $v['create_time']+48*3600):"", //截止时间
]; ];
...@@ -398,7 +414,7 @@ class OrderService ...@@ -398,7 +414,7 @@ class OrderService
"order_id"=>$order_id, "order_id"=>$order_id,
"order_sn"=>$orderInfo["order_sn"], "order_sn"=>$orderInfo["order_sn"],
"order_amount"=>$orderInfo["order_amount"], "order_amount"=>$orderInfo["order_amount"],
"sub_total"=>$orderInfo["order_amount"], //小计 "sub_total"=>OrderPriceModel::getOrderSubTotal($order_id), //小计
"created_time"=>timeToDate($orderInfo["create_time"]), //创建时间 "created_time"=>timeToDate($orderInfo["create_time"]), //创建时间
"reviewed_time"=>timeToDate($orderInfo["confirm_time"]), //审核时间 "reviewed_time"=>timeToDate($orderInfo["confirm_time"]), //审核时间
"paid_time"=>timeToDate($orderInfo["pay_time"]), //支付时间 "paid_time"=>timeToDate($orderInfo["pay_time"]), //支付时间
......
...@@ -17,5 +17,12 @@ class OrderPriceModel extends Model ...@@ -17,5 +17,12 @@ class OrderPriceModel extends Model
return ($res) ? $res->toArray() : []; return ($res) ? $res->toArray() : [];
} }
//计算订单总金额
public static function getOrderSubTotal($order_id)
{
return self::where("order_id",$order_id)->wherein("price_type",[1,3,5])->sum("price");
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment