文件
mashangyoujiu/Application/NotifyApi/Controller/DistributionController.class.php

142 行
5.2 KiB
PHP
可执行文件

<?php
namespace NotifyApi\Controller;
use Common\Business\CacheHandle;
use Common\Model\RemitRecordModel;
use Common\Model\RetailSellModel;
use Distribution\Model\WithdrawalModel;
use Distribution\Model\DistributorModel;
use Distribution\Api\AutoSettlement;
use Distribution\Model\OrderModel;
use Distribution\Model\SellModel;
use Think\Controller;
//[1.7.74]
/**
* 分销自动更新数据
* Class DistributionController
* @package NotifyApi\Controller
*/
class DistributionController extends Controller
{
/**
* 查询提现打款处理中的订单是否打款成功,成功则更新状态
* @return string
*/
public function updateWithdrawalState()
{
$WithDrawModel = new WithdrawalModel();
$RemitRecordModel = new RemitRecordModel();
$map = array(
'state' => 2,
'status' => array('in', '1,2'),
'add_time' => array('lt', time()),
);
$data = $WithDrawModel->getSelect($map, 'id,remit_record_id');
foreach ($data as $val) {
$result = $WithDrawModel->getOrderStatus($val['id']);
switch ($result) {
case 1:
$WithDrawModel->updateOrder(['id' => $val['id']], ['state' => '1']);
$RemitRecordModel->updateOrder(['id' => $val['remit_record_id']], ['order_state' => 'SUCCESS']);
break;
case 2:
$WithDrawModel->updateOrder(['id' => $val['id']], ['state' => '0']);
$RemitRecordModel->updateOrder(['id' => $val['remit_record_id']], ['order_state' => 'FAILED']);
break;
case 3:
// $WithDrawModel->updateOrder(['id' => $val['id']], ['state' => '2']);
// $RemitRecordModel->updateOrder(['id' => $val['remit_record_id']], ['order_state' => 'PROCESSING']);
break;
case 0:
break;
}
}
}
/**
* 分销订单自动结算
*/
public function autoSettlement()
{
$Order = new AutoSettlement();
$time = date("Y_m_d", time());
$CacheHandle = new CacheHandle();
// 获取是否存在缓存,防止重复点击
$hasSetRedis = $CacheHandle->getSingleCache('auto_settlement_' . $time);
if ($hasSetRedis) {
return true;
}
// 添加redis
$CacheHandle->addTimeCache('auto_settlement_' . $time, 300, 1);
$Order->getPlugMerchant(); // 结算
}
/**
* 分销员自动升级
*/
public function autoUpgrade()
{
$DistributorModel = new DistributorModel();
$DistributorModel->userUpgrade(); // 升级
}
/**
* 分销sell表数据
*/
public function updateSellInfo()
{
$SellModel = new SellModel();
$RetailSellModel = new RetailSellModel();
$DistributionOrderModel = new OrderModel();
$orderList = $DistributionOrderModel->getSelect(['id' => ['gt', 0]]);
foreach ($orderList as $value) {
if ($value['dis_str_id']) {
$sell_id = $RetailSellModel->getFindField(['bill_id' => $value['bill_id']], 'id');
$newSellData = [
'bill_id' => $value['bill_id'], //订单id
'sell_id' => $sell_id, //retail_sell的id
'settled_id' => $value['id'], //分销订单id
'dis_goods_id' => $value['dis_str_id'], //分销商品ID
'sell_first_money' => $value['sell_first_money'], //订单一级佣金
'sell_second_money' => $value['sell_second_money'], //订单二级佣金
'first_refund_money' => $value['first_refund_money'], //一级佣金被退金额
'second_refund_money' => $value['second_refund_money'], //二级佣金被退金额
'first_balance_rate' => $value['first_balance_rate'], //一级佣金比
'second_balance_rate' => $value['second_balance_rate'], //二级佣金比
'total_amount' => $value['total_amount'], //总金额
];
$SellModel->addOrder($newSellData);
}
}
}
/**
* 修正分销员可提现金额
*/
public function correctionMoney()
{
$DistributorModel = new DistributorModel();
$WithDrawModel = new WithdrawalModel();
$distriMap = [
'status' => 0,
'total_commission' => ['gt', 0],
];
$distributorList = $DistributorModel->getSelect($distriMap, 'id,total_commission');
foreach ($distributorList as $val) {
$totalWithMoney = $WithDrawModel->getSum(['distributor_id' => $val['id']], 'withdrawal_money');
$realCommision = bcsub($val['total_commission'], $totalWithMoney, 2);
if ($realCommision > 0) {
$DistributorModel->updateOrder(['id' => $val['id']], ['settable_amount' => $realCommision]);
}
}
echo '分销员可提现金额更新完成';
}
}