| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2025 赤店商城 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- use yii\db\ActiveRecord;
- class QuanziUp extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%quanzi_up}}';
- }
- public function behaviors()
- {
- return [
- [
- // 自动更新创建和更新时间
- 'class' => TimestampBehavior::class,
- ]
- ];
- }
- public static function upInit($user_id) {
- if(empty($user_id)){
- return new self();
- }
- $key = ['quanzi', 'upInit', $user_id];
- // cache_lock_del($key);
- if(!cache_lock($key, 86400*999)){
- try{
- $up = QuanziUp::findOne(['user_id' => $user_id]);
- if(!$up){
- $user = User::findOne($user_id);
- $up = new QuanziUp();
- $up->store_id = $user->store_id;
- $up->user_id = $user->id;
- $up->status = 1;
- $up->save();
- }
-
- } catch (\Exception $ex) {
- \Yii::error($ex);
- debug_log([__FUNCTION__, 'err', $user_id, $ex->getMessage()], __CLASS__ . '.log');
- cache_lock_del($key);
- }
- }
- return new self();
- }
- public static function blackUpUserIdAdd($user_id, $up_user_id, $del = 0) {
- $info = QuanziUp::upInit($user_id)::findOne(['user_id' => $user_id]);
- $ids = $info['black_up_user_ids'] ? explode(',', $info['black_up_user_ids']) : [];
- if($del){
- if(in_array($up_user_id, $ids)){
- $info->black_up_user_ids = implode(',', array_values(array_diff($ids, [$up_user_id])));
- $info->save();
- }
- }else{
- if(!in_array($up_user_id, $ids)){
- $info->black_up_user_ids = implode(',', array_values(array_merge($ids, [$up_user_id])));
- $info->save();
- }
- }
- }
- public static function labelUserSave($user_id, $label = '') {
- $info = QuanziUp::upInit($user_id)::findOne(['user_id' => $user_id]);
- $info->label_user = trim($label);
- $info->save();
- }
- }
|