HappinessExpensesLog.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace addons\Happiness\common\models;
  3. use addons\Happiness\common\enums\HappinessEnum;
  4. use common\enums\StatusEnum;
  5. use common\models\user\User;
  6. use Yii;
  7. /**
  8. * This is the model class for table "{{%addons_happiness_expenses_log}}".
  9. * 支出统计表
  10. *
  11. * @property int $id
  12. * @property int $mall_id 商城id
  13. * @property int $store_id 小店id
  14. * @property int $user_id 会员id
  15. * @property int $order_id 订单id
  16. * @property string $order_no 订单编号
  17. * @property float $order_money 订单金额
  18. * @property float $store_money 小店收益
  19. * @property float $share_money 分享奖励
  20. * @property float $promotion_money 推广奖励
  21. * @property float $agent_money 代理奖励
  22. * @property float $fans_money 锁定奖励
  23. * @property float $pension_money 养老金
  24. * @property float $pv_money PV值
  25. * @property int $status 状态[0禁用 1启用 -1删除]
  26. * @property int|null $created_at 添加时间戳
  27. * @property int|null $updated_at 更新时间戳
  28. */
  29. class HappinessExpensesLog extends \common\models\base\BaseActiveRecord
  30. {
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public static function tableName()
  35. {
  36. return '{{%addons_happiness_expenses_log}}';
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function rules()
  42. {
  43. return [
  44. [['mall_id', 'store_id', 'user_id', 'order_id', 'status', 'created_at', 'updated_at'], 'integer'],
  45. [['order_money', 'store_money', 'share_money', 'promotion_money', 'agent_money', 'fans_money', 'pension_money', 'pv_money'], 'number'],
  46. [['order_no'], 'string', 'max' => 255],
  47. ];
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function attributeLabels()
  53. {
  54. return [
  55. 'id' => 'ID',
  56. 'mall_id' => '商城id',
  57. 'store_id' => '小店id',
  58. 'user_id' => '会员id',
  59. 'order_id' => '订单id',
  60. 'order_no' => '订单编号',
  61. 'order_money' => '订单金额',
  62. 'store_money' => '小店收益',
  63. 'share_money' => '分享奖励',
  64. 'promotion_money' => '推广奖励',
  65. 'agent_money' => '代理奖励',
  66. 'fans_money' => '锁定奖励',
  67. 'pension_money' => '养老金',
  68. 'pv_money' => 'PV值',
  69. 'status' => '状态[0禁用 1启用 -1删除]',
  70. 'created_at' => '添加时间戳',
  71. 'updated_at' => '更新时间戳',
  72. ];
  73. }
  74. public function getUser()
  75. {
  76. return $this->hasOne(User::class, ['id' => 'user_id']);
  77. }
  78. public function getStore()
  79. {
  80. return $this->hasOne(HappinessStore::class, ['id' => 'store_id']);
  81. }
  82. public static function setData($params)
  83. {
  84. try {
  85. if (!empty($params['user_id'] && !empty($params['mall_id'])) && !empty($params['order_id'])) {
  86. $model = self::findOne(['user_id' => $params['user_id'], 'mall_id' => $params['mall_id'],'order_id' => $params['order_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  87. }
  88. else if(!empty($params['id']))
  89. $model = self::findOne($params['id']);
  90. else {
  91. $model = new self();
  92. $model->loadDefaultValues();
  93. }
  94. if(!$model)
  95. {
  96. $model = new self();
  97. $model->loadDefaultValues();
  98. }
  99. if (!$model->load($params, '') || !$model->save()) {
  100. throw new \Exception($model->getErrorMessage());
  101. }
  102. return $model;
  103. } catch (\Exception $e) {
  104. self::$static_error = $e->getMessage();
  105. return false;
  106. }
  107. }
  108. }