83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
<?php
|
||
|
||
namespace app\models\log;
|
||
|
||
use Yii;
|
||
use app\models\Model;
|
||
|
||
/**
|
||
* This is the model class for table "{{%pay_notify_log}}".
|
||
*
|
||
* @property int $id ID
|
||
* @property int|null $cx_mch_id 平台商户ID
|
||
* @property string $order_no 订单号
|
||
* @property string $content 回调数据
|
||
* @property int $created_at 添加时间
|
||
* @property int $is_delete 是否删除:0=否,1=是
|
||
* @property int $deleted_at 删除时间
|
||
*/
|
||
class PayNotifyLog extends \yii\db\ActiveRecord
|
||
{
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public static function tableName()
|
||
{
|
||
return '{{%pay_notify_log}}';
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function rules()
|
||
{
|
||
return [
|
||
[['cx_mch_id', 'created_at', 'is_delete', 'deleted_at'], 'integer'],
|
||
[['order_no', 'content'], 'required'],
|
||
[['content'], 'string'],
|
||
[['order_no'], 'string', 'max' => 64],
|
||
];
|
||
}
|
||
|
||
/**
|
||
* {@inheritdoc}
|
||
*/
|
||
public function attributeLabels()
|
||
{
|
||
return [
|
||
'id' => 'ID',
|
||
'cx_mch_id' => '平台商户ID',
|
||
'order_no' => '订单号',
|
||
'content' => '回调数据',
|
||
'created_at' => '添加时间',
|
||
'is_delete' => '是否删除:0=否,1=是',
|
||
'deleted_at' => '删除时间',
|
||
];
|
||
}
|
||
|
||
public function beforeSave($insert) {
|
||
if(parent::beforeSave($insert)){
|
||
if($this->isNewRecord){
|
||
$this->created_at = time();
|
||
}
|
||
if($this->is_delete == 1)
|
||
$this->deleted_at = time();
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public static function logger($order_no, $content, $cx_mch_id = 0)
|
||
{
|
||
$model = new PayNotifyLog();
|
||
$model->cx_mch_id = $cx_mch_id;
|
||
$model->order_no = $order_no;
|
||
$model->content = is_string($content) ? $content : json_encode($content, JSON_UNESCAPED_UNICODE);
|
||
if(!$model->save()){
|
||
return (new Model())->getModelError($model);
|
||
}
|
||
return Model::asReturnSuccess();
|
||
}
|
||
}
|