| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <?php
- namespace addons\Happiness\common\models;
- use addons\Happiness\common\enums\HappinessEnum;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Yii;
- /**
- * This is the model class for table "{{%addons_happiness_expenses_log}}".
- * 支出统计表
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $store_id 小店id
- * @property int $user_id 会员id
- * @property int $order_id 订单id
- * @property string $order_no 订单编号
- * @property float $order_money 订单金额
- * @property float $store_money 小店收益
- * @property float $share_money 分享奖励
- * @property float $promotion_money 推广奖励
- * @property float $agent_money 代理奖励
- * @property float $fans_money 锁定奖励
- * @property float $pension_money 养老金
- * @property float $pv_money PV值
- * @property int $status 状态[0禁用 1启用 -1删除]
- * @property int|null $created_at 添加时间戳
- * @property int|null $updated_at 更新时间戳
- */
- class HappinessExpensesLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_happiness_expenses_log}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'store_id', 'user_id', 'order_id', 'status', 'created_at', 'updated_at'], 'integer'],
- [['order_money', 'store_money', 'share_money', 'promotion_money', 'agent_money', 'fans_money', 'pension_money', 'pv_money'], 'number'],
- [['order_no'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'store_id' => '小店id',
- 'user_id' => '会员id',
- 'order_id' => '订单id',
- 'order_no' => '订单编号',
- 'order_money' => '订单金额',
- 'store_money' => '小店收益',
- 'share_money' => '分享奖励',
- 'promotion_money' => '推广奖励',
- 'agent_money' => '代理奖励',
- 'fans_money' => '锁定奖励',
- 'pension_money' => '养老金',
- 'pv_money' => 'PV值',
- 'status' => '状态[0禁用 1启用 -1删除]',
- 'created_at' => '添加时间戳',
- 'updated_at' => '更新时间戳',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id']);
- }
- public function getStore()
- {
- return $this->hasOne(HappinessStore::class, ['id' => 'store_id']);
- }
- public static function setData($params)
- {
- try {
- if (!empty($params['user_id'] && !empty($params['mall_id'])) && !empty($params['order_id'])) {
- $model = self::findOne(['user_id' => $params['user_id'], 'mall_id' => $params['mall_id'],'order_id' => $params['order_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- }
- else if(!empty($params['id']))
- $model = self::findOne($params['id']);
- else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if(!$model)
- {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) {
- throw new \Exception($model->getErrorMessage());
- }
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|