123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- declare(strict_types=1);
- namespace app\logics;
- use app\model\Employee;
- use app\model\Org;
- use app\model\User as Model;
- use app\model\UserSignLog;
- class UserLogic
- {
- /**
- * 检测是否已经抓取过用户信息
- *
- * @param stirng openid 小程序openid
- * @return Array
- */
- public function getInfo($condition, $field = ['id', 'nickname', 'headimgurl', 'sex', 'subscribe'])
- {
- $data = Model::where($condition)->find();
- if (empty($data)) {
- return $data;
- }
- // 是否是员工
- $bindedObj = Employee::where([['uid', '=', $data['id']],['root_id', '=', $data['root_id']], ['state', '<>', '离职']])->find();
- $data = $data->visible($field)->toArray();
- if ($bindedObj) {
- $orgType = Org::where('id', $bindedObj->org_id)->value('org_type');
- $binded = [
- 'id' => $bindedObj->id,
- 'name' => $bindedObj->name,
- 'org_name' => $bindedObj->org->name,
- 'org_id' => $bindedObj->org_id,
- 'isManager' => $bindedObj->is_manager,
- 'isNewbie' => $bindedObj->is_newbie,
- 'state' => $bindedObj->state,
- 'qrcode' => $bindedObj->qrcode,
- 'org_type' => $orgType
- ];
- $data['binded'] = $binded;
- }
- // 今日是否已签到
- $data['sign'] = UserSignLog::where([['user_id', '=', $data['id']], ['date', '=', date('Y-m-d')]])->count();
- return $data;
- }
- /**
- * 将小程序中获取到用户信息保存
- */
- public function saveMiniInfo($data)
- {
- // 保存个人信息
- $miniUser = Model::where(['mini_openid'=>$data['mini_openid'], 'root_id'=>$data['root_id']])->findOrEmpty();
- $miniUser->save($data);
- // // 检测是否存在
- // if (isset($data['phone'])) {
- // $employee = Employee::where(['phone' => $data['phone'], 'root_id' => $data['root_id']])->find();
- // if ($employee->uid !== $miniUser->id) $employee->uid = $miniUser->id;
- // }
- return $miniUser;
- }
- }
|