PHP code example of mano-code / approval

1. Go to this page and download the library: Download mano-code/approval library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mano-code / approval example snippets


    
    /**
     * The event to listener mappings for the application.
     *
     * @var array<class-string, array<int, class-string>>
     */
    protected $listen = [
        // ...........
        \ManoCode\Corp\Events\DingNotify\DefaultEvent::class=>[
            \ManoCode\Approval\Listeners\ApprovalEventHandler::class,
        ],
        // ...........
    ];



namespace YourNameSpace;

use Illuminate\Database\Eloquent\Model;
use ManoCode\Approval\Library\DataSourcesAbstract;

/**
 * 采购审批
 */
class PurchaseDataSources extends DataSourcesAbstract
{
    /**
     * 监听的事件 这里可以自定义事件 或者 created、saved 默认就是 created、saved 默认事件会在model数据操作变更时自动触发
     * 如果需要手动提审则需要去掉 默认事件并且 自定义事件
     *
     * @return string[]
     */
    public function getListenEvent(): array
    {
        return [
            'push-process'
        ];
    }

    /**
     * 流程名称
     * @return string
     */
    public function getName():string
    {
        return '采购审批';
    }

    /**
     * 流程描述
     * @return string
     */
    public function getDescription():string
    {
        return '采购审批';
    }

    /**
     * 获取数据模型 也就是需要审批的主表模型
     * @return string
     */
    public function getModel(): string
    {
        return MemberAccount::class;
    }

    /**
     * 审批模板(自动创建时 审批模板时 使用 可以参考钉钉文档 )
     * https://open.dingtalk.com/document/orgapp/create-or-update-approval-templates-new#h2-imr-6km-isq
     * @return array[]
     */
    public function getFormComponentsStruct(): array
    {
        return [
            [
                'componentType'=>'TextField',
                'props'=>[
                    'componentId'=>'order_no',
                    'label'=>'采购单号',
                    '// 必填
                    'disabled'=>false, // 不允许修改
                ]
            ],
            [
                'componentType'=>'TextField',
                'props'=>[
                    'componentId'=>'mobile',
                    'label'=>'联系电话',
                    'rn void
     */
    public function reject(Model $model): void
    {
        $model->setAttribute('status',4);
        $model->save();
    }

    /**
     * 当发起审批时的回调
     * @param Model $model
     * @return void
     */
    public function wait(Model $model): void
    {
        $model->setAttribute('status',0);
        $model->save();
    }
}


\ManoCode\Approval\Library\DataSourcesManager::getInstance()->registerDataSources(new PurchaseDataSources());


    /**
     * 推送采购审核
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse|void
     */
    public function pushProcessApi(Request $request)
    {
        if (!($purchase = Purchase::query()->where(['id' => $request->input('id'), 'status' => 5])->first())) {
            return $this->response()->fail('采购订单不存在');
        }
        /**
         * 触发 自定义推送事件 时间内会自动修改状态为 待审核
         */
        \ManoCode\Approval\Library\DataSourcesManager::getInstance()->triggerEvent('push-process', $purchase);
        return $this->response()->success([], '提审成功');
    }