ProductController.php 7.7 KB

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