DistributionGoodsSetting.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace addons\Distribution\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_distribution_goods_setting".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $goods_id 商品id
  12. * @property string|null $content 独立配置详情
  13. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  14. * @property int $created_at
  15. * @property int $updated_at
  16. */
  17. class DistributionGoodsSetting extends BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_distribution_goods_setting}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'goods_id', 'status', 'created_at', 'updated_at'], 'integer'],
  33. [['content'], 'string'],
  34. ];
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function attributeLabels()
  40. {
  41. return [
  42. 'id' => 'ID',
  43. 'mall_id' => '商城ID',
  44. 'goods_id' => '商品id',
  45. 'content' => '独立配置详情',
  46. 'status' => '状态[-1:删除;0:禁用;1启用]',
  47. 'created_at' => 'Created At',
  48. 'updated_at' => 'Updated At',
  49. ];
  50. }
  51. /**
  52. * 保存数据
  53. * @Author: lun
  54. * @DateTime: 2021/10/29 0029 17:31
  55. * @Copyright: copyright (c) 2021 广东七件事集团
  56. * @param $params
  57. * @return bool
  58. */
  59. public static function setData($params)
  60. {
  61. try{
  62. if (!empty($params['goods_id'])) {
  63. $model = self::findOne(['goods_id' => $params['goods_id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED]]);
  64. if (empty($model)) {
  65. $model = new self();
  66. $model->mall_id = $params['mall_id'];
  67. $model->goods_id = $params['goods_id'];
  68. $model->content = $params['content'];
  69. $model->loadDefaultValues();
  70. }
  71. } else {
  72. throw new \Exception('商品ID不能为空');
  73. }
  74. if(!$model->load($params,'') || !$model->save()){
  75. throw new \Exception($model->getErrorMessage());
  76. }
  77. return true;
  78. }catch(\Exception $e){
  79. self::$static_error = $e->getMessage();
  80. return false;
  81. }
  82. }
  83. }