| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 | <?phpnamespace App\Admin\Controllers\Company;use App\Http\Controllers\Controller;use App\Models\Invoice;use App\Models\InvoiceCategory;use App\Models\Order;use App\Services\Common\PmsService;use Encore\Admin\Auth\Permission;use Encore\Admin\Controllers\HasResourceActions;use Encore\Admin\Facades\Admin;use Encore\Admin\Form;use Encore\Admin\Grid;use Encore\Admin\Layout\Content;use Encore\Admin\Show;class InvoiceController extends Controller{    use HasResourceActions;    protected $pmsService;    /**     * InvoiceController constructor.     * @param $pmsService     */    public function __construct(PmsService $pmsService)    {        $this->pmsService = $pmsService;    }    /**     * Index interface.     *     * @param Content $content     * @return Content     */    public function index(Content $content)    {        return $content            ->header('发票列表')            ->description('列表')            ->body($this->grid());    }    /**     * Show interface.     *     * @param mixed $id     * @param Content $content     * @return Content     */    public function show($id, Content $content)    {        return $content            ->header('Detail')            ->description('description')            ->body($this->detail($id));    }    /**     * Edit interface.     *     * @param mixed $id     * @param Content $content     * @return Content     */    public function edit($id, Content $content)    {        return $content            ->header('修改')            ->description('description')            ->body($this->editForm()->edit($id));    }    /**     * Create interface.     *     * @param Content $content     * @return Content     */    public function create(Content $content)    {        return $content            ->header('Create')            ->description('description')            ->body($this->form());    }    /**     * Make a grid builder.     *     * @return Grid     */    protected function grid()    {        Permission::check('invoice_manager_index');        $grid = new Grid(new Invoice);        $grid->model()->when(get_subsite_id()>0, function ($querys) {            $querys->whereHas('companys', function ($query) {                $query->where('subsite_id', get_subsite_id());            });        })->orderByRaw('audit asc, created_at desc');        $grid->cid('服务名称')->display(function ($cid) {            $list = InvoiceCategory::list()->pluck('categoryname', 'id');            foreach ($list as $key => $value) {                if ($cid == $key) {                    return $value;                }            }        });        $grid->audit('处理状态')->display(function ($audit) {            switch ($audit) {                case 0:                    return "<span style='color:green'>未开票</span>";                    break;                case 1:                    return "<span style='color:#55acee'>已开票</span>";                    break;                case 2:                    return "<span style='color:red'>取消</span>";                    break;            }        });        $grid->title('发票抬头')->display(function ($title) {            switch ($title) {                case 1:                    return "企业";                    break;                case 2:                    return "个人";                    break;            }        });        $grid->oid('订单号');        $grid->order_num('金额')->display(function ($order_num){            return Order::where('id',$order_num)->value('amount');        });        $grid->organization('单位名称');        $grid->addressee('收件人');        $grid->mobile('收件人电话');        $grid->address('邮寄地址');        $grid->postcode('邮编');        $grid->actions(function ($actions) {            if (Admin::user()->can('invoice_manager_index_edit')) {                $actions->disableEdit(false);            }            if (Admin::user()->can('invoice_manager_index_delete')) {                $actions->disableDelete(false);            }        });        $grid->filter(function ($filter) {            $filter->column(1/2, function ($filter) {                $filter->where(function ($query) {                    $query->whereHas('companys', function ($query) {                        $query->where('companyname', 'like', "%{$this->input}%");                    });                }, '公司名称');                $filter->like('addressee', '收件人');                $filter->equal('uid', '会员ID');                $filter->between('created_at', '添加时间')->datetime();            });            $filter->column(1/2, function ($filter) {                $filter->equal('audit', '处理状态')->select([0=>'未开票',1=>'已开票',2=>'取消']);                $filter->equal('title', '发票抬头')->select(['1'=>'企业','2'=>'个人']);                $filter->equal('cid', '发票内容')->select(                    InvoiceCategory::list()->pluck('categoryname', 'id')                );            });        });        return $grid;    }    /**     * Make a show builder.     *     * @param mixed $id     * @return Show     */    protected function detail($id)    {        $show = new Show(Invoice::findOrFail($id));        $show->cid('服务名称')->as(function ($cid) {            $list = InvoiceCategory::list()->pluck('categoryname', 'id');            foreach ($list as $key => $value) {                if ($cid == $key) {                    return $value;                }            }        });        $show->audit('处理状态')->as(function ($audit) {            switch ($audit) {                case 0:                    return "未开票";                    break;                case 1:                    return "已开票";                    break;                case 2:                    return "取消";                    break;            }        });        $show->title('发票抬头')->as(function ($title) {            switch ($title) {                case 1:                    return "企业";                    break;                case 2:                    return "个人";                    break;            }        });        $show->organization('单位名称');        $show->addressee('收件人');        $show->deposit_bank('开户行');        $show->account('开户账号');        $show->mobile('收件人电话');        $show->address('邮寄地址');        $show->postcode('邮编');        return $show;    }    /**     * Make a form builder.     *     * @return Form     */    protected function form()    {        $form = new Form(new Invoice);        $form->display('ID');        $form->display('Created at');        $form->display('Updated at');        return $form;    }    protected function editForm()    {        Permission::check('invoice_manager_index_edit');        $form = new Form(new Invoice);        $form->html("<h4>订单信息</h4>");        $form->display('orders.is_pay', '支付状态')->with(function ($is_pay) {            switch ($is_pay) {                case 3:                    return "已取消";                    break;                case 1:                    return '待支付';                    break;                case 2:                    return '已支付';                    break;            }        });        $form->display('orders.uid', '申请充值会员');        $form->display('orders.amount', '订单金额');        $form->display('orders.pay_amount', '现金支付金额');        $form->display('orders.pay_points', '积分支付额');        $form->display('orders.order_type', '订单类型')->with(function ($order_type) {            $arr = [                1=>"套餐升级",                2=>"充值积分",                3=>"简历置顶",                4=>"醒目标签",                5=>"简历模板",                6=>"简历包",                7=>"短信包",                8=>"职位置顶",                9=>"职位紧急",                10=>"企业模板",                12=>"预约刷新职位",                13=>"职位刷新",                14=>"简历下载"            ];            foreach ($arr as $key => $val) {                if ($key == $order_type) {                    return $val;                }            }        });        $form->display('orders.payment_cn', '支付方式');        $form->display('orders.oid', '订单号');        $form->display('orders.created_at', '申请时间');        $form->display('orders.payment_time', '支付时间')->with(function ($payment_time) {            return date('Y-m-d H:i:s', $payment_time);        });        $form->display('orders.notes', '备注');        $form->html("<h4>发票信息</h4>");        $form->display('cid', '发票内容')->with(function ($cid) {            $list = InvoiceCategory::list()->pluck('categoryname', 'id');            foreach ($list as $key => $value) {                if ($cid == $key) {                    return $value;                }            }        });        $form->display('organization', '发票抬头');        $form->display('addressee', '收件人');        $form->display('deposit_bank', '开户行');        $form->display('account', '开户账号');        $form->display('tax_number', '信用代码证号');        $form->display('mobile', '手机号');        $form->display('address', '邮寄地址');        $form->display('postcode', '邮寄地址');        $form->radio('audit', '审核状态')->options([1=>'已开票', 2=>'取消', 0=>'未开票'])->attribute('class', 'audit');        $form->text('reason', '取消原因')->attribute('id', 'reason');        $js = <<<EOT        $('.audit').on('ifCreated',function(){            if(true == $(this).is(':checked')){                var audit = $(this).val();                if(audit == 2){                    $('#reason').closest(".form-group").css('display','block');                }else{                    $('#reason').closest(".form-group").css('display','none');                }            }        });                $('.audit').on('ifChecked', function(){            var audit = $(this).val();            if(audit == 2){                $('#reason').closest(".form-group").css('display','block');            }else{                $('#reason').closest(".form-group").css('display','none');            }        });EOT;        Admin::script($js);        $form->saved(function (Form $form) {            $audit = $form->audit;            $reason = $form->reason?$form->reason:'无';            $html = '发票状态为:';            switch ($audit) {                case 1:                    $html .= "已开票";                    break;                case 2:                    $html .= "取消";                    break;                case 0:                    $html .= "未开票";                    break;            }            $insert_data = array(                'utype'      => 1,                'msgtype'    => 1,                'msgfromuid' => admin::user()->id,                'msgfrom'     => admin::user()->username,                'msgtoname'   =>getCompanyName($form->model()->orders->uid)->companyname,                'msgtouid'    => $form->model()->orders->uid,                'message'     => $html.',【备注】'.$reason,                'new'          => 1,                'created_at' =>date('Y-m-d H:i:s', time()),                'updated_at' =>date('Y-m-d H:i:s', time()),            );            $this->pmsService->addBatchPms($insert_data);        });        return $form;    }    public function update($id)    {        Permission::check('invoice_manager_index_edit');        return $this->editForm()->update($id);    }}
 |