Files
tuiguangzhushou/application/common/service/Withdrawal.php
2020-08-06 15:26:41 +08:00

109 lines
3.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +------------------------------------------------+
// |http://www.cjango.com |
// +------------------------------------------------+
// | 修复BUG不是一朝一夕的事情等我喝醉了再说吧 |
// +------------------------------------------------+
// | Author: 小陈叔叔 <Jason.Chen> |
// +------------------------------------------------+
namespace app\common\service;
use app\common\model\Member;
use app\common\model\Withdrawal as WithdrawalModel;
use app\common\service\Wechat as WechatService;
use app\common\validate\Withdrawal as WithdrawalValidate;
use cjango\Wechat;
class Withdrawal extends _Init
{
/**
* 创建提现记录
* @param [type] $data [description]
*/
public static function create($data)
{
$data['charge'] = $data['money'] * 0.05;
$data['price'] = $data['money'] - $data['charge'];
$data['status'] = 1;
$validate = new WithdrawalValidate();
if (!$validate->check($data)) {
return $validate->getError();
}
$info = WithdrawalModel::create($data);
if ($info) {
$res = Account::rule($data['uid'], 'withdrawal', -$data['money']);
if ($res === true) {
return true;
} else {
$info->delete();
return $res;
}
} else {
return '提现失败';
}
}
/**
* [status description]
* @param [type] $id [description]
* @param [type] $status [description]
* @param [type] $type [description]
* @return [type] [description]
*/
public static function status($id, $status)
{
$list = WithdrawalModel::where('id', 'in', $id)->select();
if (empty($list)) {
return '提现信息不存在';
}
$data = [
'status' => $status,
];
$data['audit'] = UID;
foreach ($list as $key => $value) {
if ($value->status == 1 && in_array($status, [2, 3])) {
if ($status == 3) {
Account::rule($value->uid, 'rejected', $value->money);
} else {
$userinfo = Member::get($value->uid);
$remark = "会员" . $userinfo->info->nickname . '提现:' . $value->money . '元';
self::initWechat();
$result = Wechat\Pay::transfers(\tools\Str::orderid(), $userinfo->openid, $value->price, $remark);
if (!$result) {
return Wechat::error();
}
if ($userinfo->openid) {
$account = [
'openid' => $userinfo->openid,
'create_time' => date('Y-m-d'),
'increase' => (string) $value->money,
'balance' => $userinfo->account->price,
];
//加模板消息
Tmplmsg::account($account);
}
}
$value->status = $status;
$value->save();
}
}
return true;
}
/**
* 初始化微信
* @return void
*/
public static function initWechat()
{
WechatService::instance();
}
}