예제 #1
0
 /**
  * [活动属性处理接口]
  * @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;
     }
 }
예제 #2
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');
     }
 }
예제 #3
0
 /**
  * 一呼百应活动支付生成订单
  * @1.活动产品rel_id,2.手机号:mobile,3.用户名:username,4.地址:address,5.支付宝号:alipay  6.验证签名:checkkey
  * @测试地址:http://dev.idaiyan.cn/activity/generationh5&rel_id=32827#
  * @提交地址:http://dev.idaiyan.cn/order/orderbuild?rel_id=32770&a_id=7&address=北京市海淀区
  * @线上地址:http://test.idaiyan.cn/order/orderbuild?rel_id=32770&a_id=7&address=beijing
  */
 public function actionOrderbuild()
 {
     //开启缓存
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     // //判断用户有没有登录
     // $_SESSION['user']['uid'] = 26;
     // // $uid = '26';
     $parr = Yii::$app->request->post();
     // $m_member = spClass("m_member");
     $mobile = $_SESSION['user']['mobile'];
     // $mobile = '13718147652';
     $rel_id = intval($parr['rel_id']);
     //查询产品id
     $ActivityProduct = new ActivityProduct();
     $apt = $ActivityProduct->pk($rel_id);
     $product_id = $apt['product_id'];
     $a_id = intval($parr['a_id']);
     $address = strip_tags($parr['address']);
     $truename = isset($parr['share_name']) ? strip_tags($parr['share_name']) : '';
     // if ($uid) {
     if ($address) {
         //获取活动价格
         $acprattr_model = new ActivityProductAttrVal();
         $acprattr = $acprattr_model->getRealAttrVals($rel_id, $a_id);
         $price = isset($acprattr['discount_price']['val']['price']) ? $acprattr['discount_price']['val']['price'] : '1';
         // 已登录  密码 动态码 情况
         if (!empty($_SESSION['user']['uid']) && $rel_id) {
             //添加订单数据
             $uid = $_SESSION['user']['uid'];
             $model_order = new Order();
             $model_order->uid = $uid;
             $model_order->mobile = $mobile;
             $model_order->rel_id = $rel_id;
             $model_order->acti_id = $a_id;
             $model_order->product_id = $product_id;
             $model_order->truename = $truename;
             $model_order->address = $address;
             $model_order->create_time = time();
             $model_order->totalpay = $price;
             //活动详细页面
             $model_order->ip = PublicLibrary::get_ip();
             //ip
             $model_order->orderno = 'iwx' . date('YmdHis', time()) . mt_rand(100000, 999999);
             $model_order->save();
             $order_id = Yii::$app->db->getLastInsertID();
             //获取刚刚插入到数据库的订单id
             // echo $order_id;
             if ($order_id) {
                 $output['status'] = 1;
                 $output['order_id'] = '/weixin/jspay?id=' . $order_id;
                 $output['info'] = '订单生成成功!';
                 // $mProductStat->updatePartake($pid);
             } else {
                 $output['status'] = 0;
                 $output['order_id'] = 0;
                 $output['info'] = '订单生成失败,请重新提交!';
             }
         } else {
             $output['status'] = 0;
             $output['order_id'] = 0;
             $output['info'] = '用户未登录或没有该产品!';
         }
         // return $this->redirect('weixin/jspay',['act' =>'pay', 'id' =>$rel_id]);
     } else {
         $output['status'] = 0;
         $output['order_id'] = 0;
         $output['info'] = '信息填写不完整!';
     }
     // }
     $output = PublicLibrary::format_res_encode($output['status'], $output['info'], $output['order_id']);
     // var_dump($output);
     echo $output;
 }
