100], [['remark'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'store_id' => 'Store ID', 'user_id' => 'User ID', 'video_id' => 'Video ID', 'order_no' => 'Order No', 'pay_status' => 'Pay Status', 'pay_time' => 'Pay Time', 'pay_money' => 'Pay Money', 'payment_type' => 'Payment Type', 'remark' => 'Remark', 'status' => 'Status', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public static function setData($params) { try{ $model = new self(); $model->loadDefaultValues(); if (!$model->load($params, '') || !$model->save()) throw new \PHPUnit\Util\Exception($model->getErrorMessage()); return $model; }catch(\Exception $e){ self::$static_error = $e->getMessage(); return false; } } public static function pay($params, $peyment_type) { try { $trans = Yii::$app->db->beginTransaction(); $model = self::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED]]); if (empty($model)) throw new Exception('订单不存在或已删除'); if ($model->pay_status == StatusEnum::ENABLED) throw new Exception('订单已支付,请不要重复支付'); $model->payment_type = $peyment_type; $model->pay_status = StatusEnum::ENABLED; $model->pay_time = time(); $res = $model->save(); if ($res === false) throw new Exception('修改订单失败:' . $model->getErrorMessage()); $trans->commit(); // 触发订单支付事件,事务提交完成后触发 $event = new VideoOrderPaidEvent($model['mall_id']); $order['id'] = $model['id']; $order['operator_id'] = $params['operator_id'] ?? 0; $order['operator_name'] = $params['operator_name'] ?? ''; Yii::$app->services->events->dispatch($event, $order, $event->listeners); return $model; } catch (Exception $e) { if (isset($trans)) $trans->rollback(); self::$static_error = $e->getMessage(); return false; } } }