| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace addons\BusinessCard\common\models;
- use addons\BusinessCard\common\enums\CardEnums;
- use common\enums\StatusEnum;
- use common\models\user\User;
- use Exception;
- /**
- * This is the model class for table "qimall_addons_business_card_customer_log".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $user_id
- * @property int $item_id 对象ID
- * @property int $log_type 1:浏览首页,2:查看图文,3:查看商品,4:授权号码,5:转发名片,6:查看名片,7:查看视频,8:保存手机,9:点赞,10:收藏,11:评论,12:查看动态,13:新增客户,14:新增线索,15:下单
- * @property int $status 状态[1启用 0禁用 -1删除]
- * @property int $created_at 创建时间
- * @property int $updated_at 更新事件
- * @property int|null $material_log_id 素材浏览ID
- * @property int|null $material_id 素材ID
- * @property int|null $material_times 次数
- */
- class BusinessCardCustomerLog extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_addons_business_card_customer_log';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'item_id', 'log_type', 'status', 'created_at', 'updated_at', 'material_log_id', 'material_id', 'material_times'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'item_id' => 'Item ID',
- 'log_type' => 'Log Type',
- 'status' => 'Status',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'material_log_id' => 'Material Log ID',
- 'material_id' => 'Material ID',
- 'material_times' => 'Material Times',
- ];
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id, nickname, username, avatar_url, mobile');
- }
- public function getCard()
- {
- return $this->hasOne(BusinessCard::class, ['id' => 'item_id']);
- }
- /**
- * 保存数据
- *
- * @author hpei
- * @return bool|Exception
- */
- public static function setData($params) {
- try {
- if (empty($params['id'])) {
- $model = new self();
- $model->loadDefaultValues();
- } else {
- $model = self::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) throw new \Exception('数据不存在或者已删除');
- }
- if (!$model->load($params, '') || !$model->save()) throw new \Exception($model->getErrorMessage());
- return $model->id;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 最近浏览
- * @author hpei
- */
- public static function latelyBrowse($card_id, $day = 100) {
- $start_time = strtotime("-$day day");
- $user_list = self::find()->select(['user_id'])
- ->where(['item_id' => $card_id, 'log_type' => CardEnums::LOG_TYPE_LIKE])
- ->andWhere(['>', 'created_at', $start_time])
- ->andWhere(['<', 'created_at', time()])
- ->column();
- return User::find()->where(['id' => $user_list])->select(['avatar_url'])->column();
- }
- /**
- * 秒数转时分格式
- * @param $time int
- * @author jack
- * @throws string
- * @return string
- */
- public static function sec2Time($time)
- {
- $value = [
- "years" => 0, "days" => 0, "hours" => 0,
- "minutes" => 0, "seconds" => 0,
- ];
- if ($time >= 31556926) {
- $value["years"] = floor($time/31556926);
- $time = ($time%31556926);
- }
- if ($time >= 86400) {
- $value["days"] = floor($time/86400);
- $time = ($time%86400);
- }
- if ($time >= 3600) {
- $value["hours"] = floor($time/3600);
- $time = ($time%3600);
- }
- if ($time >= 60) {
- $value["minutes"] = floor($time/60);
- $time = ($time%60);
- }
- $value["seconds"] = floor($time);
- $t = '';
- if($value["years"]>0) $t .= $value["years"] . "年";
- if($value["days"]>0) $t .= $value["days"] . "天";
- if($value["hours"]>0) $t .= $value["hours"] . "小时";
- if($value["minutes"]>0) $t .= $value["minutes"] . "分";
- if($value["seconds"]>0) $t .= $value["seconds"] . "秒";
- return $t;
- }
- }
|