| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace addons\ShortVideo\common\models;
- use common\enums\OrderStatusEnum;
- use common\enums\StatusEnum;
- use common\models\order\Order;
- use Yii;
- /**
- * This is the model class for table "{{%addons_short_video_order_award}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $video_id 视频id
- * @property int $order_id 子订单id
- * @property int $user_id 用户id
- * @property int $goods_id 商品id
- * @property int $goods_price 商品售价
- * @property float $money 奖励金额
- * @property int $award_type 奖励类型 0:金额 1:百分比
- * @property float $award_percentage 奖励百分比
- * @property float $award_money 奖励金额
- * @property int $is_settlement 是否结算 0:否 1:是
- * @property int|null $settlement_time 结算时间
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $goods_num 商品数量
- * @property int|null $is_award 是否带货奖励商品 0:否 1:是
- * @property int $created_at
- * @property int $updated_at
- */
- class ShortVideoOrderAward extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_short_video_order_award}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'video_id', 'order_id', 'user_id', 'goods_id'], 'required'],
- [['mall_id', 'video_id', 'order_id', 'user_id', 'goods_id', 'award_type', 'is_settlement', 'settlement_time', 'status', 'goods_num', 'is_award', 'created_at', 'updated_at'], 'integer'],
- [['money', 'award_percentage', 'award_money', 'goods_price'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '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;
- }
- }
|