<?php
|
|
namespace app\agent\model\app;
|
|
use app\common\model\app\App as AppModel;
|
use think\facade\Cache;
|
|
/**
|
* 应用模型
|
*/
|
class App extends AppModel
|
{
|
/**
|
* 更新应用设置
|
*/
|
public function edit($data)
|
{
|
$this->startTrans();
|
try {
|
// 删除app缓存
|
self::deleteCache();
|
$where['agent_id'] = self::$agent_id;
|
|
$count = $this->count($where);
|
// 更新小程序设置
|
if ($count > 0) {
|
self::update($data, $where);
|
}
|
if ($count == 0) {
|
$data['agent_id'] = self::$agent_id;
|
self::create($data);
|
}
|
$this->commit();
|
return true;
|
} catch (\Exception $e) {
|
$this->error = $e->getMessage();
|
$this->rollback();
|
return false;
|
}
|
}
|
|
public function count($where)
|
{
|
return $this->where($where)->count();
|
}
|
|
/**
|
* 删除app缓存
|
*/
|
public static function deleteCache()
|
{
|
return Cache::delete('agent_' . self::$agent_id);
|
}
|
|
}
|