vr-shopxo-source/app/service/PayLogService.php

294 lines
11 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://opensource.org/licenses/mit-license.php )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\service;
use think\facade\Db;
/**
* 支付日志服务层
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class PayLogService
{
/**
* 支付日志添加
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @datetime 2019-05-07T00:57:36+0800
* @param [array] $params [输入参数]
* @param [int] $user_id [用户id]
* @param [int] $business_ids [业务订单id]
* @param [float] $total_price [业务订单实际金额]
* @param [string] $subject [业务订单名称]
* @param [string] $business_type [业务类型,字符串(如:订单、钱包充值、会员购买、等...]
* @return [boolean] [成功true, 失败false]
*/
public static function PayLogInsert($params = [])
{
// 请求参数
$p = [
[
'checked_type' => 'empty',
'key_name' => 'business_ids',
'error_msg' => '业务id为空',
],
[
'checked_type' => 'is_array',
'key_name' => 'business_ids',
'error_msg' => '业务id数据类型有误',
],
[
'checked_type' => 'empty',
'key_name' => 'user_id',
'error_msg' => '用户id为空',
],
[
'checked_type' => 'empty',
'key_name' => 'business_type',
'error_msg' => '业务类型为空',
],
[
'checked_type' => 'isset',
'key_name' => 'total_price',
'error_msg' => '业务金额为空',
],
];
$ret = ParamsChecked($params, $p);
if($ret !== true)
{
return DataReturn($ret, -1);
}
// 业务id
if(empty($params['business_ids']))
{
return DataReturn('业务id为空', -1);
}
// 日志主数据
$data = [
'log_no' => date('YmdHis').GetNumberCode(6),
'user_id' => intval($params['user_id']),
'total_price' => PriceNumberFormat($params['total_price']),
'business_type' => trim($params['business_type']),
'subject' => isset($params['subject']) ? $params['subject'] : '',
'payment' => isset($params['payment']) ? $params['payment'] : '',
'payment_name' => isset($params['payment_name']) ? $params['payment_name'] : '',
'add_time' => time(),
];
$pay_log_id = Db::name('PayLog')->insertGetId($data);
if($pay_log_id > 0)
{
$business_nos = isset($params['business_nos']) && is_array($params['business_nos']) ? $params['business_nos'] : [];
$value_data = [];
foreach($params['business_ids'] as $bk=>$bv)
{
$value_data[] = [
'pay_log_id' => $pay_log_id,
'business_id' => $bv,
'business_no' => isset($business_nos[$bk]) ? trim($business_nos[$bk]) : '',
'add_time' => time(),
];
}
$res = Db::name('PayLogValue')->insertAll($value_data);
if($res >= count($params['business_ids']))
{
// 日志 id 加入数组中
$data['id'] = $pay_log_id;
// 支付日志添加成功钩子
$hook_name = 'plugins_service_paylog_insert_success';
$ret = EventReturnHandle(