CpController.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace console\controllers;
  3. use biz\cp\services\PtCpService;
  4. use biz\main\classes\MainClass;
  5. use biz\shop\classes\ShopClass;
  6. use bizGhs\cp\classes\CpClass;
  7. use bizGhs\cp\classes\CpClassClass;
  8. use common\components\noticeUtil;
  9. use common\components\util;
  10. use yii\console\Controller;
  11. use Yii;
  12. class CpController extends Controller
  13. {
  14. //创建分店时,复制产品,重要脚本,不能删除
  15. public function actionCopyCp()
  16. {
  17. $copyKey = 'copy_old_cp_to_new_cp';
  18. $copyList = [];
  19. while ($count = Yii::$app->redis->executeCommand('LLEN', [$copyKey])) {
  20. $current = Yii::$app->redis->executeCommand('RPOP', [$copyKey]);
  21. $copyList[] = $current;
  22. }
  23. if (empty($copyList)) {
  24. return false;
  25. }
  26. foreach ($copyList as $copy) {
  27. $arr = json_decode($copy, true);
  28. $oldMainId = $arr['oldMainId'] ?? 0;
  29. $newMainId = $arr['newMainId'] ?? 0;
  30. $main = MainClass::getById($newMainId, true);
  31. if (empty($main)) {
  32. continue;
  33. }
  34. $has = CpClassClass::getByCondition(['mainId' => $newMainId], true);
  35. if (!empty($has)) {
  36. continue;
  37. }
  38. $connection = Yii::$app->db;
  39. $transaction = $connection->beginTransaction();
  40. try {
  41. CpClass::copyCp($oldMainId, $newMainId);
  42. $transaction->commit();
  43. noticeUtil::push("success 旧mainId:{$oldMainId}复制产品到新mainId:{$newMainId} 成功", '15280215347');
  44. } catch (\Exception $e) {
  45. $transaction->rollBack();
  46. $msg = $e->getMessage();
  47. noticeUtil::push("error 旧mainId:{$oldMainId}复制产品到新mainId:{$newMainId} 报错:{$msg}", '15280215347');
  48. }
  49. }
  50. }
  51. //商家的产品初始化 ssh 20240215
  52. public function actionInitMainCp()
  53. {
  54. ini_set('memory_limit', '2045M');
  55. set_time_limit(0);
  56. $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
  57. //$shopList = ShopClass::getAllByCondition(['id' => 36523], null, '*', null, true);
  58. if (empty($shopList)) {
  59. util::stop('没有找到门店84');
  60. }
  61. foreach ($shopList as $shop) {
  62. $mainId = $shop->mainId;
  63. $hasClass = CpClass::getByCondition(['mainId' => $mainId], true);
  64. if (!empty($hasClass)) {
  65. continue;
  66. }
  67. $main = MainClass::getById($mainId, true);
  68. if (empty($main)) {
  69. noticeUtil::push("mainId:{$mainId} 初始化产品没有找到main信息", '15280215347');
  70. continue;
  71. }
  72. $connection = Yii::$app->db;
  73. $transaction = $connection->beginTransaction();
  74. try {
  75. PtCpService::initMainCp($main);
  76. $transaction->commit();
  77. echo "mainId:{$mainId} 初始化产品 success \n";
  78. } catch (\Exception $e) {
  79. $transaction->rollBack();
  80. $msg = $e->getMessage();
  81. noticeUtil::push("mainId:{$mainId} 初始化产品报错:{$msg}", '15280215347');
  82. }
  83. }
  84. }
  85. }