StatIncomeMonthClass.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace bizHd\stat\classes;
  3. use bizHd\stat\models\StatIncomeMonth;
  4. use Yii;
  5. use bizHd\base\classes\BaseClass;
  6. class StatIncomeMonthClass extends BaseClass
  7. {
  8. public static $baseFile = '\bizHd\stat\models\StatIncomeMonth';
  9. public static function updateOrInsert($main, $shop, $amount)
  10. {
  11. $time = date('Ym');
  12. $mainId = $shop->mainId ?? 0;
  13. $where = ['mainId' => $mainId, 'time' => $time,];
  14. $model = self::getByCondition($where, true);
  15. if (empty($model)) {
  16. $data = ['mainId' => $mainId, 'time' => $time, 'amount' => 0, 'totalAmount' => $main->totalIncome, 'createTime' => date('Y-m-d H:i:s')];
  17. $model = self::add($data, true);
  18. }
  19. $id = $model->id;
  20. //查id行级锁
  21. $stat = StatIncomeMonthClass::getLockById($id);
  22. $stat->amount = bcadd($amount, $stat->amount, 2);
  23. $stat->totalAmount = $main->totalIncome;
  24. $stat->save();
  25. }
  26. //查询当天收入金额
  27. public static function getAmountMonth($shopId)
  28. {
  29. $time = date('Ym');
  30. $res = self::getDetail($shopId, $time);
  31. return $res['amount'] ?? 0;
  32. }
  33. //查询某一个月的信息
  34. public static function getDetail($shopId, $time)
  35. {
  36. $where = [
  37. 'shopId' => $shopId,
  38. 'time' => $time,
  39. ];
  40. $model = self::getByCondition($where);
  41. return $model;
  42. }
  43. }