Exemplo n.º 1
0
 public function actionAa()
 {
     //更改订单状态
     $orders = PayOrder::sn('56a82aeab957e');
     $time = time();
     $order_id = $orders->order_id;
     $sql1 = "update fin_pay_order set order_status = '4',order_pay_time = '{$time}' where order_id = {$order_id}";
     $user_id = $orders->user_id;
     $coin = $orders->order_price;
     //给用户添加金币
     $student = Students::findOne($user_id);
     $money = $student->stu_money + $coin;
     $stu_id = $student->stu_id;
     $sql2 = "update fin_students set stu_money = '{$money}' where stu_id = '{$stu_id}'";
     //生成记录
     $sql3 = "insert into fin_payment(user_id,payment_type,payment_addtime,payment_money,payment_note,payment_way) values('{$user_id}','1','{$time}','{$coin}','充值金币','2')";
     $connection = \Yii::$app->db;
     $transaction = $connection->beginTransaction();
     try {
         $connection->createCommand($sql1)->execute();
         $connection->createCommand($sql2)->execute();
         $connection->createCommand($sql3)->execute();
         $transaction->commit();
     } catch (Exception $e) {
         $transaction->rollBack();
         echo $e->getMessage();
     }
 }
 /**
  *  支付
  */
 public function actionPay()
 {
     $session = Yii::$app->session->get('userinfo');
     $user_id = $session['user_id'];
     $price = YII::$app->request->post('price');
     // 生成订单
     $Order = new PayOrder();
     $Order->order_sn = uniqid();
     $Order->user_id = $user_id;
     $Order->order_addtime = time();
     $Order->order_price = $price;
     $re = $Order->save();
     $order_id = Yii::$app->db->getLastInsertID();
     $this->redirect(['/alipay/index', 'order_id' => $order_id]);
 }
Exemplo n.º 3
0
 /**
  * 支付宝服务器异步通知页面
  */
 public function actionNotifyUrl()
 {
     $this->enableCsrfValidation = false;
     require_once '../../vendor/alipay/lib/alipay_core.function.php';
     require_once '../../vendor/alipay/lib/alipay_md5.function.php';
     require_once '../../vendor/alipay/lib/alipay_notify.class.php';
     require_once '../../vendor/alipay/lib/alipay_submit.class.php';
     $alipay_config = Yii::$app->params['alipay']['alipay_config'];
     //计算得出通知验证结果
     $alipayNotify = new \AlipayNotify($alipay_config);
     $verify_result = $alipayNotify->verifyNotify();
     if ($verify_result) {
         //验证成功
         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
         //请在这里加上商户的业务逻辑程序代
         //——请根据您的业务逻辑来编写程序(以下代码仅作参考)——
         //获取支付宝的通知返回参数,可参考技术文档中服务器异步通知参数列表
         //商户订单号
         $out_trade_no = $_POST['out_trade_no'];
         $type = substr($out_trade_no, 0, 3);
         //支付宝交易号
         $trade_no = $_POST['trade_no'];
         //交易状态
         $trade_status = $_POST['trade_status'];
         if ($type == '110') {
             //更改订单状态
             $orders = GoodsOrder::sn($out_trade_no);
             $time = time();
             $order_id = $orders->order_id;
             $sql1 = "update fin_goods_order set order_status = '4',order_pay_time = '{$time}' where order_id = {$order_id}";
             $user_id = $orders->user_id;
             $order_amount = $orders->order_amount;
             $order_price = $orders->order_price;
             $coin = $order_price - $order_amount;
             //给用户减金币
             $student = Students::findOne($user_id);
             $money = $student->stu_money - $coin;
             $stu_id = $student->stu_id;
             $sql2 = "update fin_students set stu_money = '{$money}' where stu_id = '{$stu_id}'";
             //生成记录
             $sql3 = "insert into fin_payment(user_id,payment_type,payment_addtime,payment_money,payment_note,payment_way) values('{$user_id}','1','{$time}','{$coin}','商家订单','2')";
             $connection = \Yii::$app->db;
             $transaction = $connection->beginTransaction();
             try {
                 $connection->createCommand($sql1)->execute();
                 $connection->createCommand($sql2)->execute();
                 $connection->createCommand($sql3)->execute();
                 $transaction->commit();
             } catch (Exception $e) {
                 $transaction->rollBack();
                 echo $e->getMessage();
             }
         } elseif ($type == '100') {
             //更改订单状态
             $orders = PayOrder::sn($out_trade_no);
             $time = time();
             $order_id = $orders->order_id;
             $sql1 = "update fin_pay_order set order_status = '4',order_pay_time = '{$time}' where order_id = {$order_id}";
             $user_id = $orders->user_id;
             $coin = $orders->order_price;
             //给用户添加金币
             $student = Students::findOne($user_id);
             $money = $student->stu_money + $coin;
             $stu_id = $student->stu_id;
             $sql2 = "update fin_students set stu_money = '{$money}' where stu_id = '{$stu_id}'";
             //生成记录
             $sql3 = "insert into fin_payment(user_id,payment_type,payment_addtime,payment_money,payment_note,payment_way) values('{$user_id}','1','{$time}','{$coin}','充值金币','2')";
             $connection = \Yii::$app->db;
             $transaction = $connection->beginTransaction();
             try {
                 $connection->createCommand($sql1)->execute();
                 $connection->createCommand($sql2)->execute();
                 $connection->createCommand($sql3)->execute();
                 $transaction->commit();
             } catch (Exception $e) {
                 $transaction->rollBack();
                 echo $e->getMessage();
             }
         }
         if ($_POST['trade_status'] == 'TRADE_FINISHED') {
             //判断该笔订单是否在商户网站中已经做过处理
             //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
             //如果有做过处理,不执行商户的业务程序
             //注意:
             //该种交易状态只在两种情况下出现
             //1、开通了普通即时到账,买家付款成功后。
             //2、开通了高级即时到账,从该笔交易成功时间算起,过了签约时的可退款时限(如:三个月以内可退款、一年以内可退款等)后。
             //调试用,写文本函数记录程序运行情况是否正常
             //logResult("这里写入想要调试的代码变量值,或其他运行的结果记录");
             //logResult($_POST['trade_status']);
         } else {
             if ($_POST['trade_status'] == 'TRADE_SUCCESS') {
                 //判断该笔订单是否在商户网站中已经做过处理
                 //如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
                 //如果有做过处理,不执行商户的业务程序
                 //注意:
                 //该种交易状态只在一种情况下出现——开通了高级即时到账,买家付款成功后。
                 //调试用,写文本函数记录程序运行情况是否正常
                 //logResult("这里写入想要调试的代码变量值,或其他运行的结果记录");
                 //logResult($_POST['trade_status']);
             }
         }
         //——请根据您的业务逻辑来编写程序(以上代码仅作参考)——
         echo "success";
         //请不要修改或删除
         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     } else {
         //验证失败
         echo "fail";
         //调试用,写文本函数记录程序运行情况是否正常
         //logResult("这里写入想要调试的代码变量值,或其他运行的结果记录");
     }
 }