liuzejian пре 2 година
родитељ
комит
9a0b4cef44

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

@@ -23,4 +23,6 @@ class Errors
     public const  CALLBACK_RECORD_LOG_ERROR= [500104, '回传日志补传信息缺失'];
     public const  JULIANG_ACCOUNT_PROMOTION_UNIQUE = [500105, '巨量广告账户只允许绑定一个推广'];
     public const  JULIANG_ACCOUNT_CONFIG_NOT_EXISTS = [500106, '回传配置不存在'];
+    public const  TIXIAN_YUE_BUZU = [500201, '提现余额不足'];
+    public const  BANK_CARD_STATUS_ERROR = [500202, '银行卡不存在或当前状态不可提现'];
 }

+ 14 - 0
modules/Jiesuan/Http/Controllers/BankAccountController.php

@@ -105,6 +105,20 @@ class BankAccountController extends CatchController
     }
 
     /**
+     * 公司管理员可用的银行卡列表
+     * @param Request $request
+     */
+    public function listAvailableBankCard(Request $request) {
+        $company_uid = $this->getLoginUserId();
+        return DB::table('bank_cards')
+            ->where([
+                'company_uid' => $company_uid,
+                'status' => 2
+            ])->select('id', 'bank_name', 'card_no', 'sub_bank_name')
+            ->get();
+    }
+
+    /**
      * 合作信息
      * @param Request $request
      */

+ 54 - 17
modules/Jiesuan/Http/Controllers/JiesuanController.php

@@ -6,6 +6,10 @@ use Catch\Base\CatchController;
 use Illuminate\Foundation\Validation\ValidatesRequests;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
+use Modules\Common\Errors\Errors;
+use Modules\Common\Exceptions\CommonBusinessException;
+use Modules\Jiesuan\Services\CompanyUserMoneyService;
+use Modules\Jiesuan\Services\ConstService;
 use Modules\User\Http\Controllers\UserTrait;
 
 class JiesuanController extends CatchController
@@ -41,6 +45,8 @@ class JiesuanController extends CatchController
         foreach ($results as $item) {
             $item->share_rate .= '%';
         }
+
+        return $results;
     }
 
     /**
@@ -49,19 +55,7 @@ class JiesuanController extends CatchController
      */
     public function accountInfo(Request $request) {
         $company_uid = $this->getLoginUserId();
-        $moneyInfo = DB::table('company_user_money')
-            ->where('company_uid', $company_uid)
-            ->select('total_income', 'total_dakuan', 'total_tuikuan', 'id')
-            ->first();
-
-        $tixian_money = DB::table('tixian_records')
-            ->where('company_uid', $company_uid)
-            ->whereIn('status', [1,3])
-            ->sum('tixian_money');
-
-        $moneyInfo->tixian_money = $tixian_money;
-        $moneyInfo->yue_money = $moneyInfo->total_income - $moneyInfo->total_tuikuan - $moneyInfo->total_dakuan - $tixian_money;
-        return $moneyInfo;
+        return CompanyUserMoneyService::userMoneyInfo($company_uid);
     }
 
     /**
@@ -74,9 +68,30 @@ class JiesuanController extends CatchController
             'tixian_money' => 'required|numeric|min:500'
         ]);
         $company_uid = $this->getLoginUserId();
-
-//        DB::table('tixian_records')
-//            ->insert()
+        $tixianMoney = $request->input('tixian_money');
+        $userMoneyInfo = CompanyUserMoneyService::userMoneyInfo($company_uid);
+        if($tixianMoney > $userMoneyInfo->yue_money) {
+            CommonBusinessException::throwError(Errors::TIXIAN_YUE_BUZU);
+        }
+        $bank_card_id = $request->input('bank_card_id');
+        $bankCard = DB::table('bank_cards')->where(['id' => $bank_card_id, 'status' => 2])->first();
+        if(!$bankCard) {
+            CommonBusinessException::throwError(Errors::BANK_CARD_STATUS_ERROR);
+        }
+        $now = date('Y-m-d H:i:s');
+        DB::table('tixian_records')
+            ->insert([
+                'tixian_money' => $tixianMoney,
+                'company_uid' => $company_uid,
+                'bank_card_id' => $bank_card_id,
+                'card_no' => $bankCard->card_no,
+                'name_of_payee' => $bankCard->name_of_payee,
+                'status' => 1,
+                'bank_name' => $bankCard->bank_name,
+                'sub_bank_name' => $bankCard->sub_bank_name,
+                'created_at' => $now,
+                'updated_at' => $now,
+            ]);
     }
 
     /**
@@ -84,6 +99,28 @@ class JiesuanController extends CatchController
      * @param Request $request
      */
     public function listTixian(Request $request) {
-
+        $company_uid = $this->getLoginUserId();
+        $this->validate($request, [
+            'status' => 'nullable|integer|in:1,2,3,4,5'
+        ]);
+        $status = $request->input('status');
+        $isExport = $request->input('is_export');
+        $sql = DB::table('tixian_records')
+            ->where([
+                'company_uid' => $company_uid,
+            ])->when($status, function ($query, $status){
+                return $query->where('status', $status);
+            })->orderBy('id', 'desc');
+        if($isExport) {
+            $result = $sql->get();
+        } else {
+            $result = $sql->paginate($request->input('limit', 15));
+        }
+        foreach ($result as $item) {
+            $item->status_str = ConstService::TIXIAN_CHECK_STATUS[$item->status] ?? '';
+        }
+        return $result;
     }
