'ID', 'mall_id' => 'Mall ID', 'video_id' => 'Video ID', 'order_id' => 'Order ID', 'user_id' => 'User ID', 'goods_id' => 'Goods ID', 'goods_price' => '商品售价', 'money' => 'Money', 'award_type' => 'Award Type', 'award_percentage' => 'Award Percentage', 'award_money' => 'Award Money', 'is_settlement' => 'Is Settlement', 'settlement_time' => 'Settlement Time', 'status' => 'Status', 'goods_num' => 'Goods Num', 'is_award' => 'Is Award', 'created_at' => 'Created At', 'updated_at' => 'Updated At', ]; } public static function getStatData(int $mall_id, string $type, array $params = []) { $query = self::find()->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED]); if (!empty($params)) { foreach ($params as $where) { $query->andWhere($where); } } $order_awards = $query->asArray()->all(); $order_ids = array_column($order_awards, 'order_id'); // dd($order_ids); $query_o = Order::find()->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $order_ids]); if ('order_sum_money' == $type || 'order_money' == $type) { $stat_data = $query_o->sum('pay_money') ?? 0; } elseif ('order_num' == $type) { $stat_data = $query_o->count() ?? 0; } elseif ('order_people' == $type) { $stat_data = $query_o->select('user_id')->groupBy('user_id')->asArray()->count(); }elseif ('pay_money' == $type) { $query_o->andWhere(['pay_status' => OrderStatusEnum::PAY]); $stat_data = $query_o->sum('pay_money') ?? 0; } elseif ('pay_people' == $type) { $query_o->andWhere(['pay_status' => OrderStatusEnum::PAY]); $stat_data = $query_o->select('user_id')->groupBy('user_id')->asArray()->count(); } else { $stat_data = $query_o->all(); } return $stat_data; } public static function setData(int $mall_id, array $data) { if (!empty($data['id'])) { $model = self::findOne(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED, 'id' => $data['id']]); if (empty($model)) { self::$static_error = '带货订单记录不存在'; return false; } } else { $model = new self(); $model->loadDefaultValues(); $model->mall_id = $mall_id; } foreach ($data as $key => $val) { $model->$key = $val; } if (!$model->save()) { self::$static_error = '保存数据失败:' . $model->getErrorMessage(); return false; } return $model; } }