wesmiler 3 ماه پیش
والد
کامیت
500c674c54

+ 1 - 1
app/Helpers/common.php

@@ -664,7 +664,7 @@ if (!function_exists('format_bank_card')) {
     function format_bank_card($card_no, $is_format = true, $hidden=true)
     {
         if($hidden){
-            $format_card_no = '****'.substr($card_no, -4, 4);
+            $format_card_no = substr($card_no, 0, 4).'**********'.substr($card_no, -4, 4);
         }else if ($is_format) {
             // 截取银行卡号前4位
             $prefix = substr($card_no, 0, 4);

+ 69 - 0
app/Http/Controllers/Api/v1/MemberBankController.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace App\Http\Controllers\Api\v1;
+
+use App\Http\Controllers\Api\webApp;
+use App\Http\Validator\BankValidator;
+use App\Services\Api\MemberBankService;
+use App\Services\RedisService;
+
+/**
+ * 用户收款银行卡
+ * Class MemberBankController
+ * @package App\Http\Controllers\Api
+ */
+class MemberBankController extends webApp
+{
+
+    public function index()
+    {
+        $params = request()->all();
+        $pageSize = isset($params['pageSize'])? $params['pageSize'] : 18;
+        $params['user_id'] = $this->userId;
+        $datas = MemberBankService::make()->getDataList($params, $pageSize);
+        return message(1010, true, $datas);
+    }
+
+    /**
+     * @return array
+     */
+    public function save(BankValidator $validator)
+    {
+        $params = $validator->check(request()->all(), 'save');
+        if(!is_array($params)){
+            return message($params, false);
+        }
+        if(MemberBankService::make()->saveData($this->userId, $params)){
+            RedisService::clear("caches:members:banks:{$this->userId}");
+            return message(MemberBankService::make()->getError(), true);
+        }else{
+            return message(MemberBankService::make()->getError(), false);
+        }
+    }
+
+    /**
+     * 选项
+     * @return array
+     */
+    public function options()
+    {
+        $datas = MemberBankService::make()->options($this->userId);
+        return message(1010, true, $datas);
+    }
+
+
+
+    /**
+     * 删除
+     * @return array
+     */
+    public function delete()
+    {
+        if(MemberBankService::make()->delete()){
+            RedisService::clear("caches:members:banks:{$this->userId}");
+            return message(MemberBankService::make()->getError(), true);
+        }else{
+            return message(MemberBankService::make()->getError(), false);
+        }
+    }
+}

+ 48 - 0
app/Http/Validator/BankValidator.php

@@ -0,0 +1,48 @@
+<?php
+namespace App\Http\Validator;
+class BankValidator extends BaseValidator
+{
+    // 当前模型所有验证规则
+    public static $rules = [
+        'id' => 'required',
+        'bank_name' => 'required|min:2|max:50',
+        'branch_name' => 'min:2|max:50',
+        'bank_card' => 'required|min:15|max:30',
+        'status' => 'required',
+    ];
+    public static $msgs = [
+        'required' => ':attribute不能为空',
+        'string' => ':attribute必须是字符串',
+        'min' => ':attribute长度不能小于:min位',
+        'max' => ':attribute长度不能大于:max位',
+        'exists' => ':attribute不存在',
+        'rule' => ':attribute格式不正确',
+        'mobile' => ':attribute格式不正确',
+    ];
+
+    // 当前模型所有验证字段
+    public static $fields = [
+        'id' => 'ID',
+        'realname' => '收款人姓名',
+        'bank_name' => '开户行',
+        'bank_card' => '银行卡号',
+        'bank_branch' => '开户支行',
+    ];
+
+    // 当前模型所有验证场景
+    public static $scenes = [
+        'save'=> ['bank_name','bank_card','bank_branch'],
+        'del'=> ['id'],
+    ];
+
+    /**
+     * 验证
+     * @param $request
+     * @param string $scene
+     * @return int|mixed
+     */
+    public static function check($request, $scene=''){
+        $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
+        return $validator->checkParams($request, $scene);
+    }
+}

+ 13 - 0
app/Models/MemberBankModel.php

@@ -21,4 +21,17 @@ class MemberBankModel extends BaseModel
 {
     // 设置数据表
     protected $table = 'member_banks';
+
+    protected $appends = ['bank_card_text','bank_text'];
+
+    public function getBankCardTextAttribute()
+    {
+        return $this->bank_card? format_bank_card($this->bank_card) : '';
+    }
+
+    public function getBankTextAttribute()
+    {
+        return substr($this->bank_name).'('.substr($this->bank_card,-4,4).')';
+    }
+
 }

+ 157 - 0
app/Services/Api/MemberBankService.php

@@ -0,0 +1,157 @@
+<?php
+// +----------------------------------------------------------------------
+// | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
+// +----------------------------------------------------------------------
+// | 版权所有 2017~2021 LARAVEL研发中心
+// +----------------------------------------------------------------------
+// | 官方网站: http://www.laravel.cn
+// +----------------------------------------------------------------------
+// | Author: laravel开发员 <laravel.qq.com>
+// +----------------------------------------------------------------------
+
+namespace App\Services\Api;
+
+use App\Models\MemberBankModel;
+use App\Services\BaseService;
+use App\Services\RedisService;
+
+/**
+ * 用户银行卡管理-服务类
+ * @author laravel开发员
+ * @since 2020/11/11
+ * @package App\Services\Common
+ */
+class MemberBankService extends BaseService
+{
+    // 静态对象
+    protected static $instance = null;
+
+    /**
+     * 构造函数
+     * @author laravel开发员
+     * @since 2020/11/11
+     * MemberBankService constructor.
+     */
+    public function __construct()
+    {
+        $this->model = new MemberBankModel();
+    }
+
+    /**
+     * 静态入口
+     * @return static|null
+     */
+    public static function make()
+    {
+        if (!self::$instance) {
+            self::$instance = (new static());
+        }
+        return self::$instance;
+    }
+
+    /**
+     * 列表数据
+     * @param $params
+     * @param int $pageSize
+     * @return array
+     */
+    public function getDataList($params, $pageSize = 15)
+    {
+        $where = ['a.mark' => 1,'a.status'=>1];
+        $status = isset($params['status']) ? $params['status'] : 0;
+        if ($status > 0) {
+            $where['a.status'] = $status;
+        }
+        $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+        if ($userId > 0) {
+            $where['a.user_id'] = $userId;
+        }
+
+        $list = $this->model->from('member_banks as a')
+            ->where($where)
+            ->select(['a.*'])
+            ->orderBy('a.create_time', 'desc')
+            ->orderBy('a.id', 'desc')
+            ->paginate($pageSize > 0 ? $pageSize : 9999999);
+        $list = $list ? $list->toArray() : [];
+
+        return [
+            'pageSize' => $pageSize,
+            'total' => isset($list['total']) ? $list['total'] : 0,
+            'list' => isset($list['data']) ? $list['data'] : []
+        ];
+    }
+
+    /**
+     * 选项列表
+     * @param $userId
+     * @return array|mixed
+     */
+    public function options($userId, $userType=1)
+    {
+        $cacheKey = "caches:members:banks:{$userId}_{$userType}";
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+
+        $datas = $this->model->where(['user_id'=> $userId,'user_type'=>$userType,'status'=> 1,'mark'=>1])
+            ->select(['id','realname','bank_name','bank_card','status'])
+            ->get();
+        $datas = $datas? $datas->toArrayu() :[];
+        if($datas){
+            RedisService::set($cacheKey, $datas, 7200);
+        }
+
+        return $datas;
+    }
+    /**
+     * 保存数据
+     * @param $userId
+     * @param $params
+     * @return mixed
+     */
+    public function saveData($userId, $params)
+    {
+        $id = isset($params['id']) ? $params['id'] : 0;
+        $userType = isset($params['user_type']) ? $params['user_type'] : 0;
+        $data = [
+            'user_id'=> $userId,
+            'user_type'=> $userType,
+            'realname'=> isset($params['realname'])? $params['realname'] : '',
+            'bank_name'=> isset($params['bank_name'])? $params['bank_name'] : '',
+            'branch_name'=> isset($params['branch_name'])? $params['branch_name'] : '',
+            'bank_card'=> isset($params['bank_card'])? $params['bank_card'] : '',
+            'bank_code'=> isset($params['bank_code'])? $params['bank_code'] : '',
+            'status'=> isset($params['status'])? $params['status'] : 1,
+            'update_time'=> time(),
+            'mark'=> 1,
+        ];
+        if($id && $this->model->where(['id'=> $id])->value('id')){
+            $this->model->where(['id'=> $id])->update($data);
+            $this->error = $id? 1008 : 1027;
+            return true;
+        }else{
+            $data['create_time'] = time();
+            $this->error = 1027;
+            return $this->model->insertGetId($data);
+        }
+    }
+
+    /**
+     * @return array|false
+     */
+    public function delete()
+    {
+        // 参数
+        $id = request()->post('id');
+        if (empty($id)) {
+            $this->error = 2014;
+            return false;
+        }
+
+        $this->error = 1002;
+        $this->model->where(['mark'=>0])->where('update_time','<=', time() - 3*86400)->delete();
+        return $this->model->where(['id'=> $id])->update(['mark'=> 0, 'update_time'=> time()]);
+    }
+}

+ 1 - 0
app/Services/Common/ArticleService.php

@@ -130,6 +130,7 @@ class ArticleService extends BaseService
             $data['content'] = '';
         }
 
+        $data['author'] = isset($data['author']) && $data['author']?$data['author'] : \App\Services\ConfigService::make()->getConfigByCode('app_name');
         $data['cover'] = $data['cover']? get_image_path($data['cover']) : '';
 
         // 设置日志标题

+ 6 - 0
routes/api.php

@@ -66,6 +66,12 @@ Route::prefix('v1')->middleware('web.login')->group(function() {
     Route::post('/user/teamList', [\App\Http\Controllers\Api\v1\MemberController::class, 'teamList']);
     Route::post('/user/logOff', [\App\Http\Controllers\Api\v1\MemberController::class, 'logOff']);
 
+    // 银行卡
+    Route::post('/user/banks/index', [\App\Http\Controllers\Api\v1\MemberBankController::class, 'index']);
+    Route::post('/user/banks/save', [\App\Http\Controllers\Api\v1\MemberBankController::class, 'save']);
+    Route::post('/user/banks/delete', [\App\Http\Controllers\Api\v1\MemberBankController::class, 'delete']);
+
+
     // 账户明细
     Route::post('/account/index', [\App\Http\Controllers\Api\v1\AccountController::class, 'index']);
     Route::post('/account/info', [\App\Http\Controllers\Api\v1\AccountController::class, 'info']);

+ 0 - 1
routes/web.php

@@ -12,7 +12,6 @@
 use App\Http\Controllers\Admin\ActionLogController;
 use App\Http\Controllers\Admin\AdController;
 use App\Http\Controllers\Admin\CityController;
-use App\Http\Controllers\Admin\SocialCirclesController;
 use App\Http\Controllers\Admin\ConfigController;
 use App\Http\Controllers\Admin\ConfigGroupController;
 use App\Http\Controllers\Admin\IndexController;