InitController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace console\controllers;
  3. use biz\merchant\services\MerchantService;
  4. use biz\user\services\UserService;
  5. use biz\wx\services\WxOpenService;
  6. use common\services\xhAdminService;
  7. use common\services\xhMerchantAssetService;
  8. use common\services\xhMerchantExtendService;
  9. use common\services\xhWxMenuService;
  10. use Yii;
  11. use yii\console\Controller;
  12. use common\components\util;
  13. use common\services\xhTMessageService;
  14. use common\services\xhMerchantService;
  15. use common\models\xhMerchant;
  16. use common\services\xhInitService;
  17. /**
  18. * 脚本
  19. */
  20. class InitController extends Controller
  21. {
  22. //开店初始化 shish 2020.2.8
  23. public function actionRabbit()
  24. {
  25. $data = ['merchantId' => 12362];
  26. $producer = Yii::$app->rabbitmq->getProducer('openShopInitProducer');
  27. $msg = serialize($data);
  28. $producer->publish($msg, 'openShopInitExchange', 'openShopInitRoute');
  29. }
  30. //二次初始化 shish 2020.1.19
  31. public function actionSecondInit($id = 0)
  32. {
  33. $merchant = xhMerchantService::getById($id);
  34. if (empty($merchant)) {
  35. echo "商家无效\n";
  36. }
  37. //初始化微信菜单
  38. xhWxMenuService::applyInit($merchant);
  39. }
  40. public function actionChangeDb()
  41. {
  42. echo 'ok';
  43. }
  44. //接入一个商家需要的操作 shish 2019.9.7
  45. // yii init/join-one 12358 更新某个商家公众号
  46. // yii init/join-one 更新平台公众号
  47. public function actionJoinOne($id = 0)
  48. {
  49. //初始化微信菜单
  50. if ($id == 0) {
  51. $isOpen = 1;
  52. $merchant = WxOpenService::getWxInfo();
  53. $merchant['id'] = 0;
  54. } else {
  55. $isOpen = 0;
  56. $merchant = xhMerchantService::getById($id);
  57. }
  58. //xhWxMenuService::applyInit($merchant);
  59. //模板消息
  60. $r = xhTMessageService::supplement($merchant, $isOpen);
  61. print_r($r);
  62. }
  63. //yii init/sub
  64. public function actionSub()
  65. {
  66. $name = 'redis_shi';
  67. $redisPubSub = \Yii::$app->redisPubSub;
  68. $redisPubSub->setOptReadTimeout(-1);
  69. $redisPubSub->subscribe($name, function ($instance, $channelName, $message) {
  70. $a = 123;
  71. });
  72. }
  73. public function actionPub()
  74. {
  75. $name = 'redis_shi';
  76. $time = 'nihao1123';
  77. $redisPubSub = \Yii::$app->redisPubSub;
  78. $redisPubSub->publish($name, $time);
  79. }
  80. public function actionPullUser()
  81. {
  82. //拉取用户
  83. $this->actionPullUser();
  84. }
  85. // 拉取微信用户 shish 2019.9.9
  86. public function actionPullUser2()
  87. {
  88. $merchantId = 12359;
  89. $return = UserService::syncWxAllUser($merchantId);
  90. $total = isset($return['data']['total']) ? $return['data']['total'] : 0;
  91. xhMerchantAssetService::updateByMerchantId($merchantId, ['totalFans' => $total]);
  92. }
  93. }