| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace addons\WriteOff\common\models;
- use Yii;
- use common\enums\StatusEnum;
- /**
- * This is the model class for table "{{%addons_write_off_member_code}}".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property int $code 核销码
- * @property int $is_used 是否已核销[0否; 1是]
- * @property int $status 状态[-1删除; 0禁用; 1正常]
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class WriteOffMemberCode extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_write_off_member_code}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'code', 'is_used', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'code' => 'Code',
- 'is_used' => 'Is Used',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2021/10/20 0020 18:01
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AddonsBossLevel|bool
- */
- public static function setData(array $params){
- $trans = Yii::$app->db->beginTransaction();
- try{
- if(!empty($params['id'])){
- $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $params['mall_id']],['<>','status',StatusEnum::DELETE]]);
- if(empty($model)) throw new \Exception('数据不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- }
- if(!$model->load($params,'') || !$model->save()){
- throw new \Exception($model->getErrorMessage());
- }
- $trans->commit();
- return $model;
- }catch(\Exception $e){
- $trans->rollBack();
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|