390 lines
18 KiB
PHP
390 lines
18 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\logic\CompanyLogic;
|
|
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\CompanyDepositVoucher;
|
|
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;
|
|
|
|
/**
|
|
* Class CompanyController
|
|
* @package app\api\controller
|
|
*/
|
|
class CompanyController extends BaseApiController
|
|
{
|
|
public array $notNeedLogin = ['street_company'];
|
|
|
|
|
|
//**签约公司*/
|
|
public function index()
|
|
{
|
|
[$page, $limit] = $this->getPage();
|
|
$myCompany = Company::findOrEmpty($this->userInfo['company_id'])->toArray();
|
|
$companyIds = Contract::where('party_a', $myCompany['id'])->column('party_b');
|
|
$query = Company::whereIn('id', $companyIds)->where('status', 1)->append(['province_name', 'city_name', 'area_name', 'street_name', 'village_name', 'brigade_name', 'area_manager_name']);
|
|
$count = $query->count();
|
|
$companies = $query->page($page)->limit($limit)->select()->each(function ($company) {
|
|
$company['other_contacts'] = json_decode($company['other_contacts'], true);
|
|
$company['qualification'] = $company['qualification'] != null ? json_decode($company['qualification'], true) : '';
|
|
$company['company_type_name'] = Db::name('dict_data')->where('id', $company['company_type'])->value('name');
|
|
})->toArray();
|
|
return $this->success('', ['count' => $count, 'data' => $companies]);
|
|
}
|
|
|
|
/**
|
|
* 未签约
|
|
*/
|
|
public function unsigned()
|
|
{
|
|
$myCompany = Company::findOrEmpty($this->userInfo['company_id'])->toArray();
|
|
$query = Company::where(['street' => $myCompany['street'], 'company_type' => [17, 18], 'is_contract' => 0])->where('id', '<>', $this->userInfo['company_id']);
|
|
$count = $query->count();
|
|
$companies = $query->field('*,street street_name,area area_name,city city_name,province province_name,village village_name,brigade brigade_name')->select()->toArray();
|
|
return $this->success('', ['count' => $count, 'data' => $companies]);
|
|
}
|
|
|
|
public function view()
|
|
{
|
|
$id = $this->request->param('id', 0);
|
|
if (empty($id)) {
|
|
$query = Company::find($this->userInfo['company_id']);
|
|
} else {
|
|
$query = Company::find($id);
|
|
}
|
|
if (!$query) {
|
|
return $this->fail('公司不存在');
|
|
}
|
|
$company = $query->append(['province_name', 'city_name', 'area_name', 'street_name', 'area_manager_name', 'village_name', 'brigade_name'])->toArray();
|
|
$company['other_contacts'] = json_decode($company['other_contacts'], true);
|
|
$company['qualification'] = $company['qualification'] != null ? json_decode($company['qualification'], true) : '';
|
|
if ($company['qualification'] && isset($company['qualification']['other_qualifications'])) {
|
|
$company['qualification']['other_qualifications'] = json_decode($company['qualification']['other_qualifications'], true);
|
|
}
|
|
$contract = Contract::where('party_b', $id)->find();
|
|
if (!empty($contract)) {
|
|
if ($contract['type'] == 2) {
|
|
$contract['party_b_name'] = User::where('id', $contract['party_b'])->value('nickname');
|
|
} else {
|
|
$contract['party_b_name'] = Db::name('company')->where('id', $contract['party_b'])->value('company_name');
|
|
}
|
|
$contract['party_a_name'] = Db::name('company')->where('id', $contract['party_a'])->value('company_name');
|
|
|
|
$contract['contract_type_name'] = Db::name('dict_data')->where('id', $contract['contract_type'])->value('name');
|
|
}
|
|
$company['company_type_name'] = Db::name('dict_data')->where('id', $company['company_type'])->value('name');
|
|
$company['day_money_count'] = UserAccountLog::where(['company_id' => $company['id'], 'action' => 1])->whereDay('create_time')->sum('change_amount');
|
|
// $users = Admin::where('id', $company['admin_id'])->field('id,name,account,phone,qualification')->select()->toArray();
|
|
// foreach ($users as &$user) {
|
|
// $user['is_main'] = $user['id'] == $company['admin_id'] ? 1 : 0;
|
|
// $user['qualification'] = $user['qualification'] != null ? json_decode($user['qualification'], true) : [];
|
|
// unset($user['role_id'], $user['dept_id'], $user['jobs_id'], $user['id']);
|
|
// }
|
|
return $this->success('success', ['contract' => $contract ?? [], 'company' => $company]);
|
|
}
|
|
|
|
public function areaManager()
|
|
{
|
|
[$page, $limit] = $this->getPage();
|
|
$company = Company::find($this->userInfo['company_id']);
|
|
$query = Admin::where('id', $company['area_manager']);
|
|
$count = $query->count();
|
|
$data = $query->page($page)->limit($limit)->append(['province_name', 'city_name', 'area_name', 'street_name'])->field('id,name,account,avatar,province,city,area,street')->select()->toArray();
|
|
return $this->success('success', ['count' => $count, 'data' => $data]);
|
|
}
|
|
|
|
/**
|
|
* 公司人员
|
|
*/
|
|
public function users()
|
|
{
|
|
[$page, $limit] = $this->getPage();
|
|
$params = $this->request->param();
|
|
// if($companyId==0){
|
|
// $companyId=$this->userInfo['company_id'];
|
|
// }
|
|
$wehre[] = ['company_id', '=', $this->userInfo['company_id']];
|
|
if (isset($params['is_captain']) && $params['is_captain'] == 1) {
|
|
$wehre[] = ['is_captain', '=', 1];
|
|
}
|
|
$query = User::where($wehre);
|
|
$count = $query->count();
|
|
$users = $query->order('id', 'desc')->page($page)->limit($limit)->with(['company' => function ($query) {
|
|
$query->field('id,company_name');
|
|
}])->append(['province_name', 'city_name', 'area_name', 'street_name', 'village_name', 'brigade_name'])
|
|
->field('id,avatar,real_name,account,mobile as phone,province,city,area,street,village,brigade,company_id,create_time,qualification,nickname,is_contract,is_captain')
|
|
->select()->each(function ($item, $key) {
|
|
if ($item['qualification'] != '') {
|
|
$item['qualification'] = json_decode($item['qualification'], true);
|
|
}
|
|
if ($item['is_captain'] == 1) {
|
|
$item['informationg_count'] = UserInformationg::where(['create_user_id' => $item['id'], 'status' => 1])->count();
|
|
$item['informationg_update_count'] = UserInformationg::where(['create_user_id' => $item['id'], 'status' => 1, 'is_update' => 1])->count();
|
|
$time = UserInformationgDemand::order('update_time', 'desc')->value('update_time');
|
|
if ($time) {
|
|
$item['informationg_update_time'] = date('Y-m-d H:i:s', $time);
|
|
} else {
|
|
$item['informationg_update_time'] = '';
|
|
}
|
|
}
|
|
});
|
|
return $this->success('success', ['count' => $count, 'data' => $users]);
|
|
}
|
|
|
|
public function user($id)
|
|
{
|
|
$query = User::where('id', $id);
|
|
$user = $query->with(['company' => function ($query) {
|
|
$query->field('id,company_name');
|
|
}])
|
|
->field('id,sex,avatar,nickname name,account,mobile phone,id_card,qualification,province,province province_name,city,city city_name,area,area area_name,street,street street_name,village,village village_name,brigade,brigade brigade_name, is_contract,company_id,is_captain, group_id')
|
|
->append(['is_service_manager'], true)
|
|
->withAttr('is_service_manager', function ($value, $data) {
|
|
return $data['group_id'] == 14 ?1 :0;
|
|
})
|
|
->find()
|
|
->toArray();
|
|
|
|
$contract = Contract::where("type", 2)->where('party_b', $id)->append(['contract_type_name'])->find();
|
|
$user['contract'] = $contract;
|
|
// $roleIds = AdminRole::where('admin_id', $user['id'])->column('role_id');
|
|
// $user['roles'] = SystemRole::whereIn('id', $roleIds)->column('name');
|
|
$user['qualification'] = $user['qualification'] != null ? json_decode($user['qualification'], true) : [];
|
|
unset($user['role_id'], $user['dept_id'], $user['jobs_id']);
|
|
return $this->success('success', $user);
|
|
}
|
|
|
|
//**发起合同 */
|
|
public function initiate_contract()
|
|
{
|
|
$params = $this->request->param();
|
|
$params['party_a'] = $this->userInfo['company_id'];
|
|
$area_manager = Company::where('id', $params['party_a'])->value('area_manager');
|
|
$params['area_manager'] = $area_manager;
|
|
$params['type'] = 1;
|
|
$result = ContractLogic::initiate_contract($params);
|
|
if ($result == true) {
|
|
return $this->success('发起成功,等待平台风控部上传合同');
|
|
}
|
|
return $this->fail(ContractLogic::getError());
|
|
}
|
|
// /**发送合同 */
|
|
public function Draftingcontracts()
|
|
{
|
|
$params = $this->request->param();
|
|
$result = ContractLogic::Draftingcontracts($params, 1);
|
|
if ($result == true) {
|
|
return $this->success('生成合同成功');
|
|
}
|
|
return $this->fail(ContractLogic::getError());
|
|
}
|
|
|
|
//**发送短信 */
|
|
public function postsms()
|
|
{
|
|
$params = $this->request->param();
|
|
$id = Contract::where('party_b', $params['id'])->value('id');
|
|
$res = ContractLogic::postsms(['id' => $id]);
|
|
if ($res == true) {
|
|
return $this->success('发送成功', [], 1, 1);
|
|
} else {
|
|
return $this->fail(ContractLogic::getError());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 股金管理
|
|
*/
|
|
public function shareholder_info()
|
|
{
|
|
// $params = $this->request->param();
|
|
$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) {
|
|
$contract = Contract::where('party_b', $this->userInfo['company_id'])->where('contract_type', 40)->field('id,contract_no,contract_url,create_time,check_status,status')->find();
|
|
if ($contract) {
|
|
if($contract['contract_url']=='' &&$contract['status']==1){
|
|
app(JunziqianController::class)->download_file($contract['contract_no']);
|
|
$contract_url = Contract::where('id', $contract['id'])->value('contract_url');
|
|
$find['contract_url'] = env('url.url_prefix'). $contract_url;
|
|
|
|
}else{
|
|
$find['contract_url'] = env('url.url_prefix') . $contract['contract_url'];
|
|
}
|
|
$find['contract_time'] = $contract['create_time'];
|
|
$find['check_status'] = $contract['check_status'];
|
|
if ($contract['status'] == 1) {
|
|
$find['is_contract'] = 1;
|
|
}
|
|
}
|
|
$village_info = Company::where('village', $find['village'])->where('company_type', 17)->find();
|
|
if ($village_info) {
|
|
$find['is_village'] = 1;
|
|
} 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);
|
|
}
|
|
|
|
//**发起股金合同 */
|
|
public function initiate_shareholder_contract()
|
|
{
|
|
$params = $this->request->param();
|
|
$params['party_b'] = $this->userInfo['company_id'];
|
|
if(!$params['party_b']){
|
|
return $this->fail('请先绑定公司');
|
|
}
|
|
$Company = Company::where('id', $this->userInfo['company_id'])->where('company_type',18)->field('shareholder_money,village')->find();
|
|
if($Company){
|
|
$params['party_a'] = Company::where('village', $Company['village'])->where('company_type', 17)->value('id');
|
|
}else{
|
|
return $this->fail('您不是小组公司');
|
|
|
|
}
|
|
if(!isset($params['party_a'])||$params['party_a']==0){
|
|
return $this->fail('甲方公司不存在');
|
|
}
|
|
$area_manager = Company::where('id', $params['party_b'])->value('area_manager');
|
|
$params['area_manager'] = $area_manager;
|
|
$params['type'] = 1;
|
|
$result = ContractLogic::initiate_contract($params);
|
|
if ($result == true) {
|
|
return $this->success('发起成功,等待平台风控部上传合同');
|
|
}
|
|
return $this->fail(ContractLogic::getError());
|
|
}
|
|
|
|
/**
|
|
* 小组服务公司股金上交
|
|
*/
|
|
public function pay_share_capital()
|
|
{
|
|
try {
|
|
// 小组服务公司
|
|
$serviceGroupCompany = Company::where('id', $this->userInfo['company_id'])->find()->toArray();
|
|
// 村管理公司
|
|
$villageCompany = Company::where(['village'=>$serviceGroupCompany['village'], 'company_type' => 17])->find()->toArray();
|
|
Db::startTrans();
|
|
// 上交股金金额
|
|
$amount = $serviceGroupCompany['shareholder_money'];
|
|
if ($amount == 0) {
|
|
return $this->fail('股金金额不能为0');
|
|
}
|
|
$sharecapitalChangeLogData = [
|
|
'subordinate_company_id' => $serviceGroupCompany['id'],
|
|
'parent_company_id' => $villageCompany['id'],
|
|
'amount' => $amount,
|
|
'create_time' => time(),
|
|
'update_time' => time(),
|
|
];
|
|
$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('上交成功', [], 1, 1);
|
|
} catch (Exception $e) {
|
|
Db::rollback();
|
|
return $this->fail($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function complaint_feedback()
|
|
{
|
|
$params = $this->request->param();
|
|
$company = Company::where('id', $this->userInfo['company_id'])->find()->toArray();
|
|
Db::name('company_complaint_feedback')->insertGetId(['company_id'=>$company['id'], 'content'=>$params['content'],'create_time'=>time(), 'update_time'=>time()]);
|
|
return $this->success('成功');
|
|
}
|
|
|
|
/**
|
|
* 查询镇农科公司
|
|
*/
|
|
public function street_company(){
|
|
$street=$this->request->param('street_code');
|
|
$company=Db::query("select * from la_company where company_type=:company_type and FIND_IN_SET(:street,responsible_area)", ['company_type' => 41,'street'=>$street], true);
|
|
if($company){
|
|
return $this->success('ok',['title'=>$company[0]['company_name'],'organization_code'=>$company[0]['organization_code']]);
|
|
}else{
|
|
return $this->fail('当前区域无镇农科公司');
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* 查询签约的甲方公司
|
|
*/
|
|
public function getPartyACompany()
|
|
{
|
|
$re = CompanyLogic::getPartyA($this->userInfo['company_id']);
|
|
if ($re === false) {
|
|
return $this->fail(CompanyLogic::getError());
|
|
}
|
|
return $this->success('成功',$re);
|
|
}
|
|
|
|
public function getDepositRechargeTransferVoucherList()
|
|
{
|
|
[$page, $limit] = $this->getPage();
|
|
$list = CompanyDepositVoucher::where(['company_id' => $this->userInfo['company_id']])
|
|
->order(['id' => 'desc'])
|
|
->page($page)->limit($limit)->select();;
|
|
$count=CompanyDepositVoucher::where(['company_id' => $this->userInfo['company_id']])->count();
|
|
return $this->success('success', ['count' => $count, 'data' => $list]);
|
|
}
|
|
}
|