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.
143 lines
7.5 KiB
143 lines
7.5 KiB
<?php
|
|
|
|
// +----------------------------------------------------------------------
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\wap\model\institution;
|
|
|
|
|
|
use traits\ModelTrait;
|
|
use basic\ModelBasic;
|
|
use app\wap\model\institution\InstitutionBill;
|
|
use think\Db;
|
|
use think\Log;
|
|
|
|
/**
|
|
* Class MerchantFlowingWater
|
|
* @package app\admin\model\merchant
|
|
*/
|
|
class InstitutionFlowingWater 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_uid = Db::name('institution_admin')->where('mer_id', $institution_id)->value('uid');
|
|
if ($institution_uid == $order['uid']) return true;
|
|
|
|
$institution_divide = Institution::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") {
|
|
InstitutionBill::income($institution_title, $order['id'], $institution_id, 'now_money', 'user_pay', $institution_price, bcadd($institution_divide['now_money'], $institution_price, 2), $institution_mark);
|
|
Institution::commitTrans();
|
|
return true;
|
|
} else {
|
|
$res3 = self::set($institution_data);
|
|
$res2 = Institution::setMerchantNowMoney($institution_id, $institution_price);
|
|
if ($res3 && $res2) {
|
|
InstitutionBill::income($institution_title, $order['id'], $institution_id, 'now_money', 'user_pay', $institution_price, bcadd($institution_divide['now_money'], $institution_price, 2), $institution_mark);
|
|
Institution::commitTrans();
|
|
return true;
|
|
} else {
|
|
Institution::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 = InstitutionBill::where(['mer_id' => $mer_id, 'pm' => 1, 'category' => 'now_money'])->where('type', 'in', ['gold_extract', 'user_pay'])->sum('number');
|
|
$return = InstitutionBill::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 = InstitutionBill::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 = InstitutionBill::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;
|
|
}
|
|
}
|
|
|