InvoiceAction.php 2.5 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * 自定义Action:渲染生成 Invoice Action
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Admin\Extensions\Actions
 * @package   App\Admin\Extensions\Actions
 * @author    Richer <yangzi1028@163.com>
 * @date      2022年7月26日17:36:40
 * @copyright 2021-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Admin\Extensions\Actions;

use App\Admin\Rewrite\Actions\RowAction;
use App\Admin\Traits\FormFieldTrait;
use App\Models\Invoice\Invoice;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;

class InvoiceAction extends RowAction
{
    use FormFieldTrait;

//    public $name = '<i class="fa fa-check-square-o"></i>开票';
    public $name = '确认开票';

    protected $style = 'btn btn-success';

    protected $selector = '.grid-invoice';

    public function handle(Model $model)
    {

//        dump(request()->all());

        // 自定义上传文件
        $images = $this->formUpload(request(), $model);
        if (!$images) {
            return $this->response()->error(__('operate_failed'))->refresh();
        }
        $image          = Arr::get($images, 'full_path');
        $original_name  = Arr::get($images, 'original_name');
        $model->image = $image;
        $model->image_name = $original_name;
        $model->status = Invoice::INVOICED;
        $result = $model->save();
        if ($result) {
            return $this->response()->success(__('operate_succeeded'))->refresh();
        } else {
            return $this->response()->error(__('operate_failed'))->refresh();
        }
    }

    public function form()
    {
        // 上传文件
        $this->image('image', __('invoice_image'))
            ->removable()
            ->uniqueName()
            ->required()
            ->move('/admin/invoice/'.date('Ymd'));
//        $type = [
//            1 => '广告',
//            2 => '违法',
//            3 => '钓鱼',
//        ];
//
//
//        $this->image('name', 'Placeholder...');
//
//        $this->checkbox('type', '类型')->options($type);
//        $this->textarea('reason', '原因')->rules('required');
    }

    public function html($html = '')
    {
        return "<a class='report-posts btn btn-sm btn-danger'><i class='fa fa-info-circle'></i>举报</a>";
    }
}