Explorar o código

Merge branch 'liuzj-pay-dev' into liuzj-fist-page-dev

# Conflicts:
#	modules/Manage/routes/route.php
liuzejian hai 1 ano
pai
achega
17c864d414

+ 26 - 0
modules/Common/Repository/Options/CommonParams.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace Modules\Common\Repository\Options;
+
+use Catch\Enums\Status as StatusEnum;
+
+class CommonParams implements OptionInterface
+{
+    public function get(): array
+    {
+        /**
+         * @see modules/Common/config/common.php
+         */
+        $commonConfig = config('common.common');
+        return [
+            /**
+             * 支付类型
+             */
+           'payType' => $commonConfig['payType'],
+            /**
+             * 小程序类型
+             */
+            'miniprogramType' => $commonConfig['miniprogramType'],
+        ];
+    }
+}

+ 31 - 1
modules/Common/config/common.php

@@ -16,5 +16,35 @@ return [
     'moduleMap' => [
         '1' => 'weixin',
         '2' => 'douyin',
-    ]
+    ],
+    /**
+     * 支付方式
+     */
+    'payType' => [
+        [
+            'key' => 1,
+            'val' => '易宝支付',
+        ],
+        [
+            'key' => 2,
+            'val' => '微信原生支付',
+        ],
+        [
+            'key' => 3,
+            'val' => '抖音支付'
+        ],
+    ],
+    /**
+     * 小程序类型
+     */
+    'miniprogramType' => [
+        [
+            'key' => 1,
+            'val' => '微信'
+        ],
+        [
+            'key' => 2,
+            'val' => '抖音'
+        ]
+    ],
 ];

+ 104 - 0
modules/Manage/Http/Controllers/PayConfigController.php

@@ -0,0 +1,104 @@
+<?php
+
+namespace Modules\Manage\Http\Controllers;
+
+use Catch\Base\CatchController;
+use Illuminate\Foundation\Validation\ValidatesRequests;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+
+/**
+ * 支付配置管理
+ */
+class PayConfigController extends CatchController
+{
+    use ValidatesRequests;
+    /**
+     * 配置列表
+     * @param Request $request
+     */
+    public function list(Request $request) {
+        $this->validate($request,[
+            'name' => 'nullable|string|max:256',
+            'pay_type' => 'nullable|in:1,2,3',
+            'miniprogram_type' => 'nullable|in:1,2',
+            'remark' => 'nullable|string|max:256',
+            'pay_appid' => 'nullable|string|max:256',
+        ]);
+        $name = $request->input('name');
+        $payType = $request->input('pay_type');
+        $miniprogramType = $request->input('miniprogram_type');
+        $payAppid = $request->input('pay_appid');
+        $remark = $request->input('remark');
+        $isAll = $request->input('is_all', 0);
+        $commonConfig = config('common.common');
+
+
+        $sql = DB::table('pay_merchants')
+            ->when($name, function ($query, $name){
+                return $query->where('name', 'like', '%'. $name .'%');
+            })->when($payType, function ($query, $payType){
+                return $query->where('pay_type', $payType);
+            })->when($miniprogramType, function ($query, $miniprogramType) {
+                return $query->where('miniprogram_type', $miniprogramType);
+            })->when($payAppid, function ($query, $payAppid) {
+                return $query->where('pay_appid', $payAppid);
+            })->when($remark, function ($query, $remark){
+                return $query->where('remark', 'like', '%'. $remark. '%');
+            })->orderBy('id', 'desc');
+
+        if($isAll) {
+            $result =  $sql->get();
+        } else {
+            $result =  $sql->paginate($request->input('limit', 15));
+        }
+
+        $payTypeMap = collect($commonConfig['payType'])->keyBy('key');
+        $miniprogramTypeMap = collect($commonConfig['miniprogramType'])->keyBy('key');
+        foreach ($result as $item) {
+            $item->pay_type_str = $payTypeMap[$item->pay_type]['val'] ?? '';
+            $item->miniprogram_type_str = $miniprogramTypeMap[$item->miniprogram_type]['val'] ?? '';
+        }
+
+        return $result;
+    }
+
+    /**
+     * 修改备注
+     * @param Request $request
+     */
+    public function remark(Request $request) {
+        $this->validate($request, ['id' => 'required']);
+        DB::table('pay_merchants')
+            ->where(['id' => $request->input('id')])
+            ->update(['remark' => $request->input('remark', ''),
+                'updated_at' => date('Y-m-d H:i:s')]);
+
+        return 'ok';
+    }
+
+    /**
+     * 添加支付配置信息
+     * @param Request $request
+     */
+    public function addConfig(Request $request) {
+        $this->validate($request, [
+            'name' => 'required|string|max:256',
+            'payee_name' => 'required|string|max:256',
+            'pay_appid' => 'required',
+            'pay_type' => 'required|integer|in:1,2,3',
+            'pay_common_params' => 'required',
+            'miniprogram_type' => 'required|in:1,2',
+            'remark' => 'nullable|string|max:256'
+        ]);
+        $data = $request->only(['name', 'payee_name', 'pay_appid', 'pay_type', 'miniprogram_type']);
+        $now = date('Y-m-d H:i:s');
+        $data['created_at'] = $data['updated_at'] = $now;
+        $data['pay_common_params'] = \json_encode($request->input('pay_common_params', []));
+        $data['remark'] = $request->input('remark', '');
+            DB::table('pay_merchants')
+            ->insert($data);
+
+        return 'ok';
+    }
+}

