<?php
namespace app\mobile\controller;

use think\facade\Db;

class OmsCommon extends OmsBase
{
    public function teams()
    {
        return $this->guarded(function () {
            $this->requireMethod('GET');
            $account = $this->current();
            $member = $account['user_id'] ? Db::name('member_list')->find($account['user_id']) : null;
            $teams = Db::name('team_list')->where('status', 1)->field('id,team,project')->order('project,team,id')->select()->toArray();
            $projects = Db::name('team_base')->where('mid', 1)->column('title', 'id');
            foreach ($teams as &$team) {
                $team['id'] = (int)$team['id']; $team['project'] = (int)$team['project'];
                $team['projectName'] = $projects[$team['project']] ?? '其他班组';
            } unset($team);
            return json(['code'=>0, 'message'=>'成功', 'data'=>['teams'=>$teams, 'defaultTeamId'=>(int)($member['tid'] ?? 0)]]);
        });
    }
}
