Commit 74e7f2b5 by 孙龙

订单相关

parent 1bf66c33
......@@ -83,7 +83,12 @@ class OrderApiController extends BaseController
}
return response()->json(["code"=>0,"msg"=>"ok","data"=>["list"=>$orderInfo["orderItemList"]],"count"=>count($orderInfo["orderItemList"] )]);
return response()->json(["code"=>0,"msg"=>"ok","data"=>[
"list"=>$orderInfo["orderItemList"],
"order_amount"=>decimal_number_format_usd($orderInfo["order_amount"]),
"return_order_amount"=>decimal_number_format_usd($orderInfo["order_amount"]),
],"count"=>count($orderInfo["orderItemList"] )]);
}
......@@ -116,13 +121,22 @@ class OrderApiController extends BaseController
$params = $request->all();
$order_id = arrayGet($params,"order_id",0,"intval");
$orderItems = arrayGet($params,"order_items","","trim");
$order_remark = arrayGet($params,"order_remark","","trim");
$validator = Validator::make($params, [
'order_id' => 'required',
'order_items.*.order_items_id' => 'required',
'order_items.*.goods_price' => 'required|gt:0',
'order_items.*.goods_number' => 'required|gt:0',
'order_items.*.return_goods_price' => 'gt:0',
'order_items.*.return_goods_number' => 'gt:0',
'order_items' => 'required',
], [
'order_id.required' => admin_trans("order.validator.order_id_required"),
'order_items.required' => admin_trans("order.validator.order_items_required"),
'order_items.*.goods_price.gt' => admin_trans("order.validator.goods_price.gt"),
'order_items.*.goods_number.gt' => admin_trans("order.validator.goods_number.gt"),
'order_items.*.return_goods_price.gt' => admin_trans("order.validator.return_goods_price.gt"),
'order_items.*.return_goods_number.gt' => admin_trans("order.validator.return_goods_number.gt"),
], [
// 'order_id' => '订单id',
......@@ -134,9 +148,46 @@ class OrderApiController extends BaseController
throw new InvalidRequestException($err_msg);
}
OrderService::editOrderItems($order_id,$orderItems);
OrderService::editOrderItems($order_id,$orderItems,$order_remark);
return $this->setSuccess();
}
public function editOrderAdress(Request $request){
$reqParams = $request->all();
$validator = Validator::make($reqParams, [
'order_id' => 'required',
'order_address_type' => 'required',
], [
'order_id.required' => admin_trans("order.validator.order_id_required"),
'order_address_type.required' => admin_trans("order.validator.order_address.required"),
], []);
if ($validator->fails()) {
$errors = $validator->errors()->toArray();
$err_msg = ValidatorMsg::getMsg($errors);
throw new InvalidRequestException($err_msg);
}
$order_id = arrayGet($reqParams,"order_id",0,"intval");
$data["order_address_type"] = arrayGet($reqParams,"order_address_type",0,"intval");
$data["shipping_name"] = arrayGet($reqParams,"shipping_name","","trim");
$data["shipping_sn"] = arrayGet($reqParams,"shipping_sn","","trim");
$data["consignee"] = arrayGet($reqParams,"consignee","","trim");
$data["company_name"] = arrayGet($reqParams,"company_name","","trim");
$data["email"] = arrayGet($reqParams,"email","","trim");
$data["phone"] = arrayGet($reqParams,"phone","","trim");
$data["country"] = arrayGet($reqParams,"country",0,"intval");
$data["country_name"] = arrayGet($reqParams,"country_name","","trim");
$data["province"] = arrayGet($reqParams,"province","","trim");
$data["city"] = arrayGet($reqParams,"city","","trim");
$data["detail_address"] = arrayGet($reqParams,"detail_address","","trim");
OrderService::editOrderAdress($order_id,$data);
return $this->setSuccess();
}
public function editOrderSettlement(Request $request){
}
}
......@@ -85,6 +85,7 @@ class OrderService extends BaseService
public static function orderIitemList($order_id=0){
}
//取消订单
public static function cancelOrder($order_id=0){
(new self)->startTransaction();
try{
......@@ -100,8 +101,8 @@ class OrderService extends BaseService
public static function editOrderItems($order_id,$orderItems){
//修改订单明细数量价格
public static function editOrderItems($order_id,$orderItems,$order_remark){
(new self)->startTransaction();
try{
// $orderItemids = Arr::pluck($orderItems,"order_items_id");
......@@ -130,7 +131,9 @@ class OrderService extends BaseService
$createOrEdit = false;
if(!empty($returnItems)){
foreach($insertReturnItemData as $field=>$val){
if(!in_array($val["type"],[1,2]) || !$val["return_goods_number"] || !$val["return_goods_price"]){
continue;
}
if(empty($returnItems[$field]) || $returnItems[$field] != $val){
$createOrEdit = true;//新增
break;
......@@ -144,6 +147,14 @@ class OrderService extends BaseService
//修改订单总金额
self::pullOrderAmount($order_id);
//修改订单备注
if($order_remark){
Order::updateOrder(["order_id"=>$order_id],[
"order_remark"=>$order_remark,
]);
}
}catch (\Throwable $e){
(new self)->rollBackTransaction();
throw new InvalidRequestException(sprintf("%s:%s",admin_trans("order.return_msg.50003"),$e->getMessage()));
......@@ -152,7 +163,7 @@ class OrderService extends BaseService
(new self)->commitTransaction();
}
//拉取订单明细金额 回写订单主表
public static function pullOrderAmount($order_id=0){
$amount = OrderItem::getOrderTotalAmount($order_id);
Order::updateOrder(["order_id"=>$order_id],[
......@@ -160,4 +171,42 @@ class OrderService extends BaseService
]);
}
/**
* Notes:
* User: sl
* Date: 2022-11-18 10:52
* @param $reqParams
*/
public static function editOrderAdress($order_id,$data){
return OrderAddress::updateOrCreate([
"order_id"=>$order_id,
"order_address_type"=>$data["order_address_type"],
],[
"shipping_name"=>$data["shipping_name"],
"shipping_sn"=>$data["shipping_sn"],
"consignee"=>$data["consignee"],
"company_name"=>$data["company_name"],
"email"=>$data["email"],
"phone"=>$data["phone"],
"country"=>$data["country"],
"country_name"=>$data["country_name"],
"province"=>$data["province"],
"city"=>$data["city"],
"detail_address"=>$data["detail_address"],
"create_time"=>time(),
"update_time"=>time(),
]);
}
public static function changeOrderSales($userids,$sale_id){
}
//获取订单退款总金额
public static function getOrderReturnAmount($order_id = 0)
{
}
}
......@@ -27,6 +27,8 @@ Route::group([
Route::get('/api/orderList', '\App\Admin\Controllers\Api\OrderApiController@orderList');//订单详情获取明细数据
Route::get('/api/orderDownloadShow', '\App\Admin\Controllers\Api\OrderApiController@orderDownloadShow');//订单下载
Route::match(['get', 'post'],'/api/order/editOrderItems', '\App\Admin\Controllers\Api\OrderApiController@editOrderItems');//订单修改明细数据
Route::match(['get', 'post'],'/api/order/editOrderAdress', '\App\Admin\Controllers\Api\OrderApiController@editOrderAdress');//修改订单收货地址账单地址
Route::match(['get', 'post'],'/api/order/editOrderSettlement', '\App\Admin\Controllers\Api\OrderApiController@editOrderSettlement');//修改订单结算信息
});
......
......@@ -17,6 +17,8 @@ class Order extends Model
protected $primaryKey = 'order_id';
protected $guarded = ['order_id']; //设置字段黑名单
public $timestamps = false;
public static $STATUS_WAIT_AUDIT = 1;//待审核
......
......@@ -15,6 +15,7 @@ class OrderAddress extends Model
protected $table = 'order_address';
protected $primaryKey = 'order_address_id';
protected $guarded = ['order_address_id']; //设置字段黑名单
public $timestamps = false;
......@@ -37,4 +38,6 @@ class OrderAddress extends Model
}
......@@ -14,6 +14,7 @@ class OrderItem extends Model
protected $table = 'order_items';
protected $primaryKey = 'rec_id';
protected $guarded = ['rec_id']; //设置字段黑名单
public $timestamps = false;
......
......@@ -14,6 +14,7 @@ class OrderPrice extends Model
protected $table = 'order_price';
protected $primaryKey = 'price_id';
protected $guarded = ['price_id']; //设置字段黑名单
public $timestamps = false;
......
......@@ -31,7 +31,9 @@ class OrderReturnItems extends Model
public static function getOrderReturnTotalAmount($order_id){
}
......
......@@ -32,6 +32,21 @@ return [
"validator"=>[
'order_id_required' => '订单id必填',
'order_items_required' => '订单明细数据错误',
'goods_price' => [
"gt"=>"商品单价不能小于0"
],
'goods_number' => [
"gt"=>"商品数量不能小于0"
],
'return_goods_price' => [
"gt"=>"售后单价不能小于0"
],
'return_goods_number' => [
"gt"=>"售后数量不能小于0"
],
'order_address_type' => [
"required"=>"订单地址类型是必须的"
],
],
'options' => [
"status"=>[
......
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