/**
  * 设置活动开始结束时间接口
  *  @param int  $rel_id  活动产品id
  *  @param str  $start_time 开始时间
  *
  * @return json
  * */
 public function actionSetdate()
 {
     $form = Yii::$app->request->post();
     $rel_id = isset($form['rel_id']) ? intval($form['rel_id']) : '';
     $uid = isset($form['uid']) ? intval($form['uid']) : '';
     $start_time = isset($form['start_time']) ? $form['start_time'] : '';
     if (empty($rel_id) || empty($start_time) || empty($uid)) {
         echo PublicLibrary::format_res_encode('1001', 'param error!');
         exit;
     }
     $mactpro = new ActivityProduct();
     if ($mactpro->searchStartime($start_time)) {
         echo PublicLibrary::format_res_encode('1002', 'start_time error!');
     } else {
         $activitymoedel = new ActivityBase();
         $activity = $activitymoedel->pk(7);
         $component = new BaseAttribute();
         $result = $component->save($rel_id, $uid, 13, $start_time, $activity['config']);
         if ($result) {
             echo PublicLibrary::format_res_encode('0', 'success');
         } else {
             echo PublicLibrary::format_res_encode('1003', 'save error');
         }
     }
 }
 /**
  * 一呼百应 属性接口
  * @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');
     }
 }
Example #3
0
 public function actionAb()
 {
     $component = new BaseAttribute();
     $mActivity = new ActivityBase();
     $acti = $mActivity->pk(7);
     $component->save(28846, 241639, 13, time(), $acti['config']);
     // $component->save(28841, 241573, time(), '');
     // var_dump($component->save(28841, 241573, 2, time()));
     // var_dump($component->val(28843, 10));
 }
 /**
  * [活动属性处理接口]
  * @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;
     }
 }
 /**
  * 获取属性"真正"的值
  *
  * 本方法与[[$this->getAttrVal]]方法的主要区别在于,本方法还会
  * 进一步获取属性类型为Model的数据信息
  *
  * @param int $relid 活动产品ID
  * @param int $aid 活动ID
  * @return array
  * 结果集的数据结构如下:
  * ~~~
  *  [
  *      '属性自定义ID' => [
  *          'rel_id' => '活动产品ID',
  *          'product_id' => '产品ID',
  *          'acti_id' => '活动ID',
  *          'val' => '属性值',
  *      ],
  *  ]
  * ~~~
  */
 public function getRealAttrVals($relid, $aid)
 {
     $relid = intval($relid);
     $conditions = ['rel_id' => $relid];
     $result = [];
     $attrvals = self::find()->where($conditions)->joinWith('attr')->asArray()->all();
     if ($attrvals && is_array($attrvals)) {
         $model = new BaseAttribute();
         foreach ($attrvals as $attrval) {
             if ($attrval['attr']['custom_id']) {
                 $key = $attrval['attr']['custom_id'];
                 $result[$key] = ['product_id' => $attrval['product_id'], 'acti_id' => $attrval['acti_id'], 'type' => $attrval['attr']['type'], 'data_type' => $attrval['attr']['data_type'], 'attr_val' => $attrval['attr_val']];
                 $result[$key]['val'] = $model->parse($result[$key]);
                 $result[$key]['rel_id'] = $attrval['rel_id'];
                 $result[$key]['attr_id'] = $attrval['attr_id'];
             }
         }
     }
     return $result;
 }