SystemStoreStaffServices.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\system\store;
  12. use app\dao\system\store\SystemStoreStaffDao;
  13. use app\services\BaseServices;
  14. use crmeb\exceptions\AdminException;
  15. use crmeb\services\FormBuilder;
  16. /**
  17. * 门店店员
  18. * Class SystemStoreStaffServices
  19. * @package app\services\system\store
  20. * @mixin SystemStoreStaffDao
  21. */
  22. class SystemStoreStaffServices extends BaseServices
  23. {
  24. /**
  25. * @var FormBuilder
  26. */
  27. protected $builder;
  28. /**
  29. * 构造方法
  30. * SystemStoreStaffServices constructor.
  31. * @param SystemStoreStaffDao $dao
  32. * @param FormBuilder $builder
  33. */
  34. public function __construct(SystemStoreStaffDao $dao, FormBuilder $builder)
  35. {
  36. $this->dao = $dao;
  37. $this->builder = $builder;
  38. }
  39. /**
  40. * 判断是否是有权限核销的店员
  41. * @param $uid
  42. * @return bool
  43. * @throws \think\db\exception\DataNotFoundException
  44. * @throws \think\db\exception\DbException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. */
  47. public function verifyStatus($uid)
  48. {
  49. return (bool)$this->dao->getOne(['uid' => $uid, 'status' => 1, 'verify_status' => 1]);
  50. }
  51. /**
  52. * 获取店员列表
  53. * @param array $where
  54. * @return array
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\DbException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. */
  59. public function getStoreStaffList(array $where)
  60. {
  61. [$page, $limit] = $this->getPageValue();
  62. $list = $this->dao->getStoreStaffList($where, $page, $limit);
  63. $count = $this->dao->count($where);
  64. return compact('list', 'count');
  65. }
  66. /**
  67. * 获取select选择框中的门店列表
  68. * @return array
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\DbException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. */
  73. public function getStoreSelectFormData()
  74. {
  75. /** @var SystemStoreServices $service */
  76. $service = app()->make(SystemStoreServices::class);
  77. $menus = [];
  78. foreach ($service->getStore() as $menu) {
  79. $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
  80. }
  81. return $menus;
  82. }
  83. /**
  84. * 获取核销员表单
  85. * @param array $formData
  86. * @return mixed
  87. * @throws \FormBuilder\Exception\FormBuilderException
  88. * @throws \think\db\exception\DataNotFoundException
  89. * @throws \think\db\exception\DbException
  90. * @throws \think\db\exception\ModelNotFoundException
  91. */
  92. public function createStoreStaffForm(array $formData = [])
  93. {
  94. if ($formData) {
  95. $field[] = $this->builder->frameImage('image', '更换头像', $this->url(config('app.admin_prefix', 'admin') . '/widget.images/index', array('fodder' => 'image'),true), $formData['avatar'] ?? '')->icon('el-icon-user')->width('950px')->height('560px')->props(['footer' => false]);
  96. } else {
  97. $field[] = $this->builder->frameImage('image', '商城用户', $this->url(config('app.admin_prefix', 'admin') . '/system.User/list', ['fodder' => 'image'], true))->icon('el-icon-user')->width('950px')->height('560px')->Props(['srcKey' => 'image', 'footer' => false]);
  98. }
  99. $field[] = $this->builder->hidden('uid', $formData['uid'] ?? 0);
  100. $field[] = $this->builder->hidden('avatar', $formData['avatar'] ?? '');
  101. $field[] = $this->builder->select('store_id', '所属提货点', ($formData['store_id'] ?? ''))->setOptions($this->getStoreSelectFormData())->filterable(true);
  102. $field[] = $this->builder->input('staff_name', '核销员名称', $formData['staff_name'] ?? '')->col(24)->required();
  103. $field[] = $this->builder->input('phone', '手机号码', $formData['phone'] ?? '')->col(24)->required();
  104. $field[] = $this->builder->radio('verify_status', '核销开关', $formData['verify_status'] ?? 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
  105. $field[] = $this->builder->radio('status', '状态', $formData['status'] ?? 1)->options([['value' => 1, 'label' => '开启'], ['value' => 0, 'label' => '关闭']]);
  106. return $field;
  107. }
  108. /**
  109. * 添加核销员表单
  110. * @return array
  111. * @throws \FormBuilder\Exception\FormBuilderException
  112. * @throws \think\db\exception\DataNotFoundException
  113. * @throws \think\db\exception\DbException
  114. * @throws \think\db\exception\ModelNotFoundException
  115. */
  116. public function createForm()
  117. {
  118. return create_form('添加核销员', $this->createStoreStaffForm(), $this->url('/merchant/store_staff/save/0'));
  119. }
  120. /**
  121. * 编辑核销员form表单
  122. * @param int $id
  123. * @return array
  124. * @throws \FormBuilder\Exception\FormBuilderException
  125. * @throws \think\db\exception\DataNotFoundException
  126. * @throws \think\db\exception\DbException
  127. * @throws \think\db\exception\ModelNotFoundException
  128. */
  129. public function updateForm(int $id)
  130. {
  131. $storeStaff = $this->dao->get($id);
  132. if (!$storeStaff) {
  133. throw new AdminException(100026);
  134. }
  135. return create_form('修改核销员', $this->createStoreStaffForm($storeStaff->toArray()), $this->url('/merchant/store_staff/save/' . $id));
  136. }
  137. }