/** * 用户产品列表 * * 个人中心产品列表显示 * * @param int $uid 用户的id号 * * @return array 个人中心产品列表页渲染所有数据 */ public function actionLists() { // print_r($_GET);exit; $uid = Yii::$app->request->get('uid'); $uid = intval($uid); $self = false; //表示身份 $login = PublicLibrary::is_login() ? PublicLibrary::is_login() : ''; //异常默认uid if (empty($uid) && PublicLibrary::is_login()) { $uid = $login['uid']; } //判断是否登录 if ($login !== '' && $login['uid'] == $uid) { $self = true; } //用户信息 $member = new Member(); $user = $member->getByUid($uid); // print_r($user);exit; //完善用户信息 if (!$user) { //是否存在该用户 return $this->redirect(['product/index']); } else { $user['renqi'] = isset($user['memberstar']) && is_array($user['memberstar']) ? array_sum($user['memberstar']) : 0; //用户位置信息 $dist = new District(); if (!empty($user['city'])) { $user['address'] = $dist->getByCity($user['city']['id']); } else { // $user['address'] = $dist->getByCity(40); $user['address'] = ['name' => '不详', 'province' => '地址']; } //获取用户头像 $user['avatar'] = PublicLibrary::getBigAvatar($user['avatar']); //获取用户发布产品个数数据 $iProductBase = new IProductBase(); $user['pub_num'] = $iProductBase->getCountByUid($uid); } //筛选map $activeMap = ['0' => '全部', '1' => '即将开始', '2' => '预定中', '3' => '已结束']; //游客和自己可以看的map是不同的 if ($self) { //筛选参数处理 $statusMap = ['0' => '全部', '2' => '待发布', '3' => '审核中', '4' => '发布中', '6' => '审核未通过']; $orderMap = ['0' => '全部', '1' => '最新发布', '2' => '支持最多', '3' => '最新更新']; } else { //筛选参数处理 $statusMap = ['0' => '全部', '2' => '待发布']; $orderMap = ['0' => '默认', '1' => '最新发布', '2' => '支持最多', '3' => '最新更新']; } $params = []; $type = Yii::$app->request->get('type') ? Yii::$app->request->get('type') : 0; $type = intval($type); in_array($type, array_keys($statusMap)) ? $params['type'] = $type : ($params['type'] = 0); $stat = Yii::$app->request->get('stat') ? Yii::$app->request->get('stat') : 0; $stat = intval($stat); in_array($stat, array_keys($activeMap)) ? $params['stat'] = $stat : ($params['stat'] = 0); $order = Yii::$app->request->get('order') ? Yii::$app->request->get('order') : 0; $order = intval($order); in_array($order, array_keys($orderMap)) ? $params['order'] = $order : ($params['order'] = 0); $iProductBase = new IProductBase(); $list = $iProductBase->choose($uid, $type, $stat, $order); //获取用户没有删除的产品总数 $user['count'] = $iProductBase->hasCountByUid($uid); // print_r($user['count']);exit; //修该 $list便于模板展示 //未填第二步发布信息,提示信息map $map = ['roles' => ['1' => '创始人', '2' => '合伙人', '3' => '分销推广代表', '4' => '投资人', '5' => '股东', '6' => '企业法人', '7' => '继承人', '8' => '投资人', '9' => '股东', '10' => '企业法人', '11' => '继承人'], 'ages' => ['1' => '0-15周岁', '10' => '16-30周岁', '100' => '30-60周岁', '1000' => '60周岁以上'], 'gender' => ['0' => '全部', '1' => '男', '2' => '女']]; //活动map $activityBase = new ActivityBase(); $activesMap = $activityBase->getActivityMap(); //休整$list——便于显示 // print_r($list);exit; foreach ($list as $k => $v) { if ($v['status'] == IProductBase::STATUS_VERIFEND) { //产品都是发布成功的——状态为4 //功能判断标志 $rendMark = ['del' => 1, 'update' => 1, 'apply' => 1]; //产品发布天数 $days = floor((time() - $v['create_time']) / 86400); $list[$k]['days'] = $days; if (!empty($v['aproduct'])) { //有活动 //到期时间——默认为true到期 $endTime = true; //活动计数 $num = 0; foreach ($v['aproduct'] as $ki => $vi) { // print_r(!$self);exit; //当游客看时 取出不合格的活动信息 if ($self) { if ($vi['acti_id'] == ActivityBase::FANS_FESTIVAL) { unset($list[$k]['aproduct'][$ki]); continue; } } else { if ($vi['acti_id'] == ActivityBase::FANS_FESTIVAL || $vi['status'] != ActivityProduct::STATUS_VERIFY_THROUGH) { unset($list[$k]['aproduct'][$ki]); continue; } } $num++; if ($vi['end_time'] > time()) { $endTime = false; } //删除功能 if ($vi['status'] == ActivityProduct::STATUS_VERIFYING || $vi['status'] == ActivityProduct::STATUS_VERIFY_THROUGH) { //审核中或有通过审核的 $rendMark['del'] = 0; } //编辑功能 if ($vi['status'] == ActivityProduct::STATUS_VERIFYING) { $rendMark['update'] = 0; } //活动申请 if ($num == 4 || $vi['status'] == ActivityProduct::STATUS_VERIFYING || $vi['status'] == ActivityProduct::STATUS_VERIFY_NOTTHROUGH || $vi['status'] == ActivityProduct::STATUS_SAVE) { $rendMark['apply'] = 0; } //状态显示 $map1 = ['flow' => '', 'now' => time()]; if ($vi['status'] == ActivityProduct::STATUS_SAVE) { $map1['flow'] = '保存中'; } else { if ($vi['status'] == ActivityProduct::STATUS_VERIFYING) { $map1['flow'] = '审核中'; } else { if ($vi['status'] == ActivityProduct::STATUS_VERIFY_NOTTHROUGH) { $map1['flow'] = '审核未通过'; } else { if ($vi['status'] == ActivityProduct::STATUS_VERIFY_THROUGH) { if (!empty($vi['start_time']) || !empty($vi['end_time'])) { $start = $vi['start_time']; $end = $vi['end_time']; } else { $start = $activesMap[$vi['acti_id']]['start_time']; $end = $activesMap[$vi['acti_id']]['end_time']; } // $start = $vi['start_time']; // $end = $vi['end_time']; $now = time(); if ($now < $start) { $map1['flow'] = '即将开始'; } else { if ($end > $now && $now >= $start) { $map1['flow'] = '进行中'; } else { if ($now >= $end) { $map1['flow'] = '已结束'; } } } } } } } $list[$k]['aproduct'][$ki]['map'] = $map1; //页面只显示四个活动 多的数据清除掉 if ($num > 4) { unset($list[$k]['aproduct'][$ki]); } } if ($endTime) { $rendMark['del'] = 1; } } $list[$k]['rendMark'] = $rendMark; } else { if ($v['status'] == IProductBase::STATUS_FIRST || $v['status'] == IProductBase::STATUS_INVALID) { //状态为5 只发布第一步 或状态为99 预览 显示信息拼凑 $list[$k]['apply_role'] = $map['roles'][$v['apply_role']]; $rand = str_split(str_pad($v['user_oriented_age'], 4, 0, STR_PAD_LEFT)); $ages = ''; $rand[3] ? $ages .= $map['ages']['1'] . ' 、' : ($ages = $ages); $rand[2] ? $ages .= $map['ages']['10'] . ' 、' : ($ages = $ages); $rand[1] ? $ages .= $map['ages']['100'] . ' 、' : ($ages = $ages); $rand[0] ? $ages .= $map['ages']['1000'] . ' 、' : ($ages = $ages); $list[$k]['user_oriented_age'] = trim($ages, '、'); $list[$k]['user_oriented_gender'] = $map['gender'][$v['user_oriented_gender']]; $iProductType = new IProductType(); $typeMap = $iProductType->getTypeMap(); $list[$k]['type'] = $typeMap[$v['type']]; } } } // print_r($list);exit; // //活动map // $activityBase = new ActivityBase(); // $activesMap = $activityBase->getActivityMap(); // print_r($activesMap);exit; //调用个人中心的布局 $this->layout = '@app/views/layouts/main.php'; // return $this->render( // 'index', // [ // 'list' => $list, // 'user' => $user, // 'self' => $self, // 'activesMap' => $activesMap // ] // ); // print_r($list);exit; //user 数据添加 $mMerberStat = new MemberStat(); $user['stat'] = $mMerberStat->getByUid($uid); // print_r($list);exit; $refresh = isset($_GET['pid']) ? $_GET['pid'] : ''; return $this->render('homepage', ['user' => $user, 'self' => $self, 'list' => $list, 'params' => $params, 'statusMap' => $statusMap, 'orderMap' => $orderMap, 'activesMap' => $activesMap, 'activeMap' => $activeMap, 'refresh' => $refresh]); }
/** * 创始人列表页(所有 审核通过产品 关联 发布用户 分页显示) * @author song <*****@*****.**> * * @param $page int 当前页数 * * @return */ public function actionFounder() { $page = Yii::$app->request->get('page'); $page = isset($page) ? intval($page) : 1; $memberStatModel = new MemberStat(); $result = $memberStatModel->getFounderPage($page, false); $pages = new Pagination(['totalCount' => $result->count(), 'pageSize' => Member::PAGE_SIZE]); $memberList = $result->asArray()->all(); //获取总数 $cache = Yii::$app->cache; $memberCount = $cache->get('founderNum'); if ($memberCount == false) { $memberCount = $memberStatModel->getFounderCount(); $cache->set('founderNum', $memberCount, '3600*24'); } return $this->render('founder', ['memberlist' => $memberList, 'membercount' => $memberCount, 'pages' => $pages]); }
/** * [用户关注] * @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'); } }
/** * 定义与 用户统计表 的关联关系 */ public function getMemberstar() { return $this->hasOne(MemberStat::className(), ['uid' => 'uid']); }
/** * 产品更新 [发布/修改/预览] * @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; } }
/** * 用户支持产品和支付金额统计 * Action AllSupportNumPrice */ public function actionAllSupportNumPrice() { $i = 0; $mMemberStat = new MemberStat(); $mOrder = new Order(); do { $i++; $startnum = ($i - 1) * self::GROUP_NUMBER; $data = $mMemberStat->find()->select('uid')->offset($startnum)->limit(self::GROUP_NUMBER)->asArray()->all(); foreach ($data as $key => $value) { $result = $mOrder->find()->select(['count(product_id) as num', 'sum(totalpay) as price'])->where(['uid' => $value['uid'], 'ispay' => self::PAY_SUCCESS, 'status' => self::ORDER_NORMAL])->asArray()->all(); $price = floatval($result[0]['price']); $num = intval($result[0]['num']); $sql = "update `i_member_stat` set `support_num` = " . $num . ",`support_price` = " . $price . " where `uid` = " . $value['uid']; $q = Yii::$app->db->createCommand($sql)->execute(); echo "uid = " . $value['uid']; echo ";"; echo "support_num = " . $num . "\n"; echo "uid = " . $value['uid']; echo ";"; echo "support_price = " . $price . "\n"; } } while ($data); }