130 lines
3.6 KiB
PHP
130 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic\customer;
|
|
|
|
|
|
use app\common\model\customer\Customer;
|
|
use app\common\logic\BaseLogic;
|
|
use think\facade\Db;
|
|
|
|
|
|
/**
|
|
* 客户管理逻辑
|
|
* Class CustomerLogic
|
|
* @package app\admin\logic\customer
|
|
*/
|
|
class CustomerLogic extends BaseLogic
|
|
{
|
|
|
|
|
|
/**
|
|
* @notes 添加客户管理
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2024/04/23 14:44
|
|
*/
|
|
public static function add(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
Customer::create([
|
|
'name' => $params['name'],
|
|
'number' => $params['number'],
|
|
'contacts' => $params['contacts'],
|
|
'tel' => $params['tel'],
|
|
'add' => $params['add'],
|
|
'birthday' => $params['birthday'],
|
|
'bank' => $params['bank'],
|
|
'account' => $params['account'],
|
|
'tax' => $params['tax'],
|
|
'other' => $params['other'],
|
|
'email' => $params['email'],
|
|
'data' => $params['data'],
|
|
'more' => $params['more'],
|
|
'sort' => $params['sort'],
|
|
'customer_type' => $params['customer_type'],
|
|
'price_level' => $params['price_level'],
|
|
'dept_type' => $params['dept_type'],
|
|
'related_suppliers' => $params['related_suppliers'],
|
|
'invoice_type' => $params['invoice_type']
|
|
]);
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 编辑客户管理
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2024/04/23 14:44
|
|
*/
|
|
public static function edit(array $params): bool
|
|
{
|
|
Db::startTrans();
|
|
try {
|
|
Customer::where('id', $params['id'])->update([
|
|
'name' => $params['name'],
|
|
'number' => $params['number'],
|
|
'contacts' => $params['contacts'],
|
|
'tel' => $params['tel'],
|
|
'add' => $params['add'],
|
|
'birthday' => $params['birthday'],
|
|
'bank' => $params['bank'],
|
|
'account' => $params['account'],
|
|
'tax' => $params['tax'],
|
|
'other' => $params['other'],
|
|
'email' => $params['email'],
|
|
'data' => $params['data'],
|
|
'more' => $params['more'],
|
|
'sort' => $params['sort'],
|
|
'customer_type' => $params['customer_type'],
|
|
'price_level' => $params['price_level'],
|
|
'dept_type' => $params['dept_type'],
|
|
'related_suppliers' => $params['related_suppliers'],
|
|
'invoice_type' => $params['invoice_type']
|
|
]);
|
|
|
|
Db::commit();
|
|
return true;
|
|
} catch (\Exception $e) {
|
|
Db::rollback();
|
|
self::setError($e->getMessage());
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 删除客户管理
|
|
* @param array $params
|
|
* @return bool
|
|
* @author likeadmin
|
|
* @date 2024/04/23 14:44
|
|
*/
|
|
public static function delete(array $params): bool
|
|
{
|
|
return Customer::destroy($params['id']);
|
|
}
|
|
|
|
|
|
/**
|
|
* @notes 获取客户管理详情
|
|
* @param $params
|
|
* @return array
|
|
* @author likeadmin
|
|
* @date 2024/04/23 14:44
|
|
*/
|
|
public static function detail($params): array
|
|
{
|
|
return Customer::findOrEmpty($params['id'])->toArray();
|
|
}
|
|
} |