+
+
 }

+ 1 - 1
modules/Jiesuan/Services/BusinessmanService.php

@@ -8,7 +8,7 @@ class BusinessmanService
 {
     public static function list() {
         return DB::table('users')
-            ->join('user_has_roles', 'urser.id', 'user_has_roles.user_id')
+            ->join('user_has_roles', 'users.id', 'user_has_roles.user_id')
             ->join('roles', 'user_has_roles.role_id', 'roles.id')
             ->where([
                 'roles.identify' => 'business',

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

@@ -0,0 +1,50 @@
+<?php
+
+namespace Modules\Jiesuan\Services;
+
+use Illuminate\Support\Facades\DB;
+
+class CompanyUserMoneyService
+{
+    /**
+     * 公司管理员用户金额详情
+     * @param $companyUid
+     * @return null | object
+     * <pre>
+     * {
+     *      'company_uid' : 1, // 公司管理员uid
+     *      'total_income' : 1, // 总收入,
+     *      'total_dakuan' :1, //已打款金额
+     *      'total_tuikuan' : 1, // 总退款金额
+     *      'tixian_money' : 1, // 审核中提现金额
+     *      'yue_money' : 1, // 当前余额
+     * }
+     * </pre>
+     */
+    public static function userMoneyInfo($companyUid)
+    {
+        $moneyInfo = DB::table('company_user_money')
+            ->where('company_uid', $companyUid)
+            ->select('total_income', 'total_dakuan', 'total_tuikuan', 'company_uid')
+            ->first();
+        if(!$moneyInfo) {
+            return (object)[
+                'company_uid' => $companyUid,
+                'total_income' => 0,
+                'total_dakuan' => 0,
+                'total_tuikuan' => 0,
+                'tixian_money' => 0,
+                'yue_money' => 0,
+            ];
+        }
+
+        $tixian_money = DB::table('tixian_records')
+            ->where('company_uid', $companyUid)
+            ->whereIn('status', [1, 3])
+            ->sum('tixian_money');
+
+        $moneyInfo->tixian_money = $tixian_money;
+        $moneyInfo->yue_money = $moneyInfo->total_income - $moneyInfo->total_tuikuan - $moneyInfo->total_dakuan - $tixian_money;
+        return $moneyInfo;
+    }
+}

+ 17 - 5
modules/Jiesuan/routes/route.php

@@ -1,13 +1,25 @@
 <?php
 
 use Illuminate\Support\Facades\Route;
-use Modules\System\Http\Controllers\NoticesController;
-use Modules\System\Http\Controllers\NoticeTypesController;
-use Modules\Video\Http\Controllers\BankAccountController;
-use Modules\Video\Http\Controllers\VideoCategoryController;
-use Modules\Video\Http\Controllers\VideoController;
+use Modules\Jiesuan\Http\Controllers\BankAccountController;
+use Modules\Jiesuan\Http\Controllers\JiesuanController;
+
 
 Route::prefix('jiesuanManage')->group(function () {
+    Route::prefix('bankAccount')->group(function (){
+        Route::get('hezuoInfo', [BankAccountController::class, 'hezuoInfo']);
+        Route::get('listCompanyCard', [BankAccountController::class, 'listCompanyCard']);
+        Route::get('listAvailableBankCard', [BankAccountController::class, 'listAvailableBankCard']);
+        Route::get('listBank', [BankAccountController::class, 'listBank']);
+        Route::get('listShangwu', [BankAccountController::class, 'listShangwu']);
+        Route::post('addCompanyCard', [BankAccountController::class, 'addCompanyCard']);
+    });
 
+    Route::prefix('jiesuan')->group(function(){
+        Route::get('listTixian', [JiesuanController::class, 'listTixian']);
+        Route::get('list', [JiesuanController::class, 'list']);
+        Route::get('accountInfo', [JiesuanController::class, 'accountInfo']);
+        Route::post('tixian', [JiesuanController::class, 'tixian']);
+    });
 });
 

+ 95 - 0
tests/Jiesuan/Http/Controllers/BankAccountControllerTest.php

@@ -0,0 +1,95 @@
+<?php
+
+namespace Tests\Jiesuan\Http\Controllers;
+
+use Modules\Jiesuan\Http\Controllers\BankAccountController;
+use PHPUnit\Framework\TestCase;
+use Tests\UsedTestCase;
+
+class BankAccountControllerTest extends UsedTestCase
+{
+
+    public function testHezuoInfo()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/jiesuanManage/bankAccount/hezuoInfo', []);
+        $res->dump();
+    }
+    public function testaddCompanyCard()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/jiesuanManage/bankAccount/addCompanyCard', [
+            'owner_name' => 'fsdadfasfsaf',
+            'name_of_payee' => 'jlkjkljklj',
+            'card_no' => '21432515',
+            'bank_name' => '中国银行',
+            'sub_bank_name' => '第一支行',
+            'phone_of_payee' => '143214141',
+            'business_id' => 8
+        ]);
+        $res->dump();
+
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/jiesuanManage/bankAccount/addCompanyCard', [
+            'id' => 1,
+            'owner_name' => 'fsdadfasfsaf2222',
+            'name_of_payee' => 'jlkjkljklj3333',
+            'card_no' => '2143251544',
+            'bank_name' => '中国银行',
+            'sub_bank_name' => '第一支行22',
+            'phone_of_payee' => '14321414123323232',
+            'business_id' => 8
+        ]);
+        $res->dump();
+    }
+
+    public function testaddCompanyCard1() {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/jiesuanManage/bankAccount/addCompanyCard', [
+            'id' => 1,
+            'owner_name' => 'fasd',
+            'name_of_payee' => 'fdsa',
+            'card_no' => '2143251544',
+            'bank_name' => '中国银行',
+            'sub_bank_name' => '第一支行22',
+            'phone_of_payee' => '1231',
+            'business_id' => 8
+        ]);
+        $res->dump();
+    }
+
+    public function testlistShangwu()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/jiesuanManage/bankAccount/listShangwu');
+        $res->dump();
+    }
+    public function testlistBank()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/jiesuanManage/bankAccount/listBank');
+        $res->dump();
+    }
+    public function testlistCompanyCard()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/jiesuanManage/bankAccount/listCompanyCard');
+        $res->dump();
+    }
+    public function testlistAvailableBankCard()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/jiesuanManage/bankAccount/listAvailableBankCard');
+        $res->dump();
+    }
+
+
+}

