FeedbackRepository.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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\repositories\user;
  12. use app\common\dao\user\FeedbackDao;
  13. use app\common\repositories\BaseRepository;
  14. use FormBuilder\Factory\Elm;
  15. use think\exception\ValidateException;
  16. use think\facade\Route;
  17. /**
  18. * Class FeedbackRepository
  19. * @package app\common\repositories\user
  20. * @author xaboy
  21. * @day 2020/5/28
  22. * @mixin FeedbackDao
  23. */
  24. class FeedbackRepository extends BaseRepository
  25. {
  26. /**
  27. * FeedbackRepository constructor.
  28. * @param FeedbackDao $dao
  29. */
  30. public function __construct(FeedbackDao $dao)
  31. {
  32. $this->dao = $dao;
  33. }
  34. public function getList(array $where, $page, $limit)
  35. {
  36. $query = $this->dao->search($where)->with(['type' => function($query){
  37. $query->field('feedback_category_id,cate_name');
  38. }]);
  39. $count = $query->count();
  40. $list = $query->page($page, $limit)->withAttr('images',function($val){
  41. return $val ? json_decode($val, true) : [];
  42. })->select();
  43. return compact('count', 'list');
  44. }
  45. public function get( $id)
  46. {
  47. $data = $this->dao->getWhere([$this->dao->getPk() => $id]);
  48. $type = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $data['type']]);
  49. $parent = app()->make(FeedBackCategoryRepository::class)->getWhere(['feedback_category_id' => $type['pid']]);
  50. $data['type'] = $type['cate_name'];
  51. $data['category'] = $parent['cate_name'];
  52. return $data;
  53. }
  54. public function replyForm($id)
  55. {
  56. $formData = $this->dao->get($id);
  57. if (!$formData) throw new ValidateException('数据不存在');
  58. if ($formData->status == 1) throw new ValidateException('该问题已回复过了');
  59. $form = Elm::createForm(Route::buildUrl('systemUserFeedBackReply',['id' => $id])->build());
  60. $form->setRule([
  61. Elm::textarea('reply', '回复内容'),
  62. ]);
  63. return $form->setTitle('回复用户')->formData($formData->toArray());
  64. }
  65. }