ProductController.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace console\controllers;
  3. use biz\item\classes\PtItemClass;
  4. use biz\product\classes\ProductClass;
  5. use biz\product\models\Product;
  6. use yii\console\Controller;
  7. use Yii;
  8. class ProductController extends Controller
  9. {
  10. // ./yii product/reset-cover
  11. public function actionResetCover()
  12. {
  13. $sql = "SELECT * FROM `" . Product::tableName() . "` WHERE cover not like '%.%'";
  14. $command = Yii::$app->db->createCommand($sql);
  15. $data = $command->queryAll();
  16. if (empty($data)) {
  17. return false;
  18. }
  19. foreach ($data as $item) {
  20. $id = $item['id'] ?? 0;
  21. $ptItemId = $item['itemId'] ?? 0;
  22. $preCover = $item['cover'] ?? '';
  23. $ptItem = PtItemClass::getById($ptItemId, true);
  24. $cover = $ptItem->cover ?? '';
  25. if (!empty($cover)) {
  26. ProductClass::updateById($id, ['cover' => $cover]);
  27. echo "productId:" . $id . "原图:{$preCover}, 恢复图片:" . $cover . "\n";
  28. } else {
  29. echo "productId:" . $id . " 恢复图片没有成功-----------------\n";
  30. }
  31. }
  32. }
  33. // ./yii product/sk-price
  34. public function actionSkPrice()
  35. {
  36. ini_set('memory_limit', '2045M');
  37. set_time_limit(0);
  38. $list = ProductClass::getAllByCondition([], null, '*', null, true);
  39. if (empty($list)) {
  40. return false;
  41. }
  42. foreach ($list as $key => $item) {
  43. $price = $item->price ?? 0;
  44. $skAddPrice = $item->skAddPrice ?? 0;
  45. $addPrice = $item->addPrice ?? 0;
  46. $diff = bcsub($skAddPrice, $addPrice, 2);
  47. $currentPrice = $price;
  48. if ($diff > 0) {
  49. $currentPrice = bcadd($price, $diff, 2);
  50. }
  51. $item->skPrice = $currentPrice;
  52. $item->save();
  53. }
  54. }
  55. // ./yii product/get-img
  56. public function actionGetImg()
  57. {
  58. $list = ProductClass::getAllByCondition(['shopId' => 10], null, '*', null, true);
  59. $arr = [];
  60. if (!empty($list)) {
  61. foreach ($list as $key => $val) {
  62. $name = $val->name ?? '';
  63. $price = $val->price ?? 0;
  64. $cover = $val->cover ?? '';
  65. $arr[] = [
  66. 'name' => $name,
  67. 'price' => $price,
  68. 'cover' => $cover,
  69. ];
  70. }
  71. }
  72. echo json_encode($arr);
  73. }
  74. }