Merge pull request '更新支付成功回调' (#13) from feature_orderhandle into master

Reviewed-on: #13
This commit is contained in:
mkm 2023-09-08 11:51:13 +08:00
commit 10992a8d4d
2 changed files with 123 additions and 2 deletions

View File

@ -42,6 +42,7 @@ use app\common\repositories\user\UserRepository;
use crmeb\jobs\PayGiveCouponJob;
use crmeb\jobs\ProductImportJob;
use crmeb\jobs\SendSmsJob;
use crmeb\jobs\SendGoodsCodeJob;
use crmeb\jobs\UserBrokerageLevelJob;
use crmeb\services\CombinePayService;
use crmeb\services\CrmebServeServices;
@ -271,8 +272,9 @@ class StoreOrderRepository extends BaseRepository
$flag = false;
}
}
//发起物流信息处理
event('order.sendGoodsCode', $order);
//发起队列物流信息处理
//event('order.sendGoodsCode', $order);
Queue::push(SendGoodsCodeJob::class, $order);
// 商户流水账单数据
$finance[] = [

View File

@ -0,0 +1,119 @@
<?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 crmeb\interfaces\JobInterface;
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 ============= handle监听order_id " . $this->event['order_id']);
if ($this->event['activity_type'] == 0) {
//发起物流信息返回快递员手机
$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);
//记录订单收货地址记录
$this->recordOrderAddr($this->event);
}
$job->delete();
}
//订单收货记录
public function recordOrderAddr($order) {
//province_code . city_code . district_code . street_code . village_code . brigade_id;
//设置地址信息
$addressInfo = explode(',', $order['user_address_code'] ?? '');
$productOrder = [
'uid' => $order['uid'] ?? 0,
'order_id' => $order['order_id'] ?? 0,
'province_code' => $addressInfo[0] ?? '',
'city_code' => $addressInfo[1] ?? '',
'district_code' => $addressInfo[2] ?? '',
'street_code' => $addressInfo[3] ?? '',
'village_code' => $addressInfo[4] ?? '',
'brigade_id' => $addressInfo[5] ?? 0,
'status' => 1,
'create_time' => date('Y-m-d H:i:s')
];
//商品信息
$productInfo = Db::name('store_order_product')->where('order_id', $order['order_id'] ?? 0)->find();
if ($productInfo) {
$productOrder['product_id'] = $productInfo['product_id'] ?? 0;
$productOrder['product_price'] = $productInfo['product_price'] ?? 0;
$productOrder['total_price'] = $productInfo['total_price'] ?? 0;
$productOrder['product_num'] = $productInfo['product_num'] ?? 0;
}
//商户信息
$merchantInfo = Db::name('merchant')->where('mer_id', $order['mer_id'] ?? 0)->find();
if ($merchantInfo) {
$productOrder['mer_id'] = $merchantInfo['mer_id'] ?? 0;
$productOrder['mer_category_id'] = $merchantInfo['category_id'] ?? 0;
$productOrder['mer_type_id'] = $merchantInfo['type_id'] ?? 0;
$productOrder['is_trader'] = $merchantInfo['is_trader'] ?? 0;
}
Db::name('ProductOrderLog')->insert($productOrder);
}
//用户收货码
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)
{
$postUrl = env('LOGISTICS_HOST_URL') . '/api/lstSet';
Log::info("物流HOST: {$postUrl}");
Log::info("发送物流信息 orderId: {$orderId}, orderSn: {$orderSn}");
$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;
}
public function failed($data)
{
// TODO: Implement failed() method.
}
}