Files
2026-09-17 16:25:31 +08:00

110 lines
3.0 KiB
PHP

<?php
namespace app\common\service;
use app\common\model\demand\Contracts;
use app\common\traits\ServiceTrait;
class ContractService
{
use ServiceTrait;
/** @var Contracts */
public static $Model = Contracts::class;
// 竞标状态
const STATUS_NO = 0; //无
const STATUS_ONGOING = 1; //签约中
const STATUS_FINISHED = 2; //签约完成
const STATUS_FAILED = 3; //签约失败
const STATUS_MAP = [
self::STATUS_NO => '无',
self::STATUS_ONGOING => '签约中',
self::STATUS_FINISHED => '签约完成',
self::STATUS_FAILED => '签约失败',
];
/**
* 开发者创建签约记录
* @throws
*/
public static function createData($demandId, $biddingId, $depositAmount, $formData): bool
{
$saveData = [
'demand_id' => $demandId,
'bidding_id' => $biddingId,
'task_content' => $formData['taskContent'],
'total_amount' => $formData['totalCost'],
'deposit_amount' => $depositAmount,
'need_days' => $formData['needDays'],
'data_json' => ['devData' => $formData],//[devData=>[], customData=>[]]
'status' => ContractService::STATUS_FINISHED,
'status2' => ContractService::STATUS_ONGOING,
];
$result = self::$Model::create($saveData, true);
if (!$result) {
throw new \Exception('签约保存失败');
}
return true;
}
/**
* 客户更新签约记录
* @param $demandId
* @param $formData
* @return mixed
* @throws \Exception
*/
public static function updateCustomerContractData($demandId, $formData)
{
$info = self::getWinBiddingContract($demandId);
$jsonData = $info->data_json;
$jsonData['customData'] = $formData;
$info->data_json = $jsonData;
$info->signed_time = time();
$saveRes = $info->save();
if (!$saveRes) {
exception('更新签约记录失败');
}
return $info;
}
/**
* 获取第一次签约合同
* @param $demandId
* @return mixed
* @throws \Exception
*/
public static function getFirstContract($demandId)
{
$info = self::getOne(['demand_id' => $demandId, 'status2' => self::STATUS_FINISHED], ['demandBidding'], ['id']);
return $info;
}
/**
* 获取中标的合同签约
* @param $demandId
* @return mixed
* @throws
*/
public static function getWinBiddingContract($demandId)
{
$winBidding = DemandBiddingService::getOne(['demand_id' => $demandId, 'bidding_status' => DemandBiddingService::STATUS_BIDDING_WIN]);
$where = [
'demand_id' => $demandId,
'bidding_id' => $winBidding->id,
];
$info = self::getOne($where, ['demandBidding']);
if (!$info) {
throw new \Exception('签约记录不存在');
}
return $info;
}
}