AgreementServices.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\other;
  12. use app\dao\other\AgreementDao;
  13. use app\services\BaseServices;
  14. use crmeb\exceptions\AdminException;
  15. /**
  16. * Class AgreementServices
  17. * @package app\services\other
  18. */
  19. class AgreementServices extends BaseServices
  20. {
  21. public function __construct(AgreementDao $dao)
  22. {
  23. $this->dao = $dao;
  24. }
  25. /** 修改协议内容
  26. * @param array $where
  27. * @param $content
  28. * @return bool|\crmeb\basic\BaseModel
  29. */
  30. public function saveAgreement(array $data, $id = 0)
  31. {
  32. if (!$data) return false;
  33. if (!isset($data['type']) || !$data['type'] || $data['type'] == 0) throw new AdminException(400548);
  34. if (!isset($data['title']) || !$data['title']) throw new AdminException(400549);
  35. if (!isset($data['content']) || !$data['content']) throw new AdminException(400550);
  36. if (!$id) {
  37. $getOne = $this->getAgreementBytype($data['type']);
  38. if ($getOne) throw new AdminException(400551);
  39. }
  40. return $this->dao->saveAgreement($data, $id);
  41. }
  42. /**获取会员协议
  43. * @param $type
  44. * @return array|\think\Model|null
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. */
  49. public function getAgreementBytype($type)
  50. {
  51. if (!$type) return [];
  52. $data = $this->dao->getOne(['type' => $type]);
  53. return $data ? $data->toArray() : [];
  54. }
  55. }