AreaCommissionItemSettingDetail.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace addons\Area\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_area_commission_item_setting_detail".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $area_commission_item_setting_id
  12. * @property int $level
  13. * @property float $agent_team_prize 团队奖
  14. * @property float $agent_equal_prize 平级奖
  15. * @property int $status 状态[-1:删除;0:禁用;1启用]
  16. * @property int $created_at
  17. * @property int $updated_at
  18. */
  19. class AreaCommissionItemSettingDetail extends BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%addons_area_commission_item_setting_detail}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['mall_id', 'area_commission_item_setting_id'], 'required'],
  35. [['mall_id', 'area_commission_item_setting_id', 'level', 'status', 'created_at', 'updated_at'], 'integer'],
  36. [['agent_team_prize', 'agent_equal_prize'], 'number'],
  37. ];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => 'ID',
  46. 'mall_id' => '商城ID',
  47. 'area_commission_item_setting_id' => 'Area Commission Item Setting ID',
  48. 'level' => 'Level',
  49. 'agent_team_prize' => '团队奖',
  50. 'agent_equal_prize' => '平级奖',
  51. 'status' => '状态[-1:删除;0:禁用;1启用]',
  52. 'created_at' => 'Created At',
  53. 'updated_at' => 'Updated At',
  54. ];
  55. }
  56. public static function setData($params, $data)
  57. {
  58. try{
  59. foreach ($data as $item) {
  60. $model = self::findOne([
  61. 'mall_id' => $params['mall_id'],
  62. 'level' => $item['level'],
  63. 'area_commission_item_setting_id' => $params['area_commission_item_setting_id'],
  64. 'status' => [StatusEnum::ENABLED]
  65. ]);
  66. if (empty($model)) {
  67. $model = new self();
  68. $model->mall_id = $params['mall_id'];
  69. $model->area_commission_item_setting_id = $params['area_commission_item_setting_id'];
  70. $model->loadDefaultValues();
  71. }
  72. if(!$model->load($item,'') || !$model->save()){
  73. throw new \Exception($model->getErrorMessage());
  74. }
  75. }
  76. return true;
  77. }catch(\Exception $e){
  78. self::$static_error = $e->getMessage();
  79. return false;
  80. }
  81. }
  82. }