/** * [用户关注] * @param [int] $passive_uid [被关注用户id] * @param [int] $type [1,2] * 1 关注 2 取消关注 * 0 执行成功 1001 参数错误 1002 系统繁忙 1003请求出错 * 接口:http://idaiyan_new.cn/frontend/web/index.php?r=ucenter/follow */ public function actionFollow() { //判断登陆 $user = PublicLibrary::is_login(); if (empty($user) || !PublicLibrary::is_ajax()) { echo PublicLibrary::format_res_encode('1002', 'login or ajax error'); exit; } if (Yii::$app->request->isPost) { $passive_uid = Yii::$app->request->post('passive_uid') ? intval(Yii::$app->request->post('passive_uid')) : ''; $type = Yii::$app->request->post('type') ? intval(Yii::$app->request->post('type')) : ''; if (empty($passive_uid) || empty($type)) { echo PublicLibrary::format_res_encode('1001', 'param error'); exit; } // $passive_uid = 3; //$user['uid'] = 5; // $type = 1; $memberfollow_model = new MemberFollow(); $MemberStat_model = new MemberStat(); if ($type == 1) { $follow = $memberfollow_model->SetMemberFollow($passive_uid, $user['uid']); if ($follow == -3) { $follow_num = count($memberfollow_model->getFollowMember($passive_uid)); } else { //$MemberStat_model->incr($user['uid'], 'follow_num'); $MemberStat_model->incr($passive_uid, 'follow_num'); $data = $MemberStat_model->getByUid($passive_uid); $follow_num = $data['follow_num']; //var_dump($follow_num);die; } } else { $follow = $memberfollow_model->unMemberFollow($passive_uid, $user['uid']); //$MemberStat_model->decr($user['uid'], 'follow_num'); $MemberStat_model->decr($passive_uid, 'follow_num'); $data = $MemberStat_model->getByUid($passive_uid); $follow_num = $data['follow_num']; //var_dump($follow_num);die; } //重新读取关注 赋值 session $userfollow = $memberfollow_model->getMemberFollow($user['uid']); //$userfollow = array_column($userfollow, 'passive_uid'); //$userfollow = array_map("array_pop",$userfollow1); $userfollow = ArrayHelper::getColumn($userfollow, 'passive_uid'); $session = Yii::$app->session; $session->isActive ? '' : $session->open(); $session->set('follow_user', $userfollow); // var_dump($session['follow_user']); if ($follow) { // //重新读取关注 赋值 session // $userfollow = $memberfollow_model->getMemberFollow($user['uid']); // //$userfollow = array_column($userfollow, 'passive_uid'); // //$userfollow = array_map("array_pop",$userfollow1); // $userfollow = ArrayHelper::getColumn($userfollow, 'passive_uid'); // $session = Yii::$app->session; // $session->isActive?'':$session->open(); // $session->set('follow_user', $userfollow); // // var_dump($session['follow_user']); echo PublicLibrary::format_res_encode('0', 'success', array('follow' => $follow_num)); } else { echo PublicLibrary::format_res_encode($follow, 'params error'); } } else { echo PublicLibrary::format_res_encode('1003', 'request error'); } }
/** * 产品更新 [发布/修改/预览] * @param [int] $id [产品id] * @return [array] $product [产品相关信息] * @return [int] $id [产品id] * @return [string] $url [地址] * @return [string] $formhash [哈希值验证] */ public function actionRenew() { $form = Yii::$app->request->post('extra'); // print_r($form);exit; //获取hash值 $formhash = Yii::$app->request->post('formhash', false); $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; } //formhash验证 if (!PublicLibrary::verifyFormhash($formhash)) { echo '<script>alert("非法提交!");window.history.back(-1);</script>'; exit; } if (empty($form['apply_role']) || empty($form['user_oriented_age'])) { echo '<script>alert("代言角色和面向群体都不能为空!");window.history.back(-1);</script>'; exit; } if (isset($form)) { if (empty($form['summary']) || empty($form['name'])) { echo '<script>alert("产品名和简介都不能为空!");window.history.back(-1);</script>'; exit; } else { //上传封面图片 if ($_FILES['album']['name'] != '') { if ($_FILES['album']['size'] > ProductImage::MAX_SIZE || $_FILES['album']['error'] != 0) { echo '<script>alert("封面图片格式不对或大于1M!");window.history.back(-1);</script></script>'; exit; } } //album图片上传 $album = UploadedFile::getInstanceByName('album'); //试取图片album if ($album !== null) { //判断图片大小是否符合规定 if ($album->size > ProductImage::MAX_SIZE || $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; //封面图路径 } $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->save(); } //上传封面图片结束 //banner1上传 $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->pos_id = 1; $model->save(); } } //图片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(); } //banner1上传结束 //banner2上传 if ($_FILES['bigbanner2']['name'] != '') { if ($_FILES['bigbanner2']['size'] > 1048576 * 2 || $_FILES['bigbanner2']['error'] != 0) { echo '<script>alert("通栏第二张图片格式不对或大于2M!");window.history.back(-1);</script></script>'; exit; } } //图片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 = intval($form['id']); $model->url = $bannerPath; $model->create_time = time(); $model->pos_id = 2; $model->save(); } } //banner2上传结束 //banner3上传 if ($_FILES['bigbanner3']['name'] != '') { if ($_FILES['bigbanner3']['size'] > 1048576 * 2 || $_FILES['bigbanner3']['error'] != 0) { echo '<script>alert("通栏第三张图片格式不对或大于2M!");window.history.back(-1);</script></script>'; exit; } } //图片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 = intval($form['id']); $model->url = $bannerPath; $model->create_time = time(); $model->pos_id = 3; $model->save(); } } //banner3上传结束 //对i_product_base表的修改 //年龄段的处理 $age = isset($form['user_oriented_age']) ? $form['user_oriented_age'] : array(); if (!$age) { $age_nums = 0; } else { $age_nums = array_sum($age); } $IProductBase = new IProductBase(); //状态判断 $act = Yii::$app->request->get(); //判断产品是的状态 $res = IProductBase::find()->select('status')->where('id = :id', [':id' => $form['id']])->asArray()->one(); $session = Yii::$app->session; $session->isActive ? '' : $session->open(); $MemberStat = new MemberStat(); if (!empty($act['act'])) { if ($act['act'] == 'save') { //点击保存 if ($res['status'] == IProductBase::STATUS_VERIFEND) { //去过是发布状态 用户统计表产品减一 $MemberStat->decr($session['user']['uid'], 'product_num'); } $status = IProductBase::STATUS_VERIFING; } elseif ($act['act'] == 'view') { //点击预览 if ($res['status'] != IProductBase::STATUS_VERIFEND) { $status = IProductBase::STATUS_INVALID; //保持预览状态 } else { $status = IProductBase::STATUS_VERIFEND; //过去是发布状态,保持原状态 } } } else { if ($res['status'] != IProductBase::STATUS_VERIFEND) { //去过不是发布状态 用户统计表产品加一 $MemberStat->incr($session['user']['uid'], 'product_num'); } $status = IProductBase::STATUS_VERIFEND; } $datab = ['id' => intval($form['id']), 'type' => intval($form['tid']), 'apply_role' => intval($form['apply_role']), 'user_oriented_gender' => intval($form['user_oriented_gender']), 'user_oriented_age' => $age_nums, 'name' => strip_tags($form['name']), 'price' => strip_tags($form['price']), 'province' => strip_tags($form['province']), 'city' => strip_tags($form['city']), 'status' => $status, 'update_time' => time()]; $base = $IProductBase->store($datab); if (!$base) { echo '<script>alert("非法提交!");window.history.back(-1);</script>'; exit; } $detaile = PublicLibrary::msg_safe($form['detail']); //对i_product_extra表的插入或修改 $data = ['product_id' => intval($form['id']), 'summary' => strip_tags($form['summary']), 'video_url' => strip_tags($form['video_url']), 'detail' => $detaile, 'update_time' => time()]; $IProductExtra = new IProductExtra(); $extra = $IProductExtra->store($data); if (!$extra) { echo '<script>alert("非法提交!");window.history.back(-1);</script>'; exit; } $session = Yii::$app->session; $session->isActive ? '' : $session->open(); if (!empty($act['act']) && $act['act'] == 'view') { return $this->redirect(['product/view', 'id' => $form['id']]); //跳转到产品详细页 } else { return $this->redirect(['home-page/lists', 'uid' => $_SESSION['user']['uid'], 'pid' => $form['id']]); //跳转到个人中心 } } } else { echo '<script>alert("非法提交!");window.history.back(-1);</script>'; exit; } }