Commit 34d4b89f authored by pengfei's avatar pengfei

Merge branch 'feature_optimize_order_create_refund' into test

# Conflicts:
#	application/modules/Marketing/controllers/Marketing.php
#	vendor/autoload.php
#	vendor/composer/autoload_real.php
#	vendor/composer/autoload_static.php
#	vendor/composer/installed.json
parents b232d47a b7d99b6f
......@@ -19,6 +19,7 @@ class GoodsException extends BaseException
const LABEL_PRINTER_ALREADY_EXIST = 53;
const PRINTER_BIND_ERROR = 54;
const PRINTER_SN_ERROR = 55;
const PARAMS_NULL_ERROR = 56;
protected $cus = [
0 => '商品创建失败,请稍后重试',
......@@ -77,5 +78,6 @@ class GoodsException extends BaseException
self::LABEL_PRINTER_ALREADY_EXIST => '标签打印机已被%s绑定',
self::PRINTER_BIND_ERROR => '打印机绑定失败:%s',
self::PRINTER_SN_ERROR => '打印机sn号码有误',
self:: PARAMS_NULL_ERROR => '参数不能为空',
];
}
\ No newline at end of file
......@@ -314,7 +314,7 @@ class GoodsController extends Base
*/
public function refundAction()
{
(new RefundGoodsValidate())->validate();
//(new RefundGoodsValidate())->validate();
$params = $this->params;
$res = GoodsService::refundGoods($params);
$this->success(["result" => $res]);
......@@ -349,4 +349,15 @@ class GoodsController extends Base
$res = GoodsSnapshotsService::goodsSnapshots($this->params);
$this->success(["result" => $res]);
}
/**
* 下单时获取商品数据 sku and spu
* @throws Exception
*/
public function place_order_goods_listAction()
{
$params = $this->params;
$data = GoodsService::getPlaceOrderGoodsList($params);
$this->success(["result" => $data]);
}
}
\ No newline at end of file
......@@ -14,6 +14,11 @@ class KafkaService
*/
public static function productMarketingUpdate(array $marketingInfo) : void
{
if ($marketingInfo['userId'] == '17963416161910792')
{
return;
}
$msg = json_encode([
'marketingInfo' => $marketingInfo,
'time' => time(),
......
......@@ -1935,19 +1935,27 @@ class GoodsService
* @return bool
* @throws GoodsException
*/
public static function refundGoods($params)
public static function refundGoods($dataJson)
{
if (empty($dataJson)){
throw new GoodsException(["cus" => GoodsException::PARAMS_NULL_ERROR]);
}
foreach ($dataJson as $params){
$goodsSukParams = GoodsSkuId::getGoodsSkuIdParams($params["goods_sku_id"]);
if (!empty($goodsSukParams)) {
if (isset($goodsSukParams["table_tag"]) && ($goodsSukParams["table_tag"] == GoodsSkuId::TABLE_TAG_PINDAN
|| $goodsSukParams["category_1_id"] == "00")) {
return MarketingPindanGoodsService::refundGoods($params);
$refundGoodsData[] = $params;
}
} else {
throw new GoodsException(["cus" => 41]);
}
}
if (empty($refundGoodsData)){
return true;
}
return MarketingPindanGoodsService::refundGoods($refundGoodsData);
}
/**
* 通过goods_sku_id 获取 拼单商品的ota信息
......@@ -1973,4 +1981,69 @@ class GoodsService
}
return $data;
}
/**
* 下单时获取商品数据
* @param array $params
* @return array
*/
public static function getPlaceOrderGoodsList($params)
{
if (!$goodsSkuList = self::getPlaceOrderGoodsSkuList($params)) {
return [];
}
$goodsSpuList = self::getGoodsSpuList(['goods_spu_id' => array_column($goodsSkuList, 'goods_spu_id')]);
$goodsSpuList = array_column($goodsSpuList, null, 'goods_spu_id');
$goodsSkuData = [];
foreach ($goodsSkuList as $goodsInfo) {
if (!empty($goodsSpuList[$goodsInfo['goods_spu_id']])) {
$goodsSpuInfo = $goodsSpuList[$goodsInfo['goods_spu_id']];
$goodsSkuData[] = [
'goods_sku_id' => $goodsInfo['goods_sku_id'],
'goods_spu_id' => $goodsInfo['goods_spu_id'],
'goods_version' => $goodsInfo['goods_version'],
'price' => $goodsInfo['price'],
'clear_price' => $goodsInfo['clear_price'],
'rule_limit' => $goodsInfo['rule_limit'],
'online_status' => $goodsInfo['online_status'],
'inventory_rest' => $goodsInfo['inventory_rest'],
'rule_refund' => $goodsSpuInfo['rule_refund'],
'goods_sale_type' => $goodsSpuInfo['goods_sale_type'],
'goods_type' => $goodsSpuInfo['goods_type'],
'shop_id' => $goodsSpuInfo['shop_id'],
'life_account_id' => $goodsSpuInfo['life_account_id']
];
}
}
return $goodsSkuData;
}
/**
* 下单时获取商品sku数据
* @param array $params
* @return array
*/
public static function getPlaceOrderGoodsSkuList($params)
{
if (empty($params['goods_sku_id'])) {
return [];
}
$goodsSkuIdList = [];
foreach ($params['goods_sku_id'] as $goodsSkuId) {
$goodsParams = GoodsSkuId::getGoodsSkuIdParams($goodsSkuId);
$goodsSkuIdList[$goodsParams['goods_type']][] = $goodsSkuId;
}
$goodsSkuList = [];
foreach ($goodsSkuIdList as $goodsType => $goodsSkuIds) {
// 现在只有两种类型 实体,虚拟
if ($goodsType == GoodsSpu::TYPE_VIRTUAL) {
$goodsData = self::generalGetGoodsSkuList(['goods_sku_id' => $goodsSkuIds]);
} else {
$goodsData = self::generalGetPindanGoodsSkuList(['goods_sku_id' => $goodsSkuIds]);
}
$goodsSkuList = array_merge($goodsSkuList, $goodsData);
}
return $goodsSkuList;
}
}
\ No newline at end of file
......@@ -471,20 +471,22 @@ class MarketingPindanGoodsService
}
/**
* 退款拼单商品,库存调整
* 退款拼单商品,库存调整 (批量退库存)
* @param $params
* @return bool
* @throws GoodsException
*/
public static function refundGoods($params)
public static function refundGoods($dataJson)
{
if (empty($dataJson)){
throw new GoodsException(["cus" => GoodsException::PARAMS_NULL_ERROR]);
}
PindanGoodsSku::beginTransaction();
foreach ($dataJson as $params){
$sku = PindanGoodsSku::get("*", ["goods_sku_id" => $params["goods_sku_id"]]);
if (empty($sku)) {
throw new GoodsException(["cus" => 15]);
}
PindanGoodsSku::beginTransaction();
$records = GoodsRefundRecord::getRecordMaster([
"goods_sku_id" => $params["goods_sku_id"],
"order_item_id" => $params["order_item_id"],
......@@ -504,9 +506,7 @@ class MarketingPindanGoodsService
"total_amount_order[-]" => $params["num"],
"inventory_rest[+]" => $params["num"],
], ["goods_sku_id" => $sku["goods_sku_id"], "total_amount_sold[>=]" => $params["num"], "total_amount_order[>=]" => $params["num"]]);
FileLog::info('goods_refund_log', 'json decode error raw:' . json_encode($params));
if ($row < 1){
PindanGoodsSku::rollback();
GoodsRefundRecord::save([
......@@ -519,7 +519,7 @@ class MarketingPindanGoodsService
throw new GoodsException(["cus" => 0]);
}
}
}
if (!PindanGoodsSku::commit()) {
PindanGoodsSku::rollback();
throw new GoodsException(["cus" => 0]);
......
......@@ -355,11 +355,6 @@ class MarketingService
$lists[$key]["online_status_desc"] = Marketing::$onlineStatusDesc[$value["online_status"]];
if (!empty($priceData[$value["marketing_id"]])) {
$currentLifeAccountId = $priceData[$value["marketing_id"]]["publish_life_account_id"];
//小程序前端过滤掉线上测试生活号发布的活动
//TODO::预发环境要调整这里
if ($params['from'] == 1 && $currentLifeAccountId == self::ONLINE_LIFE_ACCOUNT_ID_TEST) {
continue;
}
$lists[$key]["publish_life_account_id"] = $currentLifeAccountId;
if (!empty($lifeAccountList[$currentLifeAccountId])) {
......@@ -1101,7 +1096,6 @@ class MarketingService
$marketingData["life_account_icon"] = $lifeAccountList[$pindanMarketing["publish_life_account_id"]]["life_account_icon"];
$marketingData["life_account_register_days"] = self::countAccountRegisterDays($lifeAccountList[$pindanMarketing["publish_life_account_id"]]['create_time']);
}
$marketingData["id"] = $marketingInfo["marketing_id"];
$marketingData["marketing_name"] = $marketingInfo["marketing_name"];
$marketingData["good_count"] = $marketingInfo["good_count"];
......@@ -1197,6 +1191,7 @@ class MarketingService
return $info;
}
public static function getMarketingList($params)
{
$where['marketing_id'] = !empty($params['marketing_id']) ? $params['marketing_id'] : '';
......
......@@ -6,8 +6,8 @@
"require": {
"php": "7.2.*",
"ext-json": "*",
"api/php_services":"1.0.15",
"api/php_utils":"1.0.17",
"api/php_services":"1.0.14",
"ext-openssl": "*"
},
"minimum-stability": "dev",
......
This diff is collapsed.
......@@ -44,6 +44,23 @@ class FeiPrinter extends \Api\PhpServices\Printer\Printer
*/
private const API_ADD_PRINTER = "Open_printerAddlist";
/**
* 打印(标签)
*/
private const API_LABEL_PRINT = "Open_printLabelMsg";
/**
* 标签打印常量
*/
private const LABEL_WIDTH = 320;
private const LABEL_HIGH = 240;
private const LABEL_FONT = 12;
private const LABEL_MARGIN_WIDTH = 20;
private const LABEL_MARGIN_HIGH = 20;
private const LABEL_PADDING = 45;
private const LABEL_FIELD_PADDING = 30;
private const LABEL_WORD_FULL_WIDTH = 22.4;
private const LABEL_WORD_HALF_WIDTH = 11.2;
/**
* @param string $apiName api 名字
......@@ -192,4 +209,99 @@ class FeiPrinter extends \Api\PhpServices\Printer\Printer
}
throw new \Exception("接口调用异常");
}
/**
* 测试标签打印机
* 570203776
* alter table ota add column `label_printer_sn` varchar(50) NOT NULL DEFAULT '' COMMENT '打印机SN' after `printer_key`, add column `label_printer_key` varchar(50) NOT NULL DEFAULT '' after `label_printer_sn`;
* @param string $printerId
* @param array $content
$content = [
'维多利亚',
'西红柿教育-维多利亚D1015',
'B:干豆角红烧肉+炝炒圆白菜(含米饭)',
'孟维甫 186****5946'
];
* @return string
* @throws \Exception
*/
public function printLabelContent(string $printerId, array $content): string
{
$rowCount = count($content);
$firstRow = true;
$lastRow = false;
$formatContent = '';
$fontSize = self::LABEL_FONT;
$Y = self::LABEL_MARGIN_HIGH;
foreach (array_values($content) as $key => $row) {
// 判断是否是最后一行
($key + 1) == $rowCount && $lastRow = true;
//获取 换行后的每一行
$wrappedRow = self::_getWrappedRow($row);
foreach ($wrappedRow as $r) {
$wordWidth = mb_strwidth($r) * self::LABEL_WORD_HALF_WIDTH;
if ($lastRow) { // 右对齐
$X = intval(self::LABEL_WIDTH - $wordWidth - self::LABEL_MARGIN_WIDTH);
}
else if($firstRow) { //居中
$X = intval((self::LABEL_WIDTH - self::LABEL_MARGIN_WIDTH * 2 - $wordWidth) / 2) + self::LABEL_MARGIN_WIDTH;
}
else { // 左对齐
$X = self::LABEL_MARGIN_WIDTH;
}
$formatContent .= "<TEXT x=\"{$X}\" y=\"{$Y}\" font=\"{$fontSize}\" w=\"1\" h=\"1\" r=\"0\">{$r}</TEXT>";
$firstRow = false;
$Y += self::LABEL_FIELD_PADDING;
}
$Y += (self::LABEL_PADDING - self::LABEL_FIELD_PADDING);
}
$res = $this->request(self::API_LABEL_PRINT, [
'sn' => $printerId,
'content' => $formatContent,
'times' => 1,// 打印联数
]);
if ($res['code'] == 0 && isset($res['response'])) {
if ($res['response']['ret'] == 0) {
return $res['response']['data'];
}
throw new \Exception($res['response']['msg']);
}
throw new \Exception("接口调用异常");
}
/**
* 自动换行
* @param string $row
* @return array
*/
private static function _getWrappedRow(string $row) : array
{
$wrappedRow = [];
$XCapacity = self::LABEL_WIDTH - self::LABEL_MARGIN_WIDTH * 2;
$wordWidth = mb_strwidth($row) * self::LABEL_WORD_HALF_WIDTH;
if ($wordWidth > $XCapacity) {
$begin = 0;
for ($i = 1; $i <= mb_strlen($row); $i++) {
$r = mb_substr($row, $begin, $i - $begin);
$rWidth = mb_strwidth($r) * self::LABEL_WORD_HALF_WIDTH;
if ($rWidth > $XCapacity) {
$wrappedRow[] = mb_substr($row, $begin, $i - $begin - 1);
$begin = $i - 1;
}
}
$wrappedRow[] = mb_substr($row, $begin);
}
else {
$wrappedRow[] = $row;
}
return $wrappedRow;
}
}
\ No newline at end of file
......@@ -42,6 +42,14 @@ abstract class Printer
*/
abstract public function printContent(string $printerId, array $content): string;
/**
* 打印
* @param string $printerId
* @param array $content 要打印的内容 支持一位数组 二维数组
* @return string 打印OrderID, ID
*/
abstract public function printLabelContent(string $printerId, array $content): string;
/**
* 查询打印状态
* @param string $orderId 为printContent 返回
......
......@@ -338,7 +338,7 @@ class ClassLoader
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
* @return true|null True if loaded, null otherwise
*/
public function loadClass($class)
{
......@@ -347,6 +347,8 @@ class ClassLoader
return true;
}
return null;
}
/**
......
This diff is collapsed.
......@@ -141,6 +141,7 @@ return array(
'App\\Models\\user\\mysql\\UserWechatBind' => $baseDir . '/application/models/user/mysql/UserWechatBind.php',
'App\\Plugins\\Hook' => $baseDir . '/application/plugins/Hook.php',
'App\\Services\\common\\CommonService' => $baseDir . '/application/services/common/CommonService.php',
'App\\Services\\common\\KafkaService' => $baseDir . '/application/services/common/KafkaService.php',
'App\\Services\\demo\\ElasticService' => $baseDir . '/application/services/demo/ElasticService.php',
'App\\Services\\demo\\MongoService' => $baseDir . '/application/services/demo/MongoService.php',
'App\\Services\\demo\\MysqlService' => $baseDir . '/application/services/demo/MysqlService.php',
......
......@@ -8,18 +8,18 @@ $baseDir = dirname($vendorDir);
return array(
'a4a119a56e50fbb293281d9a48007e0e' => $vendorDir . '/symfony/polyfill-php80/bootstrap.php',
'6e3fae29631ef280660b3cdad06f25a8' => $vendorDir . '/symfony/deprecation-contracts/function.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
'8825ede83f2f289127722d4e842cf7e8' => $vendorDir . '/symfony/polyfill-intl-grapheme/bootstrap.php',
'e69f7f6ee287b969198c3c9d6777bd38' => $vendorDir . '/symfony/polyfill-intl-normalizer/bootstrap.php',
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
'e69f7f6ee287b969198c3c9d6777bd38' => $vendorDir . '/symfony/polyfill-intl-normalizer/bootstrap.php',
'8825ede83f2f289127722d4e842cf7e8' => $vendorDir . '/symfony/polyfill-intl-grapheme/bootstrap.php',
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
'b6b991a57620e2fb6b2f66f03fe9ddc2' => $vendorDir . '/symfony/string/Resources/functions.php',
'0d59ee240a4cd96ddbb4ff164fccea4d' => $vendorDir . '/symfony/polyfill-php73/bootstrap.php',
'7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php',
'ad155f8f1cf0d418fe49e248db8c661b' => $vendorDir . '/react/promise/src/functions_include.php',
'0d59ee240a4cd96ddbb4ff164fccea4d' => $vendorDir . '/symfony/polyfill-php73/bootstrap.php',
'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php',
'a9ed0d27b5a698798a89181429f162c5' => $vendorDir . '/khanamiryan/qrcode-detector-decoder/lib/Common/customFunctions.php',
'8592c7b0947d8a0965a9e8c3d16f9c24' => $vendorDir . '/elasticsearch/elasticsearch/src/autoload.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
'3a37ebac017bc098e9a86b35401e7a68' => $vendorDir . '/mongodb/mongodb/src/functions.php',
'8592c7b0947d8a0965a9e8c3d16f9c24' => $vendorDir . '/elasticsearch/elasticsearch/src/autoload.php',
);
This diff is collapsed.
......@@ -434,6 +434,8 @@ class OptionsResolver implements Options
* @param string $package The name of the composer package that is triggering the deprecation
* @param string $version The version of the package that introduced the deprecation
* @param string|\Closure $message The deprecation message to use
*
* @return $this
*/
public function setDeprecated(string $option/*, string $package, string $version, $message = 'The option "%name%" is deprecated.' */): self
{
......
......@@ -602,6 +602,9 @@ final class Mbstring
if (80000 > \PHP_VERSION_ID) {
return false;
}
if (\is_int($c) || 'long' === $c || 'entity' === $c) {
return false;
}
throw new \ValueError('Argument #1 ($substitute_character) must be "none", "long", "entity" or a valid codepoint');
}
......
......@@ -9,6 +9,8 @@
* file that was distributed with this source code.
*/
class JsonException extends Exception
{
if (\PHP_VERSION_ID < 70300) {
class JsonException extends Exception
{
}
}
<?php
class UnhandledMatchError extends Error
{
if (\PHP_VERSION_ID < 80000) {
class UnhandledMatchError extends Error
{
}
}
<?php
class ValueError extends Error
{
if (\PHP_VERSION_ID < 80000) {
class ValueError extends Error
{
}
}
......@@ -313,11 +313,9 @@ class PropertyAccessor implements PropertyAccessorInterface
if (!$zval[self::VALUE] instanceof \ArrayAccess && !\is_array($zval[self::VALUE])) {
return false;
}
} else {
if (!$this->isPropertyWritable($zval[self::VALUE], $propertyPath->getElement($i))) {
} elseif (!\is_object($zval[self::VALUE]) || !$this->isPropertyWritable($zval[self::VALUE], $propertyPath->getElement($i))) {
return false;
}
}
if (\is_object($zval[self::VALUE])) {
return true;
......@@ -663,10 +661,6 @@ class PropertyAccessor implements PropertyAccessorInterface
*/
private function isPropertyWritable(object $object, string $property): bool
{
if (!\is_object($object)) {
return false;
}
$mutatorForArray = $this->getWriteInfo(\get_class($object), $property, []);
if (PropertyWriteInfo::TYPE_NONE !== $mutatorForArray->getType() || ($object instanceof \stdClass && property_exists($object, $property))) {
......
......@@ -44,6 +44,8 @@ class PropertyAccessorBuilder
/**
* Enables the use of all magic methods by the PropertyAccessor.
*
* @return $this
*/
public function enableMagicMethods(): self
{
......@@ -54,6 +56,8 @@ class PropertyAccessorBuilder
/**
* Disable the use of all magic methods by the PropertyAccessor.
*
* @return $this
*/
public function disableMagicMethods(): self
{
......@@ -86,6 +90,8 @@ class PropertyAccessorBuilder
/**
* Enables the use of "__set" by the PropertyAccessor.
*
* @return $this
*/
public function enableMagicSet(): self
{
......@@ -108,6 +114,8 @@ class PropertyAccessorBuilder
/**
* Disables the use of "__get" by the PropertyAccessor.
*
* @return $this
*/
public function disableMagicGet(): self
{
......@@ -118,6 +126,8 @@ class PropertyAccessorBuilder
/**
* Disables the use of "__set" by the PropertyAccessor.
*
* @return $this
*/
public function disableMagicSet(): self
{
......@@ -227,7 +237,7 @@ class PropertyAccessorBuilder
/**
* Sets a cache system.
*
* @return PropertyAccessorBuilder
* @return $this
*/
public function setCacheItemPool(CacheItemPoolInterface $cacheItemPool = null)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment