Esempio n. 1
0
 public function pay()
 {
     if (IS_POST && count($_SESSION['cart']) > 0) {
         $cart = new \Common\ORG\Cart();
         $user_address = M('user_address');
         $item_order = M('item_order');
         $order_detail = M('order_detail');
         $item_goods = M('item');
         $this->visitor->info['id'];
         //用户ID
         $this->visitor->info['username'];
         //用户账号
         $this->visitor->info['wechatid'];
         //用户账号
         //生成订单号
         $dingdanhao = date("Y-m-dH-i-s");
         $dingdanhao = str_replace("-", "", $dingdanhao);
         $dingdanhao .= rand(1000, 2000);
         $time = time();
         //订单添加时间
         $address_options = input('post.address_options', 'intval');
         //地址  0:刚填的地址 大于0历史的地址
         $shipping_id = input('post.shipping_id', 'intval');
         //配送方式
         $postscript = input('post.postscript', 'trim');
         //卖家留言
         $data['note'] = $postscript;
         $data['freetype'] = 0;
         $data['order_sumPrice'] = $cart->getPrice();
         if ($data['order_sumPrice'] < C('FREE_DELIVERY_AMOUNT')) {
             $data['freeprice'] = C('DELIVERY_FEE');
             $data['order_sumPrice'] += $data['freeprice'];
         }
         $data['orderId'] = $dingdanhao;
         //订单号
         $data['add_time'] = $time;
         //添加时间
         $data['goods_sumPrice'] = $cart->getPrice();
         //商品总额
         $data['userId'] = $this->visitor->info['id'];
         //用户ID
         if ($this->visitor->info['username']) {
             $data['userName'] = $this->visitor->info['username'];
             //用户名
         } else {
             $data['userName'] = $this->visitor->info['wechatid'];
             //用微信id做用户名
         }
         if ($address_options == 0) {
             $consignee = input('post.consignee', 'trim');
             //真实姓名
             $sheng = input('post.sheng', 'trim');
             //省
             $shi = input('post.shi', 'trim');
             //市
             $qu = input('post.qu', 'trim');
             //区
             $address = input('post.address', 'trim');
             //详细地址
             $phone_mob = input('post.phone_mob', 'trim');
             //电话号码
             $save_address = input('post.save_address', 'trim');
             //是否保存地址
             $data['address_name'] = $consignee;
             //收货人姓名
             $data['mobile'] = $phone_mob;
             //电话号码
             $data['address'] = $sheng . $shi . $qu . $address;
             //地址
             if ($save_address) {
                 $add_address['uid'] = $this->visitor->info['id'];
                 $add_address['consignee'] = $consignee;
                 $add_address['address'] = $address;
                 $add_address['mobile'] = $phone_mob;
                 $add_address['sheng'] = $sheng;
                 $add_address['shi'] = $shi;
                 $add_address['qu'] = $qu;
                 $user_address->data($add_address)->add();
             }
         } else {
             $userId = $this->visitor->info['id'];
             $address = $user_address->where("uid='{$userId}'")->find($address_options);
             //取到地址
             $data['address_name'] = $address['consignee'];
             //收货人姓名
             $data['mobile'] = $address['mobile'];
             //电话号码
             $data['address'] = $address['sheng'] . $address['shi'] . $address['qu'] . $address['address'];
             //地址
         }
         if ($orderid = $item_order->data($data)->add()) {
             $orders['orderId'] = $dingdanhao;
             foreach ($_SESSION['cart'] as $item) {
                 $orders['itemId'] = $item['id'];
                 //商品ID
                 $orders['title'] = $item['name'];
                 //商品名称
                 $orders['img'] = $item['img'];
                 //商品图片
                 $orders['price'] = $item['price'];
                 //商品价格
                 $orders['quantity'] = $item['num'];
                 //购买数量
                 $orders['item_attr'] = $item['attr'];
                 //商品属性
                 $order_detail->data($orders)->add();
             }
             $cart->clear();
             //清空购物车
             $this->assign('orderid', $orderid);
             //订单ID
             $this->assign('dingdanhao', $dingdanhao);
             //订单号
             $this->assign('order_sumPrice', $data['order_sumPrice']);
             vendor('Sms.Sms', COMMON_PATH . 'Vendor/');
             $api = \Common\Vendor\Sms\Sms::getInstance(C('SMS_API'));
             $data['cid'] = \Common\Vendor\Sms\Api\SmsWeimi::ORDER_CREATE;
             $data['0'] = $this->visitor->info['mobile'];
             $data['1'] = $dingdanhao;
             $data['2'] = C('ORDER_KEEP_TIME');
             $api->send($mobile, $data);
         } else {
             $this->error('生成订单失败!');
         }
     } else {
         if (isset($_GET['orderId'])) {
             $item_order = M('item_order');
             $orderId = $_GET['orderId'];
             //订单号
             $userId = $this->visitor->info['id'];
             $orders = $item_order->where("userId='{$userId}' and orderId='{$orderId}'")->find();
             if (!is_array($orders)) {
                 $this->_404();
             }
             if (empty($orders['supportmetho']) || $orders['supportmetho'] == 4) {
                 $this->assign('orderid', $orders['id']);
                 //订单ID
                 $this->assign('dingdanhao', $orders['orderId']);
                 //订单号
                 $this->assign('order_sumPrice', $orders['order_sumPrice']);
             } elseif ($orders['supportmetho'] == 1) {
                 $pay = M('pay')->where(array('pay_type' => 'alipay'))->find();
                 $alipay = unserialize($pay['config']);
                 //$this->assign('alipayview',$pay['status']);
                 echo "<script>location.href='api/wapalipay/alipayapi.php?WIDseller_email=" . $alipay['alipayname'] . "&WIDout_trade_no=" . $orderId . "&WIDsubject=" . $orderId . "&WIDtotal_fee=" . $orders['order_sumPrice'] . "'</script>";
             } elseif ($orders['supportmetho'] == 3) {
                 //$pay=M('pay')->where(array('pay_type'=>'wxpay'))->find();
                 //dump($orders);exit;
                 //$wxpay=unserialize($pay['config']);
                 $wxconfig = $this->wxconfig();
                 $ip = get_client_ip();
                 //获取ip
                 //echo $ip;exit;
                 echo "<script>location.href='api/wxpay/jsapicall.php?ip=" . $ip . "&partner=" . $wxconfig['partnerid'] . "&out_trade_no=" . $orderId . "&body=" . $orderId . "&total_fee=" . $orders['order_sumPrice'] . "&notify_url=" . $wxconfig['notify_url'] . "&showwxpaytitle=1'</script>";
             } elseif ($orders['supportmetho'] == 4) {
                 //支付宝个人收款主页收款
                 $modpayset = M('setting');
                 $alipayhome = $modpayset->where("name='alipayhome'")->getField('data');
                 echo "<script>location.href='{$alipayhome}'</script>";
                 exit;
             }
         } else {
             $this->redirect('User/index');
         }
     }
     $alipay = M('pay')->where(array('pay_type' => 'alipay'))->find();
     $this->assign('alipaystatus', $alipay['status']);
     $wxpay = M('pay')->where(array('pay_type' => 'wxpay'))->find();
     $this->assign('wxpaystatus', $wxpay['status']);
     $this->display();
 }
