| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?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_analysis".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property int $user_id 用户id
- * @property int $buy_numbers 购买次数
- * @property float $total_pay_money 交易金额
- * @property string $date 日期
- * @property int|null $status 状态[-1:删除;0:禁用;1启用;]
- * @property int $created_at 创建时间
- * @property int $updated_at 上次更新数据时间
- */
- class CensusMallAnalysis extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%census_mall_analysis}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'buy_numbers', 'status', 'created_at', 'updated_at'], 'integer'],
- [['total_pay_money'], 'number'],
- [['date'], 'string', 'max' => 20],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户id',
- 'buy_numbers' => '购买次数',
- 'total_pay_money' => '交易金额',
- 'date' => '日期',
- 'status' => '状态[-1:删除;0:禁用;1启用;]',
- 'created_at' => '创建时间',
- 'updated_at' => '上次更新数据时间',
- ];
- }
- public static function getConfigList($key = null)
- {
- $config_list = [
- 1 => ['min' => 1, 'max' => 30, 'desc' => 'R<30'],
- 2 => ['min' => 30, 'max' => 90, 'desc' => '30<=R<90'],
- 3 => ['min' => 90, 'max' => 180, 'desc' => '90<=R<180'],
- 4 => ['min' => 180, 'max' => 365, 'desc' => '180<=R<365'],
- 5 => ['min' => 365, 'max' => 365, 'desc' => 'R>=365'],
- ];
- if ($key !== null && isset($config_list[$key])) {
- return $config_list[$key];
- }
- return $config_list;
- }
- public static function setData($params)
- {
- try {
- if (empty($params['mall_id']) || empty($params['date']) || empty($params['user_id'])) return false;
- $model = self::findOne(['mall_id' => $params['mall_id'], 'user_id' => $params['user_id'], 'date' => $params['date'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) {
- $model = new self();
- $model->date = $params['date'];
- $model->user_id = $params['user_id'];
- $model->mall_id = $params['mall_id'];
- $model->loadDefaultValues();
- }
- if (!empty($params['buy_numbers'])) $model->buy_numbers += $params['buy_numbers'];
- if (!empty($params['total_pay_money'])) $model->total_pay_money += $params['total_pay_money'];
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|