Staff.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/9/22
  8. * Time: 13:37
  9. */
  10. namespace business\common\models;
  11. use app\common\models\BaseModel;
  12. use app\common\models\Member;
  13. use business\common\services\SettingService;
  14. use Illuminate\Database\Eloquent\Builder;
  15. use Illuminate\Database\Eloquent\SoftDeletes;
  16. use Yunshop\GroupDevelopUser\common\models\GroupMemberLog;
  17. class Staff extends BaseModel
  18. {
  19. public $table = 'yz_business_staff';
  20. public $timestamps = true;
  21. protected $guarded = [];
  22. protected $appends = ['userid','avatar_mediaid'];
  23. protected $casts = [];
  24. const STATUS_UNCONNECT = 0;
  25. const STATUS_ACTIVE = 1;
  26. const STATUS_BAN = 2;
  27. const STATUS_UNACTIVE = 4;
  28. const STATUS_LEAVE = 5;
  29. const GENDER_DESC = [
  30. '0' => '未知',
  31. '1' => '男',
  32. '2' => '女',
  33. ];
  34. const STATUS_DESC = [
  35. self::STATUS_UNCONNECT => '未关联',
  36. self::STATUS_ACTIVE => '已激活',
  37. self::STATUS_BAN => '已禁用',
  38. self::STATUS_UNACTIVE => '未激活',
  39. self::STATUS_LEAVE => '退出企业',
  40. ];
  41. use SoftDeletes;
  42. public function getUseridAttribute()
  43. {
  44. return $this->attributes['user_id'];
  45. }
  46. public function getAvatarMediaidAttribute()
  47. {
  48. return $this->attributes['avatar'];
  49. }
  50. public static function business($business_id = 0)
  51. {
  52. $business_id = $business_id ?: SettingService::getBusinessId();
  53. return self::uniacid()->where('business_id', $business_id);
  54. }
  55. public function hasManyDepartmentStaff()
  56. {
  57. return $this->hasMany(DepartmentStaff::class, 'staff_id', 'id');
  58. }
  59. public function hasOneMember()
  60. {
  61. return $this->hasOne(Member::class, 'uid', 'uid');
  62. }
  63. public function hasOneBusiness()
  64. {
  65. return $this->hasOne(Business::class, 'id', 'business_id');
  66. }
  67. public function getQyWxStaff($staff, $department_id_arr = [], $department_order_arr = [], $department_leader_arr = [])
  68. {
  69. if (is_array($staff)) $staff = (Object)$staff;
  70. return [
  71. 'userid' => $staff->user_id,
  72. 'name' => $staff->name,
  73. 'alias' => $staff->alias ?: '',
  74. 'mobile' => $staff->mobile,
  75. 'department' => $department_id_arr,
  76. 'order' => $department_order_arr,
  77. 'position' => $staff->position ?: '',
  78. 'gender' => in_array($staff->gender, [1, 2]) ? $staff->gender : 0,
  79. 'email' => $staff->email ?: '',
  80. 'telephone' => $staff->telephone ?: '',
  81. 'is_leader_in_dept' => $department_leader_arr,
  82. 'address' => $staff->address ?: ''
  83. ];
  84. }
  85. }