/** * [用户关注] * @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 $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]); }
/** * 删除商品 * * @param int $id 产品id号 * @return string $result * [ * 'code'=> 0 成功 1001 失败 * 'msg'=> '产品删除成功' '产品删除成功' * 'data'=>[], * ] * */ public function actionDel() { $id = Yii::$app->request->post('id'); //必须是Ajax if (!PublicLibrary::is_ajax() || !isset($id)) { echo PublicLibrary::format_res_encode('1002', '不是Ajax 或不是post请求'); exit; } else { if (!PublicLibrary::is_login()) { echo PublicLibrary::format_res_encode('1004', '没登陆'); exit; } } $user = PublicLibrary::is_login(); //是否是该用户的产品 $mIProductBase = new IProductBase(); $id = intval($id); if (!$mIProductBase->isMyProduct($user['uid'], $id)) { echo PublicLibrary::format_res_encode('1003', '非法操作'); exit; } $del = $this->findModel($id); if ($del['status'] != IProductBase::STATUS_FIRST) { $del->status = 0; if ($del->save()) { //发布成功后更新用户统计表 $session = Yii::$app->session; $session->isActive ? '' : $session->open(); $MemberStat = new MemberStat(); $MemberStat->decr($session['user']['uid'], 'product_num'); $res = $MemberStat->getByUid($session['user']['uid']); $num = $res['product_num']; $resutl = ['code' => 0, 'msg' => '产品删除成功1', 'data' => $num]; } else { $resutl = ['code' => 1001, 'msg' => '产品删除失败', 'data' => []]; } } else { $del->status = 0; if ($del->save()) { //发布成功后更新用户统计表 $session = Yii::$app->session; $session->isActive ? '' : $session->open(); $MemberStat = new MemberStat(); $res = $MemberStat->getByUid($session['user']['uid']); $num = $res['product_num']; $resutl = ['code' => 0, 'msg' => '产品删除成功2', 'data' => $num]; } else { $resutl = ['code' => 1001, 'msg' => '产品删除失败', 'data' => []]; } } return json_encode($resutl); }