CommunityGoodsModeSetting.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace addons\Community\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_community_goods_mode_setting}}".
  7. *
  8. * @property int $id ID
  9. * @property int $mall_id 商城ID
  10. * @property string $commission_type 分佣类型; score积分分佣, commission佣金分佣
  11. * @property int $enable 是否参与自提奖励[0:否, 1:是]
  12. * @property int $is_alone 是否独立设置[0:否, 1:是]
  13. * @property int $is_percent 类型 0百分比 1 固定金额
  14. * @property string $item_type 项目类型:商品goods
  15. * @property int $item_id 项目id
  16. * @property float $give_num 赠送数额
  17. * @property int $status 状态[-1:删除;0:禁用;1启用]
  18. * @property int $created_at 创建时间
  19. * @property int $updated_at 更新时间
  20. */
  21. class CommunityGoodsModeSetting extends \common\models\base\BaseActiveRecord
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public static function tableName()
  27. {
  28. return '{{%addons_community_goods_mode_setting}}';
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['mall_id', 'enable', 'is_alone', 'is_percent', 'item_id', 'status', 'created_at', 'updated_at'], 'integer'],
  37. [['give_num'], 'number'],
  38. [['commission_type', 'item_type'], 'string', 'max' => 255],
  39. ];
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. public function attributeLabels()
  45. {
  46. return [
  47. 'id' => 'ID',
  48. 'mall_id' => '商城ID',
  49. 'commission_type' => '分佣类型; score积分分佣, commission佣金分佣',
  50. 'enable' => '是否参与自提奖励[0:否, 1:是]',
  51. 'is_alone' => '是否独立设置[0:否, 1:是]',
  52. 'is_percent' => '类型 0百分比 1 固定金额',
  53. 'item_type' => '项目类型:商品goods',
  54. 'item_id' => '项目id',
  55. 'give_num' => '赠送数额',
  56. 'status' => '状态[-1:删除;0:禁用;1启用]',
  57. 'created_at' => '创建时间',
  58. 'updated_at' => '更新时间',
  59. ];
  60. }
  61. public static function setData($params, $data)
  62. {
  63. try{
  64. foreach ($data as $item) {
  65. $model = self::findOne([
  66. 'mall_id' => $params['mall_id'],
  67. 'item_type' => $item['item_type'],
  68. 'commission_type' => $item['commission_type'],
  69. 'item_id' => $params['item_id'],
  70. 'status' => [StatusEnum::ENABLED]
  71. ]);
  72. if (empty($model)) {
  73. $model = new self();
  74. $model->mall_id = $params['mall_id'];
  75. $model->item_id = $params['item_id'];
  76. $model->loadDefaultValues();
  77. }
  78. if(!$model->load($item,'') || !$model->save()){
  79. throw new \Exception($model->getErrorMessage());
  80. }
  81. }
  82. return true;
  83. }catch(\Exception $e){
  84. self::$static_error = $e->getMessage();
  85. return false;
  86. }
  87. }
  88. }