Commit 45e72bdc by 孙龙

订单取消 和 审核

parent 97532c3e
......@@ -3,6 +3,9 @@
namespace App\Admin\Actions;
use App\Admin\Service\OrderService;
use App\Exceptions\InvalidRequestException;
use App\Models\Order;
use App\Models\Order as OrderModel;
use Dcat\Admin\Grid\BatchAction;
use Dcat\Admin\Grid\Tools\AbstractTool;
......@@ -69,8 +72,15 @@ class OrderCancelAction extends RowAction
// 获取 parameters 方法传递的参数
$rowData = $request->get('rowData');
$orderInfo = Order::getOne($rowData["order_id"]??0);
if(empty($orderInfo)){
$this->response()->error('没找到相关的订单数据')->refresh();
}
try{
OrderService::cancelOrder($rowData["order_id"]??0);
}catch (InvalidRequestException $e){
$this->response()->error($e->getMessage())->refresh();
}
return $this->response()->success('取消成功')->refresh();
}
......
......@@ -21,11 +21,14 @@ class OrderApiController extends Controller
$order_id = 1;
$orderAddressList = OrderService::getOrderAddress($order_id);
$orderAddressList = arrayChangeKeyByField($orderAddressList,"order_address_type");
dump($orderAddressList);
// dump($orderAddressList);
$info["sn"] = OrderService::getSn($type);
if(empty($info["sn"])){
abort(500, '获取编码失败');
}
$info["orderList"] = OrderService::getOrderList($order_id);
if($type == "1"){
//PI
return view('export.order_contract_PI',[
......@@ -35,10 +38,18 @@ class OrderApiController extends Controller
]);
}elseif($type == "2"){
//CI
return view('export.order_contract_CI');
return view('export.order_contract_CI',[
"ship"=>$orderAddressList[1]??[],
"bill"=>$orderAddressList[2]??[],
"info"=>$info
]);
}else{
//PL
return view('export.order_contract_PL');
return view('export.order_contract_PL',[
"ship"=>$orderAddressList[1]??[],
"bill"=>$orderAddressList[2]??[],
"info"=>$info
]);
}
}
......@@ -70,7 +81,23 @@ class OrderApiController extends Controller
public function orderDownload(Request $request){
// $params = $request->all();
// return Excel::download(new \App\Exports\ContractExport(),'PI.xlsx');
$params = $request->all();
$type = arrayGet($params, "type");
$order_id = 1;
$orderAddressList = OrderService::getOrderAddress($order_id);
$orderAddressList = arrayChangeKeyByField($orderAddressList,"order_address_type");
$info["sn"] = OrderService::getSn($type);
if(empty($info["sn"])){
abort(500, '获取编码失败');
}
$info["orderList"] = OrderService::getOrderList($order_id);
return Excel::download(new \App\Exports\ContractExport([
"ship"=>$orderAddressList[1]??[],
"bill"=>$orderAddressList[2]??[],
"info"=>$info
]),'PI.xlsx');
}
}
......@@ -128,12 +128,26 @@ class OrderController extends AdminController
// 获取当前行主键值
$id = $actions->getKey();
//取消按钮
if(in_array($rowArray["status"],[1,2])){
$actions->append(new OrderCancelAction());
}
//下载
if($rowArray["status"] >= 2){
$options = [
'PI',
];
if($rowArray["status"] > 2){
array_push($options,"CI","PL");
}
$actions->prepend(
\App\Admin\Controllers\OrderController::down($id)
\App\Admin\Controllers\OrderController::down($id,$options)
);
}
});
......@@ -144,16 +158,12 @@ class OrderController extends AdminController
}
public static function down($id){
public static function down($id,$optoins=[]){
$menu1 = Dropdown::make()
->button('下载')
->buttonClass('btn btn-primary btn-sm btn-mini') // 设置按钮样式
->options([
'PI',
'CI',
'PL',
])->map(function ($v, $k) use($id) {
->options($optoins)->map(function ($v, $k) use($id) {
$k++;
return "<a style='min-width: 5rem' class='test_item' data-orderid='$id' data-id='$k', data-value='{$v}' data-test='Hello world.' href='javascript:void(0)'>$v</a>";
});
......
......@@ -2,13 +2,16 @@
namespace App\Admin\Service;
use App\Exceptions\InvalidRequestException;
use App\Models\Cms\CmsUser;
use App\Models\Increasid;
use App\Models\Order;
use App\Models\OrderAddress;
use App\Models\OrderItem;
use App\Models\OrderPrice;
use Dcat\Admin\Grid;
class OrderService
class OrderService extends BaseService
{
......@@ -19,7 +22,37 @@ class OrderService
* @param $orderId
*/
public static function getOrderList($orderId=0){
$orderList = Order::getOrderList($orderId);
$orderItems = $orderList["order_items"]??[];
$orderPrice = $orderList["order_price"]??[];
$orderList["total_qty"] = 0;
foreach($orderItems as $k=>$item){
$orderList["total_qty"] += $item["goods_number"];
$orderItems[$k]["total_amount"] = decimal_number_format($item["goods_price"]*$item["goods_number"]);
$orderItems[$k]["total_amount_format"] = decimal_number_format($item["goods_price"]*$item["goods_number"],DIGITS_TWO,2);
}
$orderList["payServiceFee"] = 0;//支付手续费
$orderList["carriage"] = 0;//运费
foreach($orderPrice as $item){
switch ($item["price_type"]){
case OrderPrice::$PRICE_TYPE_LIST["支付手续费"]:
$orderList["payServiceFee"] += $item["price"];
break;
case OrderPrice::$PRICE_TYPE_LIST["运费"]:
$orderList["carriage"] += $item["price"];
break;
}
}
$orderList["order_items"] = $orderItems;
$orderList["total_amount"] = $orderList["order_amount"]+$orderList["payServiceFee"]+$orderList["carriage"]+$orderList["carriage"];
//支付手续费
$orderList["payServiceFee_format"] = decimal_number_format($orderList["payServiceFee"],DIGITS_TWO,2);
//运费
$orderList["carriage_format"] = decimal_number_format($orderList["carriage"],DIGITS_TWO,2);
$orderList["total_amount"] = decimal_number_format($orderList["total_amount"]);
$orderList["total_amount_format"] = decimal_number_format($orderList["total_amount"],DIGITS_TWO,2);
return $orderList;
}
......@@ -50,5 +83,18 @@ class OrderService
public static function orderIitemList($order_id=0){
}
public static function cancelOrder($order_id=0){
(new self)->startTransaction();
try{
Order::canelOrder($order_id);
OrderItem::canelOrder($order_id);
}catch (\Exception $e){
(new self)->rollBackTransaction();
throw new InvalidRequestException(sprintf("取消订单失败:%s",$e->getMessage()));
}
(new self)->commitTransaction();
}
}
......@@ -22,7 +22,7 @@ class ContractExport implements FromView, WithColumnWidths, WithDefaultStyles, W
public function view(): View
{
return view('export.order_contract', $this->order_info);
return view('export.order_contract_PI', $this->order_info);
}
public function columnWidths(): array
......@@ -32,11 +32,13 @@ class ContractExport implements FromView, WithColumnWidths, WithDefaultStyles, W
'B' => 23,
'C' => 22,
'D' => 10,
'E' => 10,
'E' => 23,
'F' => 10,
'G' => 12,
'H' => 12,
'I' => 15,
'J' => 15,
'K' => 15,
];
}
......@@ -49,11 +51,11 @@ class ContractExport implements FromView, WithColumnWidths, WithDefaultStyles, W
{
return [
AfterSheet::class => function (AfterSheet $event) {
// $cellRange = $this->specific_cells;
// foreach ($cellRange as $cell) {
// // 单个单元格设置格式
// $event->sheet->getDelegate()->getStyle($cell)->getNumberFormat()->setFormatCode('0.000000');
// }
// $cellRange = $this->specific_cells;
// foreach ($cellRange as $cell) {
// // 单个单元格设置格式
// $event->sheet->getDelegate()->getStyle($cell)->getNumberFormat()->setFormatCode('0.000000');
// }
// 垂直居中
// $last_line = $this->order_item_num + 8; // 最后行 = 明细数量 + (起始行 - 1)
......
......@@ -23,6 +23,19 @@ class Order extends Model
public static $STATUS_WAIT_PAY = 2;//待付款
public static $STATUS_FORAMT=[
"已取消"=>-1,
"审核不通过"=>-2,
"待审核"=>1,
"待付款"=>2,
"待付尾款"=>3,
"待发货"=>4,
"部分发货"=>7,
"待收货"=>8,
"交易成功"=>10,
];
public function scmUser()
{
return $this->belongsTo(ScmUser::class, 'user_id', 'id');
......@@ -33,6 +46,11 @@ class Order extends Model
return $this->hasMany(OrderItem::class, 'order_id', 'order_id');
}
public function order_price()
{
return $this->hasMany(OrderPrice::class, 'order_id', 'order_id');
}
//审核订单
......@@ -41,11 +59,27 @@ class Order extends Model
}
//获取订单数据
public static function getOrderList($orderId=0){
self::where("order_id",$orderId)->whereHas("order_items",function ($q){
if(empty($orderId)){
return [];
}
$info = self::where("order_id",$orderId)->whereHas("order_items",function ($q){
$q->where("status",1);
})->get()->toArray();
})->with("order_items")->with("order_price")->with("scmUser")->first();
return $info ? $info->toArray() : [];
}
public static function getOne($orderId=0){
$orderInfo = self::where("order_id",$orderId)->first();
return $orderInfo ? $orderInfo->toArray() : [];
}
//取消
public static function canelOrder($orderId=0){
return self::where("order_id",$orderId)->update([
"status"=>self::$STATUS_FORAMT["已取消"],
]);
}
}
......@@ -25,6 +25,12 @@ class OrderAddress extends Model
return $this->belongsTo(Order::class, 'order_id', 'order_id');
}
public function country()
{
return $this->belongsTo(Country::class, 'country_name', 'id');
}
public static function getOrderAddress($orderId=0){
return self::where("order_id",$orderId)->get()->toArray();
}
......
......@@ -17,6 +17,11 @@ class OrderItem extends Model
public $timestamps = false;
public static $STATUS_FORMAT=[
"已删除"=>-1,
"正常"=>1,
];
public static function getOrderItems($order_id=0){
return self::where("order_id",$order_id)->get()->toArray();
......@@ -24,5 +29,11 @@ class OrderItem extends Model
}
//取消
public static function canelOrder($orderId=0){
return self::where("order_id",$orderId)->update([
"status"=>self::$STATUS_FORMAT["已删除"],
]);
}
}
......@@ -100,7 +100,7 @@ if (!function_exists('decimal_number_format')) {
if($currency){
$minus = $amount < 0 ? '-' : '';
$numerical = number_format(abs($amount),$digits,".",$thousandsSymbol);
$sign = \Arr::get(config("field.currency_sign"),intval($currency),"");
$sign = Arr::get(config("field.currency_sign"),intval($currency),"");
if (!empty($sign)) {
$numerical = $sign . $numerical;
}
......
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