jingcai-php/app/Admin/Forms/CustomerPasswordForm.php

59 lines
1.9 KiB
PHP

<?php
namespace App\Admin\Forms;
use App\Model\Customer\Customer;
use App\Model\Seller\ShopPayChannel;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
use Illuminate\Support\Arr;
use Log;
class CustomerPasswordForm extends Form implements LazyRenderable
{
use LazyWidget;
public function handle(array $input)
{
$id = Arr::get($input, 'id');
if (!$id) {
return $this->response()->alert()->error('参数有误');
}
$customer = Customer::find($id);
if (!$customer) {
return $this->response()->alert()->error('数据不存在!');
}
$password = Arr::get($input, 'password');
$passwordPay = Arr::get($input, 'password_pay');
if (!$password && !$passwordPay) {
return $this->response()->alert()->error('密码和支付密码必须填写一个!');
}
$customer->password = Customer::encryPassword($password);
$customer->password_pay = Customer::encryPassword($password);
$customer->save();
return $this->response()->success("设置成功")->refresh();
}
public function form()
{
$id = $this->payload['id'];
$customer = Customer::find($id);
if (!$customer) {
return $this->response()->alert()->error('数据不存在!');
}
$this->display('shop_sn','店铺编号')->value($customer->shop->shop_sn);
$this->display('shop_name','店铺名称')->value($customer->shop->name);
$this->display('phone','手机号')->value($customer->phone);
$this->display('name','真实姓名')->value($customer->name);
$this->display('nickname','昵称')->value($customer->nickname);
$this->text('password', '密码')->help('请输入新密码');
$this->text('password_pay', '支付密码')->help('请输入新的支付密码');
$this->hidden('id')->value($id);
}
}