32], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'ID' => 'ID', 'USER_ID' => '用户id', 'AMOUNTS' => '消耗金额', 'CREATED_AT' => '修改时间', ]; } /** * @throws Exception */ public static function changeAmountLogs($prpId, $amount, $periodNum, $orderId = '') { $id = Date::today('Ymd') . self::_random(10, 1); $model = new self(); $model->ID = $id; $model->USER_PERFORMANCE_ID = $prpId; $model->ORDER_ID = $orderId; $model->AMOUNTS = $amount; $model->PERIOD_NUM = $periodNum; $model->CREATED_AT = time(); if(!$model->save()){ throw new Exception($model->getErrors()); } } private static function _random($length, $numeric = 0) { $seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35); $seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed)); $hash = ''; $max = strlen($seed) - 1; for ($i = 0; $i < $length; $i++) { $hash .= $seed[mt_rand(0, $max)]; } return $hash; } }