CensusMallUser.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_user".
  8. *
  9. * @property int $id ID
  10. * @property int $mall_id 商城ID
  11. * @property int $user_id 用户id
  12. * @property int $total_views 浏览量
  13. * @property int $total_pay_money 交易额
  14. * @property int|null $status 状态[-1:删除;0:禁用;1启用;]
  15. * @property int $created_at 创建时间
  16. * @property int $updated_at 上次更新数据时间
  17. * @property int $add_pay_nums 支付件数
  18. * @property int $add_orders
  19. * @property int $add_order_money
  20. * @property int $add_pay_orders 支付订单数
  21. * @property int $add_sale_orders
  22. * @property int $add_sale_money
  23. */
  24. class CensusMallUser extends BaseActiveRecord
  25. {
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public static function tableName()
  30. {
  31. return '{{%census_mall_user}}';
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function rules()
  37. {
  38. return [
  39. [['mall_id', 'user_id', 'total_views', 'status',
  40. 'created_at', 'updated_at','add_pay_nums','add_orders','add_pay_orders','add_sale_orders'
  41. ], 'integer'],
  42. [['total_pay_money','add_sale_money','add_order_money'], 'number'],
  43. ];
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function attributeLabels()
  49. {
  50. return [
  51. 'id' => 'ID',
  52. 'mall_id' => '商城ID',
  53. 'user_id' => '用户id',
  54. 'total_views' => '浏览量',
  55. 'total_pay_money' => '交易额',
  56. 'status' => '状态[-1:删除;0:禁用;1启用;]',
  57. 'created_at' => '创建时间',
  58. 'updated_at' => '上次更新数据时间',
  59. ];
  60. }
  61. public static function setData($params)
  62. {
  63. try {
  64. if (empty($params['mall_id'])&&empty($params['user_id'])) {
  65. return false;
  66. }
  67. $model = self::findOne(['mall_id' => $params['mall_id'],'user_id' => $params['user_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  68. if (empty($model)) {
  69. $model = new self();
  70. $model->mall_id = $params['mall_id'];
  71. $model->user_id = $params['user_id'];
  72. $model->loadDefaultValues();
  73. }
  74. if (!empty($params['views'])) $model->total_views += $params['views'];
  75. if (!empty($params['pay_money'])) $model->total_pay_money += $params['pay_money'];
  76. if (!empty($params['add_pay_nums'])) $model->add_pay_nums += $params['add_pay_nums'];
  77. if (!empty($params['add_pay_orders'])) $model->add_pay_orders += $params['add_pay_orders'];
  78. if (!empty($params['add_orders'])) $model->add_orders += $params['add_orders'];
  79. if (!empty($params['add_order_money'])) $model->add_order_money += $params['add_order_money'];
  80. if (!empty($params['add_sale_money'])) $model->add_sale_money += $params['add_sale_money'];
  81. if (!empty($params['add_sale_orders'])) $model->add_sale_orders += $params['add_sale_orders'];
  82. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  83. return $model;
  84. } catch (\Exception $e) {
  85. self::$static_error = $e->getMessage();
  86. return false;
  87. }
  88. }
  89. }