Răsfoiți Sursa

福利账户清零功能

gorden 1 lună în urmă
părinte
comite
e0ab9eb944

+ 11 - 1
app/admin/controller/member/MemberController.php

@@ -370,7 +370,7 @@ class MemberController
 
     public function welfareInfo(Request $request)
     {
-        $memberId = $request->get('member_id', '');
+        $memberId = $request->get('member_id');
         if (!$memberId) {
             return json_fail("参数错误");
         }
@@ -378,6 +378,16 @@ class MemberController
         return MemberService::welfareInfo($request);
     }
 
+    public function clearWelfare(Request $request)
+    {
+        $memberId = $request->post('member_id', '');
+        if (!$memberId) {
+            return json_fail("参数错误");
+        }
+
+        return MemberService::clearWelfare($request);
+    }
+
     public function balanceInfo(Request $request)
     {
         $memberId = $request->get('member_id', '');

+ 57 - 3
app/admin/service/member/MemberService.php

@@ -82,8 +82,8 @@ class MemberService
                 }
                 $query->whereBetween('member.member_addtimes', $addtime);
             })->when(!empty($nickname), function ($query) use ($nickname) {
-                $query->where(function($query2) use ($nickname){
-                    $query2->where('member_info.member_info_nickname','like','%'.$nickname.'%')->orWhere('member.member_mobile','like','%'.$nickname.'%');
+                $query->where(function ($query2) use ($nickname) {
+                    $query2->where('member_info.member_info_nickname', 'like', '%' . $nickname . '%')->orWhere('member.member_mobile', 'like', '%' . $nickname . '%');
                 });
             })
             ->select('member_id', 'member_is_vip', 'member_is_owner', 'member_classify', 'member_status', 'member_mobile', 'member_from', 'member_addtimes', 'member_extend_json',
@@ -659,6 +659,60 @@ class MemberService
         return json_success('', compact('rows', 'page', 'pageSize', 'total'));
     }
 
+    public static function clearWelfare(Request $request)
+    {
+        $memberId = $request->post('member_id');
+        $payTime = $request->post('pay_paytimes', date('Y-m-d H:i:s'));
+        $payTime = date('Y-m-d H:i:s',strtotime($payTime));
+        $payRemark = $request->post('pay_remark', '');
+        $clearPwd = $request->post('clear_password');
+        if (!$clearPwd || $clearPwd != '123456'){
+            return json_fail('清零密码错误');
+        }
+
+        Db::beginTransaction();
+        try {
+            $account = MemberAccount::where('join_account_member_id', $memberId)
+                ->where('member_account_classify', 'WELFARE')
+                ->where('member_account_status', 'ACTIVED')
+                ->first();
+            if (!$account) {
+                throw new BusinessException("账户异常");
+            }
+            if ($account->member_account_surplus <= 0){
+                throw new BusinessException("账户余额为0,无需清零");
+            }
+            // 创建清除记录
+            PayDetail::insert([
+                'join_pay_member_id' => $memberId,
+                'pay_status' => 'SUCCESS',
+                'pay_category' => 'CLEAR',
+                'pay_amount' => $account->member_account_surplus,
+                'pay_paytimes' => $payTime,
+                'pay_prepayid' => $memberId . '-WELFARE',
+                'pay_remark' => $payRemark,
+                'pay_addtimes' => time()
+            ]);
+
+            // 账户归零
+            $account->member_account_expend = $account->member_account_expend + $account->member_account_surplus;
+            $account->member_account_surplus = 0;
+            $account->save();
+
+            Db::commit();
+
+            return json_success('success');
+        }catch (BusinessException $e){
+            Db::rollBack();
+            return json_fail($e->getMessage());
+        } catch (\Exception $e) {
+            dump($e->getMessage());
+            Db::rollBack();
+
+            return json_fail('清零失败');
+        }
+    }
+
     public static function balanceInfo(Request $request)
     {
         $memberId = $request->get('member_id', '');
@@ -741,7 +795,7 @@ class MemberService
 
                 $item['balance'] = number_format($balance, 2, '.', '');
                 $balance = $balance - $item['pay_amount'];
-                if ($item['pay_category'] != 'GIVE'){
+                if ($item['pay_category'] != 'GIVE') {
                     $data[] = $item;
                 }
 

+ 1 - 0
route/admin.php

@@ -685,6 +685,7 @@ Route::group('/admin', function () {
             Route::get('/selectMemberAllQuota', [\app\admin\controller\member\MemberController::class, 'selectMemberAllQuota']);
             Route::get('/selectMemberAllQuotaByAppointment', [\app\admin\controller\member\MemberController::class, 'selectMemberAllQuotaByAppointment']);
             Route::get('/welfareInfo', [\app\admin\controller\member\MemberController::class, 'welfareInfo']);
+            Route::post('/clearWelfare', [\app\admin\controller\member\MemberController::class, 'clearWelfare']);
             Route::get('/vipInfo', [\app\admin\controller\member\MemberController::class, 'vipInfo']);
             Route::get('/coupon', [\app\admin\controller\member\MemberController::class, 'coupon']);
             Route::get('/couponCount', [\app\admin\controller\member\MemberController::class, 'couponCount']);