| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- /*
- * @Author: your name
- * @Date: 2021-05-12 10:51:33
- * @LastEditTime: 2021-05-19 14:51:01
- * @LastEditors: Please set LastEditors
- * @Description: In User Settings Edit
- * @FilePath: \admin_php\modules\client\models\v1\FavoriteAddForm.php
- */
- namespace app\modules\alliance\models;
- use app\models\Favorite;
- use yii\base\Model;
- class FavoriteAddForm extends Model
- {
- public $store_id;
- public $user_id;
- public $saas_id;
- public $id;
- public $type;
- public function rules()
- {
- return [
- [['type'], 'default', 'value' => 0],
- ['type', 'in', 'range' => [Favorite::FAVORITE_GOODS, Favorite::FAVORITE_SHOP]],
- [['id'], 'default', 'value' => 0],
- //[['id'], 'required',],
- ];
- }
- public function save()
- {
- if (!$this->validate()) {
- return [
- 'code' => 1,
- 'msg' => $this->getErrorSummary(false)[0]
- ];
- }
- $existFavorite = Favorite::findOne([
- 'store_id' => $this->store_id,
- 'user_id' => 0,
- 'saas_id' => $this->saas_id,
- 'goods_id' => $this->id,
- 'type' => $this->type,
- ]);
- if ($existFavorite) {
- $existFavorite->is_delete = 0;
- $existFavorite->save();
- return [
- 'code' => 0,
- 'msg' => 'success',
- ];
- }
-
- $favorite = new Favorite();
- $favorite->store_id = $this->store_id;
- $favorite->user_id = 0;
- $favorite->saas_id = $this->saas_id;
- $favorite->goods_id = $this->id;
- $favorite->type = $this->type;
- $favorite->created_at = time();
- if ($favorite->save()) {
- return [
- 'code' => 0,
- 'msg' => 'success',
- ];
- } else {
- return [
- 'code' => 1,
- 'msg' => 'fail',
- ];
- }
- }
- }
|