添加开发者发货功能
This commit is contained in:
@@ -70,6 +70,7 @@ class DemandService
|
||||
const BUTTON_COMPLETE_WORK = 'completeWork'; //完成工作
|
||||
const BUTTON_ACCEPT_PASSED = 'acceptPassed'; //验收通过
|
||||
const BUTTON_CONFIRM_RECEIPT = 'confirmReceipt'; //确认收货
|
||||
const BUTTON_DELIVER_GOODS = 'deliverGoods'; //开发者发货
|
||||
|
||||
/**
|
||||
* 创建需求
|
||||
@@ -130,6 +131,9 @@ class DemandService
|
||||
case self::BUTTON_CONFIRM_RECEIPT:
|
||||
$res = self::confirmReceipt($requestData, $userId);
|
||||
break;
|
||||
case self::BUTTON_DELIVER_GOODS:
|
||||
$res = self::deliverGoods($requestData, $userId);
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('非法操作');
|
||||
}
|
||||
@@ -434,6 +438,70 @@ class DemandService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 开发者发货(交付开发成果)
|
||||
* 凭证截图、交付附件与备注写入订单发货表,尾款订单转为已发货(待收货)
|
||||
* @param $requestData
|
||||
* @param $userId
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function deliverGoods($requestData, $userId)
|
||||
{
|
||||
try {
|
||||
$demandId = $requestData['demandId'] ?? 0;
|
||||
$images = array_values($requestData['images'] ?? []);
|
||||
$files = array_values($requestData['files'] ?? []);
|
||||
$remark = trim($requestData['remark'] ?? '');
|
||||
Db::startTrans();
|
||||
if (!$images || !$files) {
|
||||
throw new \Exception('请上传开发完成的凭证截图和交付附件');
|
||||
}
|
||||
$demand = self::getOne(['id' => $demandId], ['winBidding']);
|
||||
if (!$demand) {
|
||||
throw new \Exception('该需求不存在');
|
||||
}
|
||||
if ($demand->status != self::STATUS_CONFIRM_RECEIPT) {
|
||||
throw new \Exception('该需求为' . self::STATUS_MAP[$demand->status] . ',不能发货');
|
||||
}
|
||||
if (!$demand->winBidding || $demand->winBidding->user_id != $userId) {
|
||||
throw new \Exception('只有中标开发者才能发货');
|
||||
}
|
||||
//尾款订单必须已支付(待发货)才能发货
|
||||
$finalOrder = OrderService::getDemandOrder($demand->parent_order_no, OrderService::ORDER_TYPE_FINAL_PAYMENT);
|
||||
if (!$finalOrder) {
|
||||
throw new \Exception('获取尾款订单失败');
|
||||
}
|
||||
if ($finalOrder->order_status != OrderService::ORDER_STATUS_WAIT_SHIP) {
|
||||
throw new \Exception('该订单为' . OrderService::ORDER_STATUS_MAP[$finalOrder->order_status] . ',不能发货');
|
||||
}
|
||||
//交付内容写入订单发货表
|
||||
$spuId = $finalOrder->orderGoods[0]->spu_id ?? 0;
|
||||
OrderShipService::createDemandDelivery($finalOrder->order_no, $spuId, $demandId, $images, $files, $remark);
|
||||
//尾款订单改为已发货(待收货)
|
||||
$upRes = OrderService::where(['id' => $finalOrder->id])->update(['order_status' => OrderService::ORDER_STATUS_SHIPPED]);
|
||||
if (!$upRes) {
|
||||
exception('更新发货状态失败');
|
||||
}
|
||||
Db::commit();
|
||||
//给客户发送发货通知
|
||||
$msgData = [
|
||||
'values' => [
|
||||
$finalOrder->order_no,
|
||||
mb_substr($demand->title, 0, 20),
|
||||
'已发货',
|
||||
'开发成果已交付,请到需求详情查看交付内容并确认收货',
|
||||
]
|
||||
];
|
||||
(new EasyWeChatService)->sendMsg($demand->user_id, SubscribeMessageService::MSG_TEMP_ORDER_SHIPPED, $msgData);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认收货
|
||||
* @param $requestData
|
||||
@@ -461,6 +529,11 @@ class DemandService
|
||||
if (!$saveRes) {
|
||||
exception('更新需求状态失败');
|
||||
}
|
||||
//关联订单状态改为已完成
|
||||
$upRes = OrderService::where(['parent_order_no' => $demand->parent_order_no])->update(['order_status' => OrderService::ORDER_STATUS_FINISHED]);
|
||||
if (!$upRes) {
|
||||
exception('更新订单状态失败');
|
||||
}
|
||||
Db::commit();
|
||||
return $demand;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user