| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- namespace addons\SignIn\common\models;
- use common\components\export\CsvTool;
- use common\enums\DownloadEnum;
- use common\models\common\Download;
- use common\models\base\BaseActiveRecord;
- use common\models\user\User;
- use Exception;
- use Yii;
- /**
- * This is the model class for table "{{%addons_user_sign_in_record}}".
- * @property int $id
- * @property int $user_id
- * @property int $created_at 创建时间
- */
- class UserSignInRecord extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_user_sign_in_record}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules(){
- return [
- [['user_id'], 'required'],
- [['user_id', 'mall_id', 'status', 'created_at', 'updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels(){
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '签到天数',
- 'status' => '状态',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间'
- ];
- }
- /**
- * 导出字段
- */
- public static function exportFieldsList($field = null)
- {
- $fields = [
- 'usr.user_id' => '用户ID',
- 'u.nickname' => '用户昵称',
- 'u.mobile' => '用户手机',
- 'u.level' => '用户等级',
- 'usr.today' => '签到时间',//占位置,计算最新签到时间使用 created_at计算
- 'usr.created_at' => '今日签到状态',
- 'usr.score_num' => '签到赠送积分',
- 'usr.coupon_num' => '签到赠送优惠券',
- ];
- $temp = [];
- foreach ($fields as $key => $val) {
- $showField = explode('.', $key)[1];
- if (strstr($showField, ' ')) {
- $showField = explode(' ', $showField)[1];
- }
- if ($field === null) {
- $temp[$showField] = $val;
- } else if (in_array($showField, $field)) {
- $temp[$key] = $val;
- }
- }
- return $temp;
- }
- // public static function exportSignIn(array $data) {
- // $download_id = $data['download_id'] ?? 0;
- // $download = Download::findOne(['id' => $download_id]);
- // if ($download) {
- // $params = json_decode($download->params, true);
- // $fields = isset($params['fields']) ? $params['fields'] : null;//原始的字段
- // $exportField = self::exportFieldsList($fields);
- // //导出时查询的字段
- // unset($exportField['usr.today'], $exportField['u.nickname'], $exportField['u.mobile'], $exportField['u.level'], $exportField['u.coupon_num'], $exportField['u.score_num']);
- // //$where['where'][] = ['=', 'mall_id', $params['mall_id']];
- // if (isset($params['keywork']) && !empty($params['keywork'])) {
- // $where = [['=', 'id', $params['keywork']], ['=', 'mobile', $params['mobile']]];
- // $select[] = 'id';
- // !isset($fields['u.nickname']) && $select[] = 'nickname';
- // !isset($fields['u.mobile']) && $select[] = 'mobile';
- // !isset($fields['u.level']) && $select[] = 'level';
- // $model = User::find();
- // User::paramPack(['where' => $where, 'select' => $select], $model);
- // $userList = $model->asArray()->all();
- // if (!$userList) return;
- // $userSignMDL = self::find()->where(['user_id' => $userList['id']]);
- // $exportData = [];
- // $exportHeader = [];
- // $isSetHeader = false;
- // foreach ($userSignMDL->asArray()->each(500) as $l) {
- // $temp = [];
- // if (isset($fields['usr.user_id'])) $temp['user_id'] = $l['user_id'];
- // if (isset($fields['usr.today'])) $temp['sign_time'] = date('Y-m-d H:i:s', $l['created_at']);
- // if (isset($fields['usr.created_at'])) $temp['is_today'] = date('Y-m-d', $l['created_at']) == date('Y-m-d') ? '已签到' : '未签到';
- // if (isset($fields['usr.user_id'])) $temp['user_id'] = $l['user_id'];
-
- // }
- // }
-
- // }
- // }
- public static function getSignIn($where) {
- $model = self::find();
- $params['where'] = $where;
- $params['select'] = ['created_at'];
- self::paramPack($params, $model);
- return $model->column();
- }
- }
|