SystemStoreStaff.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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::page((int)$where['page'], (int)$where['limit']);
  41. if (isset($where['store_id']) && $where['store_id'] != '') {
  42. $model = $model->where('store_id', $where['store_id']);
  43. }
  44. // if (isset($where['type']) && $where['type'] != '' && ($data = self::setData($where['type']))) {
  45. // $model = $model->where($data);
  46. // }
  47. $model = $model->alias('a')
  48. ->join('wechat_user u', 'u.uid=a.uid')
  49. ->join('system_store s', 'a.store_id = s.id')
  50. ->field('a.id,u.nickname,a.avatar,a.staff_name,a.status,a.add_time,s.name');
  51. $data = $model->select();
  52. $count = $data->count();
  53. return compact('count', 'data');
  54. }
  55. /**
  56. * 设置查找店员条件
  57. * @param array $where
  58. * @return $this
  59. */
  60. public static function staffWhere(array $where = [])
  61. {
  62. $model = User::where('uid', 'not in', function ($query) {
  63. $query->name('system_store_staff')->field('uid')->select();
  64. });
  65. if (isset($where['nickname']) && $where['nickname']) {
  66. $model->where('nickname|phone', 'like', "%$where[nickname]%");
  67. }
  68. return $model;
  69. }
  70. /**
  71. * 获取选择的商城用户
  72. */
  73. public static function getUserList($page = 1, $limit = 10, $nickname = '')
  74. {
  75. $list = self::staffWhere(['nickname' => $nickname])->page($page, $limit)->select();
  76. $count = self::staffWhere(['nickname' => $nickname])->count();
  77. return ['data' => $list, 'count' => $count];
  78. }
  79. }