InitController.php 7.4 KB

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