| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?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();
- }
- }
- // ./yii product/get-img
- public function actionGetImg()
- {
- $list = ProductClass::getAllByCondition(['shopId' => 10], null, '*', null, true);
- $arr = [];
- if (!empty($list)) {
- foreach ($list as $key => $val) {
- $name = $val->name ?? '';
- $price = $val->price ?? 0;
- $cover = $val->cover ?? '';
- $arr[] = [
- 'name' => $name,
- 'price' => $price,
- 'cover' => $cover,
- ];
- }
- }
- echo json_encode($arr);
- }
- }
|