| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?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 "{{%worker_goods}}".
- *
- * @property integer $id
- * @property integer $worker_id
- * @property integer $goods_id
- * @property integer $status
- * @property integer $created_at
- * @property integer $updated_at
- * @property integer $type
- * @property integer $is_delete
- */
- class WorkerGoods extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%worker_goods}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- ]
- ];
- }
-
- //增加或者全部替换
- public static function saveAll($worker_id, $goodsIds = [], $delAll = 0) {
- if($delAll){
- self::updateAll(['status' => 0], ['worker_id' => $worker_id]);
- }
- self::updateAll(['status' => 1], ['worker_id' => $worker_id, 'goods_id' => $goodsIds]);
- foreach($goodsIds as $goodsId){
- $has = self::findOne(['status' => 1, 'worker_id' => $worker_id, 'goods_id' => $goodsId]);
- if($has){
- continue;
- }
- $self = new self();
- $self->worker_id = $worker_id;
- $self->goods_id = $goodsId;
- $self->save();
- }
- return true;
- }
- public static function del($worker_id, $ids = []) {
- return self::updateAll(['status' => 0], ['worker_id' => $worker_id, 'goods_id' => $ids]);
- }
- }
|