Files
amb_wechatapp/application/common/library/app/physical/express/provider/Base.php
T

76 lines
2.2 KiB
PHP

<?php
namespace app\common\library\app\physical\express\provider;
use app\common\library\app\physical\express\contract\ExpressInterface;
use app\common\model\app\physical\OrderExpress;
use app\common\model\app\physical\OrderExpressLog;
class Base implements ExpressInterface
{
public function __construct()
{
}
public function search(array $data, $orderExpress = 0)
{
return null;
}
public function subscribe(array $data)
{
throw new \Exception('当前快递驱动不支持物流信息订阅');
}
public function push(array $data)
{
throw new \Exception('当前快递驱动不支持接受推送');
}
public function eOrder(array $data, $items)
{
throw new \Exception('当前快递驱动不支持电子面单');
}
protected function updateExpress(array $data, $orderExpress)
{
if (is_numeric($orderExpress)) {
$orderExpress = OrderExpress::find($orderExpress);
}
if ($orderExpress) {
$orderExpress->status = $data['status'];
$orderExpress->save();
$this->syncTraces($data['traces'], $orderExpress);
}
}
protected function syncTraces($traces, $orderExpress)
{
$orderExpressLog = OrderExpressLog::where('order_express_id', $orderExpress->id)->select();
$log_count = count($orderExpressLog);
if ($log_count > 0) {
if (is_array($traces)) {
array_splice($traces, 0, $log_count);
}
}
if (is_array($traces)) {
foreach ($traces as $k => $trace) {
$orderExpressLog = new OrderExpressLog();
$orderExpressLog->uniacid = UNIACID;
$orderExpressLog->user_id = $orderExpress['user_id'];
$orderExpressLog->order_id = $orderExpress['order_id'];
$orderExpressLog->order_express_id = $orderExpress['id'];
$orderExpressLog->content = $trace['content'];
$orderExpressLog->change_date = $trace['change_date'];
$orderExpressLog->status = $trace['status'];
$orderExpressLog->save();
}
}
}
}