| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace common\models\census;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_census_mall_user".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $user_id 用户id
- * @property int $total_views 浏览量
- * @property int $total_pay_money 交易额
- * @property int|null $status 状态[-1:删除;0:禁用;1启用;]
- * @property int $created_at 创建时间
- * @property int $updated_at 上次更新数据时间
- * @property int $add_pay_nums 支付件数
- * @property int $add_orders
- * @property int $add_order_money
- * @property int $add_pay_orders 支付订单数
- * @property int $add_sale_orders
- * @property int $add_sale_money
- */
- class CensusMallUser extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%census_mall_user}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'total_views', 'status',
- 'created_at', 'updated_at','add_pay_nums','add_orders','add_pay_orders','add_sale_orders'
- ], 'integer'],
- [['total_pay_money','add_sale_money','add_order_money'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户id',
- 'total_views' => '浏览量',
- 'total_pay_money' => '交易额',
- 'status' => '状态[-1:删除;0:禁用;1启用;]',
- 'created_at' => '创建时间',
- 'updated_at' => '上次更新数据时间',
- ];
- }
- public static function setData($params)
- {
- try {
- if (empty($params['mall_id'])&&empty($params['user_id'])) {
- return false;
- }
- $model = self::findOne(['mall_id' => $params['mall_id'],'user_id' => $params['user_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) {
- $model = new self();
- $model->mall_id = $params['mall_id'];
- $model->user_id = $params['user_id'];
- $model->loadDefaultValues();
- }
- if (!empty($params['views'])) $model->total_views += $params['views'];
- if (!empty($params['pay_money'])) $model->total_pay_money += $params['pay_money'];
- if (!empty($params['add_pay_nums'])) $model->add_pay_nums += $params['add_pay_nums'];
- if (!empty($params['add_pay_orders'])) $model->add_pay_orders += $params['add_pay_orders'];
- if (!empty($params['add_orders'])) $model->add_orders += $params['add_orders'];
- if (!empty($params['add_order_money'])) $model->add_order_money += $params['add_order_money'];
- if (!empty($params['add_sale_money'])) $model->add_sale_money += $params['add_sale_money'];
- if (!empty($params['add_sale_orders'])) $model->add_sale_orders += $params['add_sale_orders'];
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|