2023-07-21 11:32:23 +08:00
< ? php
namespace app\api\controller ;
2023-08-07 15:13:34 +08:00
use app\common\logic\contract\ContractLogic ;
2023-07-21 11:32:23 +08:00
use app\common\model\auth\Admin ;
use app\common\model\Company ;
use app\common\model\contract\Contract ;
2023-07-29 22:10:33 +08:00
use app\common\model\user\User ;
2023-08-02 23:13:05 +08:00
use app\common\model\user\UserAccountLog ;
2023-07-21 12:00:39 +08:00
use think\facade\Db ;
2023-08-03 11:51:56 +08:00
use app\common\model\informationg\UserInformationg ;
2023-08-21 09:28:09 +08:00
use app\common\model\informationg\UserInformationgDemand ;
2023-07-21 11:32:23 +08:00
/**
* Class CompanyController
* @ package app\api\controller
*/
class CompanyController extends BaseApiController
{
2023-08-02 23:13:05 +08:00
//**签约公司*/
2023-07-21 11:32:23 +08:00
public function index ()
{
2023-07-21 16:28:51 +08:00
[ $page , $limit ] = $this -> getPage ();
2023-08-01 22:24:25 +08:00
$myCompany = Company :: findOrEmpty ( $this -> userInfo [ 'company_id' ]) -> toArray ();
2023-07-21 11:32:23 +08:00
$companyIds = Contract :: where ( 'party_a' , $myCompany [ 'id' ]) -> column ( 'party_b' );
2023-08-31 17:40:17 +08:00
$query = Company :: whereIn ( 'id' , $companyIds ) -> where ( 'status' , 1 ) -> append ([ 'province_name' , 'city_name' , 'area_name' , 'street_name' , 'village_name' , 'brigade_name' , 'area_manager_name' ]);
2023-07-21 11:39:02 +08:00
$count = $query -> count ();
$companies = $query -> page ( $page ) -> limit ( $limit ) -> select () -> each ( function ( $company ) {
2023-07-21 11:32:23 +08:00
$company [ 'other_contacts' ] = json_decode ( $company [ 'other_contacts' ], true );
2023-07-21 14:06:24 +08:00
$company [ 'qualification' ] = $company [ 'qualification' ] != null ? json_decode ( $company [ 'qualification' ], true ) : '' ;
2023-07-24 21:03:18 +08:00
$company [ 'company_type_name' ] = Db :: name ( 'dict_data' ) -> where ( 'id' , $company [ 'company_type' ]) -> value ( 'name' );
2023-07-21 11:32:23 +08:00
}) -> toArray ();
2023-07-21 11:39:02 +08:00
return $this -> success ( '' , [ 'count' => $count , 'data' => $companies ]);
2023-07-21 11:32:23 +08:00
}
2023-08-02 23:13:05 +08:00
/**
* 未签约
*/
public function unsigned ()
{
$myCompany = Company :: findOrEmpty ( $this -> userInfo [ 'company_id' ]) -> toArray ();
2023-08-31 17:40:17 +08:00
$query = Company :: where ([ 'street' => $myCompany [ 'street' ], 'company_type' => [ 17 , 18 ], 'is_contract' => 0 ]) -> where ( 'id' , '<>' , $this -> userInfo [ 'company_id' ]);
2023-08-02 23:13:05 +08:00
$count = $query -> count ();
2023-08-12 13:56:48 +08:00
$companies = $query -> field ( '*,street street_name,area area_name,city city_name,province province_name,village village_name,brigade brigade_name' ) -> select () -> toArray ();
2023-08-02 23:13:05 +08:00
return $this -> success ( '' , [ 'count' => $count , 'data' => $companies ]);
}
2023-07-21 14:06:24 +08:00
public function view ()
2023-07-21 11:32:23 +08:00
{
2023-07-21 14:06:24 +08:00
$id = $this -> request -> param ( 'id' , 0 );
if ( empty ( $id )) {
2023-08-01 22:24:25 +08:00
$query = Company :: find ( $this -> userInfo [ 'company_id' ]);
2023-07-21 14:06:24 +08:00
} else {
2023-07-22 10:52:19 +08:00
$query = Company :: find ( $id );
2023-07-21 14:06:24 +08:00
}
2023-08-02 23:13:05 +08:00
if ( ! $query ) {
2023-08-01 22:24:25 +08:00
return $this -> fail ( '公司不存在' );
}
2023-08-31 17:40:17 +08:00
$company = $query -> append ([ 'province_name' , 'city_name' , 'area_name' , 'street_name' , 'area_manager_name' , 'village_name' , 'brigade_name' ]) -> toArray ();
2023-07-21 11:32:23 +08:00
$company [ 'other_contacts' ] = json_decode ( $company [ 'other_contacts' ], true );
2023-07-21 14:06:24 +08:00
$company [ 'qualification' ] = $company [ 'qualification' ] != null ? json_decode ( $company [ 'qualification' ], true ) : '' ;
2023-08-31 17:40:17 +08:00
if ( $company [ 'qualification' ] && isset ( $company [ 'qualification' ][ 'other_qualifications' ])) {
$company [ 'qualification' ][ 'other_qualifications' ] = json_decode ( $company [ 'qualification' ][ 'other_qualifications' ], true );
2023-08-07 15:31:59 +08:00
}
2023-08-31 17:40:17 +08:00
$contract = Contract :: where ( 'party_b' , $id ) -> find ();
2023-07-24 17:51:00 +08:00
if ( ! empty ( $contract )) {
2023-08-07 09:36:32 +08:00
if ( $contract [ 'type' ] == 2 ) {
$contract [ 'party_b_name' ] = User :: where ( 'id' , $contract [ 'party_b' ]) -> value ( 'nickname' );
2023-07-24 17:51:00 +08:00
} 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' );
2023-07-21 12:00:39 +08:00
2023-07-24 17:51:00 +08:00
$contract [ 'contract_type_name' ] = Db :: name ( 'dict_data' ) -> where ( 'id' , $contract [ 'contract_type' ]) -> value ( 'name' );
}
2023-07-21 12:00:39 +08:00
$company [ 'company_type_name' ] = Db :: name ( 'dict_data' ) -> where ( 'id' , $company [ 'company_type' ]) -> value ( 'name' );
2023-08-03 12:47:20 +08:00
$company [ 'day_money_count' ] = UserAccountLog :: where ([ 'company_id' => $company [ 'id' ], 'action' => 1 ]) -> whereDay ( 'create_time' ) -> sum ( 'change_amount' );
2023-08-09 14:43:30 +08:00
// $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 ]);
2023-07-21 11:32:23 +08:00
}
2023-07-21 14:53:56 +08:00
public function areaManager ()
{
2023-07-22 15:00:16 +08:00
[ $page , $limit ] = $this -> getPage ();
2023-08-01 22:24:25 +08:00
$company = Company :: find ( $this -> userInfo [ 'company_id' ]);
2023-07-22 17:34:59 +08:00
$query = Admin :: where ( 'id' , $company [ 'area_manager' ]);
2023-07-22 15:00:16 +08:00
$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 ]);
2023-07-21 14:53:56 +08:00
}
2023-08-03 11:46:36 +08:00
/**
* 公司人员
*/
2023-07-21 16:28:51 +08:00
public function users ()
{
[ $page , $limit ] = $this -> getPage ();
2023-08-03 12:47:20 +08:00
$params = $this -> request -> param ();
2023-08-01 22:24:25 +08:00
// if($companyId==0){
// $companyId=$this->userInfo['company_id'];
// }
2023-08-03 12:47:20 +08:00
$wehre [] = [ 'company_id' , '=' , $this -> userInfo [ 'company_id' ]];
if ( isset ( $params [ 'is_captain' ]) && $params [ 'is_captain' ] == 1 ) {
$wehre [] = [ 'is_captain' , '=' , 1 ];
2023-08-03 11:46:36 +08:00
}
$query = User :: where ( $wehre );
2023-07-21 16:28:51 +08:00
$count = $query -> count ();
2023-08-07 11:28:56 +08:00
$users = $query -> order ( 'id' , 'desc' ) -> page ( $page ) -> limit ( $limit ) -> with ([ 'company' => function ( $query ) {
2023-07-21 16:28:51 +08:00
$query -> field ( 'id,company_name' );
2023-08-31 17:40:17 +08:00
}]) -> append ([ 'province_name' , 'city_name' , 'area_name' , 'street_name' , 'village_name' , 'brigade_name' ])
2023-08-21 09:28:09 +08:00
-> 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' )
2023-08-03 12:47:20 +08:00
-> 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 ();
2023-08-31 17:40:17 +08:00
$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' ] = '' ;
2023-08-21 11:43:17 +08:00
}
2023-08-03 12:47:20 +08:00
}
});
2023-07-21 16:28:51 +08:00
return $this -> success ( 'success' , [ 'count' => $count , 'data' => $users ]);
}
2023-07-22 11:26:25 +08:00
public function user ( $id )
{
2023-08-01 22:24:25 +08:00
$query = User :: where ( 'id' , $id );
2023-07-22 11:26:25 +08:00
$user = $query -> with ([ 'company' => function ( $query ) {
$query -> field ( 'id,company_name' );
2023-08-07 09:36:32 +08:00
}]) -> 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' ) -> find () -> toArray ();
2023-08-31 17:40:17 +08:00
$contract = Contract :: where ( " type " , 2 ) -> where ( 'party_b' , $id ) -> append ([ 'contract_type_name' ]) -> find ();
2023-07-22 11:26:25 +08:00
$user [ 'contract' ] = $contract ;
2023-08-01 22:24:25 +08:00
// $roleIds = AdminRole::where('admin_id', $user['id'])->column('role_id');
// $user['roles'] = SystemRole::whereIn('id', $roleIds)->column('name');
2023-07-22 11:26:25 +08:00
$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 );
}
2023-08-03 11:27:03 +08:00
2023-08-03 12:47:20 +08:00
//**发起合同 */
public function initiate_contract ()
{
$params = $this -> request -> param ();
$params [ 'party_a' ] = $this -> userInfo [ 'company_id' ];
2023-08-26 16:25:44 +08:00
$area_manager = Company :: where ( 'id' , $params [ 'party_a' ]) -> value ( 'area_manager' );
$params [ 'area_manager' ] = $area_manager ;
2023-08-03 12:47:20 +08:00
$params [ 'type' ] = 1 ;
2023-08-07 15:13:34 +08:00
$result = ContractLogic :: initiate_contract ( $params );
2023-08-03 12:47:20 +08:00
if ( $result == true ) {
return $this -> success ( '发起成功,等待平台风控部上传合同' );
2023-08-03 11:27:03 +08:00
}
2023-08-07 15:13:34 +08:00
return $this -> fail ( ContractLogic :: getError ());
2023-08-03 12:47:20 +08:00
}
2023-08-07 15:13:34 +08:00
// /**发送合同 */
2023-08-03 12:47:20 +08:00
public function Draftingcontracts ()
{
$params = $this -> request -> param ();
2023-08-31 17:40:17 +08:00
$result = ContractLogic :: Draftingcontracts ( $params , 1 );
2023-08-03 12:47:20 +08:00
if ( $result == true ) {
return $this -> success ( '生成合同成功' );
2023-08-03 11:27:03 +08:00
}
2023-08-07 15:13:34 +08:00
return $this -> fail ( ContractLogic :: getError ());
2023-08-03 12:47:20 +08:00
}
//**发送短信 */
public function postsms ()
{
$params = $this -> request -> param ();
2023-08-31 17:40:17 +08:00
$id = Contract :: where ( 'party_b' , $params [ 'id' ]) -> value ( 'id' );
$res = ContractLogic :: postsms ([ 'id' => $id ]);
2023-08-03 12:47:20 +08:00
if ( $res == true ) {
return $this -> success ( '发送成功' , [], 1 , 1 );
} else {
2023-08-07 15:13:34 +08:00
return $this -> fail ( ContractLogic :: getError ());
2023-08-03 12:47:20 +08:00
}
}
2023-08-30 13:50:50 +08:00
/**
* 股金管理
*/
2023-08-31 17:40:17 +08:00
public function shareholder_info ()
{
2023-08-30 13:50:50 +08:00
// $params = $this->request->param();
2023-08-31 17:40:17 +08:00
$find = Company :: where ( 'id' , $this -> userInfo [ 'company_id' ]) -> field ( '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 ( 'contract_url,create_time,check_status,status' ) -> find ();
if ( $contract ) {
$find [ 'contract_url' ] = 'https://worker-task.lihaink.cn' . $contract [ 'contract_url' ];
$find [ 'contract_time' ] = $contract [ 'create_time' ];
$find [ 'check_status' ] = $contract [ 'check_status' ];
if ( $contract [ 'status' ] == 1 ) {
$find [ 'is_contract' ] = 1 ;
2023-08-31 17:25:06 +08:00
}
2023-08-31 17:19:51 +08:00
}
2023-08-31 17:40:17 +08:00
$village_info = Company :: where ( 'village' , $find [ 'village' ]) -> where ( 'company_type' , 17 ) -> find ();
if ( $village_info ) {
$find [ 'is_amount_turned' ] = 1 ;
} else {
$find [ 'is_amount_turned' ] = 0 ;
2023-08-30 14:46:22 +08:00
}
2023-08-31 17:40:17 +08:00
} else {
$find [ 'contract_url' ] = '' ;
$find [ 'contract_time' ] = '' ;
$find [ 'is_amount_turned' ] = 0 ;
2023-08-30 13:50:50 +08:00
}
2023-08-31 17:40:17 +08:00
return $this -> success ( 'ok' , $find );
2023-08-30 13:50:50 +08:00
}
2023-08-30 14:46:22 +08:00
2023-08-31 17:40:17 +08:00
//**发起股金合同 */
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' ]) -> field ( 'shareholder_money,village' ) -> find ();
if ( $Company ){
$params [ 'party_a' ] = Company :: where ( 'village' , $Company [ 'village' ]) -> where ( 'company_type' , 17 ) -> value ( 'id' );
}
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 ()
{
2023-08-30 14:46:22 +08:00
// return
}
2023-08-02 23:13:05 +08:00
}