MqController.php 4.1 KB

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