예제 #1
0
 /**
  * 用户收货地址
  */
 public function actionProAddress()
 {
     $user_id = Yii::app()->user->getId();
     $userprodaddress = UserProudctAddress::model()->find("user_id=:user_id", array(":user_id" => $user_id));
     if (!$userprodaddress) {
         $userprodaddress = new UserProudctAddress();
     }
     if (isset($_POST['UserProudctAddress'])) {
         $userprodaddress = MemberService::saveProAddress($userprodaddress, $user_id);
     }
     $this->pageTitle = "收货地址";
     $this->render('member_proaddress', array("userprodaddress" => $userprodaddress));
 }
예제 #2
0
 /**
  * 记录订单
  */
 public function actionOrder()
 {
     $this->pageTitle = "购买商品";
     $error = "";
     if (isset($_GET['id'])) {
         $pid = $_GET['id'];
         $product = Product::model()->findByPk($pid);
         if ($product) {
             #获得用户的可用资金
             $user_id = Yii::app()->user->getId();
             #判断用户是否已经填写了送货地址
             $userAddress = UserProudctAddress::model()->find("user_id=:user_id", array(":user_id" => $user_id));
             if ($userAddress) {
                 $userAccount = Account::model()->find("user_id=:user_id", array(":user_id" => $user_id));
                 if (!$userAccount->use_money < $product->product_price) {
                     #调有存储过程冻结资金并生成订单
                     try {
                         $addip = Yii::app()->request->getUserHostAddress();
                         $in_order_price = $in_order_pay_price = $product->product_price;
                         $in_coupon_id = 0;
                         $in_p_user_id = $product->product_user_id;
                         $p_id = $product->product_id;
                         $in_realname = $userAddress->realname;
                         $in_phone = $userAddress->phone;
                         $in_address = $userAddress->address;
                         $conn = Yii::app()->db;
                         $command = $conn->createCommand('call p_build_Product_Order(:in_user_id,:in_p_user_id,:p_id,:in_order_price,:in_order_pay_price,:in_coupon_id,:in_realname,:in_phone,:in_address,:in_addip,@out_status,@out_remark)');
                         $command->bindParam(":in_user_id", $user_id, PDO::PARAM_INT);
                         $command->bindParam(":in_p_user_id", $in_p_user_id, PDO::PARAM_INT);
                         $command->bindParam(":p_id", $p_id, PDO::PARAM_INT);
                         $command->bindParam(":in_order_price", $in_order_price, PDO::PARAM_STR, 30);
                         $command->bindParam(":in_order_pay_price", $in_order_pay_price, PDO::PARAM_STR, 30);
                         $command->bindParam(":in_coupon_id", $in_coupon_id, PDO::PARAM_INT);
                         $command->bindParam(":in_realname", $in_realname, PDO::PARAM_STR, 30);
                         $command->bindParam(":in_phone", $in_phone, PDO::PARAM_STR, 30);
                         $command->bindParam(":in_address", $in_address, PDO::PARAM_STR, 200);
                         $command->bindParam(":in_addip", $addip, PDO::PARAM_STR, 50);
                         $command->execute();
                         $result = $conn->createCommand("select @out_status as status,@out_remark as remark")->queryRow(true);
                         if ($result['status'] == 1) {
                             $error = '购买成功!';
                             $notices = array('type' => 3, 'msgtitle' => '错误信息', 'message' => $error, 'backurl' => Yii::app()->request->urlReferrer, 'backtitle' => '返回', 'tourl' => Yii::app()->createUrl('/wechat/member/myProduct'), 'totitle' => '查看订单');
                         } else {
                             $error = $result['remark'];
                             $notices = array('type' => 2, 'msgtitle' => '错误信息', 'message' => $error, 'backurl' => Yii::app()->request->urlReferrer, 'backtitle' => '返回');
                         }
                     } catch (Exception $e) {
                         $error = '系统繁忙,暂时无法处理';
                         $notices = array('type' => 2, 'msgtitle' => '错误信息', 'message' => $error, 'backurl' => Yii::app()->request->urlReferrer, 'backtitle' => '返回');
                     }
                 } else {
                     #跳转到充值页面
                     $error = "你的可用资金不足以购买此商品。";
                     $notices = array('type' => 3, 'msgtitle' => '错误信息', 'message' => $error, 'backurl' => Yii::app()->request->urlReferrer, 'backtitle' => '返回', 'tourl' => Yii::app()->createUrl('/wechat/member/addmoney'), 'totitle' => '前往充值');
                 }
             } else {
                 #跳转到充值页面
                 $error = "您没有填写收货地址。";
                 $notices = array('type' => 3, 'msgtitle' => '错误信息', 'message' => $error, 'backurl' => Yii::app()->request->urlReferrer, 'backtitle' => '返回', 'tourl' => Yii::app()->createUrl('/wechat/member/proAddress'), 'totitle' => '完善送货地址');
             }
         } else {
             $error = "不存在此商品或者该商品已下架。";
             $notices = array('type' => 2, 'msgtitle' => '错误信息', 'message' => $error, 'backurl' => Yii::app()->request->urlReferrer, 'backtitle' => '返回');
         }
     } else {
         $error = "不存在此商品或者该商品已下架。";
         $notices = array('type' => 2, 'msgtitle' => '错误信息', 'message' => $error, 'backurl' => Yii::app()->request->urlReferrer, 'backtitle' => '返回');
     }
     #msg类型:type=1错误信息2指示跳转3返回跳转
     Yii::app()->user->setFlash('wechat_fail', array($notices));
     $this->redirect(Yii::app()->createUrl('wechat/notice/errors'));
 }
