/** * Action Index */ public function actionIndex() { //$this->layout = false; $session = Yii::$app->session; $session->isActive ? '' : $session->open(); $session->remove('backurl'); $session->remove('form'); $mPageBlock = new PageCustomBlock(); $slideOption['customId'] = PageCustomBlock::MAIN_PAGE_SLIDE; $speechesOption['customId'] = PageCustomBlock::MAIN_PAGE_SPEECHES; $newsOption['customId'] = PageCustomBlock::MAIN_PAGE_NEWS; $productsOption['customId'] = PageCustomBlock::MAIN_PAGE_PRODUCTS; // $slide = $mPageBlock->block(PageCustomBlock::MAIN_PAGE_SLIDE); // $speeches = $mPageBlock->block(PageCustomBlock::MAIN_PAGE_SPEECHES); // $products = $mPageBlock->block(PageCustomBlock::MAIN_PAGE_PRODUCTS); $slide = $mPageBlock->block($slideOption); $speeches = $mPageBlock->block($speechesOption); $news = $mPageBlock->block($newsOption); $products = $mPageBlock->block($productsOption); // print_r($news);exit; //获取产品类型 $product_type = new IProductType(); $product_type = $product_type->product_type_list(); //获取活动 $aproduct = new ActivityBase(); $aproduct = $aproduct->getByStatus(); // //zhanglu // print_r($aproduct);exit; $data = []; //zhanglu //为了获取产品想过活动信息 $mActivityProduct = new ActivityProduct(); foreach ($aproduct as $key => $value0) { $data[$value0['id']] = $value0; } $reg['slide'] = $slide; $reg['speeches'] = $speeches; $reg['products'] = $products; $reg['product_type'] = $product_type; // echo "<pre>"; // print_r($reg['products']); // echo "<pre>"; // print_r($reg['aproduct']); //获取活动详细信息 // print_r($data);exit; foreach ($reg['products'] as $key => $value) { // print_r($value);exit; //zhanglu $ap = $mActivityProduct->getActivitiseById($value['id']); // print_r($ap);exit; // print_r($value);exit; foreach ($value['aproduct'] as $key1 => $value1) { foreach ($data as $key2 => $value2) { if ($value1['acti_id'] == $value2['id']) { $reg['products'][$key]['aproduct'][$key1]['activity'] = $data[$key2]; //zhanglu $reg['products'][$key]['aproduct'][$key1]['apstat'] = $ap[$key1]['apstat']; // $reg['products'][$key]['activity'][$key1]['order']= $key1; } //zhanglu // $reg['products'][$key]['activity'][$key1]['apstat']= $ap[$key1]['apstat']; } } // print_r($reg);exit; //获取用户所在省市 // var_dump($value['user'][province]); // var_dump($value['user'][city]); if ($value['user']['province'] && $value['user']['city']) { $district = new District(); $province = $district->getById(intval($value['user']['province'])); $reg['products'][$key]['user']['province'] = $province['name']; $city = $district->getById(intval($value['user']['city'])); $reg['products'][$key]['user']['city'] = $city['name']; } } // echo "<pre>"; // // print_r($reg);exit; // var_dump($reg['products']);die; //return $this->render('index',['slide' => $slide,'speeches' => $speeches,'products' => $products,'product_type' => $product_type]); $reg['news'] = $news; return $this->render('index', $reg); }
/** * 商品生成订单 * @1.活动产品id rel_id, * @2.代金券id:v_id, * @3.数量:nums, * @4.价格:totalpay, * @5.默认地址id:address_id * @提交地址:http://dev.idaiyan.cn/payment/orderbuild?rel_id=33104&v_id=4&nums=5&totalpay=66&address_id=8 * todo 仅仅可以通过某个链接过来。 */ public function actionOrderbuild() { //开启缓存 $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->post(); if ($parr) { //接收传过来的数据 $address_id = isset($parr['address_id']) ? intval($parr['address_id']) : ''; $v_id = isset($parr['v_id']) ? intval($parr['v_id']) : ''; //优惠券id $nums = isset($parr['nums']) ? intval($parr['nums']) : ''; //数量 $rel_id = isset($parr['rel_id']) ? intval($parr['rel_id']) : ''; //活动产品id //判断是否重复提交表单 $originator = isset($parr['originator']) ? strip_tags($parr['originator']) : ''; //重复提交表单的判断 if ($originator) { if (!empty($_SESSION['fsess'])) { // echo 'ok'; if ($originator == $_SESSION['fsess']) { $_SESSION['fsess'] = mt_rand(0, 1000000); } else { return $this->redirect(['ucenter/my-order']); exit; } } } /* 通过address_id uid查询用户相关的信息 1、判断传过来的地址是否是该用户的地址 2、查询该用户的地址信息 */ //1、判断传过来的地址是否是该用户的地址 $amodels = new HarvestAddress(); $addr = $amodels->isUserHarvest($address_id, $uid); if (!$addr) { return $this->redirect(['product/index']); //跳转到完善信息 exit; } //2、查询该用户的地址信息 $ares = $amodels->pk($address_id); $mobile = $ares['mobile']; if (!$mobile) { $mobile = $ares['telephone']; } $truename = $ares['harvest']; $address_id = $ares['id']; $address = $ares['address']; $province_id = $ares['province']; $city_id = $ares['city']; $mDistrict = new District(); $province = $mDistrict->getById($province_id); $city = $mDistrict->getById($city_id); $location = $province['name'] . ',' . $city['name']; /* 通过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']; //库存 $acprattr_model = new ActivityProductAttrVal(); $acprattr = $acprattr_model->getRealAttrVals($rel_id, $acti_id); $discount_price = isset($acprattr['discount_price']['val']['price']) ? $acprattr['discount_price']['val']['price'] : '1'; //活动价格 //判断需求数和库存数 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']) : ''; //产品名称 if ($v_id) { /* 通过v_id 和 uid 查询优惠券的信息 */ $vmodel = new Volume(); $vres = $vmodel->isMyolume($uid, $v_id); if (!$vres) { return $this->redirect(['product/index']); exit; } $integral = $vres['integral']; //优惠金额 $totalpay = $discount_price * $nums - $integral; //最终价格 if ($totalpay <= 0) { return $this->redirect(['product/index']); exit; } } else { $totalpay = $discount_price * $nums; //最终价格 } $orderno = 'idy' . date('YmdHis', time()) . mt_rand(100000, 999999); $model_order = new Order(); $model_order->uid = $uid; $model_order->mobile = $mobile; $model_order->rel_id = $rel_id; $model_order->product_id = $product_id; $model_order->acti_id = $acti_id; $model_order->v_id = $v_id; $model_order->nums = $nums; $model_order->truename = $truename; $model_order->province = $province['name']; $model_order->city = $city['name']; $model_order->address = $address; $model_order->create_time = time(); $model_order->ip = PublicLibrary::get_ip(); //ip $model_order->totalpay = $totalpay; $model_order->orderno = $orderno; $model_order->save(); $order_id = Yii::$app->db->getLastInsertID(); // $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; } }