| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- namespace common\models\goods;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\user\UserWallet;
- use PHPUnit\Util\Exception;
- use Yii;
- /**
- * This is the model class for table "qimall_goods_collect".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $goods_id 商品id
- * @property int $user_id 会员id
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- */
- class GoodsCollect extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%goods_collect}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'goods_id', 'user_id', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'goods_id' => '商品id',
- 'user_id' => '会员id',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * @desc:保存数据
- * @Author: hua
- * @Date: 2021/11/9
- * @Time: 9:08
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return GoodsCollect|false
- */
- public static function setData(array $params)
- {
- try {
- if($params['type']==1){
- if (!empty($params['goods_id'])) {
- $model = self::findOne(['mall_id' => $params['mall_id'],'goods_id' => $params['goods_id'], 'user_id' => $params['user_id'], 'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]);
- if (empty($model)){
- $model = new self();
- $model->loadDefaultValues();
- }else{
- if($model->status)throw new Exception('已收藏');
- }
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }
- }
- if($params['type']==0){
- if (!empty($params['goods_id'])) {
- $model = self::findOne(['mall_id' => $params['mall_id'],'goods_id' => $params['goods_id'], 'user_id' => $params['user_id'], 'status' => [StatusEnum::ENABLED]]);
- if (empty($model)) throw new Exception('不存在');
- if (!$model->load($params, '') || !$model->save()) throw new Exception($model->getErrorMessage());
- return $model;
- }
- }
- } catch (Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|