1
0

UserLogic.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\logics;
  4. use app\model\Employee;
  5. use app\model\Org;
  6. use app\model\User as Model;
  7. use app\model\UserSignLog;
  8. class UserLogic
  9. {
  10. /**
  11. * 检测是否已经抓取过用户信息
  12. *
  13. * @param stirng openid 小程序openid
  14. * @return Array
  15. */
  16. public function getInfo($condition, $field = ['id', 'nickname', 'headimgurl', 'sex', 'subscribe'])
  17. {
  18. $data = Model::where($condition)->find();
  19. if (empty($data)) {
  20. return $data;
  21. }
  22. // 是否是员工
  23. $bindedObj = Employee::where([['uid', '=', $data['id']],['root_id', '=', $data['root_id']], ['state', '<>', '离职']])->find();
  24. $data = $data->visible($field)->toArray();
  25. if ($bindedObj) {
  26. $orgType = Org::where('id', $bindedObj->org_id)->value('org_type');
  27. $binded = [
  28. 'id' => $bindedObj->id,
  29. 'name' => $bindedObj->name,
  30. 'org_name' => $bindedObj->org->name,
  31. 'org_id' => $bindedObj->org_id,
  32. 'isManager' => $bindedObj->is_manager,
  33. 'isNewbie' => $bindedObj->is_newbie,
  34. 'state' => $bindedObj->state,
  35. 'qrcode' => $bindedObj->qrcode,
  36. 'org_type' => $orgType
  37. ];
  38. $data['binded'] = $binded;
  39. }
  40. // 今日是否已签到
  41. $data['sign'] = UserSignLog::where([['user_id', '=', $data['id']], ['date', '=', date('Y-m-d')]])->count();
  42. return $data;
  43. }
  44. /**
  45. * 将小程序中获取到用户信息保存
  46. */
  47. public function saveMiniInfo($data)
  48. {
  49. // 保存个人信息
  50. $miniUser = Model::where(['mini_openid'=>$data['mini_openid'], 'root_id'=>$data['root_id']])->findOrEmpty();
  51. $miniUser->save($data);
  52. // // 检测是否存在
  53. // if (isset($data['phone'])) {
  54. // $employee = Employee::where(['phone' => $data['phone'], 'root_id' => $data['root_id']])->find();
  55. // if ($employee->uid !== $miniUser->id) $employee->uid = $miniUser->id;
  56. // }
  57. return $miniUser;
  58. }
  59. }