ProductController.php 9.8 KB

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