diff --git a/app/adminapi/controller/supplier/SupplierContactsController.php b/app/adminapi/controller/supplier/SupplierContactsController.php new file mode 100644 index 000000000..45ae52481 --- /dev/null +++ b/app/adminapi/controller/supplier/SupplierContactsController.php @@ -0,0 +1,108 @@ +dataLists(new SupplierContactsLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public function add() + { + $params = (new SupplierContactsValidate())->post()->goCheck('add'); + $result = SupplierContactsLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(SupplierContactsLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public function edit() + { + $params = (new SupplierContactsValidate())->post()->goCheck('edit'); + $result = SupplierContactsLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(SupplierContactsLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public function delete() + { + $params = (new SupplierContactsValidate())->post()->goCheck('delete'); + SupplierContactsLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public function detail() + { + $params = (new SupplierContactsValidate())->goCheck('detail'); + $result = SupplierContactsLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/supplier/SupplierContactsLists.php b/app/adminapi/lists/supplier/SupplierContactsLists.php new file mode 100644 index 000000000..293993c3e --- /dev/null +++ b/app/adminapi/lists/supplier/SupplierContactsLists.php @@ -0,0 +1,85 @@ + ['sc.supplier_id', 'sc.name', 'sc.contacts_type'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public function lists(): array + { + return Db::name('SupplierContacts')->alias('sc') + ->where($this->searchWhere) + ->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) + ->order(['sc.id' => 'desc']) + ->select()->each(function($item, $key){ + //关联数据后续添加 + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public function count(): int + { + return Db::name('SupplierContacts')->alias('sc') + ->where($this->searchWhere) + ->whereNull('sc.delete_time')->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/supplier/SupplierContactsLogic.php b/app/adminapi/logic/supplier/SupplierContactsLogic.php new file mode 100644 index 000000000..335a2f508 --- /dev/null +++ b/app/adminapi/logic/supplier/SupplierContactsLogic.php @@ -0,0 +1,146 @@ + $params['supplier_id'] ?? 0, + 'name' => $params['name'] ?? '', + 'sex' => $params['sex'] ?? 0, + 'birthday' => $params['birthday'] ?? '', + 'contacts_type' => $params['contacts_type'] ?? 0, + 'responsible' => $params['responsible'] ?? '', + 'title' => $params['title'] ?? '', + 'contacts_cate' => $params['contacts_cate'] ?? '', + 'department' => $params['department'] ?? '', + 'duties' => $params['duties'] ?? '', + 'work_phone' => $params['work_phone'] ?? '', + 'mobile' => $params['mobile'] ?? '', + 'email' => $params['email'] ?? '', + 'fax' => $params['fax'] ?? '', + 'zip_code' => $params['zip_code'] ?? '', + 'family_address' => $params['family_address'] ?? '', + 'id_type' => $params['id_type'] ?? 0, + 'idcard' => $params['idcard'] ?? '', + 'remark' => $params['remark'] ?? '', + 'annex' => $params['annex'] ?? '', + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + SupplierContacts::where('id', $params['id'])->update([ + 'supplier_id' => $params['supplier_id'] ?? 0, + 'name' => $params['name'] ?? '', + 'sex' => $params['sex'] ?? 0, + 'birthday' => $params['birthday'] ?? '', + 'contacts_type' => $params['contacts_type'] ?? 0, + 'responsible' => $params['responsible'] ?? '', + 'title' => $params['title'] ?? '', + 'contacts_cate' => $params['contacts_cate'] ?? '', + 'department' => $params['department'] ?? '', + 'duties' => $params['duties'] ?? '', + 'work_phone' => $params['work_phone'] ?? '', + 'mobile' => $params['mobile'] ?? '', + 'email' => $params['email'] ?? '', + 'fax' => $params['fax'] ?? '', + 'zip_code' => $params['zip_code'] ?? '', + 'family_address' => $params['family_address'] ?? '', + 'id_type' => $params['id_type'] ?? 0, + 'idcard' => $params['idcard'] ?? '', + 'remark' => $params['remark'] ?? '', + 'annex' => $params['annex'] ?? '', + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public static function delete(array $params): bool + { + return SupplierContacts::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public static function detail($params): array + { + $supplierContacts = SupplierContacts::findOrEmpty($params['id']); + $supplierContacts->supplier; + return $supplierContacts->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/supplier/SupplierContactsValidate.php b/app/adminapi/validate/supplier/SupplierContactsValidate.php new file mode 100644 index 000000000..ec8535f20 --- /dev/null +++ b/app/adminapi/validate/supplier/SupplierContactsValidate.php @@ -0,0 +1,100 @@ + 'require', + 'supplier_id' => 'require', + 'name' => 'require', + 'contacts_type' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'supplier_id' => '供应商id', + 'name' => '姓名', + 'contacts_type' => '联系人分类', + ]; + + + /** + * @notes 添加场景 + * @return SupplierContactsValidate + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public function sceneAdd() + { + return $this->only(['supplier_id','name','contacts_type']); + } + + + /** + * @notes 编辑场景 + * @return SupplierContactsValidate + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public function sceneEdit() + { + return $this->only(['id','supplier_id','name','contacts_type']); + } + + + /** + * @notes 删除场景 + * @return SupplierContactsValidate + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return SupplierContactsValidate + * @author likeadmin + * @date 2023/12/26 13:47 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/supplier/SupplierContacts.php b/app/common/model/supplier/SupplierContacts.php new file mode 100644 index 000000000..a0b773f36 --- /dev/null +++ b/app/common/model/supplier/SupplierContacts.php @@ -0,0 +1,38 @@ +belongsTo(\app\common\model\supplier\Supplier::class, 'supplier_id'); + } + +} \ No newline at end of file