WriteOffCommissionJob.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_commission_job}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城ID
  10. * @property string $date_limit 结算开始~结束日期
  11. * @property int $compute_period 结算周期:1天,2周,3月
  12. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  13. * @property int $created_at
  14. * @property int $updated_at
  15. */
  16. class WriteOffCommissionJob extends \common\models\base\BaseActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%addons_write_off_commission_job}}';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules()
  29. {
  30. return [
  31. [['mall_id', 'compute_period', 'status', 'created_at', 'updated_at'], 'integer'],
  32. [['date_limit'], 'string', 'max' => 45],
  33. ];
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function attributeLabels()
  39. {
  40. return [
  41. 'id' => 'ID',
  42. 'mall_id' => 'Mall ID',
  43. 'date_limit' => 'Date Limit',
  44. 'compute_period' => 'Compute Period',
  45. 'status' => 'Status',
  46. 'created_at' => 'Created At',
  47. 'updated_at' => 'Updated At',
  48. ];
  49. }
  50. /**
  51. * 保存数据
  52. * @Author: lun
  53. * @DateTime: 2021/10/20 0020 18:01
  54. * @Copyright: copyright (c) 2021 广东七件事集团
  55. * @param array $params
  56. * @return AddonsBossLevel|bool
  57. */
  58. public static function setData(array $params){
  59. $trans = Yii::$app->db->beginTransaction();
  60. try{
  61. if(!empty($params['id'])){
  62. $model = self::findOne(['and',['id' => $params['id'],'mall_id' => $params['mall_id']],['<>','status',StatusEnum::DELETE]]);
  63. if(empty($model)) throw new \Exception('数据不存在或已删除');
  64. }else{
  65. $model = new self();
  66. $model->loadDefaultValues();
  67. $model->mall_id = $params['mall_id'];
  68. }
  69. if(!$model->load($params,'') || !$model->save()){
  70. throw new \Exception($model->getErrorMessage());
  71. }
  72. $trans->commit();
  73. return $model;
  74. }catch(\Exception $e){
  75. $trans->rollBack();
  76. self::$static_error = $e->getMessage();
  77. return false;
  78. }
  79. }
  80. }