Department.php 3.3 KB
<?php
namespace app\products\controller;

use app\web\controller\BaseController;
use think\Db;
use think\Request;
use util\MCurl;
use think\Cookie;
use think\Session;
use app\common\model\products\department as departmentModel;
header("Content-type: text/html; charset=utf-8");
header('Access-Control-Allow-Origin:*');
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
/**
 * 功能描述  妇记通获客
 * Class Product
 * @package app\FuJiTong\controller
 * Date: 2021/5/6
 * Time: 10:00
 * @author nyq
 */
class Department extends BaseController
{

    /**
     * Notes:函数功能描述 获取部门列表
     * User: 张佳
     * DateTime: 2021/6/9 18:00
     */
    public function department_list(Request $request)
    {
        $data = $request->param();
        $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
        $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
        $offset=($page-1)*$rows;
        $data['offset']=$offset;
        $data['rows']=$rows;
        $where=[];

        if(!empty($data['result'])){
            $where['departmentName']=['like', '%' . $data['result'] . '%'];
        }
        //$org_id = session('organization.org_id');
        $list= Db::table('sos_user_department')->alias('d')->join("sos_user_mechanism m", "m.id=d.mechanismId")->field('d.id,d.departmentName,d.createTime,mechanismName')->where($where)->limit($offset,$rows)->select()->toArray();
        $total= Db::table('sos_user_department')->where($where)->count();

        foreach($list  as $key=>$val ){
            $list[$key]['createTime']=$val['createTime'] == ''? '' : date('Y-m-d H:i:s',$val['createTime']);
        }
        $result["total"] =$total;
        $result['rows']=$list;
        echo json_encode($result);
    }

    /**
     * Notes:函数功能描述 新增部门
     * User: 张佳
     * DateTime: 2021/6/10 10:55
     */
    public function department_add(Request $request)
    {
        $data = $request->param();
        if(isset($data['id'])){

            $info = [
                'mechanismId'=>$data['mechanism'],
                'departmentName'=>$data['name'],
            ];

            $res = Db::table('sos_user_department')->where(['id'=>$data['id']])->update($info);
            if($res){
                return json(['code'=>200,'msg'=>'修改部门成功']);
            }else{
                return json(['code'=>100,'msg'=>'修改部门失败']);
            }
        }
        $info = [
            'mechanismId'=>$data['mechanism'],
            'departmentName'=>$data['name'],
            'createTime'=>time()
        ];
        $res = Db::table('sos_user_department')->insert($info);
        if($res){
            return json(['code'=>200,'msg'=>'新增部门成功']);
        }else{
            return json(['code'=>100,'msg'=>'新增部门失败']);
        }
    }

    /**
     * Notes:函数功能描述  获取部门详情
     * User: 张佳
     * DateTime: 2021/6/10 11:07
     */
    public function getDepartment(Request $request)
    {
        $data = $request->param();
        $res = Db::table('sos_user_department')->where(['id'=>$data['id']])->find();
        return $res;
    }


}