| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- namespace console\controllers;
- use biz\cp\services\PtCpService;
- use biz\main\classes\MainClass;
- use biz\shop\classes\ShopClass;
- use bizGhs\cp\classes\CpClass;
- use bizGhs\cp\classes\CpClassClass;
- use common\components\noticeUtil;
- use common\components\util;
- use yii\console\Controller;
- use Yii;
- class CpController extends Controller
- {
- //创建分店时,复制产品,重要脚本,不能删除
- public function actionCopyCp()
- {
- $copyKey = 'copy_old_cp_to_new_cp';
- $copyList = [];
- while ($count = Yii::$app->redis->executeCommand('LLEN', [$copyKey])) {
- $current = Yii::$app->redis->executeCommand('RPOP', [$copyKey]);
- $copyList[] = $current;
- }
- if (empty($copyList)) {
- return false;
- }
- foreach ($copyList as $copy) {
- $arr = json_decode($copy, true);
- $oldMainId = $arr['oldMainId'] ?? 0;
- $newMainId = $arr['newMainId'] ?? 0;
- $main = MainClass::getById($newMainId, true);
- if (empty($main)) {
- continue;
- }
- $has = CpClassClass::getByCondition(['mainId' => $newMainId], true);
- if (!empty($has)) {
- continue;
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- CpClass::copyCp($oldMainId, $newMainId);
- $transaction->commit();
- noticeUtil::push("success 旧mainId:{$oldMainId}复制产品到新mainId:{$newMainId} 成功", '15280215347');
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("error 旧mainId:{$oldMainId}复制产品到新mainId:{$newMainId} 报错:{$msg}", '15280215347');
- }
- }
- }
- //商家的产品初始化 ssh 20240215
- public function actionInitMainCp()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
- //$shopList = ShopClass::getAllByCondition(['id' => 36523], null, '*', null, true);
- if (empty($shopList)) {
- util::stop('没有找到门店84');
- }
- foreach ($shopList as $shop) {
- $mainId = $shop->mainId;
- $hasClass = CpClass::getByCondition(['mainId' => $mainId], true);
- if (!empty($hasClass)) {
- continue;
- }
- $main = MainClass::getById($mainId, true);
- if (empty($main)) {
- noticeUtil::push("mainId:{$mainId} 初始化产品没有找到main信息", '15280215347');
- continue;
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- PtCpService::initMainCp($main);
- $transaction->commit();
- echo "mainId:{$mainId} 初始化产品 success \n";
- } catch (\Exception $e) {
- $transaction->rollBack();
- $msg = $e->getMessage();
- noticeUtil::push("mainId:{$mainId} 初始化产品报错:{$msg}", '15280215347');
- }
- }
- }
- }
|