增加自媒体渠道

This commit is contained in:
2026-04-23 15:43:22 +08:00
parent 366b005d78
commit 54431cbeb1
19 changed files with 737 additions and 47 deletions
@@ -6,6 +6,7 @@ namespace app\adminapi\logic\finance;
use app\common\logic\BaseLogic;
use app\common\model\finance\AccountCost;
use app\common\service\qywx\MediaChannelService;
class AccountCostLogic extends BaseLogic
{
@@ -13,14 +14,19 @@ class AccountCostLogic extends BaseLogic
{
try {
$costDate = (string) $params['cost_date'];
if (AccountCost::where('cost_date', $costDate)->count() > 0) {
self::setError('该日期的账户消耗已存在,请直接编辑');
$mediaChannelCode = trim((string) ($params['media_channel_code'] ?? ''));
$mediaChannelName = MediaChannelService::getNameByCode($mediaChannelCode);
if (AccountCost::where('cost_date', $costDate)->where('media_channel_code', $mediaChannelCode)->count() > 0) {
self::setError('该日期下所选渠道的账户消耗已存在,请直接编辑');
return false;
}
AccountCost::create([
'cost_date' => $costDate,
'media_channel_code' => $mediaChannelCode,
'media_channel_name' => $mediaChannelName,
'amount' => round((float) $params['amount'], 2),
'remark' => (string) ($params['remark'] ?? ''),
'creator_id' => $adminId,
@@ -65,4 +71,24 @@ class AccountCostLogic extends BaseLogic
{
return AccountCost::findOrEmpty($id)->toArray();
}
public static function delete(int $id): bool
{
try {
$model = AccountCost::find($id);
if (!$model) {
self::setError('记录不存在');
return false;
}
$model->delete();
return true;
} catch (\Throwable $e) {
self::setError($e->getMessage());
return false;
}
}
}