WokerTask/app/common/logic/finance/TownShareProfit.php

545 lines
23 KiB
PHP

<?php
namespace app\common\logic\finance;
use app\common\enum\user\AccountLogEnum;
use app\common\logic\AccountLogLogic;
use app\common\model\Company;
use app\common\model\company\CompanyAccountLog;
use app\common\model\task\Task;
use app\common\model\task_scheduling_plan\TaskSchedulingPlan;
use app\common\model\task_template\TaskTemplate;
use app\common\model\user\UserAccountLog;
use app\common\model\user\User;
use think\facade\Db;
use think\facade\Log;
class TownShareProfit
{
public function townTaskType1($taskInfo, $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function townTaskType2($taskInfo, $townCompany, $taskSchedulePlan, $step, $contractCount)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
if ($step == 2 && $contractCount >= 15) {
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function townTaskType3($taskInfo, $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function townTaskType4($taskInfo, $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function townTaskType5($taskInfo, $townCompany, $taskSchedulePlan, $leftTransactionPool)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
// 更新镇交易池
(new TaskTemplate())->updateTransactionPool($taskSchedulePlan['template_info']['id'], $leftTransactionPool);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function townTaskType6($taskInfo, $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function townTaskType7($taskInfo, $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
/**
* 分润
*/
public function shareProfit($taskInfo, $company, $taskSchedulePlan)
{
$proportion = 0;
//总金额除以2等于不可提现账号金额和收益
$masterMoney = bcdiv($taskInfo['money'], 2, 2);
$remark = '来自任务【' . $taskSchedulePlan['template_info']['title'] . '】,';
//负责人收益
if ($taskSchedulePlan['template_info']['extend']['task_role'] == 1) {
$serviceManagerUser = (new User())->searchMaster($company['id']);
Log::info([$taskSchedulePlan['template_info']['title'].'结算-市场部长用户信息', $serviceManagerUser]);
}
//市场部长收益
if ($taskSchedulePlan['template_info']['extend']['task_role'] == 2) {
$serviceManagerUser = (new User())->searchMarketingManager($company['id']);;
Log::info([$taskSchedulePlan['template_info']['title'].'结算-市场部长用户信息', $serviceManagerUser]);
}
//服务部长收益 任务金额的50%为服务部长的收益
if ($taskSchedulePlan['template_info']['extend']['task_role'] == 3) {
$serviceManagerUser = (new User())->searchServiceManager($company['id']);;
Log::info([$taskSchedulePlan['template_info']['title'].'结算-服务部长用户信息', $serviceManagerUser]);
}
// 用户收益变动
$arr = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASK, AccountLogEnum::INC, $masterMoney, $taskSchedulePlan['sn'], $remark.'任务结算获得收益' . $masterMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1];
$this->master($arr);
// 用户余额变动
$arr_two = [$serviceManagerUser['id'], AccountLogEnum::UM_INC_TASKUSER, AccountLogEnum::INC, $masterMoney, $taskSchedulePlan['sn'], $remark . '获得账户余额' . $masterMoney . '元', ['company_id' => $company['id'], 'proportion' => $proportion], 1];
$this->Account($arr_two);
// 公司收益
$deposit_count = bcadd($company['deposit'], $masterMoney, 2);
// 公司收益变动记录
$this->AccountLog($company['id'], $deposit_count, $masterMoney, 1, CompanyAccountLog::TASK_INC_INCOME);
$company_money_count = bcadd($company['company_money'], $masterMoney, 2);
//公司余额变动记录
$this->AccountLog($company['id'], $company_money_count, $masterMoney, 1, CompanyAccountLog::TASK_INC_COMPANY_MONEY);
// 变更公司收益和余额
Company::where('id', $company['id'])->update(['deposit' => Db::raw('deposit+' . $masterMoney), 'company_money' => Db::raw('company_money+' . $masterMoney)]);
}
public function AccountLog($companyId, $left_amount, $changeAmount, $change_object = 1, $change_type = 1, $action = 1)
{
$company_log = [
'sn' => generate_sn(UserAccountLog::class, 'sn', 20),
'company_id' => $companyId,
'change_object' => $change_object, //变动对象
'change_type' => $change_type, //变动类型
'action' => $action, //1-增加 2-减少
'left_amount' => $left_amount, //变动后数量
'change_amount' => $changeAmount, //变动数量
'status' => 1,
];
CompanyAccountLog::create($company_log);
}
/**负责人的分润
* @param $data
*/
private function master($data)
{
User::where('id', $data[0])->update(['deposit'=>Db::raw('deposit+' . $data[3]),'user_money'=>Db::raw('user_money+' . $data[3])]);
return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]);
}
/**成员分润
* @param $data
*/
private function member($data)
{
User::where('id', $data[0])->update(['deposit'=>Db::raw('deposit+' . $data[3]),'user_money'=>Db::raw('user_money+' . $data[3])]);
return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]);
}
private function Account($data)
{
return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]);
}
/**
*
*/
public function dealTaskSettlementMarketingDirector1($taskInfo, $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMarketingDirector2(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMarketingDirector3(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMarketingDirector4(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMarketingDirector5(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMarketingDirector6(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMarketingDirector7(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getFile(). $e->getLine(). $e->getMessage());
return false;
}
}
public function dealTaskSettlementMarketingDirector8(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMarketingDirector9(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMarketingDirector10(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMaster2(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMaster3(Task $taskInfo, Company $townCompany, $taskSchedulePlan, $leftTransactionPool)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
// 更新交易池
(new TaskTemplate())->updateTransactionPool($taskSchedulePlan['template_info']['id'], $leftTransactionPool);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMaster4(Task $taskInfo, Company $townCompany, $taskSchedulePlan, $leftTransactionPool)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
// 更新交易池
(new TaskTemplate())->updateTransactionPool($taskSchedulePlan['template_info']['id'], $leftTransactionPool);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMaster5(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMaster6(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMaster7(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMaster8(Task $taskInfo, Company $townCompany, $taskSchedulePlan)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
}