129 lines
3.4 KiB
PHP
129 lines
3.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-5
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
|
|
namespace app\modules\admin\models\ball;
|
|
|
|
use app\components\FlashStorage;
|
|
use app\models\auth\RoleUser;
|
|
use app\models\BallCart;
|
|
use app\models\CardUnion;
|
|
use app\models\District;
|
|
use app\models\Model;
|
|
use app\models\SysAdmin;
|
|
use app\models\User;
|
|
use app\modules\admin\models\AdminModel;
|
|
use app\models\common\CommonUserEditForm;
|
|
use app\modules\api\models\StoreCityForm;
|
|
|
|
class BallEditForm extends AdminModel
|
|
{
|
|
|
|
public $model;
|
|
|
|
public $name;
|
|
public $desc;
|
|
public $money;
|
|
|
|
public $created_at;
|
|
public $updated_at;
|
|
public $is_delete;
|
|
public $deleted_at;
|
|
public $status;
|
|
public $store_id;
|
|
public $mark_id;
|
|
public $ball_number;
|
|
public $cover_pic;
|
|
public $content;
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['name'], 'required'],
|
|
[['desc'], 'string'],
|
|
[['money'], 'string'],
|
|
[['cover_pic'], 'string'],
|
|
[['content'], 'string'],
|
|
[['ball_number'], 'string'],
|
|
[['store_id'], 'integer'],
|
|
[['mark_id'], 'integer'],
|
|
[['is_delete', 'created_at', 'updated_at', 'deleted_at', 'status'], 'integer'],
|
|
[['name'], 'string', 'max' => 50],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'id' => 'ID',
|
|
'name' => 'Name',
|
|
'desc' => 'Desc',
|
|
'is_delete' => 'Is Delete',
|
|
'created_at' => 'Created At',
|
|
'updated_at' => 'Updated At',
|
|
'deleted_at' => 'Deleted At',
|
|
'status' => 'Status',
|
|
];
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
|
|
if ($this->model->isNewRecord) {
|
|
$this->model->is_delete = 0;
|
|
$this->model->deleted_at = 0;
|
|
$this->model->created_at = time();
|
|
|
|
$exists = BallCart::find()->where(['ball_number' => $this->ball_number,'is_delete' => 0])->exists();
|
|
if($exists){
|
|
return $this->apiReturnError('球车编号已存在');
|
|
}
|
|
}
|
|
|
|
if(!empty($this->model) && $this->model->ball_number != $this->ball_number){
|
|
$exists = BallCart::find()->where(['ball_number' => $this->ball_number,'is_delete' => 0])->exists();
|
|
if($exists){
|
|
return $this->apiReturnError('球车编号已存在');
|
|
}
|
|
}
|
|
$this->model->updated_at = time();
|
|
$this->model->name = $this->name;
|
|
$this->model->money = $this->money;
|
|
$this->model->cover_pic = $this->cover_pic;
|
|
$this->model->ball_number = $this->ball_number;
|
|
$this->model->store_id = $this->store_id;
|
|
$this->model->mark_id = $this->mark_id;
|
|
$this->model->content = $this->content;
|
|
|
|
if ($this->desc) {
|
|
$this->model->desc = $this->desc;
|
|
}
|
|
if ($this->status) {
|
|
$this->model->status = $this->status;
|
|
}
|
|
|
|
if (!$this->model->save()) {
|
|
return $this->getModelError($this->model);
|
|
}
|
|
return $this->apiReturnSuccess('保存成功');
|
|
}
|
|
|
|
|
|
} |