CpController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 common\components\noticeUtil;
  8. use common\components\util;
  9. use yii\console\Controller;
  10. use Yii;
  11. class CpController extends Controller
  12. {
  13. //商家的产品初始化 ssh 20240215
  14. public function actionInitMainCp()
  15. {
  16. ini_set('memory_limit', '2045M');
  17. set_time_limit(0);
  18. $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true);
  19. //$shopList = ShopClass::getAllByCondition(['id' => 36523], null, '*', null, true);
  20. if (empty($shopList)) {
  21. util::stop('没有找到门店');
  22. }
  23. foreach ($shopList as $shop) {
  24. $mainId = $shop->mainId;
  25. $hasClass = CpClass::getByCondition(['mainId' => $mainId], true);
  26. if (!empty($hasClass)) {
  27. continue;
  28. }
  29. $main = MainClass::getById($mainId, true);
  30. if (empty($main)) {
  31. noticeUtil::push("mainId:{$mainId} 初始化产品没有找到main信息", '15280215347');
  32. continue;
  33. }
  34. $connection = Yii::$app->db;
  35. $transaction = $connection->beginTransaction();
  36. try {
  37. PtCpService::initMainCp($main);
  38. $transaction->commit();
  39. echo "mainId:{$mainId} 初始化产品 success \n";
  40. } catch (\Exception $e) {
  41. $transaction->rollBack();
  42. $msg = $e->getMessage();
  43. noticeUtil::push("mainId:{$mainId} 初始化产品报错:{$msg}", '15280215347');
  44. }
  45. }
  46. }
  47. }