PHP实现财务审核通过后返现金额到客户的功能_php实例_脚本之家

帝国CMS任意模板中调用留言,可只调用已审核的留言,也可不限制是否审核。

应用场景:

乱侃

代码如下:

有这么一个返现的系统,当前端客户发起提现的时候,后端就要通过审核这笔返现订单,才可以返现到客户的账号里。

      
作为一名新手,一直没有勇气去写一篇分享。原因有很多:诸如:自己水平有限、语言表达不准确、写出的东西没有一点技术点被人嘲笑。今天在公司听了内部员工的一个分享,其中最重要的一点是:提升自身水平的最佳的途径就是——交流。不管你是通过什么途径,交流也好、整理成文字分享也好等等都是很好的方式。故此,今天献丑写一篇自己的心得分享,欢迎各路大神的指教!

?//bid为留言分类ID,checked='0' 0为已审核,1为未审核$sql=$empire-query(select * from {$dbtbpre}enewsgbook where bid='1' and checked='0' order by lyid desc limit 8);while($r=$empire-fetch($sql)){ $lytext=strip_tags($r['lytext']); echo 'lia href=/e/tool/gbook/?bid=1'.$lytext.'/a/li';}? 

来看看下面的截图

   需求背景

这里的业务场景就是经过两轮审核:销售审核,财务审核都通过后,后端就会付款一笔钱到客户,当然,这里财务审核会有很多种情况,不通过与通过,通过后直接付款又有很多种情况,详细可以查看微信付款到零钱的文档。下面就来看看具体你的代码实现

    
今天接到的需求里面有个这样的需求,如下图所示,需要打印出如Excel内容呈现的单据。

微信支付配置

    动手操作第一版本

