更新快递员事件
This commit is contained in:
parent
5873ed6ccd
commit
2e1b2344bb
@ -2642,15 +2642,26 @@ class StoreOrderRepository extends BaseRepository
|
|||||||
* @param $orderSn
|
* @param $orderSn
|
||||||
* 更新扫描发货状态
|
* 更新扫描发货状态
|
||||||
*/
|
*/
|
||||||
public function deliveryGoods($orderId, $orderSn)
|
public function deliveryGoods($orderId, $orderSn, $logisticsCode='')
|
||||||
{
|
{
|
||||||
$order = $this->dao->search([], null)->where('order_sn', $orderSn)->where('order_id', $orderId)->where('StoreOrder.is_del', 0)->find();
|
if ($logisticsCode) {
|
||||||
|
$order = $this->dao->search([], null)->where('order_sn', $orderSn)->where('order_id', $orderId)->where('logistics_code', $logisticsCode)->where('StoreOrder.status', 1)->where('StoreOrder.is_del', 0)->find();
|
||||||
|
} else {
|
||||||
|
$order = $this->dao->search([], null)->where('order_sn', $orderSn)->where('order_id', $orderId)->where('StoreOrder.status', 0)->where('StoreOrder.is_del', 0)->find();
|
||||||
|
}
|
||||||
if (!$order)
|
if (!$order)
|
||||||
throw new ValidateException('订单不存在');
|
throw new ValidateException('订单不存在或编码code错误');
|
||||||
if ($order['status'] != 0 || $order['order_type'])
|
if ($order['order_type'])
|
||||||
throw new ValidateException('订单状态有误');
|
throw new ValidateException('订单状态有误');
|
||||||
$order->status = 1;
|
|
||||||
$order->mark = '快递员扫描取件';
|
if ($logisticsCode) {
|
||||||
|
$order->status = 2;
|
||||||
|
$order->mark = '快递员已完成送货';
|
||||||
|
} else {
|
||||||
|
$order->status = 1;
|
||||||
|
$order->mark = '快递员已扫描取件';
|
||||||
|
event('product.delivery', compact('order'));
|
||||||
|
}
|
||||||
$order->save();
|
$order->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -885,11 +885,18 @@ class Auth extends BaseController
|
|||||||
public function deliveryGoods($id)
|
public function deliveryGoods($id)
|
||||||
{
|
{
|
||||||
$orderSn = $this->request->param('order_sn');
|
$orderSn = $this->request->param('order_sn');
|
||||||
|
$logisticsCode = $this->request->param('logistics_code') ?? '';
|
||||||
if (empty($orderSn)) {
|
if (empty($orderSn)) {
|
||||||
return app('json')->fail('参数order_sn不能为空');
|
return app('json')->fail('参数order_sn不能为空');
|
||||||
}
|
}
|
||||||
app()->make(StoreOrderRepository::class)->deliveryGoods($id, $orderSn);
|
if (empty($logisticsCode)) {
|
||||||
return app('json')->success('快递员扫描取件成功');
|
app()->make(StoreOrderRepository::class)->deliveryGoods($id, $orderSn);
|
||||||
|
return app('json')->success('快递员扫描取件成功');
|
||||||
|
} else {
|
||||||
|
app()->make(StoreOrderRepository::class)->deliveryGoods($id, $orderSn, $logisticsCode);
|
||||||
|
return app('json')->success('快递员已完成送货');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ return [
|
|||||||
// 'community_address'=>[\app\listener\CommunityAddress::class],
|
// 'community_address'=>[\app\listener\CommunityAddress::class],
|
||||||
'order.paySuccessOrder'=>[\app\listener\paySuccessOrder::class],
|
'order.paySuccessOrder'=>[\app\listener\paySuccessOrder::class],
|
||||||
'product.create'=>[\app\listener\ProductCreate::class],
|
'product.create'=>[\app\listener\ProductCreate::class],
|
||||||
|
'product.delivery'=>[\app\listener\DeliveryGoods::class],
|
||||||
'product.sell'=>[\app\listener\CloudProduct::class], //商品上下架
|
'product.sell'=>[\app\listener\CloudProduct::class], //商品上下架
|
||||||
'refund.after'=>[\app\listener\AfterRefund::class],
|
'refund.after'=>[\app\listener\AfterRefund::class],
|
||||||
'order.create'=>[\app\listener\OrderCreate::class],
|
'order.create'=>[\app\listener\OrderCreate::class],
|
||||||
|
70
app/listener/DeliveryGoods.php
Normal file
70
app/listener/DeliveryGoods.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
declare (strict_types=1);
|
||||||
|
|
||||||
|
namespace app\listener;
|
||||||
|
|
||||||
|
use app\common\repositories\store\order\StoreOrderRepository;
|
||||||
|
use app\common\model\store\order\StoreOrder;
|
||||||
|
use crmeb\services\SmsService;
|
||||||
|
use crmeb\utils\DingTalk;
|
||||||
|
use think\facade\Db;
|
||||||
|
use think\facade\Log;
|
||||||
|
|
||||||
|
class DeliveryGoods
|
||||||
|
{
|
||||||
|
public $event;
|
||||||
|
|
||||||
|
public function handle($event)
|
||||||
|
{
|
||||||
|
$this->event = $event;
|
||||||
|
Log::info("============= handle监听order_id " . $this->event['order']['order_id']);
|
||||||
|
$this->event = $event;
|
||||||
|
//发起物流信息返回快递员手机
|
||||||
|
$logisticsPhone = $this->sendLogistics($this->event['order']['order_id'], $this->event['order']['order_sn']);
|
||||||
|
//生成用户的收货码、发生短信包含收货码
|
||||||
|
$this->generateLogisticsCode($this->event['order']['uid'], $this->event['order']['order_id'], $this->event['order']['order_sn'], $logisticsPhone);
|
||||||
|
}
|
||||||
|
|
||||||
|
//用户收货码
|
||||||
|
public function generateLogisticsCode($uid, $orderId, $orderSn, $logisticsPhone) {
|
||||||
|
$code = random_int(1000, 9999);
|
||||||
|
$res = app()->make(StoreOrderRepository::class)->update($orderId, [
|
||||||
|
'logistics_code' => $code
|
||||||
|
]);
|
||||||
|
if ($res) {
|
||||||
|
//收货人短信
|
||||||
|
$phone = StoreOrder::where('order_id', $orderId)->value('user_phone');
|
||||||
|
if ($phone) {
|
||||||
|
Log::info("发送短信 {$phone}, orderId: {$orderId}");
|
||||||
|
SmsService::create()->send($phone, 'TAKEGOOD_CODE', ['number' => substr($orderSn, -6), 'number2' => $code, 'phone' => $logisticsPhone]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//发送物流
|
||||||
|
public function sendLogistics($orderId, $orderSn)
|
||||||
|
{
|
||||||
|
Log::info("发送物流信息 orderId: {$orderId}, orderSn: {$orderSn}");
|
||||||
|
$postUrl = 'http://logistics.lihaink.cn/api/lstSet';
|
||||||
|
$curlPost = [
|
||||||
|
'order_id' => $orderId,
|
||||||
|
'order_sn' => $orderSn,
|
||||||
|
];
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, $postUrl);
|
||||||
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
|
||||||
|
$data = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
$phone = '';
|
||||||
|
if (!empty($data) && is_string($data)) {
|
||||||
|
$logisticsInfo = json_decode($data, true);
|
||||||
|
$phone = $logisticsInfo['data']['phone'];
|
||||||
|
Log::info("物流联系信息" . json_encode($logisticsInfo));
|
||||||
|
}
|
||||||
|
return $phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,8 +9,6 @@ use app\common\model\system\merchant\Merchant;
|
|||||||
use app\common\repositories\store\order\StoreOrderRepository;
|
use app\common\repositories\store\order\StoreOrderRepository;
|
||||||
use app\common\repositories\system\merchant\FinancialRecordRepository;
|
use app\common\repositories\system\merchant\FinancialRecordRepository;
|
||||||
use app\common\repositories\system\merchant\MerchantRepository;
|
use app\common\repositories\system\merchant\MerchantRepository;
|
||||||
use app\common\model\store\order\StoreOrder;
|
|
||||||
use crmeb\services\SmsService;
|
|
||||||
use crmeb\utils\DingTalk;
|
use crmeb\utils\DingTalk;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
use think\facade\Log;
|
use think\facade\Log;
|
||||||
@ -28,7 +26,6 @@ class paySuccessOrder
|
|||||||
|
|
||||||
public function handle($event)
|
public function handle($event)
|
||||||
{
|
{
|
||||||
Log::info("============= handle监听");
|
|
||||||
$this->event = $event;
|
$this->event = $event;
|
||||||
$this->finance = [];
|
$this->finance = [];
|
||||||
$this->index = 1;
|
$this->index = 1;
|
||||||
@ -140,49 +137,6 @@ class paySuccessOrder
|
|||||||
Log::error('订单分润出错', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]);
|
Log::error('订单分润出错', ['code' => $e->getCode(), 'message' => $e->getMessage(), 'trace' => $e->getTraceAsString()]);
|
||||||
DingTalk::exception($e, '订单分润出错');
|
DingTalk::exception($e, '订单分润出错');
|
||||||
}
|
}
|
||||||
//发起物流信息返回快递员手机
|
|
||||||
$logisticsPhone = $this->sendLogistics($this->event['order']['order_id'], $this->event['order']['order_sn']);
|
|
||||||
//生成用户的收货码、发生短信包含收货码
|
|
||||||
$this->generateLogisticsCode($this->event['order']['uid'], $this->event['order']['order_id'], $this->event['order']['order_sn'], $logisticsPhone);
|
|
||||||
}
|
|
||||||
|
|
||||||
//用户收货码
|
|
||||||
public function generateLogisticsCode($uid, $orderId, $orderSn, $logisticsPhone) {
|
|
||||||
$code = random_int(1000, 9999);
|
|
||||||
$res = app()->make(StoreOrderRepository::class)->update($orderId, [
|
|
||||||
'logistics_code' => $code
|
|
||||||
]);
|
|
||||||
if ($res) {
|
|
||||||
//收货人短信
|
|
||||||
$phone = StoreOrder::where('order_id', $orderId)->value('user_phone');
|
|
||||||
if ($phone) {
|
|
||||||
Log::info("发送短信 {$phone}, orderId: {$orderId}");
|
|
||||||
SmsService::create()->send($phone, 'TAKEGOOD_CODE', ['number' => substr($orderSn, -6), 'number2' => $code, 'phone' => $logisticsPhone]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//发送物流
|
|
||||||
public function sendLogistics($orderId, $orderSn)
|
|
||||||
{
|
|
||||||
$postUrl = 'http://logistics.lihaink.cn/api/lstSet';
|
|
||||||
$curlPost = [
|
|
||||||
'order_id' => $orderId,
|
|
||||||
'order_sn' => $orderSn,
|
|
||||||
];
|
|
||||||
$ch = curl_init();
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $postUrl);
|
|
||||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
curl_setopt($ch, CURLOPT_POST, 1);
|
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
|
|
||||||
$data = curl_exec($ch);
|
|
||||||
curl_close($ch);
|
|
||||||
$logisticsInfo = json_decode($data, true);
|
|
||||||
$phone = $logisticsInfo['data']['phone'] ?? '';
|
|
||||||
Log::info("发送物流信息 orderId: {$orderId}, orderSn: {$orderSn}");
|
|
||||||
Log::info("物流联系信息" . json_encode($logisticsInfo));
|
|
||||||
return $phone;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function calculate($type, $field)
|
public function calculate($type, $field)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user