예제 #4
0
 /**
  * @author song
  * 产品 下单
  *
  * */
 public function actionOrder()
 {
     $rel_id = Yii::$app->request->get('rel_id');
     $rel_id = intval($rel_id);
     //判断活动状态
     //$rel_id = $shareone['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;
     }
     $user = PublicLibrary::is_login();
     if ($user && $user['uid'] != 'weixin') {
         $uid = isset($user['uid']) ? $user['uid'] : '0';
     } else {
         $backurl = Yii::$app->params['idaiyan'] . "/baiying/order?rel_id=" . $rel_id;
         $backurl = Publiclibrary::encode_callback($backurl);
         if ($user && $user['uid'] == 'weixin') {
             return $this->redirect(['baiying/login', 'backurl' => $backurl]);
         } else {
             return $this->redirect(['baiying/auth', 'backurl' => $backurl]);
         }
     }
     if (Yii::$app->request->isPost) {
         $session = Yii::$app->session;
         $session->isActive ? '' : $session->open();
         $form = Yii::$app->request->post();
         $date = array_map('trim', $form);
         $date = array_map('strip_tags', $date);
         $rel_id = intval($date['rel_id']);
         $mactpro = new ActivityProduct();
         $actproone = $mactpro->pk($rel_id);
         if (empty($actproone)) {
             return $this->redirect(['baiying/productlist']);
         }
         //判断提交是否完整
         if (empty($rel_id) || empty($date['share_name'])) {
             return $this->redirect(['baiying/order', 'rel_id' => $rel_id]);
             exit;
         }
         $mshare = new BaiyingShare();
         $shareone = $mshare->getShareone($rel_id, $uid, ActivityBase::APPLY_BAIYING);
         if ($shareone) {
             return $this->redirect(['baiying/preview', 'sid' => $shareone['id']]);
             exit;
         }
         //图片上传
         $priceimg = UploadedFile::getInstanceByName('share_avatar');
         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');
             $content['share_avatar'] = $setpimage_path;
         } else {
             $useravatar = $mshare->getUseravater($uid);
             $headimgurl = isset($user['headimgurl']) ? $user['headimgurl'] : '';
             $content['share_avatar'] = isset($useravatar['share_avatar']) ? $useravatar['share_avatar'] : $headimgurl;
         }
         $content['rel_id'] = $rel_id;
         $content['uid'] = $uid;
         $content['acti_id'] = ActivityBase::APPLY_BAIYING;
         $content['product_id'] = $actproone['product_id'];
         $content['share_name'] = $date['share_name'];
         $content['share_sex'] = intval($date['share_sex']);
         $content['openid'] = isset($session['user']['openid']) ? $session['user']['openid'] : '';
         $sid = $mshare->store($content);
         if ($sid) {
             return $this->redirect(['baiying/preview', 'sid' => $sid]);
             exit;
         } else {
             return $this->redirect(['baiying/order', 'rel_id' => $rel_id]);
             exit;
         }
     }
     $mshare = new BaiyingShare();
     $slist = $mshare->getShareone($rel_id, $uid, ActivityBase::APPLY_BAIYING);
     //已经参与过
     if ($slist) {
         return $this->redirect(['baiying/userproduct']);
         exit;
     }
     $useravatar = $mshare->getUseravater($uid);
     if ($useravatar) {
         if (substr($useravatar['share_avatar'], 0, 4) == 'http') {
             $useravatar['share_avatar'] = $useravatar['share_avatar'];
         } else {
             $useravatar['share_avatar'] = Yii::$app->params['idaiyan'] . '/' . $useravatar['share_avatar'] . '.jpg';
         }
         $user['headimgurl'] = $useravatar['share_avatar'];
         $user['share_sex'] = $useravatar['share_sex'];
     }
     if (empty($user['headimgurl']) && isset($user['headimgurl'])) {
         $user['headimgurl'] = $_SESSION['user']['headimgurl'];
     }
     $username = $mshare->getUsername($uid);
     if ($username) {
         $user['nickname'] = $username['share_name'];
         $user['share_sex'] = $useravatar['share_sex'];
     }
     if (!$user['nickname']) {
         $user['nickname'] = $_SESSION['user']['nickname'];
     }
     //echo '<pre>';
     //print_r($user);
     $this->layout = false;
     return $this->render('order', ['rel_id' => $rel_id, 'user' => $user]);
 }
