添加开发者发货功能
This commit is contained in:
@@ -7,6 +7,7 @@ use app\common\service\CommonService;
|
||||
use app\common\service\ContractService;
|
||||
use app\common\service\DemandBiddingService;
|
||||
use app\common\service\DemandService;
|
||||
use app\common\service\OrderShipService;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\Lang;
|
||||
use think\Validate;
|
||||
@@ -128,6 +129,13 @@ class Demand extends Api
|
||||
}
|
||||
} elseif ($item->status == 3 && $item->isMyWin && $item->winBidding->bidding_status == 2 && $item->winBidding->process_status == 2) {
|
||||
$button = ['name' => '工作完成', 'theme' => 'danger'];
|
||||
} elseif ($item->status == 5 && $item->isMyWin && $item->winBidding->bidding_status == 2 && $item->winBidding->process_status == 2) {
|
||||
//客户支付尾款后,开发者发货交付
|
||||
if ($item->hasDelivery) {
|
||||
$button = ['name' => '已发货', 'theme' => 'light'];
|
||||
} else {
|
||||
$button = ['name' => '去发货', 'theme' => 'danger'];
|
||||
}
|
||||
} elseif ($item->is_bid) {
|
||||
$button = ['name' => '已投标', 'theme' => 'light'];
|
||||
} elseif ($item->status == 1) {
|
||||
@@ -147,6 +155,13 @@ class Demand extends Api
|
||||
$button = ['name' => '工作完成', 'theme' => 'danger'];
|
||||
} elseif ($item->status == 4 && $item->accept_status == 1) {
|
||||
$button = ['name' => '待验收', 'theme' => 'light'];
|
||||
} elseif ($item->status == 5 && $item->isMyWin && $item->winBidding->bidding_status == 2 && $item->winBidding->process_status == 2) {
|
||||
//客户支付尾款后,开发者发货交付
|
||||
if ($item->hasDelivery) {
|
||||
$button = ['name' => '已发货', 'theme' => 'light'];
|
||||
} else {
|
||||
$button = ['name' => '去发货', 'theme' => 'danger'];
|
||||
}
|
||||
} elseif ($item->status == 5 && $item->accept_status == 2) {
|
||||
$button = ['name' => '待收货', 'theme' => 'light'];
|
||||
}
|
||||
@@ -166,12 +181,15 @@ class Demand extends Api
|
||||
return $button;
|
||||
};
|
||||
$list = DemandService::getList($where, $page_size, 'id desc', '', ['user', 'demandContracts', 'demandBiddings', 'winBidding']);
|
||||
$list = $list->each(function ($item, $key) use ($user_id, $opType, $btnNameFun) {
|
||||
//已发货的需求集合(发货表),用于开发者视角的发货按钮展示
|
||||
$deliveredDemandIds = OrderShipService::where(['demand_id' => ['in', $list->column('id')]])->column('demand_id');
|
||||
$list = $list->each(function ($item, $key) use ($user_id, $opType, $btnNameFun, $deliveredDemandIds) {
|
||||
$demand_bidding = $item->demand_biddings;
|
||||
$bidUserIds = array_column($demand_bidding, 'user_id');
|
||||
$item->demand_biddings_count = count($demand_bidding);
|
||||
$item->is_bid = in_array($user_id, $bidUserIds);
|
||||
$item->isMyWin = $item->winBidding && $item->winBidding->user_id == $user_id;
|
||||
$item->hasDelivery = in_array($item->id, $deliveredDemandIds);
|
||||
$item->button = $btnNameFun($opType, $item);
|
||||
});
|
||||
$this->success('', $list);
|
||||
@@ -229,6 +247,14 @@ class Demand extends Api
|
||||
'url' => $fl,
|
||||
'name' => urldecode(basename($fl))
|
||||
], $info->files);
|
||||
//交付内容(订单发货表,开发者发货后展示)
|
||||
$ship = OrderShipService::where(['demand_id' => $id])->order('id', 'desc')->find();
|
||||
$info->delivery = $ship ? [
|
||||
'images' => json_decode($ship->images, true) ?: [],
|
||||
'files' => json_decode($ship->files, true) ?: [],
|
||||
'remark' => $ship->remark,
|
||||
'delivery_time' => $ship->createtime,
|
||||
] : null;
|
||||
|
||||
$this->success('', $info);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -6,6 +6,7 @@ use app\common\service\AccountLogService;
|
||||
use app\common\service\AccountService;
|
||||
use app\common\service\EasyWeChatService;
|
||||
use app\common\service\OrderService;
|
||||
use app\common\service\OrderShipService;
|
||||
use app\common\service\SubscribeMessageService;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
@@ -45,8 +46,13 @@ class DemandDeal extends Command
|
||||
foreach ($demandList as $item) {
|
||||
try {
|
||||
Db::transaction(function () use ($item, $confirmReceiptTimeoutDay) {
|
||||
//如果七天未确认收货,则自动确认收货
|
||||
if (time() > strtotime("+$confirmReceiptTimeoutDay day", $item->accept_time)) {
|
||||
//未发货的需求不自动确认收货,等待开发者发货交付
|
||||
$ship = OrderShipService::where(['demand_id' => $item->id])->order('id', 'desc')->find();
|
||||
if (!$ship) {
|
||||
return;
|
||||
}
|
||||
//发货后N天未确认收货,则自动确认收货
|
||||
if (time() > strtotime("+$confirmReceiptTimeoutDay day", intval($ship->createtime))) {
|
||||
$item->status = DemandService::STATUS_FINISHED;
|
||||
$item->settle_status = DemandService::$Common::ONGOING;
|
||||
$saveRes = $item->save();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -398,6 +398,23 @@ class OrderService
|
||||
if (!$upRes) {
|
||||
throw new \Exception('更新订单状态失败');
|
||||
}
|
||||
//需求订单(首付款/尾款):同步需求状态与关联订单
|
||||
if (in_array($order->order_type, [self::ORDER_TYPE_FIRST_PAYMENT, self::ORDER_TYPE_FINAL_PAYMENT])) {
|
||||
$demand = DemandService::getOne(['parent_order_no' => $order->parent_order_no]);
|
||||
if ($demand && $demand->status == DemandService::STATUS_CONFIRM_RECEIPT) {
|
||||
$demand->status = DemandService::STATUS_FINISHED;
|
||||
$demand->settle_status = CommonService::ONGOING; //结算中
|
||||
$saveRes = $demand->save();
|
||||
if (!$saveRes) {
|
||||
throw new \Exception('更新需求状态失败');
|
||||
}
|
||||
//同一需求下的关联订单全部改为已完成
|
||||
$upRes = self::where(['parent_order_no' => $order->parent_order_no])->update(['order_status' => self::ORDER_STATUS_FINISHED]);
|
||||
if (!$upRes) {
|
||||
throw new \Exception('更新关联订单状态失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
$info = OrderService::getOne(['id' => $orderId]);
|
||||
|
||||
|
||||
@@ -35,4 +35,38 @@ class OrderShipService
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 需求交付发货单(开发者发货:凭证截图+交付附件+备注)
|
||||
* @param $order_no
|
||||
* @param $order_goods_spu_id
|
||||
* @param $demand_id
|
||||
* @param array $images
|
||||
* @param array $files
|
||||
* @param string $remark
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createDemandDelivery($order_no, $order_goods_spu_id, $demand_id, array $images, array $files, $remark = '')
|
||||
{
|
||||
$imagesStr = json_encode($images, JSON_UNESCAPED_UNICODE);
|
||||
$filesStr = json_encode($files, JSON_UNESCAPED_UNICODE);
|
||||
if (mb_strlen($imagesStr) > 1000 || mb_strlen($filesStr) > 1000) {
|
||||
exception('附件内容过多,请精简后重新发货');
|
||||
}
|
||||
$data = [
|
||||
'order_no' => $order_no,
|
||||
'order_goods_spu_id' => $order_goods_spu_id,
|
||||
'demand_id' => $demand_id,
|
||||
'images' => $imagesStr,
|
||||
'files' => $filesStr,
|
||||
'remark' => $remark,
|
||||
];
|
||||
$res = self::create($data);
|
||||
if (!$res) {
|
||||
exception('创建发货单数据失败');
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user