UserSignInRecord.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace addons\SignIn\common\models;
  3. use common\components\export\CsvTool;
  4. use common\enums\DownloadEnum;
  5. use common\models\common\Download;
  6. use common\models\base\BaseActiveRecord;
  7. use common\models\user\User;
  8. use Exception;
  9. use Yii;
  10. /**
  11. * This is the model class for table "{{%addons_user_sign_in_record}}".
  12. * @property int $id
  13. * @property int $user_id
  14. * @property int $created_at 创建时间
  15. */
  16. class UserSignInRecord extends BaseActiveRecord
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. public static function tableName()
  22. {
  23. return '{{%addons_user_sign_in_record}}';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function rules(){
  29. return [
  30. [['user_id'], 'required'],
  31. [['user_id', 'mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
  32. ];
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function attributeLabels(){
  38. return [
  39. 'id' => 'ID',
  40. 'mall_id' => '商城ID',
  41. 'user_id' => '签到天数',
  42. 'status' => '状态',
  43. 'created_at' => '创建时间',
  44. 'updated_at' => '修改时间'
  45. ];
  46. }
  47. /**
  48. * 导出字段
  49. */
  50. public static function exportFieldsList($field = null)
  51. {
  52. $fields = [
  53. 'usr.user_id' => '用户ID',
  54. 'u.nickname' => '用户昵称',
  55. 'u.mobile' => '用户手机',
  56. 'u.level' => '用户等级',
  57. 'usr.today' => '签到时间',//占位置,计算最新签到时间使用 created_at计算
  58. 'usr.created_at' => '今日签到状态',
  59. 'usr.score_num' => '签到赠送积分',
  60. 'usr.coupon_num' => '签到赠送优惠券',
  61. ];
  62. $temp = [];
  63. foreach ($fields as $key => $val) {
  64. $showField = explode('.', $key)[1];
  65. if (strstr($showField, ' ')) {
  66. $showField = explode(' ', $showField)[1];
  67. }
  68. if ($field === null) {
  69. $temp[$showField] = $val;
  70. } else if (in_array($showField, $field)) {
  71. $temp[$key] = $val;
  72. }
  73. }
  74. return $temp;
  75. }
  76. // public static function exportSignIn(array $data) {
  77. // $download_id = $data['download_id'] ?? 0;
  78. // $download = Download::findOne(['id' => $download_id]);
  79. // if ($download) {
  80. // $params = json_decode($download->params, true);
  81. // $fields = isset($params['fields']) ? $params['fields'] : null;//原始的字段
  82. // $exportField = self::exportFieldsList($fields);
  83. // //导出时查询的字段
  84. // unset($exportField['usr.today'], $exportField['u.nickname'], $exportField['u.mobile'], $exportField['u.level'], $exportField['u.coupon_num'], $exportField['u.score_num']);
  85. // //$where['where'][] = ['=', 'mall_id', $params['mall_id']];
  86. // if (isset($params['keywork']) && !empty($params['keywork'])) {
  87. // $where = [['=', 'id', $params['keywork']], ['=', 'mobile', $params['mobile']]];
  88. // $select[] = 'id';
  89. // !isset($fields['u.nickname']) && $select[] = 'nickname';
  90. // !isset($fields['u.mobile']) && $select[] = 'mobile';
  91. // !isset($fields['u.level']) && $select[] = 'level';
  92. // $model = User::find();
  93. // User::paramPack(['where' => $where, 'select' => $select], $model);
  94. // $userList = $model->asArray()->all();
  95. // if (!$userList) return;
  96. // $userSignMDL = self::find()->where(['user_id' => $userList['id']]);
  97. // $exportData = [];
  98. // $exportHeader = [];
  99. // $isSetHeader = false;
  100. // foreach ($userSignMDL->asArray()->each(500) as $l) {
  101. // $temp = [];
  102. // if (isset($fields['usr.user_id'])) $temp['user_id'] = $l['user_id'];
  103. // if (isset($fields['usr.today'])) $temp['sign_time'] = date('Y-m-d H:i:s', $l['created_at']);
  104. // if (isset($fields['usr.created_at'])) $temp['is_today'] = date('Y-m-d', $l['created_at']) == date('Y-m-d') ? '已签到' : '未签到';
  105. // if (isset($fields['usr.user_id'])) $temp['user_id'] = $l['user_id'];
  106. // }
  107. // }
  108. // }
  109. // }
  110. public static function getSignIn($where) {
  111. $model = self::find();
  112. $params['where'] = $where;
  113. $params['select'] = ['created_at'];
  114. self::paramPack($params, $model);
  115. return $model->column();
  116. }
  117. }