Esempio n. 2
0
 /**
  * ajax发送验证码(注册,找回密码)
  **/
 public function ajaxSendSmsVerifyCode()
 {
     $mobile = input('get.mobile', 'trim');
     if (!preg_match('/1\\d{10}/', $mobile) || preg_match('/[^0-9]/', $mobile)) {
         echo json_encode(array('status' => 0, 'info' => L('invalid_mobile')));
         exit;
     }
     $code = '';
     $vc = M('verifycode');
     $date = date('Ymd');
     $codeRow = $vc->field('code, times')->where(array('code_type' => array('eq', '1'), 'mobile' => array('eq', $mobile), 'date' => array('eq', $date)))->find();
     if ($codeRow) {
         if ($codeRow['times'] == 10) {
             echo json_encode(array('status' => 0, 'info' => L('verify_times_out')));
             exit;
         }
         $code = mt_rand(111111, 999999);
         $vc->where(array('code_type' => array('eq', '1'), 'mobile' => array('eq', $mobile), 'date' => array('eq', $date)))->save(array('times' => $codeRow['times'] + 1, 'code' => $code));
     }
     if (empty($code)) {
         $code = mt_rand(111111, 999999);
         $vc->add(array('mobile' => $mobile, 'code_type' => '1', 'date' => $date, 'code' => $code, 'times' => 1));
     }
     session('sms_reg_' . $mobile, $code);
     vendor('Sms.Sms', COMMON_PATH . 'Vendor/');
     $api = \Common\Vendor\Sms\Sms::getInstance(C('SMS_API'));
     $data['cid'] = \Common\Vendor\Sms\Api\SmsWeimi::VERIFY_CODE;
     $data['0'] = $code;
     $data['1'] = C('SMS_VERIFY_CODE_TIME');
     echo json_encode($api->send($mobile, $data));
     exit;
 }