GoodsMarketing.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace common\models\goods;
  3. use addons\GroupBuy\common\enums\GroupBuyEnum;
  4. use common\enums\StatusEnum;
  5. use common\models\base\BaseActiveRecord;
  6. use Yii;
  7. /**
  8. * This is the model class for table "qimall_goods_marketing".
  9. *
  10. *
  11. * @property int $id
  12. * @property int $mall_id
  13. * @property int $goods_id 商品ID
  14. * @property int $marketing_id 营销ID
  15. * @property string $marketing_type 营销名称
  16. * @property int $status 状态[1正常 -1删除]
  17. * @property int $created_at 创建时间
  18. * @property int $updated_at 修改时间
  19. */
  20. class GoodsMarketing extends BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return '{{%goods_marketing}}';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['mall_id','goods_id', 'marketing_id', 'status', 'created_at', 'updated_at'], 'integer'],
  36. [['marketing_type'], 'string', 'max' => 255],
  37. ];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => 'ID',
  46. 'mall_id' => '商品ID',
  47. 'goods_id' => '商品ID',
  48. 'marketing_id' => '营销ID',
  49. 'marketing_type' => '营销名称',
  50. 'status' => '状态[1正常 -1删除]',
  51. 'created_at' => '创建时间',
  52. 'updated_at' => '修改时间',
  53. ];
  54. }
  55. /**
  56. * @desc:保存数据
  57. * @Author: hua
  58. * @Date: 2022/1/6
  59. * @Time: 18:01
  60. * @Copyright: copyright (c) 2021 广东七件事集团
  61. * @param array $params
  62. * @return GoodsMarketing|false
  63. */
  64. public static function setData(array $params){
  65. try{
  66. if(!empty($params['mall_id'])&&!empty($params['marketing_id'])&&!empty($params['marketing_type'])){
  67. $model = self::findOne([
  68. 'mall_id' => $params['mall_id'],
  69. 'marketing_id'=>$params['marketing_id'],
  70. 'marketing_type'=>$params['marketing_type'],
  71. ]);
  72. if(empty($model)){
  73. $model = new self();
  74. $model->loadDefaultValues();
  75. }
  76. }else{
  77. $model = new self();
  78. $model->loadDefaultValues();
  79. }
  80. if(!$model->load($params,'') || !$model->save()){
  81. throw new \Exception($model->getErrorMessage());
  82. }
  83. return $model;
  84. }catch(\Exception $e){
  85. self::$static_error = $e->getMessage();
  86. return false;
  87. }
  88. }
  89. }