change to innodb engine and cancel order

This commit is contained in:
Edward Yang 2022-08-25 16:06:05 +08:00
parent 69090d84ca
commit e1063eb3f2
3 changed files with 35 additions and 3 deletions

View File

@ -27,6 +27,7 @@ class StateMachineService
const PAID = 'paid'; // 已支付 const PAID = 'paid'; // 已支付
const SHIPPED = 'shipped'; // 已发货 const SHIPPED = 'shipped'; // 已发货
const COMPLETED = 'completed'; // 已完成 const COMPLETED = 'completed'; // 已完成
const CANCELLED = 'cancelled'; // 已取消
const ORDER_STATUS = [ const ORDER_STATUS = [
self::CREATED, self::CREATED,
@ -39,12 +40,13 @@ class StateMachineService
const MACHINES = [ const MACHINES = [
self::CREATED => [ self::CREATED => [
self::UNPAID => ['updateStatus', 'addHistory'], self::UNPAID => ['updateStatus', 'addHistory'],
self::PAID => ['updateStatus', 'addHistory', 'subStock'],
], ],
self::UNPAID => [ self::UNPAID => [
self::PAID => ['updateStatus', 'addHistory', 'subStock'], self::PAID => ['updateStatus', 'addHistory', 'subStock'],
self::CANCELLED => ['updateStatus', 'addHistory'],
], ],
self::PAID => [ self::PAID => [
self::CANCELLED => ['updateStatus', 'addHistory', 'revertStock'],
self::SHIPPED => ['updateStatus', 'addHistory'], self::SHIPPED => ['updateStatus', 'addHistory'],
self::COMPLETED => ['updateStatus', 'addHistory'] self::COMPLETED => ['updateStatus', 'addHistory']
], ],
@ -239,4 +241,13 @@ class StateMachineService
{ {
} }
/**
* 恢复库存
*/
private function revertStock($oldCode, $newCode)
{
}
} }

View File

@ -89,7 +89,7 @@ class OrderController extends Controller
/** /**
* 订单完成 * 完成订单
* *
* @param Request $request * @param Request $request
* @param $number * @param $number
@ -107,4 +107,25 @@ class OrderController extends Controller
StateMachineService::getInstance($order)->changeStatus(StateMachineService::COMPLETED, $comment); StateMachineService::getInstance($order)->changeStatus(StateMachineService::COMPLETED, $comment);
return json_success(trans('shop/account.order.completed')); return json_success(trans('shop/account.order.completed'));
} }
/**
* 取消订单
*
* @param Request $request
* @param $number
* @return array
* @throws \Exception
*/
public function cancel(Request $request, $number)
{
$customer = current_customer();
$order = OrderRepo::getOrderByNumber($number, $customer);
if (empty($order)) {
throw new \Exception('无效的订单');
}
$comment = '用户取消订单';
StateMachineService::getInstance($order)->changeStatus(StateMachineService::CANCELLED, $comment);
return json_success(trans('shop/account.order.cancelled'));
}
} }

View File

@ -57,7 +57,7 @@ return [
'prefix' => '', 'prefix' => '',
'prefix_indexes' => true, 'prefix_indexes' => true,
'strict' => true, 'strict' => true,
'engine' => null, 'engine' => 'InnoDB',
'options' => extension_loaded('pdo_mysql') ? array_filter([ 'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [], ]) : [],