<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------

namespace app\api\logic;


use app\common\model\orders\OrderEffectiveLog;
use app\common\logic\BaseLogic;
use think\facade\Db;


/**
 * OrderEffectiveLog逻辑
 * Class OrderEffectiveLogLogic
 * @package app\api\logic
 */
class OrderEffectiveLogLogic extends BaseLogic
{

    /**
     * @notes 提交保修工单申请
     */
    public static function submitEffective(array $params): bool
    {
        //Db::startTrans();
        try {
            $info = OrderEffectiveLog::find($params['id']);
            if($info['end_effective_time'] < time()){
                throw new \Exception('该保修卡已过期');
            }
            if($info['effective_status'] > 0){
                throw new \Exception('该保修卡已提交过');
            }

            OrderEffectiveLog::where('id', $params['id'])->update([
                'effective_images' => json_encode($params['effective_images']),
                'remark' => $params['remark'] ?? '',
                'effective_status' => 1,
                'effective_time' => time()
            ]);

            //Db::commit();
            return true;
        } catch (\Exception $e) {
            //Db::rollback();
            self::setError($e->getMessage());
            return false;
        }
    }

}