예제 #3
0
 public static function saveProAddress(UserProudctAddress $userprodaddress, $user_id)
 {
     $_POST['UserProudctAddress']['province'] = 'xx';
     $_POST['UserProudctAddress']['city'] = 'xx';
     $_POST['UserProudctAddress']['area'] = 'xx';
     $_POST['UserProudctAddress']['sysaddress'] = 'xx';
     if (isset($_POST['province'])) {
         $_POST['UserProudctAddress']['province'] = $_POST['province'];
         $provincename = Province::model()->find("provinceID=:proid", array(":proid" => $_POST['UserProudctAddress']['province']));
         if ($provincename) {
             $_POST['UserProudctAddress']['sysaddress'] = $provincename->province;
         }
     }
     if (isset($_POST['city'])) {
         $_POST['UserProudctAddress']['city'] = $_POST['city'];
         $cityname = City::model()->find("cityID=:cityid", array(":cityid" => $_POST['UserProudctAddress']['city']));
         if ($cityname) {
             $_POST['UserProudctAddress']['sysaddress'] .= $cityname->city;
         }
     }
     if (isset($_POST['area'])) {
         $_POST['UserProudctAddress']['area'] = $_POST['area'];
         $areaname = Area::model()->find("areaID=:areaid", array(":areaid" => $_POST['UserProudctAddress']['area']));
         if ($areaname) {
             $_POST['UserProudctAddress']['sysaddress'] .= $areaname->area;
         }
     }
     $_POST['UserProudctAddress']['user_id'] = $user_id;
     $userprodaddress->setAttributes($_POST['UserProudctAddress']);
     foreach ((array) $_POST['UserProudctAddress'] as $key => $value) {
         if (trim($value) == '') {
             $userprodaddress->addError($key, "字段不能为空");
             break;
         }
     }
     if (!$userprodaddress->getErrors()) {
         $userprodaddress->setAttribute('addtime', time());
         $userprodaddress->setAttribute('addip', Yii::app()->request->userHostAddress);
         if ($userprodaddress->validate()) {
             if ($userprodaddress->isNewRecord) {
                 $result = $userprodaddress->save();
             } else {
                 $result = $userprodaddress->update();
             }
             if (!$result) {
                 $userprodaddress->addError("realname", "更新失败");
             }
         } else {
             $userprodaddress->addError("realname", "更新失败");
         }
     }
     return $userprodaddress;
 }