PlatformFinanceDay.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace common\models\platform;
  3. use Yii;
  4. /**
  5. * This is the model class for table "{{%platform_finance_day}}".
  6. *
  7. *
  8. * @property int $id
  9. * @property float $add_money 收入,单位:元
  10. * @property float $sub_money 支出,单位:元
  11. * @property float $withdraw_money 已提现金额,单位:元
  12. * @property float $add_addons_pay 应用付费收入,单位:元
  13. * @property float $add_template 模板收入,单位:元
  14. * @property int $date 日期,年月日
  15. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  16. * @property int $created_at 添加时间戳
  17. * @property int $updated_at 更新时间戳
  18. */
  19. class PlatformFinanceDay extends \common\models\base\BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%platform_finance_day}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['add_money', 'sub_money', 'withdraw_money', 'add_addons_pay', 'add_template'], 'number'],
  35. [['date', 'status', 'created_at', 'updated_at'], 'integer'],
  36. ];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => 'ID',
  45. 'add_money' => '收入,单位:元',
  46. 'sub_money' => '支出,单位:元',
  47. 'withdraw_money' => '已提现金额,单位:元',
  48. 'add_addons_pay' => '应用付费收入,单位:元',
  49. 'add_template' => '模板收入,单位:元',
  50. 'date' => '日期,年月日',
  51. 'status' => '状态[-1:删除;0:禁用;1启用]',
  52. 'created_at' => '添加时间戳',
  53. 'updated_at' => '更新时间戳',
  54. ];
  55. }
  56. /**
  57. * 保存数据
  58. * @Author: lun
  59. * @DateTime: 2022/3/3 0003 18:30
  60. * @Copyright: copyright (c) 2021 广东七件事集团
  61. * @param $data
  62. * @return bool
  63. */
  64. public static function setData($data) {
  65. try {
  66. $date = date('ymd', time());
  67. $model = self::find()->where(['date' => $date])->one();
  68. if (empty($model)) {
  69. $model = new self();
  70. $model->date = $date;
  71. }
  72. // 循环赋值
  73. foreach ($model as $key => $value) {
  74. if (isset($data[$key]) && !empty($data[$key])) $model->$key += $data[$key];
  75. }
  76. if (!$model->save()) {
  77. self::$static_error = $model->getErrorMessage();
  78. return false;
  79. }
  80. return true;
  81. } catch (\Exception $e) {
  82. self::$static_error = $e->getMessage();
  83. return false;
  84. }
  85. }
  86. }