Exemplo n.º 1
0
 /**
  * 在线支付
  * 先判断是否是在线充值,在线支付订单需要有订单号;
  * 查询出订单信息之后将必需信息提交到支付宝;
  * 
  * 在线充值需在先生成订单信息,然后再将必需信息提交到支付宝;
  * 
  */
 public function index()
 {
     if (IS_POST) {
         $member_id = session('home_member_id');
         /*获取充值用户ID*/
         if (!$member_id) {
             $this->error('请登录后在操作', U('/User/Login/index'));
         }
         /*接收参数*/
         $posts = I('post.');
         $order_id = $posts['order_id'];
         /*获取订单ID*/
         $paytype = $posts['pay_type'];
         /*获取支付方式*/
         if ($order_id) {
             /*判断是订单支付还是在线充值*/
             /* 如果有订单ID则是订单支付 */
             /*获取即将被支付的订单*/
             $info = get_info($this->table, array('id' => $order_id, 'status' => 1));
             if (!$info) {
                 $this->error('订单不存在或已经支付');
             }
             /*获取订单号*/
             $order_no = $info['order_num'];
             $title = $info['title'];
             // 				$title = '商品一';
             $total_price = $info['total_price'];
             $param = array('order_id' => $order_id, 'shop_id' => $info['shop_id'], 'member_id' => $info['member_id']);
         } else {
             /* 没有订单ID则是在线充值 */
             $total_price = $posts['recharge_money'];
             /*获取充值金额*/
             if (floatval($total_price) <= 0) {
                 $this->error('充值金额必须大于0');
             }
             $order_no = get_order_num(C('PLATFORM_ID'), $member_id);
             $title = '账户余额充值';
             $_POST = array('title' => $title, 'qty' => '1', 'shop_id' => 0, 'order_num' => $order_no, 'member_id' => $member_id, 'total_price' => $total_price, 'status' => '1', 'pay_type' => '2', 'description' => '账户余额充值', 'type' => '1');
             $res = update_data($this->table);
             if (is_numeric($res)) {
                 /*@liuqiao  购买商品后增加积分*/
                 $get_coin = get_coin_points($total_price, $member_id);
             }
             $param = array('order_id' => $res, 'shop_id' => 0, 'member_id' => $member_id);
             if (!is_numeric($res)) {
                 $this->error('订单生成失败');
             }
         }
         if ($paytype == 'alipay') {
             $callBack = "Pay/pay";
             //$total_price=0.01;//测试完后 删除
             //$param['test']='1';
             // echo $paytype,' -- ',$order_no,' -- ',$title,' -- ',$callBack,' -- ',$param;exit;
             $callBack = "Pay/pay";
             $vo = new \Think\Pay\PayVo();
             $vo->setType($paytype)->setBody("支付成功后请不要关闭窗口,等待自动跳转")->setFee($total_price)->setOrderNo($order_no)->setTitle($title)->setCallback($callBack)->setUrl(U('/Pay/success'))->setParam($param);
             //必要的一些信息,用来产生动态时调用相关数据
             $payment_conf = C('payment.' . $paytype);
             $pay = new \Think\Pay($paytype, $payment_conf);
             echo $pay->buildRequestForm($vo);
         }
     } else {
         $paytype = 'alipay';
         $callBack = "Pay/pay";
         $title = '异步通知支付测试';
         $total_price = 0.01;
         $param['test'] = '1';
         $order_no = get_order_num(1, 1);
         $callBack = "Pay/pay";
         $vo = new \Think\Pay\PayVo();
         $vo->setType($paytype)->setBody("支付成功后请不要关闭窗口,等待自动跳转")->setFee($total_price)->setOrderNo($order_no)->setTitle($title)->setCallback($callBack)->setUrl(U('/Pay/success'))->setParam($param);
         //必要的一些信息,用来产生动态时调用相关数据
         $payment_conf = C('payment.' . $paytype);
         $pay = new \Think\Pay($paytype, $payment_conf);
         echo $pay->buildRequestForm($vo);
     }
 }
