143 lines
3.4 KiB
PHP
143 lines
3.4 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\FlashStorage;
|
|
use app\models\Admin;
|
|
use app\models\auth\RoleUser;
|
|
use app\models\Box;
|
|
use app\models\Model;
|
|
use app\models\Store;
|
|
use app\models\StoreUser;
|
|
use app\models\User;
|
|
use app\modules\admin\models\AdminModel;
|
|
use app\modules\api\models\StoreCityForm;
|
|
use yii\data\Pagination;
|
|
|
|
class BoxActionForm extends AdminModel
|
|
{
|
|
|
|
public $ids;
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
[['ids'], 'required'],
|
|
[['ids'], 'safe'],
|
|
];
|
|
}
|
|
|
|
public function attributeLabels()
|
|
{
|
|
return [
|
|
'ids' => '选择项',
|
|
];
|
|
}
|
|
|
|
//删除
|
|
public function delete()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
foreach ($this->ids as $item) {
|
|
$model = Box::findOne([
|
|
'id' => $item,
|
|
'is_delete' => 0,
|
|
]);
|
|
if ($model == null) {
|
|
return Model::asReturnError('该包厢不存在或已被清理');
|
|
}
|
|
if ($model->is_delete == 1) {
|
|
continue;
|
|
}
|
|
|
|
$model->is_delete = 1;
|
|
$model->deleted_at = time();
|
|
if (!$model->save()) {
|
|
$t->rollBack();
|
|
return Model::getModelErrorInfo($model);
|
|
}
|
|
}
|
|
|
|
$t->commit();
|
|
return Model::asReturnSuccess('操作成功');
|
|
|
|
|
|
}
|
|
|
|
//开启
|
|
public function statusYes()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
foreach ($this->ids as $item) {
|
|
$model = Box::findOne([
|
|
'id' => $item,
|
|
'is_delete' => 0,
|
|
]);
|
|
if ($model == null) {
|
|
return Model::asReturnError('该包厢不存在或已被清理');
|
|
}
|
|
if ($model->status == 1) {
|
|
continue;
|
|
}
|
|
|
|
$model->status = 1;
|
|
$model->updated_at = time();
|
|
if (!$model->save()) {
|
|
$t->rollBack();
|
|
return Model::getModelErrorInfo($model);
|
|
}
|
|
}
|
|
$t->commit();
|
|
return Model::asReturnSuccess('操作成功');
|
|
}
|
|
|
|
//关闭
|
|
public function statusNo()
|
|
{
|
|
if (!$this->validate()) {
|
|
return $this->getModelError();
|
|
}
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
foreach ($this->ids as $item) {
|
|
$model = Box::findOne([
|
|
'id' => $item,
|
|
'is_delete' => 0,
|
|
]);
|
|
if ($model == null) {
|
|
return Model::asReturnError('该包厢不存在或已被清理');
|
|
}
|
|
if ($model->status == 2) {
|
|
continue;
|
|
}
|
|
$model->status = 2;
|
|
$model->updated_at = time();
|
|
if (!$model->save()) {
|
|
$t->rollBack();
|
|
return Model::getModelErrorInfo($model);
|
|
}
|
|
}
|
|
$t->commit();
|
|
return Model::asReturnSuccess('操作成功');
|
|
}
|
|
|
|
|
|
} |