ProductController.php 9.9 KB

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