158 lines
6.1 KiB
PHP
158 lines
6.1 KiB
PHP
<?php
|
|
/**
|
|
* SAAS应用系统 --- 十年开发经验汇集巨献!
|
|
* ==========================================================
|
|
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
|
|
* ----------------------------------------------------------
|
|
* 官方网址: https://www.zoomtk.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人未经允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
|
|
* ==========================================================
|
|
*/
|
|
namespace addon\dividemoney\model;
|
|
use app\model\BaseModel;
|
|
use app\model\system\Cron;
|
|
use app\model\system\Pay;
|
|
use app\model\system\User;
|
|
use think\facade\Cache;
|
|
use think\facade\Db;
|
|
class OrderCreate extends BaseModel
|
|
{
|
|
// 订单待支付
|
|
const ORDER_CREATE = 0;
|
|
// 订单已支付
|
|
const ORDER_PAY = 1;
|
|
// 订单已关闭
|
|
const ORDER_CLOSE = -1;
|
|
|
|
/***
|
|
* 创建充值订单
|
|
* @param $pay_money
|
|
* @param $site_id 站点ID
|
|
* @param $default_site_id //平台收款站点ID
|
|
* @return array|mixed|string|void
|
|
*/
|
|
public function OrderCreate($pay_money, $site_id, $default_site_id)
|
|
{
|
|
$pay = new Pay();
|
|
$order_name = '技术服务费';
|
|
$pay_type = 'alipay';//支付方式
|
|
$app_type = 'cashier'; //扫码支付
|
|
$out_trade_no = $pay->createOutTradeNo($site_id);
|
|
$pay_detail = $default_site_id . '_' . $site_id;
|
|
$pay->addPay($default_site_id, $out_trade_no, $pay_type, $order_name, $pay_detail, $pay_money, '', 'DividemoneyOrderPayNotify', '', '');
|
|
$notify_url = addon_url("pay/pay/notify/paytype/" . $pay_type . '/app_type/' . $app_type . '/site_id/' . $default_site_id);
|
|
$return_url = addon_url("pay/pay/payreturn", ['out_trade_no' => $out_trade_no, 'app_type' => $app_type]);
|
|
$data['site_id'] = $default_site_id;
|
|
$data['out_trade_no'] = $out_trade_no;
|
|
$data['pay_money'] = $pay_money;
|
|
$data['app_type'] = $app_type;
|
|
$data['pay_body'] = $order_name;
|
|
$data['notify_url'] = $notify_url;
|
|
$data['return_url'] = $return_url;
|
|
$data['pay_type'] = $pay_type;
|
|
$data["member_id"] = $site_id;
|
|
$data["is_matched"] = 0;
|
|
$data["hb_fq_num"] = 0;
|
|
$res = event('Pay', $data, true);
|
|
$res['data']['out_trade_no'] = $out_trade_no;
|
|
return $res;
|
|
}
|
|
|
|
|
|
/***
|
|
* 商家主动支付佣金回调
|
|
* @param $data
|
|
* @return array
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function OrderPay($data)
|
|
{
|
|
if (isset($data['payInfo'])) {
|
|
$payInfo = $data['payInfo'];
|
|
list($p_site_id, $site_id) = explode('_', $payInfo['pay_detail']);
|
|
$startTime = mktime(0, 0, 0, date('m'), date('d') - 15, date('Y'));
|
|
$failWhere = [
|
|
['site_id', '=', $site_id],
|
|
['is_order_account_locking', '=', 0],
|
|
['states', 'in', [0, 2, 3]],
|
|
['create_time', '<', $startTime]
|
|
];
|
|
$res = Db::name('dividemoney_bill')->where($failWhere)
|
|
->group('account')
|
|
->field('sum(amount) as amount,ag_site_id,channel_type,account')
|
|
->select();
|
|
if ($res->toArray()) {
|
|
$log = [];
|
|
foreach ($res as $item) {
|
|
$log[] = [
|
|
'site_id' => $site_id,
|
|
'agent_site_id' => $item['ag_site_id'],
|
|
'commission_money' => $item['amount'],
|
|
'channel_type' => $item['channel_type'],
|
|
'account' => $item['account'],
|
|
'create_time' => time(),
|
|
'update_time' => time(),
|
|
'remarks' => '商家主动结算佣金',
|
|
];
|
|
}
|
|
$user_model = new User();
|
|
$update = [
|
|
'states' => 1,
|
|
'refuse' => '商户主动结算',
|
|
'is_order_account_locking' => 1,
|
|
'sub_code' => '',
|
|
];
|
|
model('website_commission')->addList($log);
|
|
model('dividemoney_bill')->update($update, $failWhere);
|
|
$cron = new Cron();
|
|
$cron->addCron(1, 1, '解除货款结算限制', 'SecureCronOrderDividemoney', time(), $site_id);
|
|
cache('alipayTradeBatchquery' . $site_id, null);
|
|
cache('is_pay_error' . $site_id, null);
|
|
$user_info = $user_model->userInfo('shop');
|
|
if (empty($user_info)) {
|
|
$user_info = model('site')->getInfo(['site_id' => $site_id], 'site_id as uid,username');
|
|
}
|
|
$user_model->addUserLog($user_info['uid'] ?: $site_id, $user_info['username'] ?: $site_id, $site_id, "商户主动支付服务佣金{$payInfo['pay_money']}元", []); //添加日志
|
|
return $this->success('结算成功');
|
|
} else {
|
|
return $this->success('结算成功');
|
|
}
|
|
}
|
|
return $this->error('无效订单');
|
|
}
|
|
|
|
/***
|
|
* 充值
|
|
* @param $pay_money
|
|
* @param $member_id
|
|
* @param $site_id
|
|
* @return void
|
|
*/
|
|
public function rechargeOrderCreate($pay_money, $member_id, $site_id = 1)
|
|
{
|
|
return $this->success('未使用');
|
|
}
|
|
|
|
/**
|
|
* 生成订单编号
|
|
* @param array $site_id
|
|
*/
|
|
public function createOrderNo($site_id, $member_id = 0)
|
|
{
|
|
$time_str = date('YmdHi');
|
|
$max_no = Cache::get($site_id . "_" . $member_id . "_" . $time_str);
|
|
if (!isset($max_no) || empty($max_no)) {
|
|
$max_no = 1;
|
|
} else {
|
|
$max_no = $max_no + 1;
|
|
}
|
|
$order_no = $time_str . $member_id . sprintf("%03d", $max_no);
|
|
Cache::set($site_id . "_" . $member_id . "_" . $time_str, $max_no);
|
|
return $order_no;
|
|
}
|
|
}
|