StatStockInMonthClass.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace biz\stat\classes;
  3. use biz\base\classes\BaseClass;
  4. use common\components\util;
  5. class StatStockInMonthClass extends BaseClass
  6. {
  7. public static $baseFile = '\biz\stat\models\StatStockInMonth';
  8. //入库添加或更新 ssh 20210526
  9. public static function replace($main, $shop, $amount)
  10. {
  11. $time = date('Ym');
  12. $year = date('Y');
  13. $month = date('m');
  14. $sjId = $shop->sjId;
  15. $mainId = $main->id ?? 0;
  16. $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'time' => $time], true);
  17. if (empty($stat)) {
  18. $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time, 'year' => $year, 'month' => $month], true);
  19. }
  20. $id = $stat->id;
  21. $unique = self::getLockById($id);
  22. if (empty($unique)) {
  23. util::fail('没有记录');
  24. }
  25. $currentAmount = bcadd($unique->amount, $amount, 2);
  26. $unique->amount = $currentAmount;
  27. $unique->totalAmount = $main->totalStockIn;
  28. $unique->save();
  29. }
  30. }