OrderItemController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace console\controllers;
  3. use bizGhs\order\classes\OrderItemClass;
  4. use yii\console\Controller;
  5. /**
  6. * 订单相关
  7. */
  8. class OrderItemController extends Controller
  9. {
  10. public function actionCost()
  11. {
  12. ini_set('memory_limit', '2045M');
  13. set_time_limit(0);
  14. $list = OrderItemClass::getAllByCondition(['id<' => 333152, 'xhUnitType' => 1], 'id DESC', '*', null, true);
  15. if (!empty($list)) {
  16. foreach ($list as $key => $item) {
  17. $cost = $item->cost ?? 0;
  18. $xhPrice = $item->xhPrice ?? 0;
  19. $ratio = $item->ratio ?? 21;
  20. $productId = $item->productId ?? 0;
  21. $name = $item->name ?? '';
  22. $smallCost = bcdiv($cost, $ratio, 2);
  23. if ($ratio > 1) {
  24. if ($cost > 10 && $cost > $xhPrice) {
  25. // echo $productId . ' ' . $name . ' 成本:' . $cost . ' 价格:' . $xhPrice . ' 比例:' . $ratio . ' 小单位成本:' . $smallCost . "\n";
  26. // $item->cost = $smallCost;
  27. // $item->save();
  28. }
  29. if ($cost < 10 && $cost > $xhPrice) {
  30. echo $productId . ' ' . $name . ' 成本:' . $cost . ' 价格:' . $xhPrice . ' 比例:' . $ratio . "\n";
  31. $item->cost = $xhPrice;
  32. $item->save();
  33. }
  34. }
  35. }
  36. }
  37. }
  38. }