Ejemplo n.º 1
0
 /**
  * 一呼百应 属性接口
  * @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');
     }
 }
Ejemplo n.º 2
0
 public function actionRag()
 {
     $model = new ActivityRelAttrGroup();
     $data = array('acti_id' => 1, 'group_id' => 1, 'attr_id' => 3);
     var_dump($model->store($data));
     // var_dump($model->cancelRelation($data));
 }
Ejemplo n.º 3
0
 /**
  * @author shimeixia <*****@*****.**>
  * @param $pid 产品id
  *
  * @return
  */
 public function actionGoodProduct()
 {
     $user = yii::$app->util->isLogin() ? yii::$app->util->isLogin() : $this->redirect(['user/login']);
     $parr = Yii::$app->request->get();
     $pid = isset($parr['pid']) ? intval($parr['pid']) : '';
     $aid = ActivityBase::GOOD_PRODUCT;
     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']]);
         //跳转到用户主页
     }
     //查询该商品有没有参加过该活动
     $mactivitypdt = new ActivityProduct();
     $one = $mactivitypdt->isinActivity($user['uid'], $aid, $pid);
     //属性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' => 1];
         $rel_id = $mactivitypdt->store($apdata);
         //插入到活动产品统计表
         $apstart = new ActivityProductStat();
         $data = ['rel_id' => $rel_id, 'acti_id' => $aid, 'product_id' => $pid];
         $apstart->store($data);
         //赛区数据入库
         $mbaseattr = new BaseAttribute();
         $value = $mbaseattr->save($rel_id, $user['uid'], 15, ActivityBase::GOODPRODUCT_CITY, false, 1);
         $value = $mbaseattr->save($rel_id, $user['uid'], 18, time(), false, 1);
     } else {
         $rel_id = $one['id'];
         if ($one['status'] == ActivityProduct::STATUS_VERIFYING) {
             //审核中
             return $this->redirect(['home-page/lists', 'uid' => $user['uid']]);
             //跳转到完善信息
         }
     }
     //查询左侧菜单
     $ActivityAttrGroup = new ActivityAttrGroup();
     $menu = $ActivityAttrGroup->getCompleteStatus($rel_id);
     // echo "<pre>";
     // var_dump($menu);die;
     $ActivityProductAttrVal = new ActivityProductAttrVal();
     $attrval = $ActivityProductAttrVal->getRealAttrVals($rel_id, $aid);
     $attrval = array_merge($attrMap, $attrval);
     if (isset($attrval['pokedex']['val']) && is_array($attrval['pokedex']['val'])) {
         foreach ($attrval['pokedex']['val'] as $key => $value) {
             if ($value['type'] == ProductImage::TYPE_GOODPRODUCT) {
                 $image[] = $value;
             }
         }
     }
     $this->layout_data = 'uc';
     return $this->render('goodproduct', ['pid' => $pid, 'rel_id' => $rel_id, 'menu' => $menu, 'attrs' => isset($attrval) ? $attrval : "", 'attrMap' => $attrMap, 'image' => isset($image) ? $image : " ", 'goodproduct_city' => ActivityBase::GOODPRODUCT_CITY]);
 }
Ejemplo n.º 4
0
 /**
  * 活动分组-属性关联的定义
  */
 public function getAttrs()
 {
     return $this->hasMany(ActivityRelAttrGroup::className(), ['group_id' => 'id']);
 }