Exemple #1
0
 public function parse2i($data)
 {
     $value = is_numeric($data['attr_val']) ? $data['attr_val'] : strtotime($data['attr_val']);
     $autoUpdateFields = ['real_start_time' => 'start_time', 'real_end_time' => 'end_time'];
     if (isset($data['ap_id']) && array_key_exists($data['attr_customid'], $autoUpdateFields)) {
         $result = ActivityProduct::findOne($data['ap_id']);
         if ($result) {
             $key = $autoUpdateFields[$data['attr_customid']];
             $result[$key] = $value;
             $result->save();
         }
     }
     return $value;
 }
Exemple #2
0
 public function parse2i($data)
 {
     $value = abs(intval($data['attr_val']));
     $mapping = ['supply_num' => 'stock'];
     if (array_key_exists($data['attr_customid'], $mapping)) {
         $result = ActivityProduct::findOne($data['ap_id']);
         if ($result && $result['status'] == ActivityProduct::STATUS_SAVE) {
             $key = $mapping[$data['attr_customid']];
             $result[$key] = $value;
             $result->save();
         }
     }
     return $value;
 }
 /**
  * [中国好产品活动宣传主题页 查询该用户的可以参加中国好产品活动的产品的接口]
  * @param  [int] $uid [用户id]
  * @return [json_encode]
  * 本地地址:http://www.idaiyan-website.cn/index.php?r=special-topic/applygoodproduct
  * 线上地址:http://test.idaiyan.cn/special-topic/applygoodproduct
  */
 public function actionApplygoodproduct()
 {
     $user = Yii::$app->util->isLogin();
     //判断是否登陆
     if (!$user) {
         echo Yii::$app->util->formatResEncode('1000', 'no login!');
         exit;
     }
     $uid = $user['uid'];
     $models = new IProductBase();
     $res = $models->myProducts($uid);
     //创建一个新数组$new,新数组以元素组的 id 为索引
     $new = array();
     foreach ($res as $key => $value) {
         $new[$value['id']]['id'] = $value['id'];
         $new[$value['id']]['name'] = $value['name'];
         if ($value['album']) {
             $new[$value['id']]['album'] = $value['album'] . ProductImage::THUMB_POSTFIX;
         } else {
             $new[$value['id']]['album'] = '';
         }
     }
     $mactivitypdt = new ActivityProduct();
     foreach ($new as $key => $value) {
         $res2 = $mactivitypdt->getActivityProduct($value['id']);
         $status = 1;
         foreach ($res2 as $key => $val) {
             // if (($val['status'] == ActivityProduct::STATUS_SAVE && $val['acti_id'] != ActivityBase::GOOD_PRODUCT) ||
             //     ($val['status'] == ActivityProduct::STATUS_VERIFYING && $val['acti_id'] != ActivityBase::GOOD_PRODUCT)) {
             //     if ($status == 1) {
             //         $status = false;
             //     }
             //     if ($status == true) {
             //         $status = true;
             //     } else {
             //        $status = false;
             //     }
             // }
             // if ($val['acti_id'] == ActivityBase::GOOD_PRODUCT && $val['status'] != ActivityProduct::STATUS_VERIFYING) {
             //     $status = true;
             // } else if ($val['acti_id'] == ActivityBase::GOOD_PRODUCT){
             //     var_dump($val['status']);
             //     $status = false;
             // }
             if ($val['acti_id'] != ActivityBase::GOOD_PRODUCT) {
                 if ($val['status'] == ActivityProduct::STATUS_SAVE || $val['status'] == ActivityProduct::STATUS_VERIFYING || $val['status'] == ActivityProduct::STATUS_VERIFY_NOTTHROUGH) {
                     if ($status == 1) {
                         $status = false;
                     }
                     if ($status == true) {
                         $status = true;
                     } else {
                         $status = false;
                     }
                 } else {
                     if ($status == 1) {
                         $status = true;
                     }
                     if ($status == false) {
                         $status = false;
                     } else {
                         $status = true;
                     }
                 }
             } else {
                 if ($val['acti_id'] == ActivityBase::GOOD_PRODUCT && $val['status'] != ActivityProduct::STATUS_VERIFYING) {
                     $status = true;
                 } else {
                     $status = false;
                 }
             }
         }
         if ($status == 1) {
             $status = true;
         }
         if ($status == false) {
             unset($new[$val['product_id']]);
         }
     }
     if ($new) {
         //成功返回产品信息 <!--如果有产品-->
         $str = '<div class="activity-product-choose">';
         $str .= '<div class="title">选择一款产品参与<span>中国好产品</span>活动</div>';
         $str .= '<form action="/goodproduct/good-product" method="GET">';
         $str .= '<div class="input-wrap">';
         $str .= '<select name="pid" class="product" id="product_id">';
         foreach ($new as $key => $val) {
             $str .= '<option value=' . $val['id'] . '>' . $val['name'] . '</option>';
         }
         $str .= '</select>';
         $str .= '<input type="hidden" name = "aid" value = "9">';
         $str .= '<button class="continue bluebtn">继续</button>';
         $str .= '</div>';
         $str .= '</form>';
         $str .= '<div class="tips">无法确认这款产品?可以去<a href="#">产品详情页</a>确认详细内容。</div>';
         $str .= '</div>';
         echo '{"code":"1001","msg":"applygoodproduct!","data":"' . addslashes($str) . '"}';
         // echo "{code:'1001','apply365days!',$str}";
         exit;
     } else {
         $str = '<div class="activity-product-choose no-product">';
         $str .= '<div class="title">您没有能参加此活动的产品,现在就去发布吧</div>';
         $str .= '<a class="publish bluebtn" href="/product/create">发布代言</a>';
         $str .= '</div>';
         echo '{"code":"1002","msg":"applygoodproduct!","data":"' . addslashes($str) . '"}';
         // echo "{code:'1001','apply365days!',$str}";
         exit;
     }
 }
 /**
  * Action Index
  */
 public function actionIndex()
 {
     //$this->layout = false;
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     $session->remove('backurl');
     $session->remove('form');
     $mPageBlock = new PageCustomBlock();
     $slideOption['customId'] = PageCustomBlock::MAIN_PAGE_SLIDE;
     $speechesOption['customId'] = PageCustomBlock::MAIN_PAGE_SPEECHES;
     $newsOption['customId'] = PageCustomBlock::MAIN_PAGE_NEWS;
     $productsOption['customId'] = PageCustomBlock::MAIN_PAGE_PRODUCTS;
     // $slide = $mPageBlock->block(PageCustomBlock::MAIN_PAGE_SLIDE);
     // $speeches = $mPageBlock->block(PageCustomBlock::MAIN_PAGE_SPEECHES);
     // $products = $mPageBlock->block(PageCustomBlock::MAIN_PAGE_PRODUCTS);
     $slide = $mPageBlock->block($slideOption);
     $speeches = $mPageBlock->block($speechesOption);
     $news = $mPageBlock->block($newsOption);
     $products = $mPageBlock->block($productsOption);
     // print_r($news);exit;
     //获取产品类型
     $product_type = new IProductType();
     $product_type = $product_type->product_type_list();
     //获取活动
     $aproduct = new ActivityBase();
     $aproduct = $aproduct->getByStatus();
     // //zhanglu
     // print_r($aproduct);exit;
     $data = [];
     //zhanglu
     //为了获取产品想过活动信息
     $mActivityProduct = new ActivityProduct();
     foreach ($aproduct as $key => $value0) {
         $data[$value0['id']] = $value0;
     }
     $reg['slide'] = $slide;
     $reg['speeches'] = $speeches;
     $reg['products'] = $products;
     $reg['product_type'] = $product_type;
     // echo "<pre>";
     // print_r($reg['products']);
     // echo "<pre>";
     // print_r($reg['aproduct']);
     //获取活动详细信息
     // print_r($data);exit;
     foreach ($reg['products'] as $key => $value) {
         // print_r($value);exit;
         //zhanglu
         $ap = $mActivityProduct->getActivitiseById($value['id']);
         // print_r($ap);exit;
         // print_r($value);exit;
         foreach ($value['aproduct'] as $key1 => $value1) {
             foreach ($data as $key2 => $value2) {
                 if ($value1['acti_id'] == $value2['id']) {
                     $reg['products'][$key]['aproduct'][$key1]['activity'] = $data[$key2];
                     //zhanglu
                     $reg['products'][$key]['aproduct'][$key1]['apstat'] = $ap[$key1]['apstat'];
                     // $reg['products'][$key]['activity'][$key1]['order']= $key1;
                 }
                 //zhanglu
                 // $reg['products'][$key]['activity'][$key1]['apstat']= $ap[$key1]['apstat'];
             }
         }
         // print_r($reg);exit;
         //获取用户所在省市
         // var_dump($value['user'][province]);
         // var_dump($value['user'][city]);
         if ($value['user']['province'] && $value['user']['city']) {
             $district = new District();
             $province = $district->getById(intval($value['user']['province']));
             $reg['products'][$key]['user']['province'] = $province['name'];
             $city = $district->getById(intval($value['user']['city']));
             $reg['products'][$key]['user']['city'] = $city['name'];
         }
     }
     // echo "<pre>";
     // // print_r($reg);exit;
     //  var_dump($reg['products']);die;
     //return $this->render('index',['slide' => $slide,'speeches' => $speeches,'products' => $products,'product_type' => $product_type]);
     $reg['news'] = $news;
     return $this->render('index', $reg);
 }
 /**
  * 好产品详细页
  * @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]);
     }
 }
Exemple #6
0
 /**
  * 通过产品ID集合获取产品信息
  *
  * @param array $ids 产品ID集合
  * @return array
  */
 public function getByIds($ids = [], $page = 1)
 {
     $result = false;
     if (!$ids || !is_array($ids)) {
         return $result;
     }
     // print_r($ids);exit;
     $startNum = ($page - 1) * self::PAGE_SIZE;
     $result = self::find()->where(['id' => $ids])->addParams([':idstr' => implode(',', $ids)])->with(['image' => function ($query) {
         return $query->select(['product_id', 'url'])->andWhere(['type' => ProductImage::TYPE_ALBUM, 'status' => ProductImage::STATUS_AVAILABLE])->orderBy(['order_num' => SORT_DESC]);
     }])->with(['stat' => function ($query) {
         return $query->select(['product_id', 'support_num', 'paied_num', 'partake_num', 'amount', 'follow_num', 'page_views']);
     }])->with(['user' => function ($query) {
         return $query->select(['uid', 'username', 'nickname', 'avatar', 'province', 'city']);
     }])->with(['aproduct' => function ($query) {
         return $query->select(['id', 'acti_id', 'product_id', 'start_time', 'end_time', 'status'])->with('apstat')->where([ActivityProduct::tableName() . '.status' => 3])->andWhere(ActivityProduct::tableName() . ".acti_id != " . ActivityBase::FANS_FESTIVAL);
     }])->with(['extra' => function ($query) {
         return $query->select(['product_id', 'summary']);
     }])->offset($startNum)->limit(self::PAGE_SIZE)->orderBy([new \yii\db\Expression('FIND_IN_SET(id, :idstr)')]);
     // asArray()->
     // all();
     // echo "<pre>";var_dump($result);exit;
     return $result;
 }
 /**
  * Action BuyingCar
  *
  */
 public function actionBuyingCar()
 {
     $user = yii::$app->util->isLogin() ? yii::$app->util->isLogin() : $this->redirect(['user/login']);
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     $product[] = $session['product'];
     $data = Yii::$app->request->post();
     if (empty($data)) {
         return $this->redirect(['product/view', 'id' => $product[0]['pid']]);
         //跳转到完善信息
     } else {
         $session->set('rel_id', $data['rel_id']);
         // $product[] = $session['product'];
         //Todo....
         $mActivityProduct = new ActivityProduct();
         $productActivity = $mActivityProduct->getByIdAndStatus($data['rel_id']);
         $number = $productActivity['stock'];
         if ($data['acti_id'] == 8) {
             //$number = 1;
             $mBaiyingShare = new BaiyingShare();
             $result = $mBaiyingShare->getCouldPay($data['rel_id'], $user['uid'], $data['acti_id']);
             if ($number > 0) {
                 $number = 1;
             }
             if ($result) {
                 $couldPay = 1;
             }
         } else {
             // $mActivityProduct = new ActivityProduct();
             // $productActivity = $mActivityProduct->getByIdAndStatus($data['rel_id']);
             // $number = $productActivity['stock'];
             $couldPay = 1;
         }
         //Endto
         $coupon = 0;
         foreach ($session['activityprice'] as $key => $value) {
             if ($key == $session['rel_id']) {
                 $payPrice = $value;
                 $coupon = intval($product[0]['price']) - intval($value);
                 if ($coupon < 0) {
                     $coupon = 0;
                 }
             }
         }
         return $this->render('buyingcar', ['product' => $product[0], 'coupon' => $coupon, 'payvalue' => $payPrice, 'num' => $number, 'couldpay' => isset($couldPay) ? $couldPay : '', 'rel_id' => $session['rel_id']]);
     }
 }
