update Supplier
This commit is contained in:
parent
9afeaeb2ef
commit
742a64cce0
@ -16,9 +16,9 @@
|
||||
namespace app\adminapi\controller\supplier;
|
||||
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\supplier\SupplierLists;
|
||||
use app\adminapi\logic\supplier\SupplierLogic;
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\supplier\SupplierLists;
|
||||
use app\adminapi\logic\supplier\SupplierLogic;
|
||||
use app\adminapi\validate\supplier\SupplierValidate;
|
||||
|
||||
|
||||
|
@ -39,7 +39,8 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [
|
||||
'=' => ['s.org_id', 's.dept_id', 's.supplier_code', 's.supplier_name', 's.group_id', 's.category_id', 's.grade'],
|
||||
'=' => ['supplier_group', 'supplier_category', 'supplier_grade'],
|
||||
'%like%' => ['supplier_code','supplier_name','contacts'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -55,19 +56,25 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
*/
|
||||
public function lists(): array
|
||||
{
|
||||
return Db::name('Supplier')->alias('s')
|
||||
->where($this->searchWhere)
|
||||
->whereNull('s.delete_time')
|
||||
->leftJoin('orgs o','o.id = s.org_id')
|
||||
->leftJoin('dept d','d.id = s.dept_id')
|
||||
->field('s.*, d.name as dept_name, o.name as org_name')
|
||||
$params = $this->request->get(['create_user_name']);
|
||||
$where = [];
|
||||
if(isset($params['create_user_name']) && $params['create_user_name'] != ''){
|
||||
$create_user_ids = Admin::where('name','like','%'.$params['create_user_name'].'%')->column('id');
|
||||
$where[] = ['create_user_id','in',$create_user_ids];
|
||||
}
|
||||
return Supplier::where($this->searchWhere)->where($where)
|
||||
->field('id,create_user_id,supplier_code,supplier_name,brand_category,supplier_group,supplier_category,supplier_grade,contacts,contacts_sex,phone,remark')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['s.id' => 'desc'])
|
||||
->select()->each(function($item, $key){
|
||||
//关联数据后续添加
|
||||
$admin = Admin::field('name')->where('id',$item['create_user_id'])->findOrEmpty();
|
||||
$item['create_user'] = $admin['name'];
|
||||
return $item;
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function($data){
|
||||
$create_user = Admin::field('name')->where('id',$data['create_user_id'])->findOrEmpty();
|
||||
$data['create_user_name'] = $create_user['name'];
|
||||
$data['supplier_group'] = $data->supplier_group_text;
|
||||
$data['supplier_category'] = $data->supplier_category_text;
|
||||
$data['supplier_grade'] = $data->supplier_grade_text;
|
||||
$data['contacts_sex'] = $data->contacts_sex_text;
|
||||
unset($data['create_user_id']);
|
||||
return $data;
|
||||
})
|
||||
->toArray();
|
||||
}
|
||||
@ -81,11 +88,13 @@ class SupplierLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return Db::name('Supplier')->alias('s')
|
||||
->where($this->searchWhere)
|
||||
->whereNull('s.delete_time')
|
||||
->leftJoin('orgs o','o.id = s.org_id')
|
||||
->leftJoin('dept d','d.id = s.dept_id')->count();
|
||||
$params = $this->request->get(['create_user_name']);
|
||||
$where = [];
|
||||
if(isset($params['create_user_name']) && $params['create_user_name'] != ''){
|
||||
$create_user_ids = Admin::where('name','like','%'.$params['create_user_name'].'%')->column('id');
|
||||
$where[] = ['create_user_id','in',$create_user_ids];
|
||||
}
|
||||
return Supplier::field('id')->where($this->searchWhere)->where($where)->count();
|
||||
}
|
||||
|
||||
}
|
@ -15,6 +15,9 @@
|
||||
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;
|
||||
@ -41,25 +44,25 @@ class SupplierLogic extends BaseLogic
|
||||
Db::startTrans();
|
||||
try {
|
||||
Supplier::create([
|
||||
'create_user_id' => $params['create_user_id'] ?? 0,
|
||||
'org_id' => $params['org_id'] ?? 0,
|
||||
'dept_id' => $params['dept_id'] ?? 0,
|
||||
'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_name' => $params['supplier_name'],
|
||||
'supplier_introduction' => $params['supplier_introduction'] ?? '',
|
||||
'brand_category' => $params['brand_category'] ?? 0,
|
||||
'photos' => $params['photos'] ?? '',
|
||||
'group_id' => $params['group_id'] ?? 0,
|
||||
'category_id' => $params['category_id'] ?? 0,
|
||||
'grade' => $params['grade'] ?? 0,
|
||||
'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' => $params['birthday'] ?? '',
|
||||
'birthday' => !empty($params['birthday']) ? strtotime($params['birthday']) : 0,
|
||||
'phone' => $params['phone'] ?? '',
|
||||
'email' => $params['email'] ?? '',
|
||||
'address' => $params['address'] ?? '',
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => $params['annex'] ?? '',
|
||||
'annex' => !empty($params['annex']) ? $params['annex'] : null,
|
||||
'invoice_company_name' => $params['invoice_company_name'] ?? '',
|
||||
'taxpayer_identification_number' => $params['taxpayer_identification_number'] ?? '',
|
||||
'bank_name' => $params['bank_name'] ?? '',
|
||||
@ -68,9 +71,8 @@ class SupplierLogic extends BaseLogic
|
||||
'bank_address' => $params['bank_address'] ?? '',
|
||||
'init_invoice_amount' => $params['init_invoice_amount'] ?? 0,
|
||||
'credit_limit' => $params['credit_limit'] ?? 0,
|
||||
'account_period' => $params['account_period'] ?? 0,
|
||||
'account_period' => $params['account_period'] ?? '',
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -93,35 +95,36 @@ class SupplierLogic extends BaseLogic
|
||||
Db::startTrans();
|
||||
try {
|
||||
Supplier::where('id', $params['id'])->update([
|
||||
'create_user_id' => $params['create_user_id'] ?? 0,
|
||||
'org_id' => $params['org_id'] ?? 0,
|
||||
'dept_id' => $params['dept_id'] ?? 0,
|
||||
'supplier_name' => $params['supplier_name'] ?? '',
|
||||
'supplier_introduction' => $params['supplier_introduction'] ?? '',
|
||||
'brand_category' => $params['brand_category'] ?? 0,
|
||||
'photos' => $params['photos'] ?? '',
|
||||
'group_id' => $params['group_id'] ?? 0,
|
||||
'category_id' => $params['category_id'] ?? 0,
|
||||
'grade' => $params['grade'] ?? 0,
|
||||
'contacts' => $params['contacts'] ?? '',
|
||||
'contacts_sex' => $params['contacts_sex'] ?? 0,
|
||||
'birthday' => $params['birthday'] ?? '',
|
||||
'phone' => $params['phone'] ?? '',
|
||||
'email' => $params['email'] ?? '',
|
||||
'address' => $params['address'] ?? '',
|
||||
'remark' => $params['remark'] ?? '',
|
||||
'annex' => $params['annex'] ?? '',
|
||||
'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'] ?? 0,
|
||||
'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' => !empty($params['annex']) ? $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) {
|
||||
@ -154,10 +157,17 @@ class SupplierLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$supplier = Supplier::findOrEmpty($params['id']);
|
||||
$supplier->org;
|
||||
$supplier->dept;
|
||||
$supplier->contact;
|
||||
return $supplier->toArray();
|
||||
$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();
|
||||
}
|
||||
}
|
@ -15,6 +15,10 @@
|
||||
namespace app\adminapi\validate\supplier;
|
||||
|
||||
|
||||
use app\common\model\auth\Admin;
|
||||
use app\common\model\dept\Dept;
|
||||
use app\common\model\dept\Orgs;
|
||||
use app\common\model\dict\DictData;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
@ -31,24 +35,34 @@ class SupplierValidate extends BaseValidate
|
||||
* @var string[]
|
||||
*/
|
||||
protected $rule = [
|
||||
'id' => 'require',
|
||||
'create_user_id' => 'require',
|
||||
'org_id' => 'require',
|
||||
'dept_id' => 'require',
|
||||
'supplier_name' => 'require',
|
||||
'id' => 'require',
|
||||
'create_user_id' => 'require|checkCreateUser',
|
||||
'org_id' => 'require|checkOrg',
|
||||
'dept_id' => 'require|checkDept',
|
||||
'supplier_name' => 'require',
|
||||
'supplier_photos' => 'checkAnnex',
|
||||
'supplier_group' => 'checkSupplierGroup',
|
||||
'supplier_category' => 'checkSupplierCategory',
|
||||
'supplier_grade' => 'checkSupplierGrade',
|
||||
'contacts_sex' => 'in:0,1',
|
||||
'birthday' => 'dateFormat:Y-m-d',
|
||||
'annex' => 'checkAnnex',
|
||||
'init_invoice_amount' => 'float|egt:0',
|
||||
'credit_limit' => 'float|egt:0',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 参数描述
|
||||
* @var string[]
|
||||
*/
|
||||
protected $field = [
|
||||
'id' => 'id',
|
||||
'create_user_id' => '建档人id',
|
||||
'org_id' => '组织id',
|
||||
'dept_id' => '部门id',
|
||||
'supplier_name' => '供应商名称',
|
||||
protected $message = [
|
||||
'id.require' => '缺少必要参数',
|
||||
'create_user_id.require' => '请选择建档人',
|
||||
'org_id.require' => '请选择组织',
|
||||
'dept_id.require' => '请选择部门',
|
||||
'supplier_name.require' => '请填写供应商名称',
|
||||
'contacts_sex.in' => '联系人性别无效',
|
||||
'birthday.dateFormat' => '出生日期数据格式错误',
|
||||
'init_invoice_amount.float' => '期初未开票金额值必须是数字',
|
||||
'init_invoice_amount.egt' => '期初未开票金额值必须大于等于0',
|
||||
'credit_limit.float' => '授信额度值必须是数字',
|
||||
'credit_limit.egt' => '授信额度值必须大于等于0',
|
||||
];
|
||||
|
||||
|
||||
@ -60,7 +74,7 @@ class SupplierValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['create_user_id','org_id','dept_id','supplier_name']);
|
||||
return $this->remove('id',true);
|
||||
}
|
||||
|
||||
|
||||
@ -71,9 +85,7 @@ class SupplierValidate extends BaseValidate
|
||||
* @date 2023/12/26 10:56
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','create_user_id','org_id','dept_id','supplier_name']);
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
@ -98,5 +110,73 @@ class SupplierValidate extends BaseValidate
|
||||
{
|
||||
return $this->only(['id']);
|
||||
}
|
||||
|
||||
public function checkCreateUser($value): bool|string
|
||||
{
|
||||
$user = Admin::where('id',$value)->findOrEmpty();
|
||||
if($user->isEmpty()){
|
||||
return '建档人信息不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkOrg($value): bool|string
|
||||
{
|
||||
$org = Orgs::where('id',$value)->findOrEmpty();
|
||||
if($org->isEmpty()) {
|
||||
return '组织不存在';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkDept($value,$rule,$data): bool|string
|
||||
{
|
||||
$dept = Dept::where('id',$value)->findOrEmpty();
|
||||
if($dept->isEmpty()){
|
||||
return '部门不存在';
|
||||
}
|
||||
if($dept['org_id'] != $data['org_id']){
|
||||
return '当前部门不属于所选择的组织';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkSupplierGroup($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','supplier_group')->column('value');
|
||||
if(!in_array($value,$dict)){
|
||||
return '供应商分组无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkSupplierCategory($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','supplier_category')->column('value');
|
||||
if(!in_array($value,$dict)){
|
||||
return '供应商分类无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkSupplierGrade($value): bool|string
|
||||
{
|
||||
$dict = DictData::where('type_value','supplier_grade')->column('value');
|
||||
if(!in_array($value,$dict)){
|
||||
return '供应商等级无效';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function checkAnnex($value): bool|string
|
||||
{
|
||||
if(!empty($value) && $value != ''){
|
||||
$annex = json_decode($value,true);
|
||||
if(empty($annex) || !is_array($annex)){
|
||||
return '附件格式错误';
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ namespace app\common\model\supplier;
|
||||
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\dict\DictData;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
|
||||
@ -29,32 +30,45 @@ class Supplier extends BaseModel
|
||||
use SoftDelete;
|
||||
protected $name = 'supplier';
|
||||
protected $deleteTime = 'delete_time';
|
||||
|
||||
/**
|
||||
* @notes 关联org
|
||||
* @return \think\model\relation\HasOne
|
||||
* @author likeadmin
|
||||
* @date 2023/12/19 15:18
|
||||
*/
|
||||
public function org()
|
||||
{
|
||||
return $this->hasOne(\app\common\model\dept\Orgs::class, 'id', 'org_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 关联dept
|
||||
* @return \think\model\relation\HasOne
|
||||
* @author likeadmin
|
||||
* @date 2023/12/19 15:18
|
||||
*/
|
||||
public function dept()
|
||||
{
|
||||
return $this->hasOne(\app\common\model\dept\Dept::class, 'id', 'dept_id');
|
||||
}
|
||||
|
||||
public function contact()
|
||||
{
|
||||
return $this->hasMany(\app\common\model\supplier\SupplierContacts::class, 'supplier_id', 'id');
|
||||
}
|
||||
|
||||
|
||||
public function getAnnexAttr($value)
|
||||
{
|
||||
return empty($value) ? null : json_decode($value,true);
|
||||
}
|
||||
|
||||
public function getSupplierPhotosAttr($value)
|
||||
{
|
||||
return empty($value) ? null : json_decode($value,true);
|
||||
}
|
||||
|
||||
public function getBirthdayAttr($value): string
|
||||
{
|
||||
return !empty($value) ? date('Y-m-d',$value) : '';
|
||||
}
|
||||
|
||||
//
|
||||
public function getContactsSexTextAttr($value,$data): string
|
||||
{
|
||||
$sex = [0=>'男',1=>'女'];
|
||||
return $sex[$data['contacts_sex']];
|
||||
}
|
||||
|
||||
public function getSupplierGroupTextAttr($value,$data): string
|
||||
{
|
||||
$dict = DictData::where('type_value','supplier_group')->column('name','value');
|
||||
return $dict[$data['supplier_group']];
|
||||
}
|
||||
|
||||
public function getSupplierCategoryTextAttr($value,$data): string
|
||||
{
|
||||
$dict = DictData::where('type_value','supplier_category')->column('name','value');
|
||||
return $dict[$data['supplier_category']];
|
||||
}
|
||||
|
||||
public function getSupplierGradeTextAttr($value,$data): string
|
||||
{
|
||||
$dict = DictData::where('type_value','supplier_grade')->column('name','value');
|
||||
return $dict[$data['supplier_grade']];
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user