예제 #5
0
 /**
  * [关注]
  * @param  [int] $product_id [产品id]
  * @param  [int] $rel_id 活动产品ID  如果存在则是 更新活动产品统计
  * @param  [int] $type [1,2]
  * 1 关注     2 取消关注
  *
  * @return [json_encode]     [0,1]
  * 0 执行成功 1001 参数错误 1002 系统繁忙
  * 关注接口:http://idaiyan_new.cn/frontend/web/index.php?r=product/user_id=24&product=4291&type=1
  * 取消接口:http://idaiyan_new.cn/frontend/web/index.php?r=product/user_id=24&product=4302&type=2
  */
 public function actionFollow()
 {
     //判断登陆
     $user = PublicLibrary::is_login();
     if ($user && PublicLibrary::is_ajax()) {
         $uid = $user['uid'];
     } else {
         echo PublicLibrary::format_res_encode('1002', 'login or not ajax error !');
         exit;
     }
     // $uid = 25;
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     $form = Yii::$app->request->post();
     $id = isset($form['id']) ? intval($form['id']) : '';
     $product_id = isset($form['product_id']) ? intval($form['product_id']) : $id;
     $type = isset($form['type']) ? intval($form['type']) : '';
     $rel_id = isset($form['rel_id']) ? intval($form['rel_id']) : '';
     //活动产品id
     //用活动产品id 获取活动ID 产品ID
     if ($rel_id) {
         $pactivity_model = new ActivityProduct();
         $pactivity = $pactivity_model->pk($rel_id);
         $activity_id = $pactivity->acti_id ? $pactivity->acti_id : 0;
         $product_id = $pactivity->product_id ? $pactivity->product_id : 0;
     }
     //用户不能关注自己产品
     if (!isset($product_id)) {
         $mActivityProduct = new ActivityProduct();
         $result = $mActivityProduct->pk($rel_id);
         $product_id = $result->product_id;
     }
     $productBase = new IProductBase();
     if ($productBase->isMyProduct($uid, $product_id)) {
         echo PublicLibrary::format_res_encode('1004', '自己不能关注自己的产品');
         exit;
     }
     $pbase = IProductBase::findOne($product_id);
     $pbaseuid = $pbase['uid'];
     // $rel_id = 24576;
     // $type = 2;
     // //用活动产品id 获取活动ID 产品ID
     // if ($rel_id) {
     //     $pactivity_model = new ActivityProduct();
     //     $pactivity = $pactivity_model->pk($rel_id);
     //     $activity_id = $pactivity->acti_id ? $pactivity->acti_id : 0;
     //     $product_id = $pactivity->product_id ? $pactivity->product_id : 0;
     // }
     if (empty($product_id)) {
         echo PublicLibrary::format_res_encode('1003', 'param error !');
         exit;
     }
     $model_Base = new ProductFollow();
     $Mpfollow = new ProductFollow();
     //对follow_num增减
     $follow_num = new IProductStat();
     $Mapstar = new ActivityProductStat();
     $Mmemberstat = new MemberStat();
     if ($type == ProductFollow::API_FOLLOW) {
         if ($rel_id) {
             //设置关注的产品id集 session
             $follow_activ_product = $session['follow_activ_product'] ? $session['follow_activ_product'] : array();
             array_push($follow_activ_product, $rel_id);
             $session['follow_activ_product'] = $follow_activ_product;
             $activityfollow = $Mpfollow->activityfollow($rel_id, $product_id, $activity_id, $uid);
             if ($activityfollow == ProductFollow::FOLLOW_OP_SUCC) {
                 $Mapstar->incr($rel_id, 'follow_num');
             }
         }
         // //设置关注的产品id集 session
         // $follow_productids = $session['follow_product'];
         // array_push($follow_productids, $product_id);
         // $session['follow_product'] = $follow_productids;
         $follow = $model_Base->follow($product_id, $uid);
         if ($follow === ProductFollow::FOLLOW_OP_SUCC || $follow === true) {
             //设置关注的产品id集 session
             $follow_productids = $session['follow_product'] ? $session['follow_product'] : array('');
             array_push($follow_productids, $product_id);
             $session['follow_product'] = $follow_productids;
             $follow_num = $follow_num->modify('follow_num', $product_id);
             //增加 产品统计表 该产品关注数
             $Mmemberstat->incr($pbaseuid, 'pfollow_allnum');
             //增加 用户统计表 产品关注总数字段
         } else {
             if ($follow === ProductFollow::FOLLOW_OP_EXISTS) {
                 // 获取该产品关注数
                 $follow_num = count($model_Base->getFollowUsers($product_id));
             }
         }
     } else {
         if ($rel_id) {
             //设置关注的产品id集 session
             $follow_activ_product = $session['follow_activ_product'] ? $session['follow_activ_product'] : array();
             $key = array_search($rel_id, $follow_activ_product);
             unset($follow_activ_product[$key]);
             $session['follow_activ_product'] = $follow_activ_product;
             $follow = $activityunfollow = $Mpfollow->activityunfollow($rel_id, $product_id, $activity_id, $uid);
             //var_dump($activityunfollow);die;
             if ($activityunfollow === true) {
                 $Mapstar->decr($rel_id, 'follow_num');
             }
             $follow_num = count($model_Base->getFollowUsers($product_id));
         } else {
             // //设置关注的产品id集 session
             // $follow_productids = $session['follow_product'];
             // $key = array_search($product_id, $follow_productids);
             // unset($follow_productids[$key]);
             // $session['follow_product'] = $follow_productids;
             $follow = $model_Base->unfollow($product_id, $uid);
             if ($follow === ProductFollow::FOLLOW_OP_SUCC || $follow === true) {
                 //设置关注的产品id集 session
                 $follow_productids = $session['follow_product'] ? $session['follow_product'] : array('');
                 $key = array_search($product_id, $follow_productids);
                 unset($follow_productids[$key]);
                 $session['follow_product'] = $follow_productids;
                 $follow_num = $follow_num->modify('follow_num', $product_id, 1, FALSE);
                 //减少该产品关注数
                 $Mmemberstat->decr($pbaseuid, 'pfollow_allnum');
                 //减少 用户统计表 产品关注总数字段
             } else {
                 if ($follow === ProductFollow::FOLLOW_OP_CANCELLED) {
                     //设置关注的产品id集 session
                     $follow_productids = $session['follow_product'] ? $session['follow_product'] : array('');
                     $key = array_search($product_id, $follow_productids);
                     unset($follow_productids[$key]);
                     $session['follow_product'] = $follow_productids;
                     // 获取该产品关注数
                     $follow_num = count($model_Base->getFollowUsers($product_id));
                 }
             }
         }
     }
     if ($follow) {
         //用户信息
         $member = new Member();
         $user = $member->getByUid($pbaseuid);
         $pfollow_allnum = $user['memberstar']['pfollow_allnum'];
         //被关注商品数
         $pfollow_num = $user['memberstar']['follow_num'];
         $renqi = isset($user['memberstar']) && is_array($user['memberstar']) ? array_sum($user['memberstar']) : 0;
         echo PublicLibrary::format_res_encode('0', 'success', array('follow_num' => $follow_num, 'renqi' => $renqi, 'pfollow_allnum' => $pfollow_allnum));
         //echo PublicLibrary::format_res_encode('0', 'success', array('follow_num'=> json_encode($session['follow_product'])));
     } else {
         echo PublicLibrary::format_res_encode('1001', 'params error');
     }
 }
