初始化
缺陷:主题配色需要优化整体的同风格
This commit is contained in:
36
app/Http/Controllers/Wx/AuthController.php
Normal file
36
app/Http/Controllers/Wx/AuthController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Wx;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\wx\WxAuthService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* 小程序登录(免鉴权)
|
||||
*/
|
||||
class AuthController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 继承的 CRUD 会被 autoRouteRegister 反射成路由,登录组里绝不能白送这些
|
||||
*/
|
||||
protected array $exceptRoute = ['list', 'option', 'detail', 'create', 'update', 'delete'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = WxAuthService::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信 code 登录
|
||||
* @Method POST
|
||||
*/
|
||||
public function login(): JsonResponse
|
||||
{
|
||||
return jok(
|
||||
$this->service->login(request()->post()),
|
||||
'登录成功'
|
||||
);
|
||||
}
|
||||
}
|
||||
39
app/Http/Controllers/Wx/HomeController.php
Normal file
39
app/Http/Controllers/Wx/HomeController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Wx;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\wx\WxHomeService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* 小程序首页(免鉴权)
|
||||
*/
|
||||
class HomeController extends BaseController
|
||||
{
|
||||
protected array $exceptRoute = ['list', 'option', 'detail', 'create', 'update', 'delete'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = WxHomeService::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页轮播
|
||||
* @Method GET
|
||||
*/
|
||||
public function carousel(): JsonResponse
|
||||
{
|
||||
return jok($this->service->carousel());
|
||||
}
|
||||
|
||||
/**
|
||||
* 一级分类
|
||||
* @Method GET
|
||||
*/
|
||||
public function categoryList(): JsonResponse
|
||||
{
|
||||
return jok($this->service->categoryList((int) request()->get('pid', 0)));
|
||||
}
|
||||
}
|
||||
96
app/Http/Controllers/Wx/ListController.php
Normal file
96
app/Http/Controllers/Wx/ListController.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Wx;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\wx\WxListService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* 小程序清单
|
||||
*/
|
||||
class ListController extends BaseController
|
||||
{
|
||||
protected array $exceptRoute = ['option'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = WxListService::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的清单
|
||||
* @Method GET
|
||||
*/
|
||||
public function list(): JsonResponse
|
||||
{
|
||||
return jok($this->service->list());
|
||||
}
|
||||
|
||||
/**
|
||||
* 清单详情
|
||||
* @Method GET
|
||||
*/
|
||||
public function detail(): JsonResponse
|
||||
{
|
||||
return jok($this->service->detail((int) request()->get('id', 0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建清单
|
||||
* @Method POST
|
||||
*/
|
||||
public function create(): JsonResponse
|
||||
{
|
||||
return jok($this->service->create(request()->post()), '创建成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 改清单名称与备注
|
||||
* @Method POST
|
||||
*/
|
||||
public function update(): JsonResponse
|
||||
{
|
||||
return jok(
|
||||
$this->service->update((int) request()->post('id', 0), request()->post()),
|
||||
'保存成功'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除清单
|
||||
* @Method POST
|
||||
*/
|
||||
public function delete(): JsonResponse
|
||||
{
|
||||
return jok($this->service->delete(request()->post('ids', [])), '删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除清单明细
|
||||
* @Method POST
|
||||
*/
|
||||
public function deleteItem(): JsonResponse
|
||||
{
|
||||
return jok($this->service->deleteItem(request()->post('ids', [])), '删除成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入清单
|
||||
* @Method POST
|
||||
*/
|
||||
public function toCart(): JsonResponse
|
||||
{
|
||||
return jok($this->service->toCart(request()->post()), '添加成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 改明细的规格与数量
|
||||
* @Method POST
|
||||
*/
|
||||
public function updateItem(): JsonResponse
|
||||
{
|
||||
return jok($this->service->updateItem(request()->post()), '保存成功');
|
||||
}
|
||||
}
|
||||
84
app/Http/Controllers/Wx/OrderController.php
Normal file
84
app/Http/Controllers/Wx/OrderController.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Wx;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\wx\WxOrderService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* 小程序订单
|
||||
*/
|
||||
class OrderController extends BaseController
|
||||
{
|
||||
protected array $exceptRoute = ['option', 'update', 'delete'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = WxOrderService::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的订单
|
||||
* @Method GET
|
||||
*/
|
||||
public function list(): JsonResponse
|
||||
{
|
||||
return jok($this->service->list());
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
* @Method GET
|
||||
*/
|
||||
public function detail(): JsonResponse
|
||||
{
|
||||
return jok($this->service->detail((int) request()->get('id', 0)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 清单转订单
|
||||
* @Method POST
|
||||
*/
|
||||
public function create(): JsonResponse
|
||||
{
|
||||
return jok($this->service->createFromList(request()->post()), '下单成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传转账凭证
|
||||
* @Method POST
|
||||
*/
|
||||
public function voucher(): JsonResponse
|
||||
{
|
||||
return jok($this->service->submitVoucher(request()->post()), '已提交,等待审核');
|
||||
}
|
||||
|
||||
/**
|
||||
* 调起微信支付
|
||||
* @Method POST
|
||||
*/
|
||||
public function wechatPay(): JsonResponse
|
||||
{
|
||||
return jok($this->service->wechatPay(request()->post()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订单
|
||||
* @Method POST
|
||||
*/
|
||||
public function cancel(): JsonResponse
|
||||
{
|
||||
return jok($this->service->cancel((int) request()->post('id', 0)), '已取消');
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认收货
|
||||
* @Method POST
|
||||
*/
|
||||
public function complete(): JsonResponse
|
||||
{
|
||||
return jok($this->service->complete((int) request()->post('id', 0)), '已完成');
|
||||
}
|
||||
}
|
||||
52
app/Http/Controllers/Wx/ProductController.php
Normal file
52
app/Http/Controllers/Wx/ProductController.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Wx;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\wx\WxHomeService;
|
||||
use App\Service\wx\WxProductService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* 小程序商品
|
||||
*/
|
||||
class ProductController extends BaseController
|
||||
{
|
||||
protected array $exceptRoute = ['option', 'create', 'update', 'delete'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = WxProductService::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品列表
|
||||
* @Method GET
|
||||
*/
|
||||
public function list(): JsonResponse
|
||||
{
|
||||
return jok($this->service->list());
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品详情,p_user_id 为代理商分享来源
|
||||
* @Method GET
|
||||
*/
|
||||
public function detail(): JsonResponse
|
||||
{
|
||||
return jok($this->service->detail(
|
||||
(int) request()->get('id', 0),
|
||||
(int) request()->get('p_user_id', 0)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 按父级取分类
|
||||
* @Method GET
|
||||
*/
|
||||
public function categoryListByPid(): JsonResponse
|
||||
{
|
||||
return jok(WxHomeService::getInstance()->categoryList((int) request()->get('pid', 0)));
|
||||
}
|
||||
}
|
||||
56
app/Http/Controllers/Wx/ThemeController.php
Normal file
56
app/Http/Controllers/Wx/ThemeController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Wx;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\wx\WxPayService;
|
||||
use App\Service\wx\WxThemeService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* 小程序主题下发与支付回调(均免鉴权)
|
||||
*/
|
||||
class ThemeController extends BaseController
|
||||
{
|
||||
protected array $exceptRoute = ['list', 'option', 'detail', 'create', 'update', 'delete'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = WxThemeService::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前主题
|
||||
* @Method GET
|
||||
*/
|
||||
public function theme(): JsonResponse
|
||||
{
|
||||
return jok($this->service->current((string) request()->get('code', '')));
|
||||
}
|
||||
|
||||
/**
|
||||
* 可选风格
|
||||
* @Method GET
|
||||
*/
|
||||
public function themeGallery(): JsonResponse
|
||||
{
|
||||
return jok($this->service->gallery());
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信支付回调
|
||||
*
|
||||
* 必须用原始报文验签:先 json_decode 再 encode 回去,字节顺序变了签名就对不上。
|
||||
* @Method POST
|
||||
*/
|
||||
public function payNotify(): JsonResponse
|
||||
{
|
||||
$headers = [];
|
||||
foreach (['wechatpay-timestamp', 'wechatpay-nonce', 'wechatpay-signature', 'wechatpay-serial'] as $key) {
|
||||
$headers[$key] = (string) request()->header($key, '');
|
||||
}
|
||||
$result = WxPayService::getInstance()->handleNotify($headers, request()->getContent());
|
||||
return response()->json($result);
|
||||
}
|
||||
}
|
||||
51
app/Http/Controllers/Wx/UserController.php
Normal file
51
app/Http/Controllers/Wx/UserController.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Wx;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\wx\WxUserCenterService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* 小程序「我的」
|
||||
*/
|
||||
class UserController extends BaseController
|
||||
{
|
||||
protected array $exceptRoute = ['list', 'option', 'detail', 'create', 'update', 'delete'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = WxUserCenterService::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的信息
|
||||
* @Method GET
|
||||
*/
|
||||
public function myInfo(): JsonResponse
|
||||
{
|
||||
return jok($this->service->myInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定手机号
|
||||
* @Method POST
|
||||
*/
|
||||
public function bandPhone(): JsonResponse
|
||||
{
|
||||
return jok($this->service->bandPhone(request()->post()), '绑定成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改昵称
|
||||
* @Method POST
|
||||
*/
|
||||
public function updateNickName(): JsonResponse
|
||||
{
|
||||
return jok(
|
||||
$this->service->updateNickName((string) request()->post('nick_name', '')),
|
||||
'保存成功'
|
||||
);
|
||||
}
|
||||
}
|
||||
37
app/Http/Controllers/Wx/WxUploadController.php
Normal file
37
app/Http/Controllers/Wx/WxUploadController.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Wx;
|
||||
|
||||
use App\BaseApp\BaseController;
|
||||
use App\Service\wx\WxUploadService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
* 小程序上传(转账凭证等)。
|
||||
*
|
||||
* 走 nl.wx 中间件鉴权(小程序登录态),路径 wx/upload/image。
|
||||
* 仅暴露 image 方法,避免反射注册把 BaseController 的 create/update/delete 挂成路由。
|
||||
*/
|
||||
class WxUploadController extends BaseController
|
||||
{
|
||||
protected array $exceptRoute = ['option', 'create', 'update', 'delete'];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->service = WxUploadService::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片上传(转账凭证)
|
||||
* @Method POST
|
||||
*/
|
||||
public function image(): JsonResponse
|
||||
{
|
||||
$file = request()->file('file');
|
||||
return jok(
|
||||
$this->service->uploadImage($file),
|
||||
'上传成功'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user