cxgj/modules/admin/models/store/StoreBjEditForm.php
2023-11-27 09:45:13 +08:00

100 lines
2.1 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2020-11-5
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\modules\admin\models\store;
use app\components\EncryptHelper;
use app\models\Admin;
use app\models\auth\RoleUser;
use app\models\common\CommonUserEditForm;
use app\models\Store;
use app\models\StoreUser;
use app\models\SysAdmin;
use app\models\User;
use app\modules\admin\models\AdminModel;
use yii\data\Pagination;
class StoreBjEditForm extends AdminModel
{
public $model;
public $store_id;
public $status;
public $name;
public $mobile;
public $created_at;
public $updated_at;
public $is_delete;
public $deleted_at;
public function rules()
{
return [
[['status', 'created_at', 'updated_at', 'is_delete', 'deleted_at', 'store_id'], 'integer'],
[['model'], 'safe'],
[['name', 'mobile'], 'string'],
[['name', 'store_id', 'mobile'], 'required'],
];
}
public function attributeLabels()
{
return [
'name' => '保洁姓名',
'mobile' => '保洁联系方式',
];
}
public function edit()
{
if (!$this->validate()) {
return $this->getModelError();
}
if (!$this->verifyMobile($this->mobile)) {
return $this->apiReturnError('请输入正确的手机号');
}
if ($this->model->isNewRecord) {
$this->model->is_delete = 0;
$this->model->deleted_at = 0;
$this->model->created_at = time();
}
$this->model->updated_at = time();
$this->model->name = $this->name;
$this->model->mobile = $this->mobile;
$this->model->store_id = $this->store_id;
$this->model->status = $this->status;
if (!$this->model->save()) {
return $this->getModelError($this->model);
}
return $this->apiReturnSuccess('保存成功');
}
private function verifyMobile($mobile)
{
if (preg_match("/^1[34578]\d{9}$/", $mobile)) {
return true;
} else {
return false;
}
}
}