| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- /**
- * This is the model class for table "{{%activity_cut_price_order}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property integer $activity_id
- * @property integer $user_id
- * @property integer $saas_id
- * @property integer $activity_goods_id
- * @property integer $goods_id
- * @property integer $order_mch_list
- * @property integer $total_price
- * @property integer $pay_price
- * @property integer $min_price
- * @property integer $used_order_id
- * @property integer $buy
- * @property integer $end_time
- * @property integer $created_at
- * @property integer $is_delete
- * @property integer $updated_at
- * @property integer $is_platform
- */
- class ActivityCutPriceOrder extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%activity_cut_price_order}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- ]
- ];
- }
- public static function getStatus($order) {
- $status = 0;
- if ($order['end_time'] > time()) {
- $status = 0;//进行中
- }
- if ($order['end_time'] < time()) {
- $status = 1; //已结束
- }
- if ($order['buy'] == 0 && $order['end_time'] < time() && $order['pay_price'] > $order['min_price']) {
- $status = 2;//已失败
- }
- if ($order['used_order_id']) {
- $order = Order::find()->select('is_pay')->where(['id' => $order['used_order_id']])->one();
- if($order['is_pay'] <= 0){
- $status = 10;//待付款
- }else{
- $status = 11;//已付款
- }
- }
- return $status;
- }
- public function beforeSave($insert)
- {
- if (parent::beforeSave($insert)) {
- if ($this->dirtyAttributes && $this->dirtyAttributes['used_order_id'] && $this->dirtyAttributes['used_order_id'] > 0) {
- $activity_goods = ActivityCutPriceGoods::findOne($this->activity_goods_id);
- $activity_goods->sale_num += 1;
- $activity_goods->save();
- }
- }
- return true;
- }
- }
|