feat: order
This commit is contained in:
@@ -42,4 +42,10 @@ class OrderCode
|
|||||||
*/
|
*/
|
||||||
const ORDER_TYPE_GOOD = 1;
|
const ORDER_TYPE_GOOD = 1;
|
||||||
const ORDER_TYPE_BALANCE = 2;
|
const ORDER_TYPE_BALANCE = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string 订单类型前缀
|
||||||
|
*/
|
||||||
|
const ORDER_TYPE_GOOD_PREFIX = 'OG';
|
||||||
|
const ORDER_TYPE_BALANCE_PREFIX = 'OB';
|
||||||
}
|
}
|
||||||
@@ -8,14 +8,25 @@ use App\Controller\AbstractController;
|
|||||||
use App\Middleware\Api\JwtAuthMiddleware;
|
use App\Middleware\Api\JwtAuthMiddleware;
|
||||||
use Hyperf\HttpServer\Annotation\Controller;
|
use Hyperf\HttpServer\Annotation\Controller;
|
||||||
use Hyperf\HttpServer\Annotation\Middlewares;
|
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||||
|
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||||
|
use Hyperf\Validation\Annotation\Scene;
|
||||||
|
|
||||||
#[Controller(prefix: 'api/order')]
|
#[Controller(prefix: 'api/pay')]
|
||||||
#[Middlewares([
|
#[Middlewares([
|
||||||
JwtAuthMiddleware::class,
|
JwtAuthMiddleware::class,
|
||||||
])]
|
])]
|
||||||
class PayController extends AbstractController
|
class PayController extends AbstractController
|
||||||
{
|
{
|
||||||
public function index()
|
#[RequestMapping(path: 'order',methods: 'POST')]
|
||||||
|
#[Scene(scene: 'order')]
|
||||||
|
public function order()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#[RequestMapping(path: 'refund',methods: 'POST')]
|
||||||
|
#[Scene(scene: 'refund')]
|
||||||
|
public function refund()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ declare(strict_types=1);
|
|||||||
namespace App\Service\Api\Order;
|
namespace App\Service\Api\Order;
|
||||||
|
|
||||||
use App\Amqp\Producer\CancelOrderProducer;
|
use App\Amqp\Producer\CancelOrderProducer;
|
||||||
use App\Constants\Common\GoodCode;
|
|
||||||
use App\Constants\Common\OrderCode;
|
use App\Constants\Common\OrderCode;
|
||||||
use App\Constants\ConfigCode;
|
use App\Constants\ConfigCode;
|
||||||
use App\Exception\ErrException;
|
use App\Exception\ErrException;
|
||||||
@@ -184,7 +183,7 @@ class PlaceOrderService extends BaseOrderService
|
|||||||
{
|
{
|
||||||
$orderInsertModel = new Order();
|
$orderInsertModel = new Order();
|
||||||
|
|
||||||
$orderInsertModel->order_sno = '123';
|
$orderInsertModel->order_sno = $this->generateOrderNo(OrderCode::ORDER_TYPE_GOOD, $this->userId);
|
||||||
$orderInsertModel->user_id = $this->userId;
|
$orderInsertModel->user_id = $this->userId;
|
||||||
$orderInsertModel->cycle_id = $this->cycleId;
|
$orderInsertModel->cycle_id = $this->cycleId;
|
||||||
$orderInsertModel->site_id = $this->siteId;
|
$orderInsertModel->site_id = $this->siteId;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use App\Cache\Redis\Api\SiteCache;
|
|||||||
use App\Cache\Redis\RedisCache;
|
use App\Cache\Redis\RedisCache;
|
||||||
use App\Constants\ApiCode;
|
use App\Constants\ApiCode;
|
||||||
use App\Constants\Common\GoodCode;
|
use App\Constants\Common\GoodCode;
|
||||||
|
use App\Constants\Common\OrderCode;
|
||||||
use App\Constants\ConfigCode;
|
use App\Constants\ConfigCode;
|
||||||
use App\Exception\ErrException;
|
use App\Exception\ErrException;
|
||||||
use Hyperf\Amqp\Producer;
|
use Hyperf\Amqp\Producer;
|
||||||
@@ -38,6 +39,20 @@ trait OrderTrait
|
|||||||
#[Inject]
|
#[Inject]
|
||||||
protected RedisCache $redis;
|
protected RedisCache $redis;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成订单号
|
||||||
|
* @param int $type
|
||||||
|
* @param int $userId
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function generateOrderNo(int $type,int $userId): string
|
||||||
|
{
|
||||||
|
return match ($type) {
|
||||||
|
OrderCode::ORDER_TYPE_GOOD => OrderCode::ORDER_TYPE_GOOD_PREFIX . '_' .date("YmdHis") . $userId . mt_rand(10000000, 99999999),
|
||||||
|
OrderCode::ORDER_TYPE_BALANCE => OrderCode::ORDER_TYPE_BALANCE_PREFIX. '_' .date("YmdHis"). $userId. mt_rand(10000000, 99999999),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成购物车数据
|
* 生成购物车数据
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
|||||||
Reference in New Issue
Block a user