WorkController.php 973 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace console\controllers;
  3. use biz\goods\classes\GoodsClass;
  4. use bizHd\work\classes\WorkClass;
  5. use yii\console\Controller;
  6. use Yii;
  7. class WorkController extends Controller
  8. {
  9. public function actionInit()
  10. {
  11. ini_set('memory_limit', '2045M');
  12. set_time_limit(0);
  13. $goodsList = GoodsClass::getAllByCondition(['id>' => 0], null, '*', null, true);
  14. if (!empty($goodsList)) {
  15. foreach ($goodsList as $goods) {
  16. $goods->stock = 0;
  17. $goods->save();
  18. }
  19. }
  20. $workList = WorkClass::getAllByCondition(['status' => 0], null, '*', null, true);
  21. if (!empty($workList)) {
  22. foreach ($workList as $work) {
  23. $num = $work->num ?? 0;
  24. $goodsId = $work->goodsId ?? 0;
  25. if (!empty($goodsId)) {
  26. GoodsClass::updateById($goodsId, ['stock' => -$num]);
  27. }
  28. }
  29. }
  30. }
  31. }