123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <?php
-
- declare (strict_types = 1);
- namespace app\admin\controller\cpuser;
- use app\admin\BaseController;
- use app\admin\model\Department as DepartmentModel;
- use app\admin\validate\FinancialValidate;
- use think\exception\ValidateException;
- use think\facade\Db;
- use think\facade\View;
- class Financial extends BaseController
- {
- /**
- * 构造函数
- */
- public function __construct()
- {
- $this->model = new DepartmentModel();
- $this->uid = get_login_admin('id');
- }
- /**
- * 数据列表
- */
- public function datalist()
- {
- if (request()->isAjax()) {
- $param = get_params();
- $where = [
- ["delete_time","=",0],
- ["pid","=",0],
- ["type","=",0]
- ];
- $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
- $order = empty($param['order']) ? 'id desc' : $param['order'];
- $list = $this->model->where($where)->field('id,title,leader_id,phone,landline,address,company_type,authorization_module')
- ->order($order)->paginate($rows, false, ['query' => $param])
- ->each(function ($item){
- $data = Db::name("admin")->where("id",$item->leader_id)->find();
- if(!empty($data["nickname"])){
- $item->leader =$data["nickname"];
- }
- if(!empty($data["username"])){
- $item->username = $data["username"];
- }
- if(!empty($data["mobile"])){
- $item->phone = $data["mobile"];
- }
- });
- // halt($list);
- return table_assign(0, '', $list);
- }
- else{
- return view();
- }
- }
- /**
- * 添加
- */
- public function add()
- {
- if (request()->isAjax()) {
- $param = get_params();
-
- // 检验完整性
- // try {
- // validate(FinancialValidate::class)->check($param);
- // } catch (ValidateException $e) {
- // // 验证失败 输出错误信息
- // return to_assign(1, $e->getError());
- // }
- $param = array_merge($param,['type'=>0]);
- try {
- $did = Db::name('Department')->strict(false)->field(true)->insertGetId($param);
- $pid = $did;
- while($pid != 0){
- $value = Db::name('department')->where('id', $pid)->column('id,pid,title')[0];
- $unit_name = $value['id'];
- $pid = $value['pid'];
- $title = $value['title'];
- }
- $unit_name = [
- 'unit_name' => $unit_name,
- ];
- Db::name('Department')->where('id', $did)->update($unit_name);
- add_log('add', $did, $param);
- } catch(\Exception $e) {
- return to_assign(1, '操作失败,原因:'.$e->getMessage());
- }
- return to_assign(0,'操作成功');
- // halt($param);
- }else{
- return view();
- }
- }
-
- /**
- * 编辑
- */
- public function edit()
- {
- $param = get_params();
- // halt($param);
- if (request()->isAjax()) {
- // 检验完整性
- // try {
- // validate(FinancialValidate::class)->check($param);
- // } catch (ValidateException $e) {
- // // 验证失败 输出错误信息
- // return to_assign(1, $e->getError());
- // }
- try {
- $param['update_time'] = time();
- $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param);
- add_log('edit', $param['id'], $param);
- } catch(\Exception $e) {
- return to_assign(1, '操作失败,原因:'.$e->getMessage());
- }
- return to_assign();
- }else{
- $id = isset($param['id']) ? $param['id'] : 0;
- $detail = $this->model->where('id', $id)->find();
- if (!empty($detail)) {
- View::assign('detail', $detail);
- return view();
- }
- else{
- throw new \think\exception\HttpException(404, '找不到页面');
- }
- }
- }
- /**
- * 查看信息
- */
- public function read()
- {
- $param = get_params();
- $id = isset($param['id']) ? $param['id'] : 0;
- $detail = $this->model->where('id', $id)->find();
- if (!empty($detail)) {
- View::assign('detail', $detail);
- return view();
- }
- else{
- throw new \think\exception\HttpException(404, '找不到页面');
- }
- }
- /**
- * 删除
- * type=0,逻辑删除,默认
- * type=1,物理删除
- */
- public function del()
- {
- $param = get_params();
- $id = isset($param['id']) ? $param['id'] : 0;
- $type = isset($param['type']) ? $param['type'] : 0;
- if($type==0){
- //逻辑删除
- try {
- $param['delete_time'] = time();
- $this->model->where('id', $id)->update(['delete_time'=>time()]);
- add_log('delete', $id);
- } catch(\Exception $e) {
- return to_assign(1, '操作失败,原因:'.$e->getMessage());
- }
- }
- else{
- //物理删除
- try {
- $this->model->where('id', $id)->delete();
- add_log('delete', $id);
- } catch(\Exception $e) {
- return to_assign(1, '操作失败,原因:'.$e->getMessage());
- }
- }
- return to_assign();
- }
- }
|