php逻辑层例子,进阶篇十一 逻辑层的应用

# 进阶篇十一 逻辑层的应用

代码示例

![](https://box.kancloud.cn/c6e0e6dc2620a3f71e85b4b6ac513e07_338x530.png)

~~~

/**

* Created by PhpStorm.

* User: Mikkle

* QQ:776329498

* Date: 2018/5/25

* Time: 18:00

*/

namespace app\base\logic\weixin;

use app\base\base\LogicBase;

use app\base\options\Fields;

use app\base\options\Tables;

use app\base\service\AuthCenter;

use app\base\service\BalanceCenter;

use mikkle\tp_tools\ShowCode;

use think\Db;

class Finance extends LogicBase

{

public function _initialize()

{

// TODO: Implement _initialize() method.

}

public function vendorTransfer($data){

$this->args = $data;

$this->functionName = __FUNCTION__;

$fieldList = [Fields::$systemId,"out_".Fields::$vendorId,"in_".Fields::$vendorId,Fields::$amount,];

if (!$this->checkArrayValueStatus($data,$fieldList) ){

return ShowCode::jsonCodeWithoutData(1003,$this->error);

}

if (!AuthCenter::authSystemId($data[Fields::$systemId]) ){

$this->addError("平台账号账号错误");

return ShowCode::jsonCodeWithoutData(1003,$this->error);

}

if ( !AuthCenter::authVendorIdAttachSystem ("out_".$data[Fields::$vendorId] , $data[Fields::$systemId]) || !AuthCenter::authVendorIdAttachSystem ("in_".$data[Fields::$vendorId] , $data[Fields::$systemId]) ){

$this->addError("出款或入款商户号错误账号错误");

return ShowCode::jsonCodeWithoutData(1003,$this->error);

}

if (!is_numeric($data[Fields::$amount] ) || $data[Fields::$amount]<=0){

$this->addError("转账金额只能为数字");

return ShowCode::jsonCodeWithoutData(1003,$this->error);

}

$balanceCenter = BalanceCenter::instance( $data["out_vendor_id"]);

if ( $balanceCenter->vendorTransfer($data["in_vendor_id"], $data[Fields::$amount])){

return ShowCode::jsonCode(1001);

}else{

return ShowCode::jsonCode(1008,$balanceCenter->getError());

}

}

public function wxPayToUser($data){

$this->args = $data;

$this->functionName = __FUNCTION__;

$fieldList = [Fields::$systemId,Fields::$vendorId,Fields::$amount,Fields::$openid];

if (!$this->checkArrayValueStatus($data,$fieldList) ){

return ShowCode::jsonCodeWithoutData(1003,$this->error);

}

if (!AuthCenter::authSystemId($data[Fields::$systemId]) ){

$this->addError("平台账号账号错误");

return ShowCode::jsonCodeWithoutData(1003,$this->error);

}

if ( !AuthCenter::authVendorIdAttachSystem ($data[Fields::$vendorId] , $data[Fields::$systemId]) ){

$this->addError("出款或入款商户号错误账号错误");

return ShowCode::jsonCodeWithoutData(1003,$this->error);

}

if (!is_numeric($data[Fields::$amount] ) || $data[Fields::$amount]<100){

$this->addError("付款金额只能为数字,并且不能小于100分");

return ShowCode::jsonCodeWithoutData(1003,$this->error);

}

$balanceCenter = BalanceCenter::instance( $data[Fields::$vendorId]);

if ( $balanceCenter->wxPayToUser($data)){

return ShowCode::jsonCode(1001);

}else{

return ShowCode::jsonCodeWithoutData(1008,$balanceCenter->getError());

}

}

public function vendorAmount($data){

$this->args = $data;

$this->functionName = __FUNCTION__;

$fieldList = [Fields::$systemId,Fields::$vendorId];

if (!$this->checkArrayValueStatus($data,$fieldList) ){

return ShowCode::jsonCodeWithoutData(1003,$this->error);

}

if ( !AuthCenter::authVendorIdAttachSystem ($data[Fields::$vendorId] , $data[Fields::$systemId]) ){

$this->addError("出款或入款商户号错误账号错误");

return ShowCode::jsonCodeWithoutData(1003,$this->error);

}

$vendorInfo = Db::table(Tables::$paymentSystemVendor)

->where([Fields::$vendorId =>$data[Fields::$vendorId],Fields::$status=>1])

->field([Fields::$systemId,Fields::$vendorId,Fields::$vendorName,Fields::$vendorAmount,Fields::$vendorAmountVersion])->find();

if ( $vendorInfo ){

return ShowCode::jsonCode(1001, $vendorInfo);

}else{

return ShowCode::jsonCodeWithoutData(1010);

}

}

}

~~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值