<?php


namespace App\Form\Services;


use App\Form\Facades\FormProductDetailFacade;
use App\Services\CommonUserBaseService;

class FormProductService extends CommonUserBaseService
{
    protected $cache = true;

    protected $cacheBucket = 'FormProduct:';

    public function addFormProduct($params){

        $add['form_id'] = $params['form_id'];
        if(isset($params['status'])){
            $add['status'] = empty($params['status'])?'0':$params['status'];
        }else{
            $add['status'] = 0;
        }
        if(!empty($params['id']) && $params['id'] > 0){
            $id = $params['id'];
            $this->updateBy([
                'id' => $id,
            ], $add);
        } else {
            $id = $this->save($add)->id;
        }
        if(!empty($id)){
            $data['product_ids']=$params['product_ids'];
            $data['form_product_id']=$id;
            FormProductDetailFacade::relationProductDetail($data);
        }
        return $id;
    }

}
