54 lines
2.0 KiB
PHP
54 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace app\common\behavior\order;
|
|
/**
|
|
* 抖音订单同步
|
|
*/
|
|
class Douyin
|
|
{
|
|
|
|
// 订单支付成功,担保支付订单同步
|
|
public function run($orderNo)
|
|
{
|
|
$data = (new \app\common\model\order\Order)->getOrderDetail($orderNo,['payment_json']);
|
|
|
|
if(!$data || $data['status'] != \app\common\constant\order\Status::STATUS_SUCCESS || $data['real_price'] == 0){
|
|
return false;
|
|
}
|
|
|
|
$data['payment_json'] = json_decode($data['payment_json'],true);
|
|
|
|
if(!$data['payment_json'] || !isset($data['payment_json']['open_id'])){
|
|
return false;
|
|
}
|
|
|
|
$orderItem = [];
|
|
|
|
$amount = 0;
|
|
foreach ($data['goodsList'] as $item){
|
|
$orderItem[] = [
|
|
'item_code'=>(string)$item['item_id'],//开发者侧商品 ID
|
|
'img'=>$item['snapshoot']['cover'],//子订单商品图片 URL
|
|
'title'=>$item['snapshoot']['name'],//子订单商品介绍标题
|
|
'amount'=>(int)$item['count'],//单类商品的数目
|
|
'price'=>(int)($item['snapshoot']['price'] * 100)//单类商品的总价,单位为分
|
|
];
|
|
|
|
$amount += $item['count'];
|
|
}
|
|
|
|
$orderDetail = [
|
|
'order_id'=>$data['order_no'],//开发者侧业务单号
|
|
'create_time'=>(int)($data['createtime'] . '123'),//订单创建的时间,13 位毫秒时间戳
|
|
'status'=>'已支付',//订单状态,建议采用以下枚举值
|
|
'amount'=>(int)$amount,//订单商品总数
|
|
'total_price'=>(int)($data['real_price'] * 100),//订单总价,单位为分
|
|
'detail_url'=>'pages/order/detail/detail?order_no='.$data['order_no'],//小程序订单详情页 path例如pages/order/orderDetail
|
|
'item_list'=>$orderItem
|
|
];
|
|
|
|
$paymentConfig = \app\common\model\config\System::getConfig('douyinpay');
|
|
|
|
$ret = \douyin\Byte::init($paymentConfig)->pushOrder($data['payment_json']['open_id'],$orderDetail);
|
|
}
|
|
} |