+ 7 - 0
modules/Manage/routes/route.php

@@ -2,6 +2,7 @@
 
 use Illuminate\Support\Facades\Route;
 use Modules\Manage\Http\Controllers\MiniprogramController;
+use Modules\Manage\Http\Controllers\PayConfigController;
 
 Route::prefix('manage')->group(function(){
     Route::prefix('miniprogram')->group(function () {
@@ -32,4 +33,10 @@ Route::prefix('manage')->group(function(){
         ->withoutMiddleware(config('catch.route.middlewares'));
 
     });
+    
+    Route::prefix('payConfig')->group(function(){
+       Route::get('list', [PayConfigController::class, 'list']);
+       Route::post('remark', [PayConfigController::class, 'remark']);
+       Route::post('addConfig', [PayConfigController::class, 'addConfig']);
+    });
 });

+ 20 - 0
tests/Common/Http/Controllers/OptionControllerTest.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace Tests\Common\Http\Controllers;
+
+use Modules\Common\Http\Controllers\OptionController;
+use PHPUnit\Framework\TestCase;
+use Tests\UsedTestCase;
+
+class OptionControllerTest extends UsedTestCase
+{
+
+    public function testIndex()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/options/CommonParams');
+        $res->dump();
+        $this->dumpJson($res);
+    }
+}

+ 53 - 0
tests/Manage/Http/Controllers/PayConfigControllerTest.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace Tests\Manage\Http\Controllers;
+
+use Modules\Manage\Http\Controllers\PayConfigController;
+use PHPUnit\Framework\TestCase;
+use Tests\UsedTestCase;
+
+class PayConfigControllerTest extends UsedTestCase
+{
+
+    public function testAddConfig()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/manage/payConfig/addConfig', [
+            'name' => 'first',
+            'payee_name' => 'first-payee_name',
+            'pay_appid' => '12342142412',
+            'pay_type' => 1,
+            'pay_common_params' => [
+                'aa' => 'bb',
+                'bb' => 'cc',
+            ],
+            'miniprogram_type' => 1,
+            'remark' => '111'
+        ]);
+        $res->dump();
+        $this->dumpJson($res);
+    }
+    public function testRemark()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('post','http://localhost/api/manage/payConfig/remark', [
+            'id' => 1,
+            'remark' => 'first---',
+        ]);
+        $res->dump();
+        $this->dumpJson($res);
+    }
+    public function testList()
+    {
+        $res = $this->withHeaders([
+            'Authorization' => 'Bearer '. $this->token,
+        ])->json('get','http://localhost/api/manage/payConfig/list', [
+
+            'pay_appid' => '12342142412'
+        ]);
+        $res->dump();
+        $this->dumpJson($res);
+    }
+}

+ 2 - 2
tests/UsedTestCase.php

@@ -13,9 +13,9 @@ abstract class UsedTestCase extends BaseTestCase
     {
         parent::setUp(); // TODO: Change the autogenerated stub
         $tokenInfo = $this->post('http://localhost/api/login', [
-//            'email' => 'catch@admin.com',
+            'email' => 'catch@admin.com',
             'remember' => false,
-            'email' => 'xiaoli@qq.com',
+//            'email' => 'xiaoli@qq.com',
             'password' => 'catchadmin',
 //            'email' => 'aa4@test.com',
         ])->json();