new-admin-api/app/controller/admin/system/supplier/Supplier.php

84 lines
2.7 KiB
PHP

<?php
namespace app\controller\admin\system\supplier;
use app\services\supplier\SystemSupplierServices;
use crmeb\basic\BaseController;
use think\App;
use think\exception\ValidateException;
class Supplier extends BaseController{
public function __construct(App $app, SystemSupplierServices $services){
parent::__construct($app);
$this->services = $services;
}
/**
* Common: 账号添加
* Author: wu-hui
* Time: 2024/01/17 11:43
* @return mixed
*/
public function accountCreate(){
// 参数获取
$data = $this->checkParam();
// 添加账号
$this->services->create((array)$data);
return app('json')->success('添加成功');
}
/**
* Common: 添加|编辑 账号参数获取
* Author: wu-hui
* Time: 2024/01/17 10:56
* @return array
*/
private function checkParam():array{
// 接收表单参数
$supplierId = (int)$this->request->param('supplier_id');
$accountInfo = $this->request->params([
'supplier_name',
'detailed_address',
'name',
['phone',''],
'email',
'sort',
'is_show',
'is_examine',
'mark',
]);
$accountPassword = $this->request->params([
'supplier_account',
'supplier_password',
]);
// 数据判断
$nameIsHave = $this->services->isHave('supplier_name',$accountInfo['supplier_name'],$supplierId);
if($nameIsHave) throw new ValidateException('供应商名称已经存在,请勿重复添加!');
if (!empty($accountInfo['phone']) && isPhone($accountInfo['phone'])) throw new ValidateException('请输入正确的手机号!');
$accountIsHas = $this->services->accountIsHas($accountPassword['supplier_account'],$supplierId);
if($accountIsHas) throw new ValidateException('账号已存在,请勿重复添加!');
return compact('supplierId','accountInfo','accountPassword');
}
/**
* Common: 获取列表
* Author: wu-hui
* Time: 2024/01/17 14:29
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(){
$search = $this->request->params(['supplier_name','name','phone','is_show']);
[$page, $limit] = $this->getPage();
$field = 'id,supplier_name,avatar,name,phone,is_show,add_time';
$data = $this->services->supplierList($search, $page, $limit, $field);
return app('json')->success($data);
}
}