<?php
/**
 * Created by PhpStorm.
 * User: hu jun
 * Date: 2018/2/2
 * Time: 14:28
 */

namespace app\model;


class ADistrict extends BaseModel
{
    /**
     * 添加部门，绑定总监关系
     *
     * @param $data
     * @param $agents_id
     * @return bool
     * @throws \think\exception\PDOException
     */
    public function addDepartmentAgents($data, $agents_id) {
        $this->startTrans();
        $date = date('Y-m-d H:i:s');
        $this->save([
            'district_name' => $data['department_name'],
            'create_time'   => $date
        ]);

        if ($this->id) {
            $agents = new AAgents();
            $agents_edit = $agents->save(['district_id' => $this->id],['id'=>$agents_id]);
            if ($agents_edit) {
                $resutlt = $this->id;
                $this->commit();
            } else {
                $resutlt = false;
                $this->rollback();
            }
        } else {
            $resutlt = false;
            $this->rollback();
        }

        return $resutlt;
    }

}