feat: order finish

This commit is contained in:
2025-04-01 14:44:31 +08:00
parent cab692b994
commit 44e773305f
2 changed files with 65 additions and 15 deletions

View File

@@ -8,7 +8,7 @@ class WxMiniCode
* 发送优惠券订阅消息模板id * 发送优惠券订阅消息模板id
*/ */
const string SEND_SUB_MESSAGE_GET_COUPON_TEMPLATE_ID = 'akV-wJt0AHWBpzPKvIsa0IRuzrf5yWPaMYvRRioI8XM'; const string SEND_SUB_MESSAGE_GET_COUPON_TEMPLATE_ID = 'akV-wJt0AHWBpzPKvIsa0IRuzrf5yWPaMYvRRioI8XM';
const string SEND_SUB_MESSAGE_DELIVER_TEMPLATE_ID = 'xxxxxxxxxx'; const string SEND_SUB_MESSAGE_DELIVER_TEMPLATE_ID = 'DPRuxtI_qS-o513Y2Vr3Q6nifwGTnat6cArJueGzpOU';
/** /**
* @var int 发送消息类型 1=获取优惠券 2=送达 * @var int 发送消息类型 1=获取优惠券 2=送达

View File

@@ -10,12 +10,16 @@ declare(strict_types=1);
namespace App\Service\Api\Driver; namespace App\Service\Api\Driver;
use App\Amqp\Producer\WxSubMessageProducer;
use App\Constants\Common\DriverCode; use App\Constants\Common\DriverCode;
use App\Constants\Common\OrderCode; use App\Constants\Common\OrderCode;
use App\Constants\Common\WxMiniCode;
use App\Exception\ErrException; use App\Exception\ErrException;
use App\Model\Order; use App\Model\Order;
use Hyperf\Amqp\Producer;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
use function Hyperf\Config\config;
class DeliverService extends BaseDriverService class DeliverService extends BaseDriverService
{ {
@@ -47,14 +51,21 @@ class DeliverService extends BaseDriverService
if ($info->status == DriverCode::DESTINATION) throw new ErrException('该点位已送达'); if ($info->status == DriverCode::DESTINATION) throw new ErrException('该点位已送达');
$orderIds = $this->orderModel $orderList = $this->orderModel
->where('cycle_id',$this->cycleId) ->leftJoin('pickup_code','pickup_code.order_id','=','order.id')
->where('status',OrderCode::DEPART) ->where('order.cycle_id',$this->cycleId)
->where('site_id',$this->siteId) ->where('order.status',OrderCode::DEPART)
->pluck('id') ->where('order.site_id',$this->siteId)
->toArray(); ->select(['order.user_id','order.id','pickup_code.pickup_code','order.order_sno'])
->get();
Db::transaction(function () use ($info,$orderIds) { if ($orderList->isEmpty()) {
$orderList = [];
} else {
$orderList = $orderList->toArray();
}
Db::transaction(function () use ($info,$orderList) {
// $this->orderModel->whereIn('id', $orderIds)->update([ // $this->orderModel->whereIn('id', $orderIds)->update([
// 'status' => OrderCode::DEPART, // 'status' => OrderCode::DEPART,
// 'set_out_time' => date('Y-m-d H:i:s'), // 'set_out_time' => date('Y-m-d H:i:s'),
@@ -63,16 +74,55 @@ class DeliverService extends BaseDriverService
$info->status = DriverCode::DESTINATION; $info->status = DriverCode::DESTINATION;
if (!$info->save()) throw new ErrException('送达失败-01'); if (!$info->save()) throw new ErrException('送达失败-01');
if (!empty($orderList)){
$dateTime = date('Y-m-d H:i:s'); $dateTime = date('Y-m-d H:i:s');
foreach (array_chunk($orderIds, 500) as $chunk) { foreach (array_chunk(array_column($orderList,'id'), 500) as $chunk) {
$this->orderModel->whereIn('id', $chunk)->update([ $this->orderModel->whereIn('id', $chunk)->update([
'status' => OrderCode::ARRIVE, 'status' => OrderCode::ARRIVE,
'delivery_time' => $dateTime, 'delivery_time' => $dateTime,
]); ]);
}
} }
}); });
$this->sendWxSubMessageMq($orderList);
return $this->return->success(); return $this->return->success();
} }
/**
* @var Producer
*/
#[Inject]
protected Producer $producer;
/**
* @param array $orderList
* @return void
*/
private function sendWxSubMessageMq(array $orderList): void
{
if (empty($orderList)) return;
$userIds = [];
foreach ($orderList as $oneOrder) {
if (in_array($oneOrder['user_id'], $userIds)) continue;
$msgData = [
'character_string19' => ['value' => $oneOrder['order_sno']],
'thing27' => ['value' => $oneOrder['pickup_code']],
'phrase16' => ['value' => '待取餐'],
'thing20' => ['value' => '您的午餐来了,早点吃饭哈,您的身体最重要'],
];
$message = new WxSubMessageProducer([
'type' => WxMiniCode::SEND_MSG_TYPE_DELIVER,
'user_id' => $oneOrder['user_id'],
'data' => $msgData,
'page' => null
]);
$this->producer->produce($message);
}
}
} }