CREATE TABLE `zmq_weixin_config`  unsigned NOT NULL AUTO_INCREMENT COMMENT '微信公众平台编号,自增id', `weixin_name` varchar NOT NULL COMMENT '微信公众平台名称', `token` varchar NOT NULL, `appid` char NOT NULL, `appsecret` char NOT NULL, `access_token` varchar NOT NULL, `api_ticket` varchar DEFAULT NULL COMMENT '微信卡包api_ticket', `api_ticket_expired_at` datetime DEFAULT NULL COMMENT '微信卡包api_ticket过期时间', `mchid` varchar DEFAULT NULL COMMENT '商户号', `mchkey` varchar DEFAULT NULL COMMENT '支付密钥', `expired_at` timestamp NULL DEFAULT NULL COMMENT 'access_token过期时间,会自动更新', `updated_at` timestamp NULL DEFAULT NULL COMMENT '记录更新时间', `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间', `sort_order` smallint NOT NULL DEFAULT '0' COMMENT '排序', `points_url` varchar DEFAULT NULL, PRIMARY KEY  ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC COMMENT='微信配置表';

    
而为了实现这个业务需要涉及三张表的数据。(存放单据的表、审核意见表、审核状态表)
     三张表的关系:单据表1:1审核状态表,单据表1:N审核意见表
     为了实现让View页面整洁,我定义了一个SpecialPrintModel类

2 .config的配置方法

public class SpecialPrintModel
  {
    /// <summary>
    /// 供应商承担
    /// </summary>
    public string SupplierUnderTaker { get; set; }

    /// <summary>
    /// 客户订单号
    /// </summary>
    public string CustomerSerialNumber { get; set; }

    /// <summary>
    /// 付款金额
    /// </summary>
    public decimal PayAmount { get; set; }

    /// <summary>
    /// 开户行
    /// </summary>
    public string OpeningBank { get; set; }

    /// <summary>
    /// 收款单位
    /// </summary>
    public string CollectionMonad { get; set; }

    /// <summary>
    /// 银行帐号
    /// </summary>
    public string BankAccount { get; set; }

    /// <summary>
    /// 经办人
    /// </summary>
    public string ResponseiblePerson { get; set; }

    /// <summary>
    /// 分管领导
    /// </summary>
    public string Leader { get; set; }

    /// <summary>
    /// 财务审核
    /// </summary>
    public string FinanceApproval { get; set; }

    /// <summary>
    /// 财务经理审核
    /// </summary>
    public string FinanceManagerApproval { get; set; }

    /// <summary>
    /// 财务总监审核
    /// </summary>
    public string FinanceDirectorApproval { get; set; }

    /// <summary>
    /// CEO审核
    /// </summary>
    public string CEOApproval { get; set; }

    /// <summary>
    /// 流水号
    /// </summary>
    public string SerialNumber { get; set; }
  }


public List<ShipSpecialPrintModel> GetTobePaidRecepit(ShipSpecialSearch search)
 {
   List<ShipSpecialPrintModel> curiseShipModel = new List<ShipSpecialPrintModel>();
   var toBePaidModel = persistant.GetTobePaidRecepit(search);//查找出待支付的单据表信息
   ArrayList serialArray=new ArrayList();//定义一个流水号列表
   toBePaidModel.ForEach((u) => { serialArr.Add(u.SerialNumber); });
   var toBePaidComment = persistant.GetTobePaidRecepitComment(serialArr);//查找出待支付单据的审核意见表(1个单据对应多少审核意见)
   foreach (var item in toBePaidModel)
   {
     ShipSpecialPrintModel temp = new ShipSpecialPrintModel()
     {
         SupplierUnderTaker = supplierUnderTaker;
         CustomerSerialNumber = item.CustomerOrderNumber;
         PayAmount = item.PayAmount;
         OpeningBank = item.PayBank;
         CollectionMonad = item.Payee;
         ResponseiblePerson = item.Creator;
         SerialNumber = item.SerialNumber;
     };
     curiseShipModel.Add(temp);
   }
    foreach (var curise in curiseShipModel)
      {
        foreach (var comment in toBePaidComment)
        {
          if (comment.SerialNumber == curise.SerialNumber)
          {
            if (comment.ApprovalLevel == (int)LevelType.BranchedLeader)
            {
              curise.Leader = comment.Creator;
            }
            else if (comment.ApprovalLevel == (int)LevelType.Finance)
            {
              curise.FinanceApproval = comment.Creator;
            }
            else if (comment.ApprovalLevel == (int)LevelType.FinanceManager)
            {
              curise.FinanceManagerApproval = comment.Creator;
            }
            else if (comment.ApprovalLevel == (int)LevelType.ProjectDirector)
            {
              curise.FinanceDirectorApproval = comment.Creator;
            }
            else if (comment.ApprovalLevel == (int)LevelType.CEO)
            {
              curise.CEOApproval = comment.Creator;
            }
          }
        }
      }

   return curiseShipModel
 }
/** * 获取微信支付配置 * 这里我是把配置信息存储在数据表里,方便调用 * $param是从controller里传值过来:weixin_config_id,notify_url * @return array */public function getWechatConfig{ $weixin = WeixinConfigBaseModel::find($param['weixin_config_id']); if  { throw new Exception; } return [ 'wechat' =>[ $app_id => $weixin->appid, 'mch_id' => $weixin->mchid, 'notify_url' => empty ? '' : $param['notify_url'], //回调url 'key' => $weixin->mchkey, 'cert_client' => resource_path().'/wechat/'.$weixin->id.'/apiclient_cert.pem', //证书与key 'cert_key' => resource_path().'/wechat/'.$weixin->id.'/apiclient_key.pem', ] ];}

   
呵呵,上面的代码基本完成了业务的需求,可是如果业务需要打印出CTO的名称、CIO的名称那在if
else这边加,虽然很简单但是违背了开放-封闭的原则。故本人决定用反射去完成这if…else的事情。
因为if…else里面的判断是当前的这笔单据的审核意见表的层级是不是跟SpecialPrintModel的字段所对应的层级相等,若相等则在对应字段写入相对应的名称。决定把SpecialPrintModel这个类修改下。
 
   动手操作第二版本

企业付款到个人零钱核心代码

public class ShipSpecialPrintModel
  {
    /// <summary>
    /// 供应商承担
    /// </summary>
    public string SupplierUnderTaker { get; set; }

    /// <summary>
    /// 客户订单号
    /// </summary>
    public string CustomerSerialNumber { get; set; }

    /// <summary>
    /// 付款金额
    /// </summary>
    public decimal PayAmount { get; set; }

    /// <summary>
    /// 开户行
    /// </summary>
    public string OpeningBank { get; set; }

    /// <summary>
    /// 收款单位
    /// </summary>
    public string CollectionMonad { get; set; }

    /// <summary>
    /// 银行帐号
    /// </summary>
    public string BankAccount { get; set; }

    /// <summary>
    /// 经办人
    /// </summary>
    public string ResponseiblePerson { get; set; }

    /// <summary>
    /// 分管领导
    /// </summary>
    [LevelAttribute(Level = 1)]
    public string Leader { get; set; }

    /// <summary>
    /// 财务审核
    /// </summary>
     [LevelAttribute(Level = 2)]
    public string FinanceApproval { get; set; }

    /// <summary>
    /// 财务经理审核
    /// </summary>
     [LevelAttribute(Level = 3)]
    public string FinanceManagerApproval { get; set; }

    /// <summary>
    /// 财务总监审核
    /// </summary>
     [LevelAttribute(Level = 4)]
    public string FinanceDirectorApproval { get; set; }

    /// <summary>
    /// CEO审核
    /// </summary>
     [LevelAttribute(Level = 5)]
    public string CEOApproval { get; set; }

    /// <summary>
    /// 流水号
    /// </summary>
    public string SerialNumber { get; set; }
  }

  public class LevelAttribute : Attribute
  {
    public int Level { get; set; }
  }


var toBePaidComment = persistant.GetTobePaidRecepitComment(ArrayList.Adapter(toBePaidModel.Select(u => u.SerialNumber).ToList()));
  var specialPropertyInfo = (from property in typeof(CuriseShipSpecialPrintModel).GetProperties()
                    where property.GetCustomAttributes(typeof(LevelAttribute), false).Count() > 0
                    select property).ToList();

 toBePaidModel.ForEach((item)=>{
    ShipSpecialPrintModel temp = new ShipSpecialPrintModel()
     {
         SupplierUnderTaker = supplierUnderTaker;
         CustomerSerialNumber = item.CustomerOrderNumber;
         PayAmount = item.PayAmount;
         OpeningBank = item.PayBank;
         CollectionMonad = item.Payee;
         ResponseiblePerson = item.Creator;
         SerialNumber = item.SerialNumber;
     };
    var thisComments=toBePaidComment.Where(u=>u.SerialNumber =item.SerialNumber ).ToList();
    thisComment.ForEach((cm)=>
    {
     if(cm.ApprovalLevel==(specialPropertyInfo.GetCustomAttributes(typeof(LevelAttribute),false).First() as LevelAttribute).Level)
     {
       cm.SetValue(model,cm.Creator,null);
     } 
    });
 })
/** * 获取微信支付配置 * 这里我是把配置信息存储在数据表里,方便调用 * $param是从controller里传值过来:weixin_config_id,notify_url * @return array */public function getWechatConfig{ $weixin = WeixinConfigBaseModel::find($param['weixin_config_id']); if  { throw new Exception; } return [ 'wechat' =>[ $app_id => $weixin->appid, 'mch_id' => $weixin->mchid, 'notify_url' => empty ? '' : $param['notify_url'], //回调url 'key' => $weixin->mchkey, 'cert_client' => resource_path().'/wechat/'.$weixin->id.'/apiclient_cert.pem', //证书与key 'cert_key' => resource_path().'/wechat/'.$weixin->id.'/apiclient_key.pem', ] ];}

   
然而看到,propertyInfos那边基本上每循环一次都需要去反射查找下元素,为了避免这样的性能消耗,决定再修改一翻,定义一个字典去存储SpecialPrintModel标有特性类的字段。

财务审核,也就是微信返现到零钱,这个时候会返回成功结果,或者是各种不成功的结果

   动手操作第三版本

//财务审核if($param['status'] == 2){ //判断返现金额与修改后的金额 if($before_rebate_amount != $param['rebate_amount']){ //返现金额不相等,则出款金额改变 $out_amount = $param['rebate_amount'] - $before_rebate_amount ; $this->outMount($business->business_id,$out_amount); } if($param['rebate_status'] == 9){ //财务拒绝通过 $business->audit_status = $param['rebate_status']; $business->rebate_amount = $param['rebate_amount']; $business->status = 6; $business->save(); //生成日志 $this->insertWithdrawLog($param['withdraw_id'], $business->status, $business->audit_status, $param['rebate_remark'], $param['admin_id']); }else{ //提现的各种返回结果 $this->payReturnResult; }}

/** * Function:微信提现返回的各种结果 * Author:cyw0413 * @param $res * @param $business * @param $param */public function payReturnResult{ $input = [ 'weixin_config_id' => 20 , 'openid' => $business->business->open_id, 'amount' => $param['rebate_amount'] * 100, 'trade_no' => $business->order_sn, //商户订单号 'desc' => "微信提现" ]; $pay = new PayLogBaseService(); $res = $pay->weixinPay; if($res['result_code']=="SUCCESS"){ //提现成功 $business->audit_status = 4; $business->status = 4; $business->rebate_amount = $param['rebate_amount']; $param['rebate_remark'] = "已付款(".$param['rebate_amount'].")"; }elseif ($res['err_code'] == "MONEY_LIMIT"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,已达到付款给此用户额度上限"; //throw new Exception($param['rebate_remark']); }elseif ($res['err_code'] == "AMOUNT_LIMIT"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,低于最低付款金额或者高于最高付款金额"; //throw new Exception($param['rebate_remark']);egdf }elseif ($res['err_code'] == "NOTENOUGH"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,付款帐号余额不足或资金未到账"; //throw new Exception($param['rebate_remark']); }elseif ($res['err_code'] == "SIGN_ERROR"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,签名错误"; }elseif ($res['err_code'] == "PARAM_ERROR"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,参数错误"; }elseif ($res['err_code'] == "OPENID_ERROR"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,Openid错误"; }elseif ($res['err_code'] == "FATAL_ERROR"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,两次请求参数不一致"; }elseif ($res['err_code'] == "CA_ERROR"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,商户API证书校验出错"; }elseif ($res['err_code'] == "V2_ACCOUNT_SIMPLE_BAN"){ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,无法给非实名用户付款"; }else{ $business->audit_status = 3; $business->status = 3; $param['rebate_remark'] = "提现失败,服务器繁忙,请稍后再试"; //throw new Exception($param['rebate_remark']); } $business->save();}
Dictionary<int, PropertyInfo> dic = new Dictionary<int, PropertyInfo>();
  propertyInfos.ForEach((myProperty) => {      dic.Add((a.GetCustomAttributes(typeof(LevelAttribute),false).First() as LevelAttribute).Level,myProperty));
   } );

 comments.ForEach((cm) =>
          {
              if (dic.Keys.Contains(cm.ApprovalLevel))
              {
                dic[cm.ApprovalLevel].SetValue(model, cm.Creator, null);
              }
          });

当微信平台余额不足或者出现各种错误而提现失败的时候,这里还有支持重新付款的功能:其实就是点击按钮后重新调用付款到零钱的功能,知道成功付款

  
总体经过三次的修改,已经避免if…else的代码。这样而言,也比较适合后面比如再需要打印CTO审核的名称。那样只需要再Model类里面填写字段与在字段上加上个特效。

/** * Function:重新付款 * Author:cyw0413 * @param $param * @throws Exception */public function repay{ if{ throw new Exception; } $business = GroupBusinessWithdrawBaseModel::find($param['withdraw_id']); if{ throw new Exception; } if($business->audit_status != 3){ throw new Exception; } //提现的各种返回结果 $this->payReturnResult;}

  总结

总结

     
就像我同事说的那样,做任务事情只要想想、多敲几次。一些问题就不是问题了。好了,今天就写到这里吧。晚安各位!

以上所述是小编给大家介绍的PHP实现财务审核通过后返现金额到客户的功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

请您花一点时间将文章分享给您的朋友或者留下评论。我们将会由衷感谢您的支持!

您可能感兴趣的文章:

  • C#通过反射打开相应窗体方法分享
  • C#实现winform用子窗体刷新父窗体及子窗体改变父窗体控件值的方法
  • C#非矩形窗体实现方法
  • C#透明窗体实现方法
  • C#中WPF使用多线程调用窗体组件的方法
  • C#窗体显示留言时间的方法
  • C#入门之窗体的简单用法实例
  • C#中使用反射遍历一个对象属性及值的小技巧
  • C#中方法的直接调用、反射调用与Lambda表达式调用对比
  • C#通过反射获取当前工程中所有窗体并打开的方法
You can leave a response, or trackback from your own site.

Leave a Reply

网站地图xml地图