| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace console\controllers;
- use biz\item\classes\PtItemClass;
- use biz\product\classes\ProductClass;
- use biz\product\models\Product;
- use yii\console\Controller;
- use Yii;
- class ProductController extends Controller
- {
- // ./yii product/reset-cover
- public function actionResetCover()
- {
- $sql = "SELECT * FROM `" . Product::tableName() . "` WHERE cover not like '%.%'";
- $command = Yii::$app->db->createCommand($sql);
- $data = $command->queryAll();
- if (empty($data)) {
- return false;
- }
- foreach ($data as $item) {
- $id = $item['id'] ?? 0;
- $ptItemId = $item['itemId'] ?? 0;
- $preCover = $item['cover'] ?? '';
- $ptItem = PtItemClass::getById($ptItemId, true);
- $cover = $ptItem->cover ?? '';
- if (!empty($cover)) {
- ProductClass::updateById($id, ['cover' => $cover]);
- echo "productId:" . $id . "原图:{$preCover}, 恢复图片:" . $cover . "\n";
- } else {
- echo "productId:" . $id . " 恢复图片没有成功-----------------\n";
- }
- }
- }
- // ./yii product/sk-price
- public function actionSkPrice()
- {
- ini_set('memory_limit', '2045M');
- set_time_limit(0);
- $list = ProductClass::getAllByCondition([], null, '*', null, true);
- if (empty($list)) {
- return false;
- }
- foreach ($list as $key => $item) {
- $price = $item->price ?? 0;
- $skAddPrice = $item->skAddPrice ?? 0;
- $addPrice = $item->addPrice ?? 0;
- $diff = bcsub($skAddPrice, $addPrice, 2);
- $currentPrice = $price;
- if ($diff > 0) {
- $currentPrice = bcadd($price, $diff, 2);
- }
- $item->skPrice = $currentPrice;
- $item->save();
- }
- }
- }
|