feat(fsgx): 完成全部24项开发任务 Phase1-7
Phase1 后端核心:
- 新增 fsgx_v1.sql 迁移脚本(is_queue_goods/frozen_points/available_points/no_assess)
- SystemConfigServices 返佣设置扩展(周期人数/分档比例/范围/时机)
- StoreOrderCreateServices 周期循环佣金计算
- StoreOrderTakeServices 佣金发放后同步冻结积分
- StoreProductServices/StoreProduct 保存 is_queue_goods
Phase2 后端接口:
- GET /api/hjf/brokerage/progress 佣金周期进度
- GET /api/hjf/assets/overview 资产总览
- HjfPointsServices 每日 frozen_points 0.4‰ 释放定时任务
- PUT /adminapi/hjf/member/{uid}/no_assess 不考核接口
- GET /adminapi/hjf/points/release_log 积分日志接口
Phase3 前端清理:
- hjfCustom.js 路由精简(仅保留 points/log)
- hjfQueue.js/hjfMember.js API 清理/重定向至 CRMEB 原生接口
- pages.json 公排→推荐佣金/佣金记录/佣金规则
Phase4-5 前端改造:
- queue/status.vue 推荐佣金进度页整体重写
- 商品详情/订单确认/支付结果页文案与逻辑改造
- 个人中心/资产页/引导页/规则页文案改造
- HjfQueueProgress/HjfRefundNotice/HjfAssetCard 组件改造
- 推广中心嵌入佣金进度摘要
- hjfMockData.js 全量更新(公排字段→佣金字段)
Phase6 Admin 增强:
- 用户列表新增 frozen_points/available_points 列及不考核操作按钮
- hjfPoints.js USE_MOCK=false 对接真实积分日志接口
Phase7 配置文档:
- docs/fsgx-phase7-config-checklist.md 后台配置与全链路验收清单
Made-with: Cursor
This commit is contained in:
93
pro_v3.5.1_副本/app/services/pay/IntegralPayServices.php
Normal file
93
pro_v3.5.1_副本/app/services/pay/IntegralPayServices.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\pay;
|
||||
|
||||
use app\services\BaseServices;
|
||||
use app\services\user\UserBillServices;
|
||||
use app\services\user\UserServices;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 积分支付
|
||||
* Class IntegralPayServices
|
||||
* @package app\services\pay
|
||||
*/
|
||||
class IntegralPayServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* 验证积分支付
|
||||
* @param int $uid
|
||||
* @param array $orderInfo
|
||||
* @param $userInfo
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function checkIntegralPay(int $uid, array $orderInfo, $userInfo = [])
|
||||
{
|
||||
if (!$uid) {
|
||||
throw new ValidateException('缺少参数');
|
||||
}
|
||||
if (!$orderInfo) {
|
||||
throw new ValidateException('订单不存在');
|
||||
}
|
||||
if ($orderInfo['paid']) {
|
||||
throw new ValidateException('该订单已支付!');
|
||||
}
|
||||
if (!$userInfo) {
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
$userInfo = $userServices->getUserInfo($uid);
|
||||
}
|
||||
if (!$userInfo) {
|
||||
throw new ValidateException('用户信息不存在');
|
||||
}
|
||||
if ($userInfo['integral'] < $orderInfo['pay_integral']) {
|
||||
throw new ValidateException('积分不足' . intval($orderInfo['pay_integral']));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用积分
|
||||
* @param int $uid
|
||||
* @param array $orderInfo
|
||||
* @param $userInfo
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function integralOrderPay(int $uid, array $orderInfo, $userInfo)
|
||||
{
|
||||
$this->checkIntegralPay($uid, $orderInfo, $userInfo);
|
||||
$priceIntegral = $orderInfo['pay_integral'];
|
||||
$res = true;
|
||||
if ($userInfo['integral'] > 0) {
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
if ($userInfo['integral'] > $priceIntegral) {
|
||||
$integral = bcsub((string)$userInfo['integral'], (string)$priceIntegral);
|
||||
} else {
|
||||
$integral = 0;
|
||||
}
|
||||
$res = $userServices->update($uid, ['integral' => $integral]);
|
||||
/** @var UserBillServices $userBillServices */
|
||||
$userBillServices = app()->make(UserBillServices::class);
|
||||
$res = $res && false !== $userBillServices->income('storeIntegral_use_integral', $uid, (int)$priceIntegral, (int)$integral, $orderInfo['id']);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
}
|
||||
50
pro_v3.5.1_副本/app/services/pay/OrderOfflineServices.php
Normal file
50
pro_v3.5.1_副本/app/services/pay/OrderOfflineServices.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\pay;
|
||||
|
||||
|
||||
use app\services\BaseServices;
|
||||
use app\services\order\StoreOrderServices;
|
||||
use app\services\order\StoreOrderSuccessServices;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 线下支付
|
||||
* Class OrderOfflineServices
|
||||
* @package app\services\pay
|
||||
*/
|
||||
class OrderOfflineServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* 线下支付
|
||||
* @param int $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function orderOffline(int $id)
|
||||
{
|
||||
/** @var StoreOrderServices $orderSerives */
|
||||
$orderSerives = app()->make(StoreOrderServices::class);
|
||||
$orderInfo = $orderSerives->get($id);
|
||||
if (!$orderInfo) {
|
||||
throw new ValidateException('订单不存在');
|
||||
}
|
||||
|
||||
if ($orderInfo->paid) {
|
||||
throw new ValidateException('订单已支付');
|
||||
}
|
||||
/** @var StoreOrderSuccessServices $storeOrderSuccessServices */
|
||||
$storeOrderSuccessServices = app()->make(StoreOrderSuccessServices::class);
|
||||
$storeOrderSuccessServices->paySuccess($orderInfo->toArray(), PayServices::OFFLINE_PAY);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
119
pro_v3.5.1_副本/app/services/pay/OrderPayServices.php
Normal file
119
pro_v3.5.1_副本/app/services/pay/OrderPayServices.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\pay;
|
||||
|
||||
|
||||
use app\services\order\StoreOrderCartInfoServices;
|
||||
use app\services\wechat\WechatUserServices;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 订单发起支付
|
||||
* Class OrderPayServices
|
||||
* @package app\services\pay
|
||||
*/
|
||||
class OrderPayServices
|
||||
{
|
||||
/**
|
||||
* 支付
|
||||
* @var PayServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected PayServices $payServices;
|
||||
|
||||
/**
|
||||
* 订单发起支付
|
||||
* @param array $orderInfo
|
||||
* @param string $payType
|
||||
* @return array|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function orderPay(array $orderInfo, string $payType)
|
||||
{
|
||||
if ($orderInfo['paid']) {
|
||||
throw new ValidateException('订单已支付!');
|
||||
}
|
||||
if ($orderInfo['pay_price'] <= 0) {
|
||||
throw new ValidateException('该支付无需支付!');
|
||||
}
|
||||
$openid = '';
|
||||
if (!in_array($payType, ['weixinh5', 'pc', 'store']) && !request()->isApp()) {
|
||||
if ($payType === 'weixin') {
|
||||
$userType = 'wechat';
|
||||
} else {
|
||||
$userType = $payType;
|
||||
}
|
||||
/** @var WechatUserServices $services */
|
||||
$services = app()->make(WechatUserServices::class);
|
||||
$openid = $services->uidToOpenid($orderInfo['uid'], $userType);
|
||||
if (!$openid) {
|
||||
throw new ValidateException('获取用户openid失败,无法支付');
|
||||
}
|
||||
}
|
||||
if (isset($orderInfo['recharge_type'])) {
|
||||
$body = '用户充值';
|
||||
$successAction = "user_recharge";
|
||||
} elseif (isset($orderInfo['member_type'])) {
|
||||
$body = substrUTf8('线下收银支付:' . $orderInfo['member_type'], 30);
|
||||
$successAction = "member";
|
||||
} else {
|
||||
/** @var StoreOrderCartInfoServices $orderInfoServices */
|
||||
$orderInfoServices = app()->make(StoreOrderCartInfoServices::class);
|
||||
$body = $orderInfoServices->getCarIdByProductTitle((int)$orderInfo['id']);
|
||||
$body = substrUTf8($body, 30);
|
||||
$successAction = "product";
|
||||
}
|
||||
|
||||
if (!$body) {
|
||||
throw new ValidateException('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
|
||||
}
|
||||
return $this->payServices->pay($payType, $openid, $orderInfo['order_id'], $orderInfo['pay_price'], $successAction, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝支付
|
||||
* @param array $orderInfo
|
||||
* @param string $quitUrl
|
||||
* @return array|string
|
||||
*/
|
||||
public function alipayOrder(array $orderInfo, string $quitUrl, bool $isCode = false)
|
||||
{
|
||||
if ($orderInfo['paid']) {
|
||||
throw new ValidateException('订单已支付!');
|
||||
}
|
||||
if ($orderInfo['pay_price'] <= 0) {
|
||||
throw new ValidateException('该支付无需支付!');
|
||||
}
|
||||
if (isset($orderInfo['recharge_type'])) {
|
||||
$body = '用户充值';
|
||||
$successAction = "user_recharge";
|
||||
} elseif (isset($orderInfo['member_type'])) {
|
||||
$body = substrUTf8($orderInfo['member_type'], 30);
|
||||
$successAction = "member";
|
||||
} else {
|
||||
/** @var StoreOrderCartInfoServices $orderInfoServices */
|
||||
$orderInfoServices = app()->make(StoreOrderCartInfoServices::class);
|
||||
$body = $orderInfoServices->getCarIdByProductTitle((int)$orderInfo['id']);
|
||||
$body = substrUTf8($body, 30);
|
||||
$successAction = "product";
|
||||
}
|
||||
|
||||
if (!$body) {
|
||||
throw new ValidateException('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
|
||||
}
|
||||
return $this->payServices->pay('alipay', $quitUrl, $orderInfo['order_id'], $orderInfo['pay_price'], $successAction, $body, $isCode);
|
||||
}
|
||||
|
||||
}
|
||||
92
pro_v3.5.1_副本/app/services/pay/PayMchNotifyServices.php
Normal file
92
pro_v3.5.1_副本/app/services/pay/PayMchNotifyServices.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\pay;
|
||||
|
||||
use app\jobs\system\CapitalFlowJob;
|
||||
use app\services\activity\lottery\LuckLotteryRecordServices;
|
||||
use app\services\order\OtherOrderServices;
|
||||
use app\services\order\StoreOrderSuccessServices;
|
||||
use app\services\user\UserExtractServices;
|
||||
use app\services\user\UserRechargeServices;
|
||||
use app\services\user\UserServices;
|
||||
|
||||
/**
|
||||
* 提现回调
|
||||
* Class PayNotifyServices
|
||||
* @package app\services\pay
|
||||
*/
|
||||
class PayMchNotifyServices
|
||||
{
|
||||
|
||||
/**
|
||||
* 提现
|
||||
* @param string|null $order_id 订单id
|
||||
* @return bool
|
||||
*/
|
||||
public function wechatTx(string $order_id = null, string $trade_no = null, string $state = null, string $fail_reason = null)
|
||||
{
|
||||
try {
|
||||
$services = app()->make(UserExtractServices::class);
|
||||
$userExtract = $services->getOne(['transfer_bill_no' => $trade_no]);
|
||||
if (!$userExtract) {
|
||||
return true;
|
||||
}
|
||||
$userExtract->wechat_state = $state;
|
||||
if ($fail_reason) {
|
||||
$userExtract->fail_reason = $fail_reason;
|
||||
}
|
||||
|
||||
if ($state == 'SUCCESS') {
|
||||
/** @var UserServices $userServices */
|
||||
$userServices = app()->make(UserServices::class);
|
||||
$userType = $userServices->value(['uid' => $userExtract['uid']], 'user_type');
|
||||
$nickname = $userServices->value(['uid' => $userExtract['uid']], 'nickname');
|
||||
$phone = $userServices->value(['uid' => $userExtract['uid']], 'phone');
|
||||
|
||||
//记录资金流水队列
|
||||
CapitalFlowJob::dispatch([['order_id' => $userExtract['id'], 'store_id' => 0, 'uid' => $userExtract['uid'], 'nickname' => $nickname, 'phone' => $phone, 'price' => $userExtract['extract_price'], 'pay_type' => $userExtract['extract_type']], 'extract']);
|
||||
|
||||
//消息推送
|
||||
event('notice.notice', [['uid' => $userExtract['uid'], 'userType' => strtolower($userType), 'extractNumber' => $userExtract['extract_price'], 'nickname' => $nickname], 'user_extract']);
|
||||
}else{
|
||||
app()->make(UserExtractServices::class)->changeFail($userExtract['id'], $userExtract->toArray(), '提现失败,原因:超时未领取');
|
||||
}
|
||||
$userExtract->save();
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 红包
|
||||
* @param string|null $order_id 订单id
|
||||
* @return bool
|
||||
*/
|
||||
public function wechatHb(string $order_id = null, string $trade_no = null, string $state = null, string $fail_reason = null)
|
||||
{
|
||||
try {
|
||||
$info = app()->make(LuckLotteryRecordServices::class)->get(['transfer_bill_no' => $trade_no]);
|
||||
if (!$info) {
|
||||
return true;
|
||||
}
|
||||
$info->wechat_state = $state;
|
||||
if ($fail_reason) {
|
||||
$info->fail_reason = $fail_reason;
|
||||
}
|
||||
$info->save();
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
149
pro_v3.5.1_副本/app/services/pay/PayNotifyServices.php
Normal file
149
pro_v3.5.1_副本/app/services/pay/PayNotifyServices.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\pay;
|
||||
|
||||
use app\services\order\OtherOrderServices;
|
||||
use app\services\order\StoreOrderSuccessServices;
|
||||
use app\services\user\UserRechargeServices;
|
||||
|
||||
/**
|
||||
* 支付成功回调
|
||||
* Class PayNotifyServices
|
||||
* @package app\services\pay
|
||||
*/
|
||||
class PayNotifyServices
|
||||
{
|
||||
|
||||
/**
|
||||
* 订单支付成功之后
|
||||
* @param string|null $order_id 订单id
|
||||
* @return bool
|
||||
*/
|
||||
public function wechatProduct(string $order_id = null, string $trade_no = null)
|
||||
{
|
||||
try {
|
||||
/** @var StoreOrderSuccessServices $services */
|
||||
$services = app()->make(StoreOrderSuccessServices::class);
|
||||
$orderInfo = $services->getOne(['order_id' => $order_id]);
|
||||
if (!$orderInfo) {
|
||||
$orderInfo = $services->getOne(['unique' => $order_id]);
|
||||
if (!$orderInfo) return true;
|
||||
}
|
||||
if ($orderInfo->paid) return true;
|
||||
return $services->paySuccess($orderInfo->toArray(), PayServices::WEIXIN_PAY, ['trade_no' => $trade_no]);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 充值成功后
|
||||
* @param string|null $order_id 订单id
|
||||
* @return bool
|
||||
*/
|
||||
public function wechatUserRecharge(string $order_id = null, string $trade_no = null)
|
||||
{
|
||||
try {
|
||||
/** @var UserRechargeServices $userRecharge */
|
||||
$userRecharge = app()->make(UserRechargeServices::class);
|
||||
if ($userRecharge->be(['order_id' => $order_id, 'paid' => 1])) return true;
|
||||
return $userRecharge->rechargeSuccess($order_id,['trade_no' => $trade_no]);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 购买会员
|
||||
* @param string|null $order_id
|
||||
* @return bool
|
||||
*/
|
||||
public function wechatMember(string $order_id = null, string $trade_no = null)
|
||||
{
|
||||
try {
|
||||
/** @var OtherOrderServices $services */
|
||||
$services = app()->make(OtherOrderServices::class);
|
||||
$orderInfo = $services->getOne(['order_id' => $order_id]);
|
||||
if (!$orderInfo) return true;
|
||||
if ($orderInfo->paid) return true;
|
||||
return $services->paySuccess($orderInfo->toArray(), PayServices::WEIXIN_PAY, ['trade_no' => $trade_no]);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝支付异步回调处理事件
|
||||
* @param string|null $order_id
|
||||
* @param string|null $trade_no
|
||||
* @return bool
|
||||
*/
|
||||
public function aliyunProduct(string $order_id = null, string $trade_no = null)
|
||||
{
|
||||
if (!$order_id || !$trade_no) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
/** @var StoreOrderSuccessServices $services */
|
||||
$services = app()->make(StoreOrderSuccessServices::class);
|
||||
$orderInfo = $services->getOne(['order_id' => $order_id]);
|
||||
if (!$orderInfo) return true;
|
||||
if ($orderInfo->paid) return true;
|
||||
return $services->paySuccess($orderInfo->toArray(), PayServices::ALIPAY_PAY, ['trade_no' => $trade_no]);
|
||||
} catch (\Throwable $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 购买会员卡支付宝异步回调
|
||||
* @param string|null $order_id
|
||||
* @param string|null $trade_no
|
||||
* @return bool
|
||||
*/
|
||||
public function aliyunMember(string $order_id = null, string $trade_no = null)
|
||||
{
|
||||
if (!$order_id || !$trade_no) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
/** @var OtherOrderServices $services */
|
||||
$services = app()->make(OtherOrderServices::class);
|
||||
$orderInfo = $services->getOne(['order_id' => $order_id]);
|
||||
if (!$orderInfo) return true;
|
||||
if ($orderInfo->paid) return true;
|
||||
return $services->paySuccess($orderInfo->toArray(), PayServices::ALIPAY_PAY, ['trade_no' => $trade_no]);
|
||||
} catch (\Throwable $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 充值成功后
|
||||
* @param string|null $order_id 订单id
|
||||
* @return bool
|
||||
*/
|
||||
public function aliyunUserRecharge(string $order_id = null, string $trade_no = null)
|
||||
{
|
||||
if (!$order_id || !$trade_no) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
/** @var UserRechargeServices $userRecharge */
|
||||
$userRecharge = app()->make(UserRechargeServices::class);
|
||||
if ($userRecharge->be(['order_id' => $order_id, 'paid' => 1])) return true;
|
||||
return $userRecharge->rechargeSuccess($order_id, ['trade_no' => $trade_no]);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
162
pro_v3.5.1_副本/app/services/pay/PayServices.php
Normal file
162
pro_v3.5.1_副本/app/services/pay/PayServices.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\services\pay;
|
||||
|
||||
use crmeb\services\AliPayService;
|
||||
use crmeb\services\wechat\Payment;
|
||||
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
|
||||
use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
|
||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 支付统一入口
|
||||
* Class PayServices
|
||||
* @package app\services\pay
|
||||
*/
|
||||
class PayServices
|
||||
{
|
||||
/**
|
||||
* 微信支付类型
|
||||
*/
|
||||
const WEIXIN_PAY = 'weixin';
|
||||
|
||||
/**
|
||||
* 积分支付
|
||||
*/
|
||||
const INTEGRAL_PAY = 'integral';
|
||||
|
||||
/**
|
||||
* 余额支付
|
||||
*/
|
||||
const YUE_PAY = 'yue';
|
||||
|
||||
/**
|
||||
* 线下支付
|
||||
*/
|
||||
const OFFLINE_PAY = 'offline';
|
||||
|
||||
/**
|
||||
* 支付宝
|
||||
*/
|
||||
const ALIPAY_PAY = 'alipay';
|
||||
|
||||
/**
|
||||
* 现金支付
|
||||
*/
|
||||
const CASH_PAY = 'cash';
|
||||
|
||||
/**
|
||||
* 支付方式
|
||||
* @var string[]
|
||||
*/
|
||||
const PAY_TYPE = [
|
||||
PayServices::WEIXIN_PAY => '微信支付',
|
||||
PayServices::YUE_PAY => '余额支付',
|
||||
PayServices::OFFLINE_PAY => '线下支付',
|
||||
PayServices::ALIPAY_PAY => '支付宝',
|
||||
PayServices::CASH_PAY => '现金支付',
|
||||
PayServices::INTEGRAL_PAY => '积分支付',
|
||||
];
|
||||
|
||||
/**
|
||||
* 二维码条码值
|
||||
* @var string
|
||||
*/
|
||||
protected string $authCode = '';
|
||||
|
||||
/**
|
||||
* 设置二维码条码值
|
||||
* @param string $authCode
|
||||
* @return $this
|
||||
*/
|
||||
public function setAuthCode(string $authCode)
|
||||
{
|
||||
$this->authCode = $authCode;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起支付
|
||||
* @param string $payType
|
||||
* @param string $openid
|
||||
* @param string $orderId
|
||||
* @param string $price
|
||||
* @param string $successAction
|
||||
* @param string $body
|
||||
* @param bool $isCode
|
||||
* @return \Alipay\EasySDK\Payment\Wap\Models\AlipayTradeWapPayResponse|array|string
|
||||
* @throws InvalidArgumentException
|
||||
* @throws InvalidConfigException
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function pay(string $payType, string $openid, string $orderId, string $price, string $successAction, string $body, bool $isCode = false)
|
||||
{
|
||||
$body = filter_emoji($body);
|
||||
switch ($payType) {
|
||||
case 'routine':
|
||||
//微信支付,从APP端请求过来
|
||||
if (request()->isApp()) {
|
||||
return Payment::appPay($openid, $orderId, $price, $successAction, $body);
|
||||
} else {
|
||||
//判断有没有打开小程序支付
|
||||
if (sys_config('pay_routine_open', 0)) {
|
||||
return Payment::miniPay($openid, $orderId, $price, $successAction, $body);
|
||||
} else {
|
||||
//开启了v3支付
|
||||
if (Payment::instance()->isV3PAy) {
|
||||
return Payment::instance()->payClient()->miniprogPay($openid, $orderId, $price, $body, $successAction);
|
||||
}
|
||||
return Payment::jsPay($openid, $orderId, $price, $successAction, $body);
|
||||
}
|
||||
}
|
||||
case 'weixinh5':
|
||||
////开启了v3支付
|
||||
if (Payment::instance()->isV3PAy) {
|
||||
return Payment::instance()->payClient()->h5Pay($orderId, $price, $body, $successAction);
|
||||
}
|
||||
//旧版v2支付
|
||||
return Payment::paymentOrder(null, $orderId, $price, $successAction, $body, '', 'MWEB');
|
||||
case self::WEIXIN_PAY:
|
||||
//微信支付,付款码支付,付款码支付使用v2支付接口
|
||||
if ($this->authCode) {
|
||||
return Payment::microPay($this->authCode, $orderId, $price, $successAction, $body);
|
||||
} else {
|
||||
//微信支付,从APP端请求过来
|
||||
if (request()->isApp()) {
|
||||
return Payment::appPay($openid, $orderId, $price, $successAction, $body);
|
||||
} else {
|
||||
//开启了v3支付
|
||||
if (Payment::instance()->isV3PAy) {
|
||||
return Payment::instance()->payClient()->jsapiPay($openid, $orderId, $price, $body, $successAction);
|
||||
}
|
||||
//使用v2旧版支付接口
|
||||
return Payment::jsPay($openid, $orderId, $price, $successAction, $body);
|
||||
}
|
||||
}
|
||||
case self::ALIPAY_PAY:
|
||||
if ($this->authCode) {
|
||||
return AliPayService::instance()->microPay($this->authCode, $body, $orderId, $price, $successAction);
|
||||
} else {
|
||||
return AliPayService::instance()->create($body, $orderId, $price, $successAction, $openid, $openid, $isCode);
|
||||
}
|
||||
case 'pc':
|
||||
case 'store':
|
||||
//方法内部已经做了区分v2和v3
|
||||
return Payment::nativePay($openid, $orderId, $price, $successAction, $body);
|
||||
default:
|
||||
throw new ValidateException('支付方式不存在');
|
||||
}
|
||||
}
|
||||
}
|
||||
88
pro_v3.5.1_副本/app/services/pay/RechargeServices.php
Normal file
88
pro_v3.5.1_副本/app/services/pay/RechargeServices.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\services\pay;
|
||||
|
||||
|
||||
use app\services\user\UserRechargeServices;
|
||||
use app\services\wechat\WechatUserServices;
|
||||
use think\annotation\Inject;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class RechargeServices
|
||||
* @package app\services\pay
|
||||
*/
|
||||
class RechargeServices
|
||||
{
|
||||
/**
|
||||
* @var PayServices
|
||||
*/
|
||||
#[Inject]
|
||||
protected PayServices $pay;
|
||||
|
||||
/**
|
||||
* 充值订单支付
|
||||
* @param string $order_id
|
||||
* @param string $payType
|
||||
* @return \Alipay\EasySDK\Payment\Wap\Models\AlipayTradeWapPayResponse|array|string
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
||||
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
||||
*/
|
||||
public function recharge(string $order_id, string $payType = 'weixin',string $from = 'weixin')
|
||||
{
|
||||
/** @var UserRechargeServices $rechargeServices */
|
||||
$rechargeServices = app()->make(UserRechargeServices::class);
|
||||
$recharge = $rechargeServices->getOne(['order_id' => $order_id]);
|
||||
if (!$recharge) {
|
||||
throw new ValidateException('订单失效或者不存在');
|
||||
}
|
||||
if ($recharge['paid'] == 1) {
|
||||
throw new ValidateException('订单已支付');
|
||||
}
|
||||
$payType = $from == 'routine' ? 'routine' : $payType;
|
||||
if ($payType != $recharge['recharge_type']) {
|
||||
$res = $rechargeServices->update(['order_id' => $order_id], ['recharge_type' => $payType]);
|
||||
if (!$res) {
|
||||
throw new ValidateException('订单支付方式修改失败');
|
||||
}
|
||||
}
|
||||
$openid = '';
|
||||
//没有付款码,不是微信H5支付,门店支付,PC支付,不再APP端,需要判断用户openid
|
||||
if (!in_array($recharge['recharge_type'], ['weixinh5', 'store', 'pc']) && !request()->isApp()) {
|
||||
$userType = '';
|
||||
switch ($recharge['recharge_type']) {
|
||||
case 'weixin':
|
||||
case 'weixinh5':
|
||||
$userType = 'wechat';
|
||||
break;
|
||||
case 'routine':
|
||||
$userType = 'routine';
|
||||
break;
|
||||
}
|
||||
if (!$userType) {
|
||||
throw new ValidateException('不支持该类型方式');
|
||||
}
|
||||
/** @var WechatUserServices $wechatUser */
|
||||
$wechatUser = app()->make(WechatUserServices::class);
|
||||
$openid = $wechatUser->uidToOpenid((int)$recharge['uid'], $userType);
|
||||
if (!$openid) {
|
||||
throw new ValidateException('获取用户openid失败,无法支付');
|
||||
}
|
||||
}
|
||||
return $this->pay->pay($recharge['recharge_type'], $openid, $recharge['order_id'], $recharge['price'], 'user_recharge', '用户充值');
|
||||
}
|
||||
|
||||
}
|
||||
107
pro_v3.5.1_副本/app/services/pay/YuePayServices.php
Normal file
107
pro_v3.5.1_副本/app/services/pay/YuePayServices.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: CRMEB Team <admin@crmeb.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\services\pay;
|
||||
|
||||
use app\services\BaseServices;
|
||||
use app\services\order\OtherOrderServices;
|
||||
use app\services\order\StoreOrderServices;
|
||||
use app\services\order\StoreOrderSuccessServices;
|
||||
use app\services\order\StoreOrderCartInfoServices;
|
||||
use app\services\user\UserMoneyServices;
|
||||
use app\services\user\UserServices;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 余额支付
|
||||
* Class YuePayServices
|
||||
* @package app\services\pay
|
||||
*/
|
||||
class YuePayServices extends BaseServices
|
||||
{
|
||||
|
||||
/**
|
||||
* 订单余额支付
|
||||
* @param array $orderInfo
|
||||
* @param $uid
|
||||
* @return bool[]|string[]
|
||||
*/
|
||||
public function yueOrderPay(array $orderInfo, $uid)
|
||||
{
|
||||
if (!$orderInfo) {
|
||||
throw new ValidateException('订单不存在');
|
||||
}
|
||||
|
||||
if ($orderInfo['paid']) {
|
||||
throw new ValidateException('该订单已支付!');
|
||||
}
|
||||
$type = 'pay_product';
|
||||
if (isset($orderInfo['member_type'])) {
|
||||
$type = 'pay_member';
|
||||
}
|
||||
/** @var UserServices $services */
|
||||
$services = app()->make(UserServices::class);
|
||||
$userInfo = $services->getUserInfo($uid);
|
||||
if ($userInfo['now_money'] < $orderInfo['pay_price']) {
|
||||
return ['status' => 'pay_deficiency', 'msg' => '余额不足' . floatval($orderInfo['pay_price'])];
|
||||
}
|
||||
|
||||
$this->transaction(function () use ($services, $orderInfo, $userInfo, $type) {
|
||||
$res = false !== $services->bcDec($userInfo['uid'], 'now_money', $orderInfo['pay_price'], 'uid');
|
||||
switch ($type) {
|
||||
case 'pay_product'://商品余额
|
||||
$id = $orderInfo['id'] ?? 0;
|
||||
/** @var StoreOrderServices $orderSerives */
|
||||
$orderSerives = app()->make(StoreOrderServices::class);
|
||||
$orderInfo = $orderSerives->get($id);
|
||||
if (!$orderInfo) {
|
||||
throw new ValidateException('订单不存在');
|
||||
}
|
||||
$orderInfo = $orderInfo->toArray();
|
||||
/** @var StoreOrderCartInfoServices $cartInfoServices */
|
||||
$cartInfoServices = app()->make(StoreOrderCartInfoServices::class);
|
||||
try {
|
||||
$storeName = $cartInfoServices->getCarIdByProductTitle($id);
|
||||
$arr = explode('|', $storeName);
|
||||
$num = count($arr);
|
||||
if ($num > 1) {
|
||||
$title = '购买' . substrUTf8($arr[0], 9, 'UTF-8', '') . '等';
|
||||
} else {
|
||||
$title = '购买' . substrUTf8($storeName, 10, 'UTF-8', '');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$title = '';
|
||||
}
|
||||
|
||||
//写入余额记录
|
||||
$now_money = bcsub((string)$userInfo['now_money'], (string)$orderInfo['pay_price'], 2);
|
||||
$number = $orderInfo['pay_price'];
|
||||
/** @var UserMoneyServices $userMoneyServices */
|
||||
$userMoneyServices = app()->make(UserMoneyServices::class);
|
||||
$res = $res && $userMoneyServices->income('pay_product', $userInfo['uid'], $number, $now_money, $orderInfo['id'], $title);
|
||||
/** @var StoreOrderSuccessServices $orderServices */
|
||||
$orderServices = app()->make(StoreOrderSuccessServices::class);
|
||||
$res = $res && $orderServices->paySuccess($orderInfo, PayServices::YUE_PAY, ['userInfo' => $userInfo]);//余额支付成功
|
||||
break;
|
||||
case 'pay_member'://会员卡支付
|
||||
/** @var OtherOrderServices $OtherOrderServices */
|
||||
$OtherOrderServices = app()->make(OtherOrderServices::class);
|
||||
$res = $res && $OtherOrderServices->paySuccess($orderInfo, PayServices::YUE_PAY, ['userInfo' => $userInfo]);//余额支付成功
|
||||
break;
|
||||
}
|
||||
if (!$res) {
|
||||
throw new ValidateException('余额支付失败!');
|
||||
}
|
||||
});
|
||||
return ['status' => true];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user