113 lines
3.1 KiB
PHP
113 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace app\admin\controller\Customer;
|
|
|
|
use app\BaseController;
|
|
use app\common\model\Customer\Customer as ModelCustomer;
|
|
use app\Request;
|
|
use think\Validate;
|
|
use think\exception\ValidateException;
|
|
use think\facade\Filesystem;
|
|
use app\common\arw\adjfut\src\Excel;
|
|
use app\common\arw\adjfut\src\UploadFile;
|
|
use app\common\exception\Tool;
|
|
use think\facade\Db;
|
|
use think\facade\Env;
|
|
|
|
|
|
class Customer extends BaseController
|
|
{
|
|
/**
|
|
* 获取客户列表
|
|
*/
|
|
public function getCustomerList(Request $request): array
|
|
{
|
|
$con = Tool::getOptionalQuery(
|
|
['customer_name', 'LIKE'],
|
|
['customer_account', 'LIKE'],
|
|
['customer_phone', 'LIKE'],
|
|
['customer_email', 'LIKE'],
|
|
['customer_sex', '='],
|
|
);
|
|
|
|
$query = ModelCustomer::where($con)
|
|
->field([
|
|
'customer_id',
|
|
'customer_guid',
|
|
'customer_name',
|
|
'customer_account',
|
|
'customer_phone',
|
|
'customer_email',
|
|
'customer_sex'
|
|
])
|
|
->order('customer_update_time', 'desc');
|
|
|
|
return msg("获取客户列表成功!", $query);
|
|
}
|
|
|
|
/**
|
|
* 添加客户
|
|
*/
|
|
public function addCustomer(Request $request): array
|
|
{
|
|
$params = $request->param();
|
|
$this->validate($params, [
|
|
'customer_name|客户昵称' => 'require',
|
|
'customer_account|客户账号' => 'require|alphaNum|min:10',
|
|
]);
|
|
$model = ModelCustomer::create($params, [
|
|
'customer_name',
|
|
'customer_account',
|
|
'customer_password',
|
|
'customer_phone',
|
|
'customer_email',
|
|
'customer_sex',
|
|
'customer_guid',
|
|
'customer_create_user_guid',
|
|
'customer_update_user_guid'
|
|
]);
|
|
return msg('添加成功!');
|
|
}
|
|
|
|
/**
|
|
* 编辑客户
|
|
*/
|
|
public function editCustomer(Request $request): array
|
|
{
|
|
$params = $request->param();
|
|
$this->validate($params, [
|
|
'customer_name|客户昵称' => 'require',
|
|
'customer_account|客户账号' => 'require',
|
|
]);
|
|
|
|
$model = ModelCustomer::where('customer_guid', $params['customer_guid'])->find();
|
|
if (!$model) throwErrorMsg("该客户不存在", 1);
|
|
$model->allowField([
|
|
'customer_name',
|
|
'customer_account',
|
|
'customer_password',
|
|
'customer_phone',
|
|
'customer_email',
|
|
'customer_sex',
|
|
'customer_update_user_guid'
|
|
])->save($params);
|
|
return msg('编辑成功!');
|
|
}
|
|
|
|
/**
|
|
* 删除客户
|
|
*/
|
|
public function deleteCustomer(Request $request): array
|
|
{
|
|
$params = $request->param();
|
|
$this->validate($params, [
|
|
'customer_guid' => 'require',
|
|
]);
|
|
$customer = ModelCustomer::where([
|
|
'customer_guid' => explode(',', $params['customer_guid'])
|
|
])->select();
|
|
$customer->delete();
|
|
return msg('删除成功!');
|
|
}
|
|
}
|