chore: init saasshop repo + sql migrations runner + gitee go
This commit is contained in:
79
app/Http/Controllers/Api/V1/AuthController.php
Normal file
79
app/Http/Controllers/Api/V1/AuthController.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\OauthAccount;
|
||||
use App\Models\Merchant;
|
||||
use App\Models\User;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function login(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'string'],
|
||||
'source' => ['nullable', 'string'],
|
||||
]);
|
||||
|
||||
$user = User::query()->where('email', $data['email'])->first();
|
||||
if (! $user || ! Hash::check($data['password'], $user->password)) {
|
||||
return ApiResponse::error('账号或密码错误', 1001, null, 422);
|
||||
}
|
||||
|
||||
$source = $data['source'] ?? 'pc';
|
||||
$user->forceFill(['last_login_source' => $source])->save();
|
||||
|
||||
return ApiResponse::success([
|
||||
'token' => base64_encode($user->id . '|' . now()->timestamp . '|demo'),
|
||||
'user' => [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'email' => $user->email,
|
||||
'source' => $source,
|
||||
],
|
||||
], '登录成功');
|
||||
}
|
||||
|
||||
public function wechatPlaceholder(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'platform' => ['required', 'in:wechat_mp,wechat_mini,app'],
|
||||
'openid' => ['nullable', 'string'],
|
||||
'unionid' => ['nullable', 'string'],
|
||||
'nickname' => ['nullable', 'string'],
|
||||
]);
|
||||
|
||||
$merchant = Merchant::query()->first();
|
||||
$user = User::query()->first();
|
||||
|
||||
if ($user && ($data['openid'] ?? null)) {
|
||||
OauthAccount::query()->updateOrCreate(
|
||||
[
|
||||
'provider' => $data['platform'],
|
||||
'openid' => $data['openid'],
|
||||
],
|
||||
[
|
||||
'user_id' => $user->id,
|
||||
'merchant_id' => $merchant?->id,
|
||||
'platform' => $data['platform'],
|
||||
'provider' => $data['platform'],
|
||||
'unionid' => $data['unionid'] ?? null,
|
||||
'nickname' => $data['nickname'] ?? null,
|
||||
'raw_payload' => $data,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return ApiResponse::success([
|
||||
'platform' => $data['platform'],
|
||||
'next_step' => '待接入真实微信 / App 登录流程',
|
||||
'received' => $data,
|
||||
], '渠道登录占位已预留');
|
||||
}
|
||||
}
|
||||
57
app/Http/Controllers/Api/V1/OrderController.php
Normal file
57
app/Http/Controllers/Api/V1/OrderController.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Order;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class OrderController extends Controller
|
||||
{
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$orders = Order::query()->latest()->get();
|
||||
return ApiResponse::success($orders, '订单列表获取成功');
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'merchant_id' => ['required', 'integer'],
|
||||
'user_id' => ['nullable', 'integer'],
|
||||
'buyer_name' => ['nullable', 'string'],
|
||||
'buyer_phone' => ['nullable', 'string'],
|
||||
'buyer_email' => ['nullable', 'email'],
|
||||
'platform' => ['nullable', 'string'],
|
||||
'payment_channel' => ['nullable', 'string'],
|
||||
'product_amount' => ['required', 'numeric'],
|
||||
'discount_amount' => ['nullable', 'numeric'],
|
||||
'shipping_amount' => ['nullable', 'numeric'],
|
||||
'pay_amount' => ['required', 'numeric'],
|
||||
'remark' => ['nullable', 'string'],
|
||||
]);
|
||||
|
||||
$order = Order::query()->create([
|
||||
'merchant_id' => $data['merchant_id'],
|
||||
'user_id' => $data['user_id'] ?? null,
|
||||
'order_no' => 'ORD' . now()->format('YmdHis') . random_int(1000, 9999),
|
||||
'status' => 'pending',
|
||||
'platform' => $data['platform'] ?? 'h5',
|
||||
'payment_channel' => $data['payment_channel'] ?? 'wechat_pay',
|
||||
'payment_status' => 'unpaid',
|
||||
'device_type' => $data['platform'] ?? 'h5',
|
||||
'product_amount' => $data['product_amount'],
|
||||
'discount_amount' => $data['discount_amount'] ?? 0,
|
||||
'shipping_amount' => $data['shipping_amount'] ?? 0,
|
||||
'pay_amount' => $data['pay_amount'],
|
||||
'buyer_name' => $data['buyer_name'] ?? null,
|
||||
'buyer_phone' => $data['buyer_phone'] ?? null,
|
||||
'buyer_email' => $data['buyer_email'] ?? null,
|
||||
'remark' => $data['remark'] ?? null,
|
||||
]);
|
||||
|
||||
return ApiResponse::success($order, '订单创建成功');
|
||||
}
|
||||
}
|
||||
31
app/Http/Controllers/Api/V1/ProductController.php
Normal file
31
app/Http/Controllers/Api/V1/ProductController.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$products = Product::query()
|
||||
->select(['id', 'merchant_id', 'title', 'slug', 'sku', 'summary', 'price', 'original_price', 'stock', 'status'])
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
return ApiResponse::success($products, '商品列表获取成功');
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$product = Product::query()->find($id);
|
||||
if (! $product) {
|
||||
return ApiResponse::error('商品不存在', 404, null, 404);
|
||||
}
|
||||
|
||||
return ApiResponse::success($product, '商品详情获取成功');
|
||||
}
|
||||
}
|
||||
34
app/Http/Controllers/Api/V1/SystemController.php
Normal file
34
app/Http/Controllers/Api/V1/SystemController.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class SystemController extends Controller
|
||||
{
|
||||
public function ping(): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'message' => 'SaaSShop API is alive',
|
||||
'time' => now()->toDateTimeString(),
|
||||
'version' => 'v1',
|
||||
]);
|
||||
}
|
||||
|
||||
public function platforms(): JsonResponse
|
||||
{
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'platforms' => [
|
||||
['key' => 'pc', 'name' => 'PC 端', 'status' => 'ready'],
|
||||
['key' => 'h5', 'name' => 'H5', 'status' => 'ready'],
|
||||
['key' => 'wechat_mp', 'name' => '微信公众号', 'status' => 'reserved'],
|
||||
['key' => 'wechat_mini', 'name' => '微信小程序', 'status' => 'reserved'],
|
||||
['key' => 'app', 'name' => 'APP', 'status' => 'reserved'],
|
||||
],
|
||||
'api_prefix' => '/api/v1',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user