发货方式优化及消息功能优化
This commit is contained in:
@@ -36,9 +36,14 @@ class Messages extends Model
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 消息类型:0=系统消息,1=公告消息,2=需求消息
|
||||
* 此处直接返回中文而非 __() 语言包:该文案会随接口返回给小程序,
|
||||
* 而 API 模块加载的语言包并不包含这些 key,__() 查不到会原样输出英文
|
||||
*/
|
||||
public function getMessageTypeList()
|
||||
{
|
||||
return ['0' => __('Message_type 0'), '1' => __('Message_type 1'), '2' => __('Message_type 2')];
|
||||
return ['0' => '系统消息', '1' => '公告消息', '2' => '需求消息'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ class Ships extends Model
|
||||
// 追加属性
|
||||
protected $append = [
|
||||
'images_list',
|
||||
'files_list'
|
||||
'files_list',
|
||||
'deliver_links_list'
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -45,6 +46,14 @@ class Ships extends Model
|
||||
return self::parseUrlList($data['files'] ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 交付链接列表([{url, name}]),供接口与后台直接使用
|
||||
*/
|
||||
public function getDeliverLinksListAttr($value, $data)
|
||||
{
|
||||
return self::parseUrlList($data['deliver_links'] ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析多图/多文件字段:英文逗号分隔的 URL 字符串 -> [{url, name}]
|
||||
* 例:http://a.com/1.jpg,http://a.com/2.pdf => [['url'=>'http://a.com/1.jpg','name'=>'1.jpg'], ...]
|
||||
|
||||
@@ -438,6 +438,28 @@ class DemandService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 规范化交付链接(只允许 1 个)
|
||||
* 支持数组或字符串,仅保留第一个 http(s) 开头的合法链接
|
||||
* @param array|string $links
|
||||
* @return array
|
||||
*/
|
||||
public static function normalizeDeliverLinks($links): array
|
||||
{
|
||||
if (is_string($links)) {
|
||||
$links = preg_split('/[,,\r\n]+/', $links) ?: [];
|
||||
}
|
||||
foreach ((array)$links as $item) {
|
||||
$url = is_array($item) ? trim($item['url'] ?? '') : trim((string)$item);
|
||||
if ($url && preg_match('/^https?:\/\//i', $url)) {
|
||||
//只保留第一个合法链接
|
||||
return [$url];
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 开发者发货(交付开发成果)
|
||||
* 凭证截图、交付附件与备注写入订单发货表,尾款订单转为已发货(待收货)
|
||||
@@ -452,10 +474,13 @@ class DemandService
|
||||
$demandId = $requestData['demandId'] ?? 0;
|
||||
$images = array_values($requestData['images'] ?? []);
|
||||
$files = array_values($requestData['files'] ?? []);
|
||||
$links = self::normalizeDeliverLinks($requestData['links'] ?? '');
|
||||
$remark = trim($requestData['remark'] ?? '');
|
||||
Db::startTrans();
|
||||
if (!$images || !$files) {
|
||||
throw new \Exception('请上传开发完成的凭证截图和交付附件');
|
||||
//源码一般在企业微信沟通群直接交付(无大小限制),平台只登记发货状态,
|
||||
//故仅凭证截图必填,附件与交付链接均选填
|
||||
if (!$images) {
|
||||
throw new \Exception('请上传开发完成的凭证截图');
|
||||
}
|
||||
$demand = self::getOne(['id' => $demandId], ['winBidding']);
|
||||
if (!$demand) {
|
||||
@@ -477,7 +502,7 @@ class DemandService
|
||||
}
|
||||
//交付内容写入订单发货表
|
||||
$spuId = $finalOrder->orderGoods[0]->spu_id ?? 0;
|
||||
OrderShipService::createDemandDelivery($finalOrder->order_no, $spuId, $demandId, $images, $files, $remark);
|
||||
OrderShipService::createDemandDelivery($finalOrder->order_no, $spuId, $demandId, $images, $files, $remark, $links);
|
||||
//尾款订单改为已发货(待收货)
|
||||
$upRes = OrderService::where(['id' => $finalOrder->id])->update(['order_status' => OrderService::ORDER_STATUS_SHIPPED]);
|
||||
if (!$upRes) {
|
||||
|
||||
@@ -75,8 +75,14 @@ class MessageService
|
||||
$lines[] = $name . ':' . $values[$key];
|
||||
}
|
||||
}
|
||||
if (!empty($template['remark'])) {
|
||||
$lines[] = '备注:' . $template['remark'];
|
||||
// 各发送点已把 remark 作为最后一个 value 传入(对应 valueNames 末位的「备注」字段),
|
||||
// 此处仅在正文尚未包含 remark 时才追加,避免出现两行重复的「备注」
|
||||
$remark = $template['remark'] ?? '';
|
||||
if ($remark !== '') {
|
||||
$content = implode("\n", $lines);
|
||||
if (mb_strpos($content, $remark) === false) {
|
||||
$lines[] = '备注:' . $remark;
|
||||
}
|
||||
}
|
||||
$content = implode("\n", $lines);
|
||||
|
||||
|
||||
@@ -37,24 +37,28 @@ class OrderShipService
|
||||
}
|
||||
|
||||
/**
|
||||
* 需求交付发货单(开发者发货:凭证截图+交付附件+备注)
|
||||
* 多图/多文件统一存英文逗号分隔的 URL 字符串:
|
||||
* 需求交付发货单(开发者发货:凭证截图 + 交付附件/链接 + 备注)
|
||||
* 多图/多文件/多链接统一存英文逗号分隔的 URL 字符串:
|
||||
* http://xxx/a.jpg,http://xxx/b.pdf
|
||||
* 说明:源码通常在企业微信沟通群直接交付,平台只登记发货状态,
|
||||
* 故附件与链接均为选填,仅凭证截图必填
|
||||
* @param $order_no
|
||||
* @param $order_goods_spu_id
|
||||
* @param $demand_id
|
||||
* @param array $images URL 数组
|
||||
* @param array $files URL 数组
|
||||
* @param array $files URL 数组(选填)
|
||||
* @param string $remark
|
||||
* @param array $links 交付链接数组(选填:Git仓库/网盘等持久获取方式)
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createDemandDelivery($order_no, $order_goods_spu_id, $demand_id, array $images, array $files, $remark = '')
|
||||
public static function createDemandDelivery($order_no, $order_goods_spu_id, $demand_id, array $images, array $files, $remark = '', array $links = [])
|
||||
{
|
||||
// 复用模型的规范化方法,统一为英文逗号分隔字符串
|
||||
$imagesStr = OrderShips::toUrlString($images);
|
||||
$filesStr = OrderShips::toUrlString($files);
|
||||
if (mb_strlen($imagesStr) > 1000 || mb_strlen($filesStr) > 1000) {
|
||||
$linksStr = OrderShips::toUrlString($links);
|
||||
if (mb_strlen($imagesStr) > 1000 || mb_strlen($filesStr) > 1000 || mb_strlen($linksStr) > 1000) {
|
||||
exception('附件数量过多或链接过长,请精简后重新发货');
|
||||
}
|
||||
$data = [
|
||||
@@ -63,6 +67,7 @@ class OrderShipService
|
||||
'demand_id' => $demand_id,
|
||||
'images' => $imagesStr,
|
||||
'files' => $filesStr,
|
||||
'deliver_links' => $linksStr,
|
||||
'remark' => $remark,
|
||||
];
|
||||
$res = self::create($data);
|
||||
@@ -99,6 +104,7 @@ class OrderShipService
|
||||
return [
|
||||
'images' => $ship->images_list,
|
||||
'files' => $ship->files_list,
|
||||
'links' => $ship->deliver_links_list,
|
||||
'remark' => $ship->remark,
|
||||
'delivery_time' => $ship->createtime,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user