【小拼科技多商户小程序商城】商家端变更信息功能

写作背景:最近在写多商户小程序商城

项目构建于看云,https://www.kancloud.cn/tpcms/merchant

效果图:
【小拼科技多商户小程序商城】商家端变更信息功能_第1张图片

【小拼科技多商户小程序商城】商家端变更信息功能_第2张图片

第一步:新建路由

Route::group(['prefix' => '/merchant', 'namespace' => "Merchant",'middleware' => ['merchant']], function () {

第二步:新建控制器

 'confirmed|min:6',
        'mobile'                        => 'digits:11',
        'merchant_name'                      => 'required',
        'merchant_logo'                         => 'required',
        'in_selling'                         => 'required',
        'account'                         => 'required'
    ];
    private $errorMsg = [
        'password.required'             => '新密码必填',
        'password.confirmed'            => '两次密码不一致',
        'password.min'                  => '新密码最小6位数',
        'mobile.digits'                 => '手机号码为11位数',
        'merchant_name.required'             => '商家名称必填',
        'merchant_logo.required'                => '商家Logo必填',
        'in_selling.required'                  => '上架状态必填',
        'account.required'             => '账号必填'
    ];

    public function index()
    {
        $item = Merchant::user();
        return view('merchant.info.item', ['item' => $item]);
    }

    public function store(Request $request)
    {
        $this->validate($request, $this->validateRule, $this->errorMsg);
        $id = Merchant::userId();
        $user = Merchant::find($id);

        # 登录的商户 与 表单账号账号
        if($user->account != Input::get('account')) {
            return $this->validateError(['account' =>'账号不能变更!']);
        }

        //判断密码是否一致
        $oldPassword = Input::get('old_password', '');
        if (!empty($oldPassword) && !App::make('hash')->check($oldPassword , $user->password)) {
            return $this->validateError(['old_password' =>'输入的原密码不正确!']);
        }
        $password = Input::get('password', '');
        if (!empty($password)) {
            $user->password = bcrypt($password);
        }
        $user->mobile = Input::get('mobile', '');
        $user->in_selling = Input::get('in_selling', 0);
        $user->contact_name = Input::get('contact_name', 0);
        $user->merchant_logo = Input::get('merchant_logo', 0);
        
        if (!$user->save()) {
            return $this->retJson(503, '操作出错!');
        }
        return $this->retJson(200, '操作成功!');
    }

}

第三步:新建静态页面

@section('title', "商家信息")
@section('content_title', '商家信息')
@section('content_title_small', "$item->merchant_name")
@section('content')
    
    

商家信息

@endsection @section('css') @endsection @section('js') @endsection @extends('layouts.merchant')

你可能感兴趣的:(laravel)