Пример #1
0
 /**
  * 定义与ActivityProductStat的关联关系
  */
 public function getApstat()
 {
     return $this->hasOne(ActivityProductStat::className(), ['rel_id' => 'id']);
 }
Пример #2
0
 /**
  * @author shimeixia <*****@*****.**>
  * @param $pid 产品id
  * @param $aid 活动id
  *
  * @return
  */
 public function actionApplybaiyingDiy()
 {
     $user = PublicLibrary::is_login() ? PublicLibrary::is_login() : $this->redirect(['user/login']);
     $parr = Yii::$app->request->get();
     $pid = isset($parr['pid']) ? intval($parr['pid']) : '';
     $aid = intval(ActivityBase::APPLY_BAIYING);
     if (empty($pid) || empty($aid)) {
         return $this->redirect(['home-page/lists', 'uid' => $user['uid']]);
         //跳转到完善信息
     }
     //判断是否存在该活动
     $mActiBase = new ActivityBase();
     $activity = $mActiBase->pk($aid);
     if (!$activity) {
         return $this->redirect(['home-page/lists', 'uid' => $user['uid']]);
         //跳转到用户主页
     }
     //查询是不是该用户发布的产品
     $model = new IProductBase();
     $res = $model->isMyProduct($user['uid'], $pid);
     if (!$res) {
         return $this->redirect(['home-page/lists', 'uid' => $user['uid']]);
         //跳转到用户主页
     }
     //$session->set('acti_config', $activity['config']);
     //查询该商品有没有参加过该活动
     $mactivitypdt = new ActivityProduct();
     $one = $mactivitypdt->isinActivity($user['uid'], $aid, $pid);
     //$one = $mactivitypdt ->applyWay($user['uid'],$aid,$pid,0);
     // echo '<pre>';
     // var_dump($one);die;
     //活动属性map
     $mArag = new ActivityRelAttrGroup();
     $attrMap = $mArag->getAttrMapping($aid);
     if (!$one) {
         //入库
         $apdata = ['product_id' => $pid, 'acti_id' => $aid, 'user_id' => $user['uid'], 'status' => ActivityProduct::STATUS_SAVE, 'apply_way' => 0];
         $rel_id = $mactivitypdt->store($apdata);
         //插入到活动产品统计表
         $apstart = new ActivityProductStat();
         $data = ['rel_id' => $rel_id, 'acti_id' => $aid, 'product_id' => $pid];
         $apstart->store($data);
     } else {
         // //判断是否是官方申请
         // $model = $mactivitypdt->pk($one['id']);
         // $model->apply_way == 1 ? '' : $this->redirect(['home-page/lists', 'uid' => $user['uid']]);
         $rel_id = $one['id'];
         if ($one['apply_way'] == 1) {
             $apdata = ['id' => $rel_id, 'apply_way' => 0];
             $mactivitypdt->store($apdata);
         }
         if ($one['status'] == ActivityProduct::STATUS_VERIFYING) {
             //审核中
             return $this->redirect(['home-page/lists', 'uid' => $_SESSION['user']['uid']]);
             //跳转到完善信息
         } else {
             $ActivityProductAttrVal = new ActivityProductAttrVal();
             $attrval = $ActivityProductAttrVal->getRealAttrVals($rel_id, $aid);
             $attrval = array_merge($attrMap, $attrval);
             // echo '<pre>';
             // print_r($attrval);
             if (isset($attrval['album']['val']) && is_array($attrval['album']['val'])) {
                 foreach ($attrval['album']['val'] as $key => $value) {
                     if ($value['type'] == ProductImage::TYPE_CATIONFIRST) {
                         $fourpimag[] = $value;
                     }
                     if ($value['type'] == ProductImage::TYPE_CATIONINDE) {
                         $fivepimag[] = $value;
                     }
                 }
             }
         }
     }
     //查询左侧菜单
     $ActivityAttrGroup = new ActivityAttrGroup();
     $menu = $ActivityAttrGroup->getCompleteStatus($rel_id);
     //echo '<pre>';
     //print_r($attrval);
     // exit;
     $this->layout_data = 'uc';
     return $this->render('applybaiyingdiy', ['price' => $res[0]['price'], 'attrs' => isset($attrval) ? $attrval : '', 'pid' => $pid, 'rel_id' => $rel_id, 'menu' => $menu, 'attrMap' => $attrMap]);
 }
