You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pdd-order-api/app/libs/repository/OrderPrint/SenderAddressRepository.php

82 lines
2.6 KiB
PHP

<?php
namespace Repository\OrderPrint;
use CommonTool;
use Dao\Common\AreaDao;
use Dao\OrderPrint\OpSenderAddressDao;
use OrderDecryptTool;
use Repository\AbstractRepository;
use ZcArrayHelper;
class SenderAddressRepository extends AbstractRepository {
private $areaDao;
private $opSenderAddressDao;
protected function __construct() {
parent::__construct();
$this->areaDao = AreaDao::instance();
$this->opSenderAddressDao = OpSenderAddressDao::instance();
}
public function getUserDefaultSenderAddress($mallId) {
$address = $this->opSenderAddressDao->getByMallId($mallId);
if (empty($address)) {
return null;
}
$address = $this->formatUserSenderAddressList([$address]);
return $address[0];
}
public function formatUserSenderAddressList($addressList) {
$addressList = OrderDecryptTool::decryptInfoListByTableName($addressList, 'op_sender_address');
$prvinceIds = array_unique(ZcArrayHelper::getSub($addressList, 'provinceAreaId'));
$cityIds = array_unique(ZcArrayHelper::getSub($addressList, 'cityAreaId'));
$countyIds = array_unique(ZcArrayHelper::getSub($addressList, 'countyAreaId'));
$provinces = $this->areaDao->getMapByAreaIds($prvinceIds);
$citys = $this->areaDao->getMapByAreaIds($cityIds);
$countys = $this->areaDao->getMapByAreaIds($countyIds);
foreach ($addressList as &$row) {
$row['province'] = $provinces[$row['provinceAreaId']]['name'];
$row['city'] = $citys[$row['cityAreaId']]['name'];
$row['county'] = $countys[$row['countyAreaId']]['name'];
}
return $addressList;
}
public function getAuthMallsMultiShopDefaultSenderAddress($authMallIds) {
if (empty($authMallIds)) {
return [];
}
$senderAddressList = $this->opSenderAddressDao->getMutiShopDefaultList($authMallIds);
if (!$senderAddressList) {
return [];
}
$senderAddressList = $this->formatUserSenderAddressList($senderAddressList);
$senderAddressList = ZcArrayHelper::changeKeyRow($senderAddressList, 'mallId');
return $senderAddressList;
}
public function getMallDefaultSenderAddress($mallId) {
$address = $this->opSenderAddressDao->getByMallId($mallId);
if (empty($address)) {
return false;
}
$address = $this->formatUserSenderAddressList([$address]);
return $address[0];
}
public function getUserSenderAddress($mallId, $senderAddressId) {
if (CommonTool::anyEmpty($mallId, $senderAddressId)) {
return null;
}
$address = $this->opSenderAddressDao->getById($senderAddressId);
if (empty($address) || $address['mallId'] != $mallId) {
return null;
}
$address = $this->formatUserSenderAddressList([$address]);
return $address[0];
}
}