+ 45 - 0
tests/Jiesuan/Http/Controllers/JiesuanControllerTest.php

@@ -0,0 +1,45 @@
+<?php
+
+namespace Tests\Jiesuan\Http\Controllers;
+
+use Modules\Jiesuan\Http\Controllers\JiesuanController;
+use PHPUnit\Framework\TestCase;
+use Tests\UsedTestCase;
+
+class JiesuanControllerTest extends UsedTestCase
+{
+
+    public function testList()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/jiesuanManage/jiesuan/list');
+        $res->dump();
+    }
+    public function testaccountInfo()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/jiesuanManage/jiesuan/accountInfo');
+        $res->dump();
+    }
+ public function testtixian()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/jiesuanManage/jiesuan/tixian', [
+            'bank_card_id' => 1,
+            'tixian_money' => 9358,
+        ]);
+        $res->dump();
+    }
+    public function testlistTixian()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/jiesuanManage/jiesuan/listTixian', [
+//            'status' => 5
+        ]);
+        $res->dump();
+    }
+}

+ 2 - 2
tests/UsedTestCase.php

@@ -15,9 +15,9 @@ abstract class UsedTestCase extends BaseTestCase
         $tokenInfo = $this->post('http://localhost/api/login', [
 //            'email' => 'catch@admin.com',
             'remember' => false,
-//            'email' => 'xiaoli@qq.com',
+            'email' => 'xiaoli@qq.com',
             'password' => 'catchadmin',
-            'email' => 'aa4@test.com',
+//            'email' => 'aa4@test.com',
         ])->json();
         $this->token = $tokenInfo['data']['token'];
     }