Commit 54cca012 by 孙龙

订单详情修改

parent 7da49779
......@@ -64,3 +64,4 @@ PERM_GOURL=http://perm.semourdev.net
ADMIN_GROUP=1000,20000
MENU_ID=2
MENU_URL=http://data.semourdev.net/api/config/
......@@ -2,15 +2,22 @@
namespace App\Admin\Controllers\Api;
use App\Admin\Controllers\BaseController;
use App\Admin\Service\OrderService;
use App\Exceptions\InvalidRequestException;
use App\Http\Utils\ValidatorMsg;
use App\Models\Increasid;
use App\Models\Order;
use App\Models\OrderAddress;
use App\Models\OrderReturnItems;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Arr;
use Maatwebsite\Excel\Facades\Excel;
use Illuminate\Support\Facades\Validator;
class OrderApiController extends Controller
class OrderApiController extends BaseController
{
public function orderDownloadShow(Request $request){
......@@ -56,29 +63,31 @@ class OrderApiController extends Controller
public function orderList(Request $request){
$arr=[];
$arr[0]["goods_id"]="123456";
$arr[0]["goods_name"]="商品型号";
$arr[0]["standard_brand_name"]="标准品牌";
$arr[0]["supplier_name"]="应商";
$arr[0]["raw_goods_sn"]="供应商物料唯一编码";
$arr[0]["raw_brand_name"]="供应商物料品牌";
$arr[0]["purchase_name"]="采购员";
$arr[0]["currency_cn"]="美金";
$arr[0]["goods_price"]="0.12344";//单价
$arr[0]["goods_number"]="66";//购买数量
$arr[0]["total_amount"]="100";//小计
$arr[0]["discount_amount"]="0.2";//折扣金额
$arr[0]["other_amount"]="0.1";//其它费用
$arr[0]["delivery_time"]="1-200年";//货期
$arr[0]["batch"]="1-200年";//批次
$arr[0]["remarks"]="客户备注";//客户备注
return response()->json(["code"=>0,"msg"=>"ok","data"=>["list"=>$arr],"count"=>0]);
$params = request()->all();
$order_id = arrayGet($params,"order_id",0,"intval");
$orderInfo = Order::getOneAndRelationList($order_id);
$orderItems = $orderInfo["order_items"]??[];
$orderInfo["orderItemList"] = $orderItems;
foreach($orderInfo["orderItemList"] as $k=>$item){
$orderInfo["orderItemList"][$k]["goods_price_format"] = decimal_number_format_usd($item["goods_price"]);
$orderInfo["orderItemList"][$k]["total_amount"] = decimal_number_format($item["goods_price"]*$item["goods_number"]);
$orderInfo["orderItemList"][$k]["total_amount_format"] = decimal_number_format_usd($item["goods_price"]*$item["goods_number"]);
$returnItems = OrderReturnItems::getOrderReturnItem($item["rec_id"]);
$orderInfo["orderItemList"][$k]["return_num"] = $returnItems["return_num"] ?? "";
$orderInfo["orderItemList"][$k]["return_price"] = $returnItems["return_price"] ?? "";
$orderInfo["orderItemList"][$k]["return_amount"] = $returnItems["return_amount"] ?? "";
$orderInfo["orderItemList"][$k]["type"] = $returnItems["type"] ?? "";
$orderInfo["orderItemList"][$k]["type_cn"] = Arr::get(OrderReturnItems::$TYPE,$returnItems["type"] ?? 0,"");
}
return response()->json(["code"=>0,"msg"=>"ok","data"=>["list"=>$orderInfo["orderItemList"]],"count"=>count($orderInfo["orderItemList"] )]);
}
//订单明细修改
public function orderDownload(Request $request){
$params = $request->all();
......@@ -100,4 +109,34 @@ class OrderApiController extends Controller
"info"=>$info
]),'PI.xlsx');
}
//订单明细修改
public function editOrderItems(Request $request){
$params = $request->all();
$order_id = arrayGet($params,"order_id",0,"intval");
$orderItems = arrayGet($params,"order_items","","trim");
$validator = Validator::make($params, [
'order_id' => 'required',
'order_items.*.order_items_id' => 'required',
'order_items' => 'required',
], [
'order_id.required' => admin_trans("order.validator.order_id_required"),
'order_items.required' => admin_trans("order.validator.order_items_required"),
], [
// 'order_id' => '订单id',
// 'order_items' => '订单明细',
]);
if ($validator->fails()) {
$errors = $validator->errors()->toArray();
$err_msg = ValidatorMsg::getMsg($errors);
throw new InvalidRequestException($err_msg);
}
OrderService::editOrderItems($order_id,$orderItems);
return $this->setSuccess();
}
}
<?php
namespace App\Admin\Controllers;
use App\Http\ApiHelper\ApiCode;
use Illuminate\Routing\Controller;
class BaseController extends Controller
{
public function setSuccessData($data = [], $count = 0, $code = ApiCode::API_CODE_SUCCESS, $msg = 'ok')
{
$res_data = [
"code" => $code,
"data" => $data,
];
if ($msg) {
$res_data['msg'] = $msg;
}
if ($count) {
$res_data['count'] = $count;
}
return response()->json($res_data);
}
public function setSuccess($msg = 'Operation succeeded', $code = ApiCode::API_CODE_SUCCESS, $data = [])
{
$res_data = [
"code" => $code,
"msg" => $msg,
'data' => (object)$data,
];
return response()->json($res_data);
}
public function setError($msg, $code = ApiCode::API_CODE_ERROR, $data = [])
{
$res_data = [
"code" => $code,
"msg" => $msg,
];
if ($data) {
$res_data['data'] = $data;
}
$this->logErr($msg, $code = ApiCode::API_CODE_ERROR, $data = null);
return response()->json($res_data);
}
}
......@@ -32,7 +32,6 @@ class OrderController extends AdminController
*/
public function index(Content $content)
{
return $content
->translation($this->translation())
->title($this->title())
......@@ -53,7 +52,7 @@ class OrderController extends AdminController
return Grid::make(new Order(), function (Grid $grid) {
$grid->model()->with("scmUser")->orderBy('order_id', 'desc');
$grid->fixColumns(1,2);//固定列
$grid->showColumnSelector();//开启字段选择器功能
// $grid->showColumnSelector();//开启字段选择器功能
// 在 display 回调中使用
$grid->column('序号')->display(function () {
return $this->_index + 1;
......@@ -245,8 +244,7 @@ JS
$order_id = arrayGet($params,"order_id",0,"intval");
$orderInfo = Order::getOneAndRelationList($order_id);
$orderItems = $orderInfo["orderItems"]??[];
dump($orderInfo);
$orderItems = $orderInfo["order_items"]??[];
$info=[];
// $info["orderInfo"] = $orderInfo;
......@@ -290,7 +288,7 @@ JS
$info["settlementInfo"]["order_freight_amount_format"] = "";
$info["settlementInfo"]["order_pay_commission_amount"] = 0;//手续费
$info["settlementInfo"]["order_pay_commission_amount_format"] = "";
$orderItemsId = Arr::pluck($orderItems,"rec_id");
// $orderItemsId = Arr::pluck($orderItems,"rec_id");
foreach($orderPrice as $orderPriceItem){
switch ($orderPriceItem["price_type"]){
......@@ -313,6 +311,5 @@ dump($info);
return view('admin.pages.order-page',["info"=>$info]);
// return $content->body(new OrderDetailPage());
}
}
......@@ -9,7 +9,9 @@ use App\Models\Order;
use App\Models\OrderAddress;
use App\Models\OrderItem;
use App\Models\OrderPrice;
use App\Models\OrderReturnItems;
use Dcat\Admin\Grid;
use Illuminate\Support\Arr;
class OrderService extends BaseService
{
......@@ -90,11 +92,72 @@ class OrderService extends BaseService
OrderItem::canelOrder($order_id);
}catch (\Exception $e){
(new self)->rollBackTransaction();
throw new InvalidRequestException(sprintf("取消订单失败:%s",$e->getMessage()));
throw new InvalidRequestException(sprintf("%s:%s",admin_trans("order.return_msg.50002"),$e->getMessage()));
}
(new self)->commitTransaction();
}
public static function editOrderItems($order_id,$orderItems){
(new self)->startTransaction();
try{
// $orderItemids = Arr::pluck($orderItems,"order_items_id");
// $orderItemsInfo = OrderItem::getItemsInfo($orderItemids);
// $orderItemsInfo = arrayChangeKeyByField($orderItemsInfo,"rec_id");
// $returnItems = OrderReturnItems::getOrderReturnItem($orderItemids);
// $returnItems = arrayChangeKeyByField($returnItems,"rec_id");
// dd($returnItems);
foreach ($orderItems as $orderItem){
OrderItem::updateOrderItem(["rec_id"=>$orderItem["order_items_id"]],[
"goods_price"=>$orderItem["goods_price"],
"goods_number"=>$orderItem["goods_number"],
]);
$returnItems = OrderReturnItems::getOrderReturnItem($orderItem["order_items_id"]);
$insertReturnItemData = [
"type"=>$orderItem["return_type"],
"order_id"=>$order_id,
"rec_id"=>$orderItem["order_items_id"],
"return_num"=>$orderItem["return_goods_number"],
"return_price"=>$orderItem["return_goods_price"],
"return_amount"=> decimal_number_format($orderItem["return_goods_number"] * $orderItem["return_goods_price"]),
];
$createOrEdit = false;
if(!empty($returnItems)){
foreach($insertReturnItemData as $field=>$val){
if(empty($returnItems[$field]) || $returnItems[$field] != $val){
$createOrEdit = true;//新增
break;
}
}
}
$createOrEdit && OrderReturnItems::create(array_merge($insertReturnItemData,["create_time"=>time()]));
}
//修改订单总金额
self::pullOrderAmount($order_id);
}catch (\Throwable $e){
(new self)->rollBackTransaction();
throw new InvalidRequestException(sprintf("%s:%s",admin_trans("order.return_msg.50003"),$e->getMessage()));
}
(new self)->commitTransaction();
}
public static function pullOrderAmount($order_id=0){
$amount = OrderItem::getOrderTotalAmount($order_id);
Order::updateOrder(["order_id"=>$order_id],[
"order_amount"=>$amount,
]);
}
}
......@@ -7,7 +7,6 @@ use Dcat\Admin\Admin;
Admin::routes();
Route::group([
'prefix' => config('admin.route.prefix'),
'namespace' => config('admin.route.namespace'),
......@@ -24,9 +23,10 @@ Route::group([
$router->resource('users', 'UserController');
$router->resource('country', 'CountryController');
//下载pdf
Route::get('/api/order_download', '\App\Admin\Controllers\Api\OrderApiController@orderDownload');
Route::get('/api/orderList', '\App\Admin\Controllers\Api\OrderApiController@orderList');
Route::get('/api/orderDownloadShow', '\App\Admin\Controllers\Api\OrderApiController@orderDownloadShow');
Route::get('/api/order_download', '\App\Admin\Controllers\Api\OrderApiController@orderDownload');//下载订单pdf
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');//订单修改明细数据
});
......
<?php
namespace App\Http\ApiHelper;
interface ApiCode
{
const API_CODE_SUCCESS = 0;//接口请求正常
const API_CODE_ERROR = 1;//接口请求异常 可预测失败
const API_CODE_NEED_LOGIN = 101; //需要登录
const API_CODE_LOGIN_ERROR = 102; // 登录信息错误
const API_CODE_MOBILE_NOTFOUND_ERROR = 103; // 手机号不存在
const API_CODE_PASSWD_NOTFOUND_ERROR = 104; // 密码错误
const API_CODE_USER_DISABLE_ERROR = 105; // 账号被封禁
}
<?php
/**
* Created by PhpStorm.
* User: duwenjun
* Date: 2021/8/11
* Time: 2:52 PM
*/
namespace App\Http\ApiHelper;
class Response
{
public static function setError($errMsg, $errCode = ApiCode::API_CODE_ERROR, $data = [])
{
return json_encode(['code' => $errCode, 'msg' => $errMsg, 'data' => $data],
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
public static function setSuccess($data, $code = ApiCode::API_CODE_SUCCESS, $msg = "")
{
return json_encode(['code' => $code, 'msg' => $msg, 'data' => $data],
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
}
\ No newline at end of file
......@@ -39,7 +39,7 @@ class Kernel extends HttpKernel
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
// \App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
......
<?php
/**
* Created by PhpStorm.
* User: duwenjun
* Date: 2021/9/1
* Time: 9:40 AM
*/
namespace App\Http\Utils;
use Illuminate\Support\Facades\Validator;
class ValidatorMsg
{
// 只返回错误的第一条错误
public static function getMsg($error_list)
{
$err_msg = '';
foreach ($error_list as $err_key => $err_msgs) {
foreach ($err_msgs as $msg) {
$err_msg .= "{$err_key}|{$msg}";
break;
}
break;
}
return $err_msg;
}
public static function checkValidateParamThrowException($validateRule,$params)
{
$validator = Validator::make($params, $validateRule);
if ($validator->fails()) {
$errors = $validator->errors()->toJson(JSON_UNESCAPED_UNICODE);
throw new \InvalidArgumentException($errors);
}
return true;
}
}
......@@ -36,4 +36,18 @@ class OrderItem extends Model
]);
}
//修改订单
public static function updateOrderItem($where,$update){
return self::where($where)->update($update);
}
public static function getItemsInfo($rec_id=[]){
return self::whereIn("rec_id",$rec_id)->get()->toArray();
}
public static function getOrderTotalAmount($order_id){
$info = self::where("order_id",$order_id)->where("status",self::$STATUS_FORMAT["正常"])->selectRaw("sum(goods_price*goods_number) as total_amount")->first();
return $info ? decimal_number_format($info->total_amount) : 0;
}
}
......@@ -14,12 +14,25 @@ class OrderReturnItems extends Model
protected $table = 'order_return_items';
protected $primaryKey = 'return_items_id';
protected $guarded = ['return_items_id']; //设置字段黑名单
public $timestamps = false;
public static function getOrderReturnItemList($rec_ids=[]){
self::whereIn("rec_id")
public static $TYPE=[
"1" => "退货退款",
"2" => "仅退款",
];
public static function getOrderReturnItem($rec_id){
$info = self::where("rec_id",$rec_id)->orderBy("return_items_id","desc")->limit(1)->first();
return $info ? $info->toArray() : [];
}
}
......@@ -25,7 +25,13 @@ return [
],
"return_msg"=>[
"50000"=>"操作成功",
"50001"=>"只能修改不是待审核的订单状态"
"50001"=>"只能修改不是待审核的订单状态",
"50002"=>"取消订单失败",
"50003"=>"修改订单失败",
],
"validator"=>[
'order_id_required' => '订单id必填',
'order_items_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