1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace app\services\other;
- use app\dao\other\AgreementDao;
- use app\services\BaseServices;
- use think\exception\ValidateException;
- class AgreementServices extends BaseServices
- {
- public function __construct(AgreementDao $dao)
- {
- $this->dao = $dao;
- }
-
- public function saveAgreement(array $data, int $id = 0)
- {
- if (!$data) return false;
- if (!isset($data['type']) || !$data['type'] || $data['type'] == 0) throw new ValidateException('协议类型缺失');
- if (!isset($data['title']) || !$data['title']) throw new ValidateException('请填写协议名称');
- if (!isset($data['content']) || !$data['content']) throw new ValidateException('请填写协议内容');
- if (!$id){
- $getOne = $this->getAgreementBytype($data['type']);
- if ($getOne) throw new ValidateException('该类型协议已经存在');
- }
- return $this->dao->saveAgreement($data, $id);
- }
-
- public function getAgreementBytype($type)
- {
- if (!$type) return [];
- $data = $this->dao->getOne(['type' => $type]);
- return $data ? $data->toArray() : [];
- }
- }
|