From bce9d447c1ded4430d5b6d732a8eae2d1b3e473f Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Mon, 29 Jan 2024 16:18:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE=EF=BC=8C?= =?UTF-8?q?=E6=89=A3=E9=99=A4=E5=8A=B3=E5=8A=A1=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/adminapi/logic/user/UserLogic.php | 17 +++++++++++++++++ app/api/controller/ShopCallController.php | 23 ++++++++++++++++++++++- app/common/enum/user/AccountLogEnum.php | 4 +++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/adminapi/logic/user/UserLogic.php b/app/adminapi/logic/user/UserLogic.php index e10e250d..ac25b2b6 100644 --- a/app/adminapi/logic/user/UserLogic.php +++ b/app/adminapi/logic/user/UserLogic.php @@ -20,6 +20,7 @@ use app\common\logic\BaseLogic; use app\common\model\contract\Contract; use app\common\model\dict\DictData; use app\common\model\user\User; +use app\common\model\user\UserAccountLog; use app\common\service\ConfigService; use think\facade\Config; use think\facade\Db; @@ -307,4 +308,20 @@ class UserLogic extends BaseLogic { return Db::name('user_invite_first_order_log')->insert(['user_id' => $userId, 'order_money' => bcdiv($orderMoney, 100, 2), 'order_no' => $orderNo, 'create_time' => time()]); } + + public static function handleProfitRefund($orderNo) + { + $userAccountLog = UserAccountLog::where('source_sn', $orderNo)->where('action', 1)->find(); + if ($userAccountLog) { + $money = $userAccountLog['change_amount']; + $arr = [$userAccountLog['user_id'], AccountLogEnum::UM_DEC_ORDER_REFUND, AccountLogEnum::DEC, $money, $orderNo, '订单退款' . '扣除劳务费' . $money . '元', ['company_id' => 0, 'proportion' => 0], 1]; + self::decrUserAccountLog($arr); + } + } + + private static function decrUserAccountLog($data) + { + User::where('id', $data[0])->update(['user_money'=>Db::raw('user_money-' . $data[3])]); + return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]); + } } \ No newline at end of file diff --git a/app/api/controller/ShopCallController.php b/app/api/controller/ShopCallController.php index c469fef1..ec736757 100644 --- a/app/api/controller/ShopCallController.php +++ b/app/api/controller/ShopCallController.php @@ -5,6 +5,7 @@ namespace app\api\controller; use app\adminapi\logic\user\UserLogic; use app\common\logic\ShopRequestLogic; use app\common\model\user\User; +use app\common\model\user\UserAccountLog; use think\exception\ValidateException; use think\facade\Log; @@ -13,7 +14,7 @@ use think\facade\Log; */ class ShopCallController extends BaseApiController { - public array $notNeedLogin = ['user_first_order_share_profit', 'user_order_share_profit']; + public array $notNeedLogin = ['user_first_order_share_profit', 'user_order_share_profit', 'handleRefund']; public string $apiSecret = ''; public function initialize() @@ -229,4 +230,24 @@ class ShopCallController extends BaseApiController Log::info('镇合伙人,配送员分润通知商城返回:'.json_encode($res)); return $this->success('成功', ['user_id' => $userSelf['id'], 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, $proportion, 2)]); } + + // 退款扣除佣金 + public function handleRefund() + { + $params = $this->request->param(); + $timestamp = $params['timestamp']; + $iv = substr(md5($this->apiSecret.$timestamp), 5, 16); +// $secretData = encrypt($params, $this->apiSecret, $iv); halt($secretData); +// halt($secretData); + $requestDatas = decrypt($params['data'], $this->apiSecret, $iv); + Log::info('镇合伙人,配送员分润请求参数:'.json_encode($requestDatas)); + if (null === $requestDatas) { + return $this->fail('非法访问,解析失败'); + } + $orderNo = $requestDatas['data']['order_sn']; // 订单金额 + + UserLogic::handleProfitRefund($orderNo); + + return $this->success('成功'); + } } \ No newline at end of file diff --git a/app/common/enum/user/AccountLogEnum.php b/app/common/enum/user/AccountLogEnum.php index 4f952480..b5ec1be6 100644 --- a/app/common/enum/user/AccountLogEnum.php +++ b/app/common/enum/user/AccountLogEnum.php @@ -48,6 +48,7 @@ class AccountLogEnum const UM_DEC_ADMIN = 100; const UM_DEC_RECHARGE_REFUND = 101; const UM_DEC_WITHDRAW = 102; // 提现 + const UM_DEC_ORDER_REFUND = 103; // 订单退狂 /** * 用户余额增加类型 @@ -64,7 +65,8 @@ class AccountLogEnum const UM_DEC = [ self::UM_DEC_ADMIN, self::UM_DEC_RECHARGE_REFUND, - self::UM_DEC_WITHDRAW + self::UM_DEC_WITHDRAW, + self::UM_DEC_ORDER_REFUND ];