You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
4.0 KiB
125 lines
4.0 KiB
<?php
|
|
namespace app\api\controller;
|
|
|
|
use app\admin\controller\project\CompanyUser;
|
|
use app\admin\model\AuthGroup;
|
|
use app\admin\model\AuthGroupAccess;
|
|
use app\common\controller\Api;
|
|
use app\common\model\ProjectCompanyUser;
|
|
use app\common\model\ProjectWorkerOrder;
|
|
use app\common\model\User;
|
|
use app\common\model\UserCompany;
|
|
use fast\Random;
|
|
use http\Env\Request;
|
|
use think\Db;
|
|
use think\Exception;
|
|
|
|
class Company extends Api {
|
|
protected $noNeedLogin = ['demo'];
|
|
protected $noNeedRight = '*';
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
}
|
|
|
|
public function add() {
|
|
if ($this->auth->isCompanyAdminNew($this->auth->id, $this->auth->company_id)) {
|
|
$this->error('您已经是企业管理员了,请勿重复提交');
|
|
}
|
|
$post = $this->request->post();
|
|
$res = $this->validate($post, 'company.add');
|
|
if(true !== $res) {
|
|
$this->error($res);
|
|
}
|
|
Db::startTrans();
|
|
try {
|
|
$res = UserCompany::where('id', $this->auth->company_id)->find();
|
|
//检查企业是否待审核
|
|
if ($res['audit_status'] === '0') {
|
|
$this->error('企业待审核');
|
|
}
|
|
|
|
//检查企业名是否重复
|
|
if ($res['company_name'] == $post['company_name']) {
|
|
$this->error('企业名已存在');
|
|
}
|
|
$res = UserCompany::create($post);
|
|
if ($res) {
|
|
//更新用户信息
|
|
$user = $this->auth->getUser();
|
|
$salt = Random::alnum();
|
|
$user->username = $post['account'];
|
|
$user->password = $this->auth->getEncryptPassword($post['pwd'],$salt);
|
|
$user->company_id = $res->id;
|
|
$user->email = $post['contact_email'];
|
|
$user->mobile = $post['contact_phone'];
|
|
$user->salt = $salt;
|
|
$user->avatar = '/assets/img/avatar.png';
|
|
$user->save();
|
|
|
|
Db::commit();
|
|
$this->success('入驻成功', []);
|
|
}
|
|
} catch (Exception $e) {
|
|
Db::rollback();
|
|
$this->error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 企业列表
|
|
* @return void
|
|
*/
|
|
public function list() {
|
|
$user = $this->auth->getUser();
|
|
$company_ids = ProjectCompanyUser::getCompanyIds($user->id);
|
|
//工程客户所属企业 和用户企业合并
|
|
$customer_company_ids = ProjectWorkerOrder::where('customer_phone', $user->mobile)->column('company_id');
|
|
if ($customer_company_ids || $company_ids) {
|
|
$company_ids = array_merge($customer_company_ids,$company_ids);
|
|
}
|
|
|
|
$data = UserCompany::getInfoByIds($company_ids);
|
|
$this->success('获取成功', $data);
|
|
}
|
|
|
|
/**
|
|
* 登录账号是否可以进行企业支付
|
|
*/
|
|
public function isCompanyPay() {
|
|
$user = $this->auth->getUser();
|
|
$is_pay = 0;//是否可以支付 1-可以 0-不可以
|
|
$money = 0;
|
|
$company_id = 0;
|
|
|
|
//判断是否企业用户
|
|
$company_ids = ProjectCompanyUser::getCompanyIds($user->id) ?? [];
|
|
// var_dump($company_ids);exit();
|
|
$company_pay = UserCompany::getPayByCompanyIds($user->id,$company_ids);
|
|
|
|
$ret = [
|
|
'money' => $company_pay['money'],
|
|
'is_pay' => $company_pay['is_pay'],
|
|
'company_id' => $company_pay['company_id']
|
|
];
|
|
|
|
$this->success('success', $ret);
|
|
}
|
|
|
|
public function detail() {
|
|
$user = $this->auth->getUser();
|
|
$company_id = $user->company_id;
|
|
if ($company_id > 0) {
|
|
$info = UserCompany::get($company_id);
|
|
if (empty($info)) {
|
|
$this->success('暂无数据');
|
|
}
|
|
$info->license = $this->request->domain().'/'.$info->license;
|
|
$info->hidden(['pwd']);
|
|
$this->success('success', $info);
|
|
}
|
|
$this->success('暂无数据');
|
|
}
|
|
|
|
}
|
|
|