StatStockInClass.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace biz\stat\classes;
  3. use biz\base\classes\BaseClass;
  4. use biz\stat\models\StatStockIn;
  5. class StatStockInClass extends BaseClass
  6. {
  7. public static $baseFile = '\biz\stat\models\StatStockIn';
  8. //获取总和 ssh 20210829
  9. public static function getSum($where)
  10. {
  11. $amount = self::sum($where, 'amount');
  12. return empty($amount) ? 0 : $amount;
  13. }
  14. //入库添加或更新 ssh 20210526
  15. public static function replace($main, $shop, $amount)
  16. {
  17. $sjId = $shop->sjId;
  18. $mainId = $main->id ?? 0;
  19. $time = date('Ymd');
  20. $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'time' => $time], true);
  21. if (empty($stat)) {
  22. $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time], true);
  23. }
  24. $id = $stat->id;
  25. $unique = self::getLockById($id);
  26. if (empty($unique)) {
  27. util::fail('没有记录');
  28. }
  29. $currentAmount = bcadd($unique->amount, $amount, 2);
  30. $unique->amount = $currentAmount;
  31. $unique->totalAmount = $main->totalStockIn;
  32. $unique->save();
  33. //当月
  34. StatStockInMonthClass::replace($main, $shop, $amount);
  35. }
  36. }