SystemStoreStaff.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace app\admin\model\system;
  3. use app\admin\model\user\User;
  4. use crmeb\traits\ModelTrait;
  5. use crmeb\basic\BaseModel;
  6. use crmeb\services\PHPExcelService;
  7. /**
  8. * 店员 model
  9. * Class SystemStore
  10. * @package app\admin\model\system
  11. */
  12. class SystemStoreStaff extends BaseModel
  13. {
  14. use ModelTrait;
  15. /**
  16. * 数据表主键
  17. * @var string
  18. */
  19. protected $pk = 'id';
  20. /**
  21. * 模型名称
  22. * @var string
  23. */
  24. protected $name = 'system_store_staff';
  25. protected function getAddTimeAttr($value)
  26. {
  27. if ($value) $value = date('Y-m-d H:i:s', $value);
  28. return $value;
  29. }
  30. /**
  31. * 获取门店列表
  32. * @param $where
  33. * @return array
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\DbException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. */
  38. public static function lst($where)
  39. {
  40. $model = self::alias('a')
  41. ->join('wechat_user u', 'u.uid=a.uid')
  42. ->join('system_store s', 'a.store_id = s.id')
  43. ->field('a.id,u.nickname,a.avatar,a.staff_name,a.status,a.add_time,s.name');
  44. if (isset($where['store_id']) && $where['store_id'] != '') {
  45. $model = $model->where('store_id', $where['store_id']);
  46. }
  47. if ($where['name']) $model = $model->where('u.uid|u.nickname', '=', $where['name']);
  48. $count = $model->count();
  49. $model = $model->page((int)$where['page'], (int)$where['limit']);
  50. $data = $model->select();
  51. return compact('count', 'data');
  52. }
  53. /**
  54. * 设置查找店员条件
  55. * @param array $where
  56. * @return $this
  57. */
  58. public static function staffWhere(array $where = [])
  59. {
  60. $model = User::where('uid', 'not in', function ($query) {
  61. $query->name('system_store_staff')->field('uid')->select();
  62. });
  63. if (isset($where['nickname']) && $where['nickname']) {
  64. $model->where('nickname|phone', 'like', "%$where[nickname]%");
  65. }
  66. return $model;
  67. }
  68. /**
  69. * 获取选择的商城用户
  70. */
  71. public static function getUserList($page = 1, $limit = 10, $nickname = '')
  72. {
  73. $list = self::staffWhere(['nickname' => $nickname])->page($page, $limit)->select();
  74. $count = self::staffWhere(['nickname' => $nickname])->count();
  75. return ['data' => $list, 'count' => $count];
  76. }
  77. }