StatStockOutMonthClass.php 1.0 KB

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