TemplateMessageRepository.php 2.8 KB

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