| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace common\models;
- use common\helpers\Date;
- use Exception;
- /**
- * This is the model class for table "{{%USER_PERFORMANCE_LOGS}}".
- *
- * @property string ID
- * @property string USER_PERFORMANCE_ID
- * @property string ORDER_ID
- * @property double AMOUNTS
- * @property integer PERIOD_NUM
- * @property integer CREATED_AT
- * @property string REMARK
- */
- class UserPerformanceLogs extends \common\components\ActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%USER_PERFORMANCE_LOGS}}';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['USER_PERFORMANCE_ID'], 'required'],
- [['AMOUNTS'], 'number'],
- [['UPDATED_AT', 'PERIOD_NUM'], 'integer'],
- [['ID','USER_ID'], 'string', 'max' => 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;
- }
- }
|