| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace addons\DoubleCopy\common\models;
- use common\enums\StatusEnum;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_double_copy_change_pos}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property string|null $content 交换内容
- * @property int|null $change_status 交换状态[-1=交换失败,0=交换中,1=交换成功]
- * @property string|null $reason 失败原因
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int|null $created_at 创建时间
- * @property int|null $updated_at 更新时间
- */
- class DoubleCopyChangePos extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_double_copy_change_pos}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'change_status', 'status', 'created_at', 'updated_at'], 'integer'],
- [['content','reason'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'content' => '交换内容',
- 'change_status' => '交换状态[-1=交换失败,0=交换中,1=交换成功]',
- 'reason' => '失败原因',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- /**
- * 检测是否还有为完成的提交
- * @Author: lun
- * @DateTime: 2023/6/3 0003 11:47
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @return bool
- */
- public static function check($mall_id)
- {
- $data = self::find()->where(['mall_id' => $mall_id, 'change_status' => StatusEnum::DISABLED, 'status' => StatusEnum::ENABLED])->asArray()->one();
- if ($data) return false;
- return true;
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2023/6/3 0003 11:45
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @param $params
- * @return bool|int
- */
- public static function setData($mall_id, $params)
- {
- try {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $mall_id;
- $model->content = json_encode($params);
- if (!$model->save()) throw new Exception($model->getErrorMessage());
- return $model->id;
- } catch (\Exception $e) {
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
|