Index.php 3.91 KB
<?php

namespace addons\fastflow\controller;

use addons\qingdong\controller\StaffApi;
use addons\qingdong\model\ExamineRecord;
use addons\qingdong\model\Flow;
use think\Db;
use think\Exception;

class Index extends StaffApi
{
    protected $noNeedLogin = ['*'];


    public function index()
    {

        $list = Db::name('fastflow_bill_rule')->select();

        foreach ($list as &$item){
            $item['title'] = json_decode($item['title']);
        }
        $this->success('',$list);

    }



    //发起审批
    public function startBill(){

        $param = $this->request->param();

        $models = $param['models'];

        unset($param['models']);
        unset($param['addon']);
        unset($param['controller']);
        unset($param['action']);


        $param['initiator_id'] = $this->auth->id;
        $param['status'] = 1;
        $param['createtime'] = time();
        $param['updatetime'] = time();


        //halt($this->auth->id);
        Db::startTrans();
        try {

            DB::table($models)->insert($param);
            $bill_id = Db::table($models)->getLastInsID();
            $flow_id = (new \app\admin\model\fastflow\flow\Flow())->where('bill',$models)->value('id');

            $data = [
                'bill'=>$models,
                'bill_id'=>$bill_id,
                'ebill_id'=>'',
                'flow_id'=>$flow_id,
                'checkcontent'=>'',
                'file_name'=>'',
                'file'=>'',
                'carbon_scope'=>'1',
                'carbon_receiver'=>'',
                'carbon_range'=>'1',

            ];
            $res = (new Run())->start($data);

            Db::commit();;
        } catch (Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }

        $this->success();

    }

    //发起审批
    public function agreeBill(){


        $param = $this->request->param();

        $thread_id= $param['thread_id'];

        unset($param['thread_id']);
        unset($param['addon']);
        unset($param['controller']);
        unset($param['action']);


        $result = false;
        Db::startTrans();
        try {

            $data = [
                'thread_id'=>$thread_id,

                'checkcontent'=>'',
                'file_name'=>'',
                'file'=>'',
                'carbon_scope'=>'1',
                'carbon_receiver'=>'',
                'carbon_range'=>'1',
                'start'=>1,

            ];
            $res = (new Run())->agree($data);


            if($res['code'] == 0){
                $msg = $res['msg'];
            }else{
                $result = true;
            }
            Db::commit();
        } catch (Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }

        if ($result === false) {
            $this->error($msg);
        }
        $this->success();


    }


    //拒绝
    public function backBill(){


        $param = $this->request->param();

        $thread_id= $param['thread_id'];

        unset($param['thread_id']);
        unset($param['addon']);
        unset($param['controller']);
        unset($param['action']);


        $result = false;
        Db::startTrans();
        try {

            $data = [
                'thread_id'=>$thread_id,

                'checkcontent'=>'',
                'file_name'=>'',
                'file'=>'',
                'carbon_scope'=>'1',
                'carbon_receiver'=>'',
                'carbon_range'=>'1',

            ];
            $res = (new Run())->back($data);


            if($res['code'] == 0){
                $msg = $res['msg'];
            }else{
                $result = true;
            }
            Db::commit();
        } catch (Exception $e) {
            Db::rollback();
            $this->error($e->getMessage());
        }

        if ($result === false) {
            $this->error($msg);
        }
        $this->success();


    }











}