<?php
/**
 * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 * @author      pillar<ltmn@qq.com>
 * 配置
 */
namespace app\allwin\model;
use think\Model;

class AllwinConfig extends Model{

    protected $pk = 'id';
  
    //配置表
    public static function getConfig(int $miniapp_id){
        return self::where(['member_miniapp_id' => $miniapp_id])->cache(true)->find();
    }
    
    //编辑
    public static function configs(array $param,int $miniapp_id){
        $rel = self::where(['member_miniapp_id' => $miniapp_id])->find();
        if(empty($rel)){
            $param['member_miniapp_id'] = $miniapp_id;
            return self::insert($param);
        }else{
            return self::where(['member_miniapp_id' => $miniapp_id])->update($param);
        }
    }

    //读取小程序列表
    public static function MiniappLists(){
        return self::view('member_miniapp','id,appname,miniapp_id,create_time,is_lock')
        ->view('miniapp','miniapp_dir','member_miniapp.miniapp_id = miniapp.id')
        ->view('allwin_config','is_psp,is_wechat_profitsharing,is_wechat_redpacket,is_wechat_touser','allwin_config.member_miniapp_id = member_miniapp.id')
        ->where(['miniapp.miniapp_dir' => 'allwin'])
        ->order('id desc')->paginate(20);
    }
}