SystemNoticeConfigDao.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\dao\system\notice;
  12. use app\common\dao\BaseDao;
  13. use app\common\model\system\notice\SystemNoticeConfig;
  14. class SystemNoticeConfigDao extends BaseDao
  15. {
  16. protected function getModel(): string
  17. {
  18. return SystemNoticeConfig::class;
  19. }
  20. public function getNoticeStatusByKey(string $key, string $field)
  21. {
  22. $value = $this->getModel()::getDb()->where('notice_key',$key)->value($field);
  23. return $value == 1 ? true : false;
  24. }
  25. public function getNoticeStatusByConstKey(string $key)
  26. {
  27. $value = $this->getModel()::getDb()->where('const_key',$key)->field('notice_sys,notice_wechat,notice_routine,notice_sms')->find();
  28. return $value;
  29. }
  30. public function search($where)
  31. {
  32. $query = $this->getModel()::getDb()
  33. ->when(isset($where['is_sms']) && $where['is_sms'] != '', function($query){
  34. $query->whereIn('notice_sms',[0,1]);
  35. })
  36. ->when(isset($where['is_routine']) && $where['is_routine'] != '', function($query){
  37. $query->whereIn('notice_routine',[0,1]);
  38. })
  39. ->when(isset($where['is_wechat']) && $where['is_wechat'] != '', function($query){
  40. $query->whereIn('notice_wechat',[0,1]);
  41. })
  42. ;
  43. return $query;
  44. }
  45. public function getSubscribe()
  46. {
  47. $arr = [];
  48. $res = $this->search([])->where(['notice_routine' => 1])->with(['routineTemplate'])->select()->toArray();
  49. foreach ($res as $re) {
  50. $arr[$re['const_key']] = $re['routineTemplate']['tempid'] ?? '';
  51. }
  52. return $arr;
  53. }
  54. }