152 lines
5.4 KiB
PHP
152 lines
5.4 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\supplier;
|
||
|
||
|
||
use app\common\model\supplier\Supplier;
|
||
use app\common\model\supplier\SupplierContacts;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* SupplierContacts逻辑
|
||
* Class SupplierContactsLogic
|
||
* @package app\adminapi\logic\supplier
|
||
*/
|
||
class SupplierContactsLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/26 13:47
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
SupplierContacts::create([
|
||
'supplier_id' => $params['supplier_id'],
|
||
'name' => $params['name'],
|
||
'sex' => $params['sex'] ?? 0,
|
||
'birthday' => !empty($params['birthday']) ? strtotime($params['birthday']) : 0,
|
||
'contacts_type' => $params['contacts_type'] ?? 0,
|
||
'responsible' => $params['responsible'] ?? '',
|
||
'title' => $params['title'] ?? '',
|
||
'contacts_cate' => $params['contacts_cate'] ?? 0,
|
||
'department' => $params['department'] ?? '',
|
||
'duties' => $params['duties'] ?? '',
|
||
'work_phone' => $params['work_phone'] ?? '',
|
||
'mobile' => $params['mobile'] ?? '',
|
||
'email' => $params['email'] ?? '',
|
||
'fax' => $params['fax'] ?? '',
|
||
'zip_code' => $params['zip_code'] ?? '',
|
||
'family_address' => $params['family_address'] ?? '',
|
||
'id_type' => $params['id_type'] ?? 0,
|
||
'idcard' => $params['idcard'] ?? '',
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : '',
|
||
]);
|
||
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/12/26 13:47
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
SupplierContacts::where('id', $params['id'])->update([
|
||
'supplier_id' => $params['supplier_id'],
|
||
'name' => $params['name'],
|
||
'sex' => $params['sex'] ?? 0,
|
||
'birthday' => !empty($params['birthday']) ? strtotime($params['birthday']) : 0,
|
||
'contacts_type' => $params['contacts_type'] ?? 0,
|
||
'responsible' => $params['responsible'] ?? '',
|
||
'title' => $params['title'] ?? '',
|
||
'contacts_cate' => $params['contacts_cate'] ?? 0,
|
||
'department' => $params['department'] ?? '',
|
||
'duties' => $params['duties'] ?? '',
|
||
'work_phone' => $params['work_phone'] ?? '',
|
||
'mobile' => $params['mobile'] ?? '',
|
||
'email' => $params['email'] ?? '',
|
||
'fax' => $params['fax'] ?? '',
|
||
'zip_code' => $params['zip_code'] ?? '',
|
||
'family_address' => $params['family_address'] ?? '',
|
||
'id_type' => $params['id_type'] ?? 0,
|
||
'idcard' => $params['idcard'] ?? '',
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : '',
|
||
'update_time' => time(),
|
||
]);
|
||
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/12/26 13:47
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return SupplierContacts::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/26 13:47
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = SupplierContacts::findOrEmpty($params['id']);
|
||
$supplier = Supplier::field('supplier_code,supplier_name')->where('id',$data['supplier_id'])->findOrEmpty();
|
||
$data['supplier_code'] = $supplier['supplier_code'];
|
||
$data['supplier_name'] = $supplier['supplier_name'];
|
||
$data['sex_text'] = $data->sex_text;
|
||
$data['contacts_type_text'] = $data->contacts_type_text;
|
||
$data['contacts_cate_text'] = $data->contacts_cate_text;
|
||
$data['id_type_text'] = $data->id_type_text;
|
||
return $data->toArray();
|
||
}
|
||
} |