hrjy 2 years ago
parent
commit
d0e360e257
3 changed files with 160 additions and 0 deletions
  1. 122 0
      app/api/controller/user/UserController.php
  2. 34 0
      app/models/user/UserPay.php
  3. 4 0
      route/api/route.php

+ 122 - 0
app/api/controller/user/UserController.php

@@ -6,6 +6,7 @@ use app\admin\model\diagnosis\DiagnosisApply;
 use app\admin\model\diagnosis\DiagnosisOrder;
 use app\http\validates\user\AddressValidate;
 use app\models\system\SystemCity;
+use app\models\user\UserPay;
 use app\models\user\UserVisit;
 use crmeb\services\CacheService;
 use think\db\exception\DataNotFoundException;
@@ -28,6 +29,7 @@ use app\models\user\UserExtract;
 use app\models\user\UserNotice;
 use crmeb\services\GroupDataService;
 use crmeb\services\UtilService;
+use think\facade\Validate;
 
 /**
  * 用户类
@@ -700,4 +702,124 @@ class UserController
         }
         return app('json')->successful($list);
     }
+
+    /**
+     * 添加收款方式
+     * @param Request $request
+     * @return void
+     */
+    public function pay(Request $request)
+    {
+        $data = UtilService::postMore([
+            ['payment'],
+            ['image'],
+            ['bank'],
+            ['name'],
+            ['type'],
+            ['phone'],
+            ['bank_name']
+        ], $request);
+        if (!$data['type'])  return app('json')->fail('数据传入错误');
+        $data['uid'] =$request->uid();
+        $model = new UserPay();
+        $pay = $model->where([['uid', '=', $request->uid()], ['type', '=', $data['type']]])->find();
+        $res = Validate::rule([
+            'phone' => 'mobile'
+        ]);
+        $res->message([
+            'phone.mobile' => '请填写正确手机格式'
+        ]);
+        if (!$res->check($data)){
+            return app('json')->fail($res->getError());
+        }
+        if (!empty($pay)){
+            if ($data['type'] == 1 ){
+                // 微信收款方式
+                if (!$data['payment'])  return app('json')->fail('微信账号不能为空');
+                if (!$data['image'])  return app('json')->fail('二维码不能为空');
+                if (!$data['name'])  return app('json')->fail('姓名不能为空');
+                $pay['payment'] = $data['payment'];
+                $pay['image'] = $data['image'];
+                $pay['name'] = $data['name'];
+                $pay['phone'] = $data['phone'];
+            }elseif ($data['type'] == 2){
+                // 支付宝收款方式
+                if (!$data['payment'])  return app('json')->fail('支付宝账号不能为空');
+                if (!$data['name'])  return app('json')->fail('姓名不能为空');
+                $pay['payment'] = $data['payment'];
+                $pay['name'] = $data['name'];
+                $pay['phone'] = $data['phone'];
+            }elseif ($data['type'] == 3){
+                // 银行卡收款方式
+                if (!$data['payment'])  return app('json')->fail('银行卡号不能为空');
+                if (!$data['name'])  return app('json')->fail('姓名不能为空');
+                if (!$data['bank'])  return app('json')->fail('开户行不能为空');
+                if (!$data['bank_name'])  return app('json')->fail('开户支行不能为空');
+                if (!$data['phone'])  return app('json')->fail('请填写手机号');
+                $pay['payment'] = $data['payment'];
+                $pay['bank'] = $data['bank'];
+                $pay['bank_name'] = $data['bank_name'];
+                $pay['phone'] = $data['phone'];
+                $pay['name'] = $data['name'];
+
+            }
+            $res = $pay->save();
+            if ($res) return app('json')->successful('修改成功');
+            return app('json')->fail('修改失败');
+        }else{
+            if ($data['type'] == 1 ){
+                // 微信收款方式
+                if (!$data['payment'])  return app('json')->fail('微信账号不能为空');
+                if (!$data['image'])  return app('json')->fail('二维码不能为空');
+                if (!$data['name'])  return app('json')->fail('姓名不能为空');
+                if (!$data['phone'])  return app('json')->fail('请填写手机号');
+
+            }elseif ($data['type'] == 2){
+                // 支付宝收款方式
+                if (!$data['payment'])  return app('json')->fail('支付宝账号不能为空');
+                if (!$data['name'])  return app('json')->fail('姓名不能为空');
+                if (!$data['phone'])  return app('json')->fail('请填写手机号');
+
+            }elseif ($data['type'] == 3){
+                // 银行卡收款方式
+                if (!$data['payment'])  return app('json')->fail('银行卡号不能为空');
+                if (!$data['name'])  return app('json')->fail('姓名不能为空');
+                if (!$data['bank'])  return app('json')->fail('开户行不能为空');
+                if (!$data['bank_name'])  return app('json')->fail('开户支行不能为空');
+                if (!$data['phone'])  return app('json')->fail('请填写手机号');
+            }
+            $res = $model->save($data);
+            if ($res) return app('json')->successful('添加成功');
+            return app('json')->fail('添加失败');
+        }
+    }
+
+    /**
+     * 收款方式详情
+     * @param Request $request
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function pay_list(Request $request)
+    {
+        $model = new UserPay();
+        $list = $model->where('uid', $request->uid())->select();
+
+        $list = empty($list)? []: $list->toArray();
+        $data['wx'] = [];
+        $data['zfb'] = [];
+        $data['bank'] = [];
+        foreach ($list as $k => $v){
+            if ($v['type'] == 1){
+                $data['wx'] = $v;
+            }elseif ($v['type'] == 2){
+                $data['zfb'] = $v;
+            }elseif ($v['type'] == 3){
+                $data['bank'] = $v;
+            }
+        }
+        return app('json')->successful($data);
+    }
 }

+ 34 - 0
app/models/user/UserPay.php

@@ -0,0 +1,34 @@
+<?php
+
+namespace app\models\user;
+
+use app\models\store\StoreProduct;
+use crmeb\services\SystemConfigService;
+use think\facade\Db;
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+
+/**
+ * TODO 场馆model
+ * Class Article
+ * @package app\models\article
+ */
+class UserPay extends BaseModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型名称
+     * @var string
+     */
+    protected $name = 'user_pay';
+
+    use ModelTrait;
+    protected $autoWriteTimestamp = true;
+
+
+}

+ 4 - 0
route/api/route.php

@@ -192,6 +192,10 @@ Route::group(function () {
 
     Route::post('user/apply', 'user.UserController/apply')->name('apply');//接单员申请
     Route::get('user/user_apply', 'user.UserController/user_apply')->name('user_apply');//申请记录
+
+
+    Route::post('auction/pay', 'user.UserController/pay')->name('pay');// 添加收款方式
+    Route::get('auction/pay_list', 'user.UserController/pay_list')->name('pay_list');// 用户收款方式
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, true);
 //未授权接口
 Route::group(function () {