Merge pull request 'update SupplierContacts' (#131) from zhangwei into dev
Reviewed-on: #131
This commit is contained in:
commit
7b7c02c1df
@ -16,9 +16,9 @@
|
|||||||
namespace app\adminapi\controller\supplier;
|
namespace app\adminapi\controller\supplier;
|
||||||
|
|
||||||
|
|
||||||
use app\adminapi\controller\BaseAdminController;
|
use app\adminapi\controller\BaseAdminController;
|
||||||
use app\adminapi\lists\supplier\SupplierContactsLists;
|
use app\adminapi\lists\supplier\SupplierContactsLists;
|
||||||
use app\adminapi\logic\supplier\SupplierContactsLogic;
|
use app\adminapi\logic\supplier\SupplierContactsLogic;
|
||||||
use app\adminapi\validate\supplier\SupplierContactsValidate;
|
use app\adminapi\validate\supplier\SupplierContactsValidate;
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ namespace app\adminapi\lists\supplier;
|
|||||||
|
|
||||||
|
|
||||||
use app\adminapi\lists\BaseAdminDataLists;
|
use app\adminapi\lists\BaseAdminDataLists;
|
||||||
|
use app\common\model\supplier\Supplier;
|
||||||
use app\common\model\supplier\SupplierContacts;
|
use app\common\model\supplier\SupplierContacts;
|
||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
@ -38,7 +39,8 @@ class SupplierContactsLists extends BaseAdminDataLists implements ListsSearchInt
|
|||||||
public function setSearch(): array
|
public function setSearch(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'=' => ['sc.supplier_id', 'sc.name', 'sc.contacts_type'],
|
'=' => ['supplier_id','contacts_type','contacts_cate','sex'],
|
||||||
|
'%like%' => ['name']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,16 +56,18 @@ class SupplierContactsLists extends BaseAdminDataLists implements ListsSearchInt
|
|||||||
*/
|
*/
|
||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return Db::name('SupplierContacts')->alias('sc')
|
return SupplierContacts::where($this->searchWhere)
|
||||||
->where($this->searchWhere)
|
->field('id,name,sex,birthday,contacts_type,responsible,contacts_cate,department,duties,work_phone,remark')
|
||||||
->whereNull('sc.delete_time')
|
|
||||||
->leftJoin('Supplier s','s.id = sc.supplier_id')
|
|
||||||
->field('sc.*, s.supplier_code, s.supplier_name')
|
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['sc.id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()->each(function($item, $key){
|
->select()->each(function($data){
|
||||||
//关联数据后续添加
|
$supplier = Supplier::field('supplier_code,supplier_name')->where('id',$data['supplier_id'])->findOrEmpty();
|
||||||
return $item;
|
$data['supplier_code'] = $supplier['supplier_code'];
|
||||||
|
$data['supplier_name'] = $supplier['supplier_name'];
|
||||||
|
$data['sex_text'] = $data->sex_text;
|
||||||
|
$data['contacts_type_text'] = $data->contacts_type_text;
|
||||||
|
$data['contacts_cate_text'] = $data->contacts_cate_text;
|
||||||
|
return $data;
|
||||||
})
|
})
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
namespace app\adminapi\logic\supplier;
|
namespace app\adminapi\logic\supplier;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\supplier\Supplier;
|
||||||
use app\common\model\supplier\SupplierContacts;
|
use app\common\model\supplier\SupplierContacts;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
@ -41,14 +42,14 @@ class SupplierContactsLogic extends BaseLogic
|
|||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
SupplierContacts::create([
|
SupplierContacts::create([
|
||||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
'supplier_id' => $params['supplier_id'],
|
||||||
'name' => $params['name'] ?? '',
|
'name' => $params['name'],
|
||||||
'sex' => $params['sex'] ?? 0,
|
'sex' => $params['sex'] ?? 0,
|
||||||
'birthday' => $params['birthday'] ?? '',
|
'birthday' => !empty($params['birthday']) ? strtotime($params['birthday']) : 0,
|
||||||
'contacts_type' => $params['contacts_type'] ?? 0,
|
'contacts_type' => $params['contacts_type'] ?? 0,
|
||||||
'responsible' => $params['responsible'] ?? '',
|
'responsible' => $params['responsible'] ?? '',
|
||||||
'title' => $params['title'] ?? '',
|
'title' => $params['title'] ?? '',
|
||||||
'contacts_cate' => $params['contacts_cate'] ?? '',
|
'contacts_cate' => $params['contacts_cate'] ?? 0,
|
||||||
'department' => $params['department'] ?? '',
|
'department' => $params['department'] ?? '',
|
||||||
'duties' => $params['duties'] ?? '',
|
'duties' => $params['duties'] ?? '',
|
||||||
'work_phone' => $params['work_phone'] ?? '',
|
'work_phone' => $params['work_phone'] ?? '',
|
||||||
@ -60,9 +61,8 @@ class SupplierContactsLogic extends BaseLogic
|
|||||||
'id_type' => $params['id_type'] ?? 0,
|
'id_type' => $params['id_type'] ?? 0,
|
||||||
'idcard' => $params['idcard'] ?? '',
|
'idcard' => $params['idcard'] ?? '',
|
||||||
'remark' => $params['remark'] ?? '',
|
'remark' => $params['remark'] ?? '',
|
||||||
'annex' => $params['annex'] ?? '',
|
'annex' => !empty($params['annex']) ? $params['annex'] : null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -85,14 +85,14 @@ class SupplierContactsLogic extends BaseLogic
|
|||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
SupplierContacts::where('id', $params['id'])->update([
|
SupplierContacts::where('id', $params['id'])->update([
|
||||||
'supplier_id' => $params['supplier_id'] ?? 0,
|
'supplier_id' => $params['supplier_id'],
|
||||||
'name' => $params['name'] ?? '',
|
'name' => $params['name'],
|
||||||
'sex' => $params['sex'] ?? 0,
|
'sex' => $params['sex'] ?? 0,
|
||||||
'birthday' => $params['birthday'] ?? '',
|
'birthday' => !empty($params['birthday']) ? strtotime($params['birthday']) : 0,
|
||||||
'contacts_type' => $params['contacts_type'] ?? 0,
|
'contacts_type' => $params['contacts_type'] ?? 0,
|
||||||
'responsible' => $params['responsible'] ?? '',
|
'responsible' => $params['responsible'] ?? '',
|
||||||
'title' => $params['title'] ?? '',
|
'title' => $params['title'] ?? '',
|
||||||
'contacts_cate' => $params['contacts_cate'] ?? '',
|
'contacts_cate' => $params['contacts_cate'] ?? 0,
|
||||||
'department' => $params['department'] ?? '',
|
'department' => $params['department'] ?? '',
|
||||||
'duties' => $params['duties'] ?? '',
|
'duties' => $params['duties'] ?? '',
|
||||||
'work_phone' => $params['work_phone'] ?? '',
|
'work_phone' => $params['work_phone'] ?? '',
|
||||||
@ -104,9 +104,9 @@ class SupplierContactsLogic extends BaseLogic
|
|||||||
'id_type' => $params['id_type'] ?? 0,
|
'id_type' => $params['id_type'] ?? 0,
|
||||||
'idcard' => $params['idcard'] ?? '',
|
'idcard' => $params['idcard'] ?? '',
|
||||||
'remark' => $params['remark'] ?? '',
|
'remark' => $params['remark'] ?? '',
|
||||||
'annex' => $params['annex'] ?? '',
|
'annex' => !empty($params['annex']) ? $params['annex'] : null,
|
||||||
|
'update_time' => time(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -139,8 +139,14 @@ class SupplierContactsLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function detail($params): array
|
public static function detail($params): array
|
||||||
{
|
{
|
||||||
$supplierContacts = SupplierContacts::findOrEmpty($params['id']);
|
$data = SupplierContacts::findOrEmpty($params['id']);
|
||||||
$supplierContacts->supplier;
|
$supplier = Supplier::field('supplier_code,supplier_name')->where('id',$data['supplier_id'])->findOrEmpty();
|
||||||
return $supplierContacts->toArray();
|
$data['supplier_code'] = $supplier['supplier_code'];
|
||||||
|
$data['supplier_name'] = $supplier['supplier_name'];
|
||||||
|
$data['sex_text'] = $data->sex_text;
|
||||||
|
$data['contacts_type_text'] = $data->contacts_type_text;
|
||||||
|
$data['contacts_cate_text'] = $data->contacts_cate_text;
|
||||||
|
$data['id_type_text'] = $data->id_type_text;
|
||||||
|
return $data->toArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,6 +15,8 @@
|
|||||||
namespace app\adminapi\validate\supplier;
|
namespace app\adminapi\validate\supplier;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\dict\DictData;
|
||||||
|
use app\common\model\supplier\Supplier;
|
||||||
use app\common\validate\BaseValidate;
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
|
|
||||||
@ -31,22 +33,23 @@ class SupplierContactsValidate extends BaseValidate
|
|||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require',
|
'id' => 'require',
|
||||||
'supplier_id' => 'require',
|
'supplier_id' => 'require|checkSupplier',
|
||||||
'name' => 'require',
|
'name' => 'require',
|
||||||
'contacts_type' => 'require',
|
'sex' => 'in:0,1',
|
||||||
|
'birthday' => 'dateFormat:Y-m-d',
|
||||||
|
'contacts_type' => 'checkContactsType',
|
||||||
|
'contacts_cate' => 'checkContactsCate',
|
||||||
|
'id_type' => 'checkIdType',
|
||||||
|
'annex' => 'checkAnnex'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $message = [
|
||||||
/**
|
'id.require' => '缺少必要参数',
|
||||||
* 参数描述
|
'supplier_id.require' => '请选择供应商',
|
||||||
* @var string[]
|
'name.require' => '请填写姓名',
|
||||||
*/
|
'sex.in' => '性别值无效',
|
||||||
protected $field = [
|
'birthday.dateFormat' => '出生日期数据格式错误',
|
||||||
'id' => 'id',
|
|
||||||
'supplier_id' => '供应商id',
|
|
||||||
'name' => '姓名',
|
|
||||||
'contacts_type' => '联系人分类',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -58,7 +61,7 @@ class SupplierContactsValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneAdd()
|
public function sceneAdd()
|
||||||
{
|
{
|
||||||
return $this->only(['supplier_id','name','contacts_type']);
|
return $this->remove('id',true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -69,9 +72,7 @@ class SupplierContactsValidate extends BaseValidate
|
|||||||
* @date 2023/12/26 13:47
|
* @date 2023/12/26 13:47
|
||||||
*/
|
*/
|
||||||
public function sceneEdit()
|
public function sceneEdit()
|
||||||
{
|
{}
|
||||||
return $this->only(['id','supplier_id','name','contacts_type']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,5 +97,52 @@ class SupplierContactsValidate extends BaseValidate
|
|||||||
{
|
{
|
||||||
return $this->only(['id']);
|
return $this->only(['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkSupplier($value): bool|string
|
||||||
|
{
|
||||||
|
$supplier = Supplier::where('id',$value)->findOrEmpty();
|
||||||
|
if($supplier->isEmpty()){
|
||||||
|
return '供应商信息不存在';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkContactsType($value): bool|string
|
||||||
|
{
|
||||||
|
$dict = DictData::where('type_value','contacts_type')->column('value');
|
||||||
|
if(!in_array($value,$dict)){
|
||||||
|
return '联系人分类无效';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkContactsCate($value): bool|string
|
||||||
|
{
|
||||||
|
$dict = DictData::where('type_value','contacts_cate')->column('value');
|
||||||
|
if(!in_array($value,$dict)){
|
||||||
|
return '联系人类型无效';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkIdType($value): bool|string
|
||||||
|
{
|
||||||
|
$dict = DictData::where('type_value','id_type')->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\BaseModel;
|
||||||
|
use app\common\model\dict\DictData;
|
||||||
use think\model\concern\SoftDelete;
|
use think\model\concern\SoftDelete;
|
||||||
|
|
||||||
|
|
||||||
@ -29,10 +30,39 @@ class SupplierContacts extends BaseModel
|
|||||||
use SoftDelete;
|
use SoftDelete;
|
||||||
protected $name = 'supplier_contacts';
|
protected $name = 'supplier_contacts';
|
||||||
protected $deleteTime = 'delete_time';
|
protected $deleteTime = 'delete_time';
|
||||||
|
|
||||||
public function supplier()
|
public function getAnnexAttr($value)
|
||||||
{
|
{
|
||||||
return $this->belongsTo(\app\common\model\supplier\Supplier::class, 'supplier_id');
|
return empty($value) ? null : json_decode($value,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getBirthdayAttr($value): string
|
||||||
|
{
|
||||||
|
return !empty($value) ? date('Y-m-d',$value) : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSexTextAttr($value,$data): string
|
||||||
|
{
|
||||||
|
$sex = [0=>'男',1=>'女'];
|
||||||
|
return $sex[$data['sex']];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContactsTypeTextAttr($value,$data): string
|
||||||
|
{
|
||||||
|
$dict = DictData::where('type_value','contacts_type')->column('name','value');
|
||||||
|
return $dict[$data['contacts_type']];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContactsCateTextAttr($value,$data): string
|
||||||
|
{
|
||||||
|
$dict = DictData::where('type_value','contacts_cate')->column('name','value');
|
||||||
|
return $dict[$data['contacts_cate']];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIdTypeTextAttr($value,$data): string
|
||||||
|
{
|
||||||
|
$dict = DictData::where('type_value','id_type')->column('name','value');
|
||||||
|
return $dict[$data['id_type']];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user