187 lines
6.6 KiB
PHP
187 lines
6.6 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\adminapi\logic;
|
||
|
||
|
||
use app\common\model\Company;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\contract\Contract;
|
||
use think\exception\ValidateException;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* Company逻辑
|
||
* Class CompanyLogic
|
||
* @package app\adminapi\logic
|
||
*/
|
||
class CompanyLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/07/15 14:43
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
// $exist = Company::where('admin_id', $params['admin_id'])->find();
|
||
// if (!empty($exist)) {
|
||
// throw new ValidateException('该账号已经注册过企业');
|
||
// }
|
||
$data=Company::create([
|
||
// 'level_two' => $params['level_two'],
|
||
// 'level_one' => $params['level_one'],
|
||
'company_name' => $params['company_name'],
|
||
'organization_code' => $params['organization_code'],
|
||
'province' => $params['province'],
|
||
'city' => $params['city'],
|
||
'area' => $params['area'],
|
||
'street' => $params['street'],
|
||
'address' => $params['address'],
|
||
'company_type' => $params['company_type'],
|
||
'master_name' => $params['master_name'],
|
||
'master_position' => $params['master_position'],
|
||
'master_phone' => $params['master_phone'],
|
||
'master_email' => $params['master_email'],
|
||
'other_contacts' => $params['other_contacts'],
|
||
// 'area_manager' => $params['area_manager'],
|
||
// 'is_contract' => $params['is_contract'],
|
||
// 'account' => $params['account'],
|
||
// 'password' => $params['password'],
|
||
// 'deposit' => $params['deposit'],
|
||
// 'deposit_time' => $params['deposit_time'],
|
||
'qualification' => $params['qualification'],
|
||
'admin_id' => $params['admin_id'] ?? 0,
|
||
// 'status' => $params['status']
|
||
]);
|
||
self::contract($data['id'], $params);
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/07/15 14:43
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
Company::where('id', $params['id'])->update([
|
||
// 'level_two' => $params['level_two'],
|
||
// 'level_one' => $params['level_one'],
|
||
'company_name' => $params['company_name'],
|
||
'organization_code' => $params['organization_code'],
|
||
'province' => $params['province'],
|
||
'city' => $params['city'],
|
||
'area' => $params['area'],
|
||
'street' => $params['street'],
|
||
'address' => $params['address'],
|
||
'company_type' => $params['company_type'],
|
||
'master_name' => $params['master_name'],
|
||
'master_position' => $params['master_position'],
|
||
'master_phone' => $params['master_phone'],
|
||
'master_email' => $params['master_email'],
|
||
'other_contacts' => $params['other_contacts'],
|
||
// 'area_manager' => $params['area_manager'],
|
||
// 'is_contract' => $params['is_contract'],
|
||
// 'account' => $params['account'],
|
||
// 'password' => $params['password'],
|
||
// 'deposit' => $params['deposit'],
|
||
// 'deposit_time' => $params['deposit_time'],
|
||
'qualification' => $params['qualification'],
|
||
// 'status' => $params['status']
|
||
]);
|
||
self::contract($params['id'], $params);
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage(), $e->getFile());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/07/15 14:43
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return Company::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/07/15 14:43
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
|
||
$data=Company::findOrEmpty($params['id'])->toArray();
|
||
if($data){
|
||
$data['other_contacts']=json_decode($data['other_contacts'],true);
|
||
$data['qualification']=json_decode($data['qualification'],true);
|
||
$data['contract']=Db::name('contract')->where('party_b',$data['id'])
|
||
->withAttr('party_a_name',function($value,$data){
|
||
return Db::name('company')->where('id',$data['party_a'])->value('company_name');
|
||
})
|
||
// ->withAttr('contract_file_url',function($value,$data){
|
||
// return Db::name('dict_data')->where('id',$data['contract_type_two'])->value('value');
|
||
// })
|
||
->find();
|
||
}
|
||
return $data;
|
||
}
|
||
|
||
public static function contract($companyId, $params)
|
||
{
|
||
$model = Contract::where(['party_b'=>$companyId])->find();
|
||
if (empty($model)) {
|
||
$model = new Contract();
|
||
$model->party_b = $companyId;
|
||
$model->contract_no = time();
|
||
$model->create_time = time();
|
||
$model->type = 1;
|
||
}
|
||
$model->update_time = time();
|
||
$model->setAttrs($params['contract']);
|
||
$model->save();
|
||
}
|
||
|
||
} |