镇管理公司任务-小组服务公司上交股金接口

This commit is contained in:
chenbo 2023-09-23 14:19:51 +08:00
parent 0e5697f454
commit dabac037c4

View File

@ -5,9 +5,12 @@ namespace app\api\controller;
use app\common\logic\contract\ContractLogic;
use app\common\model\auth\Admin;
use app\common\model\Company;
use app\common\model\company\CompanyAccountLog;
use app\common\model\contract\Contract;
use app\common\model\task\Task;
use app\common\model\user\User;
use app\common\model\user\UserAccountLog;
use think\Exception;
use think\facade\Db;
use app\common\model\informationg\UserInformationg;
use app\common\model\informationg\UserInformationgDemand;
@ -201,7 +204,7 @@ class CompanyController extends BaseApiController
public function shareholder_info()
{
// $params = $this->request->param();
$find = Company::where('id', $this->userInfo['company_id'])->field('shareholder_money,village')->find()->toArray();
$find = Company::where('id', $this->userInfo['company_id'])->field('id,shareholder_money,village')->find()->toArray();
$find['is_contract'] = 0;
$find['check_status'] = 0;
if ($find) {
@ -227,10 +230,17 @@ class CompanyController extends BaseApiController
} else {
$find['is_village'] = 0;
}
// 股金任务是否完成
$task = Task::where(['company_id' => $find['id'], 'type' => 35, 'status' => 3])->find();
$find['is_done_task'] = 0;
if (!empty($task)) {
$find['is_done_task'] = 1;
}
} else {
$find['contract_url'] = '';
$find['contract_time'] = '';
$find['is_village'] = 0;
$find['is_done_task'] = 0;
}
return $this->success('ok', $find);
}
@ -262,8 +272,75 @@ class CompanyController extends BaseApiController
}
return $this->fail(ContractLogic::getError());
}
/**
* 小组服务公司股金上交
*/
public function pay_share_capital()
{
// return
try {
$param = $this->request->param();
// 上交股金金额
$amount = $param['amount'];
// 小组服务公司
$serviceGroupCompany = Company::where('id', $this->userInfo['company_id'])->find()->toArray();
if ($amount < 0) {
$this->fail('参数错误,金额不能为负数');
}
if ($amount > $serviceGroupCompany['shareholder_money']) {
$this->fail('公司股东金额不足以抵扣上交股金金额');
}
// 村管理公司
$villageCompany = Company::where(['village'=>$serviceGroupCompany['village'], 'company_type' => 17])->find()->toArray();
Db::startTrans();
$sharecapitalChangeLogData = [
'subordinate_company_id' => $serviceGroupCompany['id'],
'parent_company_id' => $villageCompany['id'],
'amount' => $amount
];
$sharecapitalChangeLogInsertId = Db::name('company_sharecapital_change_log')->insertGetId($sharecapitalChangeLogData);
// 小组服务公司股金变动 + 公司股金减少记录
$leftAmount = bcsub($serviceGroupCompany['shareholder_money'], $amount, 2);
Company::where('id', $this->userInfo['company_id'])->save('shareholder_money', $leftAmount);
$company_log1 = [
'sn' => generate_sn(UserAccountLog::class, 'sn', 20),
'company_id' => $serviceGroupCompany['id'],
'change_object' => 2, // 变动对象 1余额 2股金
'change_type' => CompanyAccountLog::SHAREHOLDER_DEC_DEPOSIT, //变动类型
'action' => 2, //1-增加 2-减少
'left_amount' => $leftAmount, //变动后数量
'change_amount' => $amount, //变动数量
'extend' => json_encode(['company_sharecapital_change_log_id' => $sharecapitalChangeLogInsertId]),
'status' => 1,
];
CompanyAccountLog::create($company_log1);
// 村管理公司股金变动 + 公司股金增加记录
$addAmount = bcadd($villageCompany['shareholder_money'], $amount, 2);
Company::where('id', $villageCompany['id'])->save('shareholder_money', $addAmount);
// 公司账户变动记录
$company_log2 = [
'sn' => generate_sn(UserAccountLog::class, 'sn', 20),
'company_id' => $villageCompany['id'],
'change_object' => 2, // 变动对象 1余额 2股金
'change_type' => CompanyAccountLog::TASK_INC_SHAREHOLDER_MONEY, //变动类型
'action' => 1, //1-增加 2-减少
'left_amount' => $addAmount, //变动后数量
'change_amount' => $amount, //变动数量
'extend' => json_encode(['company_sharecapital_change_log_id' => $sharecapitalChangeLogInsertId]),
'status' => 1,
];
CompanyAccountLog::create($company_log2);
Db::commit();
return $this->success('上交成功');
} catch (Exception $e) {
Db::rolback();
return $this->fail($e->getMessage());
}
}
}