2026-09-17 16:25:31 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\common\service;
|
|
|
|
|
|
|
|
|
|
use app\common\model\order\Ships as OrderShips;
|
|
|
|
|
use app\common\traits\ServiceTrait;
|
|
|
|
|
|
|
|
|
|
class OrderShipService
|
|
|
|
|
{
|
|
|
|
|
use ServiceTrait;
|
|
|
|
|
|
|
|
|
|
/** @var OrderShips */
|
|
|
|
|
public static $Model = OrderShips::class;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param $order_no
|
|
|
|
|
* @param $order_goods_spu_id
|
|
|
|
|
* @param $code
|
|
|
|
|
* @param $remark
|
|
|
|
|
* @return mixed
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
|
|
|
|
public static function createData($order_no, $order_goods_spu_id, $code, $remark = '')
|
|
|
|
|
{
|
|
|
|
|
$data = [
|
|
|
|
|
'order_no' => $order_no,
|
|
|
|
|
'order_goods_spu_id' => $order_goods_spu_id,
|
|
|
|
|
'code' => $code,
|
|
|
|
|
'remark' => $remark,
|
|
|
|
|
];
|
|
|
|
|
$res = self::create($data);
|
|
|
|
|
if (!$res) {
|
|
|
|
|
exception('创建发货单数据失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
2026-09-30 14:56:56 +08:00
|
|
|
|
|
|
|
|
/**
|
2026-10-08 20:34:08 +08:00
|
|
|
* 需求交付发货单(开发者发货:凭证截图 + 交付附件/链接 + 备注)
|
|
|
|
|
* 多图/多文件/多链接统一存英文逗号分隔的 URL 字符串:
|
2026-09-30 16:57:26 +08:00
|
|
|
* http://xxx/a.jpg,http://xxx/b.pdf
|
2026-10-08 20:34:08 +08:00
|
|
|
* 说明:源码通常在企业微信沟通群直接交付,平台只登记发货状态,
|
|
|
|
|
* 故附件与链接均为选填,仅凭证截图必填
|
2026-09-30 14:56:56 +08:00
|
|
|
* @param $order_no
|
|
|
|
|
* @param $order_goods_spu_id
|
|
|
|
|
* @param $demand_id
|
2026-09-30 16:57:26 +08:00
|
|
|
* @param array $images URL 数组
|
2026-10-08 20:34:08 +08:00
|
|
|
* @param array $files URL 数组(选填)
|
2026-09-30 14:56:56 +08:00
|
|
|
* @param string $remark
|
2026-10-08 20:34:08 +08:00
|
|
|
* @param array $links 交付链接数组(选填:Git仓库/网盘等持久获取方式)
|
2026-09-30 14:56:56 +08:00
|
|
|
* @return mixed
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
2026-10-08 20:34:08 +08:00
|
|
|
public static function createDemandDelivery($order_no, $order_goods_spu_id, $demand_id, array $images, array $files, $remark = '', array $links = [])
|
2026-09-30 14:56:56 +08:00
|
|
|
{
|
2026-09-30 16:57:26 +08:00
|
|
|
// 复用模型的规范化方法,统一为英文逗号分隔字符串
|
|
|
|
|
$imagesStr = OrderShips::toUrlString($images);
|
|
|
|
|
$filesStr = OrderShips::toUrlString($files);
|
2026-10-08 20:34:08 +08:00
|
|
|
$linksStr = OrderShips::toUrlString($links);
|
|
|
|
|
if (mb_strlen($imagesStr) > 1000 || mb_strlen($filesStr) > 1000 || mb_strlen($linksStr) > 1000) {
|
2026-09-30 16:57:26 +08:00
|
|
|
exception('附件数量过多或链接过长,请精简后重新发货');
|
2026-09-30 14:56:56 +08:00
|
|
|
}
|
|
|
|
|
$data = [
|
|
|
|
|
'order_no' => $order_no,
|
|
|
|
|
'order_goods_spu_id' => $order_goods_spu_id,
|
|
|
|
|
'demand_id' => $demand_id,
|
|
|
|
|
'images' => $imagesStr,
|
|
|
|
|
'files' => $filesStr,
|
2026-10-08 20:34:08 +08:00
|
|
|
'deliver_links' => $linksStr,
|
2026-09-30 14:56:56 +08:00
|
|
|
'remark' => $remark,
|
|
|
|
|
];
|
|
|
|
|
$res = self::create($data);
|
|
|
|
|
if (!$res) {
|
|
|
|
|
exception('创建发货单数据失败');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
2026-09-30 16:57:26 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取需求最新的发货单(未发货返回 null)
|
|
|
|
|
* @param int $demandId
|
|
|
|
|
* @return OrderShips|null
|
|
|
|
|
*/
|
|
|
|
|
public static function getDemandLastShip($demandId)
|
|
|
|
|
{
|
|
|
|
|
return self::where(['demand_id' => $demandId])->order('id', 'desc')->find();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取需求的交付内容(未发货返回 null)
|
|
|
|
|
* 结构:['images' => [{url,name}], 'files' => [{url,name}], 'remark' => '', 'delivery_time' => 时间戳]
|
|
|
|
|
* @param int $demandId
|
|
|
|
|
* @return array|null
|
|
|
|
|
*/
|
|
|
|
|
public static function getDemandDelivery($demandId)
|
|
|
|
|
{
|
|
|
|
|
$ship = self::getDemandLastShip($demandId);
|
|
|
|
|
if (!$ship) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [
|
|
|
|
|
'images' => $ship->images_list,
|
|
|
|
|
'files' => $ship->files_list,
|
2026-10-08 20:34:08 +08:00
|
|
|
'links' => $ship->deliver_links_list,
|
2026-09-30 16:57:26 +08:00
|
|
|
'remark' => $ship->remark,
|
|
|
|
|
'delivery_time' => $ship->createtime,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断需求是否已发货
|
|
|
|
|
* @param int $demandId
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function hasDemandDelivery($demandId)
|
|
|
|
|
{
|
|
|
|
|
return !empty(self::getDemandLastShip($demandId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量获取已发货的需求ID(用于列表按钮展示,避免 N+1 查询)
|
|
|
|
|
* @param array $demandIds
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getDeliveredDemandIds(array $demandIds)
|
|
|
|
|
{
|
|
|
|
|
$demandIds = array_filter(array_unique(array_map('intval', $demandIds)));
|
|
|
|
|
if (!$demandIds) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self::where(['demand_id' => ['in', $demandIds]])->column('demand_id');
|
|
|
|
|
}
|
2026-09-17 16:25:31 +08:00
|
|
|
}
|