gq il y a 7 ans
Parent
commit
77d378d360

+ 94 - 0
server/app/Http/Controllers/Api/V1/MyController.php

xqd xqd
@@ -9,6 +9,7 @@ use App\Models\DreamInfoModel;
 use App\Models\SearchInfoModel;
 use App\Models\Suggest;
 use App\Models\SystemInfoModel;
+use App\Models\UserBank;
 use App\Models\UserCareDream;
 use App\Models\UserCashOut;
 use App\Models\UserInfoModel;
@@ -652,4 +653,97 @@ class MyController extends Controller
 
     }
 
+
+    //我的银行账户
+
+
+    /**
+     * @api {get} /api/my/bank/list 我的银行账户
+     * @apiDescription 我的银行账户
+     * @apiGroup My
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     *{
+     *   "status": true,
+     *   "status_code": 0,
+     *  "message": "",
+     *   "data":[] or
+     *  "data": [
+     *   {
+     *       "id": 1,
+     *      "user_id": 1,
+     *      "bank_name": "1",
+     *      "bank_number": "1",
+     *      "bank_phone": "1",
+     *      "bank_user": "1"
+     *   }
+     *]
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     */
+    public function bankList()
+    {
+        $user = $this->getUser();
+        $data =  UserBank::where('user_id',$user->id)->orderBy('id','desc')->get();
+        return $this->api($data);
+    }
+
+   // 添加银行卡
+
+    /**
+     * @api {post} /api/my/suggest 添加银行卡
+     * @apiDescription 添加银行卡
+     * @apiGroup My
+     *    @apiParam {string} data[bank_name]         银行名称
+     *    @apiParam {string} data[bank_number]       银行卡号
+     *    @apiParam {int} data[bank_phone]           银行卡绑定手机号
+     *    @apiParam {string} data[bank_user]         银行卡用户姓名
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     *{
+     *   "status": false,
+     *  "status_code": 200,
+     *  "message": "操作成功",
+     *  "data": null
+     *}
+     * @apiErrorExample {json} Error-Response:
+     *{
+     *  "status": false,
+     *  "status_code": 700,
+     *  "message": "操作失败",
+     *  "data": null
+     *}
+     */
+    public function bankCreate(Request $request)
+    {
+        $data = $request->data;
+        $user = $this->getUser();
+        $validator = \Validator::make($request->all(),
+            [
+                'data.bank_name'  => 'required',
+                'data.bank_number'  => 'required',
+                'data.bank_phone'  => 'required',
+                'data.bank_user'  => 'required',
+            ],
+            [
+                'data.bank_name.required'  => '请选择账号类型',
+                'data.bank_number.required'  => '请输入账号',
+                'data.bank_phone.required'  => '请输入账号绑定手机号码',
+                'data.bank_user.required'  => '请输入账号绑定用户姓名',
+            ]
+        );
+        if($validator->fails()) return $this->validatorError($validator->messages()->all(),ErrorCode::CLIENT_WRONG_PARAMS);
+        $data['user_id'] = $user->id;
+        $ok =UserBank::create($data);
+        if ($ok) {
+            return $this->error(ErrorCode::OPERATION_SUCCESS);
+        }else{
+            return $this->error(ErrorCode::OPERATION_FAILED);
+        }
+    }
+
 }

+ 17 - 0
server/app/Models/UserBank.php

xqd
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class UserBank extends Model
+{
+    protected $table = 'user_banks';
+    protected $fillable = [
+        'user_id',
+        'bank_name',
+        'bank_number',
+        'bank_phone',
+        'bank_user',
+    ];
+}

+ 40 - 0
server/database/migrations/2017_08_14_113214_create_user_banks_table.php

xqd
@@ -0,0 +1,40 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+/**
+ * Migration auto-generated by Sequel Pro Laravel Export
+ * @see https://github.com/cviebrock/sequel-pro-laravel-export
+ */
+class CreateUserBanksTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('user_banks', function (Blueprint $table) {
+            $table->increments('id')->comment('绑定银行卡,支付方式的id');
+            $table->unsignedInteger('user_id')->comment('关联用户id, users.id');
+            $table->string('bank_name', 60)->comment('银行名称, 支付方式名称');
+            $table->string('bank_number', 120)->comment('银行卡号码, 支付宝帐号, 微信帐号');
+            $table->string('bank_phone', 120)->comment('银行卡 网上支付绑定的手机号');
+            $table->string('bank_user', 60)->comment('银行卡用户姓名');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('user_banks');
+    }
+}

+ 8 - 0
server/routes/api.php

xqd
@@ -160,6 +160,14 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($a
         'as' => 'my.cash',
         'uses' => 'MyController@cash',
     ]);
+    $api->get('my/bank/list', [
+        'as' => 'my.bank_list',
+        'uses' => 'MyController@bankList',
+    ]);
+    $api->get('my/bank/create', [
+        'as' => 'my.bank_create',
+        'uses' => 'MyController@bankCreate',
+    ]);
 //    用户信息
     $api->get('user/show', [
         'as' => 'user.show',