| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace addons\HuijuBill\common\models;
- use addons\HuijuBill\common\enums\StatusEnum;
- use common\models\common\PaymentTrade;
- use Yii;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%addons_huiju_bill_order}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property string $merchant_no 分账方账号
- * @property int $trade_id 支付流水ID
- * @property string $trade_type 分账支付类型
- * @property string $sys_order_no 系统支付订单号
- * @property string $trx_no 汇聚分账支付订单号
- * @property float $fee 手续费
- * @property int $status 100:成功,101:失败,102:已创建
- * @property int|null $updated_at
- * @property int|null $created_at
- */
- class OrderModel extends ActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_huiju_bill_order}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'merchant_no', 'trade_id', 'trade_type', 'sys_order_no', 'trx_no', 'status'], 'required'],
- [['mall_id', 'trade_id', 'status', 'updated_at', 'created_at'], 'integer'],
- [['fee'], 'number'],
- [['merchant_no', 'trade_type', 'sys_order_no', 'trx_no'], 'string', 'max' => 32],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'merchant_no' => 'Merchant No',
- 'trade_id' => 'Trade ID',
- 'trade_type' => 'Trade Type',
- 'sys_order_no' => 'Sys Order No',
- 'trx_no' => 'Trx No',
- 'fee' => 'Fee',
- 'status' => 'Status',
- 'updated_at' => 'Updated At',
- 'created_at' => 'Created At',
- ];
- }
- /**
- * 支付流水记录表
- *
- * @return ActiveQuery
- */
- public function getTrade()
- {
- return $this->hasOne(PaymentTrade::class, ['id' => 'trade_id']);
- }
- /**
- * 添加分账支付记录
- *
- * @param array $data
- * [
- * 'mall_id' => 'Mall ID',
- * 'merchant_no' => 'Merchant No',
- * 'trade_id' => 'Trade ID',
- * 'trade_type' => 'Trade Type',
- * 'sys_order_no' => 'Sys Order No',
- * 'trx_no' => 'Trx No'
- * 'fee' => 'Fee'
- * 'status' => 'Status'
- * ]
- * @return OrderModel
- */
- public static function addLog($data = [])
- {
- if (
- isset($data['trade_id']) &&
- self::find()->where(['trade_id' => $data['trade_id']])->select('id')->one()
- ) {
- return true;
- }
- $data['created_at'] = $data['updated_at'] = time();
- $model = new self();
- $model->load($data, '');
- return $model->save();
- }
- /**
- * 支付成功
- *
- * @return void
- */
- public function success()
- {
- $this->status = StatusEnum::STATUS_100;
- $this->updated_at = time();
- return $this->save();
- }
- }
|