$sjId, 'time' => $time, 'sourceType' => $sourceType], true); if (empty($income)) { $data['time'] = $time; $data['addTime'] = $addTime; $income = self::add($data, true); } else { $income->amount += $amount; } $income = business::savePayWayAmount($income, $amount, $payWay); $income->save(); /**每个月增加**/ $data['time'] = date("Ym", strtotime($time)); StatIncomeSourceMonthService::replaceData($data); return true; } //取最近的按来源分的收入 ssh 2019.9.21 public static function getLatestSource($start, $end, $sjId) { $list = self::getAllList('sourceType,amount', ['sjId' => $sjId, 'time' => ['between', [$start, $end]]], 'time asc'); $data = []; $sourceType = UserClass::$sourceType; $totalAmount = 0; if (!empty($list)) { foreach ($sourceType as $id => $item) { $data[$id]['name'] = $item; $data[$id]['value'] = 0; } foreach ($list as $key => $val) { $currentSourceType = $val['sourceType']; $amount = $val['amount']; $data[$currentSourceType]['value'] = stringUtil::calcAdd($data[$currentSourceType]['value'], $amount); $totalAmount = stringUtil::calcAdd($totalAmount, $amount); } } return ['data' => array_values($data), 'sourceTypeName' => $sourceType, 'totalAmount' => $totalAmount]; } }