| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 | <?php/** * IdentifyInQueueModel.php UTF-8 *   实名认证队列中信息 * * @date    : 2021/4/28 14:33 * * @license 这不是一个自由软件,未经授权不许任何使用和传播。 * @author  : chenbingling <cbl@huosdk.com> * @version : HUOSDK-IDENTITY 1.0 */namespace huoIdentify\model;use huo\model\common\CommonModel;use huolib\constant\CacheConst;use think\Cache;class IdentifyInQueueModel extends CommonModel {    protected $name = 'identify_in_queue';    protected $pk   = 'id';    /* 开启自动写入时间戳字段 */    protected $autoWriteTimestamp = true;    protected $cache_key_prefix   = CacheConst::CACHE_IDENTIFY_IN_QUEUE_PREFIX;    protected $type                                  = [            'id'           => 'integer',            'uid'          => 'string',            'channel_code' => 'string',            'real_name'    => 'string',            'id_card'      => 'string',            'identify_pi'  => 'string',            'create_time'  => 'timestamp',            'update_time'  => 'timestamp',        ];    /**     * 获取单条记录缓存key     *     * @param int $id ID     *     * @return string :string     */    protected function getSingleCacheKey($id) {        return $this->cache_key_prefix.$id;    }    /**     * 获取单条记录缓存key     *     * @param $uid     * @param $channel_code     * @param $id_card     *     * @return string :string     */    protected function getCacheKeyByUidCodeCard($uid, $channel_code, $id_card) {        $uid = (string)$uid;        $channel_code = (string)$channel_code;        $id_card = (string)$id_card;        $_array = [$uid, $channel_code, $id_card];        return $this->cache_key_prefix.'unc_'.md5(json_encode($_array));    }    /**     * 加入数据库     *     * @param array $data     *     * @return bool|int     */    public function addData($data) {        $_data = $data;        $_rs = parent::addData($_data);        if (empty($_rs)) {            return false;        }        $_cache_key = $this->getCacheKeyByUidCodeCard(            $_data['uid'], $_data['channel_code'], $_data['id_card']        );        Cache::set($_cache_key, $_rs);        return $_rs;    }    /**     * 通过ID获取信息     *     * @param int $id 主键ID     *     * @return array     */    public function getInfoById($id) {        /* 缓存操作 */        $_single_cache_key = $this->getSingleCacheKey($id);        $_data = Cache::get($_single_cache_key);        if (!empty($_data)) {            return $_data;        }        $_data = parent::getInfoById($id);        if (empty($_data)) {            return [];        }        Cache::set($_single_cache_key, $_data);        return $_data;    }    /**     * 更新单条数据     *     * @param array $data 数据     * @param int   $id   ID     *     * @return bool     */    public function updateData($data, $id) {        $_data = $data;        $_rs = parent::updateData($_data, $id);        if (false === $_rs) {            return false;        }        /* 缓存操作 */        $_single_cache_key = $this->getSingleCacheKey($id);        Cache::rm($_single_cache_key);        return true;    }    /**     * 删除单条数据     *     * @param      $id     * @param bool $is_complete     *     * @return bool|int     */    public function deleteData($id, $is_complete = true) {        $_old_data = $this->getInfoById($id);        $_rs = parent::deleteData($id, $is_complete);        if (false !== $_rs) {            $_cache_key = $this->getSingleCacheKey($id);            Cache::rm($_cache_key);            $_cache_key = $this->getCacheKeyByUidCodeCard(                $_old_data['uid'], $_old_data['channel_code'], $_old_data['id_card']            );            Cache::set($_cache_key, 0);        }        return $_rs;    }    /**     * 根据uid real_name id_card 获取id     *     * @param $uid     * @param $channel_code     * @param $id_card     *     * @return int|mixed     */    public function getIdByUidCodeCard($uid, $channel_code, $id_card) {        $_cache_key = $this->getCacheKeyByUidCodeCard($uid, $channel_code, $id_card);        if (Cache::has($_cache_key)) {            return Cache::get($_cache_key);        }        $_map = [            'uid'          => $uid,            'channel_code' => $channel_code,            'id_card'      => $id_card,        ];        $_id = $this->where($_map)->value($this->pk);        if (empty($_id)) {            $_id = 0;        }        Cache::set($_cache_key, $_id);        return $_id;    }}
 |