Exemple #8
0
 /**
  * 与中国好产品活动的关系
  */
 public function getAct()
 {
     return $this->hasOne(ActivityProduct::className(), ['id' => 'owner_id']);
 }
 /**
  * @author song
  * 提屁股 成功修改状态接口
  * @param int  $supportid 支持人id
  * @param int $supnum 踢屁股次数
  *
  * @return json
  * */
 public function actionGamesuccess()
 {
     //判断登陆
     $user = PublicLibrary::is_login();
     if ($user && $user['uid'] != 'weixin' && PublicLibrary::is_ajax()) {
         $date = Yii::$app->request->post();
         $supportid = isset($date['supportid']) ? intval($date['supportid']) : 0;
         $supnum = isset($date['supnum']) ? intval($date['supnum']) : 0;
         $msupport = new BaiyingSupport();
         $supportone = $msupport->pk($supportid);
         if ($supportone && $supportone['support_status'] == BaiyingSupport::SUPPORT_STATUS_DEF) {
             if ($supnum > BaiyingSupport::SUPPORT_STATAR) {
                 $mshare = new BaiyingShare();
                 //查询分享人uid
                 $oldres = $mshare->pk($supportone['shareid']);
                 $rel_id = $oldres['rel_id'];
                 //判断活动状态
                 $mactpro = new ActivityProduct();
                 $productattr = $mactpro->getDetailBypk($rel_id);
                 if ($productattr['status'] != ActivityProduct::STATUS_VERIFY_THROUGH) {
                     echo "<script>alert('活动已结束!'),window.location.href='/baiying/userproduct';</script>";
                     exit;
                 }
                 //查询该分享人所有的分享列表
                 $sharelist = $mshare->getSharelistByuid('', $oldres['uid'], ActivityBase::APPLY_BAIYING);
                 foreach ($sharelist as $key => $val) {
                     $sarr[] = $val['id'];
                 }
                 //查询当前用户支持成功的 记录
                 $usersuplist = $msupport->getSupportlist('', $user['uid'], BaiyingSupport::SUPPORT_STATUS_SUCCE);
                 foreach ($usersuplist as $key => $val) {
                     $uresanduser = $mshare->pk($val['shareid']);
                     //当前用户支持的产品的发布用户 等于 要支持订单的发布者
                     if ($uresanduser['uid'] == $oldres['uid']) {
                         $uarr[] = $val['shareid'];
                     }
                 }
                 if (isset($sarr) && isset($uarr)) {
                     $insec = array_intersect($sarr, $uarr);
                 }
                 //                $cc = isset($insec)?$insec:'1';
                 //                echo '<pre>';
                 //                print_r($cc);
                 if (isset($insec) && is_array($insec)) {
                 } else {
                     //增加分享支持统计数
                     $shafu = $mshare->addSharenum($supportone['shareid']);
                 }
                 $shareone = $mshare->pk($supportone['shareid']);
                 //支持数大于标准(30),且状态为1 修改支付状态
                 if ($shareone['share_num'] >= BaiyingShare::SHARE_STANDARD && $shareone['share_status'] == BaiyingShare::SHARE_STATUS_DEF) {
                     $sharecontent['id'] = $supportone['shareid'];
                     //商品剩余不足 状态修改成 售罄
                     //支付成功的分享
                     $succnum = $mshare->getcountnum($shareone['rel_id'], BaiyingShare::SHARE_STATUS_PAY);
                     //商品属性
                     $mapattrval = new ActivityProductAttrVal();
                     $acprattr = $mapattrval->getRealAttrVals($shareone['rel_id'], ActivityBase::APPLY_BAIYING);
                     if ($succnum >= $acprattr['supply_num']['attr_val']) {
                         $sharecontent['share_status'] = BaiyingShare::SHARE_OUT;
                     } else {
                         $sharecontent['share_status'] = BaiyingShare::SHARE_STATUS_SUCCE;
                     }
                     $res = $mshare->store($sharecontent);
                 }
                 $upcontent['support_status'] = BaiyingSupport::SUPPORT_STATUS_SUCCE;
             }
             //更新支持提屁股次数和 状态
             $upcontent['id'] = $supportid;
             $upcontent['uid'] = isset($user['uid']) ? $user['uid'] : '';
             $upcontent['mobile'] = isset($user['mobile']) ? $user['mobile'] : '';
             if ($supnum > $supportone['sup_num']) {
                 $upcontent['sup_num'] = $supnum;
             }
             $supfu = $msupport->store($upcontent);
             if ($supfu) {
                 echo PublicLibrary::format_res_encode('0', 'success', 'f**k');
             } else {
                 echo PublicLibrary::format_res_encode('1001', 'save error!');
             }
         } else {
             $upcontent['id'] = $supportid;
             if ($supnum > $supportone['sup_num']) {
                 $upcontent['sup_num'] = $supnum;
             }
             $upcontent['support_status'] = BaiyingSupport::SUPPORT_STATUS_SUCCE;
             $supfu = $msupport->store($upcontent);
             if ($supfu) {
                 echo PublicLibrary::format_res_encode('01', 'supnum up success!');
             } else {
                 echo PublicLibrary::format_res_encode('1003', 'supnum up error!');
             }
         }
     } else {
         echo PublicLibrary::format_res_encode('1001', 'the user no login or no ajax!');
         exit;
     }
 }
 public function actionBuysuccess()
 {
     $user = PublicLibrary::is_login();
     if ($user && $user['uid'] != 'weixin') {
         $uid = isset($user['uid']) ? $user['uid'] : '';
     } else {
         $this->redirect(['baiying/index']);
     }
     $parr = Yii::$app->request->get();
     //获取地址栏中get过来的信息
     // echo '<pre>';
     // print_r($parr);
     $orderno = strip_tags($parr['orderno']) ? strip_tags($parr['orderno']) : '';
     $model_order = new Order();
     $res = $model_order->Paysuccess($orderno);
     $this->layout = false;
     $rel_id = $res['rel_id'];
     $acti_id = $res['acti_id'];
     $mactpro = new ActivityProduct();
     $productattr = $mactpro->getDetailBypk($rel_id);
     $mapattrval = new ActivityProductAttrVal();
     $acprattr = $mapattrval->getRealAttrVals($rel_id, $acti_id);
     return $this->render('buysuccess', ['acprattr' => $acprattr, 'productattr' => $productattr]);
 }
