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); } }