12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace app\index\controller;
- use addons\epay\library\Service;
- use app\common\controller\Frontend;
- use app\common\model\MobileOrder;
- use think\Db;
- /**
- * 第三方登录控制器
- */
- class Payment extends Frontend
- {
- protected $noNeedLogin='*';
- /**
- * 支付成功回调
- */
- public function notify($type,$order_no)
- {
- $data=Service::checkNotify($type);
- if (!$data) {
- echo '签名错误';
- return;
- }
- $name="pay/$type/{$order_no}";
- user_log($name,compact('type','order_no','data'));
- Db::startTrans();
- $order=MobileOrder::where('order_no',$order_no)->lock(true)->find();
- if(!$order){
- user_log($name,"订单没找到");
- Db::rollback();
- return '订单没找到';
- }
- if($order['pay_time']){
- user_log($name,"订单已支付");
- Db::rollback();
- return '订单已支付';
- }
- $order['pay_time']=time();
- if($type=='wechat'){
- $order['pay_type']=1;
- $order['pay_no']=$data['transaction_id'];
- }else{
- $order['pay_type']=2;
- }
- if(!$order->save()){
- user_log($name,"保存失败");
- Db::rollback();
- return '保存失败';
- }
- Db::commit();
- //你可以在这里你的业务处理逻辑,比如处理你的订单状态、给会员加余额等等功能
- //下面这句必须要执行,且在此之前不能有任何输出
- echo "success";
- return;
- }
- }
|