DistributionGoodsSetting.php 2.5 KB

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