| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace addons\WechatVideoShop\console\controllers;
- use addons\WechatVideoShop\common\enums\WechatVideoShopEnums;
- use addons\WechatVideoShop\common\expand\sdk\weixin\src\model\basic\AddressCodeModel;
- use addons\WechatVideoShop\common\expand\sdk\weixin\src\request\basic\AddressCodeRequest;
- use addons\WechatVideoShop\common\helper\WechatRequestHelper;
- use addons\WechatVideoShop\common\logic\SyncRefundLogic;
- use addons\WechatVideoShop\common\logic\SyncSharerLogic;
- use addons\WechatVideoShop\common\models\WechatVideoShop;
- use addons\WechatVideoShop\common\models\WechatVideoShopRegion;
- use common\enums\StatusEnum;
- use common\helpers\FormatHelper;
- use common\models\mall\Mall;
- use common\models\mall\MallAddons;
- use yii\console\Controller;
- class SyncController extends Controller
- {
- /**
- * 每分钟一次 - 同步分销员
- * @return void
- */
- public function actionSharer()
- {
- // 同步分销员
- SyncSharerLogic::sharer();
- }
- /**
- * 每5分钟同步一次退款
- * @return void
- */
- public function actionRefund()
- {
- SyncRefundLogic::refund();
- }
- public function actionUnionid()
- {
- $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";
- $resp = file_get_contents($url);
- var_dump($resp);
- }
- public function actionRegion()
- {
- foreach (Mall::getAllMallIds() as $mallId) {
- $config = \Yii::$app->services->setting->addons->get($mallId, WechatVideoShopEnums::ADDONS_NAME, 'basic');
- if (!empty($config['is_enable']) && !empty($config['sharer_default_apply_shop_id'])) {
- $config = WechatVideoShop::findOne(['id' => $config['sharer_default_apply_shop_id']]);
- break;
- }
- $config = null;
- }
- if (!empty($config)) {
- /**
- * @var $region WechatVideoShopRegion
- */
- foreach (WechatVideoShopRegion::find()->where(['status' => StatusEnum::ENABLED])
- ->andWhere(['<', 'level', 4])
- ->each() as $region) {
- $req = new AddressCodeRequest($config->toArray());
- $model = new AddressCodeModel();
- $model->addr_code = intval($region->id);
- try {
- $resp = WechatRequestHelper::accessTokenAndToArray($req, $model);
- if (!empty($resp['addrs_msg'])) {
- $region->name = $resp['addrs_msg']['name'];
- }
- } catch (\Exception $e) {
- \Yii::error(FormatHelper::exception($e, __METHOD__));
- $region->status = -1;
- }
- $region->save();
- }
- }
- }
- }
|