You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
zhishifufei_php/application/wap/model/merchant/MerchantFlowingWater.php

213 lines
10 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\wap\model\merchant;
use traits\ModelTrait;
use basic\ModelBasic;
use app\wap\model\merchant\MerchantBill;
use think\Db;
use think\Log;
/**
* Class MerchantFlowingWater
* @package app\admin\model\merchant
*/
class MerchantFlowingWater extends ModelBasic
{
use ModelTrait;
/**
* @param $order 代理分成
* @param int $type
*/
public static function setAgentFlowingWater($order, $type = 0)
{
if ($order['agent_id'] <= 0) return true;
$agent_id = $order['agent_id'];
$agent_divide = Db::name('agent_user')->where('id', $agent_id)->field('now_money,mer_special_divide,mer_store_divide,mer_event_divide,mer_data_divide,mer_test_divide')->find(); //代理分成
switch ($type) {
case 0: //课程订单
$divide = bcdiv($agent_divide['mer_special_divide'], 100, 2); //百分比
if ($divide <= 0) return true;
$agent_data['total_price'] = $order['total_price'];
$agent_data['pay_price'] = $order['pay_price'];
$agent_data['price'] = bcmul($agent_data['total_price'], $divide, 2);
$agent_title = '购买课程';
$agent_mark = $agent_title . '支付' . floatval($agent_data['pay_price']) . '元';
break;
case 2: //商品订单
$divide = bcdiv($agent_divide['mer_store_divide'], 100, 2); //百分比
if ($divide <= 0) return true;
$agent_data['total_price'] = $order['total_price'];
$agent_data['pay_price'] = $order['pay_price'];
$agent_price = bcmul($agent_data['total_price'], $divide, 2);
// $agent_data['price'] = bcadd($agent_price, $order['total_postage'], 2);
$agent_data['price'] = $agent_price;
$agent_title = '购买商品';
$agent_mark = $agent_title . '支付' . floatval($agent_data['pay_price']) . '元';
break;
case 3: //资料订单
$divide = bcdiv($agent_divide['mer_data_divide'], 100, 2); //百分比
if ($divide <= 0) return true;
$agent_data['total_price'] = $order['total_price'];
$agent_data['pay_price'] = $order['pay_price'];
$agent_data['price'] = bcmul($agent_data['total_price'], $divide, 2);
$agent_title = '购买资料';
$agent_mark = $agent_title . '支付' . floatval($agent_data['pay_price']) . '元';
break;
case 4: //报名订单
$divide = bcdiv($agent_divide['mer_event_divide'], 100, 2); //百分比
if ($divide <= 0) return true;
$agent_data['total_price'] = $order['pay_price'];
$agent_data['pay_price'] = $order['pay_price'];
$agent_data['price'] = bcmul($agent_data['total_price'], $divide, 2);
$agent_title = '活动报名';
$agent_mark = $agent_title . '支付' . floatval($agent_data['pay_price']) . '元';
break;
case 5: //试卷订单
$divide = bcdiv($agent_divide['mer_test_divide'], 100, 2); //百分比
if ($divide <= 0) return true;
$agent_data['total_price'] = $order['total_price'];
$agent_data['pay_price'] = $order['pay_price'];
$agent_data['price'] = bcmul($agent_data['total_price'], $divide, 2);
$agent_title = '购买试卷';
$agent_mark = $agent_title . '支付' . floatval($agent_data['pay_price']) . '元';
break;
}
AgentUser::beginTrans();
$agent_data['oid'] = $order['id'];
$agent_data['mer_id'] = $agent_id;
$agent_data['type'] = $type;
$agent_data['status'] = 1;
$agent_data['agent_id'] = $agent_id;
$agent_data['add_time'] = time();
$agent_price = $agent_data['price'];
if ($agent_price === "0.00") {
MerchantBill::income($agent_title, $order['id'], $agent_id, 'now_money', 'user_pay', $agent_price, bcadd($agent_divide['now_money'], $agent_price, 2), $agent_mark);
AgentUser::commitTrans();
return true;
} else {
$res3 = self::set($agent_data);
$res2 = AgentUser::setAgentUserNowMoney($agent_id, $agent_price);
if ($res3 && $res2) {
MerchantBill::income($agent_title, $order['id'], $agent_id, 'now_money', 'user_pay', $agent_price, bcadd($agent_divide['now_money'], $agent_price, 2), $agent_mark);
AgentUser::commitTrans();
return true;
} else {
AgentUser::rollbackTrans();
return false;
}
}
}
/**
* @param $order 讲师分成
* @param int $type
*/
public static function setMerchantFlowingWater($order, $type = 0)
{
if ($order['mer_id'] <= 0) return true;
$mer_id = $order['mer_id']; //讲师ID
$mer_divide = Merchant::where('id', $mer_id)->field('now_money,mer_special_divide,mer_store_divide,mer_event_divide,mer_data_divide,mer_test_divide')->find(); //讲师分成
switch ($type) {
case 0: //课程订单
$divide = bcdiv($mer_divide['mer_special_divide'], 100, 2); //百分比
if ($divide <= 0) return true;
$data['total_price'] = $order['total_price'];
$data['pay_price'] = $order['pay_price'];
$data['price'] = bcmul($data['total_price'], $divide, 2);
$title = '购买课程';
$mark = $title . '支付' . floatval($data['pay_price']) . '元';
break;
case 2: //商品订单
$divide = bcdiv($mer_divide['mer_store_divide'], 100, 2); //百分比
if ($divide <= 0) return true;
$data['total_price'] = $order['total_price'];
$data['pay_price'] = $order['pay_price'];
$price = bcmul($data['total_price'], $divide, 2);
$data['price'] = bcadd($price, $order['total_postage'], 2);
$title = '购买商品';
$mark = $title . '支付' . floatval($data['pay_price']) . '元';
break;
case 3: //资料订单
$divide = bcdiv($mer_divide['mer_data_divide'], 100, 2); //百分比
if ($divide <= 0) return true;
$data['total_price'] = $order['total_price'];
$data['pay_price'] = $order['pay_price'];
$data['price'] = bcmul($data['total_price'], $divide, 2);
$title = '购买资料';
$mark = $title . '支付' . floatval($data['pay_price']) . '元';
break;
case 4: //报名订单
$divide = bcdiv($mer_divide['mer_event_divide'], 100, 2); //百分比
if ($divide <= 0) return true;
$data['total_price'] = $order['pay_price'];
$data['pay_price'] = $order['pay_price'];
$data['price'] = bcmul($data['total_price'], $divide, 2);
$title = '活动报名';
$mark = $title . '支付' . floatval($data['pay_price']) . '元';
break;
case 5: //试卷订单
$divide = bcdiv($mer_divide['mer_test_divide'], 100, 2); //百分比
if ($divide <= 0) return true;
$data['total_price'] = $order['total_price'];
$data['pay_price'] = $order['pay_price'];
$data['price'] = bcmul($data['total_price'], $divide, 2);
$title = '购买试卷';
$mark = $title . '支付' . floatval($data['pay_price']) . '元';
break;
}
Merchant::beginTrans();
$data['oid'] = $order['id'];
$data['mer_id'] = $mer_id;
$data['type'] = $type;
$data['status'] = 1;
$data['add_time'] = time();
$price = $data['price'];
if ($price === "0.00") {
MerchantBill::income($title, $order['id'], $mer_id, 'now_money', 'user_pay', $price, bcadd($mer_divide['now_money'], $price, 2), $mark);
Merchant::commitTrans();
return true;
} else {
$res = self::set($data);
$res1 = Merchant::setMerchantNowMoney($mer_id, $price);
if ($res && $res1) {
MerchantBill::income($title, $order['id'], $mer_id, 'now_money', 'user_pay', $price, bcadd($mer_divide['now_money'], $price, 2), $mark);
Merchant::commitTrans();
return true;
} else {
Merchant::rollbackTrans();
return false;
}
}
}
/**收益统计
* @param int $mer_id
* @return mixed
*/
public static function get_merchant_data($mer_id = 0)
{
$now_day = strtotime(date('Y-m-d')); //今日
$profit = MerchantBill::where(['mer_id' => $mer_id, 'pm' => 1, 'category' => 'now_money'])->where('type', 'in', ['gold_extract', 'user_pay'])->sum('number');
$return = MerchantBill::where(['mer_id' => $mer_id, 'pm' => 0, 'category' => 'now_money'])->where('type', 'in', ['user_refund'])->sum('number');
$data['total'] = bcsub($profit, $return, 2);
$today_profit = MerchantBill::where(['mer_id' => $mer_id, 'pm' => 1, 'category' => 'now_money'])->where('add_time', 'gt', $now_day)->where('type', 'in', ['gold_extract', 'user_pay'])->sum('number');
$today_return = MerchantBill::where(['mer_id' => $mer_id, 'pm' => 0, 'category' => 'now_money'])->where('add_time', 'gt', $now_day)->where('type', 'in', ['user_refund'])->sum('number');
$data['today'] = bcsub($today_profit, $today_return, 2);
return $data;
}
}