ProductController.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 biz\shop\classes\ShopClass;
  7. use bizGhs\item\classes\ItemClass;
  8. use bizGhs\item\models\Item;
  9. use yii\console\Controller;
  10. use Yii;
  11. class ProductController extends Controller
  12. {
  13. public function actionChangeSk()
  14. {
  15. ini_set('memory_limit', '2045M');
  16. set_time_limit(0);
  17. //$id = 36523;
  18. $id = 520;
  19. $shop = ShopClass::getById($id, true);
  20. $mainId = $shop->mainId ?? 0;
  21. $sjId = $shop->sjId ?? 0;
  22. $chainShopList = ShopClass::getAllByCondition(['sjId' => $sjId, 'join' => 0], null, '*', null, true);
  23. $default = $shop->default ?? 0;
  24. $productList = ProductClass::getAllByCondition(['mainId' => $mainId], null, '*', 'id', true);
  25. if (!empty($productList)) {
  26. foreach ($productList as $product) {
  27. $price = $product->price ?? 0;
  28. $skPrice = bcadd(floatval($price), 3, 0);
  29. $product->skPrice = $skPrice;
  30. $product->save();
  31. $ptItemId = $product->itemId ?? 0;
  32. if ($default == 1) {
  33. foreach ($chainShopList as $chain) {
  34. if ($chain->id == $shop->id) {
  35. continue;
  36. }
  37. $chainMainId = $chain->mainId ?? 0;
  38. $chainProduct = ProductClass::getByCondition(['mainId' => $chainMainId, 'itemId' => $ptItemId], true);
  39. if (!empty($chainProduct)) {
  40. $chainProduct->skPrice = $skPrice;
  41. $chainProduct->save();
  42. }
  43. }
  44. }
  45. }
  46. }
  47. }
  48. //修改散客比批发价格贵 ssh 20220609
  49. public function actionSkMore()
  50. {
  51. $query = new \yii\db\Query();
  52. $query->from(Item::tableName());
  53. $query->where(['>', 'id', 0]);
  54. foreach ($query->batch() as $batchItem) {
  55. foreach ($batchItem as $item) {
  56. $addPrice = $item['addPrice'] ?? 0;
  57. $id = $item['id'] ?? 0;
  58. $skAddPrice = $item['skAddPrice'] ?? 0;
  59. if ($skAddPrice > $addPrice) {
  60. $add = bcsub($skAddPrice, $addPrice, 2);
  61. ItemClass::updateById($id, ['skMore' => $add]);
  62. } else {
  63. echo "零售加价小于批发加价 {$id}\n";
  64. }
  65. }
  66. }
  67. }
  68. //更新纯彩花艺的价格 ./yii product/update-price ssh 20211020
  69. public function actionUpdatePrice()
  70. {
  71. $list = ProductClass::getAllByCondition(['shopId' => 10], null, '*', null, true);
  72. if (!empty($list)) {
  73. foreach ($list as $key => $item) {
  74. $price = $item->price ?? 0;
  75. $addPrice = $item->addPrice ?? 0;
  76. $skAddPrice = $item->skAddPrice ?? 0;
  77. $hjAddPrice = $item->hjAddPrice ?? 0;
  78. $zsAddPrice = $item->zsAddPrice ?? 0;
  79. $skDiff = bcsub($addPrice, $skAddPrice, 2);
  80. $skPrice = bcsub($price, $skDiff, 2);
  81. $hjDiff = bcsub($addPrice, $hjAddPrice, 2);
  82. $hkPrice = bcsub($price, $hjDiff, 2);
  83. $zsDiff = bcsub($addPrice, $zsAddPrice, 2);
  84. $zsPrice = bcsub($price, $zsDiff, 2);
  85. $item->skPrice = $skPrice;
  86. $item->hjPrice = $hkPrice;
  87. $item->zsPrice = $zsPrice;
  88. $item->save();
  89. }
  90. }
  91. }
  92. // ./yii product/reset-cover
  93. public function actionResetCover()
  94. {
  95. $sql = "SELECT * FROM `" . Product::tableName() . "` WHERE cover not like '%.%'";
  96. $command = Yii::$app->db->createCommand($sql);
  97. $data = $command->queryAll();
  98. if (empty($data)) {
  99. return false;
  100. }
  101. foreach ($data as $item) {
  102. $id = $item['id'] ?? 0;
  103. $ptItemId = $item['itemId'] ?? 0;
  104. $preCover = $item['cover'] ?? '';
  105. $ptItem = PtItemClass::getById($ptItemId, true);
  106. $cover = $ptItem->cover ?? '';
  107. if (!empty($cover)) {
  108. ProductClass::updateById($id, ['cover' => $cover]);
  109. echo "productId:" . $id . "原图:{$preCover}, 恢复图片:" . $cover . "\n";
  110. } else {
  111. echo "productId:" . $id . " 恢复图片没有成功-----------------\n";
  112. }
  113. }
  114. }
  115. // ./yii product/sk-price
  116. public function actionSkPrice()
  117. {
  118. ini_set('memory_limit', '2045M');
  119. set_time_limit(0);
  120. $list = ProductClass::getAllByCondition([], null, '*', null, true);
  121. if (empty($list)) {
  122. return false;
  123. }
  124. foreach ($list as $key => $item) {
  125. $price = $item->price ?? 0;
  126. $skAddPrice = $item->skAddPrice ?? 0;
  127. $addPrice = $item->addPrice ?? 0;
  128. $diff = bcsub($skAddPrice, $addPrice, 2);
  129. $currentPrice = $price;
  130. if ($diff > 0) {
  131. $currentPrice = bcadd($price, $diff, 2);
  132. }
  133. $item->skPrice = $currentPrice;
  134. $item->save();
  135. }
  136. }
  137. //二个空间问题
  138. public function actionSame()
  139. {
  140. ini_set('memory_limit', '5045M');
  141. set_time_limit(0);
  142. if (getenv('YII_ENV') == 'production') {
  143. $mainId = 8164;
  144. } else {
  145. $mainId = 644;
  146. }
  147. $list = ProductClass::getAllByCondition(['mainId' => $mainId], null, '*', null);
  148. if (!empty($list)) {
  149. $ids = array_column($list, 'itemId');
  150. $ptInfo = PtItemClass::getByIds($ids, null, 'id');
  151. foreach ($list as $item) {
  152. $id = $item['id'] ?? 0;
  153. $name = $item['name'] ?? '';
  154. $ptItemId = $item['itemId'] ?? 0;
  155. $pt = $ptInfo[$ptItemId];
  156. $ptName = $pt['name'] ?? '';
  157. if ($name != $ptName) {
  158. echo $id . ' ' . $name . ' ' . $ptName . "\n";
  159. }
  160. }
  161. }
  162. }
  163. }