# 进阶篇十一 逻辑层的应用
代码示例
![](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);
}
}
}
~~~