예제 #6
0
 /**
  * 获取分组完成度
  *
  * @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;
 }
예제 #7
0
 /**
  * 商品生成订单
  * @1.订单id orderno,
  * @提交地址:http://dev.idaiyan.cn/payment/finishpay?orderno=idy20150424163341192185
  * todo 仅仅可以通过某个链接过来。
  */
 public function actionFinishpay()
 {
     //开启缓存
     $session = Yii::$app->session;
     $session->isActive ? '' : $session->open();
     //判断用户有没有登录
     $user = PublicLibrary::is_login();
     if (!$user) {
         return $this->redirect(['product/index']);
         exit;
     }
     $uid = $_SESSION['user']['uid'];
     $parr = Yii::$app->request->get();
     if ($parr) {
         //接收传过来的数据
         $orderno = isset($parr['orderno']) ? strip_tags($parr['orderno']) : '';
         $model_order = new Order();
         $res = $model_order->getByOrderNo($orderno, $uid);
         if (!$res) {
             return $this->redirect(['product/index']);
             exit;
         }
         //支付成功的话跳转到个人中心
         if ($res['ispay']) {
             return $this->redirect(['ucenter/my-order']);
             exit;
         }
         $rel_id = $res['rel_id'];
         $nums = $res['nums'];
         $totalpay = $res['totalpay'];
         $truename = $res['truename'];
         $address = $res['address'];
         $mobile = $res['mobile'];
         $province = $res['province'];
         $city = $res['city'];
         $location = $province . ',' . $city;
         /*
             通过rel_id 查询产品相关的信息
         */
         $pmodel = new ActivityProduct();
         // $product = $pmodel->pk(33104);//33104
         $product = $pmodel->pk($rel_id);
         //33104
         $product_id = $product['product_id'];
         $acti_id = $product['acti_id'];
         $stock = $product['stock'];
         //库存
         //判断需求数和库存数
         if ($nums > $stock) {
             return $this->redirect(['product/index']);
             exit;
         }
         /*
             通过product_id 查询产品相关的信息
         */
         $pmodel = new IProductBase();
         $pres = $pmodel->pk($product_id);
         $name = isset($pres['name']) ? strip_tags($pres['name']) : '';
         //产品名称
         $relpay = $totalpay * 100;
         //价格换算
         $native = Yii::$app->util->weixinnative(1, $name, $orderno);
         //支付宝生成二维码
         $params = ['out_trade_no' => $orderno, 'subject' => $name, 'total_fee' => 0.01, 'body' => $name, 'show_url' => Yii::$app->params['idaiyan'] . '/product/view?id=' . $product_id];
         $formHtml = Yii::$app->alipay->form($params);
         $qrCodeHtml = Yii::$app->alipay->qrcode($params);
         return $this->render('order', ['orderno' => $orderno, 'totalpay' => $totalpay, 'address' => $address, 'location' => $location, 'mobile' => $mobile, 'truename' => $truename, 'native' => $native, 'formHtml' => $formHtml, 'qrCodeHtml' => $qrCodeHtml]);
     } else {
         echo '该页面已经过期啦!';
         exit;
     }
 }