InitController.php 7.6 KB

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