Store.php 2.8 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/5/8
 * Time: 13:24
 */

namespace app\index\model;


use think\Model;

class Store extends Model
{
    public function getProvinceIdsAttr($value){
        $province_ids = [];
        if(!empty($value)){
            $province_ids = explode(',',trim($value,','));
        }
        return $province_ids;
    }
    public function getThumbnailAttr($value){
        return cdnurl($value);
    }
    public function selectData($where){
        $data = $this->where($where)->select();
        $areaModel = new Area();
        foreach($data as $key => $vo){
            //判断会员是否过期
            $is_vip = '2';
            if(!empty($vo['vip_passtime'])){
                if($vo['vip_passtime'] > time()){
                    $is_vip = "1";
                }
            }
            $is_svip = '2';
            if(!empty($vo['svip_passtime'])){
                if($vo['svip_passtime'] > time()){
                    $is_svip = "1";
                }
            }
            $data[$key]['is_vip'] = $is_vip;
            $data[$key]['is_svip'] = $is_svip;
            //获取省市区
            $province_name = $areaModel->where(['id'=>$vo['province_id']])->value('name');
            $city_name = $areaModel->where(['id'=>$vo['city_id']])->value('name');
            $county_name = $areaModel->where(['id'=>$vo['county_id']])->value('name');
            $data[$key]['province_name'] = $province_name;
            $data[$key]['city_name'] = $city_name;
            $data[$key]['county_name'] = $county_name;
        }
        return $data;
    }
    public function findData($where){
        $data = $this->where($where)->find();
        if(!empty($data)){
            //判断会员是否过期
            $is_vip = '2';
            if(!empty($data['vip_passtime'])){
                if($data['vip_passtime'] > time()){
                    $is_vip = "1";
                }
            }
            $is_svip = '2';
            if(!empty($data['svip_passtime'])){
                if($data['svip_passtime'] > time()){
                    $is_svip = "1";
                }
            }
            $data['is_vip'] = $is_vip;
            $data['is_svip'] = $is_svip;
            //获取省市区
            $areaModel = new Area();
            $province_name = $areaModel->where(['id'=>$data['province_id']])->value('name');
            $city_name = $areaModel->where(['id'=>$data['city_id']])->value('name');
            $county_name = $areaModel->where(['id'=>$data['county_id']])->value('name');
            $data['province_name'] = $province_name;
            $data['city_name'] = $city_name;
            $data['county_name'] = $county_name;
        }
        return $data;
    }
    public function updateData($where,$data){
        $result = $this->where($where)->update($data);
        return $result;
    }
}