Пример #3
0
 /**
  * 好产品详细页
  * @author song
  * @param int $rel_id 活动产品id
  *
  * @return
  * */
 public function actionDetail()
 {
     $rel_id = Yii::$app->request->get('rel_id');
     $rel_id = intval($rel_id);
     if ($rel_id > 0) {
         //查询活动产品详细
         $mActivityProduct = new ActivityProduct();
         $actproduct = $mActivityProduct->getDetailBypk($rel_id);
         if (!$actproduct && $actproduct['status'] != 3) {
             Yii::$app->util->msg('审核未通过,请联系管理员!');
             exit;
         }
         //查询活动产品属性
         $mapattrval = new ActivityProductAttrVal();
         $attrval = $mapattrval->getRealAttrVals($rel_id, ActivityBase::GOOD_PRODUCT);
         //投票信息
         $city = isset($attrval['division']['val']) ? $attrval['division']['val'] : '';
         $poll_type_id = PollType::GOODPRODUCT_TYPE;
         $mpoll = new poll();
         $pollone = $mpoll->getPollByCity($city, $poll_type_id);
         //投票项信息
         $moption = new polloption();
         $optione = $moption->getOptionByowner($pollone['poll_id'], $rel_id);
         //var_dump($optione);
         //exit;
         //增加页面访问量
         $ActivityProductStat_model = new ActivityProductStat();
         $ActivityProductStat_model->incr($rel_id, 'page_views');
         //产品类型
         $IProductType = new IProductType();
         $Ptype = $IProductType->product_type_list();
         $Ptype = ArrayHelper::map($Ptype, 'id', 'name');
         $Ptype[6] = "";
         //页面当name为『其他』时,不然显示
         // print_r($Ptype);exit;
         //            echo '<pre>';
         //            print_r($actproduct);
         // print_r($attrval);
         // exit;
         //数据过滤
         if (isset($attrval['pokedex']['val']) && is_array($attrval['pokedex']['val'])) {
             $tmp = [];
             foreach ($attrval['pokedex']['val'] as $v) {
                 if (!empty($v['title']) && !empty($v['desc']) && !empty($v['url'])) {
                     $tmp[] = $v;
                 }
             }
             $attrval['pokedex']['val'] = $tmp;
         }
         $this->layout = false;
         return $this->render('detail', ['attrval' => $attrval, 'product' => $actproduct, 'optione' => $optione, 'type' => $Ptype, 'goodproduct_city' => ActivityBase::GOODPRODUCT_CITY]);
     }
 }
Пример #4
0
 /**
  * Action ActivityProductStat
  */
 public function actionAps()
 {
     $mAPS = new ActivityProductStat();
     // $mAPS->op(1, 1, 4, [ 'support_num' => 100 ]);
     // $mAPS->op(1, 1, 4, 'support_num');
     // var_dump($mAPS->incr(24577, 'support_num', 10));
     // var_dump($mAPS->incr(24577, 'paied_num', 1));
     var_dump($mAPS->store(['rel_id' => 1000, 'acti_id' => 1, 'product_id' => 100]));
 }
