StoreServiceRepository.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. namespace app\common\repositories\store\service;
  3. use app\common\dao\store\service\StoreServiceDao;
  4. use app\common\repositories\BaseRepository;
  5. use FormBuilder\Exception\FormBuilderException;
  6. use FormBuilder\Factory\Elm;
  7. use FormBuilder\Form;
  8. use think\db\exception\DataNotFoundException;
  9. use think\db\exception\DbException;
  10. use think\db\exception\ModelNotFoundException;
  11. use think\facade\Route;
  12. /**
  13. * Class StoreServiceRepository
  14. * @package app\common\repositories\store\service
  15. * @author zfy
  16. * @day 2020/5/29
  17. * @mixin StoreServiceDao
  18. */
  19. class StoreServiceRepository extends BaseRepository
  20. {
  21. /**
  22. * StoreServiceRepository constructor.
  23. * @param StoreServiceDao $dao
  24. */
  25. public function __construct(StoreServiceDao $dao)
  26. {
  27. $this->dao = $dao;
  28. }
  29. /**
  30. * @param array $where
  31. * @param $page
  32. * @param $limit
  33. * @return array
  34. * @throws DataNotFoundException
  35. * @throws DbException
  36. * @throws ModelNotFoundException
  37. * @author zfy
  38. * @day 2020/5/29
  39. */
  40. public function getList(array $where, $page, $limit)
  41. {
  42. $query = $this->dao->search($where)->with(['user' => function ($query) {
  43. $query->field('nickname,avatar,uid');
  44. }]);
  45. $count = $query->count();
  46. $list = $query->page($page, $limit)->select();
  47. return compact('count', 'list');
  48. }
  49. /**
  50. * @return Form
  51. * @throws FormBuilderException
  52. * @author zfy
  53. * @day 2020/5/29
  54. */
  55. public function form()
  56. {
  57. return Elm::createForm(Route::buildUrl('merchantServiceCreate')->build(), [
  58. Elm::frameImage('uid', '用户', '/' . config('admin.merchant_prefix') . '/setting/userList?field=uid&type=1')->prop('srcKey', 'src')->width('675px')->height('500px')->modal(['modal' => false]),
  59. Elm::frameImage('avatar', '客服头像', '/' . config('admin.merchant_prefix') . '/setting/uploadPicture?field=avatar&type=1')->width('896px')->height('480px')->props(['footer' => false])->modal(['modal' => false]),
  60. Elm::input('nickname', '客服昵称')->required(),
  61. Elm::switches('status', '客服状态', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关闭')->activeText('开启'),
  62. Elm::switches('notify', '订单通知', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关闭')->activeText('开启')->control([
  63. [
  64. 'value' => 1,
  65. 'rule' => [
  66. Elm::input('phone', '通知电话')
  67. ]
  68. ]
  69. ]),
  70. Elm::switches('customer', '手机端订单管理', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关闭')->activeText('开启'),
  71. Elm::number('sort', '排序', 0),
  72. Elm::switches('is_verify', '开启核销', 1)->activeValue(1)->inactiveValue(0)->inactiveText('关闭')->activeText('开启'),
  73. ])->setTitle('添加客服');
  74. }
  75. /**
  76. * @param $id
  77. * @return Form
  78. * @throws FormBuilderException
  79. * @throws DataNotFoundException
  80. * @throws DbException
  81. * @throws ModelNotFoundException
  82. * @author zfy
  83. * @day 2020/5/29
  84. */
  85. public function updateForm($id)
  86. {
  87. $service = $this->dao->getWith($id, ['user' => function ($query) {
  88. $query->field('avatar,uid');
  89. }])->toArray();
  90. $service['uid'] = ['id' => $service['uid'], 'src' => $service['user']['avatar']];
  91. unset($service['user']);
  92. return $this->form()->formData($service)->setTitle('编辑表单')->setAction(Route::buildUrl('merchantServiceUpdate', compact('id'))->build());
  93. }
  94. /**
  95. * @param $merId
  96. * @param $uid
  97. * @return array|mixed|\think\Model|null
  98. * @throws DataNotFoundException
  99. * @throws DbException
  100. * @throws ModelNotFoundException
  101. * @author zfy
  102. * @day 2020/5/29
  103. */
  104. public function getChatService($merId, $uid)
  105. {
  106. $logRepository = app()->make(StoreServiceLogRepository::class);
  107. $lastServiceId = $logRepository->getLastServiceId($merId, $uid);
  108. $service = null;
  109. if ($lastServiceId)
  110. $service = $this->getValidServiceInfo($lastServiceId);
  111. if ($service) return $service;
  112. $service = $this->dao->getRandService($merId);
  113. if ($service) return $service;
  114. }
  115. public function getServices($uid, array $where = [])
  116. {
  117. $where['uid'] = $uid;
  118. $where['status'] = 1;
  119. return $this->search($where)->with(['merchant' => function ($query) {
  120. $query->field('mer_id,mer_avatar,mer_name');
  121. }])->select();
  122. }
  123. }