MqController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace console\controllers;
  3. use bizGhs\book\classes\BookItemCustomClass;
  4. use bizHd\purchase\classes\PurchaseClass;
  5. use bizHd\shop\classes\ShopClass;
  6. use biz\wx\classes\WxMessageClass;
  7. use yii\console\Controller;
  8. use bizGhs\order\classes\OrderClass;
  9. use \common\components\push;
  10. use Yii;
  11. class MqController extends Controller
  12. {
  13. //预订变化下架花材 ssh 20240729
  14. public function actionBookChangeOutStock()
  15. {
  16. $noticeKey = "bookChangeOffItem";
  17. while ($count = Yii::$app->redis->executeCommand('LLEN', [$noticeKey])) {
  18. $json = Yii::$app->redis->executeCommand('RPOP', [$noticeKey]);
  19. //$json = '{"id":163,"num":"1","shopId":36523}';
  20. if (!empty($json)) {
  21. $arr = json_decode($json, true);
  22. $id = $arr['id'] ?? 0;
  23. $num = $arr['num'] ?? 0;
  24. $shopId = $arr['shopId'] ?? 0;
  25. $res = BookItemCustomClass::getById($id, true);
  26. if (!empty($res)) {
  27. $shop = \biz\shop\classes\ShopClass::getById($shopId, true);
  28. WxMessageClass::bookChangeOutStockInform($shop, $res, $num);
  29. }
  30. }
  31. }
  32. }
  33. //花店采购通知供货商 ssh 20230805
  34. public function actionHdCgNoticeGhs()
  35. {
  36. $noticeKey = "hdCgNoticeGhs";
  37. while ($count = Yii::$app->redis->executeCommand('LLEN', [$noticeKey])) {
  38. $json = Yii::$app->redis->executeCommand('RPOP', [$noticeKey]);
  39. if (!empty($json)) {
  40. $arr = json_decode($json, true);
  41. $orderId = $arr['orderId'] ?? 0;
  42. if (!empty($orderId)) {
  43. $order = OrderClass::getById($orderId, true);
  44. $shopId = $order->shopId ?? 0;
  45. $shop = ShopClass::getById($shopId, true);
  46. if (!empty($shop)) {
  47. WxMessageClass::ghsHasNewOrderInform($shop, $order);
  48. // 向供货商App发通知
  49. $allDevices = \bizGhs\device\classes\GhsDeviceClass::getAllByCondition(['shopId'=>$shopId]);
  50. $cids = array_column($allDevices, 'clientId');
  51. $title = '你有新的订单';
  52. $content = $shop->shopName . ' ¥' . $order->actPrice;
  53. $payload = [
  54. "page" => "pagesOrder/detail",
  55. "params" => ["id" => $order->id]
  56. ];
  57. $push = new push('ghs', push::MSG_TYPE_ORDER);
  58. $push->pushByCloud($cids, $title, $content, $payload);
  59. }
  60. }
  61. }
  62. }
  63. }
  64. //预订增加减少通知 ssh 20240820
  65. public function actionBookChangeNotice()
  66. {
  67. $noticeKey = "bookChangeNoticeStaff";
  68. while ($count = Yii::$app->redis->executeCommand('LLEN', [$noticeKey])) {
  69. $json = Yii::$app->redis->executeCommand('RPOP', [$noticeKey]);
  70. if (!empty($json)) {
  71. $arr = json_decode($json, true);
  72. $shopId = $arr['shopId'] ?? 0;
  73. if (!empty($shopId)) {
  74. $shop = ShopClass::getById($shopId, true);
  75. if (!empty($shop)) {
  76. WxMessageClass::bookChangeInform($shop, $arr);
  77. }
  78. }
  79. }
  80. }
  81. }
  82. //供货商开单通知花店 ssh 20231129
  83. public function actionGhsKdNoticeHd()
  84. {
  85. $noticeKey = "ghsKdNoticeHd";
  86. while ($count = Yii::$app->redis->executeCommand('LLEN', [$noticeKey])) {
  87. $json = Yii::$app->redis->executeCommand('RPOP', [$noticeKey]);
  88. if (!empty($json)) {
  89. $arr = json_decode($json, true);
  90. $id = $arr['id'] ?? 0;
  91. if (!empty($id)) {
  92. $cg = PurchaseClass::getById($id, true);
  93. $shopId = $cg->shopId ?? 0;
  94. $shop = ShopClass::getById($shopId, true);
  95. if (!empty($shop)) {
  96. WxMessageClass::hdNewCgOrderInform($shop, $cg);
  97. }
  98. }
  99. }
  100. }
  101. }
  102. }