REAPI/app/merchant/service/ProjectProductService.php

85 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\merchant\service;
use app\core\Service;
use think\admin\extend\CodeExtend;
use app\merchant\service\MerchantService;
/**
* 商户产品服务
* Class ProductService
* @package app\merchant\service
*/
class ProjectProductService extends Service
{
/**
* 设置默认操作表
* @var string
*/
public $table = 'merchant_project_product';
# 获取商户信息
public function getInfo($mid, $project_id, $product_key)
{
$where['mid'] = $mid;
$where['project_id'] = $project_id;
$where['product_key'] = $product_key;
$data = $this->db()->where($where)->order('sort desc')->find();
return $data;
}
# 获取所有信息
public function getAll($mid, $project_id, $product_key)
{
$where['mid'] = $mid;
$where['project_id'] = $project_id;
$where['product_key'] = $product_key;
$data = $this->db()->where($where)->order('sort desc')->select()->toArray();
return $data;
}
# 获取缓存
public function get($mid, $project_id, $product_key, $get = true)
{
if (!$get) {
return false;
}
$cache_key = 'percent_' . $mid . '_' . $project_id . '_' . $product_key;
$data = !$get ? false : $this->cache($cache_key);
if (!$data) {
$data = $this->getInfo($mid, $project_id, $product_key);
if ($data) {
$this->cache($cache_key, $data);
}
}
if ($data) {
if ($data['status'] != 1) {
return false;
}
if ($data['is_deleted'] != 0) {
return false;
}
}
return $data;
}
# 更新
public function up($mid, $project_id, $product_key)
{
$info = $this->db()->where(['mid' => $mid, 'project_id' => $project_id, 'product_key' => $product_key])->find();
if ($info) {
//$data['mid'] = $mid;
$data['product_key'] = $product_key;
$this->db()->where(['id' => $info['id']])->update($data);
}
}
}