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\user\UserServices;
  15. use crmeb\exceptions\AdminException;
  16. use crmeb\services\FormBuilder;
  17. /**
  18. * 配送
  19. * Class DeliveryServiceServices
  20. * @package app\services\order
  21. * @method getStoreServiceOrderNotice() 获取接受通知的客服
  22. */
  23. class DeliveryServiceServices extends BaseServices
  24. {
  25. /**
  26. * 创建form表单
  27. * @var Form
  28. */
  29. protected $builder;
  30. /**构造方法
  31. * DeliveryServiceServices constructor.
  32. * @param DeliveryServiceDao $dao
  33. * @param FormBuilder $builder
  34. */
  35. public function __construct(DeliveryServiceDao $dao, FormBuilder $builder)
  36. {
  37. $this->dao = $dao;
  38. $this->builder = $builder;
  39. }
  40. /**
  41. * 获取配送员列表
  42. * @param array $where
  43. * @return array
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\DbException
  46. * @throws \think\db\exception\ModelNotFoundException
  47. */
  48. public function getServiceList(array $where)
  49. {
  50. [$page, $limit] = $this->getPageValue();
  51. $list = $this->dao->getServiceList($where, $page, $limit);
  52. $count = $this->dao->count($where);
  53. return compact('list', 'count');
  54. }
  55. /**
  56. *获取配送员列表
  57. */
  58. public function getDeliveryList()
  59. {
  60. [$page, $limit] = $this->getPageValue();
  61. [$list, $count] = $this->dao->getList($page, $limit);
  62. return compact('list', 'count');
  63. }
  64. /**
  65. * 创建配送员表单
  66. * @param array $formData
  67. * @return mixed
  68. * @throws \FormBuilder\Exception\FormBuilderException
  69. */
  70. public function createServiceForm(array $formData = [])
  71. {
  72. if ($formData) {
  73. $field[] = $this->builder->frameImage('avatar', '配送员头像', $this->url('admin/widget.images/index', ['fodder' => 'avatar'], true), $formData['avatar'] ?? '')->icon('ios-add')->width('60%')->height('435px');
  74. // $field[] = $this->builder->frameImage('avatar', '用户头像', $this->url('admin/widget.images/index', array('fodder' => 'avatar')))->icon('ios-add')->width('50%')->height('396px');
  75. } else {
  76. $field[] = $this->builder->frameImage('image', '商城用户', $this->url('admin/system.user/list', ['fodder' => 'image'], true))->icon('ios-add')->width('50%')->height('500px')->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 $this->dao->count(['uid' => $uid, 'status' => 1]) ? true : false;
  139. }
  140. }