InitController.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. namespace console\controllers;
  3. use biz\merchant\services\MerchantService;
  4. use biz\user\services\UserService;
  5. use common\services\xhAdminService;
  6. use common\services\xhMerchantAssetService;
  7. use common\services\xhMerchantExtendService;
  8. use common\services\xhWxMenuService;
  9. use Yii;
  10. use yii\console\Controller;
  11. use common\components\util;
  12. use common\services\xhTMessageService;
  13. use common\services\xhMerchantService;
  14. use common\models\xhMerchant;
  15. use common\services\xhInitService;
  16. /**
  17. * 脚本
  18. */
  19. class InitController extends Controller
  20. {
  21. //开店初始化 shish 2020.2.8
  22. public function actionRabbit()
  23. {
  24. $data = ['merchantId' => 12362];
  25. $producer = Yii::$app->rabbitmq->getProducer('openShopInitProducer');
  26. $msg = serialize($data);
  27. $producer->publish($msg, 'openShopInitExchange', 'openShopInitRoute');
  28. }
  29. //哪些东西开店时需要初始化!!!!!
  30. public function actionFirstInit()
  31. {
  32. //CouponAsset优惠券资产
  33. //初始化微信菜单
  34. //模板消息
  35. }
  36. //二次初始化 shish 2020.1.19
  37. public function actionSecondInit($id = 0)
  38. {
  39. $merchant = xhMerchantService::getById($id);
  40. if (empty($merchant)) {
  41. echo "商家无效\n";
  42. }
  43. //初始化微信菜单
  44. xhWxMenuService::applyInit($merchant);
  45. }
  46. public function actionChangeDb()
  47. {
  48. echo 'ok';
  49. }
  50. //接入一个商家需要的操作 shish 2019.9.7 yii init/join-one
  51. public function actionJoinOne()
  52. {
  53. $id = 12360;
  54. //初始化微信菜单
  55. $merchant = xhMerchantService::getById($id);
  56. //xhWxMenuService::applyInit($merchant);
  57. //模板消息
  58. $r = xhTMessageService::supplement($merchant);
  59. print_r($r);
  60. }
  61. //yii init/sub
  62. public function actionSub()
  63. {
  64. $name = 'redis_shi';
  65. $redisPubSub = \Yii::$app->redisPubSub;
  66. $redisPubSub->setOptReadTimeout(-1);
  67. $redisPubSub->subscribe($name, function ($instance, $channelName, $message) {
  68. $a = 123;
  69. });
  70. }
  71. public function actionPub()
  72. {
  73. $name = 'redis_shi';
  74. $time = 'nihao1123';
  75. $redisPubSub = \Yii::$app->redisPubSub;
  76. $redisPubSub->publish($name, $time);
  77. }
  78. public function actionBegin()
  79. {
  80. //先清除公众号里的模板消息!!!!!!!
  81. $num = 0;
  82. //清空数据
  83. $this->actionFlushAll();
  84. //国兰花尚
  85. if ($num == 0) {
  86. xhAdminService::updateById(1, ['mobile' => '18030142050', 'password' => '6a348767a0b612172e5da7539de20cb5', 'confirmPassword' => 'c80fd29375a3a91d3681d8445822248a', 'adminName' => '姜祖岚']);
  87. xhMerchantService::updateById(12358, [
  88. 'merchantName' => '国兰花尚',
  89. 'miniAppId' => 'wxe994a9f5fd036f69',
  90. 'miniAppSecret' => '53b646675251e940f56bd304c2dba480',
  91. 'wxAppId' => 'wx193341a4a80f6ea3',
  92. 'wxUserName' => 'gh_090c30df22e6',
  93. 'wxAliasName' => 'glhs520',
  94. 'openAppId' => 'wxe9211595a1d5a39f',
  95. 'wxToken' => 'wt01467284437',
  96. 'status' => 1,
  97. ]);
  98. xhMerchantExtendService::updateByMerchantId(12358, [
  99. 'wxAppId' => 'wx193341a4a80f6ea3',
  100. 'miniAppId' => 'wxe994a9f5fd036f69',
  101. 'wxPayMerchantId' => '1244548702',
  102. 'wxPayKey' => 'eez23jf739jsmm4309j10jnza3qw8dwm',
  103. 'webTitle' => '国兰花尚',
  104. 'webKeyword' => '国兰花尚',
  105. 'webDescription' => '国兰花尚',
  106. 'alipayAccount' => '18030142050',
  107. 'alipayAccountName' => '游俊涛',
  108. ]);
  109. }
  110. //花美灵
  111. if ($num == 1) {
  112. xhAdminService::updateById(1, ['mobile' => '15280215347', 'password' => '6a348767a0b612172e5da7539de20cb5', 'confirmPassword' => '6a348767a0b612172e5da7539de20cb5', 'adminName' => '石少华']);
  113. xhMerchantService::updateById(12358, [
  114. 'merchantName' => '花美灵',
  115. 'miniAppId' => 'wxe4675bab299a52f7',
  116. 'miniAppSecret' => '03dd4000a26af5c17fb86321b7d1ebf3',
  117. 'wxAppId' => 'wx84d95afcb7b594eb',
  118. 'wxUserName' => 'gh_090c30df22e6',
  119. 'wxAliasName' => 'glhs520',
  120. 'wxToken' => 'wt01467284437',
  121. 'openAppId' => 'wxb46e972ab18f27bb',
  122. 'status' => 1,
  123. ]);
  124. xhMerchantExtendService::updateByMerchantId(12358, [
  125. 'wxAppId' => 'wx84d95afcb7b594eb',
  126. 'miniAppId' => 'wxe4675bab299a52f7',
  127. 'wxPayMerchantId' => '1371367002',
  128. 'wxPayKey' => 'eoz23aG739jscv4309275jnza32wvdwm',
  129. 'webTitle' => '花美灵',
  130. 'webKeyword' => '花美灵',
  131. 'webDescription' => '花美灵',
  132. 'alipayAccount' => 'shishaohua8879@sina.com',
  133. 'alipayAccountName' => '石少华',
  134. ]);
  135. }
  136. //花卉宝
  137. if ($num == 2) {
  138. xhAdminService::updateById(1, ['mobile' => '15280215347', 'password' => '6a348767a0b612172e5da7539de20cb5', 'confirmPassword' => '6a348767a0b612172e5da7539de20cb5', 'adminName' => '石少华']);
  139. xhMerchantService::updateById(12358, [
  140. 'merchantName' => '花卉宝',
  141. 'miniAppId' => '',
  142. 'miniAppSecret' => '',
  143. 'wxAppId' => 'wx66dd83ff8744f7a8',
  144. 'wxUserName' => 'gh_a9105e0f02b9',
  145. 'wxAliasName' => 'ihuahuibao',
  146. 'wxToken' => 'wt01467284437',
  147. 'status' => 1,
  148. ]);
  149. xhMerchantExtendService::updateByMerchantId(12358, [
  150. 'wxAppId' => 'wx66dd83ff8744f7a8',
  151. 'miniAppId' => '',
  152. 'wxPayMerchantId' => '1442448402',
  153. 'wxPayKey' => 'xxe29ax639jvcv4m082a1jnza32svdd0',
  154. 'webTitle' => '花卉宝',
  155. 'webKeyword' => '花卉宝',
  156. 'webDescription' => '花卉宝',
  157. 'alipayAccount' => 'shishaohua8879@sina.com',
  158. 'alipayAccountName' => '石少华',
  159. ]);
  160. }
  161. }
  162. public function actionLast()
  163. {
  164. //拉取用户
  165. $this->actionPullUser();
  166. //生成模板消息
  167. //$this->actionTMSupplement();
  168. }
  169. public function actionFlushAll()
  170. {
  171. $sql = "TRUNCATE xhDrawCash;
  172. TRUNCATE xhInvite;
  173. TRUNCATE xhLuckyDrawActivity;
  174. TRUNCATE xhLuckyDrawAward;
  175. TRUNCATE xhLuckyDrawAwardCustomer;
  176. TRUNCATE xhLuckyDrawAwardParticipant;
  177. TRUNCATE xhMerchantCapital;
  178. TRUNCATE xhOrder;
  179. TRUNCATE xhOrderDayNum;
  180. TRUNCATE xhOrderGoods;
  181. TRUNCATE xhOrderMonthNum;
  182. TRUNCATE xhRecharge;
  183. TRUNCATE xhStatDealByDay;
  184. TRUNCATE xhStatInDay;
  185. TRUNCATE xhStatInMonth;
  186. TRUNCATE xhStatOutDay;
  187. TRUNCATE xhStatOutMonth;
  188. TRUNCATE xhStatUserByDay;
  189. TRUNCATE xhStatVisitByDay;
  190. TRUNCATE xhUnionUser;
  191. TRUNCATE xhUser;
  192. TRUNCATE xhUserAlipay;
  193. TRUNCATE xhUserAsset;
  194. TRUNCATE xhUserByDay;
  195. TRUNCATE xhUserByMonth;
  196. TRUNCATE xhUserCapital;
  197. TRUNCATE xhUserIntegral;
  198. TRUNCATE xhUserOldData;
  199. TRUNCATE xhUserByDay;";
  200. //清空用户
  201. $sql .= "TRUNCATE xhUser;TRUNCATE xhUserAsset;TRUNCATE xhUserCapital;TRUNCATE xhUserIntegral;";
  202. $sql .= "TRUNCATE xhUserIntegral;TRUNCATE xhUserAlipay;ALTER TABLE xhUser AUTO_INCREMENT=12536580;";
  203. //清空提现申请记录
  204. $sql .= "TRUNCATE xhDrawCash;";
  205. Yii::$app->db->createCommand($sql)->execute();
  206. //清空订单
  207. $sql = "TRUNCATE xhOrder;TRUNCATE xhOrderDayNum;TRUNCATE xhOrderGoods;TRUNCATE xhOrderMonthNum;";
  208. Yii::$app->db->createCommand($sql)->execute();
  209. //清空缓存
  210. Yii::$app->redis->executeCommand('FLUSHDB');
  211. }
  212. /**
  213. * 拉取微信用户 shish 2019.9.9
  214. */
  215. public function actionPullUser()
  216. {
  217. $merchantId = 12359;
  218. $return = UserService::syncWxAllUser($merchantId);
  219. $total = isset($return['data']['total']) ? $return['data']['total'] : 0;
  220. xhMerchantAssetService::updateByMerchantId($merchantId, ['totalFans' => $total]);
  221. }
  222. /**
  223. * 开放平台初始化
  224. * yii init/open hhb
  225. */
  226. public function actionOpen($myOption = 'hhb')
  227. {
  228. $hostname = isset($_SERVER['HOSTNAME']) ? $_SERVER['HOSTNAME'] : '';
  229. if ($hostname == 'iZ23b0wy8awZ') {
  230. util::stop("线上服务器不允许初始化\n");
  231. }
  232. echo "开始初始化…\n";
  233. xhInitService::clear($myOption);
  234. echo "初始化完成!\n";
  235. }
  236. /**
  237. * 模板消息补充增加
  238. * ./yii init/t-m-supplement
  239. */
  240. public function actionTMSupplement()
  241. {
  242. //服务号
  243. $allMerchant = xhMerchant::getAllByCondition(['status' => 1]);
  244. if (empty($allMerchant)) {
  245. echo "没有商家需要初始化模板消息";
  246. Yii::$app->end();
  247. }
  248. foreach ($allMerchant as $val) {
  249. $merchantId = $val['id'];
  250. $merchant = xhMerchantService::getById($merchantId);
  251. xhTMessageService::supplement($merchant);
  252. }
  253. }
  254. }