request->post(); $row = $model->FindById($input['id']); switch ($type) { case 1: if($row->is_view == 1) { $row->is_view = 2; } else if($row->is_view == 2) { $row->is_view = 1; } break; case 2: $row->del = 2; break; } if($row->save() == true) return true; } public function GroupEdit() { $model = new GroupPurchase(); $validateData = $model->Authenticator(Yii::$app->request->post()); if(is_object($validateData)) { $row = $model->FindById(Yii::$app->request->post('id')); if($row != null) { $delIdentifying = false; $row['many_img'] = json_decode($row['many_img'],true); $delimg = Yii::$app->request->post('delimg'); //需要删除的数组 $ImgUrl = Yii::$app->params['img_url']['group']; $arrImg = []; if(!empty($delimg)) { $arrImg = array_diff($row['many_img'],$delimg); //需要保留的数组 如果删除全部图片 返回空数组 if(empty($arrImg)) { $delIdentifying = true; //标识是否删除所有图片 } foreach ($delimg as $val) { UploadFile::delImg($ImgUrl,$val); } } else { $arrImg = $row['many_img']; } $imgArr = \backend\server\UploadFile::InstancesImgName('img',$ImgUrl); if(is_array($imgArr)) { $arrImg = array_merge($imgArr,$arrImg); if(Yii::$app->request->post('thumb_watermark') == 1 ) { $ImgSet = new SetUploadImg(); $ImgSet->SetImgWatermark($imgArr,$ImgUrl); } //压缩图片 $compressParams = []; $compressParams['data']['imgname'] = $imgArr;; $compressParams['data']['url'] = $ImgUrl; $this->onCompress($compressParams); } $setAttr = Help::SetAttr(Yii::$app->request->post(),$validateData,$row); if(!empty($arrImg) || $delIdentifying == true) { $setAttr->many_img = json_encode($arrImg); } else { $setAttr->many_img = json_encode($setAttr->many_img); //没有修改图片的情况下 } $img_mobile = UploadFile::InstanceImgName('img_mobile',$ImgUrl); $img_pc = UploadFile::InstanceImgName('img_pc',$ImgUrl); if($img_mobile != false) { UploadFile::delImg($ImgUrl,$row['img_mobile']); $setAttr->img_mobile = $img_mobile; } if($img_pc != false) { UploadFile::delImg($ImgUrl,$row['img_pc']); $setAttr->img_pc = $img_pc; } if($setAttr->update() == true) return true; } } return $validateData; } public function GroupAdd() { $model = new GroupPurchase(); $auth = $model->Authenticator(Yii::$app->request->post()); if(is_object($auth)) { $url = Yii::$app->params['img_url']['group']; $img_mobile = UploadFile::InstanceImgName('img_mobile',$url); $img_pc = UploadFile::InstanceImgName('img_pc',$url); //处理多图图片 $row = \backend\server\UploadFile::InstancesImgName('img',$url); if(is_array($row)){ $model->many_img = json_encode($row); } if($img_mobile != false) { $auth->img_mobile = $img_mobile; } if($img_pc != false) { $auth->img_pc = $img_pc; } return $auth->save(false); } return false; } //压缩图片 private function onCompress($data) { $model = new \backend\event\TinifyEvent(); $model->CompressImg($data); } }