Kaynağa Gözat

Merge branch 'liuzj-permission-dev' into test

liuzejian 1 yıl önce
ebeveyn
işleme
c9e25f58b7

+ 7 - 32
app/Console/Commands/Jiesuan/CompanyChargeDayJiesuan.php

@@ -6,6 +6,7 @@ use Illuminate\Console\Command;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Redis;
 use Modules\Jiesuan\Services\CompanyUserMoneyService;
+use Modules\Jiesuan\Services\ConstService;
 
 class CompanyChargeDayJiesuan extends Command
 {
@@ -77,61 +78,35 @@ class CompanyChargeDayJiesuan extends Command
                             'updated_at' => $now,
                         ];
                     }
-                   DB::transaction(function () use ($insertData, $now){
+
+                DB::transaction(function () use ($insertData, $now){
                        DB::table('jiesuan_records')->insert($insertData);
                        foreach ($insertData as $item) {
                            $beforeUserMoneyInfo = CompanyUserMoneyService::userMoneyInfo($item['company_uid']);
                            $companyUserMoney = DB::table('company_user_money')
                                ->where('company_uid', $item['company_uid'])->first();
                            if($companyUserMoney) {
-                               $beforeTotalIncome = $companyUserMoney->total_income;
                                $afterTotalIncome = bcadd($companyUserMoney->total_income, $item['charge_money'], 2);
                                DB::table('company_user_money')
                                    ->where(['company_uid' => $item['company_uid']])
                                    ->update([
                                        'total_income' => $afterTotalIncome,
+                                       'total_tuikuan' => bcadd($companyUserMoney->total_tuikuan, $item['tuikuan_money'], 2),
                                        'updated_at' => $now
                                    ]);
                            } else {
-                               $beforeTotalIncome = 0;
                                $afterTotalIncome = $item['charge_money'];
                                DB::table('company_user_money')
                                    ->insert([
                                        'company_uid' => $item['company_uid'],
                                        'total_income' => $afterTotalIncome,
+                                       'total_tuikuan' => $item['tuikuan_money'],
                                        'created_at' => $now, 'updated_at' => $now,
                                    ]);
                            }
                            $currentUserMoneyInfo = CompanyUserMoneyService::userMoneyInfo($item['company_uid']);
-                           DB::table('company_user_money_change_logs')
-                               ->insert([
-                                   'type' => 1,
-                                   'company_uid' => $item['company_uid'],
-                                   'created_at' => $now,
-                                   'log' => \json_encode([
-                                       'desc' => sprintf('总充值变动:[%s元-->%s元],当前总打款:[%s元],总退款变动:[%s元-->%s元],当前审核中:[%s元],余额变动:[%s元-->%s元]',
-                                       $beforeTotalIncome, $currentUserMoneyInfo->total_income,$currentUserMoneyInfo->total_dakuan,
-                                           $beforeUserMoneyInfo->total_tuikuan,
-                                       $currentUserMoneyInfo->total_tuikuan, $currentUserMoneyInfo->tixian_money,
-                                           $beforeUserMoneyInfo->yue_money,
-                                           $currentUserMoneyInfo->yue_money),
-                                       'before' => [
-                                           'total_income' => $beforeUserMoneyInfo->total_income,
-                                           'total_dakuan' => $beforeUserMoneyInfo->total_dakuan,
-                                           'total_tuikuan' => $beforeUserMoneyInfo->total_tuikuan,
-                                           'tixian_money' => $beforeUserMoneyInfo->tixian_money,
-                                           'yue_money' => $beforeUserMoneyInfo->yue_money,
-                                       ],
-                                       'after' => [
-                                           'total_income' => $currentUserMoneyInfo->total_income,
-                                           'total_dakuan' => $currentUserMoneyInfo->total_dakuan,
-                                           'total_tuikuan' => $currentUserMoneyInfo->total_tuikuan,
-                                           'tixian_money' => $currentUserMoneyInfo->tixian_money,
-                                           'yue_money' => $currentUserMoneyInfo->yue_money,
-                                       ],
-                                       'created_at' => $now,
-                                   ], JSON_UNESCAPED_UNICODE)
-                               ]);
+                           CompanyUserMoneyService::log($item['company_uid'], ConstService::MONEY_CHANGE_TYPE_DAY_JIESUAN,
+                               $beforeUserMoneyInfo, $currentUserMoneyInfo);
                        }
                    });
             });

+ 1 - 0
modules/Common/Errors/Errors.php

@@ -25,4 +25,5 @@ class Errors
     public const  JULIANG_ACCOUNT_CONFIG_NOT_EXISTS = [500106, '回传配置不存在'];
     public const  TIXIAN_YUE_BUZU = [500201, '提现余额不足'];
     public const  BANK_CARD_STATUS_ERROR = [500202, '银行卡不存在或当前状态不可提现'];
+    public const  TIXIAN_RECORD_NOT_EXISTS = [500203, '提现记录不存在'];
 }

+ 36 - 1
modules/Jiesuan/Http/Controllers/FinanceCheckController.php

@@ -70,7 +70,15 @@ class FinanceCheckController extends CatchController
             'status' => 'required|in:2,3',
             'id' => 'required'
         ]);
-
+        $record = DB::table('tixian_records')
+            ->where([
+                'id' => $request->input('id'),
+                'status' => 1
+            ])->first();
+        if(!$record) {
+            CommonBusinessException::throwError(Errors::TIXIAN_RECORD_NOT_EXISTS);
+        }
+        $before = CompanyUserMoneyService::userMoneyInfo($record->company_uid);
         DB::table('tixian_records')
             ->where([
                 'id' => $request->input('id'),
@@ -79,6 +87,11 @@ class FinanceCheckController extends CatchController
                 'status' => $request->input('status'),
                 'updated_at' => date('Y-m-d H:i:s')
             ]);
