/** * 通过关联ID获取活动产品对应的属性值 * * @param int $id 活动产品关联ID * @return array */ public function getAttrValById($id) { $result = []; $id = intval($id); if (!$id) { return FALSE; } $result = self::find()->where(['id' => $id, 'status' => self::STATUS_VERIFY_THROUGH])->with(['attrval' => function ($query) { return $query->select(['rel_id', 'attr_id', 'attr_val', 'finish_status']); }])->asArray()->one(); // 解析AttrVal if ($result) { $mActiAttr = new ActivityAttrBase(); $attrs = $mActiAttr->getAll(FALSE, 'id'); } return $result; }
/** * 一呼百应 属性接口 * @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'); } }
/** * [活动属性处理接口] * @param array $data 数据 * [ * 'rel_id' => '活动产品关联ID', * 'attrid' => '属性ID', * 'attrval' => '属性值', * 'type' => '活动产品关联ID', * 'id' => '图鉴属性ID', * 'delid' => '图鉴属性ID', * 'title' => '图片标题', * 'desc' => '图片描述', * 'pimage' => '图片', * ] * @return [json_encode] [0,1001] * 00 执行成功,已完成 * 01 执行成功,未完成 * 02 删除成功 * 1001 未登录 * 1004 参数错误 * 1005 图片上传错误 */ public function actionAttrprocess() { //判断登陆 $user = yii::$app->util->isLogin(); if ($user) { $uid = $user['uid']; } else { echo PublicLibrary::format_res_encode('1001', 'the user no landing or no ajax!'); exit; } $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['attrval']) ? $date['attrval'] : ''; $type = isset($date['type']) ? $date['type'] : ''; $delid = isset($date['delid']) ? intval($date['delid']) : ''; //用活动产品id 获取活动id $mpactivity = new ActivityProduct(); $pcone = $mpactivity->pk($rel_id); //当前用户和产品活动发布用户不同 if (empty($pcone) || $uid != $pcone['user_id'] || $pcone['status'] == ActivityProduct::STATUS_VERIFYING) { echo yii::$app->util->formatResEncode('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 yii::$app->util->formatResEncode('1004', 'params error'); exit; } //查询属性基础信息 $mattrbase = new ActivityAttrBase(); $attr = $mattrbase->pk($attrid); if (!empty($type)) { $attribute = []; $content = []; $sign = false; //添加标示 $comsta = false; //完成度标示 $delstat = false; //删除标识 if ($type == "image") { $pimage_model = new ProductImage(); //删除 if ($delid) { if ($pimage_model->delBypk($delid)) { $delstat = true; } } else { $imgstatus = false; $pos_id = 100; //图片上传 $pimage = UploadedFile::getInstanceByName('pimage'); if ($pimage !== null) { //判断图片大小是否符合规定 if ($pimage->size > ProductImage::MAX_SIZE || $pimage->error != 0) { echo yii::$app->util->formatResEncode('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($pimage->tempName, $setpimage_path . '.jpg'); //生成缩略图 $sreturn = $this->smallimg($setpimage_path, 200, 125); //产品详细 $pimage_path = $sreturn ? $setpimage_path . ProductImage::THUMB_PDETIAL : $setpimage_path . '.jpg'; $content['url'] = $setpimage_path; $imgstatus = true; } //填写描述 if (!empty($date['id']) && !empty($date['desc'])) { $content['desc'] = $date['desc']; $imgstatus = true; } //填写标题 if (!empty($date['id']) && !empty($date['title'])) { $content['title'] = $date['title']; $imgstatus = true; } if ($imgstatus) { $content['product_id'] = $product_id; $content['type'] = $pos_id; if (isset($date['id']) && !empty($date['id'])) { $content['id'] = intval($date['id']); $imgid = $pimage_model->imageSave($content); } else { $pimid = $pimage_model->getByTypeAndPid($pos_id, $product_id); //详细图文介绍 图片个数不超过9个,超过9个不做新增操作 if (count($pimid) < 9 && $pos_id == 100) { // var_dump($date);die; $imgid = $pimage_model->imageSave($content); } } if (isset($imgid) && $imgid > 0) { $sign = $imgid; //判断该条信息是否完整 if ($pimage_model->iscomplete($imgid, "title")) { $complete = array('id' => $imgid, 'is_complete' => ProductImage::IS_COMPLETE); if ($pimage_model->imageSave($complete)) { $comsta = true; } } } } } } if ($type == "video") { // var_dump($date);die; $pvideo_model = new ProductVideo(); if (isset($date['video_url'])) { if (!empty($date['video_url'])) { $content['video_url'] = $date['video_url']; //$content['video_url'] = Yii::$app->util->generalVideo($date['video_url']); } $content['uid'] = $uid; $content['product_id'] = $product_id; if (isset($date['id']) && !empty($date['id'])) { $content['id'] = $date['id']; $videoid = $pvideo_model->store($content); // $sign = $videoid; } else { //一个产品的视频属性 只能存在一条,如果已经存在,不做新增操作, 返回存在的id值, $rvid = $pvideo_model->getByPid($product_id, true); if (!$rvid) { $videoid = $pvideo_model->store($content); } else { $videoid = isset($rvid['id']) ? $rvid['id'] : ''; } } if ($videoid) { $sign = $videoid; $comsta = true; } } } if ($delstat) { //+TOOD 删除 修改 产品属性值 表数据操作 echo yii::$app->util->formatResEncode('02', 'deletet success'); exit; } else { if ($sign) { $baseattr_model = new BaseAttribute(); $imgurl = isset($pimage_path) ? $pimage_path : ''; $videoid = isset($videoid) ? intval($videoid) : 1; if ($comsta) { $btas = $baseattr_model->save($rel_id, $uid, $attrid, $videoid, false, 1); echo yii::$app->util->formatResEncode('00', 'success', array('id' => $sign, 'imgurl' => $imgurl)); exit; } else { $btas = $baseattr_model->save($rel_id, $uid, $attrid, $videoid, false, 0); echo yii::$app->util->formatResEncode('01', 'success', array('id' => $sign, 'imgurl' => $imgurl)); exit; } } } } else { $mbaseattr = new BaseAttribute(); $btas = $mbaseattr->save($rel_id, $uid, $attrid, $attval, false, 1); echo yii::$app->util->formatResEncode('0', 'success'); exit; } }
public function actionAab() { $model = new ActivityAttrBase(); /* $data = array( 'id' => 1, 'name' => 'TEST2', 'type' => 100, 'widget' => 'START_TIME', ); */ // var_dump($model->store($data)); // var_dump($model->setStatus(1, ActivityAttrBase::STATUS_DISABLE)); var_dump($model->getAll(FALSE, 'id')); }
/** * 活动分组-属性关联的定义 */ public function getAttr() { return $this->hasOne(ActivityAttrBase::className(), ['id' => 'attr_id']); }
/** * 数据 */ public function val($relid, $attrid) { $mAttrBase = new ActivityAttrBase(); $attr = $mAttrBase->pk($attrid); $result = false; if (!$attr || $attr['status'] == ActivityAttrBase::STATUS_DISABLE) { return FALSE; } $mAttrVal = new ActivityProductAttrVal(); $attrval = []; if (!($attrval = $mAttrVal->getAttrVal($relid, $attrid))) { return FALSE; } $result = $this->parse(['ap_id' => $relid, 'product_id' => $attrval['product_id'], 'acti_id' => $attrval['acti_id'], 'type' => $attr['type'], 'attr_customid' => $attr['custom_id'], 'data_type' => $attr['data_type'], 'attr_val' => $attrval['attr_val']]); return $result; }