173 lines
6.9 KiB
PHP
173 lines
6.9 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\auth\Admin;
|
||
use app\common\model\dept\Dept;
|
||
use app\common\model\dept\Orgs;
|
||
use app\common\model\supplier\Supplier;
|
||
use app\common\logic\BaseLogic;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* Supplier逻辑
|
||
* Class SupplierLogic
|
||
* @package app\adminapi\logic\supplier
|
||
*/
|
||
class SupplierLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/12/26 10:56
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
Supplier::create([
|
||
'create_user_id' => $params['create_user_id'],
|
||
'org_id' => $params['org_id'],
|
||
'dept_id' => $params['dept_id'],
|
||
'supplier_code' => data_unique_code('SC'),
|
||
'supplier_name' => $params['supplier_name'],
|
||
'supplier_introduction' => $params['supplier_introduction'] ?? '',
|
||
'brand_category' => $params['brand_category'] ?? '',
|
||
'supplier_photos' => !empty($params['supplier_photos']) ? $params['supplier_photos'] : null,
|
||
'supplier_group' => $params['supplier_group'] ?? 0,
|
||
'supplier_category' => $params['supplier_category'] ?? 0,
|
||
'supplier_grade' => $params['supplier_grade'] ?? 0,
|
||
'contacts' => $params['contacts'] ?? '',
|
||
'contacts_sex' => $params['contacts_sex'] ?? 0,
|
||
'birthday' => !empty($params['birthday']) ? strtotime($params['birthday']) : 0,
|
||
'phone' => $params['phone'] ?? '',
|
||
'email' => $params['email'] ?? '',
|
||
'address' => $params['address'] ?? '',
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
'invoice_company_name' => $params['invoice_company_name'] ?? '',
|
||
'taxpayer_identification_number' => $params['taxpayer_identification_number'] ?? '',
|
||
'bank_name' => $params['bank_name'] ?? '',
|
||
'bank_accnout_name' => $params['bank_accnout_name'] ?? '',
|
||
'bank_account' => $params['bank_account'] ?? '',
|
||
'bank_address' => $params['bank_address'] ?? '',
|
||
'init_invoice_amount' => $params['init_invoice_amount'] ?? 0,
|
||
'credit_limit' => $params['credit_limit'] ?? 0,
|
||
'account_period' => $params['account_period'] ?? '',
|
||
]);
|
||
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 10:56
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
Supplier::where('id', $params['id'])->update([
|
||
'create_user_id' => $params['create_user_id'],
|
||
'org_id' => $params['org_id'],
|
||
'dept_id' => $params['dept_id'],
|
||
'supplier_code' => data_unique_code('SC'),
|
||
'supplier_name' => $params['supplier_name'],
|
||
'supplier_introduction' => $params['supplier_introduction'] ?? '',
|
||
'brand_category' => $params['brand_category'] ?? '',
|
||
'supplier_photos' => !empty($params['supplier_photos']) ? $params['supplier_photos'] : null,
|
||
'supplier_group' => $params['supplier_group'] ?? 0,
|
||
'supplier_category' => $params['supplier_category'] ?? 0,
|
||
'supplier_grade' => $params['supplier_grade'] ?? 0,
|
||
'contacts' => $params['contacts'] ?? '',
|
||
'contacts_sex' => $params['contacts_sex'] ?? 0,
|
||
'birthday' => !empty($params['birthday']) ? strtotime($params['birthday']) : 0,
|
||
'phone' => $params['phone'] ?? '',
|
||
'email' => $params['email'] ?? '',
|
||
'address' => $params['address'] ?? '',
|
||
'remark' => $params['remark'] ?? '',
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
'invoice_company_name' => $params['invoice_company_name'] ?? '',
|
||
'taxpayer_identification_number' => $params['taxpayer_identification_number'] ?? '',
|
||
'bank_name' => $params['bank_name'] ?? '',
|
||
'bank_accnout_name' => $params['bank_accnout_name'] ?? '',
|
||
'bank_account' => $params['bank_account'] ?? '',
|
||
'bank_address' => $params['bank_address'] ?? '',
|
||
'init_invoice_amount' => $params['init_invoice_amount'] ?? 0,
|
||
'credit_limit' => $params['credit_limit'] ?? 0,
|
||
'account_period' => $params['account_period'] ?? '',
|
||
'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 10:56
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return Supplier::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/12/26 10:56
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$data = Supplier::findOrEmpty($params['id']);
|
||
$create_user = Admin::field('name')->where('id',$data['create_user_id'])->findOrEmpty();
|
||
$org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty();
|
||
$dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty();
|
||
$data['create_user_name'] = $create_user['name'];
|
||
$data['org_name'] = $org['name'];
|
||
$data['dept_name'] = $dept['name'];
|
||
$data['supplier_group_text'] = $data->supplier_group_text;
|
||
$data['supplier_category_text'] = $data->supplier_category_text;
|
||
$data['supplier_grade_text'] = $data->supplier_grade_text;
|
||
$data['contacts_sex_text'] = $data->contacts_sex_text;
|
||
return $data->toArray();
|
||
}
|
||
} |