cncpvc 2021-11-11 17:41 采纳率: 85.7%
浏览 21
已结题

如何让错误信息记事本改成记录到数据中


<?php
// +----------------------------------------------------------------------
// | Quotes [ 只为给用户更好的体验]**[我知道发出来有人会盗用,但请您留版权]
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 青涩  <3489621943@qq.com>          盗用不留版权,你就不配拿去!
// +----------------------------------------------------------------------
// | Date: 20210324// +----------------------------------------------------------------------
include("../includes/common.php");
try{
    function success($data,$msg='获取成功'){
    echo json_encode(array_merge([
        'code'=>1,
        'msg'=>$msg
    ],$data));
    exit();
}
function error($msg){
    echo json_encode([
        'code'=>-1,
        'msg'=>$msg
    ]);
    exit();
}
$action = $_REQUEST['act'];
    file_put_contents(__DIR__.'/request.txt',var_export($_REQUEST,true)."\n",\FILE_APPEND);
if($action=='query'){
//$rows=$DB->getRow("select * from ucenter_apps where type='$type' and pid='$pid' and trade_no='$trade_no' or out_trade_no='$out_trade_no' limit 1");
    success([
        "pid"=>$_REQUEST['pid'],
        "key"=>$_REQUEST['key'],
        "qq"=>"0",
        "paymb"=>"99999999",
        "outtime"=>"120",
        "repeat"=>"1",
        "money_nums"=>"5",
        "login"=>0,
        "addtime"=>date('Y-m-d H:i:s'),
        "active"=>"1"
    ]);
}else if($action=='submit'){
    $apikey = $_REQUEST['apikey'];
    $pid = $_REQUEST['pid'];
    $key = $_REQUEST['key'];
    $pay_id = $_REQUEST['pay_id'];
    $outtime = $_REQUEST['outtime'];
    $trade_no = $_REQUEST['trade_no'];
    $apikey = $_REQUEST['apikey'];
    $out_trade_no = $_REQUEST['out_trade_no'];
    $notify_url = $_REQUEST['notify_url'];
    $type = $_REQUEST['type'];
    $name = $_REQUEST['name'];
    $money = $_REQUEST['money'];
    $sign = $_REQUEST['sign'];
    // file_put_contents('./test.txt',var_export($_REQUEST,true),\FILE_APPEND);
    //判断订单是否存在
    $rows=$DB->getRow("select * from ucenter_order where type='$type' and pid='$pid' and trade_no='$trade_no' or out_trade_no='$out_trade_no' limit 1");
    if($rows){
           file_put_contents(__DIR__.'/err1.txt', "订单号已存在,请重试!\n",\FILE_APPEND);
        error('订单号已存在,请重试!');
    }
    $time  = time();
    $rows=$DB->getRow("select * from ucenter_order where  name='$name' and type='$type' and pid='$pid' and  status=0 and pay_money='$money' and outtime>'$time' limit 1");
    $pay_money  = $money;
    if($rows){
        $maxMoney = $money+0.1;
        $moneys=$DB->getAll("select * from ucenter_order where name='$name' and  type='$type' and pid='$pid' and  status=0 and pay_money>'$money' and pay_money <='$maxMoney' and outtime>'$time' order by pay_money");
        // file_put_contents(__DIR__.'/err1.txt',var."\n",\FILE_APPEND);
        if($moneys){
             $moneys = array_column($moneys,'pay_money',null);
            for($i=0.01;$i<0.1;$i+=0.01){
                if(!in_array(($money+$i).'',$moneys)){
                    //可以使用的价格
                    $pay_money = $money+$i;
                    break;
                }
            }
        }else{
              $pay_money = $money+0.01;
        }
       
        if($pay_money==$money){
         file_put_contents(__DIR__.'/err1.txt', "业务繁忙,请重新提交订单!\n",\FILE_APPEND);

            error('业务繁忙,请重新提交订单!');
        }
    
    // echo '订单价格相同';
    // exit();
    }
    // $appkey = md5(mt_rand(0,999).time());
    $sql="insert into `ucenter_order` (`apikey`,`pid`,`key`,`pay_id`,`outtime`,`trade_no`,`out_trade_no`,`notify_url`,`type`,`name`,`money`,`pay_money`,`apitime`,`addtime`,`sign`) values (:apikey,:pid,:key,:pay_id, :outtime, :trade_no, :out_trade_no, :notify_url, :type, :name, :money,:pay_money,:apitime,:addtime,:sign)";
    $res =$DB->exec($sql, [
        'apikey'=>$apikey,
        'pid'=>$pid,
        'key'=>$key,
        'pay_id'=>$pay_id, 
        'outtime'=>time()+$outtime, 
        'trade_no'=>$trade_no, 
        'out_trade_no'=>$out_trade_no,
        'notify_url'=>$notify_url, 
        'type'=>$type,
        'name'=>$name,
        'money'=>$money,
        'pay_money'=>$pay_money,
        'apitime'=>time(),
        'sign'=>$sign,
        'addtime'=>time(),
    ]);
    if($res!==false){
        success([
            "money"=>$pay_money,
            'pid' => $pid,
            'login' => 0,
            'out_trade_no' =>$out_trade_no,
            'name' => $name,
            'date' =>date('Y-m-d H:i:s')
        ],'记录订单成功');
    }else{
        error($DB->error());
    }
}
}catch(\Exception $e){
    file_put_contents(__DIR__.'/err.txt', $e->getMessage()."\n",\FILE_APPEND);
}

这段代码中: file_put_contents(DIR.'/err1.txt', "订单号已存在,请重试!\n",\FILE_APPEND);,是记录错误信息的记事本代码,我已经创建了数据库,我不想让他记事本记录,直接记录到数据的表记录即可。

  • 写回答

1条回答 默认 最新

  • li_zhicheng_126 2021-11-12 21:57
    关注

    看了你的代码,建议学习一个框架,学好了代码会正规很多,开发效率也会高很多。
    框架里面都有错误记录处理模块的。

    你的代码里可以修改function error($msg) 这个函数,把$msg写入数据库

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月15日
  • 已采纳回答 12月7日
  • 创建了问题 11月11日

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分