|
|
@@ -7,6 +7,7 @@ use biz\item\classes\PtItemClass;
|
|
|
use biz\item\classes\PtItemClassClass;
|
|
|
use biz\item\classes\UnitClass;
|
|
|
use biz\shop\services\ShopService;
|
|
|
+use biz\wx\classes\WxMessageClass;
|
|
|
use bizGhs\base\classes\BaseClass;
|
|
|
use bizGhs\item\classes\ItemClass;
|
|
|
use bizGhs\item\classes\ItemClassClass;
|
|
|
@@ -15,6 +16,7 @@ use bizGhs\order\classes\CheckOrderClass;
|
|
|
use bizGhs\order\classes\CheckOrderItemClass;
|
|
|
use bizGhs\order\traits\OrderTrait;
|
|
|
use bizGhs\stock\services\StockRecordService;
|
|
|
+use common\components\dict;
|
|
|
use common\components\imgUtil;
|
|
|
use common\components\orderSn;
|
|
|
use common\components\stringUtil;
|
|
|
@@ -1025,7 +1027,7 @@ class ProductClass extends BaseClass
|
|
|
|
|
|
//小菊的结构
|
|
|
$ptItemId = $data['itemId'] ?? 0;
|
|
|
- $ptItemInfo = PtItemClass::getById($ptItemId,true);
|
|
|
+ $ptItemInfo = PtItemClass::getById($ptItemId, true);
|
|
|
$data['variety'] = $ptItemInfo->variety ?? 0;
|
|
|
|
|
|
//根据sjId, 找到所有的shopId,都添加
|
|
|
@@ -1135,4 +1137,68 @@ class ProductClass extends BaseClass
|
|
|
$data = self::getGhsItemAll($sjId, 'classId,itemId');
|
|
|
return $data;
|
|
|
}
|
|
|
+
|
|
|
+ //库存预警通知 shish 20210909
|
|
|
+ public static function stockWarningAddQueue($product, $stock)
|
|
|
+ {
|
|
|
+ $warningNum = $product['stockWarning'] ?? 0;
|
|
|
+ if ($warningNum <= 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $date = date("Y-m-d");
|
|
|
+ $productId = $product['id'] ?? 0;
|
|
|
+ $key = 'stockWarning_' . $productId . '_' . $date;
|
|
|
+
|
|
|
+ //当天已经放入队列通知的不再通知
|
|
|
+ $hasWarning = Yii::$app->redis->executeCommand('GET', [$key]);
|
|
|
+ if (isset($hasWarning) && !empty($hasWarning)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($stock <= $warningNum) {
|
|
|
+ Yii::$app->redis->executeCommand('SETEX', [$key, 86400, 'hasWarning']);
|
|
|
+
|
|
|
+ $shopId = $product['shopId'] ?? 0;
|
|
|
+ if (empty($shopId)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //队列方式去处理
|
|
|
+ $stockWarningListKey = 'stockWarningList_' . $shopId;
|
|
|
+ Yii::$app->redis->executeCommand('LPUSH', [$stockWarningListKey, $productId]);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //所有门店进行库存通知 shish 20210909
|
|
|
+ public static function allShopStockWarningFromQueue()
|
|
|
+ {
|
|
|
+ $ghs = dict::getDict('ptStyle', 'ghs');
|
|
|
+ $shopList = ShopClass::getAllByCondition(['ptStyle' => $ghs], null, '*', null, true);
|
|
|
+ if (!empty($shopList)) {
|
|
|
+ foreach ($shopList as $key => $shop) {
|
|
|
+ $ids = [];
|
|
|
+ $shopId = $shop->id ?? 0;
|
|
|
+ $stockWarningListKey = 'stockWarningList_' . $shopId;
|
|
|
+ echo $stockWarningListKey."\n";
|
|
|
+ while ($count = Yii::$app->redis->executeCommand('LLEN', [$stockWarningListKey])) {
|
|
|
+ $productId = Yii::$app->redis->executeCommand('RPOP', [$stockWarningListKey]);
|
|
|
+ if (is_numeric($productId)) {
|
|
|
+ $ids[] = $productId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (empty($ids)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $ids = array_unique(array_filter($ids));
|
|
|
+ $productList = ProductClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
|
|
|
+ if (!empty($productList)) {
|
|
|
+ foreach ($productList as $product) {
|
|
|
+ WxMessageClass::stockWarningInform($shop, $product);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|