ContractService.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\demand\Contracts;
  4. use app\common\traits\ServiceTrait;
  5. class ContractService
  6. {
  7. use ServiceTrait;
  8. /** @var Contracts */
  9. public static $Model = Contracts::class;
  10. // 竞标状态
  11. const STATUS_NO = 0; //无
  12. const STATUS_ONGOING = 1; //签约中
  13. const STATUS_FINISHED = 2; //签约完成
  14. const STATUS_FAILED = 3; //签约失败
  15. const STATUS_MAP = [
  16. self::STATUS_NO => '无',
  17. self::STATUS_ONGOING => '签约中',
  18. self::STATUS_FINISHED => '签约完成',
  19. self::STATUS_FAILED => '签约失败',
  20. ];
  21. /**
  22. * 开发者创建签约记录
  23. * @throws
  24. */
  25. public static function createData($demandId, $biddingId, $depositAmount, $formData): bool
  26. {
  27. $saveData = [
  28. 'demand_id' => $demandId,
  29. 'bidding_id' => $biddingId,
  30. 'task_content' => $formData['taskContent'],
  31. 'total_amount' => $formData['totalCost'],
  32. 'deposit_amount' => $depositAmount,
  33. 'need_days' => $formData['needDays'],
  34. 'data_json' => ['devData' => $formData],//[devData=>[], customData=>[]]
  35. 'status' => ContractService::STATUS_FINISHED,
  36. 'status2' => ContractService::STATUS_ONGOING,
  37. ];
  38. $result = self::$Model::create($saveData, true);
  39. if (!$result) {
  40. throw new \Exception('签约保存失败');
  41. }
  42. return true;
  43. }
  44. /**
  45. * 客户更新签约记录
  46. * @param $demandId
  47. * @param $formData
  48. * @return mixed
  49. * @throws \Exception
  50. */
  51. public static function updateCustomerContractData($demandId, $formData)
  52. {
  53. $info = self::getWinBiddingContract($demandId);
  54. $jsonData = $info->data_json;
  55. $jsonData['customData'] = $formData;
  56. $info->data_json = $jsonData;
  57. $info->signed_time = time();
  58. $saveRes = $info->save();
  59. if (!$saveRes) {
  60. exception('更新签约记录失败');
  61. }
  62. return $info;
  63. }
  64. /**
  65. * 获取第一次签约合同
  66. * @param $demandId
  67. * @return mixed
  68. * @throws \Exception
  69. */
  70. public static function getFirstContract($demandId)
  71. {
  72. $info = self::getOne(['demand_id' => $demandId, 'status2' => self::STATUS_FINISHED], ['demandBidding'], ['id']);
  73. return $info;
  74. }
  75. /**
  76. * 获取中标的合同签约
  77. * @param $demandId
  78. * @return mixed
  79. * @throws
  80. */
  81. public static function getWinBiddingContract($demandId)
  82. {
  83. $winBidding = DemandBiddingService::getOne(['demand_id' => $demandId, 'bidding_status' => DemandBiddingService::STATUS_BIDDING_WIN]);
  84. $where = [
  85. 'demand_id' => $demandId,
  86. 'bidding_id' => $winBidding->id,
  87. ];
  88. $info = self::getOne($where, ['demandBidding']);
  89. if (!$info) {
  90. throw new \Exception('签约记录不存在');
  91. }
  92. return $info;
  93. }
  94. }