TemplateMessageRepository.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\repositories\wechat;
  12. use app\common\dao\wechat\TemplateMessageDao;
  13. use app\common\repositories\BaseRepository;
  14. use FormBuilder\Factory\Elm;
  15. use think\facade\Config;
  16. use think\facade\Route;
  17. /**
  18. * Class TemplateMessageRepository
  19. * @package app\common\repositories\wechat
  20. * @mixin TemplateMessageDao
  21. */
  22. class TemplateMessageRepository extends BaseRepository
  23. {
  24. /**
  25. * @var TemplateMessageDao
  26. */
  27. public $dao;
  28. /**
  29. * TemplateMessageRepository constructor.
  30. * @param TemplateMessageDao $dao
  31. */
  32. public function __construct(TemplateMessageDao $dao)
  33. {
  34. $this->dao = $dao;
  35. }
  36. public function getList($wereh,$page,$limit)
  37. {
  38. $query = $this->dao->search($wereh);
  39. $count = $query->count();
  40. $list = $query->page($page,$limit)->select();
  41. return compact('count','list');
  42. }
  43. /**
  44. * TODO
  45. * @param int|null $id
  46. * @param int $type
  47. * @return \FormBuilder\Form
  48. * @author Qinii
  49. * @day 2020-06-19
  50. */
  51. public function form(?int $id = null,$type = 0)
  52. {
  53. $form = Elm::createForm(Route::buildUrl('systemTemplateMessageCreate')->build());
  54. $form->setRule([
  55. Elm::hidden('type',$type),
  56. Elm::input('tempkey','模板编号'),
  57. Elm::input('name','模板名'),
  58. Elm::input('tempid','模板ID'),
  59. Elm::textarea('content','回复内容'),
  60. Elm::switches('status','状态',1)->activeValue(1)->inactiveValue(0)->inactiveText('关闭')->activeText('开启'),
  61. ]);
  62. return $form->setTitle(is_null($id) ? '添加' : '编辑');
  63. }
  64. /**
  65. * TODO
  66. * @param $id
  67. * @return \FormBuilder\Form
  68. * @author Qinii
  69. * @day 2020-06-19
  70. */
  71. public function updateForm($id)
  72. {
  73. $tem = $this->dao->get($id);
  74. $form = Elm::createForm(Route::buildUrl('systemTemplateMessageUpdate',['id' => $id])->build());
  75. $form->setRule([
  76. Elm::hidden('type',$tem['type']),
  77. Elm::input('tempkey','模板编号',$tem['tempkey'])->disabled(1),
  78. Elm::input('name','模板名',$tem['name'])->disabled(1),
  79. Elm::input('tempid','模板ID',$tem['tempid']),
  80. Elm::switches('status','状态',$tem['status'])->activeValue(1)->inactiveValue(0)->inactiveText('关闭')->activeText('开启'),
  81. ]);
  82. return $form->setTitle('编辑');
  83. }
  84. public function getSubscribe()
  85. {
  86. $res = [];
  87. $data = $this->dao->search(['type' => 0])->column('tempid','tempkey');
  88. $arr = Config::get('template.stores.subscribe.template_id');
  89. foreach ($arr as $k => $v){
  90. $res[$k] = $data[$v];
  91. }
  92. return $res;
  93. }
  94. }