CensusMallAnalysis.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace common\models\census;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_census_mall_analysis".
  8. *
  9. * @property int $id ID
  10. * @property int $mall_id 商城ID
  11. * @property int $user_id 用户id
  12. * @property int $buy_numbers 购买次数
  13. * @property float $total_pay_money 交易金额
  14. * @property string $date 日期
  15. * @property int|null $status 状态[-1:删除;0:禁用;1启用;]
  16. * @property int $created_at 创建时间
  17. * @property int $updated_at 上次更新数据时间
  18. */
  19. class CensusMallAnalysis extends BaseActiveRecord
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. public static function tableName()
  25. {
  26. return '{{%census_mall_analysis}}';
  27. }
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public function rules()
  32. {
  33. return [
  34. [['mall_id', 'user_id', 'buy_numbers', 'status', 'created_at', 'updated_at'], 'integer'],
  35. [['total_pay_money'], 'number'],
  36. [['date'], 'string', 'max' => 20],
  37. ];
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function attributeLabels()
  43. {
  44. return [
  45. 'id' => 'ID',
  46. 'mall_id' => '商城ID',
  47. 'user_id' => '用户id',
  48. 'buy_numbers' => '购买次数',
  49. 'total_pay_money' => '交易金额',
  50. 'date' => '日期',
  51. 'status' => '状态[-1:删除;0:禁用;1启用;]',
  52. 'created_at' => '创建时间',
  53. 'updated_at' => '上次更新数据时间',
  54. ];
  55. }
  56. public static function getConfigList($key = null)
  57. {
  58. $config_list = [
  59. 1 => ['min' => 1, 'max' => 30, 'desc' => 'R<30'],
  60. 2 => ['min' => 30, 'max' => 90, 'desc' => '30<=R<90'],
  61. 3 => ['min' => 90, 'max' => 180, 'desc' => '90<=R<180'],
  62. 4 => ['min' => 180, 'max' => 365, 'desc' => '180<=R<365'],
  63. 5 => ['min' => 365, 'max' => 365, 'desc' => 'R>=365'],
  64. ];
  65. if ($key !== null && isset($config_list[$key])) {
  66. return $config_list[$key];
  67. }
  68. return $config_list;
  69. }
  70. public static function setData($params)
  71. {
  72. try {
  73. if (empty($params['mall_id']) || empty($params['date']) || empty($params['user_id'])) return false;
  74. $model = self::findOne(['mall_id' => $params['mall_id'], 'user_id' => $params['user_id'], 'date' => $params['date'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  75. if (empty($model)) {
  76. $model = new self();
  77. $model->date = $params['date'];
  78. $model->user_id = $params['user_id'];
  79. $model->mall_id = $params['mall_id'];
  80. $model->loadDefaultValues();
  81. }
  82. if (!empty($params['buy_numbers'])) $model->buy_numbers += $params['buy_numbers'];
  83. if (!empty($params['total_pay_money'])) $model->total_pay_money += $params['total_pay_money'];
  84. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  85. return $model;
  86. } catch (\Exception $e) {
  87. self::$static_error = $e->getMessage();
  88. return false;
  89. }
  90. }
  91. }