| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- namespace addons\Coupon\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_coupon_good_statistics}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $coupon_id
- * @property int $good_id
- * @property int $booking_number 该商品使用该优惠券下单的总数量
- * @property int $payed_number 使用该优惠券已支付的该商品数量
- * @property int $booking_user_number 该商品使用该优惠券下单的总人数
- * @property int $buyed_user_number 使用该优惠券已购买该商品人数
- * @property int $created_at 创建时间
- * @property int $updated_at
- */
- class AddonsCouponGoodStatistics extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_coupon_good_statistics}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'coupon_id', 'good_id'], 'required'],
- [['mall_id', 'coupon_id', 'good_id', 'booking_number', 'payed_number', 'booking_user_number', 'buyed_user_number', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'coupon_id' => 'Coupon ID',
- 'good_id' => 'Good ID',
- 'booking_number' => 'Booking Number',
- 'payed_number' => 'Payed Number',
- 'booking_user_number' => 'Booking User Number',
- 'buyed_user_number' => 'Buyed User Number',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- public static function setData($params)
- {
- try {
- if (empty($params['mall_id'])) return false;
- $model = self::findOne(['mall_id' => $params['mall_id'],'coupon_id' => $params['coupon_id'],'good_id' => $params['good_id']]);
- if (empty($model)) {
- $model = new self();
- $model->mall_id = $params['mall_id'];
- $model->coupon_id = $params['coupon_id'];
- $model->good_id = $params['good_id'];
- $model->loadDefaultValues();
- }
- if (!empty($params['payed_number'])){
- $model->payed_number += $params['payed_number'];
- if($model->payed_number<0) $model->payed_number = 0;
- }
- if (!empty($params['buyed_user_number'])){
- $model->buyed_user_number += $params['buyed_user_number'];
- if($model->buyed_user_number<0) $model->buyed_user_number = 0;
- }
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|