| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace console\controllers;
- use bizHd\goods\classes\GoodsCategoryClass;
- use bizHd\goods\classes\GoodsClass;
- use bizHd\goods\classes\KindClass;
- use bizHd\order\classes\OrderGoodsClass;
- use bizHd\shop\classes\ShopClass;
- use bizHd\work\classes\WorkClass;
- use yii\console\Controller;
- use Yii;
- class KindController extends Controller
- {
- //品类更新 ssh 20230320
- public function actionUpdate()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $shopList = ShopClass::getAllByCondition(['ptStyle' => 1], null, '*', null, true);
- if (!empty($shopList)) {
- foreach ($shopList as $shop) {
- $mainId = $shop->mainId ?? 0;
- $kindList = KindClass::getAllByCondition(['mainId' => $mainId], null, '*');
- $lzKindId = 0;
- $lzName = '';
- $hsKindId = 0;
- $hsName = '';
- if (!empty($kindList)) {
- foreach ($kindList as $kindInfo) {
- $name = $kindInfo['name'] ?? '';
- $kId = $kindInfo['id'] ?? 0;
- if ($name == '绿植') {
- $lzKindId = $kId;
- $lzName = $name;
- }
- if ($name == '花束') {
- $hsKindId = $kId;
- $hsName = $name;
- }
- }
- }
- if (empty($lzKindId) || empty($hsKindId)) {
- echo '有品类id没有 ' . $shop->merchantName . ' ' . $shop->shopName;
- Yii::$app->end();
- }
- GoodsClass::updateByCondition(['mainId' => $mainId, 'flower' => 1], ['kindId' => $hsKindId, 'kindName' => $hsName]);
- GoodsCategoryClass::updateByCondition(['mainId' => $mainId, 'flower' => 1], ['kindId' => $hsKindId, 'kindName' => $hsName]);
- GoodsClass::updateByCondition(['mainId' => $mainId, 'flower' => 0], ['kindId' => $lzKindId, 'kindName' => $lzName]);
- GoodsCategoryClass::updateByCondition(['mainId' => $mainId, 'flower' => 0], ['kindId' => $lzKindId, 'kindName' => $lzName]);
- $workList = WorkClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
- if (!empty($workList)) {
- foreach ($workList as $work) {
- $goodsId = $work->goodsId ?? 0;
- $goodsInfo = GoodsClass::getById($goodsId, true);
- if (!empty($goodsInfo)) {
- $thisKindId = $goodsInfo->kindId ?? 0;
- $thisKindName = $goodsInfo->kindName ?? '';
- $work->kindId = $thisKindId;
- $work->kindName = $thisKindName;
- $work->save();
- }
- }
- }
- $arr = OrderGoodsClass::getAllByCondition(['id>' => 0], null, '*', null, true);
- if (!empty($arr)) {
- foreach ($arr as $in) {
- $goodsId = $in->goodsId ?? 0;
- $goodsInfo = GoodsClass::getById($goodsId, true);
- if (!empty($goodsInfo)) {
- $thisKindId = $goodsInfo->kindId ?? 0;
- $thisKindName = $goodsInfo->kindName ?? '';
- $in->kindId = $thisKindId;
- $in->kindName = $thisKindName;
- $in->save();
- }
- }
- }
- }
- }
- }
- //种类初始化 ssh 20230301
- public function actionInit()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $shopList = ShopClass::getAllByCondition(['ptStyle' => 1], null, '*', null, true);
- if (!empty($shopList)) {
- foreach ($shopList as $shop) {
- $mainId = $shop->mainId ?? 0;
- $sjId = $shop->sjId ?? 0;
- $has = KindClass::getByCondition(['mainId' => $mainId], true);
- if (!empty($has)) {
- continue;
- }
- $data = [
- 'mainId' => $mainId,
- 'sjId' => $sjId,
- ];
- KindClass::initKind($data);
- }
- }
- }
- }
|