Commit fc74d7d6 by 孙龙

订单用户统计 更改订单跟进人

parent 3f7169f3
...@@ -82,12 +82,13 @@ class OrderApiController extends BaseController ...@@ -82,12 +82,13 @@ class OrderApiController extends BaseController
$orderInfo["orderItemList"][$k]["type_cn"] = Arr::get(OrderReturnItems::$TYPE,$returnItems["type"] ?? 0,""); $orderInfo["orderItemList"][$k]["type_cn"] = Arr::get(OrderReturnItems::$TYPE,$returnItems["type"] ?? 0,"");
} }
$returnAmount = OrderService::getOrderReturnAmount($order_id);
return response()->json(["code"=>0,"msg"=>"ok","data"=>[ return response()->json(["code"=>0,"msg"=>"ok","data"=>[
"list"=>$orderInfo["orderItemList"], "list"=>$orderInfo["orderItemList"],
"order_amount"=>decimal_number_format_usd($orderInfo["order_amount"]), "order_amount"=>decimal_number_format_usd($orderInfo["order_amount"]),
"return_order_amount"=>decimal_number_format_usd($orderInfo["order_amount"]), "return_order_amount"=>$returnAmount,
"return_order_amount_format"=>decimal_number_format_usd($returnAmount),
],"count"=>count($orderInfo["orderItemList"] )]); ],"count"=>count($orderInfo["orderItemList"] )]);
} }
...@@ -186,8 +187,22 @@ class OrderApiController extends BaseController ...@@ -186,8 +187,22 @@ class OrderApiController extends BaseController
return $this->setSuccess(); return $this->setSuccess();
} }
//修改订单结算信息
public function editOrderSettlement(Request $request){ public function editOrderSettlement(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);
}
} }
} }
...@@ -199,14 +199,52 @@ class OrderService extends BaseService ...@@ -199,14 +199,52 @@ class OrderService extends BaseService
]); ]);
} }
public static function changeOrderSales($userids,$sale_id){ //更新订单的业务员
public static function changeOrderSales($userids,$sale_id,$sale_name){
return Order::updateOrderSale($userids,$sale_id,$sale_name);
}
//返回用户的下单数
public static function getUserOrderStatistical($userIds=[])
{
$ongoingOrders = Order::getUserOrderStatistical($userIds,1);
$finishedOrders = Order::getUserOrderStatistical($userIds,2);
$arr=[];
foreach($userIds as $user_id){
$arr[$user_id]["pending"] =0;
$arr[$user_id]["all"] =0;
foreach($ongoingOrders as $ongoingOrder){
if($ongoingOrder["user_id"] == $user_id){
$arr[$user_id]["pending"] =$ongoingOrder["nums"];
break;
}
} }
foreach($finishedOrders as $finishedOrder){
if($finishedOrder["user_id"] == $user_id){
$arr[$user_id]["all"] =$finishedOrder["nums"];
break;
}
}
}
return $arr;
}
//获取订单退款总金额 //获取订单退款总金额
public static function getOrderReturnAmount($order_id = 0) public static function getOrderReturnAmount($order_id = 0)
{ {
$orderItemIds = OrderItem::getOrderItemids($order_id);
$returnAmount = 0;
foreach($orderItemIds as $orderItemId){
$returnInfo = OrderReturnItems::getOrderReturnItem($orderItemId);
if(!empty($returnInfo)){
$returnAmount += $returnInfo["return_amount"];
}
}
return decimal_number_format($returnAmount);
} }
} }
...@@ -24,6 +24,7 @@ Route::group([ ...@@ -24,6 +24,7 @@ Route::group([
$router->resource('country', 'CountryController'); $router->resource('country', 'CountryController');
//下载pdf //下载pdf
Route::get('/api/order_download', '\App\Admin\Controllers\Api\OrderApiController@orderDownload');//下载订单pdf Route::get('/api/order_download', '\App\Admin\Controllers\Api\OrderApiController@orderDownload');//下载订单pdf
Route::get('/api/test', '\App\Admin\Controllers\Api\TestController@index');
Route::get('/api/orderList', '\App\Admin\Controllers\Api\OrderApiController@orderList');//订单详情获取明细数据 Route::get('/api/orderList', '\App\Admin\Controllers\Api\OrderApiController@orderList');//订单详情获取明细数据
Route::get('/api/orderDownloadShow', '\App\Admin\Controllers\Api\OrderApiController@orderDownloadShow');//订单下载 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/editOrderItems', '\App\Admin\Controllers\Api\OrderApiController@editOrderItems');//订单修改明细数据
......
...@@ -104,4 +104,27 @@ class Order extends Model ...@@ -104,4 +104,27 @@ class Order extends Model
return self::where($where)->update($update); return self::where($where)->update($update);
} }
//修改订单的销售
public static function updateOrderSale($userids,$sale_id,$sale_name){
return self::whereIn("user_id",$userids)
->whereRaw("status >= 1 and status < 10")
->update([
"sale_id"=>$sale_id,
"sale_name"=>$sale_name,
"update_time"=>time(),
]);
}
//统计用户的下单数
public static function getUserOrderStatistical($userIds,$type){
$query = self::whereIn("user_id",$userIds)->selectRaw("user_id,count(order_id) as nums");
if($type == "1"){
$query->whereRaw("status >= 1 and status <= 8");
}elseif($type == "2"){
$query->whereRaw("status >= 1");
}
return $query->groupBy("user_id")->get()->toArray();
}
} }
...@@ -51,4 +51,8 @@ class OrderItem extends Model ...@@ -51,4 +51,8 @@ class OrderItem extends Model
return $info ? decimal_number_format($info->total_amount) : 0; return $info ? decimal_number_format($info->total_amount) : 0;
} }
public static function getOrderItemids($order_id){
return self::where("order_id",$order_id)->where("status",self::$STATUS_FORMAT["正常"])->pluck("rec_id")->toArray();
}
} }
...@@ -31,9 +31,7 @@ class OrderReturnItems extends Model ...@@ -31,9 +31,7 @@ class OrderReturnItems extends Model
public static function getOrderReturnTotalAmount($order_id){
}
......
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