SyncController.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace addons\WechatVideoShop\console\controllers;
  3. use addons\WechatVideoShop\common\enums\WechatVideoShopEnums;
  4. use addons\WechatVideoShop\common\expand\sdk\weixin\src\model\basic\AddressCodeModel;
  5. use addons\WechatVideoShop\common\expand\sdk\weixin\src\request\basic\AddressCodeRequest;
  6. use addons\WechatVideoShop\common\helper\WechatRequestHelper;
  7. use addons\WechatVideoShop\common\logic\SyncRefundLogic;
  8. use addons\WechatVideoShop\common\logic\SyncSharerLogic;
  9. use addons\WechatVideoShop\common\models\WechatVideoShop;
  10. use addons\WechatVideoShop\common\models\WechatVideoShopRegion;
  11. use common\enums\StatusEnum;
  12. use common\helpers\FormatHelper;
  13. use common\models\mall\Mall;
  14. use common\models\mall\MallAddons;
  15. use yii\console\Controller;
  16. class SyncController extends Controller
  17. {
  18. /**
  19. * 每分钟一次 - 同步分销员
  20. * @return void
  21. */
  22. public function actionSharer()
  23. {
  24. // 同步分销员
  25. SyncSharerLogic::sharer();
  26. }
  27. /**
  28. * 每5分钟同步一次退款
  29. * @return void
  30. */
  31. public function actionRefund()
  32. {
  33. SyncRefundLogic::refund();
  34. }
  35. public function actionUnionid()
  36. {
  37. $url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=71_f8dSPQAdY61T3Ao6SSIAYQUgQJRI4-c80XZ9Rd4qrLuZxgQUVSkQ-nTpUWvODzilWDCYdLz_wyAzU-N2srWcPsiEp7kZ8WrFnlE9z_KCDQYiUO18O9sIgwMige0EFXiAIATUMACCESS_TOKEN&openid=oxTsl6qlKJ534BKt034WOF0rFtko&lang=zh_CN";
  38. $resp = file_get_contents($url);
  39. var_dump($resp);
  40. }
  41. public function actionRegion()
  42. {
  43. foreach (Mall::getAllMallIds() as $mallId) {
  44. $config = \Yii::$app->services->setting->addons->get($mallId, WechatVideoShopEnums::ADDONS_NAME, 'basic');
  45. if (!empty($config['is_enable']) && !empty($config['sharer_default_apply_shop_id'])) {
  46. $config = WechatVideoShop::findOne(['id' => $config['sharer_default_apply_shop_id']]);
  47. break;
  48. }
  49. $config = null;
  50. }
  51. if (!empty($config)) {
  52. /**
  53. * @var $region WechatVideoShopRegion
  54. */
  55. foreach (WechatVideoShopRegion::find()->where(['status' => StatusEnum::ENABLED])
  56. ->andWhere(['<', 'level', 4])
  57. ->each() as $region) {
  58. $req = new AddressCodeRequest($config->toArray());
  59. $model = new AddressCodeModel();
  60. $model->addr_code = intval($region->id);
  61. try {
  62. $resp = WechatRequestHelper::accessTokenAndToArray($req, $model);
  63. if (!empty($resp['addrs_msg'])) {
  64. $region->name = $resp['addrs_msg']['name'];
  65. }
  66. } catch (\Exception $e) {
  67. \Yii::error(FormatHelper::exception($e, __METHOD__));
  68. $region->status = -1;
  69. }
  70. $region->save();
  71. }
  72. }
  73. }
  74. }