Пример #5
0
 /**
  * [关注]
  * @param  [int] $product_id [产品id]
  * @param  [int] $rel_id 活动产品ID  如果存在则是 更新活动产品统计
  * @param  [int] $type [1,2]
  * 1 关注     2 取消关注
  *
  * @return [json_encode]     [0,1]
  * 0 执行成功 1001 参数错误 1002 系统繁忙
  * 关注接口:http://idaiyan_new.cn/frontend/web/index.php?r=product/user_id=24&product=4291&type=1
  * 取消接口:http://idaiyan_new.cn/frontend/web/index.php?r=product/user_id=24&product=4302&type=2
  */
 public function actionFollow()
 {
     //判断登陆
     $user = PublicLibrary::is_login();
     if ($user && PublicLibrary::is_ajax()) {
         $uid = $user['uid'];
     } else {
         echo PublicLibrary::format_res_encode('1002', 'login or not ajax error !');
         exit;
     }
     // $uid = 25;
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     $form = Yii::$app->request->post();
     $id = isset($form['id']) ? intval($form['id']) : '';
     $product_id = isset($form['product_id']) ? intval($form['product_id']) : $id;
     $type = isset($form['type']) ? intval($form['type']) : '';
     $rel_id = isset($form['rel_id']) ? intval($form['rel_id']) : '';
     //活动产品id
     //用活动产品id 获取活动ID 产品ID
     if ($rel_id) {
         $pactivity_model = new ActivityProduct();
         $pactivity = $pactivity_model->pk($rel_id);
         $activity_id = $pactivity->acti_id ? $pactivity->acti_id : 0;
         $product_id = $pactivity->product_id ? $pactivity->product_id : 0;
     }
     //用户不能关注自己产品
     if (!isset($product_id)) {
         $mActivityProduct = new ActivityProduct();
         $result = $mActivityProduct->pk($rel_id);
         $product_id = $result->product_id;
     }
     $productBase = new IProductBase();
     if ($productBase->isMyProduct($uid, $product_id)) {
         echo PublicLibrary::format_res_encode('1004', '自己不能关注自己的产品');
         exit;
     }
     $pbase = IProductBase::findOne($product_id);
     $pbaseuid = $pbase['uid'];
     // $rel_id = 24576;
     // $type = 2;
     // //用活动产品id 获取活动ID 产品ID
     // if ($rel_id) {
     //     $pactivity_model = new ActivityProduct();
     //     $pactivity = $pactivity_model->pk($rel_id);
     //     $activity_id = $pactivity->acti_id ? $pactivity->acti_id : 0;
     //     $product_id = $pactivity->product_id ? $pactivity->product_id : 0;
     // }
     if (empty($product_id)) {
         echo PublicLibrary::format_res_encode('1003', 'param error !');
         exit;
     }
     $model_Base = new ProductFollow();
     $Mpfollow = new ProductFollow();
     //对follow_num增减
     $follow_num = new IProductStat();
     $Mapstar = new ActivityProductStat();
     $Mmemberstat = new MemberStat();
     if ($type == ProductFollow::API_FOLLOW) {
         if ($rel_id) {
             //设置关注的产品id集 session
             $follow_activ_product = $session['follow_activ_product'] ? $session['follow_activ_product'] : array();
             array_push($follow_activ_product, $rel_id);
             $session['follow_activ_product'] = $follow_activ_product;
             $activityfollow = $Mpfollow->activityfollow($rel_id, $product_id, $activity_id, $uid);
             if ($activityfollow == ProductFollow::FOLLOW_OP_SUCC) {
                 $Mapstar->incr($rel_id, 'follow_num');
             }
         }
         // //设置关注的产品id集 session
         // $follow_productids = $session['follow_product'];
         // array_push($follow_productids, $product_id);
         // $session['follow_product'] = $follow_productids;
         $follow = $model_Base->follow($product_id, $uid);
         if ($follow === ProductFollow::FOLLOW_OP_SUCC || $follow === true) {
             //设置关注的产品id集 session
             $follow_productids = $session['follow_product'] ? $session['follow_product'] : array('');
             array_push($follow_productids, $product_id);
             $session['follow_product'] = $follow_productids;
             $follow_num = $follow_num->modify('follow_num', $product_id);
             //增加 产品统计表 该产品关注数
             $Mmemberstat->incr($pbaseuid, 'pfollow_allnum');
             //增加 用户统计表 产品关注总数字段
         } else {
             if ($follow === ProductFollow::FOLLOW_OP_EXISTS) {
                 // 获取该产品关注数
                 $follow_num = count($model_Base->getFollowUsers($product_id));
             }
         }
     } else {
         if ($rel_id) {
             //设置关注的产品id集 session
             $follow_activ_product = $session['follow_activ_product'] ? $session['follow_activ_product'] : array();
             $key = array_search($rel_id, $follow_activ_product);
             unset($follow_activ_product[$key]);
             $session['follow_activ_product'] = $follow_activ_product;
             $follow = $activityunfollow = $Mpfollow->activityunfollow($rel_id, $product_id, $activity_id, $uid);
             //var_dump($activityunfollow);die;
             if ($activityunfollow === true) {
                 $Mapstar->decr($rel_id, 'follow_num');
             }
             $follow_num = count($model_Base->getFollowUsers($product_id));
         } else {
             // //设置关注的产品id集 session
             // $follow_productids = $session['follow_product'];
             // $key = array_search($product_id, $follow_productids);
             // unset($follow_productids[$key]);
             // $session['follow_product'] = $follow_productids;
             $follow = $model_Base->unfollow($product_id, $uid);
             if ($follow === ProductFollow::FOLLOW_OP_SUCC || $follow === true) {
                 //设置关注的产品id集 session
                 $follow_productids = $session['follow_product'] ? $session['follow_product'] : array('');
                 $key = array_search($product_id, $follow_productids);
                 unset($follow_productids[$key]);
                 $session['follow_product'] = $follow_productids;
                 $follow_num = $follow_num->modify('follow_num', $product_id, 1, FALSE);
                 //减少该产品关注数
                 $Mmemberstat->decr($pbaseuid, 'pfollow_allnum');
                 //减少 用户统计表 产品关注总数字段
             } else {
                 if ($follow === ProductFollow::FOLLOW_OP_CANCELLED) {
                     //设置关注的产品id集 session
                     $follow_productids = $session['follow_product'] ? $session['follow_product'] : array('');
                     $key = array_search($product_id, $follow_productids);
                     unset($follow_productids[$key]);
                     $session['follow_product'] = $follow_productids;
                     // 获取该产品关注数
                     $follow_num = count($model_Base->getFollowUsers($product_id));
                 }
             }
         }
     }
     if ($follow) {
         //用户信息
         $member = new Member();
         $user = $member->getByUid($pbaseuid);
         $pfollow_allnum = $user['memberstar']['pfollow_allnum'];
         //被关注商品数
         $pfollow_num = $user['memberstar']['follow_num'];
         $renqi = isset($user['memberstar']) && is_array($user['memberstar']) ? array_sum($user['memberstar']) : 0;
         echo PublicLibrary::format_res_encode('0', 'success', array('follow_num' => $follow_num, 'renqi' => $renqi, 'pfollow_allnum' => $pfollow_allnum));
         //echo PublicLibrary::format_res_encode('0', 'success', array('follow_num'=> json_encode($session['follow_product'])));
     } else {
         echo PublicLibrary::format_res_encode('1001', 'params error');
     }
 }
 /**
  * 数据修复
  *
  * @param string $type 统计类型
  *  - support_num 支持人数
  *  - paied_num 支付数量
  *  - partake_num 参与人数
  *  - amount 总金额
  *  默认为空
  * @param string $method 统计方式
  *  - product 产品统计(默认)
  *  - activity 活动产品统计
  * @param string $ids 产品ID集合
  *  产品ID集合的格式为"产品ID1,产品ID2,.....产品IDN"
  */
 public function actionRepair($type = '', $method = 'product', $ids = '')
 {
     $page = 1;
     $perPage = 50;
     $startNum = ($page - 1) * $perPage;
     $result = [];
     $options = [];
     $count = 0;
     $mOrder = new Order();
     $types = ['support_num', 'paied_num', 'partake_num', 'amount'];
     $methods = ['product', 'activity'];
     $type = trim($type);
     $time = microtime(true);
     $log = new FileTarget();
     if (!$type) {
         die("Error: Param type is empty\n");
     }
     if (!in_array($type, $types)) {
         die("Error: Illegal Type\n");
     }
     if (!in_array($method, $methods)) {
         die("Error: Illegal Method\n");
     }
     if ($method == 'activity') {
         $ac = ActivityProductStat::find();
     } else {
         $ac = ProductStat::find();
     }
     $log->logFile = Yii::$app->getRuntimePath() . '/logs/' . self::LOGNAME_PREFIX . $method . '_' . $type . '_' . date('YmdHis') . '.log';
     if ($ids) {
         $ids = array_map('trim', explode(',', $ids));
         $ids = array_map('intval', $ids);
         $ids = array_filter($ids);
         $ids = array_unique($ids);
         $result = $ac->where(['product_id' => $ids])->all();
     } else {
         $result = $ac->offset($startNum)->limit($perPage)->all();
     }
     $this->_logger($log, 'Process Start');
     $this->_logger($log, 'Type:' . strtoupper($type));
     echo "Process Start\n";
     echo 'Type:' . strtoupper($type) . "\n";
     while ($result) {
         if ($result) {
             foreach ($result as $item) {
                 if (isset($item['product_id']) && $item['product_id']) {
                     $options['product_id'] = $item['product_id'];
                     if (isset($item['acti_id']) && $item['acti_id']) {
                         $options['acti_id'] = $item['acti_id'];
                     }
                     $count = $mOrder->getCountByType($type, $options);
                     if ($count === NULL || $count === false) {
                         continue;
                     }
                     $item[$type] = $count;
                     if ($item->save()) {
                         $this->_logger($log, 'Updated: pid=' . $item['product_id'] . ', count=' . $count);
                         echo 'Updated: pid=' . $item['product_id'] . ', count=' . $count . "\n";
                     } else {
                         $this->_logger($log, 'Error: pid=' . $item['product_id']);
                         echo 'Error: pid=' . $item['product_id'] . "\n";
                     }
                 }
             }
         }
         if ($ids) {
             break;
         } else {
             echo "========== Page {$page} finished processing ==========\n\n";
             $startNum = ($page - 1) * $perPage;
             $page++;
             $result = $ac->offset($startNum)->limit($perPage)->all();
         }
     }
     echo "Process Over\n";
     $this->_logger($log, 'Process Over');
     $log->export();
 }