128], [['mobile_prefix'], 'string', 'max' => 16], [['tpl_code', 'ipv4'], 'string', 'max' => 64], [['content'], 'string', 'max' => 1024], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'cx_mch_id' => '平台商户ID', 'user_id' => '用户ID', 'mobile_phone' => '手机号', 'mobile_prefix' => '手机号国家代码', 'tpl_code' => '短信模板', 'content' => '短信内容', 'ipv4' => 'IPV4', 'ipv6' => 'IPV6', 'created_at' => '添加时间', ]; } public function beforeSave($insert) { if(parent::beforeSave($insert)){ if($this->isNewRecord){ $this->created_at = time(); } return true; } else { return false; } } /** * 记录 * @param string $mobile 未加密的手机号 */ public static function logger($mobile, $tpl_code, $content, $user_id = 0, $cx_mch_id = 0, $mobile_prefix = '86') { $mobile = EncryptHelper::encryptMobilePhone($mobile); $model = new SmsRecord(); $model->cx_mch_id = $cx_mch_id; $model->user_id = $user_id; $model->mobile_phone = $mobile; $model->mobile_prefix = $mobile_prefix; $model->tpl_code = $tpl_code; $model->content = $content; $model->ipv4 = IPUtils::getIp(); if(!$model->save()){ return SiteHelper::getModelError($model); } return [ 'code' => 0, 'msg' => 'ok' ]; } }