/** * [活动属性处理接口] * @param array $data 数据 * [ * 'rel_id' => '活动产品关联ID', * 'attrid' => '属性ID', * 'attrval' => '属性值', * 'type' => '活动产品关联ID', * 'id' => '图鉴属性ID', * 'delid' => '图鉴属性ID', * 'title' => '图片标题', * 'desc' => '图片描述', * 'pimage' => '图片', * ] * @return [json_encode] [0,1001] * 00 执行成功,已完成 * 01 执行成功,未完成 * 02 删除成功 * 1001 未登录 * 1004 参数错误 * 1005 图片上传错误 */ public function actionAttrprocess() { //判断登陆 $user = yii::$app->util->isLogin(); if ($user) { $uid = $user['uid']; } else { echo PublicLibrary::format_res_encode('1001', 'the user no landing or no ajax!'); exit; } $date = Yii::$app->request->post(); $date = array_map('trim', $date); $date = array_map('strip_tags', $date); $rel_id = isset($date['rel_id']) ? intval($date['rel_id']) : 0; $attrid = isset($date['attrid']) ? intval($date['attrid']) : 0; $attval = isset($date['attrval']) ? $date['attrval'] : ''; $type = isset($date['type']) ? $date['type'] : ''; $delid = isset($date['delid']) ? intval($date['delid']) : ''; //用活动产品id 获取活动id $mpactivity = new ActivityProduct(); $pcone = $mpactivity->pk($rel_id); //当前用户和产品活动发布用户不同 if (empty($pcone) || $uid != $pcone['user_id'] || $pcone['status'] == ActivityProduct::STATUS_VERIFYING) { echo yii::$app->util->formatResEncode('1003', 'user or status error!'); exit; } $acti_id = $pcone->acti_id ? $pcone->acti_id : 0; $product_id = $pcone->product_id ? $pcone->product_id : 0; if (empty($rel_id) || empty($attrid) || empty($acti_id) || empty($product_id)) { echo yii::$app->util->formatResEncode('1004', 'params error'); exit; } //查询属性基础信息 $mattrbase = new ActivityAttrBase(); $attr = $mattrbase->pk($attrid); if (!empty($type)) { $attribute = []; $content = []; $sign = false; //添加标示 $comsta = false; //完成度标示 $delstat = false; //删除标识 if ($type == "image") { $pimage_model = new ProductImage(); //删除 if ($delid) { if ($pimage_model->delBypk($delid)) { $delstat = true; } } else { $imgstatus = false; $pos_id = 100; //图片上传 $pimage = UploadedFile::getInstanceByName('pimage'); if ($pimage !== null) { //判断图片大小是否符合规定 if ($pimage->size > ProductImage::MAX_SIZE || $pimage->error != 0) { echo yii::$app->util->formatResEncode('1005', 'image error'); exit; } $rootpath = 'uploads/' . date('Y/m/d') . '/'; //图片保存路径 file_exists($rootpath) or mkdir($rootpath, 0777, true); //生成图片路径 $randname = time() . rand(0, 500); //图片公有名 $setpimage_path = $rootpath . $randname; //图路径 move_uploaded_file($pimage->tempName, $setpimage_path . '.jpg'); //生成缩略图 $sreturn = $this->smallimg($setpimage_path, 200, 125); //产品详细 $pimage_path = $sreturn ? $setpimage_path . ProductImage::THUMB_PDETIAL : $setpimage_path . '.jpg'; $content['url'] = $setpimage_path; $imgstatus = true; } //填写描述 if (!empty($date['id']) && !empty($date['desc'])) { $content['desc'] = $date['desc']; $imgstatus = true; } //填写标题 if (!empty($date['id']) && !empty($date['title'])) { $content['title'] = $date['title']; $imgstatus = true; } if ($imgstatus) { $content['product_id'] = $product_id; $content['type'] = $pos_id; if (isset($date['id']) && !empty($date['id'])) { $content['id'] = intval($date['id']); $imgid = $pimage_model->imageSave($content); } else { $pimid = $pimage_model->getByTypeAndPid($pos_id, $product_id); //详细图文介绍 图片个数不超过9个,超过9个不做新增操作 if (count($pimid) < 9 && $pos_id == 100) { // var_dump($date);die; $imgid = $pimage_model->imageSave($content); } } if (isset($imgid) && $imgid > 0) { $sign = $imgid; //判断该条信息是否完整 if ($pimage_model->iscomplete($imgid, "title")) { $complete = array('id' => $imgid, 'is_complete' => ProductImage::IS_COMPLETE); if ($pimage_model->imageSave($complete)) { $comsta = true; } } } } } } if ($type == "video") { // var_dump($date);die; $pvideo_model = new ProductVideo(); if (isset($date['video_url'])) { if (!empty($date['video_url'])) { $content['video_url'] = $date['video_url']; //$content['video_url'] = Yii::$app->util->generalVideo($date['video_url']); } $content['uid'] = $uid; $content['product_id'] = $product_id; if (isset($date['id']) && !empty($date['id'])) { $content['id'] = $date['id']; $videoid = $pvideo_model->store($content); // $sign = $videoid; } else { //一个产品的视频属性 只能存在一条,如果已经存在,不做新增操作, 返回存在的id值, $rvid = $pvideo_model->getByPid($product_id, true); if (!$rvid) { $videoid = $pvideo_model->store($content); } else { $videoid = isset($rvid['id']) ? $rvid['id'] : ''; } } if ($videoid) { $sign = $videoid; $comsta = true; } } } if ($delstat) { //+TOOD 删除 修改 产品属性值 表数据操作 echo yii::$app->util->formatResEncode('02', 'deletet success'); exit; } else { if ($sign) { $baseattr_model = new BaseAttribute(); $imgurl = isset($pimage_path) ? $pimage_path : ''; $videoid = isset($videoid) ? intval($videoid) : 1; if ($comsta) { $btas = $baseattr_model->save($rel_id, $uid, $attrid, $videoid, false, 1); echo yii::$app->util->formatResEncode('00', 'success', array('id' => $sign, 'imgurl' => $imgurl)); exit; } else { $btas = $baseattr_model->save($rel_id, $uid, $attrid, $videoid, false, 0); echo yii::$app->util->formatResEncode('01', 'success', array('id' => $sign, 'imgurl' => $imgurl)); exit; } } } } else { $mbaseattr = new BaseAttribute(); $btas = $mbaseattr->save($rel_id, $uid, $attrid, $attval, false, 1); echo yii::$app->util->formatResEncode('0', 'success'); exit; } }
/** * 365活动产品属性 处理接口 涉及 视频,图片,特性,合作伙伴 * @author song * @param int $rel_id 活动产品ID * @param int $attrid 活动产品属性值ID * @param string $type 判断涉及表 * = 'video' 视频 * video_url 视频地址 * video_title 视频标题 * video_summary 视频概述 * * = 'image' 图片 * pimages 图片name * desc 图片描述 * pos_id 图片位置标识 对应type字段 1:首屏背景,2:详细图文介绍 * * = 'character' 特性 * character_title 特性标题 * character_summary 特性概述 * * = 'partner' 合作伙伴 * partner_logo 合作伙伴logo * partner_title 合作伙伴标题 * * @param int $delid 需要删除的主键ID (在删除时出现) * * @return json 返回显示信息 */ public function actionProductattributefour() { //判断登陆 $user = PublicLibrary::is_login(); //if ($user && PublicLibrary::is_ajax()) { if ($user) { $uid = $user['uid']; } else { echo PublicLibrary::format_res_encode('1001', 'the user no landing or no ajax!'); exit; } //$uid = 25; $form = Yii::$app->request->post(); $date = array_map('trim', $form); $date = array_map('strip_tags', $date); $rel_id = isset($date['rel_id']) ? intval($date['rel_id']) : 0; $attrid = isset($date['attrid']) ? intval($date['attrid']) : 0; $type = isset($date['type']) ? $date['type'] : ''; $delid = isset($date['delid']) ? intval($date['delid']) : ''; //用活动产品id 获取活动id $pactivity_model = new ActivityProduct(); $pactivity = $pactivity_model->pk($rel_id); if ($pactivity) { $user_id = $pactivity->user_id ? $pactivity->user_id : 0; } else { $user_id = 0; } //当前用户和产品活动发布用户不同 if ($uid != $user_id) { echo PublicLibrary::format_res_encode('1003', 'user error'); exit; } $activity_id = $pactivity->acti_id ? $pactivity->acti_id : 0; $product_id = $pactivity->product_id ? $pactivity->product_id : 0; if (empty($rel_id) || empty($attrid) || empty($type) || empty($activity_id) || empty($product_id)) { echo PublicLibrary::format_res_encode('1004', 'params error'); exit; } $attribute = []; $content = []; $sign = false; //添加标示 $comsta = false; //完成度标示 $delstat = false; //删除标识 $isfull = false; //是否填满 switch ($type) { case 'video': $pvideo_model = new ProductVideo(); //删除 if ($delid) { if ($pvideo_model->delBypk($delid, $uid)) { $delstat = true; } } else { //添加/修改 if (isset($date['video_url']) || isset($date['video_title']) || isset($date['video_summary'])) { if (!empty($date['video_url'])) { $content['video_url'] = $date['video_url']; $content['video_url'] = Yii::$app->util->generalVideo($date['video_url']); } if (!empty($date['video_title'])) { $content['video_title'] = $date['video_title']; } if (!empty($date['video_summary'])) { $content['video_summary'] = $date['video_summary']; } $content['uid'] = $uid; $content['product_id'] = $product_id; if (isset($date['id']) && !empty($date['id'])) { $content['id'] = $date['id']; $videoid = $pvideo_model->store($content); } else { //一个产品的视频属性 只能存在一条,如果已经存在,不做新增操作, 返回存在的id值, $rvid = $pvideo_model->getByPid($product_id, true); if (!$rvid) { $videoid = $pvideo_model->store($content); } else { $videoid = isset($rvid['id']) ? $rvid['id'] : ''; } } if ($videoid) { $sign = $videoid; if ($pvideo_model->hasCompleteData($videoid)) { $comsta = true; } } } } break; case 'image': $pimage_model = new ProductImage(); //删除 if ($delid) { if ($pimage_model->delBypk($delid)) { $delstat = true; } } else { $imgstatus = false; $pos_id = isset($date['pos_id']) && $date['pos_id'] == ProductImage::TYPE_CATIONFIRST ? ProductImage::TYPE_CATIONFIRST : ProductImage::TYPE_CATIONINDE; //图片上传 $pimage = UploadedFile::getInstanceByName('pimage'); if ($pimage !== null && isset($pos_id)) { //判断图片大小是否符合规定 if ($pimage->size > ProductImage::MAX_SIZE || $pimage->error != 0) { echo PublicLibrary::format_res_encode('1005', 'image error'); exit; } $rootpath = 'uploads/' . date('Y/m/d') . '/'; //图片保存路径 file_exists($rootpath) or mkdir($rootpath, 0777, true); //生成图片路径 $randname = time() . rand(0, 500); //图片公有名 $setpimage_path = $rootpath . $randname; //封面图路径 move_uploaded_file($pimage->tempName, $setpimage_path . '.jpg'); //生成缩略图 if ($pos_id == ProductImage::TYPE_CATIONFIRST) { //首屏缩略图 // var_dump($setpimage_path); // echo $pos_id;die; $sreturn = $this->smallimg($setpimage_path, 280, 175); $pimage_path = $sreturn ? $setpimage_path . ProductImage::THUMB_PRODUCT : $setpimage_path . '.jpg'; } else { // var_dump($setpimage_path);die; $sreturn = $this->smallimg($setpimage_path, 200, 125); //产品详细 $pimage_path = $sreturn ? $setpimage_path . ProductImage::THUMB_PDETIAL : $setpimage_path . '.jpg'; } $content['url'] = $setpimage_path; $imgstatus = true; } //填写描述 if (!empty($date['id']) && !empty($date['desc']) && !empty($pos_id)) { $content['desc'] = $date['desc']; $imgstatus = true; } if ($imgstatus) { $content['product_id'] = $product_id; $content['type'] = $pos_id; if (isset($date['id']) && !empty($date['id'])) { $content['id'] = intval($date['id']); $imgid = $pimage_model->imageSave($content); } else { $pimid = $pimage_model->getByTypeAndPid($pos_id, $product_id); //详细图文介绍 图片个数不超过9个,超过9个不做新增操作 首屏背景 图片个数不超过1个,超过1个不做新增操作 $imgid = $pimage_model->imageSave($content); // if ((count($pimid) < 9 && $pos_id == ProductImage::TYPE_CATIONINDE) || // (count($pimid) < 1 && $pos_id == ProductImage::TYPE_CATIONFIRST)) { // $imgid = $pimage_model->imageSave($content); // } } if (isset($imgid) && $imgid > 0) { $sign = $imgid; //判断该条信息是否完整 if ($pimage_model->iscomplete($imgid)) { $complete = array('id' => $imgid, 'is_complete' => ProductImage::IS_COMPLETE); if ($pimage_model->imageSave($complete)) { $comsta = true; } } } } } break; //产品特性 //产品特性 case 'character': $pcharacter_model = new ProductCharacter(); //删除 if ($delid) { if ($pcharacter_model->characterDelete($delid, $uid)) { $delstat = true; } } else { if (isset($date['character_title']) || isset($date['character_summary'])) { $content['uid'] = $uid; $content['product_id'] = $product_id; if (!empty($date['character_title'])) { $content['character_title'] = $date['character_title']; } if (!empty($date['character_summary'])) { $content['character_summary'] = $date['character_summary']; } if (isset($date['id']) && !empty($date['id'])) { $content['id'] = $date['id']; $characid = $pcharacter_model->characterSave($content); } else { $pchid = $pcharacter_model->getByPid($product_id); //产品特性 超过9条特性 不在新增 if (count($pchid) < 9) { $characid = $pcharacter_model->characterSave($content); } } if (isset($characid) && $characid > 0) { $sign = $characid; //判断该条信息是否完整 if ($pcharacter_model->iscomplete($characid)) { $complete = array('id' => $characid, 'uid' => $uid, 'is_complete' => ProductCharacter::IS_COMPLETE); if ($pcharacter_model->characterSave($complete)) { $comsta = true; } } $comsta = $pcharacter_model->hasCompleteData($product_id); } } } break; //合作伙伴 //合作伙伴 case 'partner': $parter_model = new ProductPartner(); //删除 if ($delid) { if ($parter_model->remove($delid, $uid)) { $delstat = true; } } else { $pstatus = false; //图片上传 $partner_logo = UploadedFile::getInstanceByName('partner_logo'); if ($partner_logo !== null) { //判断图片大小是否符合规定 if ($partner_logo->size > ProductImage::MAX_SIZE || $partner_logo->error != 0) { echo PublicLibrary::format_res_encode('1006', 'partner image error'); exit; } $rootpath = 'uploads/' . date('Y/m/d') . '/'; //图片保存路径 file_exists($rootpath) or mkdir($rootpath, 0700, true); //生成图片路径 $randname = time() . rand(0, 500); //图片公有名 $setpimage_path = $rootpath . $randname; //封面图路径 move_uploaded_file($partner_logo->tempName, $setpimage_path . '.jpg'); //生成缩略图 $sreturn = $this->smallimg($setpimage_path, 200, 65); $pimage_path = $sreturn ? $setpimage_path . ProductPartner::THUMB_PARTNER : $setpimage_path . '.jpg'; $content['partner_logo'] = $setpimage_path; $pstatus = true; } //填写描述 if (isset($date['id']) && isset($date['partner_title'])) { $content['partner_title'] = $date['partner_title']; $pstatus = true; } if ($pstatus) { $content['activity_id'] = $activity_id; $content['user_id'] = $uid; $content['product_id'] = $product_id; if (isset($date['id'])) { $content['id'] = $date['id']; $parterid = $parter_model->store($content); } else { $ptrid = $parter_model->getByAidAndPid($activity_id, $product_id); if (count($ptrid) < 12) { $parterid = $parter_model->store($content); } } if (isset($parterid) && $parterid > 0) { $sign = $parterid; //判断该条信息是否完整 if ($parter_model->iscomplete($parterid)) { $complete = array('id' => $parterid, 'user_id' => $uid, 'complete_status' => ProductPartner::DATA_STATUS_COMPLETE); if ($parter_model->store($complete)) { $comsta = true; } } } } } break; default: $sign = false; break; } if ($delstat) { //+TOOD 删除 修改 产品属性值 表数据操作 echo PublicLibrary::format_res_encode('02', 'deletet success'); exit; } else { if ($sign) { $baseattr_model = new BaseAttribute(); $imgurl = isset($pimage_path) ? $pimage_path : ''; $videoid = isset($videoid) ? intval($videoid) : 1; if ($comsta) { $btas = $baseattr_model->save($rel_id, $uid, $attrid, $videoid, false, 1); echo PublicLibrary::format_res_encode('00', 'success', array('id' => $sign, 'imgurl' => $imgurl)); exit; } else { $btas = $baseattr_model->save($rel_id, $uid, $attrid, $videoid, false, 0); echo PublicLibrary::format_res_encode('01', 'success', array('id' => $sign, 'imgurl' => $imgurl)); exit; } } } echo PublicLibrary::format_res_encode('1008', 'error'); exit; }
/** * 产品预览 * @param array $_POST 产品相关信息 * @return array $model 显示产品相关信息 */ public function actionPreview() { $form = Yii::$app->request->post('extra'); //数据过滤 $tmp = isset($form['detail']) ? $form['detail'] : ''; $form = array_map('trim', $form); $form = array_map('strip_tags', $form); $form = array_map('htmlspecialchars', $form); $form['detail'] = $tmp; // <script>alert('zhanglu');</script> //bug处理 限定name 和summary长度 $form['name'] = mb_substr($form['name'], 0, 20, 'utf-8'); $form['summary'] = mb_substr($form['summary'], 0, 100, 'utf-8'); //获取hash值 $formhash = Yii::$app->request->post('formhash', false); //formhash验证 if (!PublicLibrary::verifyFormhash($formhash)) { echo '<script>alert("非法提交!");window.close;</script>'; exit; } else { $session = Yii::$app->session; $session->isActive ? '' : $session->open(); $session->set('formhash', $formhash); $session->close(); } $user = PublicLibrary::is_login(); //判断是否登陆 if (!$user) { $this->redirect(['user/login', 'act' => base64_encode("home-page/lists")]); } //判断产品是否是该用户的 $mIProductBase = new IProductBase(); $res = $mIProductBase->isMyProduct($user['uid'], intval($form['id'])); if (empty($res)) { return $this->redirect(['index']); exit; } //判断产品是否是该用户的 $mIProductBase = new IProductBase(); if (!$mIProductBase->isMyProduct($user['uid'], $form['id'])) { $this->redirect(['home-page/lists', 'uid' => $user['uid']]); } if (empty($form['summary']) || empty($form['name'])) { echo '<script>alert("产品名和简介都不能为空!");window.history.back(-1);</script>'; exit; } else { //对i_product_extra表的插入或修改 $model = IProductExtra::findOne(['product_id' => $form['id']]); if ($model == null) { $model = new IProductExtra(); $model->create_time = time(); } $model->product_id = intval($form['id']); $model->summary = strip_tags($form['summary']); $model->video_url = strip_tags($form['video_url']); $model->detail = $form['detail']; $model->update_time = time(); $model->save(); //对i_product_base表的插入或修改 $model_base = IProductBase::findOne(['id' => $form['id']]); $model_base->update_time = time(); $model_base->save(); //album图片上传 $album = UploadedFile::getInstanceByName('album'); //试取图片album if ($album !== null) { //判断图片大小是否符合规定 if ($album->size > 1048576 || $album->error != 0) { echo '<script>alert("封面图片格式不对或大于1M!");window.history.back(-1);</script>'; exit; } //判断封面图片是否存在,或是修改 $model = IProductBase::findOne(['id' => $form['id']]); $albumPath = $model->album; if (!$albumPath) { $rootpath = 'uploads/' . date('Y/m/d') . '/'; //图片保存路径 file_exists($rootpath) or mkdir($rootpath, 0700, true); //生成图片路径 $randname = time() . rand(0, 500); //图片公有名 $albumPath = $rootpath . $randname; //封面图路径 } //缩略图入库用 $tmp = $albumPath; $thumbPath = $albumPath . ProductImage::THUMB_SIZE_ONE; //缩略图路径 //生成缩略图 $width = 312; $height = 196; $thumbPath = '@frontend/web/' . $thumbPath . '.jpg'; Image::thumbnail($album->tempName, $width, $height)->save(Yii::getAlias($thumbPath), ['quality' => 100]); //原图上传 $album->saveAs($albumPath . '.jpg'); $model->album = $albumPath; $model->name = strip_tags($form['name']); $model->price = strip_tags($form['price']); //原价 $model->status = IProductBase::STATUS_INVALID; $model->save(); //缩略图入库image表 $mProductImage = new ProductImage(); $re = $mProductImage->getByTypeAndPid(ProductImage::TYPE_ALBUM, $form['id']); //判断图片表中有没有该产品缩略图 if (empty($re)) { $content = ['product_id' => $form['id'], 'type' => ProductImage::TYPE_ALBUM, 'url' => $tmp, 'create_time' => time()]; $mProductImage->imageSave($content); } } else { $model = IProductBase::findOne(['id' => $form['id']]); if ($model->album !== '') { $albumPath = $model->album . '.jpg'; $thumbPath = $model->album . ProductImage::THUMB_SIZE_ONE . '.jpg'; file_exists($albumPath) && unlink($albumPath); file_exists($thumbPath) && unlink($thumbPath); $model->album = ''; } $model->name = strip_tags($form['name']); $model->price = strip_tags($form['price']); //原价 $model->status = IProductBase::STATUS_INVALID; $model->save(); //删除缩略图 $mProductImage = new ProductImage(); //判断图片表中有没有该产品缩略图 $re = $mProductImage->getByTypeAndPid(ProductImage::TYPE_ALBUM, $form['id']); if (!empty($re)) { $mProductImage->delBypk($re[0]['id']); } } //图片1上传 $banner1 = UploadedFile::getInstanceByName('bigbanner1'); //试取图片album if ($banner1 !== null) { //判断图片大小是否符合规定 if ($banner1->size > 1048576 * 2 || $banner1->error != 0) { echo '<script>alert("通栏图片格式不对或大于2M!");window.history.back(-1);</script>'; exit; } $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 1]); if ($model !== null) { $banner1->saveAs($model->url . '.jpg'); } else { $rootpath = 'uploads/' . date('Y/m/d') . '/'; //图片保存路径 file_exists($rootpath) or mkdir($rootpath, 0700, true); //生成图片路径 $randname = time() . rand(0, 500); //图片名 $bannerPath = $rootpath . $randname; //封面图路径 $banner1->saveAs($bannerPath . '.jpg'); //保存图片 //插入数据 $model = new ProductImage(); $model->product_id = $form['id']; $model->url = $bannerPath; $model->create_time = time(); $model->type = ProductImage::TYPE_BANNER; $model->pos_id = 1; $model->save(); } } else { $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 1]); if ($model !== null) { file_exists($model->url . '.jpg') && unlink($model->url . '.jpg'); $model->delete(); } } //图片1在i_product_base 中是否存在 $modelImage = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 1]); $modelBase = IProductBase::findOne(['id' => $form['id']]); if ($modelImage !== null) { $modelBase->banner_image = $modelImage->url; $modelBase->save(); } else { $modelBase->banner_image = ''; $modelBase->save(); } //图片2上传 $banner2 = UploadedFile::getInstanceByName('bigbanner2'); //试取图片album if ($banner2 !== null) { //判断图片大小是否符合规定 if ($banner2->size > 1048576 * 2 || $banner2->error != 0) { echo '<script>alert("通栏图片格式不对或大于2M!");window.history.back(-1);</script>'; exit; } $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 2]); if ($model !== null) { $banner2->saveAs($model->url . '.jpg'); } else { $rootpath = 'uploads/' . date('Y/m/d') . '/'; //图片保存路径 file_exists($rootpath) or mkdir($rootpath, 0700, true); //生成图片路径 $randname = time() . rand(0, 500); //图片名 $bannerPath = $rootpath . $randname; //封面图路径 $banner2->saveAs($bannerPath . '.jpg'); //保存图片 //插入数据 $model = new ProductImage(); $model->product_id = $form['id']; $model->url = $bannerPath; $model->create_time = time(); $model->type = ProductImage::TYPE_BANNER; $model->pos_id = 2; $model->save(); } } else { $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 2]); if ($model !== null) { file_exists($model->url . '.jpg') && unlink($model->url . '.jpg'); $model->delete(); } } //图片3上传 $banner3 = UploadedFile::getInstanceByName('bigbanner3'); //试取图片album if ($banner3 !== null) { //判断图片大小是否符合规定 if ($banner3->size > 1048576 * 2 || $banner3->error != 0) { echo '<script>alert("通栏图片格式不对或大于2M!");window.history.back(-1);</script>'; exit; } $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 3]); if ($model !== null) { $banner3->saveAs($model->url . '.jpg'); } else { $rootpath = 'uploads/' . date('Y/m/d') . '/'; //图片保存路径 file_exists($rootpath) or mkdir($rootpath, 0700, true); //生成图片路径 $randname = time() . rand(0, 500); //图片名 $bannerPath = $rootpath . $randname; //封面图路径 $banner3->saveAs($bannerPath . '.jpg'); //保存图片 //插入数据 $model = new ProductImage(); $model->product_id = $form['id']; $model->url = $bannerPath; $model->create_time = time(); $model->type = ProductImage::TYPE_BANNER; $model->pos_id = 3; $model->save(); } } else { $model = ProductImage::findOne(['product_id' => $form['id'], 'pos_id' => 3]); if ($model !== null) { file_exists($model->url . '.jpg') && unlink($model->url . '.jpg'); $model->delete(); } } } return $this->redirect(['product/view', 'id' => $form['id']]); //跳转到完善信息 }