Exemplo n.º 2
0
 /**
  * 余额支付
  * 1、判断订单所属用户是否是登录用户,是则可以支付
  * 2、判断用户余额是否足够,足够则可以直接支付,
  * 	   余额不足,查看提现账户,看提现账户余额是否足够支付不足部分,
  * 	   提现账户足够支付剩余部分,则扣除剩余部分,提现账户余额不足以支付,则提示支付失败,余额不足
  * 3、扣除支付用户支付金额之后,生成一条资金流动记录,平台账户资金增加,
  * 
  * @author						李东
  * @date						2015-07-13
  */
 public function balance_pay()
 {
     if (IS_POST) {
         $posts = I('post.');
         $order_id = $posts['order_id'];
         $dealpassword = $posts['deal_password'];
         $member_id = session('home_member_id');
         if (!$member_id) {
             /* 判断用户是否登录 */
             $tips_msg = array('status' => '0', 'msg' => '请登录后再操作');
             /*跳转到输出位置*/
             goto export;
         }
         $map['id'] = $order_id;
         $map['member_id'] = $member_id;
         /*判断订单是否属于当前用户*/
         $order_info = get_info($this->table, $map);
         if (!$order_info) {
             $tips_msg = array('status' => '0', 'msg' => '无权进行该操作');
             /*跳转到输出位置*/
             goto export;
         }
         /*查询登录用户信息*/
         $member_info = get_info($this->member_table, array('id' => $member_id));
         if (md5(md5($dealpassword)) != $member_info['deal_password']) {
             $tips_msg = array('status' => '0', 'msg' => '支付密码错误');
             /*跳转到输出位置*/
             goto export;
         }
         /* 开启事务 */
         $Model = M();
         $Model->startTrans();
         /*判断用户消费余额是否足够支付*/
         if ($member_info['balance'] >= $order_info['total_price']) {
             /*账户余额足够支付,则直接扣除余额*/
             $_POST = array('id' => $member_id, 'balance' => $member_info['balance'] - $order_info['total_price']);
             /*扣除用户金额*/
             $result1 = update_data($this->member_table);
         } elseif ($member_info['balance'] + $member_info['withdrawals'] >= $order_info['total_price']) {
             /*余额账户不足,但是加上提现账户足够支付*/
             /*计算提现账户需要扣除的金额*/
             $surplus_money = $order_info['total_price'] - $member_info['balance'];
             $_POST = array('id' => $member_id, 'balance' => 0, 'withdrawals' => $member_info['withdrawals'] - $surplus_money);
             /*扣除用户金额*/
             $result1 = update_data($this->member_table);
         } else {
             $tips_msg = array('status' => '0', 'msg' => '余额不足');
             /*直接跳转到输出信息位置*/
             goto export;
         }
         /*查询平台账户信息*/
         $platform_info = get_info($this->member_table, array('id' => C('PLATFORM_ID')));
         $_POST = array('id' => trim(C('PLATFORM_ID')), 'withdrawals' => $platform_info['withdrawals'] + $order_info['total_price']);
         /*金额转入平台账户*/
         $result2 = update_data($this->member_table);
         /*添加资金流动记录*/
         $_POST = array('order_num' => $order_info['order_num'], 'frozen' => 0, 'member_id' => C('PLATFORM_ID'), 'money' => $order_info['total_price'], 'from_member_id' => $member_id, 'description' => '购买商品支付', 'type' => '2', 'status' => '3');
         /*更新资金记录表*/
         $result3 = update_data($this->money_table);
         /*将订单状态更新为已支付状态*/
         $_POST = array('id' => $order_id, 'status' => '2', 'step' => '3', 'pay_time' => date('Y-m-d H:i:s', time()));
         $result4 = update_data($this->table);
         /*将订单状态记录添加到订单历史记录表中*/
         $_POST = array('order_id' => $order_id, 'order_status' => '2', 'description' => '付款成功');
         $result5 = update_data($this->history_table);
         /*@liuqiao  购买商品后增加积分*/
         $total_prices = $order_info['total_price'];
         $get_coin = get_coin_points($total_prices, $member_id);
         if (is_numeric($result1) && is_numeric($result2) && is_numeric($result3) && is_numeric($result4) && is_numeric($result5) && is_numeric($get_coin)) {
             /*判断用户余额,平台余额,资金记录,订单状态,订单状态历史记录是否都更新成功,成功则提交事务*/
             $Model->commit();
             $tips_msg = array('status' => '1', 'msg' => '支付成功', 'url' => U('/User/Myorder/index'));
         } else {
             /*如果有任意一个记录为成功执行,则将事务回滚*/
             $Model->rollback();
             $tips_msg = array('status' => '0', 'msg' => '支付失败');
         }
     } else {
         $tips_msg = array('status' => '0', 'msg' => '请求错误');
     }
     export:
     /*判断需要展示的web提示信息*/
     if ($tips_msg['status'] == 1) {
         $this->success($tips_msg['msg'], $tips_msg['url']);
     } else {
         $this->error($tips_msg['msg']);
     }
 }