StoreServiceRepository.php 4.9 KB

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