| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace addons\HuifuPay\common\models;
- use common\enums\StatusEnum;
- use RuntimeException;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_huifupay_pay_request_log".
- *
- * @property int $id
- * @property int $mall_id
- * @property string $url Url
- * @property string $path 请求路径
- * @property string $method 请求方式
- * @property string|null $request_data 请求数据
- * @property string|null $response_data 响应数据
- * @property string|null $headers 请求头
- * @property int $http_state_code http状态码
- * @property string $err_msg 错误信息
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class HuifupayPayRequestLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_huifupay_pay_request_log';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'http_state_code', 'status', 'created_at', 'updated_at'], 'integer'],
- [['request_data', 'headers'], 'safe'],
- [['response_data'], 'string'],
- [['path'], 'string', 'max' => 50],
- [['err_msg'], 'string', 'max' => 500],
- [['url'], 'string', 'max' => 2000],
- [['method'], 'string', 'max' => 7],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'url' => 'Url',
- 'path' => 'Path',
- 'method' => 'Method',
- 'request_data' => 'Request Data',
- 'response_data' => 'Response Data',
- 'headers' => 'Headers',
- 'http_state_code' => 'Http State Code',
- 'err_msg' => 'Err Msg',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData(int $mall_id, array $data)
- {
- if (empty($data['id'])) {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- } else {
- $model = self::findOne(['mall_id' => $mall_id, 'id' => $data['id'], 'status' => StatusEnum::ENABLED]);
- if (!$model) throw new RuntimeException('数据记录异常');
- }
- foreach ($data as $key => $val) {
- if ($key === 'response_data' && is_array($val)) {
- $val = json_encode($val, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
- }
- $model->$key = $val;
- }
- if (!$model->save()) {
- self::$static_error = '保存数据失败:' . $model->getErrorMessage();
- return false;
- }
- return $model;
- }
- }
|