Exemple #1
0
 /**
  * 数据解析
  *
  * @param string $data 活动产品合作伙伴数据
  *  - $data内容应该为JSON Encode后的字符串序列
  * @return boolean|array
  *  - 为boolean时只能为FALSE,表示数据解析失败
  *  - 为array时表示指定活动产品合作伙伴信息,结构如下:
  *  ~~~
  *  [
  *      [
  *          'id' => '合作伙伴ID',
  *          'partner_title' => '合作伙伴名称',
  *          'partner_url' => '合作伙伴链接',
  *          'partner_logo' => '合作伙伴Logo URL',
  *      ]
  *      // 其他合作伙伴数据
  *  ]
  *  ~~~
  */
 public function parse2o($data)
 {
     $result = [];
     if ($data['attr_val'] === ActivityAttrBase::DATA_FROM_MODEL) {
         $model = new ProductPartner();
         $result = $model->getByAidAndPid($data['acti_id'], $data['product_id']);
     } else {
         $result = $data ? json_decode($data['attr_val'], true) : FALSE;
     }
     return $result;
 }
 /**
  * 365活动产品属性 处理接口 涉及 视频,图片,特性,合作伙伴
  * @author song
  * @param int   $rel_id   活动产品ID
  * @param int   $attrid   活动产品属性值ID
  * @param string $type    判断涉及表
  *  = 'video'   视频
  *        video_url     视频地址
  *        video_title   视频标题
  *        video_summary 视频概述
  *
  *  = 'image'    图片
  *        pimages  图片name
  *        desc   图片描述
  *        pos_id 图片位置标识 对应type字段     1:首屏背景,2:详细图文介绍
  *
  *  = 'character'   特性
  *      character_title     特性标题
  *      character_summary   特性概述
  *
  *  = 'partner'   合作伙伴
  *      partner_logo    合作伙伴logo
  *      partner_title   合作伙伴标题
  *
  * @param int $delid 需要删除的主键ID  (在删除时出现)
  *
  * @return json  返回显示信息
  */
 public function actionProductattributefour()
 {
     //判断登陆
     $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 = 25;
     $form = Yii::$app->request->post();
     $date = array_map('trim', $form);
     $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;
     $type = isset($date['type']) ? $date['type'] : '';
     $delid = isset($date['delid']) ? intval($date['delid']) : '';
     //用活动产品id 获取活动id
     $pactivity_model = new ActivityProduct();
     $pactivity = $pactivity_model->pk($rel_id);
     if ($pactivity) {
         $user_id = $pactivity->user_id ? $pactivity->user_id : 0;
     } else {
         $user_id = 0;
     }
     //当前用户和产品活动发布用户不同
     if ($uid != $user_id) {
         echo PublicLibrary::format_res_encode('1003', 'user error');
         exit;
     }
     $activity_id = $pactivity->acti_id ? $pactivity->acti_id : 0;
     $product_id = $pactivity->product_id ? $pactivity->product_id : 0;
     if (empty($rel_id) || empty($attrid) || empty($type) || empty($activity_id) || empty($product_id)) {
         echo PublicLibrary::format_res_encode('1004', 'params error');
         exit;
     }
     $attribute = [];
     $content = [];
     $sign = false;
     //添加标示
     $comsta = false;
     //完成度标示
     $delstat = false;
     //删除标识
     $isfull = false;
     //是否填满
     switch ($type) {
         case 'video':
             $pvideo_model = new ProductVideo();
             //删除
             if ($delid) {
                 if ($pvideo_model->delBypk($delid, $uid)) {
                     $delstat = true;
                 }
             } else {
                 //添加/修改
                 if (isset($date['video_url']) || isset($date['video_title']) || isset($date['video_summary'])) {
                     if (!empty($date['video_url'])) {
                         $content['video_url'] = $date['video_url'];
                         $content['video_url'] = Yii::$app->util->generalVideo($date['video_url']);
                     }
                     if (!empty($date['video_title'])) {
                         $content['video_title'] = $date['video_title'];
                     }
                     if (!empty($date['video_summary'])) {
                         $content['video_summary'] = $date['video_summary'];
                     }
                     $content['uid'] = $uid;
                     $content['product_id'] = $product_id;
                     if (isset($date['id']) && !empty($date['id'])) {
                         $content['id'] = $date['id'];
                         $videoid = $pvideo_model->store($content);
                     } 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;
                         if ($pvideo_model->hasCompleteData($videoid)) {
                             $comsta = true;
                         }
                     }
                 }
             }
             break;
         case 'image':
             $pimage_model = new ProductImage();
             //删除
             if ($delid) {
                 if ($pimage_model->delBypk($delid)) {
                     $delstat = true;
                 }
             } else {
                 $imgstatus = false;
                 $pos_id = isset($date['pos_id']) && $date['pos_id'] == ProductImage::TYPE_CATIONFIRST ? ProductImage::TYPE_CATIONFIRST : ProductImage::TYPE_CATIONINDE;
                 //图片上传
                 $pimage = UploadedFile::getInstanceByName('pimage');
                 if ($pimage !== null && isset($pos_id)) {
                     //判断图片大小是否符合规定
                     if ($pimage->size > ProductImage::MAX_SIZE || $pimage->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($pimage->tempName, $setpimage_path . '.jpg');
                     //生成缩略图
                     if ($pos_id == ProductImage::TYPE_CATIONFIRST) {
                         //首屏缩略图
                         // var_dump($setpimage_path);
                         // echo $pos_id;die;
                         $sreturn = $this->smallimg($setpimage_path, 280, 175);
                         $pimage_path = $sreturn ? $setpimage_path . ProductImage::THUMB_PRODUCT : $setpimage_path . '.jpg';
                     } else {
                         // var_dump($setpimage_path);die;
                         $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']) && !empty($pos_id)) {
                     $content['desc'] = $date['desc'];
                     $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个不做新增操作   首屏背景 图片个数不超过1个,超过1个不做新增操作
                         $imgid = $pimage_model->imageSave($content);
                         //                        if ((count($pimid) < 9 && $pos_id == ProductImage::TYPE_CATIONINDE) ||
                         //                            (count($pimid) < 1 && $pos_id == ProductImage::TYPE_CATIONFIRST)) {
                         //                                $imgid = $pimage_model->imageSave($content);
                         //                        }
                     }
                     if (isset($imgid) && $imgid > 0) {
                         $sign = $imgid;
                         //判断该条信息是否完整
                         if ($pimage_model->iscomplete($imgid)) {
                             $complete = array('id' => $imgid, 'is_complete' => ProductImage::IS_COMPLETE);
                             if ($pimage_model->imageSave($complete)) {
                                 $comsta = true;
                             }
                         }
                     }
                 }
             }
             break;
             //产品特性
         //产品特性
         case 'character':
             $pcharacter_model = new ProductCharacter();
             //删除
             if ($delid) {
                 if ($pcharacter_model->characterDelete($delid, $uid)) {
                     $delstat = true;
                 }
             } else {
                 if (isset($date['character_title']) || isset($date['character_summary'])) {
                     $content['uid'] = $uid;
                     $content['product_id'] = $product_id;
                     if (!empty($date['character_title'])) {
                         $content['character_title'] = $date['character_title'];
                     }
                     if (!empty($date['character_summary'])) {
                         $content['character_summary'] = $date['character_summary'];
                     }
                     if (isset($date['id']) && !empty($date['id'])) {
                         $content['id'] = $date['id'];
                         $characid = $pcharacter_model->characterSave($content);
                     } else {
                         $pchid = $pcharacter_model->getByPid($product_id);
                         //产品特性 超过9条特性 不在新增
                         if (count($pchid) < 9) {
                             $characid = $pcharacter_model->characterSave($content);
                         }
                     }
                     if (isset($characid) && $characid > 0) {
                         $sign = $characid;
                         //判断该条信息是否完整
                         if ($pcharacter_model->iscomplete($characid)) {
                             $complete = array('id' => $characid, 'uid' => $uid, 'is_complete' => ProductCharacter::IS_COMPLETE);
                             if ($pcharacter_model->characterSave($complete)) {
                                 $comsta = true;
                             }
                         }
                         $comsta = $pcharacter_model->hasCompleteData($product_id);
                     }
                 }
             }
             break;
             //合作伙伴
         //合作伙伴
         case 'partner':
             $parter_model = new ProductPartner();
             //删除
             if ($delid) {
                 if ($parter_model->remove($delid, $uid)) {
                     $delstat = true;
                 }
             } else {
                 $pstatus = false;
                 //图片上传
                 $partner_logo = UploadedFile::getInstanceByName('partner_logo');
                 if ($partner_logo !== null) {
                     //判断图片大小是否符合规定
                     if ($partner_logo->size > ProductImage::MAX_SIZE || $partner_logo->error != 0) {
                         echo PublicLibrary::format_res_encode('1006', 'partner image error');
                         exit;
                     }
                     $rootpath = 'uploads/' . date('Y/m/d') . '/';
                     //图片保存路径
                     file_exists($rootpath) or mkdir($rootpath, 0700, true);
                     //生成图片路径
                     $randname = time() . rand(0, 500);
                     //图片公有名
                     $setpimage_path = $rootpath . $randname;
                     //封面图路径
                     move_uploaded_file($partner_logo->tempName, $setpimage_path . '.jpg');
                     //生成缩略图
                     $sreturn = $this->smallimg($setpimage_path, 200, 65);
                     $pimage_path = $sreturn ? $setpimage_path . ProductPartner::THUMB_PARTNER : $setpimage_path . '.jpg';
                     $content['partner_logo'] = $setpimage_path;
                     $pstatus = true;
                 }
                 //填写描述
                 if (isset($date['id']) && isset($date['partner_title'])) {
                     $content['partner_title'] = $date['partner_title'];
                     $pstatus = true;
                 }
                 if ($pstatus) {
                     $content['activity_id'] = $activity_id;
                     $content['user_id'] = $uid;
                     $content['product_id'] = $product_id;
                     if (isset($date['id'])) {
                         $content['id'] = $date['id'];
                         $parterid = $parter_model->store($content);
                     } else {
                         $ptrid = $parter_model->getByAidAndPid($activity_id, $product_id);
                         if (count($ptrid) < 12) {
                             $parterid = $parter_model->store($content);
                         }
                     }
                     if (isset($parterid) && $parterid > 0) {
                         $sign = $parterid;
                         //判断该条信息是否完整
                         if ($parter_model->iscomplete($parterid)) {
                             $complete = array('id' => $parterid, 'user_id' => $uid, 'complete_status' => ProductPartner::DATA_STATUS_COMPLETE);
                             if ($parter_model->store($complete)) {
                                 $comsta = true;
                             }
                         }
                     }
                 }
             }
             break;
         default:
             $sign = false;
             break;
     }
     if ($delstat) {
         //+TOOD 删除 修改 产品属性值 表数据操作
         echo PublicLibrary::format_res_encode('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 PublicLibrary::format_res_encode('00', 'success', array('id' => $sign, 'imgurl' => $imgurl));
                 exit;
             } else {
                 $btas = $baseattr_model->save($rel_id, $uid, $attrid, $videoid, false, 0);
                 echo PublicLibrary::format_res_encode('01', 'success', array('id' => $sign, 'imgurl' => $imgurl));
                 exit;
             }
         }
     }
     echo PublicLibrary::format_res_encode('1008', 'error');
     exit;
 }
 public function actionPp()
 {
     $model = new ProductPartner();
     //var_dump($model->hasCompleteData(7, 4289));
     //var_dump($model->remove(3, 1));
     $data = ['activity_id' => 7, 'product_id' => 100, 'user_id' => 1, 'partner_title' => 'XXXXXX'];
     /*
             $data = [
        'id' => 2,
        'user_id' => 1,
        'partner_url' => '11111XXXXXX F**K',
             ];
     */
     var_dump($model->store($data));
 }
 /**
  * 获取某产品的合作伙伴
  *
  * @param int $pid 产品ID
  * @param int $uId       发布者ID
  * @param int $aid       所属活动ID
  * @param int $num       查询条数
  *  - Default: 12
  * @return array
  */
 public function ProductPartnerlist($pid, $uId, $aid, $num = 12)
 {
     $conditions = ['uid' => $uId, 'product_id' => $pid, 'activity_id' => $aid];
     $models = ProductPartner::find()->select(['partners_title', 'partners_url', 'partners_logo'])->where($conditions)->orderBy(['partners_order' => SORT_DESC])->limit($num);
     $res = $models->asArray()->all();
     if ($res !== null) {
         return $res;
     } else {
         return false;
     }
 }