164 lines
4.4 KiB
PHP
164 lines
4.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-11-5
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
|
|
namespace app\modules\admin\models\storeMake;
|
|
|
|
use function AlibabaCloud\Client\value;
|
|
use app\components\FlashStorage;
|
|
use app\models\Admin;
|
|
use app\models\auth\RoleUser;
|
|
use app\models\Model;
|
|
use app\models\Store;
|
|
use app\models\StoreMake;
|
|
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 StoreMakeActionForm extends AdminModel
|
|
{
|
|
|
|
public $ids;
|
|
|
|
public $user_id;
|
|
|
|
public $id;
|
|
public $make_time;
|
|
public $store_id;
|
|
|
|
public function rules()
|
|
{
|
|
|
|
}
|
|
|
|
public function attributeLabels()
|
|
{
|
|
|
|
}
|
|
|
|
//删除
|
|
public function delete()
|
|
{
|
|
// if (!$this->validate()) {
|
|
// return $this->getModelError();
|
|
// }
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
|
|
foreach ($this->ids as $item) {
|
|
$model = StoreUser::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);
|
|
}
|
|
$user = User::findOne(['id' => $model->user_id]);
|
|
if ($user != null) {
|
|
$user->type = 0;
|
|
if (!$user->save()) {
|
|
$t->rollBack();
|
|
return Model::getModelErrorInfo($user);
|
|
}
|
|
}
|
|
if ($model->user_type == '1') {
|
|
$admin = \Yii::$app->db->createCommand()->update(Admin::tableName(), ['is_delete' => 1], ['user_id' => $model->user_id, 'is_delete' => 0])->execute();
|
|
$role = RoleUser::updateAll(['is_delete' => 1], ['is_delete' => 0, 'user_id' => $model->user_id, 'cx_mch_id' => 0]);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
$t->commit();
|
|
return Model::asReturnSuccess('操作成功');
|
|
|
|
|
|
}
|
|
|
|
//正常
|
|
public function statusYes()
|
|
{
|
|
|
|
$this->make_time = strtotime($this->make_time);
|
|
|
|
//根据预约时间 查询已通过的预约店长
|
|
$model = StoreMake::findOne([
|
|
// 'id' => $this->id,
|
|
'store_id' => $this->store_id,
|
|
'is_delete' => 0,
|
|
'make_time' => $this->make_time,
|
|
'status' => 1,
|
|
]);
|
|
if ($model) {
|
|
return Model::asReturnError('该时间段已有店长');
|
|
}
|
|
|
|
$select = StoreMake::find()->andWhere([
|
|
'is_delete' => 0,
|
|
'store_id' => $this->store_id,
|
|
'make_time' => $this->make_time,
|
|
])->asArray()->all();
|
|
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
foreach ($select as $key => $value) {
|
|
if ($value['id'] == $this->id) {
|
|
$storeMake = StoreMake::updateAll(['status' => 1, 'updated_at' => time()], ['id' => $this->id]);
|
|
if (!$storeMake) {
|
|
$t->rollBack();
|
|
return Model::asReturnError('分配失败111');
|
|
}
|
|
} else {
|
|
$storeMake = StoreMake::updateAll(['status' => 2, 'updated_at' => time()], ['id' => $value['id']]);
|
|
if (!$storeMake) {
|
|
|
|
|
|
$t->rollBack();
|
|
return Model::asReturnError('分配失败222');
|
|
}
|
|
}
|
|
}
|
|
$t->commit();
|
|
return Model::asReturnSuccess('操作成功');
|
|
}
|
|
|
|
//封禁
|
|
public function statusNo()
|
|
{
|
|
$model = StoreMake::findOne([
|
|
'id' => $this->id,
|
|
'is_delete' => 0,
|
|
// 'status' => 0,
|
|
]);
|
|
if ($model == null) {
|
|
return Model::asReturnError('该账号不存在或已被清理');
|
|
}
|
|
|
|
$model->status = 2;
|
|
$model->updated_at = time();
|
|
if (!$model->save()) {
|
|
return Model::getModelErrorInfo($model);
|
|
}
|
|
return Model::asReturnSuccess('操作成功');
|
|
}
|
|
|
|
|
|
} |