ActivityOrderRebateSelfGoods.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use Yii;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%activity_rebate_order_self_goods}}".
  13. *
  14. * @property integer $id
  15. */
  16. class ActivityOrderRebateSelfGoods extends \yii\db\ActiveRecord
  17. {
  18. /**
  19. * @inheritdoc
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%activity_rebate_order_self_goods}}';
  24. }
  25. public function behaviors()
  26. {
  27. return [];
  28. }
  29. public static function saveList($gids = [], $activity_id = 0) {
  30. if($activity_id){
  31. $oldList = self::find()->where(['act_id' => $activity_id])->select('goods_id')->column();
  32. $delGids = array_diff($oldList, $gids);
  33. $addGids = array_diff($gids, $oldList);
  34. if($delGids){
  35. self::deleteAll(['act_id' => $activity_id, 'goods_id' => $delGids]);
  36. }
  37. foreach($addGids as $item){
  38. $model = new self();
  39. $model->act_id = $activity_id;
  40. $model->goods_id = $item;
  41. $save = $model->save();
  42. if(!$save){
  43. \Yii::error([__METHOD__, $model->attributes]);
  44. return [
  45. 'code' => 1,
  46. 'msg' => '商品信息保存失败:' . array_shift($model->getFirstErrors()),
  47. ];
  48. }
  49. }
  50. }
  51. return [
  52. 'code' => 0,
  53. 'msg' => 'ok',
  54. ];
  55. }
  56. }