+        $after = CompanyUserMoneyService::userMoneyInfo($record->company_uid);
+        if(2 == $request->input('status')) {
+            CompanyUserMoneyService::log($record->company_uid, ConstService::MONEY_CHANGE_TYPE_CHECK_FAIL, $before, $after);
+        }
+
 
         return 'ok';
     }
@@ -96,6 +109,15 @@ class FinanceCheckController extends CatchController
             'remark' => 'nullable|string|max:256'
         ]);
 
+        $record = DB::table('tixian_records')
+            ->where([
+                'id' => $request->input('id'),
+                'status' => 3
+            ])->first();
+        if(!$record) {
+            CommonBusinessException::throwError(Errors::TIXIAN_RECORD_NOT_EXISTS);
+        }
+        $before = CompanyUserMoneyService::userMoneyInfo($record->company_uid);
         DB::table('tixian_records')
             ->where([
                 'id' => $request->input('id'),
@@ -107,6 +129,19 @@ class FinanceCheckController extends CatchController
                 'pay_no' => $request->input('pay_no'),
                 'remark' => $request->input('remark')
             ]);
+
+        $after = CompanyUserMoneyService::userMoneyInfo($record->company_uid);
+        if(4 == $request->input('status')) {
+            DB::table('company_user_money')
+                ->where(['company_uid' => $record->company_uid])
+                ->increment('total_dakuan', $record->tixian_money);
+            CompanyUserMoneyService::log($record->company_uid,
+                ConstService::MONEY_CHANGE_TYPE_CHECK_AND_DAKUAN_SUCCESS, $before, $after);
+        } else {
+            CompanyUserMoneyService::log($record->company_uid,
+                ConstService::MONEY_CHANGE_TYPE_CHECK_SUCCESS_DAKUAN_FAIL, $before, $after);
+        }
+
         return 'ok';
     }
 

+ 2 - 0
modules/Jiesuan/Http/Controllers/JiesuanController.php

@@ -92,6 +92,8 @@ class JiesuanController extends CatchController
                 'created_at' => $now,
                 'updated_at' => $now,
             ]);
+        $afterUserMoneyInfo = CompanyUserMoneyService::userMoneyInfo($company_uid);
+        CompanyUserMoneyService::log($company_uid, ConstService::MONEY_CHANGE_TYPE_USER_TIXIAN, $userMoneyInfo, $afterUserMoneyInfo);
     }
 
     /**

+ 46 - 0
modules/Jiesuan/Services/CompanyUserMoneyService.php

@@ -47,4 +47,50 @@ class CompanyUserMoneyService
         $moneyInfo->yue_money = $moneyInfo->total_income - $moneyInfo->total_tuikuan - $moneyInfo->total_dakuan - $tixian_money;
         return $moneyInfo;
     }
+
+    /**
+     * 用户金额变动日志记录
+     * @param $companyUid
+     * @param $type
+     * @param $before
+     * @param $after
+     */
+    public static function log($companyUid, $type, $before, $after) {
+        $now = date('Y-m-d H:i:s');
+        $field = [
+            'total_income' => '总充值',
+            'total_dakuan' => '总打款',
+            'total_tuikuan' => '总退款',
+            'tixian_money' => '提现金额',
+            'yue_money' => '余额'
+        ];
+        foreach ($field as $key=>$val) {
+            $des[] = sprintf('%s变动:[%s元-->%s元]', $val, $before->{$key}, $after->{$key});
+        }
+        DB::table('company_user_money_change_logs')
+            ->insert([
+                'type' => $type,
+                'company_uid' => $companyUid,
+                'created_at' => $now,
+                'log' => \json_encode([
+                    'desc' => join(', ', $des),
+                    'before' => [
+                        'total_income' => $before->total_income,
+                        'total_dakuan' => $before->total_dakuan,
+                        'total_tuikuan' => $before->total_tuikuan,
+                        'tixian_money' => $before->tixian_money,
+                        'yue_money' => $before->yue_money,
+                    ],
+                    'after' => [
+                        'total_income' => $after->total_income,
+                        'total_dakuan' => $after->total_dakuan,
+                        'total_tuikuan' => $after->total_tuikuan,
+                        'tixian_money' => $after->tixian_money,
+                        'yue_money' => $after->yue_money,
+                    ],
+                    'created_at' => $now,
+                ], JSON_UNESCAPED_UNICODE)
+            ]);
+    }
+
 }

+ 21 - 0
modules/Jiesuan/Services/ConstService.php

@@ -24,4 +24,25 @@ class ConstService
         '4' => '已打款',
         '5' => '打款失败'
     ];
+    /**
+     * 用户金额变动类型
+     * 1-每日结算
+     */
+    public const MONEY_CHANGE_TYPE_DAY_JIESUAN = 1;
+    /**
+     * 2-用户提现
+     */
+    public const MONEY_CHANGE_TYPE_USER_TIXIAN = 2;
+    /**
+     * 3-提现审核通过打款成功
+     */
+    public const MONEY_CHANGE_TYPE_CHECK_AND_DAKUAN_SUCCESS = 3;
+    /**
+     * 4-提现审核不通过
+     */
+    public const MONEY_CHANGE_TYPE_CHECK_FAIL = 4;
+    /**
+     * 5-提现审核通过打款失败
+     */
+    public const MONEY_CHANGE_TYPE_CHECK_SUCCESS_DAKUAN_FAIL = 5;
 }