WriteOffAwardLog.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace addons\WriteOff\common\models;
  3. use Yii;
  4. use common\enums\StatusEnum;
  5. /**
  6. * This is the model class for table "{{%addons_write_off_award_log}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $user_id 用户id
  11. * @property float $achievement_sum 总业绩
  12. * @property float $award_money 奖励金额
  13. * @property int|null $is_settlement 是否已结算打款 1:是
  14. * @property int $created_at
  15. * @property int $updated_at
  16. * @property int $status 状态[-1:删除;0:禁用;1启用]
  17. */
  18. class WriteOffAwardLog extends \common\models\base\BaseActiveRecord
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%addons_write_off_award_log}}';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['mall_id', 'user_id', 'is_settlement', 'created_at', 'updated_at', 'status'], 'integer'],
  34. [['achievement_sum', 'award_money','rate'], 'number'],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'mall_id' => 'Mall ID',
  45. 'user_id' => 'User ID',
  46. 'achievement_sum' => 'Achievement Sum',
  47. 'award_money' => 'Award Money',
  48. 'is_settlement' => 'Is Settlement',
  49. 'created_at' => 'Created At',
  50. 'updated_at' => 'Updated At',
  51. 'status' => 'Status',
  52. ];
  53. }
  54. /**
  55. * 保存数据
  56. * @Author: lun
  57. * @DateTime: 2021/10/20 0020 18:01
  58. * @Copyright: copyright (c) 2021 广东七件事集团
  59. * @param array $params
  60. * @return AddonsBossLevel|bool
  61. */
  62. public static function setData(array $params){
  63. $trans = Yii::$app->db->beginTransaction();
  64. try{
  65. if(!empty($params['id'])){
  66. $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $params['mall_id']],['<>','status',StatusEnum::DELETE]]);
  67. if(empty($model)) throw new \Exception('数据不存在或已删除');
  68. }else{
  69. $model = new self();
  70. $model->loadDefaultValues();
  71. $model->mall_id = $params['mall_id'];
  72. }
  73. if(!$model->load($params,'') || !$model->save()){
  74. throw new \Exception($model->getErrorMessage());
  75. }
  76. $trans->commit();
  77. return $model;
  78. }catch(\Exception $e){
  79. $trans->rollBack();
  80. self::$static_error = $e->getMessage();
  81. return false;
  82. }
  83. }
  84. }