77 lines
2.8 KiB
PHP
Executable File
77 lines
2.8 KiB
PHP
Executable File
<?php
|
||
|
||
// +----------------------------------------------------------------------
|
||
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||
// +----------------------------------------------------------------------
|
||
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
|
||
// +----------------------------------------------------------------------
|
||
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||
// +----------------------------------------------------------------------
|
||
// | Author: CRMEB Team <admin@crmeb.com>
|
||
// +----------------------------------------------------------------------
|
||
|
||
|
||
namespace crmeb\jobs;
|
||
|
||
use app\common\repositories\store\order\StoreOrderRepository;
|
||
use crmeb\interfaces\JobInterface;
|
||
use crmeb\utils\Curl;
|
||
use think\facade\Log;
|
||
use think\facade\Db;
|
||
use think\queue\Job;
|
||
|
||
class SendGoodsCodeJob implements JobInterface
|
||
{
|
||
|
||
public $event;
|
||
|
||
public function fire($job, $data)
|
||
{
|
||
$this->event = $data;
|
||
Log::info("sendGoodsCodeJob" . json_encode($this->event));
|
||
Log::info("sendGoodsCodeJob ============= handle监听order_id " . $this->event['order_id']);
|
||
try {
|
||
if ($this->event['activity_type'] == 0 || in_array($this->event['source'], [0,2,103])) {
|
||
$logisticsPhone = '';
|
||
//发起物流信息返回快递员手机
|
||
if($this->event['activity_type'] !=98 && $this->event['order_type'] != 1){
|
||
$logisticsPhone = $this->sendLogistics($this->event['order_id'], $this->event['order_sn']);
|
||
}
|
||
//生成用户的收货码
|
||
$this->generateLogisticsCode($this->event['uid'], $this->event['order_id'], $this->event['order_sn'], $logisticsPhone);
|
||
}
|
||
} catch (\Exception $e) {
|
||
Log::info('sendGoodsCodeJob 异常:' . $e->getMessage());
|
||
}
|
||
$job->delete();
|
||
}
|
||
|
||
|
||
//用户收货码
|
||
public function generateLogisticsCode($uid, $orderId, $orderSn, $logisticsPhone) {
|
||
$code = random_int(1000, 9999);
|
||
app()->make(StoreOrderRepository::class)->update($orderId, [
|
||
'logistics_code' => $code,
|
||
'logistics_phone' => $logisticsPhone
|
||
]);
|
||
}
|
||
|
||
//发送物流
|
||
public function sendLogistics($orderId, $orderSn)
|
||
{
|
||
$curl = new Curl();
|
||
$postUrl = env('LOGISTICS_HOST_URL') . '/api/lstSet';
|
||
$data = $curl->post($postUrl, ['order_id' => $orderId, 'order_sn' => $orderSn]);
|
||
if (!empty($data) && is_string($data)) {
|
||
$logisticsInfo = json_decode($data, true);
|
||
$phone = $logisticsInfo['data']['phone'] ?? '';
|
||
}
|
||
return $phone ?? '';
|
||
}
|
||
|
||
public function failed($data)
|
||
{
|
||
// TODO: Implement failed() method.
|
||
}
|
||
}
|