DeliveryServiceServices.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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\services\order;
  12. use app\dao\order\DeliveryServiceDao;
  13. use app\services\BaseServices;
  14. use app\services\message\service\StoreServiceLogServices;
  15. use app\services\user\UserServices;
  16. use crmeb\exceptions\AdminException;
  17. use crmeb\services\FormBuilder;
  18. /**
  19. * 配送
  20. * Class DeliveryServiceServices
  21. * @package app\services\order
  22. * @method getStoreServiceOrderNotice() 获取接受通知的客服
  23. */
  24. class DeliveryServiceServices extends BaseServices
  25. {
  26. /**
  27. * 创建form表单
  28. * @var Form
  29. */
  30. protected $builder;
  31. /**构造方法
  32. * DeliveryServiceServices constructor.
  33. * @param DeliveryServiceDao $dao
  34. * @param FormBuilder $builder
  35. */
  36. public function __construct(DeliveryServiceDao $dao, FormBuilder $builder)
  37. {
  38. $this->dao = $dao;
  39. $this->builder = $builder;
  40. }
  41. /**
  42. * 获取配送员列表
  43. * @param array $where
  44. * @return array
  45. * @throws \think\db\exception\DataNotFoundException
  46. * @throws \think\db\exception\DbException
  47. * @throws \think\db\exception\ModelNotFoundException
  48. */
  49. public function getServiceList(array $where)
  50. {
  51. [$page, $limit] = $this->getPageValue();
  52. $list = $this->dao->getServiceList($where, $page, $limit);
  53. $count = $this->dao->count($where);
  54. return compact('list', 'count');
  55. }
  56. /**
  57. *获取配送员列表
  58. */
  59. public function getDeliveryList()
  60. {
  61. [$page, $limit] = $this->getPageValue();
  62. [$list, $count] = $this->dao->getList($page, $limit);
  63. return compact('list', 'count');
  64. }
  65. /**
  66. * 创建配送员表单
  67. * @param array $formData
  68. * @return mixed
  69. * @throws \FormBuilder\Exception\FormBuilderException
  70. */
  71. public function createServiceForm(array $formData = [])
  72. {
  73. if ($formData) {
  74. $field[] = $this->builder->frameImage('avatar', '配送员头像', $this->url('admin/widget.images/index', ['fodder' => 'avatar'], true), $formData['avatar'] ?? '')->icon('ios-add')->width('950px')->height('505px')->modal(['footer-hide' => true]);
  75. } else {
  76. $field[] = $this->builder->frameImage('image', '商城用户', $this->url('admin/system.user/list', ['fodder' => 'image'], true))->icon('ios-add')->width('950px')->height('505px')->modal(['footer-hide' => true])->Props(['srcKey' => 'image']);
  77. $field[] = $this->builder->hidden('uid', 0);
  78. $field[] = $this->builder->hidden('avatar', '');
  79. }
  80. $field[] = $this->builder->input('nickname', '配送员名称', $formData['nickname'] ?? '')->required('请填写名称')->col(24);
  81. $field[] = $this->builder->input('phone', '手机号码', $formData['phone'] ?? '')->required('请填写电话')->col(24)->maxlength(11);
  82. $field[] = $this->builder->radio('status', '配送员状态', $formData['status'] ?? 1)->options([['value' => 1, 'label' => '显示'], ['value' => 0, 'label' => '隐藏']]);
  83. return $field;
  84. }
  85. /**
  86. * 创建配送员获取表单
  87. * @return array
  88. * @throws \FormBuilder\Exception\FormBuilderException
  89. */
  90. public function create()
  91. {
  92. return create_form('添加配送员', $this->createServiceForm(), $this->url('/order/delivery/save'), 'POST');
  93. }
  94. /**
  95. * 编辑获取表单
  96. * @param int $id
  97. * @return array
  98. * @throws \FormBuilder\Exception\FormBuilderException
  99. */
  100. public function edit(int $id)
  101. {
  102. $serviceInfo = $this->dao->get($id);
  103. if (!$serviceInfo) {
  104. throw new AdminException('数据不存在!');
  105. }
  106. return create_form('编辑配送员', $this->createServiceForm($serviceInfo->toArray()), $this->url('/order/delivery/update/' . $id), 'PUT');
  107. }
  108. /**
  109. * 获取某人的聊天记录用户列表
  110. * @param int $uid
  111. * @return array|array[]
  112. * @throws \think\db\exception\DataNotFoundException
  113. * @throws \think\db\exception\DbException
  114. * @throws \think\db\exception\ModelNotFoundException
  115. */
  116. public function getChatUser(int $uid)
  117. {
  118. /** @var StoreServiceLogServices $serviceLog */
  119. $serviceLog = app()->make(StoreServiceLogServices::class);
  120. /** @var UserServices $serviceUser */
  121. $serviceUser = app()->make(UserServices::class);
  122. $uids = $serviceLog->getChatUserIds($uid);
  123. if (!$uids) {
  124. return [];
  125. }
  126. return $serviceUser->getUserList(['uid' => $uids], 'nickname,uid,avatar as headimgurl');
  127. }
  128. /**
  129. * 检查用户是否是配送员
  130. * @param int $uid
  131. * @return bool
  132. * @throws \think\db\exception\DataNotFoundException
  133. * @throws \think\db\exception\DbException
  134. * @throws \think\db\exception\ModelNotFoundException
  135. */
  136. public function checkoutIsService(int $uid)
  137. {
  138. return (bool)$this->dao->count(['uid' => $uid, 'status' => 1]);
  139. }
  140. }