'ID', 'mall_id' => '商城ID', 'total_seed_num' => '累计种子金总数量', 'collect_seed_num' => '已收取种子金总数量', 'refund_seed_num' => '退款种子金总数量', 'bad_seed_num' => '坏账种子金数量', 'total_energy_pool' => '当前能量池总额', 'cumulative_energy_pool' => '累计能量池总额', 'release_energy_pool' => '已释放能量池总额', 'release_num' => '已释放能量池次数', 'last_release_at' => '上次释放时间', 'status' => '状态,-1:失效,1:正常,2:冻结', 'created_at' => '添加时间戳', 'updated_at' => '更新时间戳', ]; } /** * 初始化一条统计数据 * @Author: lun * @DateTime: 2022/7/27 0027 18:06 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $mall_id * @return bool */ public static function create($mall_id) { try { $model = self::findOne(['mall_id' => $mall_id]); if (empty($model)) { $model = new self(); $model->mall_id = $mall_id; $model->loadDefaultValues(); if (!$model->save()) throw new Exception($model->getErrorMessage()); } return true; } catch (\Exception $e) { self::setStaticError($e->getMessage()); return false; } } /** * 数据统计修改 * @Author: lun * @DateTime: 2022/8/1 0001 16:28 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $mall_id * @param $params * @throws Exception */ public static function saveStatistics($mall_id, $params) { $update_data['updated_at'] = time(); foreach ($params as $key => $value) { $symbol = $value >= 0 ? '+' : '-'; $update_data[$key] = new Expression($key.$symbol.abs($value)); } $res = self::updateAll($update_data, ['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED]); if (!$res) throw new Exception('修改统计数据失败'); } /** * 种子金释放失败处理 * @Author: lun * @DateTime: 2022/8/3 0003 14:11 * @Copyright: copyright (c) 2021 广东七件事集团 * @param $params * @param string $reason * @return bool */ public static function handleReleaseFail($params, $reason = '') { $trans = Yii::$app->db->beginTransaction(); try { $pool_log = SeedEnergyPool::findOne(['id' => $params['pool_id']]); // 不等于释放中直接退出,避免重复修改数据 if ($pool_log->release_status != SeedEnum::RELEASEING) { $trans->commit(); return true; } // 释放失败返还种子金奖金池 $model = self::findOne(['mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED]); $model->total_energy_pool += $pool_log->release_energy_pool; $model->release_energy_pool -= $pool_log->release_energy_pool; if (!$model->save()) throw new Exception($model->getErrorMessage()); $pool_log->reason = $reason; $pool_log->release_status = SeedEnum::RELEASE_FAIL; if (!$pool_log->save()) throw new Exception($pool_log->getErrorMessage()); $trans->commit(); return true; } catch (\Exception $e) { $trans->rollBack(); Yii::error('种子金返还失败:' . $e->getMessage()); return false; } } }