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.
282 lines
14 KiB
282 lines
14 KiB
<?php
|
|
|
|
// +----------------------------------------------------------------------
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\web\model\merchant;
|
|
|
|
|
|
use traits\ModelTrait;
|
|
use basic\ModelBasic;
|
|
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 setInstitutionFlowingWater($order, $type = 0)
|
|
{
|
|
if ($order['mer_id'] <= 0) return true;
|
|
$mer_id = $order['mer_id']; //讲师ID
|
|
// 查询机构
|
|
$institution_id = Db::name('lecturer')->where('mer_id', $mer_id)->value('agent');
|
|
if ($institution_id <= 0) return true;
|
|
$institution_divide = Merchant::where('id', $institution_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($institution_divide['mer_special_divide'], 100, 2); //百分比
|
|
if ($divide <= 0) return true;
|
|
$institution_data['total_price'] = $order['total_price'];
|
|
$institution_data['pay_price'] = $order['pay_price'];
|
|
$institution_data['price'] = bcmul($institution_data['total_price'], $divide, 2);
|
|
$institution_title = '购买课程';
|
|
$institution_mark = $institution_title . '支付' . floatval($institution_data['pay_price']) . '元';
|
|
break;
|
|
case 2: //商品订单
|
|
$divide = bcdiv($institution_divide['mer_store_divide'], 100, 2); //百分比
|
|
if ($divide <= 0) return true;
|
|
$institution_data['total_price'] = $order['total_price'];
|
|
$institution_data['pay_price'] = $order['pay_price'];
|
|
|
|
$institution_price = bcmul($institution_data['total_price'], $divide, 2);
|
|
// $agent_data['price'] = bcadd($agent_price, $order['total_postage'], 2);
|
|
$agent_data['price'] = $institution_price;
|
|
Log::error("机构分成");
|
|
Log::error($institution_price);
|
|
$institution_price = bcmul($institution_data['total_price'], $divide, 2);
|
|
// $institution_data['price'] = bcadd($institution_price, $order['total_postage'], 2);
|
|
$institution_data['price'] =$institution_price;
|
|
$institution_title = '购买商品';
|
|
$institution_mark = $institution_title . '支付' . floatval($institution_data['pay_price']) . '元';
|
|
break;
|
|
case 3: //资料订单
|
|
$divide = bcdiv($institution_divide['mer_data_divide'], 100, 2); //百分比
|
|
if ($divide <= 0) return true;
|
|
$institution_data['total_price'] = $order['total_price'];
|
|
$institution_data['pay_price'] = $order['pay_price'];
|
|
$institution_data['price'] = bcmul($institution_data['total_price'], $divide, 2);
|
|
$institution_title = '购买资料';
|
|
$institution_mark = $institution_title . '支付' . floatval($institution_data['pay_price']) . '元';
|
|
break;
|
|
case 4: //报名订单
|
|
$divide = bcdiv($institution_divide['mer_event_divide'], 100, 2); //百分比
|
|
if ($divide <= 0) return true;
|
|
$institution_data['total_price'] = $order['pay_price'];
|
|
$institution_data['pay_price'] = $order['pay_price'];
|
|
$institution_data['price'] = bcmul($institution_data['total_price'], $divide, 2);
|
|
$institution_title = '活动报名';
|
|
$institution_mark = $institution_title . '支付' . floatval($institution_data['pay_price']) . '元';
|
|
break;
|
|
case 5: //试卷订单
|
|
$divide = bcdiv($institution_divide['mer_test_divide'], 100, 2); //百分比
|
|
if ($divide <= 0) return true;
|
|
$institution_data['total_price'] = $order['total_price'];
|
|
$institution_data['pay_price'] = $order['pay_price'];
|
|
$institution_data['price'] = bcmul($institution_data['total_price'], $divide, 2);
|
|
$institution_title = '购买试卷';
|
|
$institution_mark = $institution_title . '支付' . floatval($institution_data['pay_price']) . '元';
|
|
break;
|
|
}
|
|
|
|
// 机构
|
|
$institution_data['oid'] = $order['id'];
|
|
$institution_data['mer_id'] = $institution_id;
|
|
$institution_data['type'] = $type;
|
|
$institution_data['status'] = 1;
|
|
$institution_data['add_time'] = time();
|
|
$institution_price = $institution_data['price'];
|
|
|
|
if ($institution_price === "0.00") {
|
|
MerchantBill::income($institution_title, $order['id'], $institution_id, 'now_money', 'user_pay', $institution_price, bcadd($institution_divide['now_money'], $institution_price, 2), $institution_mark);
|
|
Merchant::commitTrans();
|
|
return true;
|
|
} else {
|
|
$res3 = self::set($institution_data);
|
|
$res2 = Merchant::setMerchantNowMoney($institution_id, $institution_price);
|
|
if ($res3 && $res2) {
|
|
MerchantBill::income($institution_title, $order['id'], $institution_id, 'now_money', 'user_pay', $institution_price, bcadd($institution_divide['now_money'], $institution_price, 2), $institution_mark);
|
|
Merchant::commitTrans();
|
|
return true;
|
|
} else {
|
|
Merchant::rollbackTrans();
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* @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'];
|
|
$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;
|
|
}
|
|
}
|
|
|
|
}
|
|
|