初始化项目
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\response\Json;
|
||||
use app\api\service\User as UserService;
|
||||
use app\api\model\UserAddress as UserAddressModel;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 收货地址管理
|
||||
* Class Address
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Address extends Controller
|
||||
{
|
||||
/**
|
||||
* 收货地址列表
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list(): Json
|
||||
{
|
||||
// 获取收货地址列表
|
||||
$model = new UserAddressModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户默认收货地址
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function defaultId(): Json
|
||||
{
|
||||
$useInfo = UserService::getCurrentLoginUser(true);
|
||||
return $this->renderSuccess(['defaultId' => $useInfo['address_id']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收货地址详情
|
||||
* @param int $addressId 地址ID
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function detail(int $addressId): Json
|
||||
{
|
||||
$detail = UserAddressModel::detail($addressId);
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加收货地址
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function add(): Json
|
||||
{
|
||||
$model = new UserAddressModel;
|
||||
if ($model->add($this->postForm())) {
|
||||
return $this->renderSuccess([], '添加成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '添加失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑收货地址
|
||||
* @param int $addressId 地址ID
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function edit(int $addressId): Json
|
||||
{
|
||||
$model = UserAddressModel::detail($addressId);
|
||||
if ($model->edit($this->postForm())) {
|
||||
return $this->renderSuccess([], '更新成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设为默认地址
|
||||
* @param int $addressId 地址ID
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function setDefault(int $addressId): Json
|
||||
{
|
||||
$model = UserAddressModel::detail($addressId);
|
||||
if ($model->setDefault((int)$model['address_id'])) {
|
||||
return $this->renderSuccess([], '设置成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '设置失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除收货地址
|
||||
* @param int $addressId 地址ID
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function remove(int $addressId): Json
|
||||
{
|
||||
$model = UserAddressModel::detail($addressId);
|
||||
if ($model->remove()) {
|
||||
return $this->renderSuccess([], '删除成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '删除失败');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Article as ArticleModel;
|
||||
|
||||
/**
|
||||
* 文章控制器
|
||||
* Class Article
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Article extends Controller
|
||||
{
|
||||
/**
|
||||
* 文章列表
|
||||
* @param int $categoryId
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list(int $categoryId = 0)
|
||||
{
|
||||
$model = new ArticleModel;
|
||||
$list = $model->getList($categoryId);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章详情
|
||||
* @param int $articleId
|
||||
* @return \think\response\Json
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function detail(int $articleId)
|
||||
{
|
||||
$detail = ArticleModel::getDetail($articleId);
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\response\Json;
|
||||
use app\api\service\passport\{Captcha as CaptchaService, SmsCaptcha as SmsCaptchaService};
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 验证码管理
|
||||
* Class Cart
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Captcha extends Controller
|
||||
{
|
||||
/**
|
||||
* 图形验证码
|
||||
* @return Json
|
||||
*/
|
||||
public function image(): Json
|
||||
{
|
||||
$CaptchaService = new CaptchaService;
|
||||
return $this->renderSuccess($CaptchaService->create());
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信验证码
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function sendSmsCaptcha(): Json
|
||||
{
|
||||
$SmsCaptchaService = new SmsCaptchaService;
|
||||
if ($SmsCaptchaService->handle($this->postForm())) {
|
||||
return $this->renderSuccess('发送成功,请注意查收');
|
||||
}
|
||||
return $this->renderError($SmsCaptchaService->getError() ?: '短信发送失败');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Card as CardModel;
|
||||
use app\api\model\Setting as SettingModel;
|
||||
use app\api\service\User as UserService;
|
||||
use cores\exception\BaseException;
|
||||
use app\common\service\QueueService;
|
||||
|
||||
/**
|
||||
* 实体卡兑换管理
|
||||
* Class Card
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Card extends Controller
|
||||
{
|
||||
/**
|
||||
* 确认兑换
|
||||
* @param string|null $card_number 兑换卡号
|
||||
* @param string|null $secret_key 卡密
|
||||
* @return array|\think\response\Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function submit($card_number = null, $secret_key = null)
|
||||
{
|
||||
/*if (!$card_number) {
|
||||
return $this->renderError('请输入兑换卡号');
|
||||
}*/
|
||||
if (!$secret_key) {
|
||||
return $this->renderError('请输入卡密');
|
||||
}
|
||||
// 充值设置
|
||||
$setting = SettingModel::getItem('exchange');
|
||||
// 验证最低充值金额
|
||||
if (!$setting['is_entrance']) {
|
||||
return $this->renderError("很抱歉,兑换功能已关闭");
|
||||
}
|
||||
|
||||
// 分销对象
|
||||
$obj = CardModel::detail([['secret_key','=',$secret_key], ['is_used','=',10]]);
|
||||
if(!$obj){
|
||||
return $this->renderError('无效卡密');
|
||||
}
|
||||
// 当前用户信息
|
||||
$userInfo = UserService::getCurrentLoginUser(true);
|
||||
|
||||
// 存入队列处理
|
||||
$queueService = new QueueService();
|
||||
$queueService->push('card_queue', json_encode(['card_id'=>$obj['card_id'],'user_id'=>$userInfo['user_id']],320));
|
||||
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\response\Json;
|
||||
use app\api\model\Cart as CartModel;
|
||||
use app\api\service\Cart as CartService;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 购物车管理
|
||||
* Class Cart
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Cart extends Controller
|
||||
{
|
||||
/**
|
||||
* 购物车商品列表
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function list(): Json
|
||||
{
|
||||
// 购物车商品列表
|
||||
$service = new CartService;
|
||||
$list = $service->getList();
|
||||
// 购物车商品总数量
|
||||
$cartTotal = (new CartModel)->getCartTotal();
|
||||
return $this->renderSuccess(compact('cartTotal', 'list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 购物车商品总数量
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function total(): Json
|
||||
{
|
||||
$model = new CartModel;
|
||||
$cartTotal = $model->getCartTotal();
|
||||
return $this->renderSuccess(compact('cartTotal'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入购物车
|
||||
* @param int $goodsId 商品ID
|
||||
* @param string $goodsSkuId 商品sku索引
|
||||
* @param int $goodsNum 商品数量
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function add(int $goodsId, string $goodsSkuId, int $goodsNum): Json
|
||||
{
|
||||
$model = new CartModel;
|
||||
if (!$model->add($goodsId, $goodsSkuId, $goodsNum)) {
|
||||
return $this->renderError($model->getError() ?: '加入购物车失败');
|
||||
}
|
||||
// 购物车商品总数量
|
||||
$cartTotal = $model->getCartTotal();
|
||||
return $this->renderSuccess(compact('cartTotal'), '加入购物车成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新购物车商品数量
|
||||
* @param int $goodsId 商品ID
|
||||
* @param string $goodsSkuId 商品sku索引
|
||||
* @param int $goodsNum 商品数量
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function update(int $goodsId, string $goodsSkuId, int $goodsNum): Json
|
||||
{
|
||||
$model = new CartModel;
|
||||
if (!$model->sUpdate($goodsId, $goodsSkuId, $goodsNum)) {
|
||||
return $this->renderError($model->getError() ?: '更新失败');
|
||||
}
|
||||
// 购物车商品总数量
|
||||
$cartTotal = $model->getCartTotal();
|
||||
return $this->renderSuccess(compact('cartTotal'), '更新成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除购物车中指定记录
|
||||
* @param array $cartIds 购物车ID集, 如果为空删除所有
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function clear(array $cartIds = []): Json
|
||||
{
|
||||
$model = new CartModel;
|
||||
if (!$model->clear($cartIds)) {
|
||||
return $this->renderError($model->getError() ?: '操作失败');
|
||||
}
|
||||
// 购物车商品总数量
|
||||
$cartTotal = $model->getCartTotal();
|
||||
return $this->renderSuccess(compact('cartTotal'), '操作成功');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Category as CategoryModel;
|
||||
|
||||
/**
|
||||
* 商品分类控制器
|
||||
* Class Category
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Category extends Controller
|
||||
{
|
||||
/**
|
||||
* 分类列表
|
||||
* @return array|\think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new CategoryModel;
|
||||
$list = $model->getListPublic($this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Order as OrderModel;
|
||||
use app\api\model\Setting as SettingModel;
|
||||
use app\api\service\User as UserService;
|
||||
use app\api\service\Cart as CartService;
|
||||
use app\api\service\order\Checkout as CheckoutService;
|
||||
use app\api\validate\order\Checkout as CheckoutValidate;
|
||||
use app\common\enum\Setting as SettingEnum;
|
||||
use cores\exception\BaseException;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 订单结算控制器
|
||||
* Class Checkout
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Checkout extends Controller
|
||||
{
|
||||
// 结算台验证器
|
||||
/* @var CheckoutValidate $validate */
|
||||
private $validate;
|
||||
|
||||
/**
|
||||
* 结算台订单信息
|
||||
* @param string $mode
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function order(string $mode = 'buyNow'): Json
|
||||
{
|
||||
// 用户信息不存在 => 注册新用户 或者 跳转到绑定手机号页
|
||||
$setting = SettingModel::getItem(SettingEnum::REGISTER);
|
||||
// 当前用户信息
|
||||
$userInfo = UserService::getCurrentLoginUser(true);
|
||||
// 后台设置了需强制绑定手机号, 返回前端isBindMobile, 跳转到手机号验证页
|
||||
if ($setting['isForceBindMpweixin'] && empty($userInfo['mobile'])) {
|
||||
return $this->renderError('当前用户未绑定手机号', ['isBindMobile' => true]);
|
||||
}
|
||||
if ($mode === 'buyNow') {
|
||||
return $this->buyNow();
|
||||
} elseif ($mode === 'cart') {
|
||||
return $this->cart();
|
||||
}
|
||||
return $this->renderError('结算模式不合法');
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单提交
|
||||
* @param string $mode
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function submit(string $mode = 'buyNow'): Json
|
||||
{
|
||||
return $this->order($mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单确认-立即购买
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function buyNow(): Json
|
||||
{
|
||||
// 实例化结算台服务
|
||||
$Checkout = new CheckoutService;
|
||||
// 订单结算api参数
|
||||
$params = $Checkout->setParam($this->getParam([
|
||||
'goodsId' => 0,
|
||||
'goodsSkuId' => '',
|
||||
'goodsNum' => 0,
|
||||
]));
|
||||
// 表单验证
|
||||
if (!$this->getValidate()->scene('buyNow')->check($params)) {
|
||||
return $this->renderError($this->getValidate()->getError(), ['isCreated' => false]);
|
||||
}
|
||||
// 立即购买:获取订单商品列表
|
||||
$model = new OrderModel;
|
||||
$goodsList = $model->getOrderGoodsListByNow(
|
||||
(int)$params['goodsId'],
|
||||
(string)$params['goodsSkuId'],
|
||||
(int)$params['goodsNum']
|
||||
);
|
||||
// 获取订单确认信息
|
||||
$orderInfo = $Checkout->onCheckout($goodsList);
|
||||
if ($this->request->isGet()) {
|
||||
return $this->renderSuccess([
|
||||
'order' => $orderInfo,
|
||||
'personal' => $Checkout->getPersonal(),
|
||||
'setting' => $Checkout->getSetting(),
|
||||
]);
|
||||
}
|
||||
// 验证订单是否存在错误
|
||||
if ($Checkout->hasError()) {
|
||||
return $this->renderError($Checkout->getError(), ['is_created' => false]);
|
||||
}
|
||||
// 创建订单
|
||||
if (!$Checkout->createOrder($orderInfo)) {
|
||||
return $this->renderError($Checkout->getError() ?: '订单创建失败', ['is_created' => false]);
|
||||
}
|
||||
// 构建微信支付请求
|
||||
$payment = $model->onOrderPayment($Checkout->model, $params['payType']);
|
||||
// 返回结算信息
|
||||
return $this->renderSuccess([
|
||||
'orderId' => $Checkout->model['order_id'], // 订单id
|
||||
'payType' => $params['payType'], // 支付方式
|
||||
'payment' => $payment // 微信支付参数
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单确认-购物车结算
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
private function cart(): Json
|
||||
{
|
||||
// 实例化结算台服务
|
||||
$Checkout = new CheckoutService;
|
||||
// 订单结算api参数
|
||||
$params = $Checkout->setParam($this->getParam());
|
||||
// 购物车ID集
|
||||
$cartIds = $this->getCartIds();
|
||||
// 商品结算信息
|
||||
$CartModel = new CartService;
|
||||
// 购物车商品列表
|
||||
$goodsList = $CartModel->getOrderGoodsList($cartIds);
|
||||
// 获取订单结算信息
|
||||
$orderInfo = $Checkout->onCheckout($goodsList);
|
||||
if ($this->request->isGet()) {
|
||||
return $this->renderSuccess([
|
||||
'order' => $orderInfo,
|
||||
'personal' => $Checkout->getPersonal(),
|
||||
'setting' => $Checkout->getSetting(),
|
||||
]);
|
||||
}
|
||||
// 验证订单是否存在错误
|
||||
if ($Checkout->hasError()) {
|
||||
return $this->renderError($Checkout->getError(), ['is_created' => false]);
|
||||
}
|
||||
// 创建订单
|
||||
if (!$Checkout->createOrder($orderInfo)) {
|
||||
return $this->renderError($Checkout->getError() ?: '订单创建失败');
|
||||
}
|
||||
// 移出购物车中已下单的商品
|
||||
$CartModel->clear($cartIds);
|
||||
// 构建微信支付请求
|
||||
$payment = $Checkout->onOrderPayment();
|
||||
// 返回状态
|
||||
return $this->renderSuccess([
|
||||
'orderId' => $Checkout->model['order_id'], // 订单id
|
||||
'payType' => $params['payType'], // 支付方式
|
||||
'payment' => $payment // 微信支付参数
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取结算台验证器
|
||||
* @return CheckoutValidate
|
||||
*/
|
||||
private function getValidate(): CheckoutValidate
|
||||
{
|
||||
if (!$this->validate) {
|
||||
$this->validate = new CheckoutValidate;
|
||||
}
|
||||
return $this->validate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取购物车ID集
|
||||
* @return false|string[]
|
||||
*/
|
||||
private function getCartIds()
|
||||
{
|
||||
$cartIds = $this->request->param('cartIds');
|
||||
return explode(',', $cartIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单结算提交的参数
|
||||
* @param array $define
|
||||
* @return array
|
||||
*/
|
||||
private function getParam(array $define = []): array
|
||||
{
|
||||
return array_merge($define, $this->request->param());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,396 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Code as CodeModel;
|
||||
use app\api\model\Notify as NotifyModel;
|
||||
use app\api\model\Shop as ShopModel;
|
||||
use app\api\model\Order as OrderModel;
|
||||
use think\cache\driver\Redis;
|
||||
use cores\exception\BaseException;
|
||||
use think\facade\Cache;
|
||||
use think\response\Json;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Psr7\Request;
|
||||
use GuzzleHttp\Cookie\CookieJar;
|
||||
|
||||
/**
|
||||
* 产码控制器
|
||||
* Class Code
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Code extends Controller
|
||||
{
|
||||
/**
|
||||
* 查询支付状态
|
||||
* @throws \app\common\exception\BaseException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function payStatus()
|
||||
{
|
||||
$data = $this->request->get();
|
||||
$zone = isset($data['zone'])?$data['zone']:1; //订单分区
|
||||
$this->saveLog("进入支付查询");
|
||||
//开始
|
||||
$model = new CodeModel();
|
||||
$orderModel = new OrderModel();
|
||||
$NotifyModel = new NotifyModel();
|
||||
|
||||
$array = $model->getList($zone);
|
||||
|
||||
$this->saveLog("进入支付查询,分区:".$zone.",订单数量:".count($array));
|
||||
//获取IP组
|
||||
$iPGroup = $this->getIPGroup();
|
||||
foreach ($array as $k=>$val) {
|
||||
$payTotal = $orderModel->getZoneOrderTotal([['code_id', '=', $val['code_id']],['order_status', '=', 20]]);
|
||||
$waitPayTotal = $orderModel->getZoneOrderTotal([['code_id', '=', $val['code_id']],['order_status', '=', 10]]);
|
||||
$modelOr = OrderModel::detail([['code_id', '=', $val['code_id']],['order_status', '=', 10]]);
|
||||
$text = $val['passageway'] == 'ZFBH5'?'订单已支付':'该订单已完成支付';
|
||||
if (isset($modelOr['order_id']) && !empty($modelOr['order_id']) && $payTotal <= 0 && $waitPayTotal == 1) {
|
||||
if(isset($iPGroup[0]['ip'])) {
|
||||
$res = $this->checkStatusProxy(htmlspecialchars_decode($val['search_url']), $val['passageway'], $iPGroup[0]['ip'], $iPGroup[0]['port'], $text);
|
||||
}else {
|
||||
$res = $this->checkStatus(htmlspecialchars_decode($val['search_url']), $val['passageway'], $text);
|
||||
}
|
||||
if ($res !== false) { //支付成功
|
||||
$pass = $modelOr['callback'] == 1 ? $NotifyModel->add($modelOr) : true;
|
||||
if ($pass) {
|
||||
$model->update([
|
||||
'order_id' => $modelOr['order_id'],
|
||||
'pay_status' => 1,
|
||||
],['code_id'=>$val['code_id']]);
|
||||
$modelOr->save([
|
||||
'pay_status' => 20,
|
||||
'pay_time' => time(),
|
||||
'order_status' => 20,
|
||||
]);
|
||||
return $this->renderSuccess('操作成功');
|
||||
} else {
|
||||
return $this->renderError($NotifyModel->getError() ?: '操作失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->saveLog("支付查询结束,分区:".$zone.",订单数量:".count($array));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询失效状态
|
||||
* @throws \app\common\exception\BaseException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function lapseStatus()
|
||||
{
|
||||
//连接本地的 Redis 服务
|
||||
// 获取分布式锁
|
||||
$lock_key = 'lapseStatus_lock';
|
||||
$max_wait_time = 10; // 最大等待时间(秒)
|
||||
$retry_interval = 100; // 重试间隔时间(毫秒)
|
||||
$lock_ttl = 600; // 锁定时间(秒)
|
||||
$lock_count = 0; // 锁的重试次数
|
||||
// 获取分布式锁
|
||||
$redis = Cache::store('redis');
|
||||
$lock = false;
|
||||
$wait_time = 0;
|
||||
$lock_value = '';
|
||||
while ($wait_time <= $max_wait_time) {
|
||||
$lock_value = uniqid(); // 生成唯一的锁值
|
||||
if ($redis->set($lock_key, $lock_value, 'EX', $lock_ttl, 'NX')) {
|
||||
$lock = true;
|
||||
break;
|
||||
} else {
|
||||
// 获取锁失败,等待一段时间后重试
|
||||
$lock_count++;
|
||||
usleep($retry_interval * 1000);
|
||||
$wait_time += ($retry_interval / 1000);
|
||||
if ($lock_count > 40) {
|
||||
// 重试次数超过限制,抛出异常
|
||||
$this->saveLog("失效查询重试次数超过限制");
|
||||
}
|
||||
}
|
||||
}
|
||||
if($lock) {
|
||||
try {
|
||||
// TODO: 需要加锁的业务逻辑
|
||||
// 字符串操作
|
||||
$conn = new \think\cache\driver\Redis(config('cache.stores.redis'));
|
||||
$codesIp = $conn->get('codesIp');
|
||||
$codesPort = $conn->get('codesPort');
|
||||
$codeNum = $conn->get('codeNum');
|
||||
if (empty($codesIp) || empty($codeNum) || $codeNum <= 0) {
|
||||
//获取IP组
|
||||
$iPGroup = $this->getIPGroup();
|
||||
$codesIp = isset($iPGroup[0]['ip']) ? $iPGroup[0]['ip'] : '';
|
||||
$codesPort = isset($iPGroup[0]['port']) ? $iPGroup[0]['port'] : '';
|
||||
$codeNum = 20;
|
||||
$conn->set('codesIp', $codesIp);
|
||||
$conn->set('codesPort', $codesPort);
|
||||
}
|
||||
$modelOr = new OrderModel();
|
||||
$model = new CodeModel();
|
||||
$this->saveLog("失效查询开始");
|
||||
//非失效码的状态更新
|
||||
$nonFailure = $model->getNonFailure();
|
||||
foreach ($nonFailure as $val) {
|
||||
$codeM = CodeModel::detail($val['code_id']);
|
||||
$create_time = is_numeric($val['create_time']) ? $val['create_time'] : strtotime($val['create_time']);
|
||||
//支付码失效
|
||||
if ($create_time + $val['expiration_time'] < time()) {
|
||||
$codeM->save([
|
||||
'status' => 3,
|
||||
]);
|
||||
//分配时间过长未支付,订单超时,支付码释放
|
||||
} elseif ($val['allot_time'] + 300 < time()) {
|
||||
$text = $val['passageway'] == 'ZFBH5' ? '订单已支付' : '该订单已完成支付';
|
||||
if (!empty($codesIp)) {
|
||||
$conn->set('codeNum', $codeNum - 1);
|
||||
$res = $this->checkStatusProxy(htmlspecialchars_decode($val['search_url']), $val['passageway'], $codesIp, $codesPort, $text);
|
||||
} else {
|
||||
$res = $this->checkStatus(htmlspecialchars_decode($val['search_url']), $val['passageway'], $text);
|
||||
}
|
||||
$status = 1;
|
||||
$pay_status = 0;
|
||||
if ($res !== false) { //已支付 更改状态
|
||||
$status = 3;
|
||||
$pay_status = 1;
|
||||
} else {
|
||||
//重新写入队列左边(为的是后进先出,失败的一般代表比较前面的码,所以放在左边)
|
||||
$code_queue = ['code_id' => (int)$val['code_id'], 'expire_time' => $create_time + (float)$val['expiration_time']]; // 过期时间
|
||||
//先清楚队列再加入,避免重复
|
||||
Cache::store('redis')->lRem($val['passageway'] . '_' . ($val['money'] * 1), json_encode($code_queue, 320), 1);
|
||||
Cache::store('redis')->lPush($val['passageway'] . '_' . ($val['money'] * 1), json_encode($code_queue, 320));
|
||||
$this->saveLog("回码:".json_encode($code_queue, 320));
|
||||
}
|
||||
|
||||
$codeM->save([
|
||||
'allot_time' => 0,
|
||||
'back_time' => time(),
|
||||
'status' => $status,
|
||||
'pay_status' => $pay_status,
|
||||
]);
|
||||
}
|
||||
if ($val['code_id']) {
|
||||
$modelOr->update([
|
||||
'code_id' => 0,
|
||||
'order_status' => 30,
|
||||
'old_code_id' => $val['code_id']
|
||||
], ['code_id' => $val['code_id'],
|
||||
'order_status' => 10]);
|
||||
}
|
||||
}
|
||||
//处理未匹配上码的订单为超时
|
||||
$modelOr->update([
|
||||
'order_status' => 30,
|
||||
], [['code_id', '=', 0],
|
||||
['order_status', '=', 10], ['create_time', '<', time() - 120]]);
|
||||
$this->saveLog("失效查询结束");
|
||||
} finally {
|
||||
// 释放锁
|
||||
$lock_value_in_redis = $redis->get($lock_key);
|
||||
if ($lock_value_in_redis === $lock_value) { // 如果当前锁的值和刚才设置的值相等,则说明当前线程持有该锁,可以进行释放
|
||||
$redis->del($lock_key); // 删除锁
|
||||
}
|
||||
}
|
||||
}
|
||||
//未使用超过调起次数的支付码
|
||||
/*$modelNew = new CodeModel();
|
||||
$modelNew->setStatusLose([],['status' => array('=', 1),
|
||||
'num' => array('>=', 100)]);*/
|
||||
}
|
||||
|
||||
public function getIPGroup(): array
|
||||
{
|
||||
$html = @file_get_contents("http://http.tiqu.letecs.com/getip3?num=1&type=2&pro=&city=0&yys=0&port=1&time=1&ts=0&ys=0&cs=0&lb=1&sb=0&pb=4&mr=1®ions=");
|
||||
$result = json_decode($html,true);
|
||||
$ips = is_array($result['data'])?$result['data']:[];
|
||||
return $ips;
|
||||
}
|
||||
|
||||
public function test(){
|
||||
$data = $this->request->get();
|
||||
$queue_name = $data['passageway'].'_'.$data['money'];
|
||||
$queue_length = Cache::store('redis')->lLen($queue_name);
|
||||
var_dump($queue_length);
|
||||
// 获取队列中的所有值
|
||||
$queue_values = Cache::store('redis')->lRange($queue_name, 0, $queue_length - 1);
|
||||
var_dump($queue_values);
|
||||
die();
|
||||
/*return $this->renderSuccess([], '提交成功');
|
||||
$html = @file_get_contents("http://http.tiqu.letecs.com/getip3?num=1&type=2&pro=&city=0&yys=0&port=1&pack=301270&ts=0&ys=0&cs=0&lb=1&sb=0&pb=4&mr=1®ions=");
|
||||
$result = json_decode($html,true);
|
||||
$ips = $result['data'];
|
||||
var_dump(date("Y-m-d H:i:s"));*/
|
||||
$data = $this->request->get();
|
||||
$order_id = $data['order_id'];
|
||||
var_dump($this->checkQueue($order_id));die();
|
||||
$val = OrderModel::detail($order_id);
|
||||
$codesIp = '';
|
||||
$codesPort = '';
|
||||
//获取IP组
|
||||
$iPGroup = $this->getIPGroup();
|
||||
var_dump($iPGroup);
|
||||
$codesIp = isset($iPGroup[0]['ip'])?$iPGroup[0]['ip']:'';
|
||||
$codesPort = isset($iPGroup[0]['port'])?$iPGroup[0]['port']:'';
|
||||
/*$aa = str_replace("&", "%26", $val['search_url']);
|
||||
$bb = str_replace("amp;", "", $aa);
|
||||
$stream_opts = [
|
||||
"ssl" => [
|
||||
"verify_peer" => false,
|
||||
"verify_peer_name" => false,
|
||||
]
|
||||
];
|
||||
$html = @file_get_contents(urldecode($bb), false, stream_context_create($stream_opts));
|
||||
$res = strpos($html, '该订单已完成支付');*/
|
||||
$text = $val['passageway'] == 'ZFBH5'?'订单已支付':'该订单已完成支付';
|
||||
/*if(!empty($codesIp)) {
|
||||
$res = $this->checkStatusProxy(htmlspecialchars_decode($val['search_url']), $val['passageway'], $codesIp, $codesPort, $text);
|
||||
}else {
|
||||
$res = $this->checkStatus(htmlspecialchars_decode($val['search_url']), $val['passageway'], $text);
|
||||
}*/
|
||||
$res = $this->checkStatusProxy(htmlspecialchars_decode($val['search_url']), $val['passageway'], $codesIp, $codesPort, $text);
|
||||
//$res = $this->checkStatus(htmlspecialchars_decode($val['search_url']));
|
||||
var_dump($res);
|
||||
var_dump(date("Y-m-d H:i:s"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入队列判断当前是否可执行
|
||||
* @param $code_id
|
||||
* @return
|
||||
*/
|
||||
public function checkQueue($code_id)
|
||||
{
|
||||
$message = Cache::store('redis')->lPop("queue:$code_id");
|
||||
// 如果队列为空,则写入队列
|
||||
if ($message === null || $message === false) {
|
||||
// 消息内容
|
||||
$message = 1;
|
||||
// 监控客户的消息 Hash
|
||||
Cache::store('redis')->watch("code:$code_id");
|
||||
// 开始事务
|
||||
Cache::store('redis')->multi();
|
||||
// 将消息添加到队列末尾
|
||||
Cache::store('redis')->rPush("queue:$code_id", $message);
|
||||
// 提交事务
|
||||
$result = Cache::store('redis')->exec();
|
||||
if ($result !== null && $result !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function checkStatus($url,$passageway,$text='该订单已完成支付'){
|
||||
if(in_array($passageway,['WX','SNZFBH5'])){
|
||||
$ch = curl_init();
|
||||
curl_setopt ($ch, CURLOPT_URL, $url);
|
||||
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);
|
||||
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt ($ch, CURLOPT_MAXREDIRS, 3);
|
||||
$content = curl_exec($ch);
|
||||
}else {
|
||||
$publicPath = app()->getRootPath() . 'public/';
|
||||
$escaped_url = escapeshellarg($url);
|
||||
$command = "node {$publicPath}myscript.js {$escaped_url} 2>&1";
|
||||
$content = shell_exec($command);
|
||||
}
|
||||
//$res = strpos((string)$content,$text);
|
||||
return (string)$content;
|
||||
}
|
||||
|
||||
public function checkStatusProxy($targetUrl,$passageway,$ip,$port,$text='该订单已完成支付'){
|
||||
if(in_array($passageway,['WX','SNZFBH5'])){
|
||||
// 代理服务器
|
||||
$proxyServer = "http://" . $ip . ":" . $port;
|
||||
// 隧道身份信息
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $targetUrl);
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, false);
|
||||
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
|
||||
// 设置代理服务器
|
||||
//curl_setopt($ch, CURLOPT_PROXYTYPE, 0); //http
|
||||
|
||||
curl_setopt($ch, CURLOPT_PROXYTYPE, 5); //sock5
|
||||
|
||||
curl_setopt($ch, CURLOPT_PROXY, $proxyServer);
|
||||
|
||||
// 设置隧道验证信息
|
||||
curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
|
||||
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)");
|
||||
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
|
||||
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
|
||||
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
}else{
|
||||
$publicPath = app()->getRootPath() . 'public/';
|
||||
$escaped_url = escapeshellarg($targetUrl);
|
||||
//$command = "node {$publicPath}myscript_proxy.js {$escaped_url} {$ip} {$port} 2>&1";
|
||||
$command = "node {$publicPath}myscript.js {$escaped_url} 2>&1";
|
||||
$result = shell_exec($command);
|
||||
}
|
||||
$res = strpos((string)$result,$text);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function jysx(){
|
||||
$res = $this->checkStatus('https://t-h5.einrkv.com/qAvYzu2Uraqq/ak7X8TC8Vq6TCkRvtlHzJZE2%252FeIBI0HjIVvQc0IIwXhcng%252FC2I3D0bicsYRpOpUqmtASUp6v7MiNCtPpPPV%2BKgeNvxF%2BQ%252FEXaPT886oB785uqOkFAlj6KDk8hEzwLQ4pjMuZ1xnPeU5fljvX84bwZPx9J%2Bb7nMmsvF2yTahh6FU%3D', 'zfb');
|
||||
var_dump($res);
|
||||
return;
|
||||
$this->saveLog("码校验查询开始");
|
||||
//开始
|
||||
$model = new CodeModel();
|
||||
//连接本地的 Redis 服务
|
||||
$conn = new \Redis(); // 实例化
|
||||
$conn->connect('127.0.0.1','6379');
|
||||
$codepage = $conn->get('codepagejy');
|
||||
$codepage = empty($codepage)?1:$codepage;
|
||||
$array = $model->getSx($codepage);
|
||||
|
||||
$this->saveLog("进入码校验查询,页码:".$codepage.",码数:".count($array));
|
||||
//获取IP组
|
||||
$iPGroup = $this->getIPGroup();
|
||||
foreach ($array as $k=>$val) {
|
||||
$text = $val['passageway'] == 'ZFBH5'?'订单已支付':'该订单已完成支付';
|
||||
if(isset($iPGroup[0]['ip'])) {
|
||||
$res = $this->checkStatusProxy(htmlspecialchars_decode($val['search_url']), $iPGroup[0]['ip'], $iPGroup[0]['port'], $text);
|
||||
}else {
|
||||
$res = $this->checkStatus(htmlspecialchars_decode($val['search_url']), $text);
|
||||
}
|
||||
if ($res !== false) { //支付成功
|
||||
$model->update([
|
||||
'status' => 3,
|
||||
],['code_id'=>$val['code_id']]);
|
||||
}
|
||||
}
|
||||
if(count($array) < 20){
|
||||
$conn->set('codepagejy',1);
|
||||
}else{
|
||||
$conn->set('codepagejy',$codepage+1);
|
||||
}
|
||||
$this->saveLog("码校验查询结束");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Comment as CommentModel;
|
||||
|
||||
/**
|
||||
* 商品评价控制器
|
||||
* Class Comment
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Comment extends Controller
|
||||
{
|
||||
/**
|
||||
* 商品评价列表
|
||||
* @param int $goodsId 商品ID
|
||||
* @param int|null $scoreType 评价评分
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list(int $goodsId, int $scoreType = null)
|
||||
{
|
||||
// 评价列表
|
||||
$model = new CommentModel;
|
||||
$list = $model->getCommentList($goodsId, $scoreType);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品评分总数
|
||||
* @param int $goodsId
|
||||
* @return array|\think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function total(int $goodsId)
|
||||
{
|
||||
// 指定评分总数
|
||||
$model = new CommentModel;
|
||||
$total = $model->getTotal($goodsId);
|
||||
return $this->renderSuccess(compact('total'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品评价列表 (限制数量, 用于商品详情页展示)
|
||||
* @param int $goodsId
|
||||
* @param int $limit
|
||||
* @return array|\think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function listRows(int $goodsId, int $limit = 5)
|
||||
{
|
||||
// 评价列表
|
||||
$model = new CommentModel;
|
||||
$list = $model->listRows($goodsId, $limit);
|
||||
// 评价总数量
|
||||
$total = $model->rowsTotal($goodsId);
|
||||
return $this->renderSuccess(compact('list', 'total'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,480 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\common\crypto\Crypto;
|
||||
use think\response\Json;
|
||||
use cores\BaseController;
|
||||
use app\api\model\User as UserModel;
|
||||
use app\api\model\Store as StoreModel;
|
||||
use app\api\model\Merchant as MerchantModel;
|
||||
use app\api\service\User as UserService;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
use app\common\service\SybOil;
|
||||
|
||||
/**
|
||||
* API控制器基类
|
||||
* Class Controller
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Controller extends BaseController
|
||||
{
|
||||
// 当前商城ID
|
||||
protected $storeId;
|
||||
protected $latitude;
|
||||
protected $longitude;
|
||||
protected $province;
|
||||
|
||||
/**
|
||||
* API基类初始化
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
// 当前商城id
|
||||
$this->storeId = $this->getStoreId();
|
||||
$this->latitude = input('get.latitude');
|
||||
$this->longitude = input('get.longitude');
|
||||
$res = $this->httpCurl('https://apis.map.qq.com/ws/geocoder/v1/',['location'=>$this->latitude.','.$this->longitude,'key'=>'ETFBZ-F4XCW-YOQRI-RWBQM-BAZIQ-2VFS5']);
|
||||
if(isset($res['status']) && $res['status'] == 0){
|
||||
$this->province = $res['result']['address_component']['province'];
|
||||
}
|
||||
// 验证当前商城状态
|
||||
$this->checkStore();
|
||||
// 验证当前客户端状态
|
||||
$this->checkClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前商城ID
|
||||
* @return int|null
|
||||
* @throws BaseException
|
||||
*/
|
||||
protected function getStoreId(): ?int
|
||||
{
|
||||
$storeId = getStoreId(); // app/api/common.php
|
||||
empty($storeId) && throwError('缺少必要的参数:storeId');
|
||||
return $storeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证当前商城状态
|
||||
* @return void
|
||||
* @throws BaseException
|
||||
*/
|
||||
private function checkStore(): void
|
||||
{
|
||||
// 获取当前商城信息
|
||||
$store = StoreModel::detail($this->storeId);
|
||||
if (empty($store)) {
|
||||
throwError('当前商城信息不存在');
|
||||
}
|
||||
if ($store['is_recycle'] || $store['is_delete']) {
|
||||
throwError('当前商城已删除');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证当前客户端是否允许访问
|
||||
* @throws BaseException
|
||||
*/
|
||||
private function checkClient()
|
||||
{
|
||||
$client = getPlatform();
|
||||
$settingClass = [
|
||||
'H5' => [\app\api\model\h5\Setting::class, 'checkStatus', 'H5端']
|
||||
];
|
||||
if (!isset($settingClass[$client])) {
|
||||
return;
|
||||
}
|
||||
$status = call_user_func([$settingClass[$client][0], $settingClass[$client][1]]);
|
||||
$status === false && throwError('很抱歉,当前' . $settingClass[$client][2] . '端暂不支持访问');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户信息
|
||||
* @param bool $isForce 强制验证登录
|
||||
* @return UserModel|bool|null
|
||||
* @throws BaseException
|
||||
*/
|
||||
protected function getLoginUser(bool $isForce = true)
|
||||
{
|
||||
return UserService::getCurrentLoginUser($isForce);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回封装后的 API 数据到客户端
|
||||
* @param string|null $code 状态码
|
||||
* @param string $message
|
||||
* @param string|null $errCode
|
||||
* @param string|null $errMessage
|
||||
* @param array $data
|
||||
* @return Json
|
||||
*/
|
||||
protected function oilRenderJson(string $code = null, string $message = '', string $errCode = null, string $errMessage = null, array $data = []): Json
|
||||
{
|
||||
return json(compact('code', 'message', 'errCode', 'errMessage', 'data'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回操作成功json
|
||||
* @param array|string $data
|
||||
* @param string $code
|
||||
* @param string $message
|
||||
* @return Json
|
||||
*/
|
||||
protected function oilRenderSuccess($data = [], string $code = '', string $message = ''): Json
|
||||
{
|
||||
if(empty($code)){
|
||||
$code = '00';
|
||||
}
|
||||
if(empty($message)){
|
||||
$message = config('api_status.response_code')[$code] ?? '';
|
||||
}
|
||||
if (is_string($data)) {
|
||||
$message = $data;
|
||||
$data = [];
|
||||
}
|
||||
return $this->oilRenderJson($code, $message, null, null, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回操作失败json
|
||||
* @param string $code
|
||||
* @param string $errCode
|
||||
* @param string $message
|
||||
* @param string $errMessage
|
||||
* @return Json
|
||||
*/
|
||||
protected function oilRenderError(string $code, string $errCode, string $message = '', string $errMessage = ''): Json
|
||||
{
|
||||
if(empty($message)){
|
||||
$message = config('api_status.response_code')[$code] ?? '';
|
||||
}
|
||||
if(empty($errMessage)){
|
||||
$errMessage = config('api_status.error_code')[$errCode] ?? '';
|
||||
}
|
||||
return $this->oilRenderJson($code, $message, $errCode, $errMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回封装后的 API 数据到客户端
|
||||
* @param int|null $status 状态码
|
||||
* @param string $message
|
||||
* @param array $data
|
||||
* @return Json
|
||||
*/
|
||||
protected function renderJson(int $status = null, string $message = '', array $data = []): Json
|
||||
{
|
||||
return json(compact('status', 'message', 'data'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回操作成功json
|
||||
* @param array|string $data
|
||||
* @param string $message
|
||||
* @return Json
|
||||
*/
|
||||
protected function renderSuccess($data = [], string $message = 'success'): Json
|
||||
{
|
||||
if (is_string($data)) {
|
||||
$message = $data;
|
||||
$data = [];
|
||||
}
|
||||
return $this->renderJson(config('status.success'), $message, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回操作失败json
|
||||
* @param string $message
|
||||
* @param array $data
|
||||
* @return Json
|
||||
*/
|
||||
protected function renderError(string $message = 'error', array $data = []): Json
|
||||
{
|
||||
return $this->renderJson(config('status.error'), $message, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取post数据 (数组)
|
||||
* @param $key
|
||||
* @return mixed
|
||||
*/
|
||||
protected function postData($key = null)
|
||||
{
|
||||
return $this->request->post(is_null($key) ? '' : $key . '/a');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取post数据 (数组)
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
protected function postForm(string $key = 'form')
|
||||
{
|
||||
return $this->postData($key);
|
||||
}
|
||||
|
||||
//创建sign
|
||||
public function makeSign($data,$appKey) {
|
||||
ksort($data);
|
||||
$string = $this->toUrlParams($data);
|
||||
$string = $string . "&key=" . $appKey;
|
||||
$string = md5($string);
|
||||
$result = strtoupper($string);
|
||||
return $result;
|
||||
}
|
||||
|
||||
//检验sign是否正确
|
||||
public function verifySign($data) {
|
||||
//check sign
|
||||
if (!isset($data['sign']) || !$data['sign']) {
|
||||
return ['code'=>1,'msg'=>'发送的数据签名不存在'];
|
||||
}
|
||||
|
||||
//check sign
|
||||
if (!isset($data['appid']) || !$data['appid']) {
|
||||
return ['code'=>1,'msg'=>'发送的应用参数1不存在'];
|
||||
}
|
||||
|
||||
//check timestamp
|
||||
if (!isset($data['timestamp']) || !$data['timestamp']) {
|
||||
return ['code'=>1,'msg'=>'缺少时间戳参数'];
|
||||
}
|
||||
|
||||
// 验证请求, 10分钟失效
|
||||
if (time() - $data['timestamp'] > 600) {
|
||||
return ['code'=>1,'msg'=>'验证超时, 请重新发送请求'];
|
||||
}
|
||||
$merchant = MerchantModel::detail(['appId'=>$data['appid']]);
|
||||
if (empty($merchant['merchant_id'])) {
|
||||
return ['code'=>1,'msg'=>'appid错误'];
|
||||
}
|
||||
$clientSign = $data['sign'];
|
||||
unset($data['sign']);
|
||||
$serverSign = $this->makeSign($data,$merchant['appKey']);
|
||||
if ($clientSign == $serverSign) {
|
||||
return ['code'=>0,'msg'=>'签名验证通过','merchant_id'=>$merchant['merchant_id'],'callback'=>$merchant['callback']];
|
||||
} else {
|
||||
return ['code'=>1,'msg'=>'签名不合法'];
|
||||
}
|
||||
}
|
||||
|
||||
//生成url字符串
|
||||
private function toUrlParams($values){
|
||||
$buff = "";
|
||||
foreach ($values as $k => $v)
|
||||
{
|
||||
//&& $v != ""
|
||||
if($k != "sign" && !is_array($v)){
|
||||
$buff .= $k . "=" . $v . "&";
|
||||
}
|
||||
}
|
||||
$buff = trim($buff, "&");
|
||||
return $buff;
|
||||
}
|
||||
|
||||
/**
|
||||
* http请求
|
||||
*
|
||||
* @param $url //请求地址
|
||||
* @param $params //链接后拼接的参数数组
|
||||
* @param $method //get/post
|
||||
* @param $header //请求头数组
|
||||
* @return array
|
||||
*/
|
||||
function httpCurl($url, $params, $method = 'GET', $header = array(), $multi = false): array
|
||||
{
|
||||
date_default_timezone_set('PRC'); //设置默认时区
|
||||
$opts = array( //请求参数
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_RETURNTRANSFER => 1, //将curl_exec()获取的信息以文件流的形式返回
|
||||
CURLOPT_SSL_VERIFYPEER => false, //不对认证证书来源的检查
|
||||
CURLOPT_SSL_VERIFYHOST => false, //不从证书中检查SSL加密算法是否存在
|
||||
CURLOPT_HTTPHEADER => $header, //Content-Type类型
|
||||
CURLOPT_COOKIESESSION => true,
|
||||
CURLOPT_FOLLOWLOCATION => 1, // 使用自动跳转
|
||||
CURLOPT_COOKIE => session_name() . '=' . session_id(),
|
||||
);
|
||||
|
||||
/* 根据请求类型设置特定参数 */
|
||||
switch (strtoupper($method)) {
|
||||
case 'GET':
|
||||
// 链接后拼接参数 如xxx.com?key = value & key2=value
|
||||
$opts[CURLOPT_URL] = $url . '?' . http_build_query($params);//将数组变成key=value&key2=value
|
||||
break;
|
||||
case 'POST': //判断是否传输文件
|
||||
$params = $multi ? $params : http_build_query($params); //同上
|
||||
$opts[CURLOPT_URL] = $url;
|
||||
$opts[CURLOPT_POST] = 1;
|
||||
$opts[CURLOPT_POSTFIELDS] = $params;
|
||||
break;
|
||||
default:
|
||||
throw new BaseException(['message' => '不支持的请求方式!']);
|
||||
}
|
||||
|
||||
/* 初始化并执行curl请求 */
|
||||
$ch = curl_init();
|
||||
curl_setopt_array($ch, $opts); // 数组形式设置URL和其他参数
|
||||
$data = curl_exec($ch); // URL抓取并把它传递给浏览器
|
||||
$error = curl_error($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($error){
|
||||
$data = ['code'=>2,'message'=>$error];
|
||||
}else {
|
||||
$data = json_decode($data, true);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function sendRequest($company, $url, $businessParams = [], $appendHeaders = [], $file = null)
|
||||
{
|
||||
$crypto = new Crypto($company);
|
||||
// 签名并组合header,并加密数据
|
||||
$this->saveLog(json_encode($businessParams,320));
|
||||
$requestData = $crypto->prepareRequest($appendHeaders, $businessParams);
|
||||
$businessParams = $requestData['encryptData'];
|
||||
// 构建默认的公共参数头
|
||||
$headers = [];
|
||||
foreach ($requestData['header'] as $k=>$val){
|
||||
$headers[] = $k.': '.$val;
|
||||
}
|
||||
$this->saveLog(json_encode($requestData['header'],320));
|
||||
$this->saveLog(json_encode($businessParams,320));
|
||||
// 使用 cURL 发送请求
|
||||
$ch = curl_init();
|
||||
|
||||
// 设置请求 URL
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
|
||||
// 设置请求方式为 POST
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
|
||||
// 返回结果而不是输出
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
// 包含响应头在输出中
|
||||
curl_setopt($ch, CURLOPT_HEADER, true);
|
||||
|
||||
$headers[] = 'Charset: UTF-8';
|
||||
if ($file) {
|
||||
// 如果有文件上传,设置 multipart/form-data 表单
|
||||
$filePath = $file->getPathname();
|
||||
$fileName = $file->getOriginalName();
|
||||
$fileMime = $file->getMimeType();
|
||||
$postFields = [
|
||||
'file' => new \CURLFile($filePath, $fileMime, $fileName),
|
||||
'businessParams' => json_encode($businessParams, JSON_UNESCAPED_UNICODE),
|
||||
];
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
||||
} else {
|
||||
// 如果没有文件上传,直接发送业务参数的 JSON 数据
|
||||
$postFields = json_encode($businessParams, JSON_UNESCAPED_UNICODE);
|
||||
$headers[] = 'Content-Type: application/json';
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
// 执行请求
|
||||
$response = curl_exec($ch);
|
||||
|
||||
// 检查是否有错误
|
||||
if (curl_errno($ch)) {
|
||||
$error_msg = curl_error($ch);
|
||||
curl_close($ch);
|
||||
return ['status' => '01', 'message' => $error_msg];
|
||||
}
|
||||
|
||||
// 获取响应头大小
|
||||
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
||||
|
||||
// 分离响应头和响应体
|
||||
$headerString = substr($response, 0, $header_size);
|
||||
$bodyString = substr($response, $header_size);
|
||||
|
||||
// 关闭 cURL 句柄
|
||||
curl_close($ch);
|
||||
|
||||
// 解析响应头为数组
|
||||
$headerArray = [];
|
||||
foreach (explode("\r\n", $headerString) as $header) {
|
||||
if (trim($header) !== '' && strpos($header, ':') !== false) {
|
||||
list($key, $value) = explode(': ', $header, 2);
|
||||
$headerArray[strtolower(trim($key))] = trim($value);
|
||||
}
|
||||
}
|
||||
$res = $crypto->processResponse(['header'=>$headerArray,'encryptData'=>json_decode($bodyString, true)]);
|
||||
if(!$res){
|
||||
return ['status' => '01', 'message' => '解密失败'];
|
||||
}
|
||||
// 返回结果
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* xml/json数据的POST请求
|
||||
*
|
||||
* @param $url //请求地址
|
||||
* @param $xmlData //xml 或 json数据
|
||||
*/
|
||||
public function SendData($url,$xmlData)
|
||||
{
|
||||
$curl = curl_init();
|
||||
$param[CURLOPT_URL] = $url;
|
||||
$param[CURLOPT_HEADER] = false;
|
||||
$param[CURLOPT_RETURNTRANSFER] = true;
|
||||
$param[CURLOPT_FOLLOWLOCATION] = true;
|
||||
$param[CURLOPT_POST] = true;
|
||||
$param[CURLOPT_POSTFIELDS] = $xmlData;
|
||||
$param[CURLOPT_SSL_VERIFYPEER] = false;
|
||||
$param[CURLOPT_SSL_VERIFYHOST] = false;
|
||||
curl_setopt_array($curl,$param); //传参数
|
||||
$data = curl_exec($curl); //执行命令
|
||||
curl_close($curl);
|
||||
return $data;
|
||||
}
|
||||
|
||||
// 循环创建目录
|
||||
|
||||
public function mk_dir($dir, $mode = 0777)
|
||||
{
|
||||
if (is_dir($dir) || @mkdir($dir,$mode)) return true;
|
||||
if (!$this->mk_dir(dirname($dir),$mode)) return false;
|
||||
return @mkdir($dir,$mode);
|
||||
}
|
||||
|
||||
/** 记录日志
|
||||
* @param $data
|
||||
*/
|
||||
public function saveLog($data){
|
||||
$SybOil = new SybOil();
|
||||
$SybOil->saveLogStore($data);
|
||||
}
|
||||
/** 插入订单号
|
||||
* @param $order_no
|
||||
*/
|
||||
public function insertNo($order_no){
|
||||
return $order_no;
|
||||
//return (int)$order_no-100000;
|
||||
}
|
||||
/** 获取订单号
|
||||
* @param $order_no
|
||||
*/
|
||||
public function getOrderNo($order_no){
|
||||
return $order_no;
|
||||
//return (int)$order_no+100000;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\response\Json;
|
||||
use app\api\model\Coupon as CouponModel;
|
||||
|
||||
/**
|
||||
* 优惠券中心
|
||||
* Class Coupon
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Coupon extends Controller
|
||||
{
|
||||
/**
|
||||
* 优惠券列表
|
||||
* @return Json
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list(): Json
|
||||
{
|
||||
$model = new CouponModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Express as ExpressModel;
|
||||
|
||||
/**
|
||||
* 物流公司管理
|
||||
* Class Express
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Express extends Controller
|
||||
{
|
||||
/**
|
||||
* 物流公司列表
|
||||
* @return array|\think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new ExpressModel;
|
||||
$list = $model->getAll();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\response\Json;
|
||||
use app\api\model\{Goods as GoodsModel};
|
||||
use app\api\service\{Goods as GoodsService};
|
||||
|
||||
/**
|
||||
* 商品控制器
|
||||
* Class Goods
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Goods extends Controller
|
||||
{
|
||||
/**
|
||||
* 商品列表
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list(): \think\response\Json
|
||||
{
|
||||
// 获取列表数据
|
||||
$model = new GoodsModel;
|
||||
$param = $this->request->param();
|
||||
$list = $model->getList($param);
|
||||
return $this->renderSuccess(compact('list', 'param'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品详情
|
||||
* @param int $goodsId
|
||||
* @return \think\response\Json
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function detail(int $goodsId): \think\response\Json
|
||||
{
|
||||
// 商品详情
|
||||
$model = new GoodsModel;
|
||||
$goodsInfo = $model->getDetails($goodsId);
|
||||
return $this->renderSuccess(['detail' => $goodsInfo]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品详情(基础信息)
|
||||
* @param int $goodsId
|
||||
* @param bool $verifyStatus
|
||||
* @return \think\response\Json
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function basic(int $goodsId, bool $verifyStatus = true): \think\response\Json
|
||||
{
|
||||
// 获取商品详情
|
||||
$model = new GoodsModel;
|
||||
$detail = $model->getBasic($goodsId, $verifyStatus);
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品规格数据
|
||||
* @param int $goodsId 商品ID
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function specData(int $goodsId): \think\response\Json
|
||||
{
|
||||
// 获取商品详情
|
||||
$model = new GoodsModel;
|
||||
$specData = $model->getSpecData($goodsId);
|
||||
return $this->renderSuccess(compact('specData'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品的指定SKU信息
|
||||
* @param int $goodsId 商品ID
|
||||
* @param string $goodsSkuId 商品SKU标识
|
||||
* @return Json
|
||||
*/
|
||||
public function skuInfo(int $goodsId, string $goodsSkuId): Json
|
||||
{
|
||||
$skuInfo = GoodsService::getSkuInfo($goodsId, $goodsSkuId);
|
||||
return $this->renderSuccess(compact('skuInfo'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Help as HelpModel;
|
||||
|
||||
/**
|
||||
* 帮助中心
|
||||
* Class help
|
||||
* @package app\store\controller\wxapp
|
||||
*/
|
||||
class Help extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取列表记录
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new HelpModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
/**
|
||||
* 默认控制器
|
||||
* Class Index
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Index
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
echo '当前访问的index.php,请将index.html设为默认站点入口';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\UserCoupon as UserCouponModel;
|
||||
use app\api\service\User as UserService;
|
||||
|
||||
/**
|
||||
* 用户优惠券
|
||||
* Class Coupon
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class MyCoupon extends Controller
|
||||
{
|
||||
/**
|
||||
* 用户优惠券列表
|
||||
* @return \think\response\Json
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list(): \think\response\Json
|
||||
{
|
||||
$userId = UserService::getCurrentLoginUserId();
|
||||
$model = new UserCouponModel;
|
||||
$list = $model->getList($userId, $this->request->param());
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 领取优惠券
|
||||
* @param int $couponId
|
||||
* @return \think\response\Json
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function receive(int $couponId): \think\response\Json
|
||||
{
|
||||
$model = new UserCouponModel;
|
||||
if ($model->receive($couponId)) {
|
||||
return $this->renderSuccess([], '领取成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '领取失败');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
use app\api\model\Notify as NotifyModel;
|
||||
use app\api\model\Order as OrderModel;
|
||||
use app\api\model\Merchant as MerchantModel;
|
||||
|
||||
use app\api\model\order\Record as RecordModel;
|
||||
use app\common\library\wechat\WxPay;
|
||||
use app\common\library\leshua\LsPay;
|
||||
use think\response\Json;
|
||||
|
||||
|
||||
/**
|
||||
* 支付成功异步通知接口
|
||||
* Class Notify
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Notify extends Controller
|
||||
{
|
||||
/**
|
||||
* 支付成功异步通知(微信小程序-微信支付)
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function wxpay()
|
||||
{
|
||||
// 微信支付组件:验证异步通知
|
||||
$WxPay = new WxPay();
|
||||
$WxPay->notify();
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付成功异步通知(微信小程序-乐刷支付)
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function leshua()
|
||||
{
|
||||
// 微信支付组件:验证异步通知
|
||||
$LsPay = new LsPay();
|
||||
$LsPay->notify();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送通知
|
||||
* @throws \app\common\exception\BaseException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function sendNotify()
|
||||
{
|
||||
$model = new NotifyModel();
|
||||
$array = $model->getList();
|
||||
$this->saveLog("进入回调查询");
|
||||
$order_status = ['10'=>'等待支付','20'=>'支付成功','30'=>'支付超时'];
|
||||
foreach ($array as $val){
|
||||
$status = 0;
|
||||
//发送通知
|
||||
$model = new OrderModel;
|
||||
$order = $model->getOrderDetailById($val['order_id']);
|
||||
if(is_object($order)) {
|
||||
$order_no = $this->getOrderNo($order['order_no']);
|
||||
$merchant = MerchantModel::detail($order['merchant_id']);
|
||||
$params = [
|
||||
'appid' => $merchant['appId'],
|
||||
'name' => $order['name'],
|
||||
'money' => $order['money'],
|
||||
'order_no' => $order_no,
|
||||
'order_no_sn' => $order['order_no_sn'],
|
||||
'order_status' => $order['order_status'],
|
||||
'order_status_text' => $order_status[$order['order_status']],
|
||||
'create_time' => $order['create_time'],
|
||||
];
|
||||
//$this->saveLog("回调数据,".json_encode($params,320));
|
||||
$sign = $this->makeSign($params,$merchant['appKey']);
|
||||
$params['sign'] = $sign;
|
||||
$res = $this->httpCurl($val['notify_url'], $params, 'POST');
|
||||
$this->saveLog("回调通知,订单:".$order_no.",结果:".json_encode($res,320));
|
||||
//var_dump($res);
|
||||
if ($res['code'] == '0000') {
|
||||
$status = 1;
|
||||
}
|
||||
$nm = NotifyModel::detail($val['notify_id']);
|
||||
$result = $nm->sureNotify(['status' => $status, 'num' => $nm['num'] + 1]);
|
||||
$this->saveLog("回调通知订单状态修改,订单:".$order_no.",结果:".$result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送通知
|
||||
*/
|
||||
public function notify()
|
||||
{
|
||||
$res = json_decode('{"optType":"cancel_share","amount":3,"oilCardNo":"YKA2407232037340001","type":"sub","order_id":10171,"user_id":10001,"store_id":10001}',true);
|
||||
// 油卡变动通知
|
||||
$order = OrderModel::detail(['oilCardNo'=>$res['oilCardNo'], 'amount'=>$res['amount']]);
|
||||
$res['order_id'] = $order['order_id'];
|
||||
$res['user_id'] = $order['user_id'];
|
||||
$res['store_id'] = $order['store_id'];
|
||||
$this->saveLog('油卡变动参数:'.json_encode($res));
|
||||
$RecordModel = new RecordModel();
|
||||
$this->saveLog('油卡变动记录写入结果:'. $RecordModel->add($res));
|
||||
/*$header = [
|
||||
'method' => 'syb.notify.oilCard.share',
|
||||
];
|
||||
$body = [
|
||||
'shareNo' => '11',
|
||||
'oilCardNo' => '22',
|
||||
'saleOrderNo' => '33',
|
||||
'amount' => 0.01,
|
||||
'status' =>'success',
|
||||
'msg' => '',
|
||||
'oilCardType' => 'card',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest('http://139.129.21.253/index.php?s=/api/sybNotify/notify', $body, $header);
|
||||
//var_dump($response);*/
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,584 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
use app\api\model\partners\Order as OrderModel;
|
||||
use app\common\model\Partners as PartnersModel;
|
||||
use app\common\model\PartnersGoods as PartnersGoodsModel;
|
||||
use app\common\model\Goods as GoodsModel;
|
||||
use app\api\model\GoodsSku as GoodsSkuModel;
|
||||
use app\common\crypto\RsaUtil;
|
||||
use app\common\service\goods\source\Factory as StockFactory;
|
||||
use app\common\service\IdingjuOil;
|
||||
use app\store\model\Company as CompanyModel;
|
||||
use app\store\model\order\QrCode as QrCodeModel;
|
||||
use cores\exception\BaseException;
|
||||
use think\facade\Request;
|
||||
use think\response\Json;
|
||||
use think\facade\Db;
|
||||
use think\db\exception\PDOException;
|
||||
use app\common\service\QueueService;
|
||||
use think\facade\Validate;
|
||||
|
||||
/**
|
||||
* 用户分油
|
||||
* Class OilCard
|
||||
* @package app\api\controller\v1_0_0\oil
|
||||
*/
|
||||
class OilCard extends Controller
|
||||
{
|
||||
/**
|
||||
* 用户分油
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function share()
|
||||
{
|
||||
// 获取所有 HTTP 请求头
|
||||
$headers = Request::header();
|
||||
// 获取 JSON 格式的请求体
|
||||
$jsonData = Request::instance()->getContent();
|
||||
$data = json_decode($jsonData, true);
|
||||
$appKey = $headers['appkey'] ?? '';
|
||||
$requestId = $headers['requestid'] ?? '';
|
||||
$method = $headers['method'] ?? '';
|
||||
// 请求头METHOD参数不正确
|
||||
if($method != 'syb.oil.oilCard.share'){
|
||||
return $this->oilRenderError('12', '0005');
|
||||
}
|
||||
try {
|
||||
Db::name('request_log')->insert([
|
||||
'request_id' => $requestId,
|
||||
'app_key' => $appKey,
|
||||
'create_time' => time()
|
||||
]);
|
||||
} catch (\think\Exception $e) {
|
||||
// 判断是否唯一索引冲突
|
||||
if (strpos($e->getMessage(), 'Duplicate entry') !== false) {
|
||||
return $this->oilRenderError('12', '0012'); // 请求流水号重复
|
||||
}
|
||||
// 其他数据库异常
|
||||
return $this->oilRenderError('99', '9999'); // 未知错误
|
||||
}
|
||||
|
||||
$partners = PartnersModel::detail(['appKey' => $appKey]);
|
||||
if(!$partners){
|
||||
return $this->oilRenderError('02','0004');
|
||||
}
|
||||
$crypto = new RsaUtil($partners);
|
||||
$result = $crypto->processResponse(['header'=>$headers,'encryptData'=>$data]);
|
||||
if ($result['code'] === '00') {
|
||||
// 业务处理
|
||||
$data = $result['data'];
|
||||
$orgNo = $data['orgNo'] ?? '';
|
||||
$goodsNo = $data['goodsNo'] ?? '';
|
||||
$mobile = $data['mobile'] ?? '';
|
||||
$saleOrderNo = $data['saleOrderNo'] ?? '';
|
||||
$oilCardType = $data['oilCardType'] ?? '';
|
||||
// 请求参数orgNo与请求头appKey不存在对应关系
|
||||
if($partners['orgNo'] != $orgNo){
|
||||
return $this->oilRenderError('12','0014');
|
||||
}
|
||||
if(!preg_match('/^1[3-9]\d{9}$/', $mobile)) {
|
||||
return $this->oilRenderError('12','0013', '', '手机号格式不正确');
|
||||
}
|
||||
// 销售平台订单号重复
|
||||
$order = OrderModel::detail(['partners_id' => $partners['partners_id'], 'partners_order_no' => $saleOrderNo]);
|
||||
if($order){
|
||||
return $this->oilRenderError('12','2023');
|
||||
}
|
||||
// 未找到卡券对应的信息
|
||||
$goods = GoodsModel::detail(['goods_no' => $goodsNo, 'oilCardType' => $oilCardType]);
|
||||
if(!$goods){
|
||||
return $this->oilRenderError('12','2047');
|
||||
}
|
||||
// 判断商品库存
|
||||
$detail = GoodsSkuModel::detail($goods['goods_id'], '0');
|
||||
if (1 > $detail['stock_num']) {
|
||||
return $this->oilRenderError('12','0013', '', "很抱歉,商品 [{$goods['goods_name']}] 平台库存不足");
|
||||
}
|
||||
|
||||
$partnersGoods = PartnersGoodsModel::detail($partners['partners_id'], $goods['goods_id']);
|
||||
if(!$partnersGoods || $partnersGoods['stock_num'] <= 0){
|
||||
return $this->oilRenderError('01','2010');
|
||||
}
|
||||
$OrderModel = new OrderModel();
|
||||
$oilCardNo = 'OIL' . self::createOrderNo();
|
||||
if($OrderModel->saveOrder([
|
||||
'province' => $goods['province'],
|
||||
'mobile' => $mobile,
|
||||
'oilCardType' => $oilCardType,
|
||||
'oilCardNo' => $oilCardNo,
|
||||
'partners_order_no' => $saleOrderNo,
|
||||
'partners_id' => $partners['partners_id'],
|
||||
'goods_id' => $goods['goods_id'],
|
||||
'goods_name' => $goods['goods_name'],
|
||||
'goods_no' => $goods['goods_no'],
|
||||
'goods_price' => $goods['goods_price_min'],
|
||||
'total_num' => 1,
|
||||
'total_price' => $goods['goods_price_min'],
|
||||
'total_pay_price' => $goods['goods_price_min'],
|
||||
'store_id' => $this->storeId,
|
||||
])){
|
||||
// 更新商品库存 (针对下单减库存的商品)
|
||||
$this->updateGoodsStockNum([
|
||||
[
|
||||
'deduct_stock_type' => 10,
|
||||
'goods_id' => $goods['goods_id'],
|
||||
'goods_sku_id' => $detail['id'],
|
||||
'total_num' => 1,
|
||||
]
|
||||
]);
|
||||
// 存入队列处理
|
||||
$queueService = new QueueService();
|
||||
$queueService->push('partners_queue', json_encode(['order_id'=>$OrderModel->order_id],320));
|
||||
|
||||
return $this->oilRenderSuccess([
|
||||
'oilCardNo' => $oilCardNo,
|
||||
'amount' => $goods['goods_price_min'],
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
// 错误处理
|
||||
return $this->oilRenderError($result['code'], $result['errCode'], '', $result['errMessage'] ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新商品库存 (针对下单减库存的商品)
|
||||
* @param $order
|
||||
* @return void
|
||||
*/
|
||||
private function updateGoodsStockNum($goodsList): void
|
||||
{
|
||||
StockFactory::getFactory(10)->updateGoodsStock($goodsList);
|
||||
}
|
||||
|
||||
public static function createOrderNo(): string
|
||||
{
|
||||
// 获取当前时间戳到毫秒(13位)
|
||||
$time = (int)(microtime(true) * 1000); // 返回形如 1716544103986
|
||||
|
||||
// 拼接一个 4 位随机数
|
||||
$rand = mt_rand(1000, 9999);
|
||||
|
||||
return (string)($time . $rand); // 拼接成纯数字字符串
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $goodsNo
|
||||
* @return string
|
||||
*/
|
||||
public function getCompany($goodsNo): string
|
||||
{
|
||||
switch ($goodsNo) {
|
||||
case 'djgdface100':
|
||||
case 'djgdface200':
|
||||
case 'djgdface300':
|
||||
return 'umQZhIHKofyA';
|
||||
case 'jmgxyyface100':
|
||||
case 'jmgxyyface200':
|
||||
case 'jmgxyyface300':
|
||||
|
||||
case 'jmgzface100':
|
||||
case 'jmgzface200':
|
||||
case 'jmgzface300':
|
||||
|
||||
case 'jmfjface100':
|
||||
case 'jmfjface200':
|
||||
case 'jmfjface300':
|
||||
return 'HpWqXIgYvTBg';
|
||||
case 'face003':
|
||||
return 'NKJBgaaRNdiL'; // 测试参数
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 付款二维码申请
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function getPayQrCode()
|
||||
{
|
||||
// 获取所有 HTTP 请求头
|
||||
$headers = Request::header();
|
||||
// 获取 JSON 格式的请求体
|
||||
$jsonData = Request::instance()->getContent();
|
||||
$data = json_decode($jsonData, true);
|
||||
$appKey = $headers['appkey'] ?? '';
|
||||
$requestId = $headers['requestid'] ?? '';
|
||||
$method = $headers['method'] ?? '';
|
||||
// 请求头METHOD参数不正确
|
||||
if($method != 'syb.pay.qrCode.request'){
|
||||
return $this->oilRenderError('12', '0005');
|
||||
}
|
||||
try {
|
||||
Db::name('request_log')->insert([
|
||||
'request_id' => $requestId,
|
||||
'app_key' => $appKey,
|
||||
'create_time' => time()
|
||||
]);
|
||||
} catch (\think\Exception $e) {
|
||||
// 判断是否唯一索引冲突
|
||||
if (strpos($e->getMessage(), 'Duplicate entry') !== false) {
|
||||
return $this->oilRenderError('12', '0012'); // 请求流水号重复
|
||||
}
|
||||
// 其他数据库异常
|
||||
return $this->oilRenderError('99', '9999'); // 未知错误
|
||||
}
|
||||
$partners = PartnersModel::detail(['appKey' => $appKey]);
|
||||
if(!$partners){
|
||||
return $this->oilRenderError('02','0004');
|
||||
}
|
||||
$crypto = new RsaUtil($partners);
|
||||
$result = $crypto->processResponse(['header'=>$headers,'encryptData'=>$data]);
|
||||
if ($result['code'] === '00') {
|
||||
// 业务处理
|
||||
$data = $result['data'];
|
||||
$orgNo = $data['orgNo'] ?? '';
|
||||
$oilCardNo = $data['oilCardNo'] ?? '';
|
||||
$oilCardType = $data['oilCardType'] ?? '';
|
||||
$mobile = $data['mobile'] ?? '';
|
||||
|
||||
// 请求参数orgNo与请求头appKey不存在对应关系
|
||||
if($partners['orgNo'] != $orgNo){
|
||||
return $this->oilRenderError('12','0014');
|
||||
}
|
||||
if(!preg_match('/^1[3-9]\d{9}$/', $mobile)) {
|
||||
return $this->oilRenderError('12','0013', '', '手机号格式不正确');
|
||||
}
|
||||
$order = OrderModel::detail(['oilCardNo' => $oilCardNo]);
|
||||
if(!$order) {
|
||||
return $this->oilRenderError('12','0013', '', '未找到对应订单');
|
||||
}
|
||||
$company = CompanyModel::detail(['orgNo' => $this->getCompany($order['goods_no'])]);
|
||||
if (!$company) {
|
||||
return $this->oilRenderError('12','0013', '', '没有可用参数:【' . $order['goods_no'] . '】');
|
||||
}
|
||||
$IdingjuOil = new IdingjuOil();
|
||||
// 对接平台接口
|
||||
$res = $IdingjuOil->payQrCodeRequest(['order_no'=>$oilCardNo], $company);
|
||||
|
||||
if(isset($res['code']) && $res['code'] == '1' && isset($res['data']['useQrCodeUrl'])){
|
||||
// 插入支付码记录
|
||||
$QrCodeModel = new QrCodeModel();
|
||||
$QrCodeModel->add([
|
||||
'oilCardNo'=>$order['oilCardNo'],
|
||||
'qrCode'=>$res['data']['useQrCodeUrl'],
|
||||
'amount'=>$order['goods_price'],
|
||||
'order_id'=>$order['order_id'],
|
||||
'user_id'=>0,
|
||||
'store_id'=>$order['store_id'],
|
||||
]);
|
||||
return $this->oilRenderSuccess([
|
||||
'qrCode'=>$res['data']['useQrCodeUrl']
|
||||
]);
|
||||
}else{
|
||||
return $this->oilRenderError('12','0013', '', $res['message'] ?? '');
|
||||
}
|
||||
} else {
|
||||
// 错误处理
|
||||
return $this->oilRenderError($result['code'], $result['errCode'], '', $result['errMessage'] ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 油券库存查询
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function stock()
|
||||
{
|
||||
// 获取所有 HTTP 请求头
|
||||
$headers = Request::header();
|
||||
// 获取 JSON 格式的请求体
|
||||
$jsonData = Request::instance()->getContent();
|
||||
$data = json_decode($jsonData, true);
|
||||
$appKey = $headers['appkey'] ?? '';
|
||||
$requestId = $headers['requestid'] ?? '';
|
||||
$method = $headers['method'] ?? '';
|
||||
// 请求头METHOD参数不正确
|
||||
if($method != 'syb.oil.oilCard.stockList'){
|
||||
return $this->oilRenderError('12', '0005');
|
||||
}
|
||||
try {
|
||||
Db::name('request_log')->insert([
|
||||
'request_id' => $requestId,
|
||||
'app_key' => $appKey,
|
||||
'create_time' => time()
|
||||
]);
|
||||
} catch (\think\Exception $e) {
|
||||
// 判断是否唯一索引冲突
|
||||
if (strpos($e->getMessage(), 'Duplicate entry') !== false) {
|
||||
return $this->oilRenderError('12', '0012'); // 请求流水号重复
|
||||
}
|
||||
// 其他数据库异常
|
||||
return $this->oilRenderError('99', '9999'); // 未知错误
|
||||
}
|
||||
$partners = PartnersModel::detail(['appKey' => $appKey]);
|
||||
if(!$partners){
|
||||
return $this->oilRenderError('02','0004');
|
||||
}
|
||||
$crypto = new RsaUtil($partners);
|
||||
$result = $crypto->processResponse(['header'=>$headers,'encryptData'=>$data]);
|
||||
if ($result['code'] === '00') {
|
||||
// 业务处理
|
||||
$data = $result['data'];
|
||||
$orgNo = $data['orgNo'] ?? '';
|
||||
$goodsNo = $data['goodsNo'] ?? '';
|
||||
|
||||
// 请求参数orgNo与请求头appKey不存在对应关系
|
||||
if($partners['orgNo'] != $orgNo){
|
||||
return $this->oilRenderError('12','0014');
|
||||
}
|
||||
// 未找到卡券对应的信息
|
||||
$goods = GoodsModel::detail(['goods_no' => $goodsNo]);
|
||||
if(!$goods){
|
||||
return $this->oilRenderError('12','2047');
|
||||
}
|
||||
$partnersGoods = PartnersGoodsModel::detail($partners['partners_id'], $goods['goods_id']);
|
||||
if(!$partnersGoods){
|
||||
return $this->oilRenderError('01','2010');
|
||||
}
|
||||
$orderModel = new OrderModel();
|
||||
$sucNum = $orderModel->getCount(['partners_id' => $partners['partners_id'], 'goods_id' => $goods['goods_id']], 'all');
|
||||
$useNum = $orderModel->getCount(['partners_id' => $partners['partners_id'], 'goods_id' => $goods['goods_id']], 'used');
|
||||
return $this->oilRenderSuccess([
|
||||
'goodsNo'=>$goods['goods_no'], // 商品编号
|
||||
'canOrderNum'=>$partnersGoods['stock_num'], // 剩余可下单数量
|
||||
'unUseNum'=>floatval($sucNum) - floatval($useNum), // 未使用商品数量
|
||||
'useNum'=>$useNum, // 已使用商品数量
|
||||
]);
|
||||
} else {
|
||||
// 错误处理
|
||||
return $this->oilRenderError($result['code'], $result['errCode'], '', $result['errMessage'] ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户分油记录查询
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function shareList()
|
||||
{
|
||||
// 获取所有 HTTP 请求头
|
||||
$headers = Request::header();
|
||||
// 获取 JSON 格式的请求体
|
||||
$jsonData = Request::instance()->getContent();
|
||||
$data = json_decode($jsonData, true);
|
||||
$appKey = $headers['appkey'] ?? '';
|
||||
$requestId = $headers['requestid'] ?? '';
|
||||
$method = $headers['method'] ?? '';
|
||||
// 请求头METHOD参数不正确
|
||||
if($method != 'syb.oil.oilCard.shareList'){
|
||||
return $this->oilRenderError('12', '0005');
|
||||
}
|
||||
try {
|
||||
Db::name('request_log')->insert([
|
||||
'request_id' => $requestId,
|
||||
'app_key' => $appKey,
|
||||
'create_time' => time()
|
||||
]);
|
||||
} catch (\think\Exception $e) {
|
||||
// 判断是否唯一索引冲突
|
||||
if (strpos($e->getMessage(), 'Duplicate entry') !== false) {
|
||||
return $this->oilRenderError('12', '0012'); // 请求流水号重复
|
||||
}
|
||||
// 其他数据库异常
|
||||
return $this->oilRenderError('99', '9999'); // 未知错误
|
||||
}
|
||||
$partners = PartnersModel::detail(['appKey' => $appKey]);
|
||||
if(!$partners){
|
||||
return $this->oilRenderError('02','0004');
|
||||
}
|
||||
$crypto = new RsaUtil($partners);
|
||||
$result = $crypto->processResponse(['header'=>$headers,'encryptData'=>$data]);
|
||||
if ($result['code'] === '00') {
|
||||
// 业务处理
|
||||
$data = $result['data'];
|
||||
$data['orgNo'] = $data['orgNo'] ?? '';
|
||||
$data['mobile'] = $data['mobile'] ?? '';
|
||||
$data['shareNo'] = $data['shareNo'] ?? '';
|
||||
$data['saleOrderNo'] = $data['saleOrderNo'] ?? '';
|
||||
$data['beginDate'] = $data['beginDate'] ?? '';
|
||||
$data['endDate'] = $data['endDate'] ?? '';
|
||||
$data['pageLimit'] = $data['pageLimit'] ?? 10;
|
||||
$data['pageNum'] = $data['pageNum'] ?? 1;
|
||||
$data['partners_id'] = $partners['partners_id'];
|
||||
|
||||
// 请求参数orgNo与请求头appKey不存在对应关系
|
||||
if($partners['orgNo'] != $data['orgNo']){
|
||||
return $this->oilRenderError('12','0014');
|
||||
}
|
||||
if(!preg_match('/^1[3-9]\d{9}$/', $data['mobile'])) {
|
||||
return $this->oilRenderError('12','0013', '', '手机号格式不正确');
|
||||
}
|
||||
$rule = [
|
||||
'beginDate' => 'require|dateFormat:Ymd',
|
||||
'endDate' => 'require|dateFormat:Ymd',
|
||||
'pageLimit' => 'number|between:1,30',
|
||||
'pageNum' => 'number|min:1'
|
||||
];
|
||||
|
||||
$message = [
|
||||
'beginDate.require' => 'beginDate 不能为空',
|
||||
'beginDate.dateFormat' => 'beginDate 格式错误,正确格式为 yyyyMMdd',
|
||||
'endDate.require' => 'endDate 不能为空',
|
||||
'endDate.dateFormat' => 'endDate 格式错误,正确格式为 yyyyMMdd',
|
||||
'pageLimit.number' => 'pageLimit 必须是数字',
|
||||
'pageLimit.between' => 'pageLimit 必须在 1-30 之间',
|
||||
'pageNum.number' => 'pageNum 必须是数字',
|
||||
'pageNum.min' => 'pageNum 必须大于等于 1',
|
||||
];
|
||||
|
||||
$validate = Validate::rule($rule)->message($message);
|
||||
|
||||
if (!$validate->check($data)) {
|
||||
return $this->oilRenderError('12','0013', '', $validate->getError());
|
||||
}
|
||||
|
||||
// 检查日期间隔
|
||||
$begin = date_create_from_format('Ymd', $data['beginDate']);
|
||||
$end = date_create_from_format('Ymd', $data['endDate']);
|
||||
if ($begin > $end) {
|
||||
return $this->oilRenderError('12','0013', '', 'endDate 必须大于或等于 beginDate');
|
||||
}
|
||||
if ($begin->diff($end)->days > 365) {
|
||||
return $this->oilRenderError('12','0013', '', '日期间隔不能超过 365 天');
|
||||
}
|
||||
|
||||
$model = new OrderModel;
|
||||
$list = $model->getList($data);
|
||||
// 组装返回格式
|
||||
$result = [
|
||||
'totalNum' => $list->total(),
|
||||
'totalPage' => $list->lastPage(),
|
||||
'pageNum' => $list->currentPage(),
|
||||
'pageLimit' => $list->listRows(),
|
||||
'orderList' => array_map(function ($item) {
|
||||
return [
|
||||
'shareNo' => $item['shareNo'],
|
||||
'mobile' => $item['mobile'],
|
||||
'oilCardNo' => $item['oilCardNo'],
|
||||
'productName' => $item['goods_name'],
|
||||
'num' => $item['total_num'],
|
||||
'amount' => $item['total_price'],
|
||||
'createTime' => $item['create_time'],
|
||||
];
|
||||
}, $list->items())
|
||||
];
|
||||
return $this->oilRenderSuccess($result);
|
||||
} else {
|
||||
// 错误处理
|
||||
return $this->oilRenderError($result['code'], $result['errCode'], '', $result['errMessage'] ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单状态查询
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function orderStatus()
|
||||
{
|
||||
// 获取所有 HTTP 请求头
|
||||
$headers = Request::header();
|
||||
// 获取 JSON 格式的请求体
|
||||
$jsonData = Request::instance()->getContent();
|
||||
$data = json_decode($jsonData, true);
|
||||
$appKey = $headers['appkey'] ?? '';
|
||||
$requestId = $headers['requestid'] ?? '';
|
||||
$method = $headers['method'] ?? '';
|
||||
// 请求头METHOD参数不正确
|
||||
if($method != 'syb.oil.oilCard.orderStatus'){
|
||||
return $this->oilRenderError('12', '0005');
|
||||
}
|
||||
try {
|
||||
Db::name('request_log')->insert([
|
||||
'request_id' => $requestId,
|
||||
'app_key' => $appKey,
|
||||
'create_time' => time()
|
||||
]);
|
||||
} catch (\think\Exception $e) {
|
||||
// 判断是否唯一索引冲突
|
||||
if (strpos($e->getMessage(), 'Duplicate entry') !== false) {
|
||||
return $this->oilRenderError('12', '0012'); // 请求流水号重复
|
||||
}
|
||||
// 其他数据库异常
|
||||
return $this->oilRenderError('99', '9999'); // 未知错误
|
||||
}
|
||||
$partners = PartnersModel::detail(['appKey' => $appKey]);
|
||||
if(!$partners){
|
||||
return $this->oilRenderError('02','0004');
|
||||
}
|
||||
$crypto = new RsaUtil($partners);
|
||||
$result = $crypto->processResponse(['header'=>$headers,'encryptData'=>$data]);
|
||||
if ($result['code'] === '00') {
|
||||
// 业务处理
|
||||
$data = $result['data'];
|
||||
$data['orgNo'] = $data['orgNo'] ?? '';
|
||||
$data['oilCardNo'] = $data['oilCardNo'] ?? '';
|
||||
// $data['saleOrderNo'] = $data['saleOrderNo'] ?? '';
|
||||
|
||||
// 请求参数orgNo与请求头appKey不存在对应关系
|
||||
if($partners['orgNo'] != $data['orgNo']){
|
||||
return $this->oilRenderError('12','0014');
|
||||
}
|
||||
|
||||
$rule = [
|
||||
'oilCardNo' => 'require',
|
||||
];
|
||||
|
||||
$message = [
|
||||
'oilCardNo.require' => 'oilCardNo 不能为空',
|
||||
];
|
||||
|
||||
$validate = Validate::rule($rule)->message($message);
|
||||
|
||||
if (!$validate->check($data)) {
|
||||
return $this->oilRenderError('12','0013', '', $validate->getError());
|
||||
}
|
||||
|
||||
$detail = OrderModel::detail(['oilCardNo' => $data['oilCardNo']]);
|
||||
// 组装返回格式
|
||||
$result = [
|
||||
'province' => $detail['province'],
|
||||
'mobile' => $detail['mobile'],
|
||||
'oilCardNo' => $detail['oilCardNo'],
|
||||
'shareNo' => $detail['shareNo'],
|
||||
'saleOrderNo' => $detail['partners_order_no'],
|
||||
'goods_name' => $detail['goods_name'],
|
||||
'goods_no' => $detail['goods_no'],
|
||||
'total_price' => $detail['total_price'],
|
||||
'oil_status_zsy' => $detail['oil_status_zsy'],
|
||||
'oil_status' => $detail['oil_status'],
|
||||
'oil_time' => $detail['oil_time'],
|
||||
'use_status' => $detail['use_status'],
|
||||
'use_time' => $detail['use_time'],
|
||||
];
|
||||
return $this->oilRenderSuccess($result);
|
||||
} else {
|
||||
// 错误处理
|
||||
return $this->oilRenderError($result['code'], $result['errCode'], '', $result['errMessage'] ?? '');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,401 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Goods as GoodsModel;
|
||||
use app\api\model\Order as OrderModel;
|
||||
use app\api\model\OrderGoods as OrderGoodsModel;
|
||||
use app\api\model\Code as CodeModel;
|
||||
use app\api\model\Merchant as MerchantModel;
|
||||
use app\api\model\Setting as SettingModel;
|
||||
use app\common\service\SybOil;
|
||||
use app\common\service\IdingjuOil;
|
||||
use app\store\model\Company as CompanyModel;
|
||||
use app\store\model\Express as ExpressModel;
|
||||
use app\common\enum\order\PayType as OrderPayTypeEnum;
|
||||
use app\store\model\order\QrCode as QrCodeModel;
|
||||
use cores\exception\BaseException;
|
||||
use think\facade\Request;
|
||||
use think\response\Json;
|
||||
use think\cache\driver\Redis;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
|
||||
/**
|
||||
* 我的订单控制器
|
||||
* Class Order
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Order extends Controller
|
||||
{
|
||||
private $redis = null;
|
||||
/**
|
||||
* 获取当前用户待处理的订单数量
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function todoCounts(): Json
|
||||
{
|
||||
$model = new OrderModel;
|
||||
$counts = $model->getTodoCounts();
|
||||
return $this->renderSuccess(compact('counts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 我的订单列表
|
||||
* @param string $dataType 订单类型 (all全部 payment待付款 received待发货 deliver待收货 comment待评价)
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function list(string $dataType): Json
|
||||
{
|
||||
$model = new OrderModel;
|
||||
$list = $model->getList($dataType);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单详情信息
|
||||
* @param int $orderId 订单ID
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function detail(int $orderId): Json
|
||||
{
|
||||
// 订单详情
|
||||
$model = OrderModel::getUserOrderDetail($orderId);
|
||||
return $this->renderSuccess([
|
||||
'order' => $model, // 订单详情
|
||||
'setting' => [
|
||||
// 积分名称
|
||||
'points_name' => SettingModel::getPointsName(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物流信息
|
||||
* @param int $orderId 订单ID
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function express(int $orderId): Json
|
||||
{
|
||||
// 订单信息
|
||||
$order = OrderModel::getDetail($orderId);
|
||||
if (!$order['express_no']) {
|
||||
return $this->renderError('没有物流信息');
|
||||
}
|
||||
// 获取物流信息
|
||||
$model = ExpressModel::detail($order['express_id']);
|
||||
$express = $model->dynamic($model['express_name'], $model['kuaidi100_code'], $order['express_no']);
|
||||
if ($express === false) {
|
||||
return $this->renderError($model->getError());
|
||||
}
|
||||
return $this->renderSuccess(compact('express'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订单
|
||||
* @param int $orderId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function cancel(int $orderId): Json
|
||||
{
|
||||
$model = OrderModel::getDetail($orderId);
|
||||
if ($model->cancel()) {
|
||||
return $this->renderSuccess('订单取消成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '订单取消失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认收货
|
||||
* @param int $orderId
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function receipt(int $orderId): Json
|
||||
{
|
||||
$model = OrderModel::getDetail($orderId);
|
||||
if ($model->receipt()) {
|
||||
return $this->renderSuccess('确认收货成功');
|
||||
}
|
||||
return $this->renderError($model->getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即支付
|
||||
* @param int $orderId 订单ID
|
||||
* @param int $payType 支付方式
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function pay(int $orderId, int $payType = OrderPayTypeEnum::WECHAT): Json
|
||||
{
|
||||
// 获取订单详情
|
||||
$model = OrderModel::getUserOrderDetail($orderId);
|
||||
// 订单支付事件
|
||||
if (!$model->onPay($payType)) {
|
||||
return $this->renderError($model->getError() ?: '订单支付失败');
|
||||
}
|
||||
// 构建微信支付请求
|
||||
$payment = $model->onOrderPayment($model, $payType);
|
||||
// 支付状态提醒
|
||||
return $this->renderSuccess([
|
||||
'order_id' => $model['order_id'], // 订单id
|
||||
'pay_type' => $payType, // 支付方式
|
||||
'payment' => $payment // 微信支付参数
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交订单
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function submitOrder(): Json
|
||||
{
|
||||
$data = $this->postData();
|
||||
$verify = $this->verifySign($data);
|
||||
if($verify['code'] > 0){
|
||||
return $this->renderError($verify['msg']);
|
||||
}else {
|
||||
$data['merchant_id'] = $verify['merchant_id'];
|
||||
$data['callback'] = $verify['callback'];
|
||||
$model = new OrderModel;
|
||||
$data['order_no'] = $this->insertNo($data['order_no']);
|
||||
$data['ip'] = Request::instance()->ip();
|
||||
if(!$bool = $model->putInto($data)) {
|
||||
$this->saveLog("提交订单,订单:" . $data['order_no'] . ",数据:".json_encode($data,320).",结果:" . $bool);
|
||||
return $this->renderError('插入订单失败');
|
||||
}
|
||||
$domain = Request::instance()->domain();
|
||||
|
||||
$qrcode = $domain.'/pay?passageway='.$data['passageway'].'&orderId='.$model->order_id;
|
||||
$res = [
|
||||
'qrcode'=>$qrcode,
|
||||
];
|
||||
return $this->renderSuccess($res, '提交成功');
|
||||
}
|
||||
}
|
||||
|
||||
public function generateRandomString($length = 10, $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function searchOrder(): Json
|
||||
{
|
||||
$data = $this->postData();
|
||||
$verify = $this->verifySign($data);
|
||||
if($verify['code'] > 0){
|
||||
return $this->renderError($verify['msg']);
|
||||
}else {
|
||||
$order = OrderModel::detail(['order_no'=>$data['order_no']]);
|
||||
if(empty($order['order_id'])){
|
||||
return $this->renderError('订单错误');
|
||||
}
|
||||
$res = [
|
||||
'order_no'=>$order['order_no'],
|
||||
'pay_status'=>$order['pay_status'],
|
||||
'pay_time'=>$order['pay_time']
|
||||
];
|
||||
return $this->renderSuccess($res, '提交成功');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交订单
|
||||
* @return
|
||||
* @throws \app\common\exception\BaseException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testOrder()
|
||||
{
|
||||
$data = $this->request->get();
|
||||
$money = isset($data['money'])?$data['money']:299;
|
||||
$passageway = isset($data['passageway'])?$data['passageway']:'WX';
|
||||
$shop_id = isset($data['shop_id'])?$data['shop_id']:'';
|
||||
$merchant = MerchantModel::detail($shop_id);
|
||||
if(empty($merchant['merchant_id'])){
|
||||
return $this->renderError('商户不存在');
|
||||
}
|
||||
$domain = Request::instance()->domain();
|
||||
$ip = Request::instance()->ip();
|
||||
|
||||
$data = [
|
||||
'appid'=>$merchant['appId'],
|
||||
'name'=>'系统订单',
|
||||
'money'=>$money,
|
||||
'order_no'=> 'XT'.$this->generateRandomString(10),
|
||||
'timestamp'=>time(),
|
||||
'passageway'=>$passageway,
|
||||
'notifyUrl'=>$domain.'/index.php?s=/api/notify/received',
|
||||
'ip'=>$ip,
|
||||
];
|
||||
|
||||
$data['merchant_id'] = $merchant['merchant_id'];
|
||||
$data['shop_id'] = 10033;
|
||||
|
||||
$model = new OrderModel;
|
||||
$data['order_no'] = $this->insertNo($data['order_no']);
|
||||
|
||||
if(!$bool = $model->putInto($data)) {
|
||||
$this->saveLog("提交订单,订单:" . $data['order_no'] . ",数据:".json_encode($data,320).",结果:" . $bool);
|
||||
return $this->renderError('插入系统订单失败');
|
||||
}
|
||||
$domain = Request::instance()->domain();
|
||||
$qrcode = $domain.'/pay?passageway='.$data['passageway'].'&orderId='.$model->order_id;
|
||||
/*$qrcode = $domain.'/index.php?s=/store/passport/detail&orderId='.$model->order_id;
|
||||
return $qrcode;*/
|
||||
header('location: '.$qrcode.'');
|
||||
exit();
|
||||
}
|
||||
|
||||
/** 测试发送数据
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
//Gateway::sendToClient("7f00000107d00000001b", json_encode(['type' => 'test_send']));
|
||||
var_export(Gateway::getAllUidList());
|
||||
//Gateway::sendToClient('c0a8008a07d000000002',json_encode(['type' => 'test_send']));
|
||||
if(Gateway::isUidOnline(10001))
|
||||
{
|
||||
// 在线就转发消息给对应的uid
|
||||
Gateway::sendToUid(10001, json_encode(['type' => 'test_send']));
|
||||
}
|
||||
var_export(Gateway::isUidOnline(10001));
|
||||
//Gateway::sendToUid('10001', json_encode(['type' => 'test_send']));
|
||||
//return $this->renderSuccess([], '提交成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付二维码
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function qrCode(): Json
|
||||
{
|
||||
$IdingjuOil = new IdingjuOil();
|
||||
$postData = $this->request->param();
|
||||
$postData['order_goods_id'] = $this->request->param('orderGoodsId');
|
||||
|
||||
$orderGoods = OrderGoodsModel::detail($postData['order_goods_id']);
|
||||
if($orderGoods['use_status'] != 0){
|
||||
return $this->renderError('油券已核销');
|
||||
}else {
|
||||
$company = CompanyModel::detail($orderGoods['company_id']);
|
||||
// 对接平台接口
|
||||
$res = $IdingjuOil->payQrCodeRequest(['order_no'=>$orderGoods['oilCardNo']], $company);
|
||||
if($res['code'] == '1' && isset($res['data']['useQrCodeUrl'])){
|
||||
// 插入支付码记录
|
||||
$QrCodeModel = new QrCodeModel();
|
||||
$QrCodeModel->add([
|
||||
'oilCardNo'=>$orderGoods['oilCardNo'],
|
||||
'qrCode'=>$res['data']['useQrCodeUrl'],
|
||||
'amount'=>$orderGoods['goods_price'],
|
||||
'order_id'=>$orderGoods['order_id'],
|
||||
'user_id'=>$orderGoods['user_id'],
|
||||
'store_id'=>$orderGoods['store_id'],
|
||||
]);
|
||||
$res = [
|
||||
'qrCode'=>$res['data']['useQrCodeUrl']
|
||||
];
|
||||
return $this->renderSuccess($res, '提交成功');
|
||||
}else{
|
||||
return $this->renderError('平台创建用户失败【'.($res['errMessage'] ?? $res['message']).'】');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付二维码图片
|
||||
* @return Json
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function qrCodeImg(): Json
|
||||
{
|
||||
// $res = [
|
||||
// 'base64'=> 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAGQCAIAAAAP3aGbAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAGwElEQVR4nO3cwY4bRxAFQdPY//9l+roQ4IULVoGVmoizwO0ZUok+vdf7/f4LoODvTx8A4L8SLCBDsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjIEC8gQLCBDsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjIEC8gQLCBDsIAMwQIyBAvIECwgQ7CAjK/tP/B6vbb/xKO83+/Rv99+/9PzTE3Pf+39PM3278ENC8gQLCBDsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjIEC8gQLCBDsICM9T2sqe09nWuu7VVNz3Pt/NuunWfbtb0wNywgQ7CADMECMgQLyBAsIEOwgAzBAjIEC8gQLCBDsIAMwQIyBAvIECwgQ7CADMECMs7tYU1d2+up7yVdO//0+62ff9u19zPlhgVkCBaQIVhAhmABGYIFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZggVkCBaQIVhARn4Pi5/V96SunYfPcsMCMgQLyBAsIEOwgAzBAjIEC8gQLCBDsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIMMe1h9uuid1bT/r2nn4LDcsIEOwgAzBAjIEC8gQLCBDsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjLye1j2j36va/tWdX6fv5cbFpAhWECGYAEZggVkCBaQIVhAhmABGYIFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZ5/awnraXtG36Pqf7Tdc+f9u18zyNGxaQIVhAhmABGYIFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZggVkCBaQIVhAhmABGa/pPhF8t72HBd+5YQEZggVkCBaQIVhAhmABGYIFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZggVkCBaQ8fXpA/xf23tM08/fdu382+e59vnbrp3/2nncsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjIEC8gQLCBDsIAMwQIyBAvIWN/DuranM3Vtj+navtX25197n9d+n0/jhgVkCBaQIVhAhmABGYIFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZggVkCBaQIVhAxuvavs+1faLt/ampa9/X1LX3OWVv67PcsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjIEC8gQLCBDsIAMwQIyBAvIWN/Detoe0PbzPu19TtXfz/ZeWP335oYFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZggVkCBaQIVhAhmABGYIFZAgWkCFYQMbXpw/wq2t7QNuu7Q1t87w/u7ZPd40bFpAhWECGYAEZggVkCBaQIVhAhmABGYIFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZ63tY9T2jqWvPe21f7Nr7mdret7q2n3Xt+3LDAjIEC8gQLCBDsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjIEC8gQLCDjtb13s73H9DTX9ommru1zXTvP1LX/X9vP64YFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZggVkCBaQIVhAhmABGYIFZAgWkCFYQMbXpw/wq/re09T2nlF972nq2j7U097/NjcsIEOwgAzBAjIEC8gQLCBDsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjLO7WFNXds/eto+0dT0/Vzbk5qeZ/v3sH2ea8/rhgVkCBaQIVhAhmABGYIFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZggVkCBaQIVhARn4Pi5/V97nqe1LX1J/XDQvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjIEC8gQLCBDsIAMwQIyBAvIECwgQ7CADHtYf7hr+0fT80xNz3/teZ92/ik3LCBDsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjIEC8gQLCBDsIAMwQIy8ntY2/s7ddP3c23/aOra+et7Vde+XzcsIEOwgAzBAjIEC8gQLCBDsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjLO7WFN933gu2v7Tdf2uaaund8NC8gQLCBDsIAMwQIyBAvIECwgQ7CADMECMgQLyBAsIEOwgAzBAjIEC8gQLCBDsICM17X9HYB/44YFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZggVkCBaQIVhAhmABGYIFZAgWkCFYQIZgARmCBWQIFpAhWECGYAEZggVkCBaQIVhAhmABGYIFZAgWkCFYQIZgARmCBWQIFpAhWEDGP+OBJg1/1F6rAAAAAElFTkSuQmCC'
|
||||
//// 'base64'=> ''
|
||||
// ];
|
||||
// return $this->renderSuccess($res, '提交成功');
|
||||
$IdingjuOil = new IdingjuOil();
|
||||
$postData = $this->request->param();
|
||||
$postData['order_goods_id'] = $this->request->param('orderGoodsId');
|
||||
|
||||
$orderGoods = OrderGoodsModel::detail($postData['order_goods_id']);
|
||||
if($orderGoods['use_status'] != 0){
|
||||
return $this->renderError('油券已核销');
|
||||
}else {
|
||||
/*$res = [
|
||||
'base64'=> $this->getBase64($orderGoods['qrCode'])
|
||||
];
|
||||
return $this->renderSuccess($res, '提交成功');*/
|
||||
$company = CompanyModel::detail($orderGoods['company_id']);
|
||||
// 对接平台接口
|
||||
$res = $IdingjuOil->payQrCodeRequest(['order_no'=>$orderGoods['oilCardNo']], $company);
|
||||
//$res = $IdingjuOil->payQrCodeRequest(['oilCardNo'=>$orderGoods['oilCardNo'],'shareNo'=>$orderGoods['shareNo'],'mobile'=>$orderGoods['mobile'],'oilCardType'=>$orderGoods['oilCardType']], $company);
|
||||
//if($res['code'] == '00' && isset($res['data']['qrCode'])){
|
||||
if($res['code'] == '1' && isset($res['data']['useQrCodeUrl'])){
|
||||
// 插入支付码记录
|
||||
$QrCodeModel = new QrCodeModel();
|
||||
$QrCodeModel->add([
|
||||
'oilCardNo'=>$orderGoods['oilCardNo'],
|
||||
'qrCode'=>$res['data']['useQrCodeUrl'],
|
||||
'amount'=>$orderGoods['goods_price'],
|
||||
'order_id'=>$orderGoods['order_id'],
|
||||
'user_id'=>$orderGoods['user_id'],
|
||||
'store_id'=>$orderGoods['store_id'],
|
||||
]);
|
||||
$res = [
|
||||
'base64'=> $this->getBase64($res['data']['useQrCodeUrl'])
|
||||
];
|
||||
return $this->renderSuccess($res, '提交成功');
|
||||
}else{
|
||||
return $this->renderError('平台创建用户失败【'.($res['errMessage'] ?? $res['message']).'】');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getBase64($url){
|
||||
$publicPath = app()->getRootPath() . 'public/';
|
||||
$escaped_url = escapeshellarg($url);
|
||||
$command = "node {$publicPath}myscript.js {$escaped_url} 2>&1";
|
||||
$content = shell_exec($command);
|
||||
return (string)$content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Page as PageModel;
|
||||
|
||||
/**
|
||||
* 页面控制器
|
||||
* Class Index
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Page extends Controller
|
||||
{
|
||||
/**
|
||||
* 页面数据
|
||||
* @param int|null $pageId 页面ID, 不传的话默认为首页
|
||||
* @return array|\think\response\Json
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function detail(int $pageId = null)
|
||||
{
|
||||
// 页面数据
|
||||
$model = new PageModel;
|
||||
$pageData = $model->getPageData($pageId);
|
||||
return $this->renderSuccess(compact('pageData'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\service\passport\Login as LoginService;
|
||||
|
||||
/**
|
||||
* 用户认证模块
|
||||
* Class Passport
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Passport extends Controller
|
||||
{
|
||||
/**
|
||||
* 登录接口 (需提交手机号、短信验证码、第三方用户信息)
|
||||
* @return array|\think\response\Json
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
// 执行登录
|
||||
$LoginService = new LoginService;
|
||||
if (!$LoginService->login($this->postForm())) {
|
||||
return $this->renderError($LoginService->getError());
|
||||
}
|
||||
// 用户信息
|
||||
$userInfo = $LoginService->getUserInfo();
|
||||
return $this->renderSuccess([
|
||||
'userId' => (int)$userInfo['user_id'],
|
||||
'token' => $LoginService->getToken((int)$userInfo['user_id'])
|
||||
], '登录成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信小程序快捷登录 (需提交wx.login接口返回的code、微信用户公开信息)
|
||||
* 业务流程:判断openid是否存在 -> 存在: 更新用户登录信息 -> 返回userId和token
|
||||
* -> 不存在: 返回false, 跳转到注册页面
|
||||
* @return array|\think\response\Json
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function loginMpWx()
|
||||
{
|
||||
// 微信小程序一键登录
|
||||
$LoginService = new LoginService;
|
||||
if (!$LoginService->loginMpWx($this->postForm())) {
|
||||
return $this->renderError($LoginService->getError());
|
||||
}
|
||||
// 获取登录成功后的用户信息
|
||||
$userInfo = $LoginService->getUserInfo();
|
||||
return $this->renderSuccess([
|
||||
'userId' => (int)$userInfo['user_id'],
|
||||
'token' => $LoginService->getToken((int)$userInfo['user_id'])
|
||||
], '登录成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 快捷登录: 微信小程序授权手机号登录
|
||||
* @return array|\think\response\Json
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function loginMpWxMobile()
|
||||
{
|
||||
// 微信小程序一键登录
|
||||
$LoginService = new LoginService;
|
||||
if (!$LoginService->loginMpWxMobile($this->postForm())) {
|
||||
return $this->renderError($LoginService->getError());
|
||||
}
|
||||
// 获取登录成功后的用户信息
|
||||
$userInfo = $LoginService->getUserInfo();
|
||||
return $this->renderSuccess([
|
||||
'userId' => (int)$userInfo['user_id'],
|
||||
'token' => $LoginService->getToken((int)$userInfo['user_id'])
|
||||
], '登录成功');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\recharge\Order as OrderModel;
|
||||
use app\api\model\Setting as SettingModel;
|
||||
use app\api\service\Payment as PaymentService;
|
||||
use app\api\service\User as UserService;
|
||||
use app\common\enum\OrderType as OrderTypeEnum;
|
||||
use app\common\library\helper;
|
||||
use cores\exception\BaseException;
|
||||
use app\api\model\User as UserModel;
|
||||
|
||||
/**
|
||||
* 用户充值管理
|
||||
* Class Recharge
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Recharge extends Controller
|
||||
{
|
||||
/**
|
||||
* 确认充值
|
||||
* @param int|null $planId 方案ID
|
||||
* @param float|string|null $customMoney 自定义金额
|
||||
* @return array|\think\response\Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function submit(int $planId = null, $customMoney = null)
|
||||
{
|
||||
if (getPlatform() !== 'MP-WEIXIN') {
|
||||
return $this->renderError('很抱歉,余额充值暂时仅支持微信小程序端');
|
||||
}
|
||||
// 生成充值订单
|
||||
$model = new OrderModel;
|
||||
if (!$model->createOrder($planId, (float)$customMoney)) {
|
||||
return $this->renderError($model->getError() ?: '充值失败');
|
||||
}
|
||||
// 构建微信支付
|
||||
$payment = PaymentService::wechat(
|
||||
$model['order_id'],
|
||||
$model['order_no'],
|
||||
$model['pay_price'],
|
||||
OrderTypeEnum::RECHARGE
|
||||
);
|
||||
// 充值状态提醒
|
||||
$message = ['success' => '充值成功', 'error' => '订单未支付'];
|
||||
return $this->renderSuccess(compact('payment', 'message'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认充值
|
||||
* @param float|string|null $customMoney 自定义金额
|
||||
* @param string|null $tel 手机号
|
||||
* @return array|\think\response\Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function share($customMoney = null, $tel = null)
|
||||
{
|
||||
if ($customMoney === '' || $customMoney < 0) {
|
||||
return $this->renderError('请输入正确的分销金额');
|
||||
}
|
||||
if (!preg_match('/^\d+$/', $customMoney)) {
|
||||
return $this->renderError('金额只能输入正整数');
|
||||
}
|
||||
// 充值设置
|
||||
$setting = SettingModel::getItem('recharge');
|
||||
// 验证最低充值金额
|
||||
if (helper::bccomp($customMoney, $setting['lowest_money']) === -1) {
|
||||
return $this->renderError("很抱歉,当前最低充值金额不能低于{$setting['lowest_money']}元");
|
||||
}
|
||||
// 当前用户信息
|
||||
$userInfo = UserService::getCurrentLoginUser(true);
|
||||
if($customMoney > $userInfo['balance']){
|
||||
return $this->renderError('分销金额不能大于余额');
|
||||
}
|
||||
// 分销对象
|
||||
$obj = UserModel::detail([['mobile','=',$tel]]);
|
||||
if(!$obj){
|
||||
return $this->renderError('系统中不存在此用户,请提醒用户注册');
|
||||
}
|
||||
|
||||
if($userInfo['user_id'] == $obj['user_id']){
|
||||
return $this->renderError('不能自己分给自己');
|
||||
}
|
||||
|
||||
// 减少当前用的余额
|
||||
$dec = $userInfo->rechargeToBalance($obj['mobile'],[
|
||||
'money'=>$customMoney,
|
||||
'mode'=>'dec',
|
||||
'remark'=>'转出余额',
|
||||
]);
|
||||
if(!$dec){
|
||||
return $this->renderError('转出失败');
|
||||
}
|
||||
// 增加分销对象的余额
|
||||
$inc = $obj->rechargeToBalance($userInfo['mobile'],[
|
||||
'money'=>$customMoney,
|
||||
'mode'=>'inc',
|
||||
'remark'=>'转入余额',
|
||||
]);
|
||||
if(!$inc){
|
||||
return $this->renderError('转入失败');
|
||||
}
|
||||
return $this->renderSuccess('操作成功');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\OrderRefund as OrderRefundModel;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 订单售后服务
|
||||
* Class service
|
||||
* @package app\api\controller\user\order
|
||||
*/
|
||||
class Refund extends Controller
|
||||
{
|
||||
/**
|
||||
* 售后单列表
|
||||
* @param int $state
|
||||
* @return array|\think\response\Json
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list(int $state = -1)
|
||||
{
|
||||
$model = new OrderRefundModel;
|
||||
$list = $model->getList($state);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单商品详情
|
||||
* @param int $orderGoodsId 订单商品ID
|
||||
* @return array|\think\response\Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function goods(int $orderGoodsId)
|
||||
{
|
||||
$model = new OrderRefundModel;
|
||||
$goods = $model->getRefundGoods($orderGoodsId);
|
||||
return $this->renderSuccess(compact('goods'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请售后
|
||||
* @param int $orderGoodsId 订单商品ID
|
||||
* @return array|\think\response\Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function apply(int $orderGoodsId)
|
||||
{
|
||||
// 新增售后单记录
|
||||
$model = new OrderRefundModel;
|
||||
if ($model->apply($orderGoodsId, $this->postForm())) {
|
||||
return $this->renderSuccess([], '提交成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '提交失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 售后单详情
|
||||
* @param int $orderRefundId 售后单ID
|
||||
* @return array|\think\response\Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function detail(int $orderRefundId)
|
||||
{
|
||||
$detail = OrderRefundModel::getDetail($orderRefundId, true);
|
||||
return $this->renderSuccess(compact('detail'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户发货
|
||||
* @param int $orderRefundId 售后单ID
|
||||
* @return array|\think\response\Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function delivery(int $orderRefundId)
|
||||
{
|
||||
// 售后单详情
|
||||
$model = OrderRefundModel::getDetail($orderRefundId, false);
|
||||
if ($model->delivery($this->postForm())) {
|
||||
return $this->renderSuccess([], '操作成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '提交失败');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Region as RegionModel;
|
||||
|
||||
/**
|
||||
* 地区管理
|
||||
* Class Region
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Region extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取所有地区
|
||||
* @return array|\think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function all()
|
||||
{
|
||||
$list = RegionModel::getCacheAll();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有地区(树状)
|
||||
* @return array|\think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function tree()
|
||||
{
|
||||
$list = RegionModel::getCacheTree();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\service\Setting as SettingService;
|
||||
|
||||
/**
|
||||
* 商城设置控制器
|
||||
* Class Setting
|
||||
* @package app\store\controller
|
||||
*/
|
||||
class Setting extends Controller
|
||||
{
|
||||
/**
|
||||
* 商城公共设置(仅展示可公开的信息)
|
||||
* @return array|\think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function data()
|
||||
{
|
||||
$service = new SettingService;
|
||||
$setting = $service->getPublic();
|
||||
return $this->renderSuccess(compact('setting'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Company as CompanyModel;
|
||||
use think\facade\Db;
|
||||
use think\response\Json;
|
||||
use app\common\service\SybOil;
|
||||
|
||||
/**
|
||||
* 站点列表
|
||||
* Class Station
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Station extends Controller
|
||||
{
|
||||
/**
|
||||
* 余额账单明细列表
|
||||
* @return Json
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list(): Json
|
||||
{
|
||||
$SybOil = new SybOil();
|
||||
$company = CompanyModel::detail('2');
|
||||
$param = $this->request->param();
|
||||
$province = Db::name('area')->where(array(
|
||||
['name', '=', $param['province']],
|
||||
['level', '=', 1],
|
||||
))->find();
|
||||
$city = Db::name('area')->where(array(
|
||||
['name', '=', $param['city']],
|
||||
['pid', '=', $province['code']],
|
||||
['level', '=', 2],
|
||||
))->find();
|
||||
$goods = Db::name('goods')->where(array(
|
||||
['oilCardType', '=', 'zsy_ticket'],
|
||||
['province', '=', $param['province']],
|
||||
['status', '=', 10],
|
||||
))->order('stock_total', 'desc')
|
||||
->find();
|
||||
$list = [];
|
||||
if($goods) {
|
||||
// 对接平台接口
|
||||
$res = $SybOil->baseGasStationList(['goodsNo' => $goods['goods_no'], 'longitude' => $param['longitude'], 'latitude' => $param['latitude'], 'province' => $province['code'], 'city' => $city['code']], $company);
|
||||
if (isset($res['data']['zsyResp']['count']) && $res['data']['zsyResp']['count'] > 0) {
|
||||
$lists = $res['data']['zsyResp']['lists'];
|
||||
foreach ($lists as $k => $array) {
|
||||
$list[] = [
|
||||
'id' => $k + 1,
|
||||
'name' => $array['name'],
|
||||
'brand' => $array['brand'] == 1 ? '中国石油' : '中国BP',
|
||||
'latitude' => $array['lat'],
|
||||
'longitude' => $array['lng'],
|
||||
'address' => '',
|
||||
'distance' => $array['nearBy'],
|
||||
'width' => 30,
|
||||
'height' => 30,
|
||||
'iconPath' => '/static/marker.png',
|
||||
'stationCode' => $array['stationCode'],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Company as CompanyModel;
|
||||
use app\store\model\User as UserModel;
|
||||
use app\common\crypto\Crypto;
|
||||
use app\common\service\SybOil;
|
||||
use app\store\model\card\CardLog as CardLogModel;
|
||||
use think\facade\Db;
|
||||
use think\facade\Request;
|
||||
use app\common\service\QueueService;
|
||||
/**
|
||||
* 加油e卡通通知接口
|
||||
* Class SybNotify
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class SybNotify extends Controller
|
||||
{
|
||||
|
||||
public function yanzheng()
|
||||
{
|
||||
// 拿到队列数据处理
|
||||
$data = json_decode('{"header":{"content-length":"428","connection":"keep-alive","host":"139.129.21.253","pragma":"no-cache","cache-control":"no-cache","content-type":"application/json;charset=UTF-8","version":"1.0.0","accept-language":"zh-CN,zh;q=0.8","accept-encoding":"gzip, deflate","appkey":"qlv4l3law1","sign":"R9A4Zw5/52bq2gsmaxGMt7QcSPr9RWuxSp40D36VKSeS8uZfifTD/Yknzt6uVZn5G5rhEgDumFiLo7A/eAgo5u/tA+AMizZ3sHHv7mu0dLPO8b9LUdf01I7nxYqyqPatnNJGIgq6dTZyyNdE4YaTEShemnlEC/XI9O1T29obpt8=","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36 Hutool","requestid":"8232721b-ef72-40a7-aa24-bdbb536fd602","method":"syb.notify.oilCard.share","accept":"text/html,application/json,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},"res":{"shareNo":"CDV2408082020420001","amount":"200.00","saleOrderNo":"2024080897521014","oilCardType":"zsy_ticket","oilCardNo":"CDV2408082020420001","status":"success"}}', true);
|
||||
$headers = $data['header'];
|
||||
$res = $data['res'];
|
||||
// 存入队列处理
|
||||
$queueService = new QueueService();
|
||||
$queueService->push('callback_queue', json_encode(['header'=>$headers,'res'=>$res],320));
|
||||
}
|
||||
|
||||
/** 通知接口
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function notifyOld()
|
||||
{
|
||||
// 获取所有 HTTP 请求头
|
||||
$headers = Request::header();
|
||||
// 获取 JSON 格式的请求体
|
||||
$jsonData = Request::instance()->getContent();
|
||||
$data = json_decode($jsonData, true);
|
||||
$this->saveLog('callback_queue回调加密参数原文;header:'.json_encode($headers).',body:'.$jsonData);
|
||||
$appKey = $headers['appKey'] ?? $headers['appkey'];
|
||||
$company = CompanyModel::detail(['appKey' => $appKey]);
|
||||
$crypto = new Crypto($company);
|
||||
$res = $crypto->processResponse(['header'=>$headers,'encryptData'=>$data]);
|
||||
// 记录日志等
|
||||
$this->saveLog('callback_queue回调参数解密,'.$headers['method'].":".json_encode($res,320));
|
||||
// 检查 JSON 解码是否成功
|
||||
if (!$res) {
|
||||
return json(['code' => '03', 'message' => '报文解密异常']);
|
||||
}
|
||||
// 存入队列处理
|
||||
$queueService = new QueueService();
|
||||
$queueService->push('callback_queue', json_encode(['header'=>$headers,'res'=>$res],320));
|
||||
// 返回成功的 JSON 响应
|
||||
return json(['code' => '00', 'message' => '请求成功']);
|
||||
}
|
||||
|
||||
/** 分油下单回到
|
||||
* @return string
|
||||
*/
|
||||
public function notify()
|
||||
{
|
||||
// 获取所有 HTTP 请求头
|
||||
$headers = Request::header();
|
||||
// 获取 GET 参数
|
||||
$data = Request::param();
|
||||
$this->saveLog('callback_queue回调参数原文;header:'.json_encode($headers).',body:'.json_encode($data));
|
||||
/*$appKey = $headers['appKey'] ?? $headers['appkey'];
|
||||
$company = CompanyModel::detail(['appKey' => $appKey]);
|
||||
$crypto = new Crypto($company);
|
||||
$res = $crypto->processResponse(['header'=>$headers,'encryptData'=>$data]);
|
||||
// 记录日志等
|
||||
$this->saveLog('callback_queue回调参数解密,'.$headers['method'].":".json_encode($res,320));
|
||||
// 检查 JSON 解码是否成功
|
||||
if (!$res) {
|
||||
return json(['code' => '03', 'message' => '报文解密异常']);
|
||||
}*/
|
||||
$headers['method'] = 'oil';
|
||||
// 存入队列处理
|
||||
$queueService = new QueueService();
|
||||
$queueService->push('callback_queue', json_encode(['header'=>$headers,'res'=>$data],320));
|
||||
// 返回成功的 JSON 响应
|
||||
return 'OK';
|
||||
}
|
||||
|
||||
/** 使用结果回调
|
||||
* @return string
|
||||
*/
|
||||
public function use()
|
||||
{
|
||||
// 获取所有 HTTP 请求头
|
||||
$headers = Request::header();
|
||||
// 获取 GET 参数
|
||||
$data = Request::param();
|
||||
$this->saveLog('callback_queue回调参数原文;header:'.json_encode($headers).',body:'.json_encode($data));
|
||||
/*$appKey = $headers['appKey'] ?? $headers['appkey'];
|
||||
$company = CompanyModel::detail(['appKey' => $appKey]);
|
||||
$crypto = new Crypto($company);
|
||||
$res = $crypto->processResponse(['header'=>$headers,'encryptData'=>$data]);
|
||||
// 记录日志等
|
||||
$this->saveLog('callback_queue回调参数解密,'.$headers['method'].":".json_encode($res,320));
|
||||
// 检查 JSON 解码是否成功
|
||||
if (!$res) {
|
||||
return json(['code' => '03', 'message' => '报文解密异常']);
|
||||
}*/
|
||||
$headers['method'] = 'use';
|
||||
// 存入队列处理
|
||||
$queueService = new QueueService();
|
||||
$queueService->push('callback_queue', json_encode(['header'=>$headers,'res'=>$data],320));
|
||||
// 返回成功的 JSON 响应
|
||||
return 'OK';
|
||||
}
|
||||
|
||||
/** 分油下单回到
|
||||
* @return string
|
||||
*/
|
||||
public function partnersNotify()
|
||||
{
|
||||
// 获取所有 HTTP 请求头
|
||||
$headers = Request::header();
|
||||
// 获取 GET 参数
|
||||
$data = Request::param();
|
||||
$this->saveLog('callback_queue回调参数原文;header:'.json_encode($headers).',body:'.json_encode($data));
|
||||
$headers['method'] = 'oil_partners';
|
||||
// 存入队列处理
|
||||
$queueService = new QueueService();
|
||||
$queueService->push('callback_queue', json_encode(['header'=>$headers,'res'=>$data],320));
|
||||
// 返回成功的 JSON 响应
|
||||
return 'OK';
|
||||
}
|
||||
|
||||
/** 使用结果回调
|
||||
* @return string
|
||||
*/
|
||||
public function partnersUse()
|
||||
{
|
||||
// 获取所有 HTTP 请求头
|
||||
$headers = Request::header();
|
||||
// 获取 GET 参数
|
||||
$data = Request::param();
|
||||
$this->saveLog('callback_queue回调参数原文;header:'.json_encode($headers).',body:'.json_encode($data));
|
||||
$headers['method'] = 'use_partners';
|
||||
// 存入队列处理
|
||||
$queueService = new QueueService();
|
||||
$queueService->push('callback_queue', json_encode(['header'=>$headers,'res'=>$data],320));
|
||||
// 返回成功的 JSON 响应
|
||||
return 'OK';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use app\api\model\Setting as SettingModel;
|
||||
use app\api\model\UploadFile as UploadFileModel;
|
||||
use app\api\service\User as UserService;
|
||||
use app\common\enum\Setting as SettingEnum;
|
||||
use app\common\enum\file\FileType as FileTypeEnum;
|
||||
use app\common\library\storage\Driver as StorageDriver;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 文件库管理
|
||||
* Class Upload
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class Upload extends Controller
|
||||
{
|
||||
// 当前商城的上传设置
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
// 验证登录
|
||||
UserService::isLogin(true);
|
||||
// 存储配置信息
|
||||
$this->config = SettingModel::getItem(SettingEnum::STORAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片上传接口
|
||||
* @return array|\think\response\Json
|
||||
* @throws BaseException
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function image()
|
||||
{
|
||||
// 当前用户ID
|
||||
$userId = UserService::getCurrentLoginUserId();
|
||||
// 实例化存储驱动
|
||||
$storage = new StorageDriver($this->config);
|
||||
// 设置上传文件的信息
|
||||
$storage->setUploadFile('file')
|
||||
->setRootDirName((string)$this->storeId)
|
||||
->setValidationScene('image');
|
||||
// 执行文件上传
|
||||
if (!$storage->upload()) {
|
||||
return $this->renderError('图片上传失败:' . $storage->getError());
|
||||
}
|
||||
// 文件信息
|
||||
$fileInfo = $storage->getSaveFileInfo();
|
||||
// 添加文件库记录
|
||||
$model = new UploadFileModel;
|
||||
$model->add($fileInfo, FileTypeEnum::IMAGE, $userId);
|
||||
// 图片上传成功
|
||||
return $this->renderSuccess(['fileInfo' => $model->toArray()], '图片上传成功');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use think\response\Json;
|
||||
use app\api\model\User as UserModel;
|
||||
use app\api\model\UserCoupon as UserCouponModel;
|
||||
use app\api\service\User as UserService;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 用户管理
|
||||
* Class User
|
||||
* @package app\api
|
||||
*/
|
||||
class User extends Controller
|
||||
{
|
||||
/**
|
||||
* 当前用户详情
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function info(): Json
|
||||
{
|
||||
// 当前用户信息
|
||||
$userInfo = UserService::getCurrentLoginUser(true);
|
||||
// 获取用户头像
|
||||
$userInfo['avatar'];
|
||||
// 获取会员等级
|
||||
$userInfo['grade'];
|
||||
return $this->renderSuccess(compact('userInfo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 账户资产
|
||||
* @return Json
|
||||
* @throws BaseException
|
||||
*/
|
||||
public function assets(): Json
|
||||
{
|
||||
// 当前用户信息
|
||||
$userInfo = UserService::getCurrentLoginUser(true);
|
||||
// 用户优惠券模型
|
||||
$model = new UserCouponModel;
|
||||
// 返回数据
|
||||
return $this->renderSuccess([
|
||||
'assets' => [
|
||||
'balance' => $userInfo['balance'], // 账户余额
|
||||
'points' => $userInfo['points'], // 会员积分
|
||||
'coupon' => $model->getCount($userInfo['user_id']), // 优惠券数量(可用)
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号绑定
|
||||
* @return Json
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function bindMobile(): Json
|
||||
{
|
||||
$model = new UserModel;
|
||||
if (!$model->bindMobile($this->postForm())) {
|
||||
return $this->renderSuccess($model->getError() ?: '操作失败');
|
||||
}
|
||||
return $this->renderSuccess('恭喜您,手机号绑定成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改个人信息(头像昵称)
|
||||
* @return Json
|
||||
* @throws \cores\exception\BaseException
|
||||
*/
|
||||
public function personal(): Json
|
||||
{
|
||||
$model = new UserModel;
|
||||
if (!$model->personal($this->postForm())) {
|
||||
return $this->renderSuccess($model->getError() ?: '操作失败');
|
||||
}
|
||||
return $this->renderSuccess('恭喜您,信息修改成功');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\article;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
use app\api\model\article\Category as CategoryModel;
|
||||
|
||||
/**
|
||||
* 文章分类
|
||||
* Class Category
|
||||
* @package app\api\controller\article
|
||||
*/
|
||||
class Category extends Controller
|
||||
{
|
||||
/**
|
||||
* 文章分类列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new CategoryModel;
|
||||
$list = $model->getShowList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\balance;
|
||||
|
||||
use think\response\Json;
|
||||
use app\api\controller\Controller;
|
||||
use app\api\model\user\BalanceLog as BalanceLogModel;
|
||||
|
||||
/**
|
||||
* 余额账单明细
|
||||
* Class Log
|
||||
* @package app\api\controller\balance
|
||||
*/
|
||||
class Log extends Controller
|
||||
{
|
||||
/**
|
||||
* 余额账单明细列表
|
||||
* @return Json
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list(): Json
|
||||
{
|
||||
$model = new BalanceLogModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\card;
|
||||
|
||||
use think\response\Json;
|
||||
use app\api\controller\Controller;
|
||||
use app\api\model\card\CardLog as CardLogModel;
|
||||
|
||||
/**
|
||||
* 兑换明细
|
||||
* Class Log
|
||||
* @package app\api\controller\card
|
||||
*/
|
||||
class Log extends Controller
|
||||
{
|
||||
/**
|
||||
* 余额账单明细列表
|
||||
* @return Json
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list(): Json
|
||||
{
|
||||
$model = new CardLogModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\goods;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
use app\api\model\goods\Service as ServiceModel;
|
||||
|
||||
/**
|
||||
* 商品服务与承诺管理
|
||||
* Class Service
|
||||
* @package app\store\controller\goods
|
||||
*/
|
||||
class Service extends Controller
|
||||
{
|
||||
/**
|
||||
* 获取指定商品的服务与承诺
|
||||
* @param int $goodsId
|
||||
* @return array|\think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function list(int $goodsId)
|
||||
{
|
||||
$model = new ServiceModel;
|
||||
$list = $model->getListByGoods($goodsId);
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\order;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
use app\api\model\Order as OrderModel;
|
||||
use app\api\model\Comment as CommentModel;
|
||||
use app\api\model\OrderGoods as OrderGoodsModel;
|
||||
|
||||
/**
|
||||
* 订单评价管理
|
||||
* Class Comment
|
||||
* @package app\api\controller\order
|
||||
*/
|
||||
class Comment extends Controller
|
||||
{
|
||||
/**
|
||||
* 待评价订单商品列表
|
||||
* @param int $orderId
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function list(int $orderId)
|
||||
{
|
||||
// 订单信息
|
||||
$orderInfo = OrderModel::getDetail($orderId);
|
||||
// 验证订单是否已完成
|
||||
$model = new CommentModel;
|
||||
if (!$model->checkOrderAllowComment($orderInfo)) {
|
||||
return $this->renderError($model->getError());
|
||||
}
|
||||
// 待评价商品列表
|
||||
$goodsList = OrderGoodsModel::getNotCommentGoodsList($orderId);
|
||||
if ($goodsList->isEmpty()) {
|
||||
return $this->renderError('该订单没有可评价的商品');
|
||||
}
|
||||
return $this->renderSuccess(compact('goodsList'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建商品评价
|
||||
* @param int $orderId
|
||||
* @return array|\think\response\Json
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function submit(int $orderId)
|
||||
{
|
||||
// 订单信息
|
||||
$orderInfo = OrderModel::getDetail($orderId);
|
||||
// 验证订单是否已完成
|
||||
$model = new CommentModel;
|
||||
if (!$model->checkOrderAllowComment($orderInfo)) {
|
||||
return $this->renderError($model->getError());
|
||||
}
|
||||
// 待评价商品列表
|
||||
$goodsList = OrderGoodsModel::getNotCommentGoodsList($orderId);
|
||||
if ($goodsList->isEmpty()) {
|
||||
return $this->renderError('该订单没有可评价的商品');
|
||||
}
|
||||
// 提交商品评价
|
||||
$model = new CommentModel;
|
||||
if ($model->increased($orderInfo, $goodsList, $this->postForm())) {
|
||||
return $this->renderSuccess([], '评价发表成功');
|
||||
}
|
||||
return $this->renderError($model->getError() ?: '评价发表失败');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\points;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
use app\api\model\user\PointsLog as PointsLogModel;
|
||||
|
||||
/**
|
||||
* 积分明细
|
||||
* Class Log
|
||||
* @package app\api\controller\balance
|
||||
*/
|
||||
class Log extends Controller
|
||||
{
|
||||
/**
|
||||
* 积分明细列表
|
||||
* @return array
|
||||
* @throws \cores\exception\BaseException
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new PointsLogModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\recharge;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
use app\api\model\recharge\Order as OrderModel;
|
||||
use cores\exception\BaseException;
|
||||
|
||||
/**
|
||||
* 充值记录管理
|
||||
* Class Order
|
||||
* @package app\api\controller\recharge
|
||||
*/
|
||||
class Order extends Controller
|
||||
{
|
||||
/**
|
||||
* 我的充值记录列表
|
||||
* @return array
|
||||
* @throws BaseException
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new OrderModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\recharge;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
use app\api\model\recharge\Plan as PlanModel;
|
||||
|
||||
/**
|
||||
* 充值套餐管理
|
||||
* Class Plan
|
||||
* @package app\api\controller\recharge
|
||||
*/
|
||||
class Plan extends Controller
|
||||
{
|
||||
/**
|
||||
* 充值套餐列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function list()
|
||||
{
|
||||
$model = new PlanModel;
|
||||
$list = $model->getList();
|
||||
return $this->renderSuccess(compact('list'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\syb;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
|
||||
/**
|
||||
* 加油e卡通基础数据
|
||||
* Class SybBase
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class SybBase extends Controller
|
||||
{
|
||||
/** 油站查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function baseGasStationList($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.base.gasStation.list',
|
||||
];
|
||||
$body = [
|
||||
'province' => $data['province']??'',
|
||||
'city' => $data['city']??'',
|
||||
'longitude' => $data['longitude']??'',
|
||||
'latitude' => $data['latitude']??'',
|
||||
'pageLimit' => $data['pageLimit']??'',
|
||||
'pageNum' => $data['pageNum']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/base/gasStationList', $body, $header);
|
||||
$this->saveLog("油站查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 文件上传接口
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function baseFileUpload($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.base.file.upload',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'file' => request()->file('file'),
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/base/uploadFile', $body, $header);
|
||||
$this->saveLog("文件上传接口".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\syb;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
use app\api\model\Order as OrderModel;
|
||||
use app\api\model\Order\Record as RecordModel;
|
||||
use app\common\crypto\Crypto;
|
||||
use think\facade\Request;
|
||||
|
||||
/**
|
||||
* 加油e卡通通知接口
|
||||
* Class SybUser
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class SybNotify extends Controller
|
||||
{
|
||||
/** 通知接口
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function notify()
|
||||
{
|
||||
// 获取所有 HTTP 请求头
|
||||
$headers = Request::header();
|
||||
|
||||
// 获取 JSON 格式的请求体
|
||||
$jsonData = Request::instance()->getContent();
|
||||
$data = json_decode($jsonData, true);
|
||||
|
||||
$crypto = new Crypto();
|
||||
$res = $crypto->processResponse(['header'=>$headers,'encryptData'=>$data]);
|
||||
// 检查 JSON 解码是否成功
|
||||
if (!$res) {
|
||||
return json(['code' => '03', 'message' => '报文解密异常']);
|
||||
}
|
||||
// 此处可以根据业务逻辑处理接收到的数据
|
||||
switch ($headers['method']) {
|
||||
case "syb.notify.pay.result":
|
||||
// 二维码交易结果通知
|
||||
$where = array(
|
||||
['oilCardNo', '=', $res['oilCardNo']],
|
||||
['amount', '=', $res['amount']],
|
||||
);
|
||||
$field['qrCode'] = $res['qrCode'];
|
||||
if($res['status'] == 'success'){
|
||||
$field['order_status'] = 30;
|
||||
$field['use_status'] = 1;
|
||||
}else{
|
||||
$field['use_text'] = $res['errMessage'];
|
||||
}
|
||||
OrderModel::orderUpdate($where, $field);
|
||||
break;
|
||||
case "syb.notify.oilCard.change":
|
||||
// 油卡变动通知
|
||||
$order = OrderModel::detail(['oilCardNo'=>$res['oilCardNo'], 'amount'=>$res['amount']]);
|
||||
$res['order_id'] = $order['order_id'];
|
||||
$res['user_id'] = $order['user_id'];
|
||||
$RecordModel = new RecordModel();
|
||||
$RecordModel->add($res);
|
||||
break;
|
||||
case "syb.notify.oilCard.share":
|
||||
// 分油结果通知
|
||||
$where = array(
|
||||
['oilCardNo', '=', $res['oilCardNo']],
|
||||
['amount', '=', $res['amount']],
|
||||
);
|
||||
$field = ['oil_time' => time()];
|
||||
if($res['status'] == 'success'){
|
||||
$field['order_status'] = 20;
|
||||
$field['oil_status'] = 1;
|
||||
}else{
|
||||
$field['order_status'] = 60;
|
||||
$field['oil_status'] = 0;
|
||||
$field['oil_text'] = $res['msg'];
|
||||
}
|
||||
OrderModel::orderUpdate($where, $field);
|
||||
break;
|
||||
default:
|
||||
return json(['code' => '03', 'message' => '报文解密异常']);
|
||||
}
|
||||
|
||||
// 记录日志等
|
||||
$this->saveLog($headers['method'].":".json_encode($res,320));
|
||||
// 返回成功的 JSON 响应
|
||||
return json(['code' => '00', 'message' => '请求成功']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\syb;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
|
||||
/**
|
||||
* 加油e卡通油卡操作
|
||||
* Class SybOil
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class SybOil extends Controller
|
||||
{
|
||||
/** 油卡查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function oilOilCardSelect($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.oil.oilCard.select',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'mobile' => $data['mobile']??'',
|
||||
'userNo' => $data['userNo']??'',
|
||||
'oilCardNo' => $data['oilCardNo']??'',
|
||||
'pageLimit' => $data['pageLimit']??'10',
|
||||
'pageNum' => $data['pageNum']??'1',
|
||||
'oilCardType' => $data['oilCardType']??'card', //不填时默认为“E卡通平台自营卡”
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/oil/oilCard/select', $body, $header);
|
||||
$this->saveLog("油卡查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 用户分油
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function oilOilCardShare($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.oil.oilCard.share',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'goodsNo' => $data['goodsNo']??'',
|
||||
'amount' => $data['oilCardType']=='card' ? round($data['amount'],2) : '',
|
||||
'userNo' => $data['userNo']??'',
|
||||
'mobile' => $data['mobile']??'',
|
||||
'saleOrderNo' => $data['saleOrderNo']??'',
|
||||
'oilCardType' => $data['oilCardType']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/oil/oilCard/share', $body, $header);
|
||||
$this->saveLog("用户分油".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 分油撤销接口
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function oilOilCardCancelShare($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.oil.oilCard.cancelShare',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'shareNo' => $data['shareNo']??'',
|
||||
'amount' => !empty($data['amount']??'') ? round($data['amount'],2) : '',
|
||||
'saleOrderNo' => $data['saleOrderNo']??'',
|
||||
'type' => $data['type']??'',
|
||||
'oilCardType' => $data['oilCardType']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/oil/oilCard/cancelShare', $body, $header);
|
||||
$this->saveLog("分油撤销接口".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 用户分油记录查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function oilOilCardShareList($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.oil.oilCard.shareList',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'userNo' => $data['userNo']??'',
|
||||
'mobile' => $data['mobile']??'',
|
||||
'shareNo' => $data['shareNo']??'',
|
||||
'saleOrderNo' => $data['saleOrderNo']??'',
|
||||
'beginDate' => $data['beginDate']??'',
|
||||
'endDate' => $data['endDate']??'',
|
||||
'pageLimit' => $data['pageLimit']??'',
|
||||
'pageNum' => $data['pageNum']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/opt/oilCard/shareList', $body, $header);
|
||||
$this->saveLog("用户分油记录查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\syb;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
|
||||
/**
|
||||
* 加油e卡通加油记录查询
|
||||
* Class SybOrder
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class SybOrder extends Controller
|
||||
{
|
||||
/** 加油记录查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function orderListSale($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.order.list.sale',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'mobile' => $data['mobile']??'',
|
||||
'shareNo' => $data['shareNo']??'',
|
||||
'beginDate' => $data['beginDate']??'',
|
||||
'endDate' => $data['endDate']??'',
|
||||
'pageLimit' => $data['pageLimit']??'',
|
||||
'pageNum' => $data['pageNum']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/opt/list/sale', $body, $header);
|
||||
$this->saveLog("加油记录查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\syb;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
|
||||
/**
|
||||
* 加油e卡通支付财务
|
||||
* Class SybOil
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class SybPay extends Controller
|
||||
{
|
||||
/** 付款二维码申请
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function payQrCodeRequest($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.pay.qrCode.request',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'oilCardNo' => $data['oilCardNo']??'',
|
||||
'mobile' => $data['mobile']??'',
|
||||
'longitude' => $data['longitude']??'',
|
||||
'oilCardType' => $data['oilCardType']??'',
|
||||
'latitude' => $data['latitude']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/pay/getPayQrCode', $body, $header);
|
||||
$this->saveLog("付款二维码申请".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 主扫订单创建
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function payActiveScan($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.pay.active.scan',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'oilCardNo' => $data['oilCardNo']??'',
|
||||
'qrInfo' => $data['qrInfo']??'',
|
||||
'longitude' => $data['longitude']??'',
|
||||
'latitude' => $data['latitude']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/pay/activeScan', $body, $header);
|
||||
$this->saveLog("主扫订单创建".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 主扫订单信息确认
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function payActiveVerify($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.pay.active.verify',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'activeOrderId' => $data['activeOrderId']??'',
|
||||
'amount' => !empty($data['amount']??'') ? round($data['amount'],2) : '',
|
||||
'deviceId' => $data['deviceId']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/pay/activeVerify', $body, $header);
|
||||
$this->saveLog("主扫订单信息确认".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 账户余额查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function payAmountBalance($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.pay.account.balance',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/finance/account/balance', $body, $header);
|
||||
$this->saveLog("账户余额查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 申请发票
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function payInvoiceRequest($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.pay.invoice.request',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'amount' => !empty($data['amount']??'') ? round($data['amount'],2) : '',
|
||||
'oilNo' => $data['oilNo']??'',
|
||||
'invoiceAddress' => $data['invoiceAddress']??'',
|
||||
'invoiceHeader' => $data['invoiceHeader']??'',
|
||||
'invoicePhone' => $data['invoicePhone']??'',
|
||||
'invoiceOpenBank' => $data['invoiceOpenBank']??'',
|
||||
'taxIdentifyNo' => $data['taxIdentifyNo']??'',
|
||||
'invoiceCardNo' => $data['invoiceCardNo']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/finance/invoice/request', $body, $header);
|
||||
$this->saveLog("申请发票".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 开票状态查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function payInvoiceStatus($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.pay.invoice.status',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'invoiceNo' => $data['invoiceNo']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/finance/invoice/status', $body, $header);
|
||||
$this->saveLog("开票状态查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\syb;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
|
||||
/**
|
||||
* 加油e卡通用户账户
|
||||
* Class SybUser
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class SybUser extends Controller
|
||||
{
|
||||
/** 添加用户
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function userOptAdd($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.user.opt.add',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'mobile' => $data['mobile']??'',
|
||||
'userName' => $data['userName']??'',
|
||||
'userIdCard' => $data['userIdCard']??'',
|
||||
'userType' => $data['userType']??'user',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/user/opt/add', $body, $header);
|
||||
$this->saveLog("添加用户".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 管理系统
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.zizai.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 自在科技
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\api\controller\syb;
|
||||
|
||||
use app\api\controller\Controller;
|
||||
|
||||
/**
|
||||
* 优惠券
|
||||
* Class SybVoucher
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class SybVoucher extends Controller
|
||||
{
|
||||
/** 优惠券下单
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function voucherCreateOrder($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.opt.voucher.createOrder',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'model' => $data['model']??'',
|
||||
'voucherAmount' => $data['voucherAmount']??'',
|
||||
'fullAmount' => $data['fullAmount']??'',
|
||||
'storeNum' => $data['storeNum']??'',
|
||||
'validTime' => $data['validTime']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/voucher/createOrder', $body, $header);
|
||||
$this->saveLog("优惠券下单".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 优惠券订单查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function voucherOrderListPage($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.opt.voucher.order.listPage',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'orderNo' => $data['orderNo']??'',
|
||||
'model' => $data['model']??'',
|
||||
'pageLimit' => $data['pageLimit']??'',
|
||||
'pageNum' => $data['pageNum']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/voucher/order/listPage', $body, $header);
|
||||
$this->saveLog("优惠券订单查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/** 卡券查询
|
||||
* @param $data
|
||||
* @return array|mixed|string[]
|
||||
*/
|
||||
public function voucherItemListPage($data)
|
||||
{
|
||||
$header = [
|
||||
'method' => 'syb.opt.voucher.item.listPage',
|
||||
];
|
||||
$body = [
|
||||
'orgNo' => config('crypto.company_no'),
|
||||
'orderNo' => $data['orderNo']??'',
|
||||
'model' => $data['model']??'',
|
||||
'pageLimit' => $data['pageLimit']??'',
|
||||
'pageNum' => $data['pageNum']??'',
|
||||
];
|
||||
|
||||
$response = $this->sendRequest(config('crypto.url').'/api/1.0.0/voucher/item/listPage', $body, $header);
|
||||
$this->saveLog("卡券查询".json_encode($response,320));
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user