/** * @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]); }