Exemple #11
0
 /**
  * 属性值保存
  *
  * @param int $relid 活动产品ID
  * @param int $uid 用户ID
  * @param int $attrid 属性ID
  * @param int $attrval 属性值
  * @param str $actiConfig 活动配置
  * @param int $isCompleted 是否完成
  *
  * @return boolean
  */
 public function save($relid, $uid, $attrid, $attrval, $actiConfig = false, $isCompleted = ActivityProductAttrVal::STATUS_UNFINISHED)
 {
     $mActiProd = new ActivityProduct();
     $dActiProd = [];
     if (!($dActiProd = $mActiProd->getByPkAndUid($relid, $uid))) {
         return FALSE;
     }
     $mAttrBase = new ActivityAttrBase();
     $attr = $mAttrBase->pk($attrid);
     if (!$attr) {
         return FALSE;
     }
     $dataType = $attr['data_type'];
     $type = $attr['type'];
     $data = ['rel_id' => $dActiProd['id'], 'acti_id' => $dActiProd['acti_id'], 'product_id' => $dActiProd['product_id'], 'attr_id' => $attrid];
     if ($type == ActivityAttrBase::DATA_TYPE_MODEL) {
         $data['attr_val'] = $attrval;
         $data['finish_status'] = $isCompleted;
         //ActivityProductAttrVal::STATUS_FINISHED;
         // $data['finish_status'] = ActivityProductAttrVal::STATUS_FINISHED;
     } else {
         //if ($attr['type'] != 'cumbie') {
         //$attrval = $attrval['price'];
         //}
         $attrval = $this->parse(['ap_id' => $dActiProd['id'], 'type' => $attr['type'], 'data_type' => $attr['data_type'], 'attr_customid' => $attr['custom_id'], 'attr_val' => $attrval], self::PARSE_MODE_INPUT);
         if ($attrval === FALSE) {
             return $attrval;
         }
         $data['attr_val'] = $attrval;
         //$data['finish_status'] = $data['attr_val'] ?
         // ActivityProductAttrVal::STATUS_FINISHED : ActivityProductAttrVal::STATUS_UNFINISHED;
         $data['finish_status'] = $isCompleted;
         //ActivityProductAttrVal::STATUS_FINISHED;
     }
     $mAttrVal = new ActivityProductAttrVal();
     // 保存后
     if ($mAttrVal->store($data)) {
         if (!$actiConfig) {
             return TRUE;
         }
         $customid = $attr['custom_id'];
         if (isset($actiConfig['rel_attrs']) && isset($actiConfig['rel_attrs'][$customid]) && isset($actiConfig['rel_attrs'][$customid]['custom_id'])) {
             $itemConfig = $actiConfig['rel_attrs'][$customid];
             $attr = $mAttrBase->getByCustomID($itemConfig['custom_id']);
             if (isset($itemConfig['is_use_baseval']) && isset($itemConfig['op_type'])) {
                 // XXX: 1. 考虑调整类常量 2. 提供统一处理方法
                 // TODO: 能够根据数据类型自动选择操作
                 switch ($itemConfig['op_type']) {
                     case 'incr':
                         $attrval = $attrval + $itemConfig['val'];
                         break;
                     default:
                 }
             }
             $data['attr_id'] = $attr['id'];
             $data['attr_val'] = $attrval;
             unset($mAttrVal['id']);
             $mAttrVal->isNewRecord = TRUE;
             // TODO: 需要进行代码"解耦"
             $attrval = $this->parse(['ap_id' => $dActiProd['id'], 'type' => $attr['type'], 'data_type' => $attr['data_type'], 'attr_customid' => $attr['custom_id'], 'attr_val' => $attrval], self::PARSE_MODE_INPUT);
             return $mAttrVal->store($data);
         } else {
             return TRUE;
         }
     } else {
         return FALSE;
     }
 }
 /**
  * 产品修改判断接口(显示修改页面)
  * @param  [int] $id [产品id]
  * 测试地址:http://dev.idaiyan.cn/product/editchoose?id=4464
  * 测试地址:http://dev.idaiyan.cn/product/editchoose?id=4480
  */
 public function actionEditchoose()
 {
     $form = Yii::$app->request->post();
     $id = intval($form['id']);
     //查询这个产品参加过多少活动
     $mactivitypdt = new ActivityProduct();
     $res = $mactivitypdt->getActivitydata($id);
     foreach ($res as $key => $value) {
         if ($value['acti_id'] == 1) {
             unset($res[$key]);
         }
     }
     // echo '<pre>';
     // print_r($res);
     $ActivityAttrGroup = new ActivityAttrGroup();
     if ($res) {
         //如果参加了活动
         $temp = array();
         $result = array();
         foreach ($res as $key => $value) {
             // echo $value['apstat']['rel_id'].'<br />';
             //判断完成度
             $menu = $ActivityAttrGroup->getCompleteStatus($value['apstat']['rel_id']);
             $all = 0;
             $over = 0;
             // $all = count($menu); //菜单总数
             // $done = 0;
             // $type = 0;
             // if (!empty($menu)) {
             //     foreach ($menu as $key=>$val){
             //         $done += $val['is_completed'];
             //         $type += $val['type'];
             //     }
             // }
             foreach ($menu as $li) {
                 $status = 'status ignore';
                 if ($li['type'] == 1) {
                     $all++;
                     if ($li['is_completed'] == 1) {
                         $over++;
                     }
                 }
             }
             $step = $all - $over;
             //                 echo $all;
             //                 echo '<pre>';
             //                 echo $all;
             // echo '<pre>';
             // print_r($menu);
             $key = intval($key);
             $temp[$key] = $value['activity'];
             // $temp[$key]['status'] = $value['status'];
             if ($value['acti_id'] == 8) {
                 //如果是一呼百应活动
                 if ($value['status'] == 2) {
                     $temp[$key]['status'] = 0;
                     //审核中的活动产品不可点 灰色
                     $temp[$key]['url'] = '';
                     $temp[$key]['step'] = $step;
                 } else {
                     if ($value['status'] == 3) {
                         //审核通过,部分可以编辑(缺少对应的链接)
                         $temp[$key]['status'] = 1;
                         //
                         if ($value['apply_way']) {
                             //diy
                             $temp[$key]['url'] = '/activity/applybaiying?pid=' . $id;
                             //http://dev.idaiyan.cn/activity/productactivity?pid=4465&aid=7
                             $temp[$key]['step'] = $step;
                         } else {
                             //官方
                             $temp[$key]['url'] = '/activity/applybaiying-diy?pid=' . $id;
                             //http://dev.idaiyan.cn/activity/productactivity?pid=4465&aid=7
                             $temp[$key]['step'] = $step;
                         }
                     } else {
                         $temp[$key]['status'] = 1;
                         //
                         if ($value['apply_way']) {
                             //diy
                             $temp[$key]['url'] = '/activity/applybaiying?pid=' . $id;
                             //http://dev.idaiyan.cn/activity/productactivity?pid=4465&aid=7
                             $temp[$key]['step'] = $step;
                         } else {
                             //官方
                             $temp[$key]['url'] = '/activity/applybaiying-diy?pid=' . $id;
                             //http://dev.idaiyan.cn/activity/productactivity?pid=4465&aid=7
                             $temp[$key]['step'] = $step;
                         }
                     }
                 }
             } else {
                 if ($value['acti_id'] == 9) {
                     if ($value['status'] == 2) {
                         $temp[$key]['status'] = 0;
                         //审核中的活动产品不可点 灰色
                         $temp[$key]['url'] = '';
                     } else {
                         if ($value['status'] == 3) {
                             //审核通过,部分可以编辑(缺少对应的链接)
                             $temp[$key]['status'] = 1;
                             //
                             $temp[$key]['url'] = '/goodproduct/good-product?pid=' . $id;
                             //http://dev.idaiyan.cn/activity/productactivity?pid=4465&aid=7
                         } else {
                             $temp[$key]['status'] = 1;
                             //
                             $temp[$key]['url'] = '/goodproduct/good-product?pid=' . $id;
                         }
                     }
                     $temp[$key]['step'] = $step;
                 } else {
                     if ($value['status'] == 2) {
                         $temp[$key]['status'] = 0;
                         //审核中的活动产品不可点 灰色
                         $temp[$key]['url'] = '';
                     } else {
                         if ($value['status'] == 3) {
                             //审核通过,部分可以编辑(缺少对应的链接)
                             $temp[$key]['status'] = 1;
                             //
                             $temp[$key]['url'] = '/activity/productactivityedit?rel_id=' . $value['apstat']['rel_id'];
                             //http://dev.idaiyan.cn/activity/productactivity?pid=4465&aid=7
                         } else {
                             $temp[$key]['status'] = 1;
                             //
                             $temp[$key]['url'] = '/activity/productactivityedit?rel_id=' . $value['apstat']['rel_id'];
                         }
                     }
                     $temp[$key]['step'] = $step;
                 }
             }
             // $temp[$key]['step'] = '3';
             $t = array_push($result, $temp[$key]);
         }
         // echo '<pre>';
         // print_r($result);
         echo PublicLibrary::format_res_encode('1001', 'applyactivity!', $result);
         exit;
     } else {
         echo PublicLibrary::format_res_encode('1000', 'no applyactivity!');
         exit;
     }
 }
 /**
  * 获取分组完成度
  *
  * @param int $apid 活动产品ID
  * @return array 分组完成度数据
  * 分组完成度的数据结构如下:
  * ~~~
  *  [
  *      [
  *          'id' => '分组ID',
  *          'acti_id' => '活动ID',
  *          'name' => '名称',
  *          'is_completed' => '是否已完成, 0: 未完成; 1: 已完成',
  *      ],
  *      // 其他分组数据......
  *  ]
  * ~~~
  *
  */
 public function getCompleteStatus($apid)
 {
     $apid = intval($apid);
     $result = [];
     $attrvals = [];
     $mActiProd = new ActivityProduct();
     $actiprod = $mActiProd->pk($apid);
     if (!$actiprod) {
         return false;
     }
     $aid = intval($actiprod['acti_id']);
     $group = $this->getValidGroupsByAid($aid, TRUE);
     $mAttrVal = new ActivityProductAttrVal();
     $result = $mAttrVal->getAttrVal($apid, false, ['attr_id', 'finish_status']);
     // 重新“组织”数据结构,即使用属性ID作为Key
     if ($result && is_array($result)) {
         foreach ($result as $val) {
             $attrvals[$val['attr_id']] = $val['finish_status'];
         }
     }
     // 针对每一个分组的attrs属性进行完成度"检测",并增加is_completed元素
     // is_completed 1: 已完成, 2: 未完成
     if ($group && is_array($group)) {
         foreach ($group as $key => $val) {
             if ($val['attrs'] && is_array($val['attrs'])) {
                 $group[$key]['is_completed'] = true;
                 foreach ($val['attrs'] as $attr) {
                     $attrid = $attr['attr_id'];
                     if (!isset($attrvals[$attrid]) || !$attrvals[$attrid]) {
                         $group[$key]['is_completed'] = false;
                         break;
                     }
                 }
                 unset($group[$key]['attrs']);
             } else {
                 $group[$key]['is_completed'] = false;
             }
         }
     }
     return $group;
 }
 /**
  * 一呼百应 属性接口
  * @param int   $rel_id   活动产品id
  * @param int   $attrid   活动产品属性值ID
  * @param str   $attval   属性值
  *        endtime    结束时间
  *
  * @return json
  * */
 public function actionBaiyingattr()
 {
     //判断登陆
     $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 = 241661;
     //$rel_id = 32825;
     //$attrid = 3;
     //$priceDis = 456;
     //$date = ['rel_id' => $rel_id, 'attrid' => $attrid, 'priceDis' => '346'];
     $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['attval']) ? $date['attval'] : '';
     if (isset($date['endtime']) && $date['endtime'] == 1) {
         $attrid = 2;
     }
     //用活动产品id 获取活动id
     $mpactivity = new ActivityProduct();
     $pcone = $mpactivity->pk($rel_id);
     //当前用户和产品活动发布用户不同
     if (empty($pcone) || $uid != $pcone['user_id'] || $pcone['status'] == ActivityProduct::STATUS_VERIFYING || $pcone['status'] == ActivityProduct::STATUS_VERIFY_THROUGH) {
         echo PublicLibrary::format_res_encode('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 PublicLibrary::format_res_encode('1004', 'params error');
         exit;
     }
     // 查询属性基础信息
     $mattrbase = new ActivityAttrBase();
     $attr = $mattrbase->pk($attrid);
     //价格处理
     if ($attr['type'] == ActivityAttrBase::DATA_TYPE_MODEL_PRICE) {
         //查询价格属性值 以供修改
         $mAttrval = new ActivityProductAttrVal();
         $pattrv = $mAttrval->getAttrVal($rel_id, $attrid);
         $priceval = [];
         if (isset($pattrv['attr_val']) && !empty($pattrv['attr_val'])) {
             $priceval = json_decode($pattrv['attr_val'], true);
         }
         if (isset($priceval) && !is_array($priceval)) {
             $priceval = [];
         }
         //图片上传
         $priceimg = UploadedFile::getInstanceByName('attval');
         if ($priceimg !== null) {
             //判断图片大小是否符合规定
             if ($priceimg->size > ProductImage::MAX_SIZE || $priceimg->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($priceimg->tempName, $setpimage_path . '.jpg');
             $priceval['priceimg'] = $setpimage_path;
         } else {
             $priceval['price'] = $attval;
         }
         $attval = $priceval;
     }
     $mbaseattr = new BaseAttribute();
     $btas = $mbaseattr->save($rel_id, $uid, $attrid, $attval, false, 1);
     if ($btas) {
         $pimg = isset($setpimage_path) ? $setpimage_path . '.jpg' : '';
         //查询完成度
         $ActivityRelAttrGroup = new ActivityRelAttrGroup();
         //获取group_id
         $group = ActivityRelAttrGroup::find()->select('group_id')->where(['attr_id' => $attrid, 'acti_id' => ActivityBase::APPLY_BAIYING])->asArray()->one();
         $group_id = $group['group_id'];
         $ids = $ActivityRelAttrGroup->completion($rel_id, ActivityBase::APPLY_BAIYING, $group_id);
         if ($ids) {
             echo PublicLibrary::format_res_encode('0', 'success', ['priceImg' => $pimg]);
         } else {
             echo PublicLibrary::format_res_encode('1', 'success', ['priceImg' => $pimg]);
         }
     } else {
         echo PublicLibrary::format_res_encode('1002', 'save error');
     }
 }
Exemple #15
0
 public function actionChangeStock()
 {
     $mActivityProduct = new ActivityProduct();
     $mActivityProduct->changeStock(24574, 1);
 }
 /**
  * 365日期属性 可选择日期 接口
  * @auth song
  * @param int $month
  *
  * @return json
  * */
 public function actionChoicedate()
 {
     if (PublicLibrary::is_ajax()) {
         $month = Yii::$app->request->post('month');
         $mactpro = new ActivityProduct();
         $monthproductlist = $mactpro->getMonthlist($month);
         if ($monthproductlist) {
             foreach ($monthproductlist as $key => $val) {
                 $stime = date('Y-m-d', $val['start_time']);
                 $mlpro[] = $stime;
             }
             echo PublicLibrary::format_res_encode('0', 'success', $mlpro);
         } else {
             echo PublicLibrary::format_res_encode('1002', 'search error');
         }
     } else {
         echo PublicLibrary::format_res_encode('1001', 'requst error');
     }
 }
 /**
  * 运营后台 设置365活动中 产品开始日期
  *
  *
  * */
 public function actionSetproductdate()
 {
     $user = PublicLibrary::is_login();
     if (isset($user['uid'])) {
         $uid = $user['uid'];
     } else {
         return $this->redirect(['product/index']);
         exit;
     }
     $form = Yii::$app->request->get();
     $form = array_map('trim', $form);
     $form = array_map('strip_tags', $form);
     $form = array_map('htmlspecialchars', $form);
     $page = isset($form['page']) ? intval($form['page']) : 1;
     $data['product_name'] = isset($form['product_name']) ? $form['product_name'] : '';
     $data['username'] = isset($form['username']) ? $form['username'] : '';
     $data['mobile'] = isset($form['mobile']) ? $form['mobile'] : '';
     $data['status'] = isset($form['status']) ? $form['status'] : '';
     $data['start_time'] = isset($form['start_time']) ? strtotime($form['start_time']) : '';
     $mactpro = new ActivityProduct();
     $date = $mactpro->get365Listpage($page, false, 3, $data);
     $pages = new Pagination(['totalCount' => $date->count(), 'pageSize' => 3]);
     //        echo '<pre>';
     //        var_dump($pages);
     $productlist = $date->asArray()->all();
     $mapattrval = new ActivityProductAttrVal();
     if ($productlist) {
         foreach ($productlist as $pl => $st) {
             $acprattr = $mapattrval->getRealAttrVals($st['id'], ActivityBase::GENERAL_ACTIVITY);
             $productlist[$pl]['attr'] = $acprattr;
         }
     }
     //        echo '<pre>';
     //        print_r($productlist);
     //        exit;
     $this->layout = false;
     return $this->render('setproductdate', ['productlist' => $productlist, 'data' => $data, 'pages' => $pages]);
 }